StudentManagerServiceImpl.java 56 KB

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