StudentManagerServiceImpl.java 66 KB

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