StudentManagerServiceImpl.java 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. package com.xjrsoft.module.student.service.impl;
  2. import cn.dev33.satoken.secure.BCrypt;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.bean.BeanUtil;
  5. import cn.hutool.core.collection.CollectionUtil;
  6. import cn.hutool.core.convert.Convert;
  7. import cn.hutool.core.util.IdUtil;
  8. import cn.hutool.core.util.StrUtil;
  9. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  10. import com.baomidou.mybatisplus.core.toolkit.StringPool;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  13. import com.github.yulichang.base.MPJBaseServiceImpl;
  14. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  15. import com.xjrsoft.common.constant.GlobalConstant;
  16. import com.xjrsoft.common.enums.DeleteMark;
  17. import com.xjrsoft.common.enums.GenderDictionaryEnum;
  18. import com.xjrsoft.common.enums.RoleEnum;
  19. import com.xjrsoft.common.enums.YesOrNoEnum;
  20. import com.xjrsoft.common.exception.MyException;
  21. import com.xjrsoft.common.utils.RedisUtil;
  22. import com.xjrsoft.common.utils.TreeUtil;
  23. import com.xjrsoft.config.CommonPropertiesConfig;
  24. import com.xjrsoft.module.base.entity.BaseClass;
  25. import com.xjrsoft.module.base.entity.BaseGrade;
  26. import com.xjrsoft.module.base.entity.BaseMajorSet;
  27. import com.xjrsoft.module.base.mapper.BaseClassMapper;
  28. import com.xjrsoft.module.base.mapper.BaseGradeMapper;
  29. import com.xjrsoft.module.base.mapper.BaseMajorSetMapper;
  30. import com.xjrsoft.module.base.service.IBaseClassService;
  31. import com.xjrsoft.module.base.service.IBaseGradeService;
  32. import com.xjrsoft.module.organization.entity.Department;
  33. import com.xjrsoft.module.organization.entity.User;
  34. import com.xjrsoft.module.organization.entity.UserDeptRelation;
  35. import com.xjrsoft.module.organization.entity.UserRoleRelation;
  36. import com.xjrsoft.module.organization.mapper.UserDeptRelationMapper;
  37. import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
  38. import com.xjrsoft.module.organization.service.IDepartmentService;
  39. import com.xjrsoft.module.organization.service.IUserDeptRelationService;
  40. import com.xjrsoft.module.organization.service.IUserService;
  41. import com.xjrsoft.module.student.dto.AddBaseStudentUserDto;
  42. import com.xjrsoft.module.student.dto.BaseStudentUserPageDto;
  43. import com.xjrsoft.module.student.dto.UpdateBaseStudentUserDto;
  44. import com.xjrsoft.module.student.entity.BaseClassMajorSet;
  45. import com.xjrsoft.module.student.entity.BaseMajor;
  46. import com.xjrsoft.module.student.entity.BaseStudent;
  47. import com.xjrsoft.module.student.entity.BaseStudentContact;
  48. import com.xjrsoft.module.student.entity.BaseStudentFamily;
  49. import com.xjrsoft.module.student.entity.BaseStudentFamilyMember;
  50. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  51. import com.xjrsoft.module.student.entity.BaseStudentSubsidize;
  52. import com.xjrsoft.module.student.entity.BaseStudentUser;
  53. import com.xjrsoft.module.student.mapper.BaseStudentFamilyMapper;
  54. import com.xjrsoft.module.student.mapper.BaseStudentFamilyMemberMapper;
  55. import com.xjrsoft.module.student.mapper.BaseStudentMapper;
  56. import com.xjrsoft.module.student.mapper.BaseStudentUserMapper;
  57. import com.xjrsoft.module.student.service.IBaseMajorService;
  58. import com.xjrsoft.module.student.service.IBaseStudentContactService;
  59. import com.xjrsoft.module.student.service.IBaseStudentFamilyService;
  60. import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
  61. import com.xjrsoft.module.student.service.IBaseStudentService;
  62. import com.xjrsoft.module.student.service.IBaseStudentSubsidizeService;
  63. import com.xjrsoft.module.student.service.IStudentManagerService;
  64. import com.xjrsoft.module.student.vo.BaseClassMajorSetVo;
  65. import com.xjrsoft.module.student.vo.BaseDepMajorGradeClassStudenTreeVo;
  66. import com.xjrsoft.module.student.vo.BaseStudentClassVo;
  67. import com.xjrsoft.module.student.vo.BaseStudentUserPageVo;
  68. import com.xjrsoft.module.student.vo.PersonalPortraitPersonalInfoVo;
  69. import com.xjrsoft.module.student.vo.StudentPersonalInfoVo;
  70. import com.xjrsoft.module.system.entity.Area;
  71. import com.xjrsoft.module.system.entity.DictionaryDetail;
  72. import com.xjrsoft.module.system.entity.DictionaryItem;
  73. import com.xjrsoft.module.system.mapper.DictionarydetailMapper;
  74. import com.xjrsoft.module.system.mapper.DictionaryitemMapper;
  75. import com.xjrsoft.module.system.service.IAreaService;
  76. import lombok.AllArgsConstructor;
  77. import org.apache.commons.lang3.StringUtils;
  78. import org.springframework.beans.BeanUtils;
  79. import org.springframework.stereotype.Service;
  80. import org.springframework.transaction.annotation.Transactional;
  81. import org.springframework.web.multipart.MultipartFile;
  82. import java.io.IOException;
  83. import java.text.ParseException;
  84. import java.text.SimpleDateFormat;
  85. import java.time.LocalDate;
  86. import java.time.LocalDateTime;
  87. import java.time.format.DateTimeFormatter;
  88. import java.time.format.DateTimeParseException;
  89. import java.util.ArrayList;
  90. import java.util.Arrays;
  91. import java.util.Base64;
  92. import java.util.HashMap;
  93. import java.util.HashSet;
  94. import java.util.List;
  95. import java.util.Map;
  96. import java.util.Objects;
  97. import java.util.Set;
  98. import java.util.concurrent.CompletableFuture;
  99. import java.util.stream.Collectors;
  100. @Service
  101. @AllArgsConstructor
  102. public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUserMapper, BaseStudentUser> implements IStudentManagerService {
  103. private final com.xjrsoft.module.student.mapper.BaseStudentUserMapper studentbaseManagerBaseStudentUserMapper;
  104. private final IBaseStudentService baseStudentService;
  105. private final BaseClassMapper baseClassMapper;
  106. private final IBaseStudentContactService studentContactService;
  107. private final BaseStudentFamilyMapper familyMapper;
  108. private final BaseStudentFamilyMemberMapper familyMemberMapper;
  109. private final UserRoleRelationMapper userRoleRelationMapper;
  110. private final DictionarydetailMapper dictionarydetailMapper;
  111. private final IAreaService areaService;
  112. private final BaseGradeMapper baseGradeMapper;
  113. private final BaseMajorSetMapper baseMajorSetMapper;
  114. private final DictionaryitemMapper dictionaryitemMapper;
  115. private final IBaseStudentSchoolRollService schoolRollService;
  116. private final IBaseStudentSubsidizeService subsidizeService;
  117. private final IBaseStudentFamilyService familyService;
  118. private final BaseStudentMapper baseStudentMapper;
  119. private final IUserDeptRelationService userDeptRelationService;
  120. private final RedisUtil redisUtil;
  121. private final UserDeptRelationMapper userDeptRelationMapper;
  122. private final IUserService userService;
  123. private final CommonPropertiesConfig propertiesConfig;
  124. private final IBaseGradeService baseGradeService;
  125. private final IDepartmentService baseDeparmentService;
  126. private final IBaseMajorService baseMajorService;
  127. private final IBaseClassService baseClassService;
  128. @Override
  129. @Transactional(rollbackFor = Exception.class)
  130. public Long add(AddBaseStudentUserDto dto){
  131. BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
  132. baseStudentUser.setCode(dto.getUserName());
  133. // 用户身份证后6位作为默认密码
  134. baseStudentUser.setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
  135. studentbaseManagerBaseStudentUserMapper.insert(baseStudentUser);
  136. for (BaseStudent baseStudent : baseStudentUser.getBaseStudentList()) {
  137. baseStudent.setUserId(baseStudentUser.getId());
  138. baseStudentService.save(baseStudent);
  139. }
  140. for (BaseStudentContact baseStudentContact : baseStudentUser.getBaseStudentContactList()) {
  141. baseStudentContact.setUserId(baseStudentUser.getId());
  142. studentContactService.save(baseStudentContact);
  143. }
  144. for (BaseStudentFamily BaseStudentFamily : baseStudentUser.getBaseStudentFamilyList()) {
  145. BaseStudentFamily.setUserId(baseStudentUser.getId());
  146. familyMapper.insert(BaseStudentFamily);
  147. }
  148. for (BaseStudentFamilyMember BaseStudentFamilyMember : baseStudentUser.getBaseStudentFamilyMemberList()) {
  149. BaseStudentFamilyMember.setUserId(baseStudentUser.getId());
  150. familyMemberMapper.insert(BaseStudentFamilyMember);
  151. }
  152. for (BaseStudentSchoolRoll baseStudentSchoolRoll : baseStudentUser.getBaseStudentSchoolRollList()) {
  153. baseStudentSchoolRoll.setUserId(baseStudentUser.getId());
  154. schoolRollService.save(baseStudentSchoolRoll);
  155. }
  156. for (BaseStudentSubsidize baseStudentSubsidize : baseStudentUser.getBaseStudentSubsidizeList()) {
  157. baseStudentSubsidize.setUserId(baseStudentUser.getId());
  158. subsidizeService.save(baseStudentSubsidize);
  159. }
  160. List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
  161. if (StrUtil.isNotBlank(dto.getDepartmentIds())) {
  162. String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
  163. List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
  164. if (CollectionUtil.isNotEmpty(departmentIds)) {
  165. for (Long deptId : departmentIds) {
  166. //将用户所选部门保存到关联表中
  167. UserDeptRelation userDeptRelation = new UserDeptRelation();
  168. userDeptRelation.setUserId(baseStudentUser.getId());
  169. userDeptRelation.setDeptId(deptId);
  170. userDeptRelationList.add(userDeptRelation);
  171. }
  172. }
  173. userDeptRelationService.saveBatch(userDeptRelationList);
  174. }
  175. // 添加角色
  176. UserRoleRelation userRoleRelation = new UserRoleRelation();
  177. userRoleRelation.setUserId(baseStudentUser.getId());
  178. userRoleRelation.setRoleId(RoleEnum.STUDENT.getCode());
  179. userRoleRelationMapper.insert(userRoleRelation);
  180. CompletableFuture.runAsync(() -> {
  181. List<User> list = userService.list();
  182. redisUtil.set(GlobalConstant.USER_CACHE_KEY, list);
  183. List<UserDeptRelation> deptRelationList = userDeptRelationMapper.selectList(Wrappers.lambdaQuery(UserDeptRelation.class));
  184. redisUtil.set(GlobalConstant.USER_DEPT_RELATION_CACHE_KEY, deptRelationList);
  185. List<UserRoleRelation> userRoleRelationList = userRoleRelationMapper.selectList(Wrappers.lambdaQuery(UserRoleRelation.class));
  186. redisUtil.set(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, userRoleRelationList);
  187. });
  188. return baseStudentUser.getId();
  189. }
  190. @Override
  191. @Transactional(rollbackFor = Exception.class)
  192. public Boolean update(UpdateBaseStudentUserDto dto){
  193. BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
  194. baseStudentUser.setCode(dto.getUserName());
  195. studentbaseManagerBaseStudentUserMapper.updateById(baseStudentUser);
  196. //先删除再新增
  197. userDeptRelationService.remove(Wrappers.<UserDeptRelation>query().lambda().eq(UserDeptRelation::getUserId, baseStudentUser.getId()));
  198. List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
  199. if (StrUtil.isNotBlank(dto.getDepartmentIds())) {
  200. String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
  201. List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
  202. if (CollectionUtil.isNotEmpty(departmentIds)) {
  203. for (Long deptId : departmentIds) {
  204. //将用户所选部门保存到关联表中
  205. UserDeptRelation userDeptRelation = new UserDeptRelation();
  206. userDeptRelation.setUserId(baseStudentUser.getId());
  207. userDeptRelation.setDeptId(deptId);
  208. userDeptRelationList.add(userDeptRelation);
  209. }
  210. }
  211. userDeptRelationService.saveBatch(userDeptRelationList);
  212. }
  213. //********************************* BaseStudent 增删改 开始 *******************************************/
  214. {
  215. // 查出所有子级的id
  216. List<BaseStudent> baseStudentList = baseStudentService.list(Wrappers.lambdaQuery(BaseStudent.class).eq(BaseStudent::getUserId, baseStudentUser.getId()).select(BaseStudent::getId));
  217. List<Long> baseStudentIds = baseStudentList.stream().map(BaseStudent::getId).collect(Collectors.toList());
  218. //原有子表单 没有被删除的主键
  219. List<Long> baseStudentOldIds = baseStudentUser.getBaseStudentList().stream().map(BaseStudent::getId).filter(Objects::nonNull).collect(Collectors.toList());
  220. //找到需要删除的id
  221. List<Long> baseStudentRemoveIds = baseStudentIds.stream().filter(item -> !baseStudentOldIds.contains(item)).collect(Collectors.toList());
  222. for (BaseStudent baseStudent : baseStudentUser.getBaseStudentList()) {
  223. //如果不等于空则修改
  224. if (baseStudent.getId() != null) {
  225. baseStudentService.updateById(baseStudent);
  226. }
  227. //如果等于空 则新增
  228. else {
  229. //已经不存在的id 删除
  230. baseStudent.setUserId(baseStudentUser.getId());
  231. baseStudentService.save(baseStudent);
  232. }
  233. }
  234. //已经不存在的id 删除
  235. if (baseStudentRemoveIds.size() > 0) {
  236. baseStudentService.removeBatchByIds(baseStudentRemoveIds);
  237. }
  238. }
  239. //********************************* BaseStudent 增删改 结束 *******************************************/
  240. //********************************* BaseStudentContact 增删改 开始 *******************************************/
  241. {
  242. // 查出所有子级的id
  243. List<BaseStudentContact> baseStudentContactList = studentContactService.list(Wrappers.lambdaQuery(BaseStudentContact.class).eq(BaseStudentContact::getUserId, baseStudentUser.getId()).select(BaseStudentContact::getId));
  244. List<Long> baseStudentContactIds = baseStudentContactList.stream().map(BaseStudentContact::getId).collect(Collectors.toList());
  245. //原有子表单 没有被删除的主键
  246. List<Long> baseStudentContactOldIds = baseStudentUser.getBaseStudentContactList().stream().map(BaseStudentContact::getId).filter(Objects::nonNull).collect(Collectors.toList());
  247. //找到需要删除的id
  248. List<Long> baseStudentContactRemoveIds = baseStudentContactIds.stream().filter(item -> !baseStudentContactOldIds.contains(item)).collect(Collectors.toList());
  249. for (BaseStudentContact baseStudentContact : baseStudentUser.getBaseStudentContactList()) {
  250. //如果不等于空则修改
  251. if (baseStudentContact.getId() != null) {
  252. studentContactService.updateById(baseStudentContact);
  253. }
  254. //如果等于空 则新增
  255. else {
  256. //已经不存在的id 删除
  257. baseStudentContact.setUserId(baseStudentUser.getId());
  258. studentContactService.save(baseStudentContact);
  259. }
  260. }
  261. //已经不存在的id 删除
  262. if (baseStudentContactRemoveIds.size() > 0) {
  263. studentContactService.removeBatchByIds(baseStudentContactRemoveIds);
  264. }
  265. }
  266. //********************************* BaseStudentContact 增删改 结束 *******************************************/
  267. //********************************* BaseStudentFamily 增删改 开始 *******************************************/
  268. {
  269. // 查出所有子级的id
  270. List<BaseStudentFamily> BaseStudentFamilyList = familyMapper.selectList(Wrappers.lambdaQuery(BaseStudentFamily.class).eq(BaseStudentFamily::getUserId, baseStudentUser.getId()).select(BaseStudentFamily::getId));
  271. List<Long> BaseStudentFamilyIds = BaseStudentFamilyList.stream().map(BaseStudentFamily::getId).collect(Collectors.toList());
  272. //原有子表单 没有被删除的主键
  273. List<Long> BaseStudentFamilyOldIds = baseStudentUser.getBaseStudentFamilyList().stream().map(BaseStudentFamily::getId).filter(Objects::nonNull).collect(Collectors.toList());
  274. //找到需要删除的id
  275. List<Long> BaseStudentFamilyRemoveIds = BaseStudentFamilyIds.stream().filter(item -> !BaseStudentFamilyOldIds.contains(item)).collect(Collectors.toList());
  276. for (BaseStudentFamily BaseStudentFamily : baseStudentUser.getBaseStudentFamilyList()) {
  277. //如果不等于空则修改
  278. if (BaseStudentFamily.getId() != null) {
  279. familyMapper.updateById(BaseStudentFamily);
  280. }
  281. //如果等于空 则新增
  282. else {
  283. //已经不存在的id 删除
  284. BaseStudentFamily.setUserId(baseStudentUser.getId());
  285. familyMapper.insert(BaseStudentFamily);
  286. }
  287. }
  288. //已经不存在的id 删除
  289. if (BaseStudentFamilyRemoveIds.size() > 0) {
  290. familyMapper.deleteBatchIds(BaseStudentFamilyRemoveIds);
  291. }
  292. }
  293. //********************************* BaseStudentFamily 增删改 结束 *******************************************/
  294. //********************************* BaseStudentFamilyMember 增删改 开始 *******************************************/
  295. {
  296. // 查出所有子级的id
  297. List<BaseStudentFamilyMember> BaseStudentFamilyMemberList = familyMemberMapper.selectList(Wrappers.lambdaQuery(BaseStudentFamilyMember.class).eq(BaseStudentFamilyMember::getUserId, baseStudentUser.getId()).select(BaseStudentFamilyMember::getId));
  298. List<Long> BaseStudentFamilyMemberIds = BaseStudentFamilyMemberList.stream().map(BaseStudentFamilyMember::getId).collect(Collectors.toList());
  299. //原有子表单 没有被删除的主键
  300. List<Long> BaseStudentFamilyMemberOldIds = baseStudentUser.getBaseStudentFamilyMemberList().stream().map(BaseStudentFamilyMember::getId).filter(Objects::nonNull).collect(Collectors.toList());
  301. //找到需要删除的id
  302. List<Long> BaseStudentFamilyMemberRemoveIds = BaseStudentFamilyMemberIds.stream().filter(item -> !BaseStudentFamilyMemberOldIds.contains(item)).collect(Collectors.toList());
  303. for (BaseStudentFamilyMember BaseStudentFamilyMember : baseStudentUser.getBaseStudentFamilyMemberList()) {
  304. //如果不等于空则修改
  305. if (BaseStudentFamilyMember.getId() != null) {
  306. familyMemberMapper.updateById(BaseStudentFamilyMember);
  307. }
  308. //如果等于空 则新增
  309. else {
  310. //已经不存在的id 删除
  311. BaseStudentFamilyMember.setUserId(baseStudentUser.getId());
  312. familyMemberMapper.insert(BaseStudentFamilyMember);
  313. }
  314. }
  315. //已经不存在的id 删除
  316. if (BaseStudentFamilyMemberRemoveIds.size() > 0) {
  317. familyMemberMapper.deleteBatchIds(BaseStudentFamilyMemberRemoveIds);
  318. }
  319. }
  320. //********************************* BaseStudentFamilyMember 增删改 结束 *******************************************/
  321. //********************************* StudentSchoolRoll 增删改 开始 *******************************************/
  322. {
  323. // 查出所有子级的id
  324. List<BaseStudentSchoolRoll> baseStudentSchoolRollList = schoolRollService.list(Wrappers.lambdaQuery(BaseStudentSchoolRoll.class).eq(BaseStudentSchoolRoll::getUserId, baseStudentUser.getId()).select(BaseStudentSchoolRoll::getId));
  325. List<Long> baseStudentSchoolRollIds = baseStudentSchoolRollList.stream().map(BaseStudentSchoolRoll::getId).collect(Collectors.toList());
  326. //原有子表单 没有被删除的主键
  327. List<Long> baseStudentSchoolRollOldIds = baseStudentUser.getBaseStudentSchoolRollList().stream().map(BaseStudentSchoolRoll::getId).filter(Objects::nonNull).collect(Collectors.toList());
  328. //找到需要删除的id
  329. List<Long> baseStudentSchoolRollRemoveIds = baseStudentSchoolRollIds.stream().filter(item -> !baseStudentSchoolRollOldIds.contains(item)).collect(Collectors.toList());
  330. for (BaseStudentSchoolRoll baseStudentSchoolRoll : baseStudentUser.getBaseStudentSchoolRollList()) {
  331. //如果不等于空则修改
  332. if (baseStudentSchoolRoll.getId() != null) {
  333. schoolRollService.updateById(baseStudentSchoolRoll);
  334. }
  335. //如果等于空 则新增
  336. else {
  337. //已经不存在的id 删除
  338. baseStudentSchoolRoll.setUserId(baseStudentUser.getId());
  339. schoolRollService.save(baseStudentSchoolRoll);
  340. }
  341. }
  342. //已经不存在的id 删除
  343. if (baseStudentSchoolRollRemoveIds.size() > 0) {
  344. schoolRollService.removeBatchByIds(baseStudentSchoolRollRemoveIds);
  345. }
  346. }
  347. //********************************* StudentSchoolRoll 增删改 结束 *******************************************/
  348. //********************************* BaseStudentSubsidize 增删改 开始 *******************************************/
  349. {
  350. // 查出所有子级的id
  351. List<BaseStudentSubsidize> baseStudentSubsidizeList = subsidizeService.list(Wrappers.lambdaQuery(BaseStudentSubsidize.class).eq(BaseStudentSubsidize::getUserId, baseStudentUser.getId()).select(BaseStudentSubsidize::getId));
  352. List<Long> baseStudentSubsidizeIds = baseStudentSubsidizeList.stream().map(BaseStudentSubsidize::getId).collect(Collectors.toList());
  353. //原有子表单 没有被删除的主键
  354. List<Long> baseStudentSubsidizeOldIds = baseStudentUser.getBaseStudentSubsidizeList().stream().map(BaseStudentSubsidize::getId).filter(Objects::nonNull).collect(Collectors.toList());
  355. //找到需要删除的id
  356. List<Long> baseStudentSubsidizeRemoveIds = baseStudentSubsidizeIds.stream().filter(item -> !baseStudentSubsidizeOldIds.contains(item)).collect(Collectors.toList());
  357. for (BaseStudentSubsidize BaseStudentEducation : baseStudentUser.getBaseStudentSubsidizeList()) {
  358. //如果不等于空则修改
  359. if (BaseStudentEducation.getId() != null) {
  360. subsidizeService.updateById(BaseStudentEducation);
  361. }
  362. //如果等于空 则新增
  363. else {
  364. //已经不存在的id 删除
  365. BaseStudentEducation.setUserId(baseStudentUser.getId());
  366. subsidizeService.save(BaseStudentEducation);
  367. }
  368. }
  369. //已经不存在的id 删除
  370. if (baseStudentSubsidizeRemoveIds.size() > 0) {
  371. subsidizeService.removeBatchByIds(baseStudentSubsidizeRemoveIds);
  372. }
  373. }
  374. //********************************* BaseStudentEducation 增删改 结束 *******************************************/
  375. return true;
  376. }
  377. @Override
  378. @Transactional(rollbackFor = Exception.class)
  379. public Boolean delete(List<Long> ids) {
  380. studentbaseManagerBaseStudentUserMapper.deleteBatchIds(ids);
  381. baseStudentService.remove(Wrappers.lambdaQuery(BaseStudent.class).in(BaseStudent::getUserId, ids));
  382. studentContactService.remove(Wrappers.lambdaQuery(BaseStudentContact.class).in(BaseStudentContact::getUserId, ids));
  383. familyMapper.delete(Wrappers.lambdaQuery(BaseStudentFamily.class).in(BaseStudentFamily::getUserId, ids));
  384. familyMemberMapper.delete(Wrappers.lambdaQuery(BaseStudentFamilyMember.class).in(BaseStudentFamilyMember::getUserId, ids));
  385. schoolRollService.remove(Wrappers.lambdaQuery(BaseStudentSchoolRoll.class).in(BaseStudentSchoolRoll::getUserId, ids));
  386. subsidizeService.remove(Wrappers.lambdaQuery(BaseStudentSubsidize.class).in(BaseStudentSubsidize::getUserId, ids));
  387. return true;
  388. }
  389. @Override
  390. public BaseStudentClassVo getStudentClass(Long userId) {
  391. MPJLambdaWrapper<BaseClass> queryWrapper = new MPJLambdaWrapper<>();
  392. queryWrapper
  393. .disableSubLogicDel()
  394. .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseStudent::getId)
  395. .eq(BaseStudentSchoolRoll::getUserId, userId)
  396. .selectAsClass(BaseClass.class, BaseStudentClassVo.class);
  397. BaseClass baseClass = baseClassMapper.selectOne(queryWrapper);
  398. return BeanUtil.toBean(baseClass, BaseStudentClassVo.class);
  399. }
  400. /**
  401. * 个人财务画像,获取学生个人信息
  402. */
  403. @Override
  404. public PersonalPortraitPersonalInfoVo getPersonalInfo(Long userId) {
  405. StudentPersonalInfoVo info = baseStudentService.getPersonalInfo(userId);
  406. PersonalPortraitPersonalInfoVo p = new PersonalPortraitPersonalInfoVo();
  407. BeanUtils.copyProperties(info, p);
  408. List<BaseStudentFamilyMember> members = familyMemberMapper.selectList(
  409. new QueryWrapper<BaseStudentFamilyMember>().lambda()
  410. .eq(BaseStudentFamilyMember::getUserId, userId)
  411. .eq(BaseStudentFamilyMember::getIsGuardian, 1)
  412. );
  413. String guardianPhone = "";
  414. for (int i = 0; i < members.size(); i ++){
  415. if(i > 0){
  416. guardianPhone += ",";
  417. }
  418. guardianPhone += members.get(i).getMobile();
  419. }
  420. if(StrUtil.isNotEmpty(guardianPhone)){
  421. info.setGuardianPhone(guardianPhone);
  422. }
  423. return p;
  424. }
  425. @Override
  426. public Boolean importStudentData(List<Map<Integer, Object>> excelDataList) throws ParseException {
  427. List<String> idNumbers = new ArrayList<>();
  428. for (Map<Integer, Object> integerObjectMap : excelDataList) {
  429. idNumbers.add(integerObjectMap.get(0).toString());
  430. }
  431. //查询所有学生的用户信息,组装起来备用
  432. List<BaseStudentUser> studentUsers = this.selectJoinList(BaseStudentUser.class,
  433. new MPJLambdaWrapper<BaseStudentUser>()
  434. .leftJoin(BaseStudent.class, BaseStudent::getUserId, BaseStudentUser::getId)
  435. .in(BaseStudentUser::getCredentialNumber, idNumbers)
  436. );
  437. Map<String, BaseStudentUser> studentUserMap = new HashMap<>();
  438. Set<Long> userIds = new HashSet<>();
  439. for (BaseStudentUser studentUser : studentUsers) {
  440. studentUserMap.put(studentUser.getCredentialNumber(), studentUser);
  441. userIds.add(studentUser.getId());
  442. }
  443. //查询所有的学生信息,组装起来备用
  444. List<BaseStudent> baseStudents = baseStudentService.selectJoinList(BaseStudent.class,
  445. new MPJLambdaWrapper<BaseStudent>()
  446. .leftJoin(BaseStudentUser.class, BaseStudentUser::getId, BaseStudent::getUserId)
  447. .in(BaseStudentUser::getCredentialNumber, idNumbers)
  448. );
  449. Map<Long, BaseStudent> baseStudentMap = new HashMap<>();
  450. for (BaseStudent studentUser : baseStudents) {
  451. baseStudentMap.put(studentUser.getUserId(), studentUser);
  452. }
  453. //查询所用到的字典
  454. Map<String, String> dictionary = initDictionary();
  455. //查行政区划
  456. List<Area> areaList = areaService.list();
  457. Map<String, Long> areaMap = new HashMap<>();
  458. for (Area area : areaList) {
  459. areaMap.put(area.getName(), Long.parseLong(area.getCode()));
  460. }
  461. List<BaseStudentSchoolRoll> baseStudentSchoolRolls = schoolRollService.selectJoinList(BaseStudentSchoolRoll.class,
  462. new MPJLambdaWrapper<BaseStudentSchoolRoll>()
  463. .leftJoin(BaseStudent.class, BaseStudent::getUserId, BaseStudentSchoolRoll::getUserId)
  464. .in(!userIds.isEmpty(), BaseStudentSchoolRoll::getUserId, userIds)
  465. );
  466. Map<Long, BaseStudentSchoolRoll> studentSchoolRollMap = new HashMap<>();
  467. for (BaseStudentSchoolRoll schoolRoll : baseStudentSchoolRolls) {
  468. studentSchoolRollMap.put(schoolRoll.getUserId(), schoolRoll);
  469. }
  470. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  471. //查询年级
  472. List<BaseGrade> gradeList = baseGradeMapper.selectList(new QueryWrapper<BaseGrade>().lambda().eq(BaseGrade::getDeleteMark, DeleteMark.NODELETE.getCode()));
  473. Map<String, Long> gradeMap = new HashMap<>();
  474. for (BaseGrade grade : gradeList) {
  475. gradeMap.put(grade.getName(), grade.getId());
  476. }
  477. //查询班级
  478. List<BaseClass> classList = baseClassMapper.selectList(new QueryWrapper<BaseClass>().lambda().eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode()));
  479. Map<String, Long> classMap = new HashMap<>();
  480. for (BaseClass grade : classList) {
  481. classMap.put(grade.getName(), grade.getId());
  482. }
  483. //查询专业
  484. List<BaseMajorSet> majorSetList = baseMajorSetMapper.selectList(new QueryWrapper<BaseMajorSet>().lambda().eq(BaseMajorSet::getDeleteMark, DeleteMark.NODELETE.getCode()));
  485. Map<String, Long> majorSetMap = new HashMap<>();
  486. for (BaseMajorSet baseMajorSet : majorSetList) {
  487. majorSetMap.put(baseMajorSet.getName(), baseMajorSet.getId());
  488. }
  489. //查询资助
  490. List<BaseStudentSubsidize> baseStudentSubsidizes = subsidizeService.list(null);
  491. Map<Long, BaseStudentSubsidize> subsidizesMap = new HashMap<>();
  492. for (BaseStudentSubsidize el : baseStudentSubsidizes) {
  493. subsidizesMap.put(el.getUserId(), el);
  494. }
  495. //查询家庭
  496. List<BaseStudentFamily> studentFamilies = familyMapper.selectList(null);
  497. Map<Long, BaseStudentFamily> familyMap = new HashMap<>();
  498. for (BaseStudentFamily el : studentFamilies) {
  499. familyMap.put(el.getUserId(), el);
  500. }
  501. //查询联系信息
  502. List<BaseStudentContact> contactList = studentContactService.list();
  503. Map<Long, BaseStudentContact> contactMap = new HashMap<>();
  504. for (BaseStudentContact el : contactList) {
  505. contactMap.put(el.getUserId(), el);
  506. }
  507. List<BaseStudentUser> updateStudentUserList = new ArrayList();
  508. List<BaseStudent> updateBaseStudentList = new ArrayList();
  509. List<BaseStudentSchoolRoll> updateSchoolRollList = new ArrayList();
  510. List<BaseStudentSubsidize> updateSubsidizeList = new ArrayList();
  511. List<BaseStudentFamily> updateFamilyList = new ArrayList();
  512. List<BaseStudentContact> updateContactList = new ArrayList();
  513. List<BaseStudentUser> insertStudentUserList = new ArrayList();
  514. List<BaseStudent> insertBaseStudentList = new ArrayList();
  515. List<BaseStudentSchoolRoll> insertSchoolRollList = new ArrayList();
  516. List<BaseStudentSubsidize> insertSubsidizeList = new ArrayList();
  517. List<BaseStudentFamily> insertFamilyList = new ArrayList();
  518. List<BaseStudentContact> insertContactList = new ArrayList();
  519. long createUserId = StpUtil.getLoginIdAsLong();
  520. // long createUserId = 1000000000000000000L;
  521. int row = 3;
  522. for (Map<Integer, Object> dataMaps : excelDataList) {
  523. if(dataMaps.get(0) == null){
  524. throw new MyException("第" + row + "行数据身份证号为空,无法导入");
  525. }
  526. String credentialNumber = dataMaps.get(0).toString();//身份证号
  527. //已存在,更新
  528. BaseStudentUser user = studentUserMap.get(credentialNumber);
  529. BaseStudent baseStudent;
  530. BaseStudentSchoolRoll schoolRoll;
  531. BaseStudentSubsidize subsidize;
  532. BaseStudentFamily studentFamily;
  533. BaseStudentContact contact;
  534. long userId = IdUtil.getSnowflakeNextId();
  535. if(user != null){
  536. userId = user.getId();
  537. user.setDeleteMark(DeleteMark.NODELETE.getCode());
  538. baseStudent = baseStudentMap.get(user.getId());
  539. if(baseStudent == null){
  540. baseStudent = new BaseStudent();
  541. baseStudent.setUserId(userId);
  542. baseStudent.setCreateUserId(createUserId);
  543. baseStudent.setCreateDate(LocalDateTime.now());
  544. }
  545. baseStudent.setDeleteMark(DeleteMark.NODELETE.getCode());
  546. schoolRoll = studentSchoolRollMap.get(user.getId());
  547. if(schoolRoll == null){
  548. schoolRoll = new BaseStudentSchoolRoll();
  549. schoolRoll.setUserId(userId);
  550. schoolRoll.setCreateUserId(createUserId);
  551. schoolRoll.setCreateDate(LocalDateTime.now());
  552. }
  553. schoolRoll.setDeleteMark(DeleteMark.NODELETE.getCode());
  554. subsidize = subsidizesMap.get(user.getId());
  555. if(subsidize == null){
  556. subsidize = new BaseStudentSubsidize();
  557. subsidize.setUserId(userId);
  558. subsidize.setCreateUserId(createUserId);
  559. subsidize.setCreateDate(LocalDateTime.now());
  560. }
  561. subsidize.setDeleteMark(DeleteMark.NODELETE.getCode());
  562. studentFamily = familyMap.get(user.getId());
  563. if(studentFamily == null){
  564. studentFamily = new BaseStudentFamily();
  565. studentFamily.setUserId(userId);
  566. studentFamily.setCreateUserId(createUserId);
  567. studentFamily.setCreateDate(LocalDateTime.now());
  568. }
  569. studentFamily.setDeleteMark(DeleteMark.NODELETE.getCode());
  570. contact = contactMap.get(user.getId());
  571. if(contact == null){
  572. contact = new BaseStudentContact();
  573. contact.setUserId(userId);
  574. contact.setCreateUserId(createUserId);
  575. contact.setCreateDate(LocalDateTime.now());
  576. }
  577. contact.setDeleteMark(DeleteMark.NODELETE.getCode());
  578. }else{
  579. user = new BaseStudentUser();
  580. user.setId(userId);
  581. user.setUserName(credentialNumber);
  582. user.setCredentialNumber(credentialNumber);
  583. user.setCreateUserId(createUserId);
  584. user.setCreateDate(LocalDateTime.now());
  585. baseStudent = new BaseStudent();
  586. baseStudent.setUserId(userId);
  587. baseStudent.setCreateUserId(createUserId);
  588. baseStudent.setCreateDate(LocalDateTime.now());
  589. schoolRoll = new BaseStudentSchoolRoll();
  590. schoolRoll.setUserId(userId);
  591. schoolRoll.setCreateUserId(createUserId);
  592. schoolRoll.setCreateDate(LocalDateTime.now());
  593. subsidize = new BaseStudentSubsidize();
  594. subsidize.setUserId(userId);
  595. subsidize.setCreateUserId(createUserId);
  596. subsidize.setCreateDate(LocalDateTime.now());
  597. studentFamily = new BaseStudentFamily();
  598. studentFamily.setUserId(userId);
  599. studentFamily.setCreateUserId(createUserId);
  600. studentFamily.setCreateDate(LocalDateTime.now());
  601. contact = new BaseStudentContact();
  602. contact.setUserId(userId);
  603. contact.setCreateUserId(createUserId);
  604. contact.setCreateDate(LocalDateTime.now());
  605. }
  606. //设置字段值
  607. if(dataMaps.get(1) != null && !"".equals(dataMaps.get(1).toString())){
  608. baseStudent.setStudentId(dataMaps.get(1).toString());//学号
  609. }
  610. if(dataMaps.get(2) != null && !"".equals(dataMaps.get(2).toString())){
  611. schoolRoll.setCandidateNumber(dataMaps.get(2).toString());//考号
  612. }
  613. if(dataMaps.get(3) != null && !"".equals(dataMaps.get(3).toString())){
  614. user.setName(dataMaps.get(3).toString());//姓名
  615. }
  616. if(dataMaps.get(4) != null && !"".equals(dataMaps.get(4).toString())){
  617. user.setGender(GenderDictionaryEnum.getCode(dataMaps.get(4).toString()));//性别
  618. }
  619. if(dataMaps.get(5) != null && !"".equals(dataMaps.get(5).toString())){
  620. user.setMobile(dataMaps.get(5).toString());//手机号
  621. }
  622. if(dataMaps.get(6) != null && !"".equals(dataMaps.get(6).toString())){
  623. user.setEmail(dataMaps.get(6).toString());//邮箱
  624. }
  625. if(dataMaps.get(7) != null && !"".equals(dataMaps.get(7).toString())){
  626. baseStudent.setAsName(dataMaps.get(7).toString());//别名
  627. }
  628. if(dataMaps.get(8) != null && !"".equals(dataMaps.get(8).toString())){
  629. baseStudent.setEnName(dataMaps.get(8).toString());//英文名
  630. }
  631. if(dataMaps.get(9) != null && !"".equals(dataMaps.get(9).toString())){
  632. baseStudent.setPyName(dataMaps.get(9).toString());//姓名拼音
  633. }
  634. if(dataMaps.get(10) != null && !"".equals(dataMaps.get(10).toString())){
  635. baseStudent.setFormerName(dataMaps.get(10).toString());//曾用名
  636. }
  637. if(dataMaps.get(11) != null && !"".equals(dataMaps.get(11).toString())){
  638. user.setCredentialType(dictionary.get("credential_type" + dataMaps.get(11).toString()));//证件类型
  639. }
  640. if(dataMaps.get(12) != null && !"".equals(dataMaps.get(12).toString())){
  641. LocalDateTime birthday = parseLocalDateTime(dataMaps.get(12).toString());
  642. user.setBirthDate(birthday);//出生日期
  643. baseStudent.setDayOfBirth(birthday.toLocalDate());//出生日期
  644. }
  645. if(dataMaps.get(13) != null && !"".equals(dataMaps.get(13).toString())){
  646. baseStudent.setBirthType(dictionary.get("date_type" + dataMaps.get(13).toString()));//生日类型
  647. }
  648. if(dataMaps.get(14) != null && !"".equals(dataMaps.get(14).toString())){
  649. baseStudent.setNation(dictionary.get("nation" + dataMaps.get(14).toString()));//民族
  650. }
  651. if(dataMaps.get(15) != null && !"".equals(dataMaps.get(15).toString())){
  652. baseStudent.setBloodType(dictionary.get("blood_type" + dataMaps.get(15).toString()));//血型
  653. }
  654. if(dataMaps.get(16) != null && !"".equals(dataMaps.get(16).toString())){
  655. baseStudent.setHealth(dictionary.get("health" + dataMaps.get(16).toString()));//健康状况
  656. }
  657. if(dataMaps.get(17) != null && !"".equals(dataMaps.get(17).toString())){
  658. baseStudent.setMaritalState(dictionary.get("marital_state" + dataMaps.get(17).toString()));//婚姻状况
  659. }
  660. if(dataMaps.get(18) != null && !"".equals(dataMaps.get(18).toString())){
  661. baseStudent.setPoliticalState(dictionary.get("political_state" + dataMaps.get(18).toString()));//政治面貌
  662. }
  663. if(dataMaps.get(19) != null && !"".equals(dataMaps.get(19).toString())){
  664. baseStudent.setNationality(dictionary.get("nationality" + dataMaps.get(19).toString()));//国籍地区
  665. }
  666. if(dataMaps.get(20) != null && !"".equals(dataMaps.get(20).toString())){
  667. baseStudent.setChineseType(dictionary.get("chinese_type" + dataMaps.get(20).toString()));//港澳台侨外
  668. }
  669. if(dataMaps.get(21) != null && !"".equals(dataMaps.get(21).toString())){
  670. baseStudent.setHouseHoldType(dictionary.get("house_hold_type" + dataMaps.get(21).toString()));//户口类别
  671. }
  672. if(dataMaps.get(22) != null && !"".equals(dataMaps.get(22).toString())){
  673. baseStudent.setNativePlaceType(dataMaps.get(22).toString());//籍贯类型
  674. }
  675. if(dataMaps.get(23) != null && !"".equals(dataMaps.get(23).toString())){
  676. baseStudent.setProvinces(areaMap.get(dataMaps.get(23).toString()));//省
  677. }
  678. if(dataMaps.get(24) != null && !"".equals(dataMaps.get(24).toString())){
  679. baseStudent.setCity(areaMap.get(dataMaps.get(24).toString()));//市
  680. }
  681. if(dataMaps.get(25) != null && !"".equals(dataMaps.get(25).toString())){
  682. baseStudent.setDistrict(areaMap.get(dataMaps.get(25).toString()));//区县
  683. }
  684. if(dataMaps.get(26) != null && !"".equals(dataMaps.get(26).toString())){
  685. baseStudent.setHouseProvinces(areaMap.get(dataMaps.get(26).toString()));//户口所在地省
  686. }
  687. if(dataMaps.get(27) != null && !"".equals(dataMaps.get(27).toString())){
  688. baseStudent.setHouseCity(areaMap.get(dataMaps.get(27).toString()));//户口所在地市
  689. }
  690. if(dataMaps.get(28) != null && !"".equals(dataMaps.get(28).toString())){
  691. baseStudent.setHouseDistrict(areaMap.get(dataMaps.get(28).toString()));//户口所在地区/县
  692. }
  693. if(dataMaps.get(29) != null && !"".equals(dataMaps.get(29).toString())){
  694. baseStudent.setBelongsPolice(dataMaps.get(29).toString());//户口所属派出所
  695. }
  696. if(dataMaps.get(30) != null && !"".equals(dataMaps.get(30).toString())){
  697. baseStudent.setBirthProvinces(areaMap.get(dataMaps.get(30).toString()));//出生所在地省
  698. }
  699. if(dataMaps.get(31) != null && !"".equals(dataMaps.get(31).toString())){
  700. baseStudent.setBirthCity(areaMap.get(dataMaps.get(31).toString()));//出生所在地市
  701. }
  702. if(dataMaps.get(32) != null && !"".equals(dataMaps.get(32).toString())){
  703. baseStudent.setBirthDistrict(areaMap.get(dataMaps.get(32).toString()));//出生所在地/区县
  704. }
  705. if(dataMaps.get(33) != null && !"".equals(dataMaps.get(33).toString())){
  706. baseStudent.setHouseHoldAddress(dataMaps.get(33).toString());//户籍地址
  707. }
  708. if(dataMaps.get(34) != null && !"".equals(dataMaps.get(34).toString())){
  709. baseStudent.setResidenceType(dictionary.get("residence_type" + dataMaps.get(34).toString()));//学生居住地类型
  710. }
  711. if(dataMaps.get(35) != null && !"".equals(dataMaps.get(35).toString())){
  712. baseStudent.setTrainInterval(dataMaps.get(35).toString());//乘火车区间
  713. }
  714. if(dataMaps.get(36) != null && !"".equals(dataMaps.get(36).toString())){
  715. baseStudent.setIsMigrateChildren(YesOrNoEnum.getCode(dataMaps.get(36).toString()));//是否随迁子女
  716. }
  717. if(dataMaps.get(37) != null && !"".equals(dataMaps.get(37).toString())){
  718. baseStudent.setIsFloatingPopulation(YesOrNoEnum.getCode(dataMaps.get(37).toString()));//是否流动人口
  719. }
  720. if(dataMaps.get(38) != null && !"".equals(dataMaps.get(38).toString())){
  721. baseStudent.setHeight(Double.parseDouble(dataMaps.get(38).toString()));//身高
  722. }
  723. if(dataMaps.get(39) != null && !"".equals(dataMaps.get(39).toString())){
  724. baseStudent.setWeight(Double.parseDouble(dataMaps.get(39).toString()));//体重
  725. }
  726. if(dataMaps.get(40) != null && !"".equals(dataMaps.get(40).toString())){
  727. baseStudent.setVision(Double.parseDouble(dataMaps.get(40).toString()));//视力
  728. }
  729. if(dataMaps.get(41) != null && !"".equals(dataMaps.get(41).toString())){
  730. baseStudent.setSpecialty(dataMaps.get(41).toString());//特长
  731. }
  732. if(dataMaps.get(42) != null && !"".equals(dataMaps.get(42).toString())){
  733. user.setQqNumber(dataMaps.get(42).toString());//QQ&MSN
  734. contact.setQqMsn(dataMaps.get(42).toString());//QQ&MSN
  735. }
  736. if(dataMaps.get(43) != null && !"".equals(dataMaps.get(43).toString())){
  737. user.setWechatNumber(dataMaps.get(43).toString());//微信号码
  738. contact.setWechat(dataMaps.get(43).toString());//微信号码
  739. }
  740. if(dataMaps.get(44) != null && !"".equals(dataMaps.get(44).toString())){
  741. contact.setUserPage(dataMaps.get(44).toString());//个人主页
  742. }
  743. if(dataMaps.get(45) != null && !"".equals(dataMaps.get(45).toString())){
  744. schoolRoll.setRollNumber(dataMaps.get(45).toString());//学籍号
  745. }
  746. if(dataMaps.get(46) != null && !"".equals(dataMaps.get(46).toString())){
  747. schoolRoll.setArchivesNumber(dataMaps.get(46).toString());//学生档案编号
  748. }
  749. if(dataMaps.get(47) != null && !"".equals(dataMaps.get(47).toString())){
  750. schoolRoll.setEnrollmentDate(sdf.parse(dataMaps.get(47).toString()));//入学年月
  751. }
  752. if(dataMaps.get(48) != null && !"".equals(dataMaps.get(48).toString())){
  753. schoolRoll.setEnrollmentType(dictionary.get("enrollment_type" + dataMaps.get(48).toString()));//入学方式
  754. }
  755. if(dataMaps.get(49) != null && !"".equals(dataMaps.get(49).toString())){
  756. schoolRoll.setGradeId(gradeMap.get(dataMaps.get(49).toString()));//入学年级
  757. }
  758. if(dataMaps.get(50) != null && !"".equals(dataMaps.get(50).toString())){
  759. schoolRoll.setEnrollType(dictionary.get("enroll_type" + dataMaps.get(50).toString()));//入学招生类型
  760. }
  761. if(dataMaps.get(51) != null && !"".equals(dataMaps.get(51).toString())){
  762. schoolRoll.setMajorSetId(majorSetMap.get(dataMaps.get(51).toString()));//在读专业方向
  763. }
  764. if(dataMaps.get(52) != null && !"".equals(dataMaps.get(52).toString())){
  765. schoolRoll.setStudyYear(Double.parseDouble(dataMaps.get(52).toString()));//学制
  766. }
  767. if(dataMaps.get(53) != null && !"".equals(dataMaps.get(53).toString())){
  768. schoolRoll.setClassId(classMap.get(dataMaps.get(53).toString()));//班级
  769. }
  770. if(dataMaps.get(54) != null && !"".equals(dataMaps.get(54).toString())){
  771. schoolRoll.setStudentSource(dictionary.get("student_type" + dataMaps.get(54).toString()));//学生来源
  772. }
  773. if(dataMaps.get(55) != null && !"".equals(dataMaps.get(55).toString())){
  774. schoolRoll.setStudentType(dictionary.get("student_type" + dataMaps.get(55).toString()));//学生类别
  775. }
  776. if(dataMaps.get(56) != null && !"".equals(dataMaps.get(56).toString())){
  777. schoolRoll.setArchivesStatus(dictionary.get("archives_status" + dataMaps.get(56).toString()));//学籍状态
  778. }
  779. if(dataMaps.get(57) != null && !"".equals(dataMaps.get(57).toString())){
  780. schoolRoll.setLearnStatus(dictionary.get("roll_modality" + dataMaps.get(57).toString()));//学习形式
  781. schoolRoll.setRollModality(dictionary.get("roll_modality" + dataMaps.get(57).toString()));//学习形式
  782. }
  783. if(dataMaps.get(58) != null && !"".equals(dataMaps.get(58).toString())){
  784. schoolRoll.setStduyStatus(dictionary.get("stduy_status" + dataMaps.get(58).toString()));//就读方式
  785. }
  786. if(dataMaps.get(59) != null && !"".equals(dataMaps.get(59).toString())){
  787. schoolRoll.setChooseStatus(dictionary.get("choose_status" + dataMaps.get(59).toString()));//分流状态
  788. }
  789. if(dataMaps.get(60) != null && !"".equals(dataMaps.get(60).toString())){
  790. schoolRoll.setFosterType(dictionary.get("foster_type" + dataMaps.get(60).toString()));//分段培养方式
  791. }
  792. if(dataMaps.get(61) != null && !"".equals(dataMaps.get(61).toString())){
  793. schoolRoll.setRecruitType(dictionary.get("recruit_type" + dataMaps.get(61).toString()));//招生类型
  794. }
  795. if(dataMaps.get(62) != null && !"".equals(dataMaps.get(62).toString())){
  796. schoolRoll.setRecruitTarget(dictionary.get("recruit_target" + dataMaps.get(62).toString()));//招生对象
  797. }
  798. if(dataMaps.get(63) != null && !"".equals(dataMaps.get(63).toString())){
  799. schoolRoll.setHighestEducation(dictionary.get("education" + dataMaps.get(63).toString()));//入学前最高学历
  800. }
  801. if(dataMaps.get(64) != null && !"".equals(dataMaps.get(64).toString())){
  802. schoolRoll.setGraduatedUniversity(dataMaps.get(64).toString());//入学前毕业院校
  803. }
  804. if(dataMaps.get(65) != null && !"".equals(dataMaps.get(65).toString())){
  805. schoolRoll.setGraduatedScore(Double.parseDouble(dataMaps.get(65).toString()));//入学前毕业成绩
  806. }
  807. if(dataMaps.get(66) != null && !"".equals(dataMaps.get(66).toString())){
  808. schoolRoll.setExamineeNumber(dataMaps.get(66).toString());//入学考试准考证号
  809. }
  810. if(dataMaps.get(67) != null && !"".equals(dataMaps.get(67).toString())){
  811. schoolRoll.setTicketNumber(dataMaps.get(67).toString());//入学考试准考证号
  812. }
  813. if(dataMaps.get(68) != null && !"".equals(dataMaps.get(68).toString())){
  814. schoolRoll.setAdmissionScores(Double.parseDouble(dataMaps.get(68).toString()));//入学考试成绩
  815. }
  816. if(dataMaps.get(69) != null && !"".equals(dataMaps.get(69).toString())){
  817. schoolRoll.setRemark(dataMaps.get(69).toString());//备注
  818. }
  819. if(dataMaps.get(69) != null && !"".equals(dataMaps.get(69).toString())){
  820. schoolRoll.setRemark(dataMaps.get(69).toString());//备注
  821. }
  822. if(dataMaps.get(70) != null && !"".equals(dataMaps.get(70).toString())){
  823. subsidize.setIsIndemnify(YesOrNoEnum.getCode(dataMaps.get(70).toString()));//是否低保户
  824. }
  825. if(dataMaps.get(71) != null && !"".equals(dataMaps.get(71).toString())){
  826. subsidize.setIsStipend(YesOrNoEnum.getCode(dataMaps.get(71).toString()));//是否享受国家助学金
  827. }
  828. if(dataMaps.get(72) != null && !"".equals(dataMaps.get(72).toString())){
  829. subsidize.setStipendStand(Double.parseDouble(dataMaps.get(72).toString()));//助学金发放标准(元)
  830. }
  831. if(dataMaps.get(73) != null && !"".equals(dataMaps.get(73).toString())){
  832. subsidize.setStipendNumber(dataMaps.get(73).toString());//学生资助卡号
  833. }
  834. if(dataMaps.get(74) != null && !"".equals(dataMaps.get(74).toString())){
  835. subsidize.setIsFree(YesOrNoEnum.getCode(dataMaps.get(74).toString()));//是否免学费
  836. }
  837. if(dataMaps.get(75) != null && !"".equals(dataMaps.get(75).toString())){
  838. subsidize.setIsFilingCard(YesOrNoEnum.getCode(dataMaps.get(75).toString()));//是否建档立卡
  839. }
  840. if(dataMaps.get(76) != null && !"".equals(dataMaps.get(76).toString())){
  841. studentFamily.setZipCode(dataMaps.get(76).toString());//家庭邮编
  842. }
  843. if(dataMaps.get(77) != null && !"".equals(dataMaps.get(77).toString())){
  844. studentFamily.setTelephone(dataMaps.get(77).toString());//家庭电话
  845. }
  846. if(dataMaps.get(78) != null && !"".equals(dataMaps.get(78).toString())){
  847. studentFamily.setContact(dataMaps.get(76).toString());//联系人姓名
  848. }
  849. if(dataMaps.get(79) != null && !"".equals(dataMaps.get(79).toString())){
  850. studentFamily.setPopulation(Integer.parseInt(dataMaps.get(79).toString()));//家庭人口
  851. }
  852. if(dataMaps.get(80) != null && !"".equals(dataMaps.get(80).toString())){
  853. studentFamily.setAddress(dataMaps.get(80).toString());//家庭地址
  854. }
  855. if(dataMaps.get(81) != null && !"".equals(dataMaps.get(81).toString())){
  856. studentFamily.setIncomeSource(dataMaps.get(81).toString());//家庭主要收入来源
  857. }
  858. if(dataMaps.get(82) != null && !"".equals(dataMaps.get(82).toString())){
  859. studentFamily.setIncomeNumber(Double.parseDouble(dataMaps.get(82).toString()));//家庭月收入(元)
  860. }
  861. if(dataMaps.get(83) != null && !"".equals(dataMaps.get(83).toString())){
  862. studentFamily.setRailwayStation(dataMaps.get(83).toString());//离家最近火车站
  863. }
  864. if(studentUserMap.containsKey(credentialNumber)){
  865. updateStudentUserList.add(user);
  866. updateBaseStudentList.add(baseStudent);
  867. updateSchoolRollList.add(schoolRoll);
  868. updateSubsidizeList.add(subsidize);
  869. updateFamilyList.add(studentFamily);
  870. updateContactList.add(contact);
  871. }else{
  872. insertStudentUserList.add(user);
  873. insertBaseStudentList.add(baseStudent);
  874. if(schoolRoll.getClassId() != null && schoolRoll.getGradeId() != null && schoolRoll.getMajorSetId() != null){
  875. insertSchoolRollList.add(schoolRoll);
  876. }
  877. insertSubsidizeList.add(subsidize);
  878. insertFamilyList.add(studentFamily);
  879. insertContactList.add(contact);
  880. }
  881. row ++;
  882. }
  883. //批量修改
  884. if(!updateStudentUserList.isEmpty()){
  885. this.updateBatchById(updateStudentUserList);
  886. }
  887. if(!updateSchoolRollList.isEmpty()){
  888. schoolRollService.updateBatchById(updateSchoolRollList);
  889. }
  890. if(!updateSubsidizeList.isEmpty()){
  891. subsidizeService.updateBatchById(updateSubsidizeList);
  892. }
  893. if(!updateFamilyList.isEmpty()){
  894. familyService.updateBatchById(updateFamilyList);
  895. }
  896. if(!updateBaseStudentList.isEmpty()){
  897. baseStudentService.updateBatchById(updateBaseStudentList);
  898. }
  899. if(!updateContactList.isEmpty()){
  900. studentContactService.updateBatchById(updateContactList);
  901. }
  902. //批量新增
  903. if(!insertStudentUserList.isEmpty()){
  904. this.saveBatch(insertStudentUserList);
  905. }
  906. if(!insertBaseStudentList.isEmpty()){
  907. baseStudentService.saveBatch(insertBaseStudentList);
  908. }
  909. if(!insertSubsidizeList.isEmpty()){
  910. subsidizeService.saveBatch(insertSubsidizeList);
  911. }
  912. if(!insertFamilyList.isEmpty()){
  913. familyService.saveBatch(insertFamilyList);
  914. }
  915. if(!insertSchoolRollList.isEmpty()){
  916. schoolRollService.saveBatch(insertSchoolRollList);
  917. }
  918. if(!insertContactList.isEmpty()){
  919. studentContactService.saveBatch(insertContactList);
  920. }
  921. return true;
  922. }
  923. @Override
  924. public Page<BaseStudentUserPageVo> getStudentPage(Page<BaseStudentUserPageVo> page, BaseStudentUserPageDto dto) {
  925. return baseStudentMapper.getStudentPage(page, dto);
  926. }
  927. @Override
  928. public Boolean uploadImage(Long userId, MultipartFile file) throws IOException {
  929. BaseStudentUser studentUser = studentbaseManagerBaseStudentUserMapper.selectById(userId);
  930. String[] imgSuffix = new String[]{"png", "jpg", "jpeg"};
  931. String suffix = StringUtils.substringAfterLast(file.getOriginalFilename(), StringPool.DOT);
  932. if (!Arrays.asList(imgSuffix).contains(suffix)) {
  933. throw new MyException("图片格式不正确!");
  934. }
  935. String base64String = Base64.getEncoder().encodeToString(file.getBytes());
  936. Map<String, String> map = new HashMap<String, String>() {
  937. {
  938. put("jpg", "data:image/jpg;base64,");
  939. put("jpeg", "data:image/jpeg;base64,");
  940. put("png", "data:image/png;base64,");
  941. }
  942. };
  943. studentUser.setAvatar(map.get(suffix) + base64String);
  944. studentbaseManagerBaseStudentUserMapper.updateById(studentUser);
  945. return true;
  946. }
  947. @Override
  948. public List<BaseDepMajorGradeClassStudenTreeVo> deptMajorGradeClassTree() {
  949. List<BaseDepMajorGradeClassStudenTreeVo> voList = new ArrayList<>();
  950. MPJLambdaWrapper<BaseClass> baseClassMPJLambdaWrapper = new MPJLambdaWrapper<>();
  951. baseClassMPJLambdaWrapper
  952. .selectAs(BaseClass::getId, BaseClassMajorSetVo::getClassId)
  953. .selectAs(BaseMajorSet::getMajorId, BaseClassMajorSetVo::getMajorId)
  954. .selectAs(BaseClass::getName, BaseClassMajorSetVo::getClassName)
  955. .selectAs(BaseClass::getGradeId, BaseClassMajorSetVo::getGradeId)
  956. .leftJoin(BaseClassMajorSet.class, BaseClassMajorSet::getClassId, BaseClass::getId)
  957. .leftJoin(BaseMajorSet.class, BaseMajorSet::getId, BaseClassMajorSet::getMajorSetId)
  958. ;
  959. List<BaseClassMajorSetVo> majorSetList = baseClassService.selectJoinList(BaseClassMajorSetVo.class, baseClassMPJLambdaWrapper);
  960. List<BaseGrade> gradeList = baseGradeService.list(
  961. new QueryWrapper<BaseGrade>().lambda().eq(BaseGrade::getDeleteMark, DeleteMark.NODELETE.getCode())
  962. );
  963. List<BaseMajor> majorList = baseMajorService.list(
  964. new QueryWrapper<BaseMajor>().lambda().eq(BaseMajor::getDeleteMark, DeleteMark.NODELETE.getCode())
  965. );
  966. List<Department> departmentList =baseDeparmentService.list(
  967. new QueryWrapper<Department>().lambda().eq(Department::getDeleteMark, DeleteMark.NODELETE.getCode())
  968. .eq(Department::getParentId,"1684107782861680008")
  969. );
  970. departmentList.forEach((node) -> {
  971. voList.add(new BaseDepMajorGradeClassStudenTreeVo(){{
  972. setId(node.getId().toString());
  973. setTreeType(1);
  974. setName(node.getName());
  975. setParentId("0");
  976. }});
  977. });
  978. majorList.forEach((node)->{
  979. voList.add(new BaseDepMajorGradeClassStudenTreeVo(){{
  980. setId(node.getId().toString());
  981. setName(node.getName());
  982. setTreeType(2);
  983. setParentId(node.getDepartmentId().toString());
  984. }});
  985. gradeList.forEach((DDD)->{
  986. voList.add(new BaseDepMajorGradeClassStudenTreeVo(){{
  987. setId(node.getId().toString()+"_"+DDD.getId().toString());
  988. setName(DDD.getName());
  989. setTreeType(3);
  990. setParentId(node.getId().toString());
  991. }});
  992. });
  993. });
  994. majorSetList.forEach((node)->{
  995. voList.add(new BaseDepMajorGradeClassStudenTreeVo(){{
  996. setId(node.getClassId().toString());
  997. setName(node.getClassName());
  998. setTreeType(4);
  999. setParentId(node.getMajorId().toString()+"_"+node.getGradeId());
  1000. }});
  1001. });
  1002. List<BaseDepMajorGradeClassStudenTreeVo> treeVoList = TreeUtil.build(voList);
  1003. return treeVoList;
  1004. }
  1005. /**
  1006. * 初始化字典信息
  1007. * 身份证类型、
  1008. */
  1009. private Map<String, String> initDictionary(){
  1010. List<String> codeList = new ArrayList<>();
  1011. codeList.add("credential_type");codeList.add("nation");
  1012. codeList.add("blood_type");codeList.add("health");
  1013. codeList.add("marital_state");codeList.add("political_state");
  1014. codeList.add("nationality");codeList.add("chinese_type");
  1015. codeList.add("house_hold_type");codeList.add("residence_type");
  1016. codeList.add("enrollment_type");codeList.add("enroll_type");
  1017. codeList.add("student_type");codeList.add("archives_status");
  1018. codeList.add("roll_modality");codeList.add("stduy_status");
  1019. codeList.add("choose_status");codeList.add("foster_type");
  1020. codeList.add("recruit_type");codeList.add("recruit_target");
  1021. codeList.add("education");codeList.add("recruit_target");
  1022. codeList.add("date_type");
  1023. List<DictionaryDetail> detailList = dictionarydetailMapper.selectJoinList(DictionaryDetail.class,
  1024. new MPJLambdaWrapper<DictionaryDetail>()
  1025. .leftJoin(DictionaryItem.class, DictionaryItem::getId, DictionaryDetail::getItemId)
  1026. .in(DictionaryItem::getCode, codeList)
  1027. );
  1028. List<DictionaryItem> dictionaryItemList = dictionaryitemMapper.selectList(
  1029. new QueryWrapper<DictionaryItem>().lambda()
  1030. .eq(DictionaryItem::getDeleteMark, DeleteMark.NODELETE.getCode())
  1031. );
  1032. Map<Long, String> itemMap = new HashMap<>();
  1033. for (DictionaryItem dictionaryItem : dictionaryItemList) {
  1034. itemMap.put(dictionaryItem.getId(), dictionaryItem.getCode());
  1035. }
  1036. Map<String, String> resultMap = new HashMap<>();
  1037. for (DictionaryDetail dictionaryDetail : detailList) {
  1038. resultMap.put(itemMap.get(dictionaryDetail.getItemId()) + dictionaryDetail.getName(), dictionaryDetail.getCode());
  1039. }
  1040. return resultMap;
  1041. }
  1042. private LocalDateTime parseLocalDateTime(String dateStr){
  1043. LocalDate time = null;
  1044. try {
  1045. time = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
  1046. }catch (DateTimeParseException e){
  1047. try {
  1048. time = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy/MM/dd"));
  1049. }catch (DateTimeParseException e2){
  1050. try {
  1051. time = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
  1052. }catch (DateTimeParseException e3){
  1053. try {
  1054. time = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyyMMdd"));
  1055. }catch (DateTimeParseException e4){
  1056. throw new MyException("日期格式不正确");
  1057. }
  1058. }
  1059. }
  1060. }
  1061. if(time != null){
  1062. return time.atStartOfDay();
  1063. }
  1064. return null;
  1065. }
  1066. }