8f775ad288765f271d20dcd75c9f701e7fb486e9.svn-base 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. package com.sinosoft.exercise.examine.service;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.math.BigDecimal;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.UUID;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import javax.ws.rs.POST;
  14. import javax.ws.rs.Path;
  15. import javax.ws.rs.ProduceMime;
  16. import javax.ws.rs.core.Context;
  17. import net.sf.json.JSONArray;
  18. import net.sf.json.JSONObject;
  19. import org.apache.log4j.Logger;
  20. import org.apache.poi.ss.usermodel.Row;
  21. import com.formaction.Utils;
  22. import com.persistence.service.assitant.generator.IdentityGenerator;
  23. import com.sinosoft.common.excel.JsonPluginsUtil;
  24. import com.sinosoft.common.upLoad.util.SmartUpload;
  25. import com.sinosoft.common.util.FilePathUtil;
  26. import com.sinosoft.em.alert.report.manage.service.QueryReportProgrammeServiceImpl;
  27. import com.sinosoft.em.evaluate.excel.ExportExcelUtils;
  28. import com.sinosoft.exercise.examine.dao.ExamineManagementDao;
  29. import com.sinosoft.exercise.examine.dao.ImportExcelDao;
  30. import com.sinosoft.lz.system.util.JsonUtil;
  31. @Path("/ExamineManagementService/")
  32. public class ExamineManagementServer {
  33. @Context
  34. private org.apache.cxf.jaxrs.ext.MessageContext mc;
  35. private final static Logger log = Logger.getLogger(QueryReportProgrammeServiceImpl.class);
  36. /**
  37. * 通过题库主表主键查询对应的副表数据,也就是选项内容
  38. * @param params
  39. * @return
  40. */
  41. @POST
  42. @ProduceMime("application/json")
  43. @Path("/getDataByQuestionID/")
  44. public String getDataByQuestionID(String params){
  45. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  46. String question_id=Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);
  47. ExamineManagementDao dao = new ExamineManagementDao();
  48. try {
  49. list = dao.getDataByQuestionID(question_id);
  50. } catch (SQLException e) {
  51. // TODO Auto-generated catch block
  52. e.printStackTrace();
  53. }
  54. return JSONArray.fromObject(list).toString();
  55. }
  56. /**
  57. * 保存考生填写的答案与题号等记录到考试记录子表
  58. * @param params
  59. * @return
  60. */
  61. @POST
  62. @ProduceMime("text/html")
  63. @Path("/saveExamineeAnswer/")
  64. public String saveExamineeAnswer(String params){
  65. String scoresId=Utils.getParameter("scoresId", params)==null?"":Utils.getParameter("scoresId", params);
  66. String userId=Utils.getParameter("userId", params)==null?"":Utils.getParameter("userId", params);
  67. String userAnswer=Utils.getParameter("userAnswer", params)==null?"":Utils.getParameter("userAnswer", params);
  68. ExamineManagementDao dao = new ExamineManagementDao();
  69. try {
  70. dao.saveExamineeAnswer(scoresId,userId,userAnswer);
  71. } catch (Exception e) {
  72. // TODO Auto-generated catch block
  73. e.printStackTrace();
  74. }
  75. return "";
  76. }
  77. /**
  78. * 从题库中随机抽取20道题目
  79. * @param params
  80. * @return
  81. */
  82. @POST
  83. @ProduceMime("application/json")
  84. @Path("/getQuestionPaperForRandom/")
  85. public String getQuestionPaperForRandom(String params){
  86. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  87. String questionNum = Utils.getParameter("questionNum", params)==null?"":Utils.getParameter("questionNum", params);//题数
  88. String unitId = Utils.getParameter("unitId", params)==null?"":Utils.getParameter("unitId", params);//单位id
  89. String roleId = Utils.getParameter("roleId", params)==null?"":Utils.getParameter("roleId", params);//角色id
  90. ExamineManagementDao dao = new ExamineManagementDao();
  91. String[] num = {};
  92. if(!"".equals(questionNum)){
  93. num = questionNum.split(",");
  94. }
  95. String[] roleIds = {};
  96. if(!"".equals(roleId)){
  97. roleIds = roleId.split(",");
  98. }
  99. try {
  100. list = dao.getQuestionPaperForRandom(num,unitId,roleIds);
  101. } catch (Exception e) {
  102. // TODO Auto-generated catch block
  103. e.printStackTrace();
  104. }
  105. return JSONArray.fromObject(list).toString();
  106. }
  107. /**
  108. * 获取考生考试信息与题目信息,用于考卷查看页面
  109. * @param params
  110. * @return
  111. */
  112. @POST
  113. @ProduceMime("application/json")
  114. @Path("/getQuestionPaperDetail/")
  115. public String getQuestionPaperDetail(String params){
  116. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  117. String fd_id=Utils.getParameter("fd_id", params)==null?"":Utils.getParameter("fd_id", params);//题数
  118. ExamineManagementDao dao = new ExamineManagementDao();
  119. try {
  120. list = dao.getQuestionPaperDetail(fd_id);
  121. } catch (Exception e) {
  122. // TODO Auto-generated catch block
  123. e.printStackTrace();
  124. }
  125. return JSONArray.fromObject(list).toString();
  126. }
  127. /**
  128. * 获取答案
  129. * @param params
  130. * @return
  131. */
  132. @POST
  133. @ProduceMime("application/json")
  134. @Path("/getAnswerNum/")
  135. public String getAnswerNum(String params){
  136. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  137. String question_id=Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);
  138. ExamineManagementDao dao = new ExamineManagementDao();
  139. try {
  140. list = dao.getAnswerNum(question_id);
  141. } catch (SQLException e) {
  142. // TODO Auto-generated catch block
  143. e.printStackTrace();
  144. }
  145. return JSONArray.fromObject(list).toString();
  146. }
  147. /**
  148. * 删除模板中的题目
  149. * @param params
  150. * @return
  151. */
  152. @POST
  153. @ProduceMime("application/json")
  154. @Path("/delTemplateQuestion/")
  155. public int delTemplateQuestion(String params){
  156. int result = 0;
  157. String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
  158. String question_id=Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);
  159. ExamineManagementDao dao = new ExamineManagementDao();
  160. try {
  161. result = dao.delTemplateQuestion(template_id,question_id);
  162. } catch (SQLException e) {
  163. // TODO Auto-generated catch block
  164. e.printStackTrace();
  165. }
  166. return result;
  167. }
  168. /**
  169. * 删除模板
  170. * @param params
  171. * @return
  172. */
  173. @POST
  174. @ProduceMime("application/json")
  175. @Path("/delTemplate/")
  176. public int delTemplate(String params){
  177. int result = 0;
  178. String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
  179. ExamineManagementDao dao = new ExamineManagementDao();
  180. try {
  181. result = dao.delTemplate(template_id);
  182. } catch (SQLException e) {
  183. // TODO Auto-generated catch block
  184. e.printStackTrace();
  185. }
  186. return result;
  187. }
  188. /**
  189. * 增加使用模板次数
  190. * @param params
  191. * @return
  192. */
  193. @POST
  194. @ProduceMime("application/json")
  195. @Path("/addTemplateNumber/")
  196. public int addTemplateNumber(String params){
  197. int result = 0;
  198. String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
  199. ExamineManagementDao dao = new ExamineManagementDao();
  200. try {
  201. result = dao.addTemplateNumber(template_id);
  202. } catch (SQLException e) {
  203. // TODO Auto-generated catch block
  204. e.printStackTrace();
  205. }
  206. return result;
  207. }
  208. /**
  209. * 绑定模板
  210. * @param params
  211. * @return
  212. */
  213. @POST
  214. @ProduceMime("application/json")
  215. @Path("/bindTemplate/")
  216. public boolean bindTemplate(String params){
  217. Boolean result = false;
  218. String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
  219. String ids=Utils.getParameter("ids", params)==null?"":Utils.getParameter("ids", params);
  220. if(ids.isEmpty()){
  221. return result;
  222. }
  223. String[] id = ids.split(",");
  224. ExamineManagementDao dao = new ExamineManagementDao();
  225. try {
  226. result = dao.bindTemplate(template_id,id);
  227. } catch (SQLException e) {
  228. // TODO Auto-generated catch block
  229. e.printStackTrace();
  230. }
  231. return result;
  232. }
  233. /**
  234. * 通过模板id获取题型数量
  235. * @param tempId
  236. * @return
  237. */
  238. @POST
  239. @ProduceMime("application/json")
  240. @Path("/getQuestionTypeByTemplate/")
  241. public String getQuestionTypeByTemplate(String params){
  242. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  243. String templateId = Utils.getParameter("templateId", params)==null?"":Utils.getParameter("templateId", params);
  244. ExamineManagementDao dao = new ExamineManagementDao();
  245. try {
  246. list = dao.getQuestionTypeByTemplate(templateId);
  247. } catch (SQLException e) {
  248. // TODO Auto-generated catch block
  249. e.printStackTrace();
  250. }
  251. return JSONArray.fromObject(list).toString();
  252. }
  253. /**
  254. * 获取当前模板是否在执行任务
  255. * @param params
  256. * @return
  257. */
  258. @POST
  259. @ProduceMime("application/json")
  260. @Path("/getTaskByTemplate/")
  261. public String getTaskByTemplate(String params){
  262. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  263. String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
  264. ExamineManagementDao dao = new ExamineManagementDao();
  265. try {
  266. list = dao.getTaskByTemplate(template_id);
  267. } catch (SQLException e) {
  268. // TODO Auto-generated catch block
  269. e.printStackTrace();
  270. }
  271. return JSONArray.fromObject(list).toString();
  272. }
  273. /**
  274. * 获取考试时间
  275. * @return
  276. */
  277. @POST
  278. @ProduceMime("application/json")
  279. @Path("/getQuestionTime/")
  280. public String getQuestionTime(String params){
  281. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  282. String unitId=Utils.getParameter("unitId", params)==null?"":Utils.getParameter("unitId", params);
  283. ExamineManagementDao dao = new ExamineManagementDao();
  284. try {
  285. list = dao.getQuestionTime(unitId);
  286. } catch (SQLException e) {
  287. // TODO Auto-generated catch block
  288. e.printStackTrace();
  289. }
  290. return JSONArray.fromObject(list).toString();
  291. }
  292. /**
  293. * 根据模板从题库中提取题目
  294. * @param params
  295. * @return
  296. */
  297. @POST
  298. @ProduceMime("application/json")
  299. @Path("/getQuestionByTemplate/")
  300. public String getQuestionByTemplate(String params){
  301. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  302. String template_id = Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);//题数
  303. ExamineManagementDao dao = new ExamineManagementDao();
  304. try {
  305. list = dao.getQuestionByTemplate(template_id);
  306. } catch (Exception e) {
  307. // TODO Auto-generated catch block
  308. e.printStackTrace();
  309. }
  310. return JSONArray.fromObject(list).toString();
  311. }
  312. /**
  313. * 获取每一个分段人数,可按单位进行筛选 (图表)
  314. * @param params
  315. * @return
  316. */
  317. @POST
  318. @ProduceMime("application/json")
  319. @Path("/getScoreCountByUnit/")
  320. public String getScoreCountByUnit(String params){
  321. String result = "";
  322. String dept_ids = Utils.getParameter("dept_id", params)==null?"":Utils.getParameter("dept_id", params);//单位id
  323. String task_id = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);//任务id
  324. ExamineManagementDao dao = new ExamineManagementDao();
  325. String[] ids = dept_ids.split(",");
  326. if("".equals(task_id)||"".equals(dept_ids)){
  327. return "{\"title\":\"考试用户人数\",\"legend_data\":[\"\"],\"xAxis_data\":[\"\"]}";
  328. }
  329. try {
  330. result = dao.getScoreCountByUnit(ids,task_id);
  331. } catch (Exception e) {
  332. // TODO Auto-generated catch block
  333. e.printStackTrace();
  334. }
  335. return result;
  336. }
  337. /**
  338. * 获取单位平均得分(图表)
  339. * @param params
  340. * @return
  341. */
  342. @POST
  343. @ProduceMime("application/json")
  344. @Path("/getAvgScoreByUnit/")
  345. public String getAvgScoreByUnit(String params){
  346. String result = "";
  347. String dept_ids = Utils.getParameter("dept_id", params)==null?"":Utils.getParameter("dept_id", params);//单位id
  348. String task_id = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);//任务id
  349. ExamineManagementDao dao = new ExamineManagementDao();
  350. String[] ids = dept_ids.split(",");
  351. if("".equals(task_id)||"".equals(dept_ids)){
  352. return "{\"title\":\"单位平均分\",\"legend_data\":[\"\"],\"xAxis_data\":[\"\"]}";
  353. }
  354. try {
  355. result = dao.getAvgScoreByUnit(ids,task_id);
  356. } catch (Exception e) {
  357. // TODO Auto-generated catch block
  358. e.printStackTrace();
  359. }
  360. return result;
  361. }
  362. /**
  363. * 查询用户是否完成考试
  364. * @param params
  365. * @return
  366. */
  367. @POST
  368. @ProduceMime("application/json")
  369. @Path("/getQuestionByUserId/")
  370. public String getQuestionByUserId(String params){
  371. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  372. String user_id = Utils.getParameter("user_id", params)==null?"":Utils.getParameter("user_id", params);
  373. String task_ids = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);
  374. if(task_ids.isEmpty()){
  375. return "[]";
  376. }
  377. String[] ids = task_ids.split(",");
  378. ExamineManagementDao dao = new ExamineManagementDao();
  379. try {
  380. list = dao.getQuestionByUserId(user_id,ids);
  381. } catch (Exception e) {
  382. // TODO Auto-generated catch block
  383. e.printStackTrace();
  384. }
  385. return JSONArray.fromObject(list).toString();
  386. }
  387. /**
  388. * 查询当前题目在使用的数量
  389. * @param params
  390. * @return
  391. */
  392. @POST
  393. @ProduceMime("application/json")
  394. @Path("/getSumByquestionId/")
  395. public String getSumByquestionId(String params){
  396. Map<String, String> map = new HashMap<String, String>();
  397. String question_id = Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);//题目Id
  398. ExamineManagementDao dao = new ExamineManagementDao();
  399. try {
  400. map = dao.getSumByquestionId(question_id);
  401. } catch (Exception e) {
  402. // TODO Auto-generated catch block
  403. e.printStackTrace();
  404. }
  405. return JSONObject.fromObject(map).toString();
  406. }
  407. /**
  408. * 获取表头
  409. * @param params
  410. * @return
  411. */
  412. @POST
  413. @ProduceMime("application/json")
  414. @Path("/getTableHead/")
  415. public String getTableHead(String params){
  416. List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
  417. String role_id = Utils.getParameter("role_id", params)==null?"":Utils.getParameter("role_id", params);//角色id
  418. ExamineManagementDao dao = new ExamineManagementDao();
  419. if("".equals(role_id)){
  420. return "";
  421. }
  422. String[] role_ids = role_id.split(",");
  423. try {
  424. result = dao.getTableHead(role_ids);
  425. } catch (Exception e) {
  426. // TODO Auto-generated catch block
  427. e.printStackTrace();
  428. }
  429. return "[{\"display\":\"统计表\",\"columns\":"+JSONArray.fromObject(result)+"}]";
  430. }
  431. /**
  432. * 获取数据
  433. * @param params
  434. * @return
  435. */
  436. @POST
  437. @ProduceMime("application/json")
  438. @Path("/staticsScoreByUnit/")
  439. public String staticsScoreByUnit(String params){
  440. List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
  441. String task_id = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);//任务id
  442. String dept_id = Utils.getParameter("dept_id", params)==null?"":Utils.getParameter("dept_id", params);//单位id
  443. String role_id = Utils.getParameter("role_id", params)==null?"":Utils.getParameter("role_id", params);//角色id
  444. ExamineManagementDao dao = new ExamineManagementDao();
  445. if("".equals(role_id)||"".equals(dept_id)||"".equals(task_id)){
  446. return "";
  447. }
  448. String[] role_ids = role_id.split(",");
  449. String[] dept_ids = dept_id.split(",");
  450. try {
  451. result = dao.staticsScoreByUnit(task_id,dept_ids,role_ids);
  452. } catch (Exception e) {
  453. // TODO Auto-generated catch block
  454. e.printStackTrace();
  455. }
  456. return "{\"rows\":"+JSONArray.fromObject(result)+"}";
  457. }
  458. @POST
  459. @ProduceMime("application/json")
  460. @Path("/getRole/")
  461. public String getRole(){
  462. String result = "";
  463. ExamineManagementDao dao = new ExamineManagementDao();
  464. try {
  465. result = dao.getRole();
  466. } catch (Exception e) {
  467. // TODO Auto-generated catch block
  468. e.printStackTrace();
  469. }
  470. return result;
  471. }
  472. /**
  473. * 通用左侧树专用
  474. * 查询出到县区级的单位
  475. * @param params
  476. * @return
  477. */
  478. @ProduceMime("application/json")
  479. @POST
  480. @Path("/getAllUnitTree")
  481. public String getAllUnitTree(String params){
  482. String dept_ids = Utils.getParameter("dept_ids", params) == null ? "" : Utils.getParameter("dept_ids", params);
  483. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
  484. ExamineManagementDao dao = new ExamineManagementDao();
  485. String unitData = dao.getUnitMsgByCon("4",id,dept_ids);//获取所有单位数据
  486. StringBuffer sb = new StringBuffer();
  487. sb.append("{\"treeNodes\":");
  488. sb.append(unitData);
  489. sb.append("}");
  490. return sb.toString();
  491. }
  492. /**
  493. * 题目错误率排行榜
  494. * @param params
  495. * @return
  496. */
  497. @POST
  498. @ProduceMime("application/json")
  499. @Path("/getQuestionByMistake/")
  500. public String getQuestionByMistake(String params){
  501. String place = Utils.getParameter("place", params) == null ? "" : Utils.getParameter("place", params);//前几名
  502. List<Map<String, String>> list = new ArrayList<Map<String,String>>();
  503. ExamineManagementDao dao = new ExamineManagementDao();
  504. if("".equals(place)){
  505. return "{\"rows\":\"\"}";
  506. }
  507. try {
  508. list = dao.getQuestionByMistake(place);
  509. } catch (Exception e) {
  510. // TODO Auto-generated catch block
  511. e.printStackTrace();
  512. }
  513. return "{\"rows\":" +JSONArray.fromObject(list).toString()+ "}";
  514. }
  515. /**
  516. * 导入excel
  517. * @param params
  518. * @return
  519. */
  520. @ProduceMime("application/json")
  521. @POST
  522. @Path("/getExcelToList")
  523. public String getExcelToList(@Context HttpServletRequest request, @Context HttpServletResponse response){
  524. String fileExt = request.getParameter("fileExt");
  525. SmartUpload upload = new SmartUpload();
  526. upload.initialize(request, response, request.getSession().getServletContext());
  527. String filePath = "";
  528. try {
  529. String uploadPath = FilePathUtil.getUploadPath();
  530. log.info("路径===:"+uploadPath);
  531. int currentTotalSize = request.getContentLength();
  532. log.info("当前上传的附件总大小为-----" + currentTotalSize);
  533. if (currentTotalSize < 40 * 1024 * 1024) {
  534. upload.service(request, response);
  535. upload.setMaxFileSize(100 * 1024 * 1024);
  536. upload.setTotalMaxFileSize(400 * 1024 * 1024);
  537. upload.upload();
  538. com.sinosoft.common.upLoad.util.File file = upload.getFiles().getFile(0);
  539. String saveName = UUID.randomUUID().toString();
  540. filePath = uploadPath+File.separator+saveName+"."+fileExt;
  541. file.saveAs(filePath);
  542. }
  543. } catch (Exception e1) {
  544. e1.printStackTrace();
  545. }
  546. List<Map<String, String>> excelData = new ArrayList<Map<String, String>>();
  547. ImportExcelDao importExcelDao = new ImportExcelDao();
  548. try {
  549. excelData = importExcelDao.readInnerExcel(filePath);
  550. } catch (Exception e) {
  551. // TODO Auto-generated catch block
  552. e.printStackTrace();
  553. }
  554. return "[{\"result\":"+JsonUtil.list2json(excelData)+"}]";
  555. }
  556. /**
  557. * 保存excel数据
  558. * @param params
  559. * @return
  560. */
  561. @ProduceMime("application/json")
  562. @POST
  563. @Path("/saveQuestion")
  564. public String saveQuestion(String params) {
  565. ExamineManagementDao dao = new ExamineManagementDao();
  566. String userName = Utils.getParameter("userName", params) == null ? "" : Utils
  567. .getParameter("userName", params);
  568. String userId = Utils.getParameter("userId", params) == null ? "" : Utils
  569. .getParameter("userId", params);
  570. String userUnit = Utils.getParameter("userUnit", params) == null ? "" : Utils
  571. .getParameter("userUnit", params);
  572. String userDept = Utils.getParameter("userDept", params) == null ? "" : Utils
  573. .getParameter("userDept", params);
  574. String versionId = Utils.getParameter("versionId", params) == null ? "" : Utils
  575. .getParameter("versionId", params);
  576. String data = Utils.getParameter("data", params) == null ? "" : Utils
  577. .getParameter("data", params);
  578. List<Map<String, String>> dataList = JsonPluginsUtil.jsonToMapList(data);
  579. List<Map<String, String>> bankList = new ArrayList<Map<String,String>>();//存储主表数据
  580. List<Map<String, String>> bankSubList = new ArrayList<Map<String,String>>();//存储子表数据
  581. Map<String,String> idMap = new HashMap<String, String>();//存储id
  582. Map<String,String> classifyMap = new HashMap<String, String>();//题目类别
  583. Map<String,String> typeMap = new HashMap<String, String>();//题目类型
  584. try {
  585. classifyMap = dao.getQuestionClassify("BM_ECM_TRAIN_EXAMINE_QUESTION_CLASSIFY");
  586. typeMap = dao.getQuestionClassify("BM_ECM_TRAIN_EXAMINE_QUESTION_TYPE");
  587. } catch (SQLException e) {
  588. e.printStackTrace();
  589. }
  590. int count = 0;//记录情景选择题个数
  591. String fdid = "";//记录情景选择题id
  592. Map<String,String> type4Map = new HashMap<String, String>();//储存情景选择题主表数据
  593. //String fd_id = IdentityGenerator.getIdentityGenerator().gerenalIdentity(603);
  594. for(int i=0;i<dataList.size();i++){
  595. Map<String,String> map = dataList.get(i);
  596. Map<String,String> bankMap = new HashMap<String, String>();//存主表数据
  597. String fd_id = map.get("FD_ID");
  598. String classify = classifyMap.get(map.get("QUESTION_CLASSIFY"));//专业类别
  599. String content = map.get("EXAMINATION_CONTENT");//内容来源
  600. String applicable1 = map.get("APPLICABLE_OBJECT_1");
  601. String applicable2 = map.get("APPLICABLE_OBJECT_2");
  602. String applicable3 = map.get("APPLICABLE_OBJECT_3");
  603. String applicable4 = map.get("APPLICABLE_OBJECT_4");
  604. String applicable = "";
  605. if(!("".equals(applicable1)||"/".equals(applicable1))){
  606. applicable += "1,";
  607. }
  608. if(!("".equals(applicable2)||"/".equals(applicable2))){
  609. applicable += "2,";
  610. }
  611. if(!("".equals(applicable3)||"/".equals(applicable3))){
  612. applicable += "3,";
  613. }
  614. if(!("".equals(applicable4)||"/".equals(applicable4))){
  615. applicable += "4,";
  616. }
  617. if(applicable.length()>1){
  618. applicable = applicable.substring(0, applicable.length()-1);
  619. }
  620. String questionType = typeMap.get(map.get("QUESTION_TYPE"));//题目类型
  621. String questionName = map.get("QUESTION_NAME");//题目名称
  622. String answer1 = map.get("ANSWER_A");
  623. String answer2 = map.get("ANSWER_B");
  624. String answer3 = map.get("ANSWER_C");
  625. String answer4 = map.get("ANSWER_D");
  626. String answer5 = map.get("ANSWER_E");
  627. String answer6 = map.get("ANSWER_F");
  628. String answer7 = map.get("ANSWER_G");
  629. String questionAnswer = map.get("QUESTION_ANSWER").trim();
  630. if(!"".equals(questionType)&&!"".equals(questionName)){
  631. count = 0;//记录情景选择题个数
  632. fdid = "";//记录情景选择题id
  633. type4Map = new HashMap<String, String>();//储存情景选择题主表数据
  634. String genrenalId = IdentityGenerator.getIdentityGenerator().gerenalIdentity(603);
  635. idMap.put(fd_id, genrenalId);
  636. }
  637. if(!"3".equals(questionType)&&("".equals(answer1)||"/".equals(answer1))){
  638. continue;
  639. }
  640. /************储存主表数据(题目)**************/
  641. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  642. if(count ==0){
  643. count++;
  644. fdid = idMap.get(fd_id);
  645. type4Map.put("FD_ID", fdid);
  646. type4Map.put("INPUT_NAME", userName);
  647. type4Map.put("INPUT_NAME_ID", userId);
  648. type4Map.put("INPUT_PERSON_UNIT", userUnit);
  649. type4Map.put("INPUT_PERSON_DEPT", userDept);
  650. type4Map.put("QUESTION_NAME", questionName);
  651. type4Map.put("QUESTION_TYPE", questionType);
  652. type4Map.put("EXAMINATION_CONTENT", content);
  653. type4Map.put("APPLICABLE_OBJECT", applicable);
  654. type4Map.put("ANSWER_TYPE", "1");
  655. if(questionAnswer.length()>1){
  656. type4Map.put("ANSWER_OPTION", "2");//答案类型 情景选择题
  657. String answer = "";
  658. for(int j=0;j<questionAnswer.length();j++){//将字符串ABCD转为A,B,C,D
  659. answer += questionAnswer.charAt(j)+",";
  660. }
  661. answer = answer.substring(0, answer.length()-1);
  662. type4Map.put("QUESTION_ANSWER", answer);//答案:情景选择题-多个答案
  663. }else{
  664. type4Map.put("ANSWER_OPTION", "1");
  665. type4Map.put("QUESTION_ANSWER", questionAnswer);
  666. }
  667. type4Map.put("QUESTION_CLASSIFY", classify);
  668. type4Map.put("QUESTION_VERSION_ID", versionId);
  669. }else if(count ==3){
  670. String question_answer = type4Map.get("QUESTION_ANSWER");
  671. String answer_option = type4Map.get("ANSWER_OPTION");
  672. if(questionAnswer.length()>1){
  673. String answer = "";
  674. for(int j=0;j<questionAnswer.length();j++){//将字符串ABCD转为A,B,C,D
  675. answer += questionAnswer.charAt(j)+",";
  676. }
  677. answer = answer.substring(0, answer.length()-1);
  678. question_answer += "|"+answer;
  679. answer_option +="|2";
  680. type4Map.put("QUESTION_ANSWER", question_answer);
  681. type4Map.put("ANSWER_OPTION", answer_option);
  682. }else{
  683. question_answer += "|"+questionAnswer;
  684. answer_option +="|1";
  685. type4Map.put("QUESTION_ANSWER", question_answer);
  686. type4Map.put("ANSWER_OPTION", answer_option);
  687. }
  688. bankList.add(type4Map);
  689. count++;
  690. }else{
  691. String question_answer = type4Map.get("QUESTION_ANSWER");
  692. String answer_option = type4Map.get("ANSWER_OPTION");
  693. if(questionAnswer.length()>1){
  694. String answer = "";
  695. for(int j=0;j<questionAnswer.length();j++){//将字符串ABCD转为A,B,C,D
  696. answer += questionAnswer.charAt(j)+",";
  697. }
  698. answer = answer.substring(0, answer.length()-1);
  699. question_answer += "|"+answer;
  700. answer_option +="|2";
  701. type4Map.put("QUESTION_ANSWER", question_answer);
  702. type4Map.put("ANSWER_OPTION", answer_option);
  703. }else{
  704. question_answer += "|"+questionAnswer;
  705. answer_option +="|1";
  706. type4Map.put("QUESTION_ANSWER", question_answer);
  707. type4Map.put("ANSWER_OPTION", answer_option);
  708. }
  709. count++;
  710. }
  711. }
  712. if(!"4".equals(questionType)&&questionType!=null){//非情景选择题
  713. //将数据放入map
  714. bankMap.put("FD_ID", idMap.get(fd_id));
  715. bankMap.put("INPUT_NAME", userName);
  716. bankMap.put("INPUT_NAME_ID", userId);
  717. bankMap.put("INPUT_PERSON_UNIT", userUnit);
  718. bankMap.put("INPUT_PERSON_DEPT", userDept);
  719. bankMap.put("QUESTION_NAME", questionName);
  720. bankMap.put("QUESTION_TYPE", questionType);
  721. if("3".equals(questionType)){//判断题
  722. String answer = "";
  723. if("对".equals(questionAnswer)||"正确".equals(questionAnswer)){
  724. answer = "A";
  725. }
  726. if("错".equals(questionAnswer)||"错误".equals(questionAnswer)){
  727. answer = "B";
  728. }
  729. bankMap.put("QUESTION_ANSWER",answer);
  730. }else{
  731. String answer = "";
  732. for(int k=0;k<questionAnswer.length();k++){//将ABCD转化为A,B,C,D
  733. answer += questionAnswer.charAt(k)+",";
  734. }
  735. answer = answer.substring(0,answer.length()-1);
  736. bankMap.put("QUESTION_ANSWER", answer);//答案:情景选择题-多个答案
  737. }
  738. bankMap.put("EXAMINATION_CONTENT", content);
  739. bankMap.put("APPLICABLE_OBJECT", applicable);
  740. bankMap.put("ANSWER_TYPE", "1");
  741. bankMap.put("ANSWER_OPTION", "");//答案类型 情景选择题
  742. bankMap.put("QUESTION_CLASSIFY", classify);
  743. bankMap.put("QUESTION_VERSION_ID", versionId);
  744. bankList.add(bankMap);
  745. }
  746. /*****************************存储子表数据(题目答案)*******************************/
  747. if("3".equals(questionType)){//判断题
  748. Map<String,String> map1 = new HashMap<String, String>();
  749. Map<String,String> map2 = new HashMap<String, String>();
  750. map1.put("QUESTION_ID",idMap.get(fd_id));
  751. map1.put("OPTION","A");
  752. map1.put("OPTION_CONTENT","正确");
  753. map1.put("OPTION_INDEX","");
  754. bankSubList.add(map1);
  755. map2.put("QUESTION_ID",idMap.get(fd_id));
  756. map2.put("OPTION","B");
  757. map2.put("OPTION_CONTENT","错误");
  758. map2.put("OPTION_INDEX","");
  759. bankSubList.add(map2);
  760. }
  761. //情景、单选、多选
  762. if(!("".equals(answer1)||"/".equals(answer1))){
  763. Map<String,String> bankSubMap = new HashMap<String, String>();
  764. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  765. bankSubMap.put("QUESTION_ID", fdid);
  766. bankSubMap.put("OPTION","A");
  767. bankSubMap.put("OPTION_CONTENT",answer1);
  768. bankSubMap.put("OPTION_INDEX",String.valueOf(count));
  769. }else{
  770. bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
  771. bankSubMap.put("OPTION","A");
  772. bankSubMap.put("OPTION_CONTENT",answer1);
  773. bankSubMap.put("OPTION_INDEX","");
  774. }
  775. bankSubList.add(bankSubMap);
  776. }
  777. if(!("".equals(answer2)||"/".equals(answer2))){
  778. Map<String,String> bankSubMap = new HashMap<String, String>();
  779. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  780. bankSubMap.put("QUESTION_ID", fdid);
  781. bankSubMap.put("OPTION","B");
  782. bankSubMap.put("OPTION_CONTENT",answer2);
  783. bankSubMap.put("OPTION_INDEX",String.valueOf(count));
  784. }else{
  785. bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
  786. bankSubMap.put("OPTION","B");
  787. bankSubMap.put("OPTION_CONTENT",answer2);
  788. bankSubMap.put("OPTION_INDEX","");
  789. }
  790. bankSubList.add(bankSubMap);
  791. }
  792. if(!("".equals(answer3)||"/".equals(answer3))){
  793. Map<String,String> bankSubMap = new HashMap<String, String>();
  794. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  795. bankSubMap.put("QUESTION_ID", fdid);
  796. bankSubMap.put("OPTION","C");
  797. bankSubMap.put("OPTION_CONTENT",answer3);
  798. bankSubMap.put("OPTION_INDEX",String.valueOf(count));
  799. }else{
  800. bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
  801. bankSubMap.put("OPTION","C");
  802. bankSubMap.put("OPTION_CONTENT",answer3);
  803. bankSubMap.put("OPTION_INDEX","");
  804. }
  805. bankSubList.add(bankSubMap);
  806. }
  807. if(!("".equals(answer4)||"/".equals(answer4))){
  808. Map<String,String> bankSubMap = new HashMap<String, String>();
  809. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  810. bankSubMap.put("QUESTION_ID", fdid);
  811. bankSubMap.put("OPTION","D");
  812. bankSubMap.put("OPTION_CONTENT",answer4);
  813. bankSubMap.put("OPTION_INDEX",String.valueOf(count));
  814. }else{
  815. bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
  816. bankSubMap.put("OPTION","D");
  817. bankSubMap.put("OPTION_CONTENT",answer4);
  818. bankSubMap.put("OPTION_INDEX","");
  819. }
  820. bankSubList.add(bankSubMap);
  821. }
  822. if(!("".equals(answer5)||"/".equals(answer5))){
  823. Map<String,String> bankSubMap = new HashMap<String, String>();
  824. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  825. bankSubMap.put("QUESTION_ID", fdid);
  826. bankSubMap.put("OPTION","E");
  827. bankSubMap.put("OPTION_CONTENT",answer5);
  828. bankSubMap.put("OPTION_INDEX",String.valueOf(count));
  829. }else{
  830. bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
  831. bankSubMap.put("OPTION","E");
  832. bankSubMap.put("OPTION_CONTENT",answer5);
  833. bankSubMap.put("OPTION_INDEX","");
  834. }
  835. bankSubList.add(bankSubMap);
  836. }
  837. if(!("".equals(answer6)||"/".equals(answer6))){
  838. Map<String,String> bankSubMap = new HashMap<String, String>();
  839. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  840. bankSubMap.put("QUESTION_ID", fdid);
  841. bankSubMap.put("OPTION","F");
  842. bankSubMap.put("OPTION_CONTENT",answer6);
  843. bankSubMap.put("OPTION_INDEX",String.valueOf(count));
  844. }else{
  845. bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
  846. bankSubMap.put("OPTION","F");
  847. bankSubMap.put("OPTION_CONTENT",answer6);
  848. bankSubMap.put("OPTION_INDEX","");
  849. }
  850. bankSubList.add(bankSubMap);
  851. }
  852. if(!("".equals(answer7)||"/".equals(answer7))){
  853. Map<String,String> bankSubMap = new HashMap<String, String>();
  854. if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
  855. bankSubMap.put("QUESTION_ID", fdid);
  856. bankSubMap.put("OPTION","G");
  857. bankSubMap.put("OPTION_CONTENT",answer7);
  858. bankSubMap.put("OPTION_INDEX",String.valueOf(count));
  859. }else{
  860. bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
  861. bankSubMap.put("OPTION","G");
  862. bankSubMap.put("OPTION_CONTENT",answer7);
  863. bankSubMap.put("OPTION_INDEX","");
  864. }
  865. bankSubList.add(bankSubMap);
  866. }
  867. }
  868. Boolean questionResult = false;
  869. Boolean questionSubResult = false;
  870. try {
  871. questionResult = dao.saveQuestionByexcel(bankList);
  872. if(Boolean.TRUE.equals(questionResult)){
  873. questionSubResult = dao.saveQuestionSub(bankSubList);
  874. }
  875. } catch (SQLException e) {
  876. // TODO Auto-generated catch block
  877. e.printStackTrace();
  878. }
  879. return "[{\"questionResult\":\""+questionResult+"\",\"questionSubResult\":\""+questionSubResult+"\"}]";
  880. }
  881. /**
  882. * 获取题目版本号树
  883. * @param params
  884. * @return
  885. */
  886. @POST
  887. @ProduceMime("application/json")
  888. @Path("/getVersionTree/")
  889. public String getVersionTree(String params){
  890. String result = "";
  891. ExamineManagementDao dao = new ExamineManagementDao();
  892. try {
  893. result = dao.getVersionTree();
  894. } catch (Exception e) {
  895. // TODO Auto-generated catch block
  896. e.printStackTrace();
  897. }
  898. return result;
  899. }
  900. /**
  901. * 改变启用状态
  902. * @param params
  903. * @return
  904. */
  905. @POST
  906. @ProduceMime("application/json")
  907. @Path("/changeEnableState/")
  908. public int changeEnableState(String params){
  909. int result = 0;
  910. String versionId = Utils.getParameter("versionId", params) == null ? "" : Utils
  911. .getParameter("versionId", params);
  912. ExamineManagementDao dao = new ExamineManagementDao();
  913. try {
  914. result = dao.changeEnableState(versionId);
  915. } catch (Exception e) {
  916. // TODO Auto-generated catch block
  917. e.printStackTrace();
  918. }
  919. return result;
  920. }
  921. /**
  922. * 获取应急知识测试入口图标(无角色时)
  923. * @return
  924. */
  925. @POST
  926. @ProduceMime("application/json")
  927. @Path("/getMenuIcon/")
  928. public String getMenuIcon(){
  929. String result = "";
  930. ExamineManagementDao dao = new ExamineManagementDao();
  931. try {
  932. result = dao.getMenuIcon();
  933. } catch (Exception e) {
  934. // TODO Auto-generated catch block
  935. e.printStackTrace();
  936. }
  937. return result;
  938. }
  939. /**
  940. * 获取分类角色
  941. * @return
  942. */
  943. @POST
  944. @ProduceMime("application/json")
  945. @Path("/getClassifyRole/")
  946. public String getClassifyRole(String params){
  947. String result = "";
  948. String applicate = Utils.getParameter("applicate", params) == null ? "" : Utils.getParameter("applicate", params);
  949. ExamineManagementDao dao = new ExamineManagementDao();
  950. try {
  951. result = dao.getClassifyRole(applicate);
  952. } catch (Exception e) {
  953. // TODO Auto-generated catch block
  954. e.printStackTrace();
  955. }
  956. return result;
  957. }
  958. /**
  959. * 获取所属二级单位
  960. * @return
  961. */
  962. @POST
  963. @ProduceMime("application/text")
  964. @Path("/getCorpId/")
  965. public String getCorpId(String params){
  966. String result = "";
  967. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
  968. ExamineManagementDao dao = new ExamineManagementDao();
  969. try {
  970. result = dao.getCorpId(deptId);
  971. } catch (Exception e) {
  972. // TODO Auto-generated catch block
  973. e.printStackTrace();
  974. }
  975. return result;
  976. }
  977. /**
  978. * 获取正确和错误题目号
  979. * @param params
  980. * @return
  981. */
  982. @POST
  983. @ProduceMime("application/text")
  984. @Path("/getAnswerQuestionIndex/")
  985. public String getAnswerQuestionIndex(String params){
  986. String result = "";
  987. String fdid = Utils.getParameter("fdid", params) == null ? "" : Utils.getParameter("fdid", params);
  988. ExamineManagementDao dao = new ExamineManagementDao();
  989. try {
  990. result = dao.getAnswerQuestionIndex(fdid);
  991. } catch (Exception e) {
  992. // TODO Auto-generated catch block
  993. e.printStackTrace();
  994. }
  995. return result;
  996. }
  997. /**
  998. * 导出错误排行榜
  999. * @param params
  1000. * @return
  1001. * @throws SQLException
  1002. */
  1003. @ProduceMime("application/json")
  1004. @POST
  1005. @Path("/ExportExcelByMistake")
  1006. public String ExportExcelByMistake(String params) throws SQLException {
  1007. HttpServletRequest req = mc.getHttpServletRequest();
  1008. String fileName = UUID.randomUUID().toString() + ".xlsx";
  1009. String filePath = req.getRealPath("excels");
  1010. log.info("params:" + params);
  1011. String place = Utils.getParameter("place", params) == null ? "" : Utils.getParameter("place", params);
  1012. ExamineManagementDao dao = new ExamineManagementDao();
  1013. List<Map<String, String>> list = dao.getQuestionByMistake(place);//获取数据
  1014. List<String> headerList = new ArrayList<String>(); // 表格Titile
  1015. List<String> keyList = new ArrayList<String>(); // 表格key
  1016. List<Integer> widthList = new ArrayList<Integer>(); // 列宽
  1017. if(!list.isEmpty()){
  1018. //表头
  1019. headerList.add("题目名称");
  1020. keyList.add("QUESTION_NAME");
  1021. widthList.add(15000);
  1022. headerList.add("题目类型");
  1023. keyList.add("QUESTION_TYPE");
  1024. widthList.add(5000);
  1025. headerList.add("题目使用次数");
  1026. keyList.add("ANSWERSUM");
  1027. widthList.add(5000);
  1028. headerList.add("题目错误率");
  1029. keyList.add("SCALE");
  1030. widthList.add(5000);
  1031. //创建表头
  1032. ExportExcelUtils tableExcel = new ExportExcelUtils("题目错误率排行榜",headerList);
  1033. for(int i=0;i<list.size();i++){
  1034. Row row = tableExcel.addRow();
  1035. for (int j = 0; j <headerList.size(); j++) {
  1036. String value = list.get(i).get(keyList.get(j));
  1037. if(keyList.get(j).contains("QUESTION_TYPE")){//题目类型
  1038. if("1".equals(value)){
  1039. value = "单选题";
  1040. }
  1041. if("2".equals(value)){
  1042. value = "多选题";
  1043. }
  1044. if("3".equals(value)){
  1045. value = "判断题";
  1046. }
  1047. if("4".equals(value)){
  1048. value = "情景选择题";
  1049. }
  1050. }
  1051. if(keyList.get(j).contains("SCALE")){//题目错误率
  1052. value = new BigDecimal(Double.valueOf(value)*100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()+"%";
  1053. }
  1054. if(keyList.get(j).contains("QUESTION_NAME")){
  1055. tableExcel.addCell(row, j, value);//靠左显示
  1056. }else{
  1057. tableExcel.addCell(row, j, value, 2, Class.class);//居中显示
  1058. }
  1059. /*if(keyList.get(j).contains("standards"))
  1060. value = EvalUtils.replaceToHuanHang(value, "\\|standards\\|");
  1061. if(keyList.get(j).contains("questions"))
  1062. value = EvalUtils.replaceToHuanHang(value, "\\|questions\\|");
  1063. if(keyList.get(j).contains("suggestions"))
  1064. value = EvalUtils.replaceToHuanHang(value, "\\|suggestions\\|");
  1065. if("SCORE".equals(keyList.get(j)))
  1066. value = EvalUtils.formatXiaoShu(value);
  1067. if("OBJ_STRIPE|NAME|STA_SCORE|SCORE|CHECK_INSTRUCTION|".contains(keyList.get(j)+"|")){
  1068. ee.addCell(row, j, value, 2, Class.class);//居中显示
  1069. }else{
  1070. ee.addCell(row, j, value);//靠左显示
  1071. }*/
  1072. }
  1073. }
  1074. //设置列宽
  1075. for(int i=0;i<widthList.size();i++){
  1076. tableExcel.setColumnWidth(i, widthList.get(i));
  1077. }
  1078. try {
  1079. FileOutputStream out = new FileOutputStream(filePath + File.separator + fileName);
  1080. tableExcel.write(out);
  1081. } catch (Exception e) {
  1082. // TODO Auto-generated catch block
  1083. e.printStackTrace();
  1084. }
  1085. }
  1086. return fileName;
  1087. }
  1088. /**
  1089. * 导出统计分值
  1090. * @param params
  1091. * @return
  1092. * @throws SQLException
  1093. */
  1094. @ProduceMime("application/json")
  1095. @POST
  1096. @Path("/ExportExcelByStatic")
  1097. public String ExportExcelByStatic(String params) throws SQLException {
  1098. HttpServletRequest req = mc.getHttpServletRequest();
  1099. String fileName = UUID.randomUUID().toString() + ".xlsx";
  1100. String filePath = req.getRealPath("excels");
  1101. log.info("params:" + params);
  1102. String task_id = Utils.getParameter("taskId", params)==null?"":Utils.getParameter("taskId", params);//任务id
  1103. String role_id = Utils.getParameter("roleId", params)==null?"":Utils.getParameter("roleId", params);//角色id
  1104. String dept_id = Utils.getParameter("deptId", params)==null?"":Utils.getParameter("deptId", params);//单位id
  1105. ExamineManagementDao dao = new ExamineManagementDao();
  1106. String[] role_ids = role_id.split(",");
  1107. String[] dept_ids = dept_id.split(",");
  1108. List<Map<String,Object>> columnHead = dao.getTableHead(role_ids);//表头数据
  1109. List<Map<String,Object>> data = dao.staticsScoreByUnit(task_id,dept_ids,role_ids);//表格数据
  1110. List<String> headerList = new ArrayList<String>(); // 表格Titile
  1111. List<String> keyList = new ArrayList<String>(); // 表格key
  1112. List<Integer> widthList = new ArrayList<Integer>(); // 列宽
  1113. if(!columnHead.isEmpty()){
  1114. //表头
  1115. headerList.add("单位");
  1116. keyList.add("COMP_NAME");
  1117. widthList.add(6000);
  1118. for(int i=1;i<columnHead.size();i++){
  1119. Map<String,Object> map = columnHead.get(i);
  1120. //String role_name = (String) map.get("display");//角色名称
  1121. List<Map<String,Object>> columns = (List<Map<String, Object>>) map.get("columns");//列名
  1122. for(int j=0;j<columns.size();j++){
  1123. Map<String,Object> columnMap = columns.get(j);
  1124. String column_id = (String)columnMap.get("name");//列id
  1125. String column_name = (String)columnMap.get("display");//列名称
  1126. //表头
  1127. headerList.add(column_name);
  1128. keyList.add(column_id);
  1129. widthList.add(4000);
  1130. }
  1131. }
  1132. //创建表头
  1133. ExportExcelUtils tableExcel = new ExportExcelUtils("统计分值",headerList);
  1134. tableExcel.addHeader(headerList);
  1135. int num = 0;//记录第几个角色
  1136. for(int i=1;i<columnHead.size();i++){
  1137. int startcol = (num*3)+1;//开始列
  1138. Map<String,Object> map = columnHead.get(i);
  1139. String role_name = (String) map.get("display");//角色名称
  1140. tableExcel.getRow(1).getCell(startcol).setCellValue(role_name);
  1141. tableExcel.mergeCol(1, startcol, startcol+2);//合并列
  1142. num++;
  1143. }
  1144. tableExcel.mergeRow(1, 2, 0);//合并单位行
  1145. //表数据
  1146. for(int i=0;i<data.size();i++){
  1147. Row row = tableExcel.addRow();
  1148. for (int j = 0; j <headerList.size(); j++) {
  1149. Map<String,Object> map = data.get(i);
  1150. String value = map.get(keyList.get(j)).toString();
  1151. if(keyList.get(j).contains("PARTAKE_NUM_")){
  1152. tableExcel.addCell(row, j, new BigDecimal(value).intValue(), 2, Class.class);
  1153. }else if(keyList.get(j).contains("COMP_NAME")){
  1154. tableExcel.addCell(row, j, value, 2, Class.class);
  1155. }else{
  1156. tableExcel.addCell(row, j, Double.valueOf(value), 2, Class.class);
  1157. }
  1158. }
  1159. }
  1160. //设置列宽
  1161. for(int i=0;i<widthList.size();i++){
  1162. tableExcel.setColumnWidth(i, widthList.get(i));
  1163. }
  1164. try {
  1165. FileOutputStream out = new FileOutputStream(filePath + File.separator + fileName);
  1166. tableExcel.write(out);
  1167. } catch (Exception e) {
  1168. // TODO Auto-generated catch block
  1169. e.printStackTrace();
  1170. }
  1171. }
  1172. return fileName;
  1173. }
  1174. }