BaseNewStudentServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. package com.xjrsoft.module.student.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.excel.EasyExcel;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.github.yulichang.base.MPJBaseServiceImpl;
  8. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  9. import com.xjrsoft.common.enums.YesOrNoEnum;
  10. import com.xjrsoft.common.utils.VoToColumnUtil;
  11. import com.xjrsoft.module.banding.vo.IdManyCountVo;
  12. import com.xjrsoft.module.base.entity.BaseMajorSet;
  13. import com.xjrsoft.module.base.service.IBaseMajorSetService;
  14. import com.xjrsoft.module.outint.vo.IdCountVo;
  15. import com.xjrsoft.module.student.dto.BaseNewStudentPageDto;
  16. import com.xjrsoft.module.student.entity.BaseNewStudent;
  17. import com.xjrsoft.module.student.mapper.BaseNewStudentMapper;
  18. import com.xjrsoft.module.student.service.IBaseNewStudentService;
  19. import com.xjrsoft.module.student.vo.BaseNewStudentPageVo;
  20. import com.xjrsoft.module.student.vo.BaseNewStudentScoreExcelVo;
  21. import com.xjrsoft.module.student.vo.EnrollmentPlanGradeVo;
  22. import com.xjrsoft.module.student.vo.EnrollmentPlanTreeVo;
  23. import com.xjrsoft.module.system.entity.DictionaryDetail;
  24. import com.xjrsoft.module.system.entity.DictionaryItem;
  25. import com.xjrsoft.module.system.mapper.DictionarydetailMapper;
  26. import lombok.AllArgsConstructor;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import java.io.IOException;
  30. import java.math.BigDecimal;
  31. import java.util.ArrayList;
  32. import java.util.Date;
  33. import java.util.HashMap;
  34. import java.util.List;
  35. import java.util.Map;
  36. import java.util.stream.Collectors;
  37. /**
  38. * @title: 新生维护信息
  39. * @Author dzx
  40. * @Date: 2024-06-27
  41. * @Version 1.0
  42. */
  43. @Service
  44. @AllArgsConstructor
  45. public class BaseNewStudentServiceImpl extends MPJBaseServiceImpl<BaseNewStudentMapper, BaseNewStudent> implements IBaseNewStudentService {
  46. private final DictionarydetailMapper dictionarydetailMapper;
  47. private final IBaseMajorSetService majorSetService;
  48. @Override
  49. public Page<BaseNewStudentPageVo> getPage(Page<BaseNewStudentPageVo> page, BaseNewStudentPageDto dto) {
  50. return this.baseMapper.getPage(page, dto);
  51. }
  52. @Override
  53. public List<EnrollmentPlanTreeVo> getEnrollmentPlanList() {
  54. return this.baseMapper.getEnrollmentPlanList();
  55. }
  56. @Override
  57. public List<EnrollmentPlanGradeVo> getGradeList() {
  58. return this.baseMapper.getGradeList();
  59. }
  60. /**
  61. * 导入数据
  62. * @param file 上传的文件
  63. * @return 未成功导入的数据
  64. */
  65. @Override
  66. public List<Map<Integer, Object>> importData(Long treeId, MultipartFile file) throws IOException {
  67. List<Map<Integer, Object>> excelDataList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(3).doReadSync();
  68. //查询字典数据
  69. List<String> codeList = new ArrayList<>();
  70. codeList.add("gender");
  71. codeList.add("student_type");
  72. codeList.add("stduy_status");
  73. List<DictionaryDetail> detailList = dictionarydetailMapper.selectJoinList(DictionaryDetail.class,
  74. new MPJLambdaWrapper<DictionaryDetail>()
  75. .select(DictionaryDetail.class, x -> VoToColumnUtil.fieldsToColumns(DictionaryDetail.class).contains(x.getProperty()))
  76. .leftJoin(DictionaryItem.class, DictionaryItem::getId, DictionaryDetail::getItemId)
  77. .in(DictionaryItem::getCode, codeList)
  78. );
  79. Map<String, String> dictMap = new HashMap<>();
  80. for (DictionaryDetail detail : detailList) {
  81. dictMap.put(detail.getName(), detail.getCode());
  82. }
  83. //查询专业数据
  84. Map<String, Long> majorSetMap = majorSetService.list(new QueryWrapper<BaseMajorSet>().lambda().eq(BaseMajorSet::getDeleteMark, 0))
  85. .stream().collect(Collectors.toMap(BaseMajorSet::getName, BaseMajorSet::getId));
  86. //查询已有的学生数据
  87. List<BaseNewStudent> baseNewStudents = this.baseMapper.selectList(
  88. new QueryWrapper<BaseNewStudent>().lambda()
  89. .eq(BaseNewStudent::getEnrollmentPlanId, treeId)
  90. );
  91. Map<String, BaseNewStudent> exeistStudent = baseNewStudents.stream().collect(Collectors.toMap(BaseNewStudent::getCredentialNumber, x -> x));
  92. List<BaseNewStudent> dataList = new ArrayList<>();
  93. List<BaseNewStudent> updateList = new ArrayList<>();
  94. List<Map<Integer, Object>> errorList = new ArrayList<>();
  95. Date createDate = new Date();
  96. for (Map<Integer, Object> objectMap : excelDataList) {
  97. //1、验证数据
  98. if(checkData(objectMap, dictMap, majorSetMap) != null){
  99. errorList.add(objectMap);
  100. continue;
  101. }
  102. BaseNewStudent student = exeistStudent.get(objectMap.get(3).toString());
  103. if(student != null && student.getStatus() == 1){
  104. objectMap.put(15, "该学生已分班并已经同步到学生基本信息,无法导入");
  105. errorList.add(objectMap);
  106. continue;
  107. }
  108. if(majorSetMap.get(objectMap.get(10).toString()) == null){
  109. objectMap.put(15, "第一志愿未匹配,无法导入");
  110. errorList.add(objectMap);
  111. continue;
  112. }
  113. if(majorSetMap.get(objectMap.get(11).toString()) == null){
  114. objectMap.put(15, "第二志愿未匹配,无法导入");
  115. errorList.add(objectMap);
  116. continue;
  117. }
  118. if(student != null && student.getStatus() == 0){
  119. student.setGraduateSchool(objectMap.get(0).toString());
  120. student.setName(objectMap.get(1).toString());
  121. student.setGender(dictMap.get(objectMap.get(2).toString()));
  122. student.setCredentialNumber(objectMap.get(3).toString());
  123. student.setHeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(4).toString())));
  124. student.setWeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(5).toString())));
  125. if(objectMap.get(6) != null){
  126. student.setGraduateClass(objectMap.get(6).toString());
  127. }
  128. student.setSource(dictMap.get(objectMap.get(7).toString()));
  129. student.setStduyStatus(dictMap.get(objectMap.get(8).toString()));
  130. student.setMobile(objectMap.get(9).toString());
  131. student.setFirstAmbition(majorSetMap.get(objectMap.get(10).toString()));
  132. student.setFirstAmbitionId(majorSetMap.get(objectMap.get(10).toString()));
  133. student.setSecondAmbition(majorSetMap.get(objectMap.get(11).toString()));
  134. student.setSecondAmbitionId(majorSetMap.get(objectMap.get(11).toString()));
  135. student.setIsAdjust(YesOrNoEnum.getCode(objectMap.get(12).toString()));
  136. if(objectMap.get(13) != null){
  137. student.setFamilyMobile(objectMap.get(13).toString());
  138. }
  139. if(objectMap.get(14) != null){
  140. student.setFamilyAddress(objectMap.get(14).toString());
  141. }
  142. if(objectMap.get(15) != null){
  143. student.setScore(BigDecimal.valueOf(Double.parseDouble(objectMap.get(15).toString())));
  144. }
  145. updateList.add(student);
  146. continue;
  147. }
  148. dataList.add(
  149. new BaseNewStudent(){{
  150. setCreateDate(createDate);
  151. setCreateUserId(StpUtil.getLoginIdAsLong());
  152. setGraduateSchool(objectMap.get(0).toString());
  153. setName(objectMap.get(1).toString());
  154. setGender(dictMap.get(objectMap.get(2).toString()));
  155. setCredentialNumber(objectMap.get(3).toString());
  156. setHeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(4).toString())));
  157. setWeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(5).toString())));
  158. if(objectMap.get(6) != null){
  159. setGraduateClass(objectMap.get(6).toString());
  160. }
  161. setSource(dictMap.get(objectMap.get(7).toString()));
  162. setStduyStatus(dictMap.get(objectMap.get(8).toString()));
  163. setMobile(objectMap.get(9).toString());
  164. setFirstAmbition(majorSetMap.get(objectMap.get(10).toString()));
  165. setFirstAmbitionId(majorSetMap.get(objectMap.get(10).toString()));
  166. setSecondAmbition(majorSetMap.get(objectMap.get(11).toString()));
  167. setSecondAmbitionId(majorSetMap.get(objectMap.get(11).toString()));
  168. setIsAdjust(YesOrNoEnum.getCode(objectMap.get(12).toString()));
  169. if(objectMap.get(13) != null){
  170. setFamilyMobile(objectMap.get(13).toString());
  171. }
  172. if(objectMap.get(14) != null){
  173. setFamilyAddress(objectMap.get(14).toString());
  174. }
  175. if(objectMap.get(15) != null){
  176. setScore(BigDecimal.valueOf(Double.parseDouble(objectMap.get(15).toString())));
  177. }
  178. setEnrollmentPlanId(treeId);
  179. setStatus(0);
  180. }}
  181. );
  182. }
  183. if(!dataList.isEmpty()){
  184. this.saveBatch(dataList);
  185. }
  186. if(!updateList.isEmpty()){
  187. this.updateBatchById(updateList);
  188. }
  189. return errorList;
  190. }
  191. @Override
  192. public List<BaseNewStudentScoreExcelVo> scoreImport(MultipartFile file) throws IOException {
  193. List<DictionaryDetail> detailList = dictionarydetailMapper.selectJoinList(DictionaryDetail.class,
  194. new MPJLambdaWrapper<DictionaryDetail>()
  195. .select(DictionaryDetail.class, x -> VoToColumnUtil.fieldsToColumns(DictionaryDetail.class).contains(x.getProperty()))
  196. .leftJoin(DictionaryItem.class, DictionaryItem::getId, DictionaryDetail::getItemId)
  197. .eq(DictionaryItem::getCode, "gender")
  198. );
  199. Map<String, String> genderMap = detailList.stream().collect(Collectors.toMap(DictionaryDetail::getName, DictionaryDetail::getCode));
  200. List<BaseNewStudentScoreExcelVo> excelDataList = EasyExcel.read(file.getInputStream()).headRowNumber(2).head(BaseNewStudentScoreExcelVo.class).sheet().doReadSync();
  201. List<BaseNewStudentScoreExcelVo> errorList = new ArrayList<>();
  202. List<BaseNewStudent> updateList = new ArrayList<>();
  203. for (BaseNewStudentScoreExcelVo el : excelDataList) {
  204. List<BaseNewStudent> studentList = this.baseMapper.selectList(
  205. new QueryWrapper<BaseNewStudent>().lambda()
  206. .eq(BaseNewStudent::getGender, genderMap.get(el.getGender()))
  207. .eq(BaseNewStudent::getGraduateSchool, el.getGraduateSchool())
  208. .eq(BaseNewStudent::getGraduateClass, el.getGraduateClass())
  209. .eq(BaseNewStudent::getName, el.getName())
  210. );
  211. if(studentList.size() != 1){
  212. errorList.add(el);
  213. continue;
  214. }
  215. BaseNewStudent student = studentList.get(0);
  216. student.setScore(el.getScore());
  217. updateList.add(student);
  218. }
  219. if(!updateList.isEmpty()){
  220. this.updateBatchById(updateList);
  221. }
  222. return errorList;
  223. }
  224. @Override
  225. public List<IdCountVo> getMajorStudent(Long gradeId, String enrollType, Integer index) {
  226. if(index == 1){
  227. return this.baseMapper.getFirstAmbitionStudentCount(gradeId, enrollType);
  228. }else if(index == 2){
  229. return this.baseMapper.getSecondAmbitionStudentCount(gradeId, enrollType);
  230. }
  231. return new ArrayList<>();
  232. }
  233. @Override
  234. public List<IdManyCountVo> getMajorStudentCount(Long bandingTaskId) {
  235. return this.baseMapper.getMajorStudentCount(bandingTaskId);
  236. }
  237. /**
  238. * 检查必填字段是否为空
  239. */
  240. Map<Integer, Object> checkData(Map<Integer, Object> objectMap, Map<String, String> dictMap, Map<String, Long> majorSetMap){
  241. //验证哪些列是空
  242. List<Integer> emptyColumn = new ArrayList<>();
  243. List<String> errorMsg = new ArrayList<>();
  244. if(objectMap.get(0) == null || "".equals(objectMap.get(0).toString())){
  245. emptyColumn.add(0);
  246. }
  247. if(objectMap.get(1) == null || "".equals(objectMap.get(1).toString())){
  248. emptyColumn.add(1);
  249. }
  250. if(objectMap.get(2) == null || "".equals(objectMap.get(2).toString())){
  251. emptyColumn.add(2);
  252. }else{
  253. if(dictMap.get(objectMap.get(2).toString()) == null){
  254. errorMsg.add("性别不正确");
  255. }
  256. }
  257. if(objectMap.get(3) == null || "".equals(objectMap.get(3).toString())){
  258. emptyColumn.add(3);
  259. }
  260. if(objectMap.get(4) == null || "".equals(objectMap.get(4).toString())){
  261. emptyColumn.add(4);
  262. }else{
  263. if(objectMap.get(4) instanceof Integer){
  264. errorMsg.add("身高请只填写数字");
  265. }
  266. }
  267. if(objectMap.get(5) == null || "".equals(objectMap.get(5).toString())){
  268. emptyColumn.add(5);
  269. }else{
  270. if(objectMap.get(5) instanceof Integer){
  271. errorMsg.add("体重请只填写数字");
  272. }
  273. }
  274. if(objectMap.get(7) == null || "".equals(objectMap.get(7).toString())){
  275. emptyColumn.add(7);
  276. }else{
  277. if(dictMap.get(objectMap.get(8).toString()) == null){
  278. errorMsg.add("学生来源填写不正确");
  279. }
  280. }
  281. if(objectMap.get(8) == null || "".equals(objectMap.get(8).toString())){
  282. emptyColumn.add(8);
  283. }else{
  284. if(dictMap.get(objectMap.get(8).toString()) == null){
  285. errorMsg.add("住宿类型填写不正确");
  286. }
  287. }
  288. if(objectMap.get(9) == null || "".equals(objectMap.get(9).toString())){
  289. emptyColumn.add(9);
  290. }
  291. if(objectMap.get(10) == null || "".equals(objectMap.get(10).toString())){
  292. emptyColumn.add(10);
  293. }else{
  294. if(majorSetMap.get(objectMap.get(10).toString()) == null){
  295. errorMsg.add("第一志愿填写不正确");
  296. }
  297. }
  298. if(objectMap.get(11) == null || "".equals(objectMap.get(11).toString())){
  299. emptyColumn.add(11);
  300. }else{
  301. if(majorSetMap.get(objectMap.get(11).toString()) == null){
  302. errorMsg.add("第二志愿填写不正确");
  303. }
  304. }
  305. if(objectMap.get(12) == null || "".equals(objectMap.get(12).toString())){
  306. emptyColumn.add(12);
  307. }else{
  308. if(!"是".equals(objectMap.get(12).toString()) && !"否".equals(objectMap.get(12).toString()) ){
  309. errorMsg.add("是否可调配请只填写“是”或“否”");
  310. }
  311. }
  312. String msg = "";
  313. if(!errorMsg.isEmpty()){
  314. msg += errorMsg.toString().replace("]", "").replace("[", "");
  315. }
  316. if(!emptyColumn.isEmpty()){
  317. msg += "以下列不能为空:" + emptyColumn.toString().replace("]", "").replace("[", "") + ";";
  318. }
  319. if(StrUtil.isNotEmpty(msg)){
  320. objectMap.put(15, msg);
  321. return objectMap;
  322. }
  323. return null;
  324. }
  325. }