|
|
@@ -9,16 +9,20 @@ import com.usoftchina.smartschool.school.basic.service.CurriculumService;
|
|
|
import com.usoftchina.smartschool.school.dto.*;
|
|
|
import com.usoftchina.smartschool.school.exception.BizExceptionCode;
|
|
|
import com.usoftchina.smartschool.school.mapper.CurriculumMapper;
|
|
|
+import com.usoftchina.smartschool.school.mapper.DataImportMapper;
|
|
|
import com.usoftchina.smartschool.school.mapper.SysClazzMapper;
|
|
|
+import com.usoftchina.smartschool.school.mapper.SysGradeMapper;
|
|
|
+import com.usoftchina.smartschool.school.po.DataImportDetail;
|
|
|
import com.usoftchina.smartschool.school.po.SubjectDO;
|
|
|
import com.usoftchina.smartschool.school.wxschool.utils.ObjectUtils;
|
|
|
import com.usoftchina.smartschool.school.wxschool.utils.StringUtils;
|
|
|
import com.usoftchina.smartschool.utils.CollectionUtils;
|
|
|
+import com.usoftchina.smartschool.utils.JsonUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.Map.Entry;
|
|
|
|
|
|
/**
|
|
|
* @Description 课程表
|
|
|
@@ -30,7 +34,12 @@ public class CurriculumServiceImpl implements CurriculumService {
|
|
|
|
|
|
@Autowired
|
|
|
private CurriculumMapper curriculumMapper;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private DataImportMapper dataImportMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysGradeMapper sysGradeMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysClazzMapper sysClazzMapper;
|
|
|
|
|
|
@Override
|
|
|
public PageInfo<CurriculumListDTO> selectAll(PageRequest page, ListReqDTO listReqDTO) {
|
|
|
@@ -123,6 +132,8 @@ public class CurriculumServiceImpl implements CurriculumService {
|
|
|
//查询课表科目信息
|
|
|
List<SubjectDO> subjectDOList = curriculumMapper.selectSubject(BaseContextHolder.getSchoolId());
|
|
|
if (null != main.getId() && 0 != main.getId()){
|
|
|
+ main.setCreateTime(new Date());
|
|
|
+ main.setCreatorName(BaseContextHolder.getUserName());
|
|
|
//保存主表
|
|
|
curriculumMapper.insertSelective(main);
|
|
|
Long mId = main.getId();
|
|
|
@@ -173,4 +184,60 @@ public class CurriculumServiceImpl implements CurriculumService {
|
|
|
public void deleteDetail(Long id) {
|
|
|
curriculumMapper.deleteDetail(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveToFormal(Integer id, boolean update){
|
|
|
+ if (null == id || "0".equals(id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long schoolId = BaseContextHolder.getSchoolId();
|
|
|
+ List<DataImportDetail> details = dataImportMapper.selectDataById(id);
|
|
|
+ List<CurriculumDTO> mainList = new ArrayList<CurriculumDTO>();
|
|
|
+ if (!CollectionUtils.isEmpty(details)){
|
|
|
+ Map<String, List<DataImportDetail>> datas = CollectionUtils.groupBy(details, DataImportDetail::getDd_codevalue);
|
|
|
+ Iterator<Entry<String, List<DataImportDetail>>> it = datas.entrySet().iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ Entry<String, List<DataImportDetail>> entry = it.next();
|
|
|
+ String key = entry.getKey();
|
|
|
+ //校验课程班级格式是否符合: 年级#班级
|
|
|
+ if (StringUtils.isEmpty(key) || !key.contains("#")){
|
|
|
+ throw new BizException(BizExceptionCode.USELESS_DATA);
|
|
|
+ }
|
|
|
+ String[] keys = key.split("#");
|
|
|
+ String grade = keys[0], clazz = keys[1];
|
|
|
+ Long gradeId = sysGradeMapper.selectByName(grade, schoolId).getGrade_id();
|
|
|
+ Long clazzId = sysClazzMapper.selectByName(clazz, gradeId).getClazz_id();
|
|
|
+ List<DataImportDetail> dataImportDetailList = entry.getValue();
|
|
|
+ if (dataImportDetailList.size() > 0) {
|
|
|
+ for (DataImportDetail dataImportDetail : dataImportDetailList) {
|
|
|
+ DataImportDetail singleDataImportDetail = dataImportMapper.selectMainBycode(key, id, schoolId);
|
|
|
+ CurriculumDTO curriculumDTO = JsonUtils.fromJsonString(singleDataImportDetail.getDd_maindata(), CurriculumDTO.class);
|
|
|
+ List<CurriculumDetailDTO> curriculumDetailDTOList = JsonUtils.fromJsonArray(dataImportDetail.getDd_detaildata(), CurriculumDetailDTO.class);
|
|
|
+ //更新数据,将中文转换成ID
|
|
|
+ curriculumDTO.setStatus("1");
|
|
|
+ curriculumDTO.setCreateTime(new Date());
|
|
|
+ curriculumDTO.setClazzId(String.valueOf(clazzId));
|
|
|
+ //插入主表数据
|
|
|
+ curriculumMapper.insertSelective(curriculumDTO);
|
|
|
+ Long mainId = curriculumDTO.getId();
|
|
|
+ //插入明细表数据
|
|
|
+ //1. 替换课程名称为ID
|
|
|
+ List<SubjectDO> subjectDOList = curriculumMapper.selectSubject(schoolId);
|
|
|
+ for (SubjectDO subjectDO : subjectDOList){
|
|
|
+ curriculumDetailDTOList.forEach(curriculumDetailDTO -> {
|
|
|
+ curriculumDetailDTO.setmId(mainId);
|
|
|
+ curriculumDetailDTO.setStatus(1);
|
|
|
+ curriculumDetailDTO.setSchoolId(schoolId.intValue());
|
|
|
+ curriculumDetailDTO.setClazzId(clazzId.intValue());
|
|
|
+ convertToId(curriculumDetailDTO, subjectDO);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //2. 插入
|
|
|
+ curriculumMapper.insertDetailSelective(curriculumDetailDTOList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dataImportMapper.updateDataImport(id);
|
|
|
+ }
|
|
|
}
|