package com.dsideal.newUniversityExamination.selectcourse.service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.dsideal.newUniversityExamination.selectcourse.model.CoreCourseModel; import com.dsideal.newUniversityExamination.selectcourse.model.SelectCoursePlanModel; import com.dsideal.newUniversityExamination.selectcourse.model.StudentApplyModel; import com.dsideal.newUniversityExamination.selectcourse.util.CoreUtil; import com.dsideal.newUniversityExamination.selectcourse.util.SelectCourseUtil; import com.dsideal.newUniversityExamination.util.COMMON; import com.dsideal.newUniversityExamination.util.Constant; import com.dsideal.newUniversityExamination.util.ToolsUtil; import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Record; public class SelectCoursePlanService { public static final SelectCoursePlanService service = new SelectCoursePlanService(); /*更新t_select_course_plan 的发布状态*/ public void updatePlanIsRelease(String planId){ /*本此计划下的 班级*/ List classList = SelectCoursePlanModel.dao.getClassListByplanId(planId); if(!COMMON.isEmpty(classList)){ String classIds = ToolsUtil.getIds(classList, "class_id"); /*选择过班级 的计划s*/ List planList = SelectCoursePlanModel.dao.getPlanListByClassIdAndStatus(classIds, "",""); if(!COMMON.isEmpty(planList)){ /*所有计划变无效*/ String planIds = ToolsUtil.getIds(planList, "plan_id"); /*未生成报告的 - 状态 变成 8 */ SelectCoursePlanModel.dao.updatePlanStatus("8", planIds,"1,2,3,4"); /*生成报告的-状态改成 7 */ SelectCoursePlanModel.dao.updatePlanStatus("7", planIds,"5"); } } } private int String2Integer(String str){ int value = 0 ; try { value = Integer.parseInt(str); } catch (NumberFormatException e) { e.printStackTrace(); } return value ; } /*新增和修改选科计划*/ @SuppressWarnings("unchecked") public JSONObject setCoursePlan(String planId, String planName, String startTime, String endTime, String type, String curriculumId, String maxStudentCount, String minStudentCount, String classIds, String classRoomIds,String bureauId,String status,String sequenceYear,String sequenceStage,String testId,String testIndex,String subjectType,String subjects,String classRoomCount,String courseType,String isReport) { Record record= new Record(); record.set("bureau_id", bureauId); record.set("plan_name", planName); record.set("start_time", startTime); record.set("end_time", endTime); record.set("type", type); record.set("curriculum_id", curriculumId); record.set("max_student_count", maxStudentCount); record.set("min_student_count", minStudentCount); record.set("status", COMMON.isEmpty(status)?"1":status); record.set("sequence_year", sequenceYear); record.set("sequence_stage", sequenceStage); record.set("test_index", testIndex); record.set("subject_type", subjectType); record.set("subjects", subjects); record.set("class_room_count", classRoomCount); record.set("course_type", courseType); record.set("is_report", isReport); int test_id = String2Integer(testId); record.set("test_id", test_id); JSONObject returnJson = new JSONObject() ; /*校验是否上报*/ if(!COMMON.isEmpty(classIds)&&"1".equals(isReport)){ List list = SelectCoursePlanModel.dao.getIsReportByPlanList(bureauId, classIds,planId); if(!COMMON.isEmpty(list)){ returnJson.put("success", false); returnJson.put("info", "本计划下班级已存在上报记录,不允许上报"); return returnJson; } } /*校验班级是否正常*/ String[] classStr = classIds.split(","); int [] classTypeArray = new int [classStr.length]; for(int i=0;i map = new HashMap<>(); map = (Map) mapJson.get("map"); boolean flag = mapJson.getBooleanValue("success"); if(!flag){ returnJson.put("info", "计划对应的班级存在无效班级,不允许操作"); returnJson.put("success", false); return returnJson ; } /*校验计划名是否重复*/ List list = SelectCoursePlanModel.dao.getCoursePlanNameListYz(planName, bureauId, planId); if(!COMMON.isEmpty(list)){ returnJson.put("success", false); returnJson.put("info", "选科计划名称已存在"); return returnJson; }else{ if(COMMON.isEmpty(planId)){ SelectCoursePlanModel.dao.saveCoursePlan(record); planId = String.valueOf(record.get("id")); }else{ record.set("plan_id", planId); SelectCoursePlanModel.dao.updateCoursePlan(record); } } /*删除之前的计划绑定的班级 和人*/ SelectCoursePlanModel.dao.delCoursePlanClass(planId); SelectCoursePlanModel.dao. delCoursePlanClassPerson(planId); /*插入班级 和学生*/ List batchClassList = new ArrayList<>(); List batchPersonList = new ArrayList<>(); for(int i=0;i getClassListByPlanIdAndType(String planId,String type){ List list = new ArrayList<>(); Page pageRecord= getClassPageByPlanIdAndType(planId, type); list = pageRecord.getList(); return list ; } /** * @Description:获取未成班学生 personIds * @author :周明升 * @date: 2019-1-19 上午8:52:53 * @return: String * @throws */ private String getNotInClassStudent(String planId){ String personIds = "" ; List coreResultList = SelectCoursePlanModel.dao.getCoreResult(planId, "", "", "", "0", "1", "0", "0"); if(!COMMON.isEmpty(coreResultList)){ String resultId = String.valueOf(coreResultList.get(0).get("result_id")); Page noClass =SelectCoursePlanModel.dao.getNotClassStudentList(resultId, planId, "999", "1"); List notClassStudentList = noClass.getList(); personIds = ToolsUtil.getIds(notClassStudentList, "person_id"); } return personIds ; } public Page getClassPageByPlanIdAndType(String planId,String type){ Page pageRecord = null ; if("2".equals(type)){ pageRecord= SelectCoursePlanModel.dao.getResultClassList(planId, "", "", "0", "", "1", "0", "","0,1", "","","0","",999,1); }else if("1".equals(type)){ /*学考获取未成班的学生*/ String personIds = getNotInClassStudent(planId); pageRecord = SelectCoursePlanModel.dao.getResultClassList(planId, "", "", "1", "2", "0", "0", "", "2", "","","0",personIds,999,1); }else if("0".equals(type)){ pageRecord = SelectCoursePlanModel.dao.getResultClassList(planId, "", "", "0", "", "1", "", "", "2", "","","0","",999,1); } return pageRecord ; } /** * Description:根据ID获取选课计划详情 * @author huyue * @date 2018-1-19 */ public JSONObject getPlanInfoById(String planId,String classId,String status,String personName,String pageSize,String pageNumber,String calculateType,String type){ //获取先科计划信息 JSONObject coursePlanOb = new JSONObject(); coursePlanOb = CoreUtil.getCoursePlanStudentCount(planId); Record record = SelectCoursePlanModel.dao.getPlanInfo(planId); /*获取班级List*/ List classList = SelectCoursePlanModel.dao.getClassListByplanId(planId); String total_person_count = String.valueOf(coursePlanOb.get("total_person_count")); String finish_person_count = String.valueOf(coursePlanOb.get("finish_person_count")); String unfinish_person_count = String.valueOf(coursePlanOb.get("unfinish_person_count")); record.set("finish_person_count", finish_person_count); record.set("unfinish_person_count", Integer.parseInt(unfinish_person_count)); record.set("total_person_count", total_person_count); for(Record classListRecord:classList){ String count1 = String.valueOf(classListRecord.get("count")); classListRecord.set("student_count", count1); } record.set("class_list", classList ); /*获取学生列表*/ List resulList = new ArrayList<>(); Page pageRecord = new Page<>(resulList,Integer.parseInt(pageNumber) , Integer.parseInt(pageSize), 0, 0); List records = new ArrayList<>(); // type = 1 没有学生列表 type = 2 学生基础班级 列表 3 学生的新班级列表 if("1".equals(type)){ }else if ("2".equals(type)){ pageRecord = SelectCoursePlanModel.dao.getStudentListByPlanId(planId, classId, status, personName, pageSize, pageNumber); records = pageRecord.getList(); for(int i=0;i studentList = pageRecord.getList(); Map studentMap = ToolsUtil.list2Map(studentList, "person_id"); pageRecord = SelectCoursePlanModel.dao.getStudentListByPlanId(planId, classId, status, personName, pageSize, pageNumber); records = pageRecord.getList(); for(int i=0;i resulListClass = new ArrayList<>(); for(Record recordOb: records){ String courseClassNameStr = recordOb.get("courseClassNameStr"); if(!COMMON.isEmpty(courseClassNameStr)){ resulList.add(recordOb); }else{ resulListClass.add(recordOb); } } resulList.addAll(resulListClass); JSONObject resultJson = new JSONObject(); resultJson.put("studentList", COMMON.convertListRecord2(resulList)); resultJson.put("pageNumber", pageRecord.getPageNumber()); resultJson.put("pageSize", pageRecord.getPageSize()); resultJson.put("totalPage", pageRecord.getTotalPage()); resultJson.put("totalRow", pageRecord.getTotalRow()); resultJson.put("coursePlanInfo", COMMON.convertRecord2Json2(record)); resultJson.put("success", true); return resultJson; } /** * @Description: 删除选科计划 * @author :周明升 * @date: 2018-12-25 下午4:32:26 * @return: String * @throws */ public JSONObject delSelectCoursePlan(String planId,String type) { //验证排课任务 是否使用 JSONObject resultJson = new JSONObject(); //1删除 2还原 if("2".equals(type)){ /*校验选科计划是否可以还原*/ resultJson = checkCoursePlanCanDel(planId); boolean success = resultJson.getBooleanValue("success"); if(!success){ return resultJson ; } } //获取 resultIds List list = SelectCoursePlanModel.dao.getCoreResult(planId, "","", "", "", "", "",""); String resultIds = ToolsUtil.getIds(list, "result_id"); //获取班级Ids Page pageRecord = SelectCoursePlanModel.dao.getResultClassList(planId, "", "", "", "", "", "", "", "", "", "","" ,"",9999, 1); List classList = pageRecord.getList(); String classIds = ToolsUtil.getIds(classList, "class_id"); if(!COMMON.isEmpty(resultIds)){ // 删除 未成班的 学生 CoreCourseModel.dao.delResultNotInClass(resultIds); //删除 算法分出来的班级 CoreCourseModel.dao.delResultClass(resultIds); // 删除 算法计算出的教师剩余情况 CoreCourseModel.dao.delResultTeacherCount(resultIds); } // 删除选科 计划日志 SelectCoursePlanModel.dao.delSelectCoursePlanLog(planId); // 删除学生志愿 StudentApplyModel.dao.delStudentApplyByPlanId(planId); // 删除 算法结果 CoreCourseModel.dao.delResultCore(planId,"","",""); if(!COMMON.isEmpty(classIds)){ CoreCourseModel.dao.delResultClassPerson(classIds); } //还原 把同步状态改掉 if("2".equals(type)){ SelectCoursePlanModel.dao.updateCoursePlanIsRelease(planId, "0"); } if("1".equals(type)){ SelectCoursePlanModel.dao.delCoursePlan(planId); //删除 计划对应的班级 SelectCoursePlanModel.dao.delCoursePlanClass(planId); //删除 计划班级对应的人 SelectCoursePlanModel.dao.delCoursePlanClassPerson(planId); } resultJson.put("info", "删除成功"); resultJson.put("success", true); return resultJson; } private JSONObject checkCoursePlanCanDel(String planId){ JSONObject returnJson = new JSONObject(); returnJson.put("success", true); /*无效计划不让还原*/ JSONObject planInfo = getPlanInfo(planId); String status = String.valueOf(planInfo.get("status")); if("7".equals(status)||"8".equals(status)){ returnJson.put("info", "选科计划无效,不能还原!"); returnJson.put("success", false); return returnJson; } List resultList = SelectCoursePlanModel.dao.getCoreResult(planId, "","", "", "0", "", "0","0"); int resultLenth = 0 ; if(!COMMON.isEmpty(resultList)&&resultList.size()>0){ resultLenth = resultList.size(); } if(resultLenth != 3){ returnJson.put("info", "选科计划下走班策略报告正在生成中,不能还原!"); returnJson.put("success", false); return returnJson; } return returnJson; } /*获取选科计划列表*/ public JSONObject getCoursePlanList(String bureauId, String pageNumber, String pageSize, String stageId, String type, String status, String planName,String isRelease) { Page pageRecord = SelectCoursePlanModel.dao.getCoursePlanList(stageId, type, status, planName, bureauId, isRelease,pageSize, pageNumber); List records = pageRecord.getList(); for(Record recordPlan:records){ String planId = String.valueOf(recordPlan.get("plan_id")); //获取先科计划信息 JSONObject coursePlanOb = new JSONObject(); coursePlanOb = CoreUtil.getCoursePlanStudentCount(planId); String total_person_count = String.valueOf(coursePlanOb.get("total_person_count")); String finish_person_count = String.valueOf(coursePlanOb.get("finish_person_count")); String unfinish_person_count = String.valueOf(coursePlanOb.get("unfinish_person_count")); recordPlan.set("finish_person_count", finish_person_count); recordPlan.set("unfinish_person_count", Integer.parseInt(unfinish_person_count)); recordPlan.set("total_person_count", total_person_count); //查询已选择算法的内容,添加已分班人数,未分班人数,和算法名称 List classDetailList = SelectCoursePlanModel.dao.getAllStudentByPlanId(planId); int inClassCount = 0; int notInClassCount =0; String calculateType = "";; for(Record classDetailRecord:classDetailList){ int count = Integer.parseInt(String.valueOf(classDetailRecord.get("count"))); int indexs = Integer.parseInt(String.valueOf(classDetailRecord.get("indexs"))); if(indexs==0){ inClassCount = count; if(!COMMON.isEmpty(classDetailRecord.get("calculate_type"))){ calculateType = String.valueOf(classDetailRecord.get("calculate_type")); } }else{ notInClassCount = count ; } } recordPlan.set("inClassCount", inClassCount); recordPlan.set("notInClassCount", notInClassCount); recordPlan.set("calculate_type", calculateType); if("0".equals(calculateType)){ recordPlan.set("calculate_type_name", "优先三科成班"); recordPlan.set("check_flag", 1); }else if ("1".equals(calculateType)){ recordPlan.set("calculate_type_name", "定二走一"); recordPlan.set("check_flag", 1); }else if ("2".equals(calculateType)){ recordPlan.set("calculate_type_name", "大走班"); recordPlan.set("check_flag", 1); }else{ recordPlan.set("calculate_type_name", "还未选择算法,暂无教学班分班信息"); recordPlan.set("check_flag", 0); } } JSONObject resultJson = new JSONObject(); resultJson.put("coursePlanList", COMMON.convertListRecord2(records)); resultJson.put("pageNumber", pageRecord.getPageNumber()); resultJson.put("pageSize", pageRecord.getPageSize()); resultJson.put("totalPage", pageRecord.getTotalPage()); resultJson.put("totalRow", pageRecord.getTotalRow()); resultJson.put("success", true); return resultJson; } /** * @Description: 清空选科计划 * @author :周明升 * @date: 2018-12-26 上午8:53:34 * @return: String * @throws */ public JSONObject delCoursePlanApply(String planId) { JSONObject resultJson = new JSONObject(); Record record = SelectCoursePlanModel.dao.getPlanInfo(planId); int status=Integer.valueOf(String.valueOf(record.get("status"))) ; if(status==1){ resultJson.put("info", "任务尚未开始,系统暂无选科数据"); resultJson.put("success", false); }else if(status==2){ resultJson.put("info", "选科计划正在进行中,请'暂停'后,再选择'清空选科结果'操作"); resultJson.put("success", false); }else{ StudentApplyModel.dao.delStudentApplyByPlanId(planId); resultJson.put("info", "删除成功"); resultJson.put("success", true); } return resultJson; } /** * @Description: 获取计划详情 * @author :周明升 * @date: 2018-12-26 上午8:59:15 * @return: String * @throws */ public JSONObject getPlanInfo(String planId) { JSONObject resultJson = new JSONObject(); Record record = SelectCoursePlanModel.dao.getPlanInfo(planId); String planName = String.valueOf(record.get("plan_name")); String startTime = String.valueOf(record.get("start_time")); String endTime = String.valueOf(record.get("end_time")); String type = String.valueOf(record.get("type")); String curriculumId = String.valueOf(record.get("curriculum_id")); String maxStudentCount = String.valueOf(record.get("max_student_count")); String minStudentCount = String.valueOf(record.get("min_student_count")); String sequenceYear = String.valueOf(record.get("sequence_year")); String sequenceStage = String.valueOf(record.get("sequence_stage")); String testId = String.valueOf(record.get("test_id")); String testIndex = String.valueOf(record.get("test_index")); String subjectType = String.valueOf(record.get("subject_type")); String classRoomCount = String.valueOf(record.get("class_room_count")); String courseType = String.valueOf(record.get("course_type")); String isReport = String.valueOf(record.get("is_report")); String status = String.valueOf(record.get("status")); String subjects = String.valueOf(record.get("subjects")); String subjectName=""; String [] subjectArray = subjects.split(","); Map map=Constant.getThreeSubjectMap(); for (int i = 0; i < subjectArray.length; i++) { subjectName += map.get(subjectArray[i]); if(i!=subjectArray.length-1){ subjectName +=","; } } JSONArray classArr = new JSONArray(); List classList = SelectCoursePlanModel.dao.getClassListByplanId(planId); for(Record classRecord : classList){ JSONObject ob = new JSONObject(); String classId = String.valueOf(classRecord.get("class_id")); String className = String.valueOf(classRecord.get("class_name")); ob.put("class_id", classId); ob.put("class_name", className); classArr.add(ob); } JSONArray roomArr = new JSONArray(); resultJson.put("subject_type", subjectType); resultJson.put("subjects", subjects); resultJson.put("subjectName", subjectName); resultJson.put("class_room_count", classRoomCount); resultJson.put("classArr", classArr); resultJson.put("classCount", classArr.size()); resultJson.put("roomArr", roomArr); resultJson.put("plan_id", planId); resultJson.put("plan_name", planName); resultJson.put("start_time", startTime.substring(0, startTime.length()-2)); resultJson.put("end_time", endTime.substring(0, startTime.length()-2)); resultJson.put("type", type); resultJson.put("curriculum_id", curriculumId); resultJson.put("max_student_count", maxStudentCount); resultJson.put("min_student_count", minStudentCount); resultJson.put("sequence_stage", sequenceStage); resultJson.put("sequence_year", sequenceYear); resultJson.put("test_id", testId); resultJson.put("test_index", testIndex); resultJson.put("course_type", courseType); resultJson.put("is_report", isReport); resultJson.put("status", status); resultJson.put("stage_id", record.get("stage_id")); resultJson.put("entrance_year", record.get("grade")); resultJson.put("bureau_id", record.get("bureau_id")); resultJson.put("success", true); resultJson.put("info", "查询成功"); return resultJson; } public JSONObject saveCoursePlanStatus(String planId, String status) { JSONObject resultJson= new JSONObject(); SelectCoursePlanModel.dao.updatePlanStatus(status, planId,""); resultJson.put("info", "操作成功"); resultJson.put("success", true); if("4".equals(status)){ //这直接调用service CoreCourseService.service.startSelectCoursePlan(planId); } return resultJson; } private JSONObject checkTheSelectionToBegin(String planId, String status){ JSONObject resultJson=new JSONObject(); resultJson.put("success", false); /*校验课程计划下数据*/ JSONObject planInfo = getPlanInfo(planId); //校验选课开始时 是否有班级在别的选课计划下进行选课 if("2".equals(status)){ //求出当前计划的班级Ids List classList = SelectCoursePlanModel.dao.getClassListByplanId(planId); String classIds = ToolsUtil.getIds(classList, "class_id"); List planList = SelectCoursePlanModel.dao.getPlanListByClassIdAndStatus(classIds,"2,3",planId); if(!COMMON.isEmpty(planList)){ resultJson.put("info", "存在部分班级正在选科!"); return resultJson ; } String curriculumId=String.valueOf(planInfo.get("curriculum_id")); JSONObject subjectTimeJson= CurriculumPlanService.service.getSubjectTimeList(curriculumId, "1"); //校验 所有科目是否有课时(所有) JSONArray subjectArray = subjectTimeJson.getJSONArray("subject_list"); JSONArray baseSubjectArray = subjectTimeJson.getJSONArray("base_subject_list"); baseSubjectArray.addAll(subjectArray); int timeSum = 0 ; for(int i = 0 ;i studentList = StudentApplyModel.dao.getStudentApplyList(planId); if(!COMMON.isEmpty(studentList)){ resultJson.put("info", "学生志愿存在异常,联系管理员!"); resultJson.put("error", 1); return resultJson ; } /*校验选科计划是否是套餐模式*/ if(!checkSubectType(planInfo)){ resultJson.put("info", "部分选科志愿结果与计划不匹配,是否继续? 选择确定,将以当前志愿结果进行分班排课,与当前选科计划不一致!"); resultJson.put("error", 2); return resultJson ; } } resultJson.put("success", true); resultJson.put("info", Constant.SUCCESS_INFO); return resultJson; } public void updateCoursePlanIsRelease(String planId,String IsRelease){ SelectCoursePlanModel.dao.updateCoursePlanIsRelease(String.valueOf(planId), IsRelease); } private boolean checkSubectType(JSONObject planInfo){ String subjectType = String.valueOf(planInfo.get("subject_type")); String planId = String.valueOf(planInfo.get("plan_id")); //非全科模式 if(!"0".equals(subjectType)){ String subjects = String.valueOf(planInfo.get("subjects")); List list = StudentApplyModel.dao.getStudentApplyNotInSubjectIds(planId, subjects); if(!COMMON.isEmpty(list)){ return false; } } return true ; } /** * @Description: 校验 是否存在正在发布中的 选科计划 * @author :周明升 * @date: 2019-1-7 上午8:46:49 * @return: JSONObject * @throws */ public JSONObject checkPlanExistIsRelease(String bureauId,String planId) { JSONObject returnJson = new JSONObject(); List list = SelectCoursePlanModel.dao.getCoursePlanListByRelease(bureauId, "2"); if(!COMMON.isEmpty(list)){ returnJson.put("success", Constant.FALSE); returnJson.put("info", "存在正在发布中的选科计划,不允许发布!"); return returnJson ; } // String personIds = getNotInClassStudent(planId); // if(!COMMON.isEmpty(personIds)){ // returnJson.put("success", Constant.FALSE); // returnJson.put("info", "存在未成班的学生,不允许发布"); // return returnJson ; // } returnJson.put("success", Constant.TRUE); returnJson.put("info", Constant.SUCCESS_INFO); return returnJson; } public JSONObject checkPlanChangeStatus(String planId, String status) { JSONObject returnJson= checkTheSelectionToBegin(planId, status); return returnJson; } public JSONObject getChoiceExam(String personId) { return SelectCourseUtil.getChoiceExam(personId); } public void updateBaseClassId(List list){ SelectCoursePlanModel.dao.updateBaseClassId(list); } /** * @Description: 保存发布后的班级分层信息 * @author :周明升 * @date: 2019-2-23 下午4:19:27 * @return: void * @throws */ public void inserCoursePlanClassRelease(int planId, List list) { /*删除之前的发布的班级记录*/ SelectCoursePlanModel.dao.delCoursePlanClassRelease(planId); List batchList = new ArrayList<>() ; for(Record record : list ){ Record recordOb = new Record() ; recordOb.set("plan_id", planId); recordOb.set("class_id", record.get("class_id")); recordOb.set("level", record.get("level")); recordOb.set("base_class_id", record.get("base_class_id")); recordOb.set("base_class_type", record.get("base_class_type")); recordOb.set("classtype_teaching", record.get("classtype_teaching")); String baseClassType = String.valueOf(record.get("base_class_type")); String classtypeTeaching = String.valueOf(record.get("classtype_teaching")); int classType = SelectCourseBaseService.service.getCusinessClassType(baseClassType, classtypeTeaching); recordOb.set("class_type",classType); batchList.add(recordOb); } SelectCoursePlanModel.dao.batchInserCoursePlanClassRelease(batchList); } }