StudentManagerServiceImpl.java 58 KB

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