|
|
@@ -1,5 +1,6 @@
|
|
|
package com.usoftchina.smartschool.school.basic.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.usoftchina.smartschool.context.BaseContextHolder;
|
|
|
@@ -9,17 +10,19 @@ import com.usoftchina.smartschool.school.basic.service.StudentService;
|
|
|
import com.usoftchina.smartschool.school.dto.DocBaseDTO;
|
|
|
import com.usoftchina.smartschool.school.dto.ListReqDTO;
|
|
|
import com.usoftchina.smartschool.school.exception.BizExceptionCode;
|
|
|
+import com.usoftchina.smartschool.school.mapper.DataImportMapper;
|
|
|
import com.usoftchina.smartschool.school.mapper.SysStudentMapper;
|
|
|
-import com.usoftchina.smartschool.school.po.StudentForm;
|
|
|
-import com.usoftchina.smartschool.school.po.SysParents;
|
|
|
-import com.usoftchina.smartschool.school.po.SysStudent;
|
|
|
+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.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author: guq
|
|
|
@@ -31,6 +34,9 @@ public class StudentServiceImpl implements StudentService{
|
|
|
@Autowired
|
|
|
private SysStudentMapper sysStudentMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DataImportMapper dataImportMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public PageInfo<SysStudent> getListData(PageRequest page, ListReqDTO listReqDTO) {
|
|
|
PageHelper.startPage(page.getNumber(), page.getSize());
|
|
|
@@ -120,4 +126,85 @@ public class StudentServiceImpl implements StudentService{
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @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);
|
|
|
+ JSONObject json = null;
|
|
|
+ if (!CollectionUtils.isEmpty(details)) {
|
|
|
+ Map<String, List<DataImportDetail>> datas = CollectionUtils.groupBy(details, DataImportDetail::getDd_codevalue);
|
|
|
+ for (String code : datas.keySet()) {
|
|
|
+ Long stu_id = null;
|
|
|
+ SysStudent student = sysStudentMapper.selectByCode(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);
|
|
|
+ }
|
|
|
+ //转换字段
|
|
|
+ json = JSONObject.parseObject(main.getDd_maindata());
|
|
|
+ if (null != json) {
|
|
|
+ if ("男".equals(json.get("stu_sex"))) {
|
|
|
+ json.put("stu_sex", 1);
|
|
|
+ }else if ("女".equals(json.get("stu_sex"))) {
|
|
|
+ json.put("stu_sex", 2);
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ SysStudent stu = JSONObject.parseObject(json.toJSONString(), SysStudent.class);
|
|
|
+
|
|
|
+ //学生不存在
|
|
|
+ if (null == student) {
|
|
|
+ stu.setSchool_id(schoolId);
|
|
|
+ stu.setStu_status(1);
|
|
|
+ sysStudentMapper.insertSelective(stu);
|
|
|
+ stu_id = stu.getStu_id();
|
|
|
+ //学生存在、需要更新
|
|
|
+ } else if (update){
|
|
|
+ student.setSchool_id(schoolId);
|
|
|
+ student.setStu_status(1);
|
|
|
+ sysStudentMapper.updateByPrimaryKeySelective(student);
|
|
|
+ stu_id = student.getStu_id();
|
|
|
+ //年纪存在、不需要处理
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //添加从表
|
|
|
+ if (data.size() > 0) {
|
|
|
+ for (DataImportDetail dataDetail : data) {
|
|
|
+ StudentRelation detail = JSONObject.parseObject(dataDetail.getDd_detaildata(), StudentRelation.class);
|
|
|
+ if (null != detail) {
|
|
|
+ //保证家长已经插入
|
|
|
+ SysParents parent = sysStudentMapper.selectParentByPhone(detail.getPa_phone(), schoolId);
|
|
|
+ if (null == parent) {
|
|
|
+ parent = new SysParents();
|
|
|
+ parent.setSchool_id(schoolId);
|
|
|
+ parent.setParents_name(detail.getParents_name());
|
|
|
+ parent.setPa_phone(detail.getPa_phone());
|
|
|
+ parent.setParents_status(1);
|
|
|
+ sysStudentMapper.insertparent(parent);
|
|
|
+ }
|
|
|
+ //插入学生与父母的关系
|
|
|
+ sysStudentMapper.insertrelationDetail(stu_id, parent.getParent_id(), detail.getPs_relation());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|