|
|
package com.dsideal.newUniversityExamination.selectcourse.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.dsideal.newUniversityExamination.selectcourse.model.CurriculumPlanModel;
|
|
|
import com.dsideal.newUniversityExamination.util.COMMON;
|
|
|
import com.dsideal.newUniversityExamination.util.Constant;
|
|
|
import com.dsideal.newUniversityExamination.util.FileUtil;
|
|
|
import com.dsideal.newUniversityExamination.util.ToolsUtil;
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
import com.jfinal.upload.UploadFile;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
public class CurriculumPlanService {
|
|
|
|
|
|
public static final CurriculumPlanService service = new CurriculumPlanService();
|
|
|
|
|
|
public JSONObject saveCurriculumPlan(String curriculumPlanId,
|
|
|
String curriculumPlanName, String stageId, String grade,
|
|
|
String xqId, String subjectIds,String bureauId,String baseSubject,String type) {
|
|
|
boolean flag = false;
|
|
|
JSONObject returnJson=new JSONObject();
|
|
|
Record record= new Record();
|
|
|
record.set("curriculum_plan_name",curriculumPlanName);
|
|
|
record.set("stage_id",stageId);
|
|
|
record.set("grade",grade);
|
|
|
record.set("xq_id",xqId);
|
|
|
record.set("subject_ids",subjectIds);
|
|
|
record.set("bureau_id",bureauId);
|
|
|
record.set("base_subject",baseSubject);
|
|
|
record.set("type",type);
|
|
|
Record recordName = CurriculumPlanModel.dao.checkCurriculumName(curriculumPlanName, bureauId, curriculumPlanId);
|
|
|
if(!COMMON.isEmpty(recordName)){
|
|
|
returnJson.put("success", flag);
|
|
|
returnJson.put("info", "已存在课程计划名称");
|
|
|
return returnJson ;
|
|
|
}
|
|
|
if(!COMMON.isEmpty(curriculumPlanId)){
|
|
|
record.set("curriculum_plan_id", curriculumPlanId);
|
|
|
List<Record> taskList = CurriculumPlanModel.dao.checkExistTask(curriculumPlanId);
|
|
|
if(!COMMON.isEmpty(taskList)){
|
|
|
returnJson.put("info", "课程计划已被排课任务使用不能编辑!");
|
|
|
returnJson.put("success", false);
|
|
|
return returnJson;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(!COMMON.isEmpty(curriculumPlanId)){
|
|
|
record.set("curriculum_plan_id", curriculumPlanId);
|
|
|
flag = CurriculumPlanModel.dao.updateCurriculum(record);
|
|
|
//删除 除了选择的科目 其他科目的课时 和教师对应的课时
|
|
|
String subjectArrays = baseSubject ;
|
|
|
if(!COMMON.isEmpty(subjectIds)){
|
|
|
subjectArrays += ","+subjectIds;
|
|
|
}
|
|
|
CurriculumPlanModel.dao.delSubjectTime(curriculumPlanId, subjectArrays);
|
|
|
CurriculumPlanModel.dao.delCurriculumSubjectPerson(curriculumPlanId,"","" ,subjectArrays);
|
|
|
}else{
|
|
|
flag = CurriculumPlanModel.dao.saveCurriculum(record);
|
|
|
}
|
|
|
returnJson.put("success", flag);
|
|
|
if(flag){
|
|
|
returnJson.put("info","插入数据成功");
|
|
|
}else{
|
|
|
returnJson.put("info", "插入数据失败");
|
|
|
}
|
|
|
return returnJson;
|
|
|
}
|
|
|
|
|
|
public JSONObject getCurriculumPlanList(String pageSize, String pageNumber,
|
|
|
String bureauId,String stageId,String grade,String xqId,String curriculumPlanName,String type) {
|
|
|
Record record = new Record();
|
|
|
record.set("bureau_id", bureauId);
|
|
|
record.set("stage_id", stageId);
|
|
|
record.set("grade", grade);
|
|
|
record.set("xq_id", xqId);
|
|
|
record.set("curriculum_plan_name", curriculumPlanName);
|
|
|
record.set("type", type);
|
|
|
Page<Record> pageRecord = CurriculumPlanModel.dao.getCurriculumPlanList(record, pageSize, pageNumber);
|
|
|
List<Record> records = pageRecord.getList();
|
|
|
for(int i=0,len=records.size(); i<len; i++){
|
|
|
Record curriculumRecord = records.get(i);
|
|
|
String xqmc = curriculumRecord.get("XQMC");
|
|
|
curriculumRecord.set("xqmc", xqmc);
|
|
|
if(COMMON.isEmpty(curriculumRecord.get("base_subject"))){
|
|
|
curriculumRecord.set("base_subject", "");
|
|
|
}
|
|
|
}
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
resultJson.put("curriculumPlanList", 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;
|
|
|
}
|
|
|
public JSONObject delCurriculumPlanById(String curriculumPlanId) {
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
List<Record> planList = CurriculumPlanModel.dao.checkExistCoursePlan(curriculumPlanId);
|
|
|
if(!COMMON.isEmpty(planList)){
|
|
|
resultJson.put("info", "课程计划已被选科计划使用不能删除!");
|
|
|
resultJson.put("success", false);
|
|
|
return resultJson;
|
|
|
}
|
|
|
List<Record> taskList = CurriculumPlanModel.dao.checkExistTask(curriculumPlanId);
|
|
|
if(!COMMON.isEmpty(taskList)){
|
|
|
resultJson.put("info", "课程计划已被排课任务使用不能删除!");
|
|
|
resultJson.put("success", false);
|
|
|
return resultJson;
|
|
|
}
|
|
|
boolean flag = CurriculumPlanModel.dao.delCurriculumPlan(curriculumPlanId);
|
|
|
CurriculumPlanModel.dao.delSubjectTime(curriculumPlanId, "");
|
|
|
CurriculumPlanModel.dao.delCurriculumSubjectPerson(curriculumPlanId, "", "","");
|
|
|
if(flag){
|
|
|
resultJson.put("info", "删除成功");
|
|
|
}else{
|
|
|
resultJson.put("info", "删除失败");
|
|
|
}
|
|
|
resultJson.put("success", flag);
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
public JSONObject getSubjectTimeList(String curriculumPlanId,String type) {
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
Record record = new Record().set("curriculum_plan_id", curriculumPlanId);
|
|
|
Page<Record> pageRecord = CurriculumPlanModel.dao.getCurriculumPlanList(record, "1", "1");
|
|
|
List<Record> curriculumList = pageRecord.getList();
|
|
|
JSONArray arr = new JSONArray();
|
|
|
JSONArray arrBaseSubject = new JSONArray();
|
|
|
if(!COMMON.isEmpty(curriculumList)){
|
|
|
Record curriculumInfo = curriculumList.get(0);
|
|
|
String allSubjectIds = "";
|
|
|
String baseSubjectIds = "";
|
|
|
String selectSubjectIds = "";
|
|
|
if(!COMMON.isEmpty(curriculumInfo.get("base_subject"))){
|
|
|
allSubjectIds = curriculumInfo.get("base_subject") ;
|
|
|
baseSubjectIds = curriculumInfo.get("base_subject") ;
|
|
|
}
|
|
|
if(!COMMON.isEmpty(curriculumInfo.get("subject_ids"))){
|
|
|
allSubjectIds += ","+curriculumInfo.get("subject_ids");
|
|
|
selectSubjectIds = curriculumInfo.get("subject_ids") ;
|
|
|
}
|
|
|
if(COMMON.isEmpty(allSubjectIds)){
|
|
|
resultJson.put("false", false);
|
|
|
resultJson.put("info", "未设置学科");
|
|
|
return resultJson ;
|
|
|
}
|
|
|
/*所有课程的课时*/
|
|
|
List<Record> subjectTimeList = CurriculumPlanModel.dao.getSubjectTimeByIdAndSubjectIds(curriculumPlanId, allSubjectIds);
|
|
|
/*走班课*/
|
|
|
arr = getSubjectTimeArray(selectSubjectIds, subjectTimeList,type);
|
|
|
/*基础课程*/
|
|
|
arrBaseSubject = getSubjectTimeArray(baseSubjectIds, subjectTimeList,type);
|
|
|
}
|
|
|
resultJson.put("success", true);
|
|
|
resultJson.put("info", "查询成功");
|
|
|
resultJson.put("subject_list", arr);
|
|
|
resultJson.put("base_subject_list", arrBaseSubject);
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
/*课程 添加课时*/
|
|
|
private JSONArray getSubjectTimeArray(String subjectIds,List<Record> subjectTimeList,String type){
|
|
|
JSONArray arr = new JSONArray();
|
|
|
if(!COMMON.isEmpty(subjectIds)){
|
|
|
for(Record record : subjectTimeList){
|
|
|
String subjectId = String.valueOf(record.get("subject_id"));
|
|
|
if(ToolsUtil.arrayIncludeStr(subjectIds, subjectId)){
|
|
|
JSONObject jsonOb = new JSONObject();
|
|
|
if(COMMON.isEmpty(record.get("id"))){
|
|
|
jsonOb.put("times", 0);
|
|
|
jsonOb.put("times_choice", 0);
|
|
|
}else{
|
|
|
jsonOb.put("times", Integer.parseInt(String.valueOf(record.get("times"))));
|
|
|
jsonOb.put("id", record.get("id"));
|
|
|
jsonOb.put("times_choice", Integer.parseInt(String.valueOf(record.get("times_choice"))));
|
|
|
}
|
|
|
jsonOb.put("subject_name", record.get("subject_name"));
|
|
|
jsonOb.put("subject_id", subjectId);
|
|
|
/*添加教师信息*/
|
|
|
if("1".equals(type)){
|
|
|
addPersonList(record, jsonOb);
|
|
|
}
|
|
|
arr.add(jsonOb);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return arr ;
|
|
|
}
|
|
|
private void addPersonList(Record subjectInfo,JSONObject jsonOb){
|
|
|
String subjectId = String.valueOf(subjectInfo.get("subject_id"));
|
|
|
String personNames = String.valueOf(subjectInfo.get("person_names"));
|
|
|
String personIds = String.valueOf(subjectInfo.get("person_ids"));
|
|
|
String personTimes = String.valueOf(subjectInfo.get("person_times"));
|
|
|
String levels = String.valueOf(subjectInfo.get("levels"));
|
|
|
String pids = String.valueOf(subjectInfo.get("pids"));
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
int num = 0;
|
|
|
int sumNum = 0 ;
|
|
|
jsonOb.put("personNames", "");
|
|
|
if(!COMMON.isEmpty(subjectInfo.get("person_names"))){
|
|
|
jsonOb.put("personNames", personNames);
|
|
|
String [] personNameArray = personNames.split(",");
|
|
|
String [] personIdArray = personIds.split(",");
|
|
|
String [] personTimesArray = personTimes.split(",");
|
|
|
String [] levelsArray = levels.split(",");
|
|
|
String [] pidArray = pids.split(",");
|
|
|
sumNum = personTimesArray.length;
|
|
|
for(int i = 0 ;i < personNameArray.length ; i++){
|
|
|
JSONObject json = new JSONObject();
|
|
|
int personTime = Integer.parseInt(personTimesArray[i] );
|
|
|
json.put("person_id", personIdArray[i]);
|
|
|
json.put("person_name", personNameArray[i]);
|
|
|
json.put("times",Integer.parseInt(personTimesArray[i]) );
|
|
|
json.put("level", levelsArray[i]);
|
|
|
json.put("id", pidArray[i]);
|
|
|
json.put("subject_id",subjectId);
|
|
|
jsonArray.add(json);
|
|
|
if(personTime > 0){
|
|
|
num ++ ;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
jsonOb.put("person_list", jsonArray);
|
|
|
String percentage= getPercentage(sumNum, num);
|
|
|
jsonOb.put("percentage", percentage);
|
|
|
}
|
|
|
|
|
|
|
|
|
public JSONObject saveSubjectTime(String curriculumPlanId,String subjectTimeStr){
|
|
|
JSONObject subjectTimeJson = JSONObject.parseObject(subjectTimeStr);
|
|
|
JSONArray jsonArray = subjectTimeJson.getJSONArray("subject_list");
|
|
|
for(int i=0 ; i<jsonArray.size();i++){
|
|
|
JSONObject subjectOb = (JSONObject)jsonArray.get(i);
|
|
|
String subjectId = String.valueOf(subjectOb.get("subject_id"));
|
|
|
String times = String.valueOf(subjectOb.get("times"));
|
|
|
String timesChoice = String.valueOf(subjectOb.get("times_choice"));
|
|
|
if(COMMON.isEmpty(subjectOb.get("times_choice"))||"null".equals(String.valueOf(subjectOb.get("times_choice")))){
|
|
|
timesChoice = "0";
|
|
|
}
|
|
|
CurriculumPlanModel.dao.replaceSubjectTime(curriculumPlanId,subjectId,times,timesChoice);
|
|
|
}
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
resultJson.put("success", true);
|
|
|
resultJson.put("info", "保存成功");
|
|
|
return resultJson ;
|
|
|
}
|
|
|
|
|
|
public JSONObject getPersonSubjectList(String curriculumPlanId) {
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
JSONObject subjectJson = getSubjectTimeList(curriculumPlanId,"1");
|
|
|
JSONArray subjectList = subjectJson.getJSONArray("subject_list");
|
|
|
JSONArray baseSubjectList = subjectJson.getJSONArray("base_subject_list");
|
|
|
baseSubjectList.addAll(subjectList);
|
|
|
resultJson.put("subject_list", baseSubjectList);
|
|
|
resultJson.put("success", true);
|
|
|
return resultJson ;
|
|
|
}
|
|
|
|
|
|
//通用接口 查询科目下 教师课时不为0 的半分比
|
|
|
private String getPercentage(int denominator,int molecule){
|
|
|
String percentage = "0%";
|
|
|
//zms 加百分比
|
|
|
DecimalFormat df = new DecimalFormat("0");//格式化小数
|
|
|
if(denominator != 0){
|
|
|
float f = (float)molecule/(float)denominator ;
|
|
|
String num = df.format(f*100);//返回的是String类型
|
|
|
percentage = num +"%";
|
|
|
}
|
|
|
return percentage ;
|
|
|
}
|
|
|
|
|
|
//设置课程计划教师
|
|
|
public JSONObject setCurriculumPerson(String curriculumPlanId,String subjectId,String personIds,String level) {
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
//删除之前教师
|
|
|
CurriculumPlanModel.dao.delCurriculumSubjectPerson(curriculumPlanId, subjectId, personIds,"");
|
|
|
List<Record> batchList = new ArrayList<>();
|
|
|
if(!COMMON.isEmpty(personIds)){
|
|
|
String[] str = personIds.split(",");
|
|
|
for(int i=0;i<str.length;i++){
|
|
|
String personId = str[i];
|
|
|
Record record = new Record();
|
|
|
record.set("curriculum_plan_id", curriculumPlanId);
|
|
|
record.set("subject_id", subjectId);
|
|
|
record.set("person_id", personId);
|
|
|
record.set("level", level);
|
|
|
List<Record> list = CurriculumPlanModel.dao.getSubjectPersonList(curriculumPlanId, subjectId, personId);
|
|
|
if(COMMON.isEmpty(list)){
|
|
|
batchList.add(record);
|
|
|
}
|
|
|
}
|
|
|
CurriculumPlanModel.dao.batchInsertSubjectPerson(batchList);
|
|
|
}
|
|
|
resultJson.put("success", true);
|
|
|
resultJson.put("info", "更新成功");
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
//设置课程计划周课时数量
|
|
|
public JSONObject setCurriculumTimes(String curriculumPlanId,String subjectId,String times,String personId) {
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
CurriculumPlanModel.dao.delSubjectPersonTimes(curriculumPlanId, subjectId);
|
|
|
CurriculumPlanModel.dao.insertSubjectPersonTimes(curriculumPlanId, subjectId, times);
|
|
|
resultJson.put("success", true);
|
|
|
resultJson.put("info", "更新成功");
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
public String getCurriculumPlanSubjectPerson(String curriculumPlanId,
|
|
|
String subjectId) {
|
|
|
List<Record> subjectTimeList = CurriculumPlanModel.dao.getSubjectTimeByIdAndSubjectIds(curriculumPlanId, subjectId);
|
|
|
JSONArray jsonArry = getSubjectTimeArray(subjectId, subjectTimeList,"1");
|
|
|
List<Record> list = new ArrayList<>();
|
|
|
if(!COMMON.isEmpty(jsonArry)){
|
|
|
JSONObject json = jsonArry.getJSONObject(0);
|
|
|
JSONArray jsonArray = json.getJSONArray("person_list");
|
|
|
list = ToolsUtil.JSONArray2List(jsonArray);
|
|
|
}
|
|
|
return COMMON.convert2JsonStr(list);
|
|
|
}
|
|
|
public JSONObject setCurriculumPlanSubjectPerson(String jsonStr,String curriculumPlanId){
|
|
|
JSONObject json = JSONObject.parseObject(jsonStr);
|
|
|
JSONArray jsonArray = json.getJSONArray("table_List");
|
|
|
List<Record> batchList = new ArrayList<>();
|
|
|
for(int i=0 ; i<jsonArray.size();i++){
|
|
|
JSONObject subjectOb = (JSONObject)jsonArray.get(i);
|
|
|
String id = String.valueOf(subjectOb.get("ID"));
|
|
|
String subjectId = String.valueOf(subjectOb.get("SUBJECT_ID"));
|
|
|
String times = String.valueOf(subjectOb.get("TIMES"));
|
|
|
String level = String.valueOf(subjectOb.get("LEVEL"));
|
|
|
Record record = new Record();
|
|
|
record.set("curriculum_plan_id", curriculumPlanId);
|
|
|
record.set("subject_id", subjectId);
|
|
|
record.set("times", times);
|
|
|
record.set("level", level);
|
|
|
if(COMMON.isEmpty(subjectOb.get("ID"))||"null".equals(id)){
|
|
|
batchList.add(record);
|
|
|
}else{
|
|
|
record.set("id", id);
|
|
|
CurriculumPlanModel.dao.updateCurriculumSubjectPerson(record);
|
|
|
}
|
|
|
}
|
|
|
CurriculumPlanModel.dao.batchInsertSubjectPerson(batchList);
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
resultJson.put("success", true);
|
|
|
resultJson.put("info", "保存成功");
|
|
|
return resultJson ;
|
|
|
}
|
|
|
/**
|
|
|
* 刷新科目的半分比*(选科教师课时不为0)
|
|
|
* @param subjectId
|
|
|
* @param curriculumPlanId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject updatePercentageBySubjectId(String subjectId,
|
|
|
String curriculumPlanId) {
|
|
|
List<Record> subjectTimeList = CurriculumPlanModel.dao.getSubjectTimeByIdAndSubjectIds(curriculumPlanId, subjectId);
|
|
|
JSONArray jsonArray = getSubjectTimeArray(subjectId, subjectTimeList,"1");
|
|
|
JSONObject jsonResult = new JSONObject();
|
|
|
jsonResult.put("success", true);
|
|
|
jsonResult.put("info", "操作成功");
|
|
|
jsonResult.put("result_list", jsonArray);
|
|
|
return jsonResult;
|
|
|
}
|
|
|
/**
|
|
|
* @description 导出教师课时模板
|
|
|
* @author Mr.zms
|
|
|
* @date 2019/6/24
|
|
|
* @return void
|
|
|
*/
|
|
|
public HSSFWorkbook exportTeacherTime(int curriculumPlanId) {
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
List<Record> list = CurriculumPlanModel.dao.getCurriculumTeacherList(String.valueOf(curriculumPlanId));
|
|
|
HSSFSheet sheet = wb.createSheet("课程计划教师");
|
|
|
Record headRecord = new Record();
|
|
|
list.add(0,headRecord);
|
|
|
String [] rowArray = {"subject_name","person_name","times"};
|
|
|
String [] nameArray = {"课程","教师","周课时"};
|
|
|
for (int i = 0; i < rowArray.length; i++) {
|
|
|
headRecord.set(rowArray[i],nameArray[i]);
|
|
|
}
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
HSSFRow row = sheet.createRow(i);
|
|
|
Record record = list.get(i);
|
|
|
for (int i1 = 0; i1 < rowArray.length; i1++) {
|
|
|
HSSFCell cell = row.createCell(i1);
|
|
|
//单元格内容拼接
|
|
|
if(i1 == 2 && 0 != i){
|
|
|
int times = Integer.parseInt(String.valueOf(record.get(rowArray[i1])));
|
|
|
cell.setCellValue(times);
|
|
|
}else {
|
|
|
String cellString =String.valueOf(record.get(rowArray[i1]));
|
|
|
cell.setCellValue(cellString);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return wb;
|
|
|
}
|
|
|
|
|
|
public JSONObject importTeacherTime(int curriculumPlanId, UploadFile file) {
|
|
|
//校验文件
|
|
|
JSONObject returnJson = FileUtil.CheckUploadFileObject(file.getSaveDirectory() + File.separator + file.getFileName());
|
|
|
if(!returnJson.getBooleanValue("success")){
|
|
|
return returnJson ;
|
|
|
}
|
|
|
HSSFWorkbook wb = null;
|
|
|
try {
|
|
|
wb = new HSSFWorkbook(new FileInputStream(file.getSaveDirectory() + File.separator + file.getFileName()));
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
//检验模板 是否为空
|
|
|
if(COMMON.isEmpty(wb)){
|
|
|
return SelectCourseBaseService.service.failedResult("导入模板为空");
|
|
|
}
|
|
|
//校验模板是否正确
|
|
|
HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
String sheetName = sheet.getSheetName();
|
|
|
int rowNum=sheet.getLastRowNum();
|
|
|
int columnNum=sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
if(!"课程计划教师".equals(sheetName)||rowNum<2||3!=columnNum){
|
|
|
return SelectCourseBaseService.service.failedResult("导入模板错误");
|
|
|
}
|
|
|
String uuid = COMMON.getGuid();
|
|
|
//删除临时表数据的record
|
|
|
Record delRecord = new Record().set("field_1",uuid).set("field_2",curriculumPlanId);
|
|
|
//数据插入临时表里
|
|
|
insertImportExcel(sheet,uuid,curriculumPlanId,rowNum,columnNum);
|
|
|
//获取计划的详细信息
|
|
|
Record record = new Record().set("curriculum_plan_id",curriculumPlanId);
|
|
|
Page<Record> page = CurriculumPlanModel.dao.getCurriculumPlanList(record,"1","1");
|
|
|
if(COMMON.isEmpty(page.getList())){
|
|
|
CurriculumPlanModel.dao.delImportTeacherTime(delRecord);
|
|
|
return SelectCourseBaseService.service.failedResult("未找到相应的课程计划");
|
|
|
}
|
|
|
Record curriculumRecord = page.getList().get(0);
|
|
|
//处理临时数据 获取正确的数据
|
|
|
List<Record> batchPersonList =processingData(uuid,curriculumRecord);
|
|
|
if(COMMON.isEmpty(batchPersonList)){
|
|
|
CurriculumPlanModel.dao.delImportTeacherTime(delRecord);
|
|
|
return SelectCourseBaseService.service.failedResult("导入模板不存在合格的教师信息");
|
|
|
}
|
|
|
//删除之前的教师信息
|
|
|
CurriculumPlanModel.dao.delCurriculumSubjectPerson(String.valueOf(curriculumPlanId),"","","");
|
|
|
//批量插入教师信息
|
|
|
CurriculumPlanModel.dao.batchSubjectPerson(batchPersonList);
|
|
|
// 删除临时表数据
|
|
|
CurriculumPlanModel.dao.delImportTeacherTime(delRecord);
|
|
|
returnJson.put("success",Constant.TRUE);
|
|
|
returnJson.put("info","导入成功");
|
|
|
return returnJson ;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @description 插入临时表数据
|
|
|
* @author Mr.zms
|
|
|
* @date 2019/6/24
|
|
|
* @return void
|
|
|
*/
|
|
|
private void insertImportExcel(HSSFSheet sheet,String uuid,int curriculumPlanId,int rowNum,int columnNum ){
|
|
|
List<Record> batchList = new ArrayList<>();
|
|
|
for (int i = 1; i <= rowNum; i++) {
|
|
|
Record record = new Record();
|
|
|
record.set("field_1",uuid);
|
|
|
record.set("field_2",curriculumPlanId);
|
|
|
HSSFRow row = sheet.getRow(i);
|
|
|
for (int i1 = 0; i1 < columnNum; i1++) {
|
|
|
if(COMMON.isEmpty(row)){
|
|
|
continue;
|
|
|
}
|
|
|
HSSFCell cell = row.getCell(i1);
|
|
|
if(COMMON.isEmpty(cell)){
|
|
|
continue;
|
|
|
}
|
|
|
String cellString = cell.toString();
|
|
|
String name = "field_"+(i1+3);
|
|
|
cellString = cellString.replaceAll(" ","");
|
|
|
record.set(name,cellString);
|
|
|
}
|
|
|
batchList.add(record);
|
|
|
}
|
|
|
CurriculumPlanModel.dao.batchImportExcel(batchList,columnNum+2);
|
|
|
}
|
|
|
/**
|
|
|
* @description 处理临时表数据
|
|
|
* @author Mr.zms
|
|
|
* @date 2019/6/24
|
|
|
* @return java.util.List<com.jfinal.plugin.activerecord.Record>
|
|
|
*/
|
|
|
private List<Record> processingData(String uuid ,Record curriculumRecord){
|
|
|
int bureauId = curriculumRecord.get("bureau_id");
|
|
|
String subjectIds = curriculumRecord.get("base_subject");
|
|
|
if(!COMMON.isEmpty(curriculumRecord.get("subject_ids"))){
|
|
|
subjectIds += ","+curriculumRecord.get("subject_ids") ;
|
|
|
}
|
|
|
//数据库筛选 表数据
|
|
|
List<Record> list = CurriculumPlanModel.dao.getImportTeacherTime(uuid,subjectIds,bureauId);
|
|
|
//处理模板里的数据,课时是否是数字
|
|
|
List<Record> batchPersonList = new ArrayList<>();
|
|
|
for (Record record1 : list) {
|
|
|
String times = String.valueOf(record1.get("times"));
|
|
|
if(!COMMON.isEmpty(times)&&SelectCourseBaseService.service.isNumeric(times)){
|
|
|
int time = (int)Double.parseDouble(times);
|
|
|
record1.set("times",time);
|
|
|
batchPersonList.add(record1);
|
|
|
}
|
|
|
}
|
|
|
return batchPersonList ;
|
|
|
}
|
|
|
}
|