StudentManagerServiceImpl.java 56 KB

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