StudentManagerServiceImpl.java 65 KB

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