|
|
@@ -1,17 +1,24 @@
|
|
|
package com.usoftchina.smartschool.school.basic.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.usoftchina.smartschool.context.BaseContextHolder;
|
|
|
import com.usoftchina.smartschool.exception.BizException;
|
|
|
import com.usoftchina.smartschool.school.basic.service.GradeService;
|
|
|
import com.usoftchina.smartschool.school.exception.BizExceptionCode;
|
|
|
+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.mapper.SysSchoolMapper;
|
|
|
import com.usoftchina.smartschool.school.po.*;
|
|
|
+import com.usoftchina.smartschool.utils.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author: guq
|
|
|
@@ -29,6 +36,9 @@ public class GradeServiceImpl implements GradeService{
|
|
|
@Autowired
|
|
|
private SysClazzMapper sysClazzMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DataImportMapper dataImportMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public TreeNode getSchoolTree(Long id) {
|
|
|
if (null == id || "0".equals(id)) {
|
|
|
@@ -70,11 +80,70 @@ public class GradeServiceImpl implements GradeService{
|
|
|
}
|
|
|
gradeNode.setChildren(classesTree);
|
|
|
gradesTree.add(gradeNode);
|
|
|
- //grade.setChildren(classes);
|
|
|
}
|
|
|
}
|
|
|
schoolTree.setChildren(gradesTree);
|
|
|
- //school.setChildren(grades);
|
|
|
return schoolTree;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void saveToFormal(Integer id, boolean update) {
|
|
|
+ if (null == id || "0".equals(id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long schoolId = BaseContextHolder.getSchoolId();
|
|
|
+ StringBuilder err = new StringBuilder();
|
|
|
+ List<DataImportDetail> details = dataImportMapper.selectDataById(id);
|
|
|
+ List<SysClazz> clazzes = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(details)) {
|
|
|
+ Map<String, List<DataImportDetail>> datas = CollectionUtils.groupBy(details, DataImportDetail::getDd_codevalue);
|
|
|
+ for (String code : datas.keySet()) {
|
|
|
+ Long grade_id = null;
|
|
|
+ SysGrade grade = sysGradeMapper.selectByName(code, schoolId);
|
|
|
+ List<DataImportDetail> data = datas.get(code);
|
|
|
+ DataImportDetail main = dataImportMapper.selectMainBycode(code, id, schoolId);
|
|
|
+ //数据验证
|
|
|
+ if (StringUtils.isEmpty(main)) {
|
|
|
+ throw new BizException(BizExceptionCode.USELESS_DATA);
|
|
|
+ }
|
|
|
+ SysGrade sysGrade = JSONObject.parseObject(main.getDd_maindata(), SysGrade.class);
|
|
|
+
|
|
|
+ //年纪不存在
|
|
|
+ if (null == grade) {
|
|
|
+ sysGrade.setSchool_id(schoolId);
|
|
|
+ sysGrade.setGrade_status(1);
|
|
|
+ sysGradeMapper.insertSelective(sysGrade);
|
|
|
+ grade_id = sysGrade.getGrade_id();
|
|
|
+ //年纪存在、需要更新
|
|
|
+ } else if (update){
|
|
|
+ grade.setSchool_id(schoolId);
|
|
|
+ grade.setGrade_status(1);
|
|
|
+ sysGradeMapper.updateByPrimaryKeySelective(grade);
|
|
|
+ grade_id = grade.getGrade_id();
|
|
|
+ //年纪存在、不需要处理
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //添加从表
|
|
|
+ if (data.size() > 0) {
|
|
|
+ for (DataImportDetail dataDetail : data) {
|
|
|
+ SysClazz detail = JSONObject.parseObject(dataDetail.getDd_detaildata(), SysClazz.class);
|
|
|
+ if (null != detail) {
|
|
|
+ detail.setGrade_id(grade_id);
|
|
|
+ clazzes.add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (err.length() > 0) {
|
|
|
+ dataImportMapper.updateDataImportError(err.toString(), id);
|
|
|
+ throw new BizException(12345, err.toString());
|
|
|
+ }
|
|
|
+ for (SysClazz cla : clazzes) {
|
|
|
+ sysClazzMapper.insertSelective(cla);
|
|
|
+ }
|
|
|
+ dataImportMapper.updateDataImport(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|