StudentManagerServiceImpl.java 65 KB

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