BaseStudentScholarshipApplicantServiceImpl.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.xjrsoft.module.student.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.alibaba.excel.EasyExcel;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.github.yulichang.base.MPJBaseServiceImpl;
  7. import com.xjrsoft.common.enums.DeleteMark;
  8. import com.xjrsoft.common.enums.GenderEnum;
  9. import com.xjrsoft.common.utils.VoToColumnUtil;
  10. import com.xjrsoft.module.base.entity.BaseSemester;
  11. import com.xjrsoft.module.base.service.IBaseSemesterService;
  12. import com.xjrsoft.module.student.dto.BaseStudentScholarshipApplicantCategoryPageDto;
  13. import com.xjrsoft.module.student.entity.BaseStudentScholarshipApplicant;
  14. import com.xjrsoft.module.student.entity.BaseStudentScholarshipCategory;
  15. import com.xjrsoft.module.student.mapper.BaseStudentMapper;
  16. import com.xjrsoft.module.student.mapper.BaseStudentScholarshipApplicantMapper;
  17. import com.xjrsoft.module.student.service.IBaseStudentScholarshipApplicantService;
  18. import com.xjrsoft.module.student.service.IBaseStudentScholarshipCategoryService;
  19. import com.xjrsoft.module.student.vo.BaseStudentScholarshipApplicantCategoryPageVo;
  20. import com.xjrsoft.module.student.vo.BaseStudentScholarshipApplicantPageVo;
  21. import com.xjrsoft.module.student.vo.ScholarshipApplicantImportVo;
  22. import com.xjrsoft.module.student.vo.StudentInfoVo;
  23. import lombok.AllArgsConstructor;
  24. import org.springframework.stereotype.Service;
  25. import org.springframework.web.multipart.MultipartFile;
  26. import java.io.IOException;
  27. import java.util.ArrayList;
  28. import java.util.LinkedHashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.stream.Collectors;
  32. /**
  33. * @title: 奖学金申请
  34. * @Author dzx
  35. * @Date: 2023-11-23
  36. * @Version 1.0
  37. */
  38. @Service
  39. @AllArgsConstructor
  40. public class BaseStudentScholarshipApplicantServiceImpl extends MPJBaseServiceImpl<BaseStudentScholarshipApplicantMapper, BaseStudentScholarshipApplicant> implements IBaseStudentScholarshipApplicantService {
  41. private final BaseStudentScholarshipApplicantMapper applicantMapper;
  42. private final IBaseSemesterService semesterService;
  43. private final IBaseStudentScholarshipCategoryService categoryService;
  44. @Override
  45. public Page<BaseStudentScholarshipApplicantCategoryPageVo> getScholarshiPage(Page<BaseStudentScholarshipApplicantCategoryPageDto> page, BaseStudentScholarshipApplicantCategoryPageDto dto) {
  46. Page<BaseStudentScholarshipApplicantCategoryPageVo> result = applicantMapper.getScholarshiPage(page, dto);
  47. return result;
  48. }
  49. private final BaseStudentScholarshipApplicantMapper scholarshipApplicantMapper;
  50. private final BaseStudentMapper studentMapper;
  51. @Override
  52. public Boolean processDataHandler(Long dataId) {
  53. if (dataId == null) {
  54. return false;
  55. }
  56. // 原始数据
  57. BaseStudentScholarshipApplicant scholarshipApplicant = scholarshipApplicantMapper.selectById(dataId);
  58. // 获取学生信息
  59. StudentInfoVo studentInfo = studentMapper.getStudentInfo(scholarshipApplicant.getApplicantUserId());
  60. scholarshipApplicant.setGradeName(studentInfo.getGradeName());
  61. scholarshipApplicant.setClassName(studentInfo.getClassName());
  62. scholarshipApplicant.setName(studentInfo.getStudentName());
  63. scholarshipApplicant.setStudentId(studentInfo.getStudentId());
  64. scholarshipApplicant.setGenderName(GenderEnum.getValue(studentInfo.getGender()));
  65. scholarshipApplicant.setEnrollTypeCn(studentInfo.getEnrollmentType());
  66. scholarshipApplicant.setMajorName(studentInfo.getMajorName());
  67. return updateById(scholarshipApplicant);
  68. }
  69. @Override
  70. public List<Map<String, String>> importData(MultipartFile file) throws IOException {
  71. List<ScholarshipApplicantImportVo> dataList = EasyExcel.read(file.getInputStream()).headRowNumber(2).head(ScholarshipApplicantImportVo.class).sheet().doReadSync();
  72. List<BaseStudentScholarshipApplicant> applicantList = this.list(
  73. new QueryWrapper<BaseStudentScholarshipApplicant>().lambda()
  74. .select(BaseStudentScholarshipApplicant::getId)
  75. .select(BaseStudentScholarshipApplicant.class,x -> VoToColumnUtil.fieldsToColumns(BaseStudentScholarshipApplicantPageVo.class).contains(x.getProperty()))
  76. .eq(BaseStudentScholarshipApplicant::getStatus, 1)
  77. );
  78. List<BaseSemester> semesterList = semesterService.list(
  79. new QueryWrapper<BaseSemester>().lambda()
  80. .select(BaseSemester::getId)
  81. .select(BaseSemester.class, x -> VoToColumnUtil.fieldsToColumns(BaseSemester.class).contains(x.getProperty()))
  82. .eq(BaseSemester::getDeleteMark, DeleteMark.NODELETE.getCode())
  83. );
  84. Map<String, Long> semesterMap = semesterList.stream().collect(Collectors.toMap(BaseSemester::getName, BaseSemester::getId));
  85. List<BaseStudentScholarshipCategory> categoryList = categoryService.list(
  86. new QueryWrapper<BaseStudentScholarshipCategory>().lambda()
  87. .select(BaseStudentScholarshipCategory::getId)
  88. .select(BaseStudentScholarshipCategory.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentScholarshipCategory.class).contains(x.getProperty()))
  89. .eq(BaseStudentScholarshipCategory::getDeleteMark, DeleteMark.NODELETE.getCode())
  90. );
  91. Map<String, Long> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseStudentScholarshipCategory::getName, BaseStudentScholarshipCategory::getId));
  92. List<Map<String, String>> errorList = new ArrayList<>();
  93. List<BaseStudentScholarshipApplicant> updateList = new ArrayList<>();
  94. for (ScholarshipApplicantImportVo importVo : dataList) {
  95. List<String> errorMsg = new ArrayList<>();
  96. if(StrUtil.isEmpty(importVo.getSemesterName()) || StrUtil.isEmpty(importVo.getName()) || StrUtil.isEmpty(importVo.getCredentialNumber())
  97. || StrUtil.isEmpty(importVo.getScholarshipCategoryName()) || importVo.getScholarshipLevel() == null){
  98. errorMsg.add("有未填写的列");
  99. }
  100. if(semesterMap.get(importVo.getSemesterName()) == null){
  101. errorMsg.add("学期名称填写不正确");
  102. }
  103. Long semesterId = semesterMap.get(importVo.getSemesterName());
  104. if(categoryMap.get(importVo.getScholarshipCategoryName()) == null){
  105. errorMsg.add("奖学金名称填写不正确");
  106. }
  107. Long categoryId = categoryMap.get(importVo.getScholarshipCategoryName());
  108. for (BaseStudentScholarshipApplicant applicant : applicantList) {
  109. if(applicant.getBaseSemesterId() == semesterId && importVo.getName().equals(applicant.getName()) && importVo.getCredentialNumber().equals(applicant.getStudentId())){
  110. applicant.setBaseStudentScholarshipCategoryId(categoryId);
  111. applicant.setReviewStatus(1);
  112. applicant.setScholarshipLevel(importVo.getScholarshipLevel());
  113. updateList.add(applicant);
  114. }
  115. }
  116. if(!errorMsg.isEmpty()){
  117. LinkedHashMap<String, String> map = new LinkedHashMap<>();
  118. map.put("学期名称", importVo.getSemesterName());
  119. map.put("姓名", importVo.getName());
  120. map.put("身份证号", importVo.getCredentialNumber());
  121. map.put("奖学金名称", importVo.getScholarshipCategoryName());
  122. map.put("获奖等级", importVo.getScholarshipLevel() + "");
  123. map.put("错误信息", errorMsg.toString().replace("[", "").replace("]", ""));
  124. errorList.add(map);
  125. }
  126. }
  127. if(!updateList.isEmpty()){
  128. this.updateBatchById(updateList);
  129. }
  130. return errorList;
  131. }
  132. }