StudentManagerServiceImpl.java 65 KB

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