BaseStudentScholarshipApplicantServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.organization.entity.User;
  13. import com.xjrsoft.module.organization.service.IUserService;
  14. import com.xjrsoft.module.student.dto.BaseStudentScholarshipApplicantCategoryPageDto;
  15. import com.xjrsoft.module.student.entity.BaseStudentScholarshipApplicant;
  16. import com.xjrsoft.module.student.entity.BaseStudentScholarshipCategory;
  17. import com.xjrsoft.module.student.entity.BaseStudentScholarshipRelease;
  18. import com.xjrsoft.module.student.mapper.BaseStudentMapper;
  19. import com.xjrsoft.module.student.mapper.BaseStudentScholarshipApplicantMapper;
  20. import com.xjrsoft.module.student.mapper.BaseStudentScholarshipReleaseMapper;
  21. import com.xjrsoft.module.student.service.IBaseStudentScholarshipApplicantService;
  22. import com.xjrsoft.module.student.service.IBaseStudentScholarshipCategoryService;
  23. import com.xjrsoft.module.student.vo.BaseStudentScholarshipApplicantCategoryPageVo;
  24. import com.xjrsoft.module.student.vo.BaseStudentScholarshipApplicantPageVo;
  25. import com.xjrsoft.module.student.vo.ScholarshipApplicantImportVo;
  26. import com.xjrsoft.module.student.vo.StudentInfoVo;
  27. import lombok.AllArgsConstructor;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import java.io.IOException;
  32. import java.util.ArrayList;
  33. import java.util.HashSet;
  34. import java.util.LinkedHashMap;
  35. import java.util.List;
  36. import java.util.Map;
  37. import java.util.Set;
  38. import java.util.stream.Collectors;
  39. /**
  40. * @title: 奖学金申请
  41. * @Author dzx
  42. * @Date: 2023-11-23
  43. * @Version 1.0
  44. */
  45. @Service
  46. @AllArgsConstructor
  47. public class BaseStudentScholarshipApplicantServiceImpl extends MPJBaseServiceImpl<BaseStudentScholarshipApplicantMapper, BaseStudentScholarshipApplicant> implements IBaseStudentScholarshipApplicantService {
  48. private final BaseStudentScholarshipApplicantMapper applicantMapper;
  49. private final IBaseSemesterService semesterService;
  50. private final IBaseStudentScholarshipCategoryService categoryService;
  51. private final IUserService userService;
  52. private final BaseStudentScholarshipApplicantMapper scholarshipApplicantMapper;
  53. private final BaseStudentMapper studentMapper;
  54. private final BaseStudentScholarshipReleaseMapper releaseMapper;
  55. @Override
  56. public Page<BaseStudentScholarshipApplicantCategoryPageVo> getScholarshiPage(Page<BaseStudentScholarshipApplicantCategoryPageDto> page, BaseStudentScholarshipApplicantCategoryPageDto dto) {
  57. Page<BaseStudentScholarshipApplicantCategoryPageVo> result = applicantMapper.getScholarshiPage(page, dto);
  58. return result;
  59. }
  60. @Override
  61. public Boolean processDataHandler(Long dataId) {
  62. if (dataId == null) {
  63. return false;
  64. }
  65. // 原始数据
  66. BaseStudentScholarshipApplicant scholarshipApplicant = scholarshipApplicantMapper.selectById(dataId);
  67. // 获取学生信息
  68. StudentInfoVo studentInfo = studentMapper.getStudentInfo(scholarshipApplicant.getApplicantUserId());
  69. scholarshipApplicant.setGradeName(studentInfo.getGradeName());
  70. scholarshipApplicant.setClassName(studentInfo.getClassName());
  71. scholarshipApplicant.setName(studentInfo.getStudentName());
  72. scholarshipApplicant.setStudentId(studentInfo.getStudentId());
  73. scholarshipApplicant.setGenderName(GenderEnum.getValue(studentInfo.getGender()));
  74. scholarshipApplicant.setEnrollTypeCn(studentInfo.getEnrollmentType());
  75. scholarshipApplicant.setMajorName(studentInfo.getMajorName());
  76. return updateById(scholarshipApplicant);
  77. }
  78. @Override
  79. public List<Map<String, String>> importData(MultipartFile file) throws IOException {
  80. List<ScholarshipApplicantImportVo> dataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(ScholarshipApplicantImportVo.class).sheet().doReadSync();
  81. List<BaseStudentScholarshipApplicant> applicantList = this.list(
  82. new QueryWrapper<BaseStudentScholarshipApplicant>().lambda()
  83. .select(BaseStudentScholarshipApplicant::getId)
  84. .select(BaseStudentScholarshipApplicant.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentScholarshipApplicantPageVo.class).contains(x.getProperty()))
  85. .eq(BaseStudentScholarshipApplicant::getStatus, 1)
  86. );
  87. List<Long> userIds = applicantList.stream().map(BaseStudentScholarshipApplicant::getApplicantUserId).collect(Collectors.toList());
  88. Map<Long, User> userMap = userService.list(new QueryWrapper<User>().lambda().in(User::getId, userIds)).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
  89. List<BaseSemester> semesterList = semesterService.list(
  90. new QueryWrapper<BaseSemester>().lambda()
  91. .select(BaseSemester::getId)
  92. .select(BaseSemester.class, x -> VoToColumnUtil.fieldsToColumns(BaseSemester.class).contains(x.getProperty()))
  93. .eq(BaseSemester::getDeleteMark, DeleteMark.NODELETE.getCode())
  94. );
  95. Map<String, Long> semesterMap = semesterList.stream().collect(Collectors.toMap(BaseSemester::getName, BaseSemester::getId));
  96. List<BaseStudentScholarshipCategory> categoryList = categoryService.list(
  97. new QueryWrapper<BaseStudentScholarshipCategory>().lambda()
  98. .select(BaseStudentScholarshipCategory::getId)
  99. .select(BaseStudentScholarshipCategory.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentScholarshipCategory.class).contains(x.getProperty()))
  100. .eq(BaseStudentScholarshipCategory::getDeleteMark, DeleteMark.NODELETE.getCode())
  101. );
  102. Map<String, BaseStudentScholarshipCategory> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseStudentScholarshipCategory::getName, x -> x));
  103. Map<String, Long> categorySemeterMap = categoryList.stream().collect(Collectors.toMap(BaseStudentScholarshipCategory::getName, BaseStudentScholarshipCategory::getBaseSemesterId));
  104. List<Map<String, String>> errorList = new ArrayList<>();
  105. List<BaseStudentScholarshipApplicant> updateList = new ArrayList<>();
  106. for (ScholarshipApplicantImportVo importVo : dataList) {
  107. Set<String> errorMsg = new HashSet<>();
  108. if (StrUtil.isEmpty(importVo.getSemesterName()) || StrUtil.isEmpty(importVo.getName()) || StrUtil.isEmpty(importVo.getCredentialNumber())
  109. || StrUtil.isEmpty(importVo.getScholarshipCategoryName()) || importVo.getScholarshipLevel() == null) {
  110. errorMsg.add("有未填写的列");
  111. }
  112. if (semesterMap.get(importVo.getSemesterName()) == null) {
  113. errorMsg.add("学期填写不正确");
  114. }
  115. Long semesterId = semesterMap.get(importVo.getSemesterName());
  116. if (categoryMap.get(importVo.getScholarshipCategoryName()) == null) {
  117. errorMsg.add("奖学金名称填写不正确");
  118. }
  119. BaseStudentScholarshipCategory category = categoryMap.get(importVo.getScholarshipCategoryName());
  120. for (BaseStudentScholarshipApplicant applicant : applicantList) {
  121. User user = userMap.get(applicant.getApplicantUserId());
  122. Long baseSemesterId = categorySemeterMap.get(importVo.getScholarshipCategoryName());
  123. if (baseSemesterId.equals(semesterId)
  124. && importVo.getName().equals(user.getName())
  125. && importVo.getCredentialNumber().equals(user.getCredentialNumber())) {
  126. applicant.setBaseStudentScholarshipCategoryId(category.getId());
  127. applicant.setReviewStatus(1);
  128. applicant.setAmount(category.getTotalAmount());
  129. applicant.setScholarshipLevel(importVo.getScholarshipLevel());
  130. updateList.add(applicant);
  131. }else{
  132. errorMsg.add("身份信息匹配不上");
  133. }
  134. }
  135. if (!errorMsg.isEmpty()) {
  136. LinkedHashMap<String, String> map = new LinkedHashMap<>();
  137. map.put("学期", importVo.getSemesterName());
  138. map.put("姓名", importVo.getName());
  139. map.put("身份证号", importVo.getCredentialNumber());
  140. map.put("奖学金名称", importVo.getScholarshipCategoryName());
  141. map.put("获奖等级", importVo.getScholarshipLevel() + "");
  142. map.put("错误信息", errorMsg.toString().replace("[", "").replace("]", ""));
  143. errorList.add(map);
  144. }
  145. }
  146. if (!updateList.isEmpty()) {
  147. this.updateBatchById(updateList);
  148. }
  149. return errorList;
  150. }
  151. /**
  152. * 每次发放时根据已经发放的金额判断这次申请的发放状态
  153. * @param scholarshipApplicant
  154. * @return
  155. */
  156. @Override
  157. @Transactional
  158. public Boolean updateReleaseStatus(BaseStudentScholarshipApplicant scholarshipApplicant) {
  159. List<BaseStudentScholarshipRelease> releaseList = releaseMapper.selectList(
  160. new QueryWrapper<BaseStudentScholarshipRelease>().lambda()
  161. .eq(BaseStudentScholarshipRelease::getDeleteMark, DeleteMark.NODELETE.getCode())
  162. .eq(BaseStudentScholarshipRelease::getBaseStudentScholarshipApplicantId, scholarshipApplicant.getId())
  163. );
  164. if(releaseList.isEmpty()){
  165. scholarshipApplicant.setReleaseStatus(0);
  166. }
  167. double sum = releaseList.stream().filter(x -> x.getAmount() != null).mapToDouble(BaseStudentScholarshipRelease::getAmount).sum();
  168. if(sum == 0){
  169. scholarshipApplicant.setReleaseStatus(0);
  170. }else if(sum < scholarshipApplicant.getAmount()){
  171. scholarshipApplicant.setReleaseStatus(1);
  172. }else if(sum == scholarshipApplicant.getAmount()){
  173. scholarshipApplicant.setReleaseStatus(2);
  174. }
  175. this.updateById(scholarshipApplicant);
  176. return true;
  177. }
  178. }