1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306 |
- package com.sinosoft.exercise.examine.service;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.math.BigDecimal;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import javax.ws.rs.core.Context;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- import org.apache.log4j.Logger;
- import org.apache.poi.ss.usermodel.Row;
- import com.formaction.Utils;
- import com.persistence.service.assitant.generator.IdentityGenerator;
- import com.sinosoft.common.excel.JsonPluginsUtil;
- import com.sinosoft.common.upLoad.util.SmartUpload;
- import com.sinosoft.common.util.FilePathUtil;
- import com.sinosoft.em.alert.report.manage.service.QueryReportProgrammeServiceImpl;
- import com.sinosoft.em.evaluate.excel.ExportExcelUtils;
- import com.sinosoft.exercise.examine.dao.ExamineManagementDao;
- import com.sinosoft.exercise.examine.dao.ImportExcelDao;
- import com.sinosoft.lz.system.util.JsonUtil;
- @Path("/ExamineManagementService/")
- public class ExamineManagementServer {
- @Context
- private org.apache.cxf.jaxrs.ext.MessageContext mc;
-
- private final static Logger log = Logger.getLogger(QueryReportProgrammeServiceImpl.class);
-
- /**
- * 通过题库主表主键查询对应的副表数据,也就是选项内容
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getDataByQuestionID/")
- public String getDataByQuestionID(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- String question_id=Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getDataByQuestionID(question_id);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 保存考生填写的答案与题号等记录到考试记录子表
- * @param params
- * @return
- */
- @POST
- @ProduceMime("text/html")
- @Path("/saveExamineeAnswer/")
- public String saveExamineeAnswer(String params){
- String scoresId=Utils.getParameter("scoresId", params)==null?"":Utils.getParameter("scoresId", params);
- String userId=Utils.getParameter("userId", params)==null?"":Utils.getParameter("userId", params);
- String userAnswer=Utils.getParameter("userAnswer", params)==null?"":Utils.getParameter("userAnswer", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- dao.saveExamineeAnswer(scoresId,userId,userAnswer);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return "";
- }
-
- /**
- * 从题库中随机抽取20道题目
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getQuestionPaperForRandom/")
- public String getQuestionPaperForRandom(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
-
- String questionNum = Utils.getParameter("questionNum", params)==null?"":Utils.getParameter("questionNum", params);//题数
- String unitId = Utils.getParameter("unitId", params)==null?"":Utils.getParameter("unitId", params);//单位id
- String roleId = Utils.getParameter("roleId", params)==null?"":Utils.getParameter("roleId", params);//角色id
-
- ExamineManagementDao dao = new ExamineManagementDao();
- String[] num = {};
- if(!"".equals(questionNum)){
- num = questionNum.split(",");
- }
- String[] roleIds = {};
- if(!"".equals(roleId)){
- roleIds = roleId.split(",");
- }
- try {
- list = dao.getQuestionPaperForRandom(num,unitId,roleIds);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 获取考生考试信息与题目信息,用于考卷查看页面
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getQuestionPaperDetail/")
- public String getQuestionPaperDetail(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- String fd_id=Utils.getParameter("fd_id", params)==null?"":Utils.getParameter("fd_id", params);//题数
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getQuestionPaperDetail(fd_id);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 获取答案
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getAnswerNum/")
- public String getAnswerNum(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- String question_id=Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getAnswerNum(question_id);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
-
- /**
- * 删除模板中的题目
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/delTemplateQuestion/")
- public int delTemplateQuestion(String params){
- int result = 0;
- String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
- String question_id=Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.delTemplateQuestion(template_id,question_id);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 删除模板
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/delTemplate/")
- public int delTemplate(String params){
- int result = 0;
- String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.delTemplate(template_id);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 增加使用模板次数
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/addTemplateNumber/")
- public int addTemplateNumber(String params){
- int result = 0;
- String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.addTemplateNumber(template_id);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 绑定模板
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/bindTemplate/")
- public boolean bindTemplate(String params){
- Boolean result = false;
- String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
- String ids=Utils.getParameter("ids", params)==null?"":Utils.getParameter("ids", params);
- if(ids.isEmpty()){
- return result;
- }
- String[] id = ids.split(",");
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.bindTemplate(template_id,id);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 通过模板id获取题型数量
- * @param tempId
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getQuestionTypeByTemplate/")
- public String getQuestionTypeByTemplate(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- String templateId = Utils.getParameter("templateId", params)==null?"":Utils.getParameter("templateId", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getQuestionTypeByTemplate(templateId);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 获取当前模板是否在执行任务
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getTaskByTemplate/")
- public String getTaskByTemplate(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- String template_id=Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getTaskByTemplate(template_id);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 获取考试时间
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getQuestionTime/")
- public String getQuestionTime(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- String unitId=Utils.getParameter("unitId", params)==null?"":Utils.getParameter("unitId", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getQuestionTime(unitId);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 根据模板从题库中提取题目
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getQuestionByTemplate/")
- public String getQuestionByTemplate(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
-
- String template_id = Utils.getParameter("template_id", params)==null?"":Utils.getParameter("template_id", params);//题数
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getQuestionByTemplate(template_id);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 获取每一个分段人数,可按单位进行筛选 (图表)
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getScoreCountByUnit/")
- public String getScoreCountByUnit(String params){
- String result = "";
-
- String dept_ids = Utils.getParameter("dept_id", params)==null?"":Utils.getParameter("dept_id", params);//单位id
- String task_id = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);//任务id
- ExamineManagementDao dao = new ExamineManagementDao();
- String[] ids = dept_ids.split(",");
- if("".equals(task_id)||"".equals(dept_ids)){
- return "{\"title\":\"考试用户人数\",\"legend_data\":[\"\"],\"xAxis_data\":[\"\"]}";
- }
- try {
- result = dao.getScoreCountByUnit(ids,task_id);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
-
- }
-
- /**
- * 获取单位平均得分(图表)
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getAvgScoreByUnit/")
- public String getAvgScoreByUnit(String params){
- String result = "";
-
- String dept_ids = Utils.getParameter("dept_id", params)==null?"":Utils.getParameter("dept_id", params);//单位id
- String task_id = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);//任务id
- ExamineManagementDao dao = new ExamineManagementDao();
- String[] ids = dept_ids.split(",");
- if("".equals(task_id)||"".equals(dept_ids)){
- return "{\"title\":\"单位平均分\",\"legend_data\":[\"\"],\"xAxis_data\":[\"\"]}";
- }
- try {
- result = dao.getAvgScoreByUnit(ids,task_id);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 查询用户是否完成考试
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getQuestionByUserId/")
- public String getQuestionByUserId(String params){
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- String user_id = Utils.getParameter("user_id", params)==null?"":Utils.getParameter("user_id", params);
- String task_ids = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);
- if(task_ids.isEmpty()){
- return "[]";
- }
- String[] ids = task_ids.split(",");
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- list = dao.getQuestionByUserId(user_id,ids);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(list).toString();
- }
-
- /**
- * 查询当前题目在使用的数量
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getSumByquestionId/")
- public String getSumByquestionId(String params){
- Map<String, String> map = new HashMap<String, String>();
- String question_id = Utils.getParameter("question_id", params)==null?"":Utils.getParameter("question_id", params);//题目Id
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- map = dao.getSumByquestionId(question_id);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONObject.fromObject(map).toString();
- }
-
- /**
- * 获取表头
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getTableHead/")
- public String getTableHead(String params){
- List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
-
- String role_id = Utils.getParameter("role_id", params)==null?"":Utils.getParameter("role_id", params);//角色id
- ExamineManagementDao dao = new ExamineManagementDao();
- if("".equals(role_id)){
- return "";
- }
- String[] role_ids = role_id.split(",");
- try {
- result = dao.getTableHead(role_ids);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return "[{\"display\":\"统计表\",\"columns\":"+JSONArray.fromObject(result)+"}]";
- }
-
- /**
- * 获取数据
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/staticsScoreByUnit/")
- public String staticsScoreByUnit(String params){
- List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
-
- String task_id = Utils.getParameter("task_id", params)==null?"":Utils.getParameter("task_id", params);//任务id
- String dept_id = Utils.getParameter("dept_id", params)==null?"":Utils.getParameter("dept_id", params);//单位id
- String role_id = Utils.getParameter("role_id", params)==null?"":Utils.getParameter("role_id", params);//角色id
- ExamineManagementDao dao = new ExamineManagementDao();
- if("".equals(role_id)||"".equals(dept_id)||"".equals(task_id)){
- return "";
- }
- String[] role_ids = role_id.split(",");
- String[] dept_ids = dept_id.split(",");
- try {
- result = dao.staticsScoreByUnit(task_id,dept_ids,role_ids);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return "{\"rows\":"+JSONArray.fromObject(result)+"}";
- }
-
- @POST
- @ProduceMime("application/json")
- @Path("/getRole/")
- public String getRole(){
- String result = "";
-
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.getRole();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 通用左侧树专用
- * 查询出到县区级的单位
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getAllUnitTree")
- public String getAllUnitTree(String params){
-
- String dept_ids = Utils.getParameter("dept_ids", params) == null ? "" : Utils.getParameter("dept_ids", params);
- String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- String unitData = dao.getUnitMsgByCon("4",id,dept_ids);//获取所有单位数据
- StringBuffer sb = new StringBuffer();
- sb.append("{\"treeNodes\":");
- sb.append(unitData);
- sb.append("}");
- return sb.toString();
- }
-
- /**
- * 题目错误率排行榜
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getQuestionByMistake/")
- public String getQuestionByMistake(String params){
-
- String place = Utils.getParameter("place", params) == null ? "" : Utils.getParameter("place", params);//前几名
-
- List<Map<String, String>> list = new ArrayList<Map<String,String>>();
- ExamineManagementDao dao = new ExamineManagementDao();
-
- if("".equals(place)){
- return "{\"rows\":\"\"}";
- }
-
- try {
- list = dao.getQuestionByMistake(place);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return "{\"rows\":" +JSONArray.fromObject(list).toString()+ "}";
- }
-
- /**
- * 导入excel
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getExcelToList")
- public String getExcelToList(@Context HttpServletRequest request, @Context HttpServletResponse response){
- String fileExt = request.getParameter("fileExt");
- SmartUpload upload = new SmartUpload();
- upload.initialize(request, response, request.getSession().getServletContext());
- String filePath = "";
- try {
- String uploadPath = FilePathUtil.getUploadPath();
- log.info("路径===:"+uploadPath);
- int currentTotalSize = request.getContentLength();
- log.info("当前上传的附件总大小为-----" + currentTotalSize);
- if (currentTotalSize < 40 * 1024 * 1024) {
- upload.service(request, response);
- upload.setMaxFileSize(100 * 1024 * 1024);
- upload.setTotalMaxFileSize(400 * 1024 * 1024);
- upload.upload();
- com.sinosoft.common.upLoad.util.File file = upload.getFiles().getFile(0);
- String saveName = UUID.randomUUID().toString();
- filePath = uploadPath+File.separator+saveName+"."+fileExt;
- file.saveAs(filePath);
- }
-
- } catch (Exception e1) {
- e1.printStackTrace();
- }
-
-
- List<Map<String, String>> excelData = new ArrayList<Map<String, String>>();
- ImportExcelDao importExcelDao = new ImportExcelDao();
- try {
- excelData = importExcelDao.readInnerExcel(filePath);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return "[{\"result\":"+JsonUtil.list2json(excelData)+"}]";
- }
-
-
- /**
- * 保存excel数据
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/saveQuestion")
- public String saveQuestion(String params) {
- ExamineManagementDao dao = new ExamineManagementDao();
-
- String userName = Utils.getParameter("userName", params) == null ? "" : Utils
- .getParameter("userName", params);
-
- String userId = Utils.getParameter("userId", params) == null ? "" : Utils
- .getParameter("userId", params);
- String userUnit = Utils.getParameter("userUnit", params) == null ? "" : Utils
- .getParameter("userUnit", params);
-
- String userDept = Utils.getParameter("userDept", params) == null ? "" : Utils
- .getParameter("userDept", params);
-
- String versionId = Utils.getParameter("versionId", params) == null ? "" : Utils
- .getParameter("versionId", params);
-
- String data = Utils.getParameter("data", params) == null ? "" : Utils
- .getParameter("data", params);
- List<Map<String, String>> dataList = JsonPluginsUtil.jsonToMapList(data);
- List<Map<String, String>> bankList = new ArrayList<Map<String,String>>();//存储主表数据
- List<Map<String, String>> bankSubList = new ArrayList<Map<String,String>>();//存储子表数据
-
- Map<String,String> idMap = new HashMap<String, String>();//存储id
- Map<String,String> classifyMap = new HashMap<String, String>();//题目类别
- Map<String,String> typeMap = new HashMap<String, String>();//题目类型
- try {
- classifyMap = dao.getQuestionClassify("BM_ECM_TRAIN_EXAMINE_QUESTION_CLASSIFY");
- typeMap = dao.getQuestionClassify("BM_ECM_TRAIN_EXAMINE_QUESTION_TYPE");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- int count = 0;//记录情景选择题个数
- String fdid = "";//记录情景选择题id
- Map<String,String> type4Map = new HashMap<String, String>();//储存情景选择题主表数据
- //String fd_id = IdentityGenerator.getIdentityGenerator().gerenalIdentity(603);
- for(int i=0;i<dataList.size();i++){
- Map<String,String> map = dataList.get(i);
-
- Map<String,String> bankMap = new HashMap<String, String>();//存主表数据
-
-
- String fd_id = map.get("FD_ID");
- String classify = classifyMap.get(map.get("QUESTION_CLASSIFY"));//专业类别
- String content = map.get("EXAMINATION_CONTENT");//内容来源
- String applicable1 = map.get("APPLICABLE_OBJECT_1");
- String applicable2 = map.get("APPLICABLE_OBJECT_2");
- String applicable3 = map.get("APPLICABLE_OBJECT_3");
- String applicable4 = map.get("APPLICABLE_OBJECT_4");
- String applicable = "";
- if(!("".equals(applicable1)||"/".equals(applicable1))){
- applicable += "1,";
- }
- if(!("".equals(applicable2)||"/".equals(applicable2))){
- applicable += "2,";
- }
- if(!("".equals(applicable3)||"/".equals(applicable3))){
- applicable += "3,";
- }
- if(!("".equals(applicable4)||"/".equals(applicable4))){
- applicable += "4,";
- }
- if(applicable.length()>1){
- applicable = applicable.substring(0, applicable.length()-1);
- }
- String questionType = typeMap.get(map.get("QUESTION_TYPE"));//题目类型
- String questionName = map.get("QUESTION_NAME");//题目名称
- String answer1 = map.get("ANSWER_A");
- String answer2 = map.get("ANSWER_B");
- String answer3 = map.get("ANSWER_C");
- String answer4 = map.get("ANSWER_D");
- String answer5 = map.get("ANSWER_E");
- String answer6 = map.get("ANSWER_F");
- String answer7 = map.get("ANSWER_G");
- String questionAnswer = map.get("QUESTION_ANSWER").trim();
-
- if(!"".equals(questionType)&&!"".equals(questionName)){
- count = 0;//记录情景选择题个数
- fdid = "";//记录情景选择题id
- type4Map = new HashMap<String, String>();//储存情景选择题主表数据
- String genrenalId = IdentityGenerator.getIdentityGenerator().gerenalIdentity(603);
- idMap.put(fd_id, genrenalId);
- }
-
- if(!"3".equals(questionType)&&("".equals(answer1)||"/".equals(answer1))){
- continue;
- }
- /************储存主表数据(题目)**************/
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- if(count ==0){
- count++;
- fdid = idMap.get(fd_id);
- type4Map.put("FD_ID", fdid);
- type4Map.put("INPUT_NAME", userName);
- type4Map.put("INPUT_NAME_ID", userId);
- type4Map.put("INPUT_PERSON_UNIT", userUnit);
- type4Map.put("INPUT_PERSON_DEPT", userDept);
- type4Map.put("QUESTION_NAME", questionName);
- type4Map.put("QUESTION_TYPE", questionType);
- type4Map.put("EXAMINATION_CONTENT", content);
- type4Map.put("APPLICABLE_OBJECT", applicable);
- type4Map.put("ANSWER_TYPE", "1");
- if(questionAnswer.length()>1){
- type4Map.put("ANSWER_OPTION", "2");//答案类型 情景选择题
- String answer = "";
- for(int j=0;j<questionAnswer.length();j++){//将字符串ABCD转为A,B,C,D
- answer += questionAnswer.charAt(j)+",";
- }
- answer = answer.substring(0, answer.length()-1);
- type4Map.put("QUESTION_ANSWER", answer);//答案:情景选择题-多个答案
- }else{
- type4Map.put("ANSWER_OPTION", "1");
- type4Map.put("QUESTION_ANSWER", questionAnswer);
- }
-
- type4Map.put("QUESTION_CLASSIFY", classify);
- type4Map.put("QUESTION_VERSION_ID", versionId);
- }else if(count ==3){
- String question_answer = type4Map.get("QUESTION_ANSWER");
- String answer_option = type4Map.get("ANSWER_OPTION");
- if(questionAnswer.length()>1){
- String answer = "";
- for(int j=0;j<questionAnswer.length();j++){//将字符串ABCD转为A,B,C,D
- answer += questionAnswer.charAt(j)+",";
- }
- answer = answer.substring(0, answer.length()-1);
- question_answer += "|"+answer;
- answer_option +="|2";
- type4Map.put("QUESTION_ANSWER", question_answer);
- type4Map.put("ANSWER_OPTION", answer_option);
- }else{
- question_answer += "|"+questionAnswer;
- answer_option +="|1";
- type4Map.put("QUESTION_ANSWER", question_answer);
- type4Map.put("ANSWER_OPTION", answer_option);
- }
- bankList.add(type4Map);
- count++;
- }else{
- String question_answer = type4Map.get("QUESTION_ANSWER");
- String answer_option = type4Map.get("ANSWER_OPTION");
- if(questionAnswer.length()>1){
- String answer = "";
- for(int j=0;j<questionAnswer.length();j++){//将字符串ABCD转为A,B,C,D
- answer += questionAnswer.charAt(j)+",";
- }
- answer = answer.substring(0, answer.length()-1);
- question_answer += "|"+answer;
- answer_option +="|2";
- type4Map.put("QUESTION_ANSWER", question_answer);
- type4Map.put("ANSWER_OPTION", answer_option);
- }else{
- question_answer += "|"+questionAnswer;
- answer_option +="|1";
- type4Map.put("QUESTION_ANSWER", question_answer);
- type4Map.put("ANSWER_OPTION", answer_option);
- }
- count++;
- }
-
- }
-
- if(!"4".equals(questionType)&&questionType!=null){//非情景选择题
-
- //将数据放入map
- bankMap.put("FD_ID", idMap.get(fd_id));
- bankMap.put("INPUT_NAME", userName);
- bankMap.put("INPUT_NAME_ID", userId);
- bankMap.put("INPUT_PERSON_UNIT", userUnit);
- bankMap.put("INPUT_PERSON_DEPT", userDept);
- bankMap.put("QUESTION_NAME", questionName);
- bankMap.put("QUESTION_TYPE", questionType);
- if("3".equals(questionType)){//判断题
- String answer = "";
- if("对".equals(questionAnswer)||"正确".equals(questionAnswer)){
- answer = "A";
- }
- if("错".equals(questionAnswer)||"错误".equals(questionAnswer)){
- answer = "B";
- }
- bankMap.put("QUESTION_ANSWER",answer);
-
- }else{
- String answer = "";
- for(int k=0;k<questionAnswer.length();k++){//将ABCD转化为A,B,C,D
- answer += questionAnswer.charAt(k)+",";
- }
- answer = answer.substring(0,answer.length()-1);
-
- bankMap.put("QUESTION_ANSWER", answer);//答案:情景选择题-多个答案
- }
-
- bankMap.put("EXAMINATION_CONTENT", content);
- bankMap.put("APPLICABLE_OBJECT", applicable);
- bankMap.put("ANSWER_TYPE", "1");
- bankMap.put("ANSWER_OPTION", "");//答案类型 情景选择题
- bankMap.put("QUESTION_CLASSIFY", classify);
- bankMap.put("QUESTION_VERSION_ID", versionId);
-
- bankList.add(bankMap);
- }
-
- /*****************************存储子表数据(题目答案)*******************************/
- if("3".equals(questionType)){//判断题
- Map<String,String> map1 = new HashMap<String, String>();
- Map<String,String> map2 = new HashMap<String, String>();
- map1.put("QUESTION_ID",idMap.get(fd_id));
- map1.put("OPTION","A");
- map1.put("OPTION_CONTENT","正确");
- map1.put("OPTION_INDEX","");
- bankSubList.add(map1);
- map2.put("QUESTION_ID",idMap.get(fd_id));
- map2.put("OPTION","B");
- map2.put("OPTION_CONTENT","错误");
- map2.put("OPTION_INDEX","");
- bankSubList.add(map2);
- }
-
- //情景、单选、多选
- if(!("".equals(answer1)||"/".equals(answer1))){
- Map<String,String> bankSubMap = new HashMap<String, String>();
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- bankSubMap.put("QUESTION_ID", fdid);
- bankSubMap.put("OPTION","A");
- bankSubMap.put("OPTION_CONTENT",answer1);
- bankSubMap.put("OPTION_INDEX",String.valueOf(count));
- }else{
- bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
- bankSubMap.put("OPTION","A");
- bankSubMap.put("OPTION_CONTENT",answer1);
- bankSubMap.put("OPTION_INDEX","");
- }
-
- bankSubList.add(bankSubMap);
- }
- if(!("".equals(answer2)||"/".equals(answer2))){
- Map<String,String> bankSubMap = new HashMap<String, String>();
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- bankSubMap.put("QUESTION_ID", fdid);
- bankSubMap.put("OPTION","B");
- bankSubMap.put("OPTION_CONTENT",answer2);
- bankSubMap.put("OPTION_INDEX",String.valueOf(count));
- }else{
- bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
- bankSubMap.put("OPTION","B");
- bankSubMap.put("OPTION_CONTENT",answer2);
- bankSubMap.put("OPTION_INDEX","");
- }
- bankSubList.add(bankSubMap);
- }
- if(!("".equals(answer3)||"/".equals(answer3))){
- Map<String,String> bankSubMap = new HashMap<String, String>();
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- bankSubMap.put("QUESTION_ID", fdid);
- bankSubMap.put("OPTION","C");
- bankSubMap.put("OPTION_CONTENT",answer3);
- bankSubMap.put("OPTION_INDEX",String.valueOf(count));
- }else{
- bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
- bankSubMap.put("OPTION","C");
- bankSubMap.put("OPTION_CONTENT",answer3);
- bankSubMap.put("OPTION_INDEX","");
- }
- bankSubList.add(bankSubMap);
- }
- if(!("".equals(answer4)||"/".equals(answer4))){
- Map<String,String> bankSubMap = new HashMap<String, String>();
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- bankSubMap.put("QUESTION_ID", fdid);
- bankSubMap.put("OPTION","D");
- bankSubMap.put("OPTION_CONTENT",answer4);
- bankSubMap.put("OPTION_INDEX",String.valueOf(count));
- }else{
- bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
- bankSubMap.put("OPTION","D");
- bankSubMap.put("OPTION_CONTENT",answer4);
- bankSubMap.put("OPTION_INDEX","");
- }
- bankSubList.add(bankSubMap);
- }
- if(!("".equals(answer5)||"/".equals(answer5))){
- Map<String,String> bankSubMap = new HashMap<String, String>();
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- bankSubMap.put("QUESTION_ID", fdid);
- bankSubMap.put("OPTION","E");
- bankSubMap.put("OPTION_CONTENT",answer5);
- bankSubMap.put("OPTION_INDEX",String.valueOf(count));
- }else{
- bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
- bankSubMap.put("OPTION","E");
- bankSubMap.put("OPTION_CONTENT",answer5);
- bankSubMap.put("OPTION_INDEX","");
- }
- bankSubList.add(bankSubMap);
- }
- if(!("".equals(answer6)||"/".equals(answer6))){
- Map<String,String> bankSubMap = new HashMap<String, String>();
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- bankSubMap.put("QUESTION_ID", fdid);
- bankSubMap.put("OPTION","F");
- bankSubMap.put("OPTION_CONTENT",answer6);
- bankSubMap.put("OPTION_INDEX",String.valueOf(count));
- }else{
- bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
- bankSubMap.put("OPTION","F");
- bankSubMap.put("OPTION_CONTENT",answer6);
- bankSubMap.put("OPTION_INDEX","");
- }
- bankSubList.add(bankSubMap);
- }
- if(!("".equals(answer7)||"/".equals(answer7))){
- Map<String,String> bankSubMap = new HashMap<String, String>();
- if("4".equals(questionType)||(questionType==null&&"".equals(questionName))){//情景选择题
- bankSubMap.put("QUESTION_ID", fdid);
- bankSubMap.put("OPTION","G");
- bankSubMap.put("OPTION_CONTENT",answer7);
- bankSubMap.put("OPTION_INDEX",String.valueOf(count));
- }else{
- bankSubMap.put("QUESTION_ID",idMap.get(fd_id));
- bankSubMap.put("OPTION","G");
- bankSubMap.put("OPTION_CONTENT",answer7);
- bankSubMap.put("OPTION_INDEX","");
- }
- bankSubList.add(bankSubMap);
- }
-
- }
- Boolean questionResult = false;
- Boolean questionSubResult = false;
- try {
- questionResult = dao.saveQuestionByexcel(bankList);
- if(Boolean.TRUE.equals(questionResult)){
- questionSubResult = dao.saveQuestionSub(bankSubList);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return "[{\"questionResult\":\""+questionResult+"\",\"questionSubResult\":\""+questionSubResult+"\"}]";
- }
-
-
- /**
- * 获取题目版本号树
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getVersionTree/")
- public String getVersionTree(String params){
- String result = "";
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.getVersionTree();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 改变启用状态
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/changeEnableState/")
- public int changeEnableState(String params){
- int result = 0;
- String versionId = Utils.getParameter("versionId", params) == null ? "" : Utils
- .getParameter("versionId", params);
-
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.changeEnableState(versionId);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 获取应急知识测试入口图标(无角色时)
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getMenuIcon/")
- public String getMenuIcon(){
- String result = "";
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.getMenuIcon();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 获取分类角色
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getClassifyRole/")
- public String getClassifyRole(String params){
- String result = "";
- String applicate = Utils.getParameter("applicate", params) == null ? "" : Utils.getParameter("applicate", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.getClassifyRole(applicate);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 获取所属二级单位
- * @return
- */
- @POST
- @ProduceMime("application/text")
- @Path("/getCorpId/")
- public String getCorpId(String params){
- String result = "";
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.getCorpId(deptId);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 获取正确和错误题目号
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/text")
- @Path("/getAnswerQuestionIndex/")
- public String getAnswerQuestionIndex(String params){
- String result = "";
- String fdid = Utils.getParameter("fdid", params) == null ? "" : Utils.getParameter("fdid", params);
- ExamineManagementDao dao = new ExamineManagementDao();
- try {
- result = dao.getAnswerQuestionIndex(fdid);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * 导出错误排行榜
- * @param params
- * @return
- * @throws SQLException
- */
- @ProduceMime("application/json")
- @POST
- @Path("/ExportExcelByMistake")
- public String ExportExcelByMistake(String params) throws SQLException {
-
- HttpServletRequest req = mc.getHttpServletRequest();
- String fileName = UUID.randomUUID().toString() + ".xlsx";
- String filePath = req.getRealPath("excels");
-
- log.info("params:" + params);
- String place = Utils.getParameter("place", params) == null ? "" : Utils.getParameter("place", params);
-
- ExamineManagementDao dao = new ExamineManagementDao();
- List<Map<String, String>> list = dao.getQuestionByMistake(place);//获取数据
-
- List<String> headerList = new ArrayList<String>(); // 表格Titile
- List<String> keyList = new ArrayList<String>(); // 表格key
- List<Integer> widthList = new ArrayList<Integer>(); // 列宽
-
-
- if(!list.isEmpty()){
-
- //表头
- headerList.add("题目名称");
- keyList.add("QUESTION_NAME");
- widthList.add(15000);
-
- headerList.add("题目类型");
- keyList.add("QUESTION_TYPE");
- widthList.add(5000);
-
- headerList.add("题目使用次数");
- keyList.add("ANSWERSUM");
- widthList.add(5000);
-
- headerList.add("题目错误率");
- keyList.add("SCALE");
- widthList.add(5000);
-
-
- //创建表头
- ExportExcelUtils tableExcel = new ExportExcelUtils("题目错误率排行榜",headerList);
- for(int i=0;i<list.size();i++){
- Row row = tableExcel.addRow();
- for (int j = 0; j <headerList.size(); j++) {
-
- String value = list.get(i).get(keyList.get(j));
-
- if(keyList.get(j).contains("QUESTION_TYPE")){//题目类型
- if("1".equals(value)){
- value = "单选题";
- }
- if("2".equals(value)){
- value = "多选题";
- }
- if("3".equals(value)){
- value = "判断题";
- }
- if("4".equals(value)){
- value = "情景选择题";
- }
- }
- if(keyList.get(j).contains("SCALE")){//题目错误率
- value = new BigDecimal(Double.valueOf(value)*100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()+"%";
- }
-
- if(keyList.get(j).contains("QUESTION_NAME")){
- tableExcel.addCell(row, j, value);//靠左显示
- }else{
- tableExcel.addCell(row, j, value, 2, Class.class);//居中显示
- }
-
-
- /*if(keyList.get(j).contains("standards"))
- value = EvalUtils.replaceToHuanHang(value, "\\|standards\\|");
- if(keyList.get(j).contains("questions"))
- value = EvalUtils.replaceToHuanHang(value, "\\|questions\\|");
- if(keyList.get(j).contains("suggestions"))
- value = EvalUtils.replaceToHuanHang(value, "\\|suggestions\\|");
- if("SCORE".equals(keyList.get(j)))
- value = EvalUtils.formatXiaoShu(value);
-
- if("OBJ_STRIPE|NAME|STA_SCORE|SCORE|CHECK_INSTRUCTION|".contains(keyList.get(j)+"|")){
- ee.addCell(row, j, value, 2, Class.class);//居中显示
- }else{
- ee.addCell(row, j, value);//靠左显示
- }*/
- }
- }
- //设置列宽
- for(int i=0;i<widthList.size();i++){
- tableExcel.setColumnWidth(i, widthList.get(i));
- }
-
- try {
- FileOutputStream out = new FileOutputStream(filePath + File.separator + fileName);
- tableExcel.write(out);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return fileName;
- }
-
- /**
- * 导出统计分值
- * @param params
- * @return
- * @throws SQLException
- */
- @ProduceMime("application/json")
- @POST
- @Path("/ExportExcelByStatic")
- public String ExportExcelByStatic(String params) throws SQLException {
-
- HttpServletRequest req = mc.getHttpServletRequest();
- String fileName = UUID.randomUUID().toString() + ".xlsx";
- String filePath = req.getRealPath("excels");
-
- log.info("params:" + params);
-
- String task_id = Utils.getParameter("taskId", params)==null?"":Utils.getParameter("taskId", params);//任务id
- String role_id = Utils.getParameter("roleId", params)==null?"":Utils.getParameter("roleId", params);//角色id
- String dept_id = Utils.getParameter("deptId", params)==null?"":Utils.getParameter("deptId", params);//单位id
-
- ExamineManagementDao dao = new ExamineManagementDao();
- String[] role_ids = role_id.split(",");
- String[] dept_ids = dept_id.split(",");
-
- List<Map<String,Object>> columnHead = dao.getTableHead(role_ids);//表头数据
- List<Map<String,Object>> data = dao.staticsScoreByUnit(task_id,dept_ids,role_ids);//表格数据
-
-
- List<String> headerList = new ArrayList<String>(); // 表格Titile
- List<String> keyList = new ArrayList<String>(); // 表格key
- List<Integer> widthList = new ArrayList<Integer>(); // 列宽
-
- if(!columnHead.isEmpty()){
- //表头
- headerList.add("单位");
- keyList.add("COMP_NAME");
- widthList.add(6000);
-
- for(int i=1;i<columnHead.size();i++){
- Map<String,Object> map = columnHead.get(i);
- //String role_name = (String) map.get("display");//角色名称
- List<Map<String,Object>> columns = (List<Map<String, Object>>) map.get("columns");//列名
- for(int j=0;j<columns.size();j++){
- Map<String,Object> columnMap = columns.get(j);
- String column_id = (String)columnMap.get("name");//列id
- String column_name = (String)columnMap.get("display");//列名称
- //表头
- headerList.add(column_name);
- keyList.add(column_id);
- widthList.add(4000);
- }
- }
-
- //创建表头
- ExportExcelUtils tableExcel = new ExportExcelUtils("统计分值",headerList);
- tableExcel.addHeader(headerList);
-
- int num = 0;//记录第几个角色
- for(int i=1;i<columnHead.size();i++){
- int startcol = (num*3)+1;//开始列
- Map<String,Object> map = columnHead.get(i);
- String role_name = (String) map.get("display");//角色名称
- tableExcel.getRow(1).getCell(startcol).setCellValue(role_name);
- tableExcel.mergeCol(1, startcol, startcol+2);//合并列
- num++;
- }
- tableExcel.mergeRow(1, 2, 0);//合并单位行
-
- //表数据
- for(int i=0;i<data.size();i++){
- Row row = tableExcel.addRow();
- for (int j = 0; j <headerList.size(); j++) {
- Map<String,Object> map = data.get(i);
- String value = map.get(keyList.get(j)).toString();
-
- if(keyList.get(j).contains("PARTAKE_NUM_")){
- tableExcel.addCell(row, j, new BigDecimal(value).intValue(), 2, Class.class);
- }else if(keyList.get(j).contains("COMP_NAME")){
- tableExcel.addCell(row, j, value, 2, Class.class);
- }else{
- tableExcel.addCell(row, j, Double.valueOf(value), 2, Class.class);
- }
-
- }
- }
- //设置列宽
- for(int i=0;i<widthList.size();i++){
- tableExcel.setColumnWidth(i, widthList.get(i));
- }
-
- try {
- FileOutputStream out = new FileOutputStream(filePath + File.separator + fileName);
- tableExcel.write(out);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return fileName;
- }
-
- }
|