Browse Source

成绩发布增加subjectId

chenw 7 năm trước cách đây
mục cha
commit
be1747ae0b

+ 10 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/business/service/impl/ScoreServiceImpl.java

@@ -28,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author: guq
@@ -177,6 +178,8 @@ public class ScoreServiceImpl implements ScoreService{
                 scoreImport.setSi_gradeid(gradeId);
                 scoreImport.setSi_publish(0);
                 scoreMapper.insertScoreImport(scoreImport);
+                List<Subject> subjectList = subjectMapper.selectByConditon(null, schoolId);
+                List<String> subjectNameList = subjectList.stream().map(Subject::getSubject_name).collect(Collectors.toList());
                 //添加从表
                 if (data.size() > 0) {
                     for (DataImportDetail dataDetail : data) {
@@ -185,6 +188,9 @@ public class ScoreServiceImpl implements ScoreService{
                             if (StringUtils.isEmpty(detail.getSd_stu())) {
                                 throw new BizException(BizExceptionCode.USELESS_DATA);
                             }
+                            if (!subjectNameList.contains(detail.getSd_subject())) {
+                                throw new BizException(500006, "科目" + detail.getSd_subject() + "不存在");
+                            }
                             List<SysStudent> students = sysStudentMapper.selectByConditon("stu_name='" + detail.getSd_stu() + "' and clazz_id=" + classId, schoolId);
                             if (students.size() == 0) {
                                 throw new BizException(500006, "班级: " + class_ + " 不存在学生: " + detail.getSd_stu());
@@ -223,6 +229,7 @@ public class ScoreServiceImpl implements ScoreService{
         SysSchool school = sysSchoolMapper.selectByPrimaryKey(BaseContextHolder.getSchoolId());
         ScoreImport main = scoreMapper.selectByPrimaryKey(id);
         List<ScoreImportdetail> details = scoreMapper.selectDetail(id);
+        List<Subject> subjectList = subjectMapper.selectByConditon(null, school_id);
         for (ScoreImportdetail detail : details) {
             appScore = new StuScore();
             appScore.setSchool_id(school_id);
@@ -232,11 +239,14 @@ public class ScoreServiceImpl implements ScoreService{
             appScore.setGrade_id(main.getSi_gradeid());
             appScore.setGrade_name(main.getSi_grade());
             appScore.setScore_date(main.getSi_examdate());
+            Long subjectId = subjectList.stream().filter( subject -> subject.getSubject_name().equals(detail.getSd_subject())).findFirst().get().getSubject_id();
+            appScore.setSubject_id(subjectId);
             appScore.setScore_name(detail.getSd_subject());
             appScore.setScore_num(detail.getSd_score());
             appScore.setScore_scope(main.getSi_examscope());
             appScore.setStu_id(detail.getSd_stuid());
             appScore.setStu_name(detail.getSd_stu());
+            appScore.setScore_type("全年级");
             appScores.add(appScore);
         }
         scoreMapper.batchInsert(appScores);