|
@@ -0,0 +1,133 @@
|
|
|
|
|
+package com.xjrsoft.module.xycxedu.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
+import com.xjrsoft.common.enums.ArchivesStatusEnum;
|
|
|
|
|
+import com.xjrsoft.common.enums.DeleteMark;
|
|
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
|
|
+import com.xjrsoft.module.base.entity.BaseCourseSubject;
|
|
|
|
|
+import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
|
|
+import com.xjrsoft.module.base.service.IBaseCourseSubjectService;
|
|
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
|
|
+import com.xjrsoft.module.organization.service.IUserService;
|
|
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
|
|
+import com.xjrsoft.module.xycxedu.dto.AddExamSubjectScoreEnterDto;
|
|
|
|
|
+import com.xjrsoft.module.xycxedu.entity.ExamSubjectScore;
|
|
|
|
|
+import com.xjrsoft.module.xycxedu.entity.ExamSubjectScoreEnter;
|
|
|
|
|
+import com.xjrsoft.module.xycxedu.mapper.ExamSubjectScoreEnterMapper;
|
|
|
|
|
+import com.xjrsoft.module.xycxedu.service.IExamSubjectScoreEnterService;
|
|
|
|
|
+import com.xjrsoft.module.xycxedu.service.IExamSubjectScoreService;
|
|
|
|
|
+import com.xjrsoft.module.xycxedu.vo.ExamSubjectScoreEnterImportVo;
|
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+* @title: 成绩录入
|
|
|
|
|
+* @Author dzx
|
|
|
|
|
+* @Date: 2025-01-06
|
|
|
|
|
+* @Version 1.0
|
|
|
|
|
+*/
|
|
|
|
|
+@Service
|
|
|
|
|
+@AllArgsConstructor
|
|
|
|
|
+public class ExamSubjectScoreEnterServiceImpl extends MPJBaseServiceImpl<ExamSubjectScoreEnterMapper, ExamSubjectScoreEnter> implements IExamSubjectScoreEnterService {
|
|
|
|
|
+
|
|
|
|
|
+ private final IBaseCourseSubjectService courseSubjectService;
|
|
|
|
|
+ private final IUserService userService;
|
|
|
|
|
+ private final IExamSubjectScoreService scoreService;
|
|
|
|
|
+ private final IBaseClassService classService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Boolean importData(Long id, MultipartFile file) throws IOException {
|
|
|
|
|
+ ExamSubjectScoreEnter enter = this.getById(id);
|
|
|
|
|
+ List<ExamSubjectScoreEnterImportVo> dataList = EasyExcel.read(file.getInputStream()).headRowNumber(2).head(ExamSubjectScoreEnterImportVo.class).sheet().doReadSync();
|
|
|
|
|
+ List<BaseCourseSubject> classList = courseSubjectService.list(
|
|
|
|
|
+ new QueryWrapper<BaseCourseSubject>().lambda()
|
|
|
|
|
+ .eq(BaseCourseSubject::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
|
|
+ );
|
|
|
|
|
+ Map<Long, String> courseSubjectMaps = classList.stream().collect(Collectors.toMap(BaseCourseSubject::getId, BaseCourseSubject::getName));
|
|
|
|
|
+
|
|
|
|
|
+ List<String> credentialNumbers = dataList.stream().filter(x -> StrUtil.isNotEmpty(x.getCredentialNumber())).map(ExamSubjectScoreEnterImportVo::getCredentialNumber).collect(Collectors.toList());
|
|
|
|
|
+ if(credentialNumbers.isEmpty()){
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<User> userList = userService.list(
|
|
|
|
|
+ new QueryWrapper<User>().lambda()
|
|
|
|
|
+ .eq(User::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
|
|
+ .in(User::getCredentialNumber, credentialNumbers)
|
|
|
|
|
+ );
|
|
|
|
|
+ Map<String, Long> userMaps = userList.stream().collect(Collectors.toMap(User::getCredentialNumber, User::getId));
|
|
|
|
|
+
|
|
|
|
|
+ List<ExamSubjectScore> insertList = new ArrayList<>();
|
|
|
|
|
+ for (ExamSubjectScoreEnterImportVo importVo : dataList) {
|
|
|
|
|
+ insertList.add(
|
|
|
|
|
+ new ExamSubjectScore(){{
|
|
|
|
|
+ setCreateDate(new Date());
|
|
|
|
|
+ setCourseSubjectId(enter.getCourseSubjectId());
|
|
|
|
|
+ setScore(Float.parseFloat(importVo.getScore()));
|
|
|
|
|
+ setSemesterId(enter.getSemesterId());
|
|
|
|
|
+ setExamSubjectScoreEnterId(enter.getId());
|
|
|
|
|
+ setSemesterId(enter.getSemesterId());
|
|
|
|
|
+ setUserId(userMaps.get(importVo.getCredentialNumber()));
|
|
|
|
|
+ setClassRanking(importVo.getClassRanking());
|
|
|
|
|
+ setGradeRanking(importVo.getGradeRanking());
|
|
|
|
|
+ setCoursename(courseSubjectMaps.get(enter.getCourseSubjectId()));
|
|
|
|
|
+ setMilexamid(enter.getExamPlanId());
|
|
|
|
|
+ }}
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!insertList.isEmpty()){
|
|
|
|
|
+ scoreService.remove(new QueryWrapper<ExamSubjectScore>().lambda().eq(ExamSubjectScore::getExamSubjectScoreEnterId, enter.getId()));
|
|
|
|
|
+
|
|
|
|
|
+ scoreService.saveBatch(insertList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Boolean save(AddExamSubjectScoreEnterDto dto) {
|
|
|
|
|
+ ExamSubjectScoreEnter examSubjectScoreEnter = BeanUtil.toBean(dto, ExamSubjectScoreEnter.class);
|
|
|
|
|
+ examSubjectScoreEnter.setCreateDate(new Date());
|
|
|
|
|
+ String classIds = dto.getClassIds().toString().replace("[", "").replace("]", "").replace(" ", "");
|
|
|
|
|
+ examSubjectScoreEnter.setClassIds(classIds);
|
|
|
|
|
+ boolean isSuccess = this.save(examSubjectScoreEnter);
|
|
|
|
|
+ List<User> userList = userService.list(
|
|
|
|
|
+ new MPJLambdaWrapper<User>()
|
|
|
|
|
+ .select(User::getId)
|
|
|
|
|
+ .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
|
|
|
|
|
+ .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
|
|
|
|
|
+ .innerJoin(BaseStudent.class, BaseStudent::getUserId, User::getId)
|
|
|
|
|
+ .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
|
|
|
|
|
+ .eq(BaseStudent::getIsNormal, 1)
|
|
|
|
|
+ .in(BaseStudentSchoolRoll::getClassId, dto.getClassIds())
|
|
|
|
|
+ );
|
|
|
|
|
+ List<ExamSubjectScore> insertList = new ArrayList<>();
|
|
|
|
|
+ for (User importVo : userList) {
|
|
|
|
|
+ insertList.add(
|
|
|
|
|
+ new ExamSubjectScore(){{
|
|
|
|
|
+ setCreateDate(new Date());
|
|
|
|
|
+ setExamSubjectScoreEnterId(examSubjectScoreEnter.getId());
|
|
|
|
|
+ setUserId(importVo.getId());
|
|
|
|
|
+ }}
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ return isSuccess;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|