You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
268 lines
10 KiB
268 lines
10 KiB
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.CourseSelectTimeModel;
|
|
import com.dsideal.newUniversityExamination.selectcourse.model.TaskClassRoomModel;
|
|
import com.dsideal.newUniversityExamination.selectcourse.model.TaskModel;
|
|
import com.dsideal.newUniversityExamination.util.COMMON;
|
|
import com.dsideal.newUniversityExamination.util.ToolsUtil;
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
public class TaskClassRoomService {
|
|
|
|
public static final TaskClassRoomService service= new TaskClassRoomService();
|
|
|
|
public JSONObject getTaskClassRooms(String taskId){
|
|
JSONObject returnJson = new JSONObject();
|
|
/*获取班级列表*/
|
|
List<Record> list = TaskModel.dao.getClassListByTaskId(taskId, "");
|
|
/*获取设置了教室的Map*/
|
|
Map<String, Record> map = getClassRoomMap(taskId);
|
|
JSONArray classRooms1 = new JSONArray();
|
|
JSONArray classRooms2 = new JSONArray();
|
|
JSONArray classRooms3 = new JSONArray();
|
|
boolean isExistRoom = false ;
|
|
for(Record record:list){
|
|
JSONObject classRoom = new JSONObject();
|
|
String classId = String.valueOf(record.get("class_id"));
|
|
String classType = String.valueOf(record.get("class_type"));
|
|
String className = String.valueOf(record.get("class_name"));
|
|
String group_id = String.valueOf(record.get("group_id"));
|
|
String key = classId+"|"+classType;
|
|
Record roomIdRecord = map.get(key);
|
|
String classRoomName = "";
|
|
String classRoomId = "";
|
|
String id= "";
|
|
if(COMMON.isEmpty(roomIdRecord)){
|
|
classRoom.put("flag", false);
|
|
isExistRoom = true;
|
|
}else{
|
|
classRoomName = String.valueOf(roomIdRecord.get("class_room_name"));
|
|
classRoomId = String.valueOf(roomIdRecord.get("class_room_id"));
|
|
id = String.valueOf(roomIdRecord.get("id"));
|
|
classRoom.put("flag", true);
|
|
}
|
|
classRoom.put("classId", classId);
|
|
classRoom.put("classType", classType);
|
|
classRoom.put("className", className);
|
|
classRoom.put("classRoomName", classRoomName);
|
|
classRoom.put("classRoomId", classRoomId);
|
|
classRoom.put("groupId", group_id);
|
|
classRoom.put("id", id);
|
|
|
|
if("2".equals(classType)){
|
|
classRoom.put("type", classType);
|
|
classRoom.put("classDesc", "行政班");
|
|
classRooms1.add(classRoom);
|
|
}else if("0".equals(classType)){
|
|
classRoom.put("type", classType);
|
|
classRoom.put("classDesc", "选考教学班");
|
|
classRooms2.add(classRoom);
|
|
}else if("1".equals(classType)){
|
|
classRoom.put("type", classType);
|
|
classRoom.put("classDesc", "学考教学班");
|
|
classRooms3.add(classRoom);
|
|
}
|
|
}
|
|
|
|
returnJson.put("classRoomsList1", classRooms1);
|
|
returnJson.put("classRoomsList2", classRooms2);
|
|
returnJson.put("classRoomsList3", classRooms3);
|
|
|
|
//获取task教师信息
|
|
List<Record> personList = TaskModel.dao.getCurriculumPlanTeacherList(taskId, "","","");
|
|
returnJson.put("personList", COMMON.convertListRecord2(personList));
|
|
returnJson.put("success", true);
|
|
returnJson.put("is_exist", isExistRoom);
|
|
return returnJson;
|
|
}
|
|
Map<String, Record> getClassRoomMap(String taskId){
|
|
Map<String, Record> map = new HashMap<>();
|
|
List<Record> roomList = TaskClassRoomModel.dao.getClassRoomList(taskId,"","");
|
|
for(Record record : roomList){
|
|
String classId = String.valueOf(record.get("class_id"));
|
|
String type = String.valueOf(record.get("type"));
|
|
String key = classId+"|"+type;
|
|
map.put(key, record);
|
|
}
|
|
return map ;
|
|
}
|
|
|
|
public JSONObject setTaskClassRoom(Record record) {
|
|
JSONObject returnJson = new JSONObject();
|
|
String id = String.valueOf(record.get("id"));
|
|
String taskId = String.valueOf(record.get("taskId"));
|
|
String classId = String.valueOf(record.get("classId"));
|
|
String type = String.valueOf(record.get("type"));
|
|
String classRoomId = String.valueOf(record.get("classRoomId"));
|
|
Record taskClassRoom = new Record();
|
|
taskClassRoom.set("task_id", taskId);
|
|
taskClassRoom.set("class_id", classId);
|
|
taskClassRoom.set("class_room_id", classRoomId);
|
|
taskClassRoom.set("type", type);
|
|
Boolean flag = false;
|
|
if(COMMON.isEmpty(id)){
|
|
TaskClassRoomModel.dao.delClassRoom(taskId, "", classId, type);
|
|
flag = TaskClassRoomModel.dao.saveTaskClassroom(taskClassRoom);
|
|
}else{
|
|
taskClassRoom.set("id", id);
|
|
flag = TaskClassRoomModel.dao.updateTaskClassroom(taskClassRoom);
|
|
}
|
|
//更新课程表
|
|
TaskClassRoomModel.dao.updateTimeTableRoom(taskId, classId, classRoomId);
|
|
returnJson.put("success", flag);
|
|
returnJson.put("info", "保存成功");
|
|
return returnJson;
|
|
}
|
|
public String getClassRoomList(String taskId, String type,String bureauId,String calculateType,String groupId) {
|
|
List<Record> classRoomList = new ArrayList<>();
|
|
if("2".equals(type)){ //行政班
|
|
groupId = "";
|
|
}
|
|
if(!"2".equals(calculateType)&&"0".equals(type)){ //优先三科 和定二走一的选考走班
|
|
groupId = "";
|
|
}
|
|
classRoomList = TaskClassRoomModel.dao.getClassRoomList(taskId, type, groupId);
|
|
if("2".equals(type)){
|
|
classRoomList.addAll(TaskClassRoomModel.dao.getFunctionRooms(taskId));
|
|
classRoomList.addAll(TaskClassRoomModel.dao.getMergingClassRooms(taskId));
|
|
}
|
|
|
|
String classRoomStr = ToolsUtil.getIds(classRoomList, "class_room_id");
|
|
String str = ClassRoomService.service.getWeekOfClassById(bureauId, classRoomStr,"");
|
|
return str;
|
|
}
|
|
|
|
public JSONObject delClassRoom(String id) {
|
|
JSONObject resultJson = new JSONObject();
|
|
/*删除设置教室*/
|
|
boolean flag = TaskClassRoomModel.dao.delClassRoom("", id,"","");
|
|
if(flag){
|
|
resultJson.put("info", "删除成功");
|
|
}else{
|
|
resultJson.put("info", "删除失败");
|
|
}
|
|
resultJson.put("success", flag);
|
|
return resultJson;
|
|
}
|
|
|
|
public String getBatchClassRoom(String taskId, String bureauId) {
|
|
List<Record> list = TaskClassRoomModel.dao.getClassRoomList(taskId, "", "");
|
|
list.addAll(TaskClassRoomModel.dao.getFunctionRooms(taskId));
|
|
list.addAll(TaskClassRoomModel.dao.getMergingClassRooms(taskId));
|
|
String roomIds = ToolsUtil.getIds(list, "class_room_id");
|
|
String str = ClassRoomService.service.getWeekOfClassById(bureauId, roomIds,"");
|
|
return str ;
|
|
}
|
|
|
|
public String setBatchClassRoom(String taskId, String classRoomId,String calculateType) {
|
|
|
|
JSONArray classRoomsList1= new JSONArray();//教学班
|
|
JSONArray classRoomsList2= new JSONArray();//选考走班
|
|
JSONArray classRoomsList3= new JSONArray();//学考走班
|
|
|
|
JSONObject json = getTaskClassRooms(taskId);
|
|
classRoomsList1= JSONArray.parseArray(String.valueOf(json.get("classRoomsList1"))); //行政班
|
|
classRoomsList2= JSONArray.parseArray(String.valueOf(json.get("classRoomsList2"))); //选考走班
|
|
classRoomsList3= JSONArray.parseArray(String.valueOf(json.get("classRoomsList3"))); //学考走班
|
|
/*解析教室*/
|
|
String arry [] = classRoomId.split(",");
|
|
List<Record> resultList = new ArrayList<>();
|
|
/*设置行政班*/
|
|
if(!COMMON.isEmpty(classRoomsList1)){
|
|
String type = "2";
|
|
resultList = setBatchRoomGoclass(classRoomsList1, arry, taskId, type, resultList, "1");
|
|
}
|
|
/*选考走班 批量设置*/
|
|
if(!COMMON.isEmpty(classRoomsList2)){
|
|
String type = "0";
|
|
if("2".equals(calculateType)){
|
|
resultList= setBatchRoomGoclass(classRoomsList2, arry, taskId, type, resultList,"0");
|
|
}else {
|
|
resultList= setBatchRoomGoclass(classRoomsList2, arry, taskId, type, resultList,"1");
|
|
}
|
|
}
|
|
//学考走班 批量设置
|
|
if(!COMMON.isEmpty(classRoomsList3)){
|
|
String type = "1";
|
|
resultList= setBatchRoomGoclass(classRoomsList3, arry, taskId, type, resultList,"0");
|
|
}
|
|
TaskClassRoomModel.dao.setBatchClassRoom(resultList);
|
|
CourseSelectTimeModel.dao.updateTaskTimetableRoom(taskId);
|
|
JSONObject resultJson = new JSONObject();
|
|
resultJson.put("success", true);
|
|
resultJson.put("info", "操作成功");
|
|
return resultJson.toJSONString();
|
|
|
|
}
|
|
|
|
|
|
//走班批量设置教室
|
|
private List<Record> setBatchRoomGoclass(JSONArray classRoomsListEeach,String [] array,String taskId,String type,List<Record> resultList,String groupType){
|
|
if(!COMMON.isEmpty(classRoomsListEeach)&&"0".equals(groupType)){
|
|
/*获取grupId*/
|
|
List<Record> list = ToolsUtil.JSONArray2List(classRoomsListEeach);
|
|
List<JSONObject> groipList = new ArrayList<>();
|
|
for(Record record : list){
|
|
groipList.add(ToolsUtil.Record2Object(record));
|
|
}
|
|
ToolsUtil.removeDuplicate(groipList, "groupid");
|
|
/*以groupId分组 获取班级列表*/
|
|
List<JSONArray> classList = new ArrayList<>();
|
|
for(JSONObject json : groipList){
|
|
String groupId = String.valueOf(json.get("groupid"));
|
|
JSONArray jsonArray = new JSONArray();
|
|
int len2 = classRoomsListEeach.size();
|
|
for (int i = 0; i < len2 ; i++) {
|
|
JSONObject jsonOb = classRoomsListEeach.getJSONObject(i);
|
|
String groupId2 = String.valueOf(jsonOb.get("groupId"));
|
|
if(groupId.equals(groupId2)){
|
|
jsonArray.add(jsonOb);
|
|
}
|
|
}
|
|
classList.add(jsonArray);
|
|
}
|
|
for(JSONArray jsonArray : classList){
|
|
addRoomIdToClassId(jsonArray, resultList, taskId, array, type);
|
|
}
|
|
}else if(!COMMON.isEmpty(classRoomsListEeach)&&"1".equals(groupType)){
|
|
/*行政班*/
|
|
addRoomIdToClassId(classRoomsListEeach, resultList, taskId, array, type);
|
|
}
|
|
return resultList;
|
|
}
|
|
/*添加 班级对应的教室*/
|
|
private void addRoomIdToClassId(JSONArray jsonArray ,List<Record> list,String taskId,String [] array,String type){
|
|
int len = jsonArray.size();
|
|
int add = 0 ;
|
|
for (int i = 0; i < len ; i++) {
|
|
JSONObject jsonOb = jsonArray.getJSONObject(i);
|
|
//没有设置的教室的班级
|
|
if(COMMON.isEmpty(jsonOb.get("id"))){
|
|
String classId = String.valueOf(jsonOb.get("classId")) ;
|
|
Record record = new Record();
|
|
record.set("task_id", taskId);
|
|
record.set("class_id", classId);
|
|
record.set("class_room_id", array[add]);
|
|
record.set("type", type);
|
|
list.add(record);
|
|
add ++ ;
|
|
if(array.length == add){
|
|
break ;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|