|
@@ -3,9 +3,12 @@ package com.xjrsoft.module.student.service.impl;
|
|
|
import cn.dev33.satoken.secure.BCrypt;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
@@ -21,9 +24,13 @@ import com.xjrsoft.module.base.entity.BaseMajorSet;
|
|
|
import com.xjrsoft.module.base.mapper.BaseClassMapper;
|
|
|
import com.xjrsoft.module.base.mapper.BaseGradeMapper;
|
|
|
import com.xjrsoft.module.base.mapper.BaseMajorSetMapper;
|
|
|
+import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
|
import com.xjrsoft.module.organization.entity.UserRoleRelation;
|
|
|
import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
|
|
|
+import com.xjrsoft.module.organization.service.IUserDeptRelationService;
|
|
|
+import com.xjrsoft.module.student.dto.AddBaseStudentUserDto;
|
|
|
import com.xjrsoft.module.student.dto.BaseStudentUserPageDto;
|
|
|
+import com.xjrsoft.module.student.dto.UpdateBaseStudentUserDto;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentContact;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentFamily;
|
|
@@ -62,13 +69,7 @@ import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.DateTimeParseException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -93,9 +94,14 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
|
|
|
private final IBaseStudentFamilyService familyService;
|
|
|
private final BaseStudentMapper baseStudentMapper;
|
|
|
|
|
|
+ private final IUserDeptRelationService userDeptRelationService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean add(BaseStudentUser baseStudentUser) {
|
|
|
+ public Boolean add(AddBaseStudentUserDto dto) {
|
|
|
+
|
|
|
+ BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
|
|
|
+
|
|
|
// 用户身份证后6位作为默认密码
|
|
|
if (baseStudentUser.getCredentialNumber() != null && baseStudentUser.getCredentialNumber().length() > 6) {
|
|
|
String str = baseStudentUser.getCredentialNumber();
|
|
@@ -128,6 +134,22 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
|
|
|
subsidizeService.save(baseStudentSubsidize);
|
|
|
}
|
|
|
|
|
|
+ List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
|
|
|
+ if (StrUtil.isNotBlank(dto.getDepartmentIds())) {
|
|
|
+ String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
|
|
|
+ List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(departmentIds)) {
|
|
|
+ for (Long deptId : departmentIds) {
|
|
|
+ //将用户所选部门保存到关联表中
|
|
|
+ UserDeptRelation userDeptRelation = new UserDeptRelation();
|
|
|
+ userDeptRelation.setUserId(baseStudentUser.getId());
|
|
|
+ userDeptRelation.setDeptId(deptId);
|
|
|
+ userDeptRelationList.add(userDeptRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userDeptRelationService.saveBatch(userDeptRelationList);
|
|
|
+ }
|
|
|
+
|
|
|
// 添加角色
|
|
|
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
|
|
userRoleRelation.setUserId(baseStudentUser.getId());
|
|
@@ -139,8 +161,30 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean update(BaseStudentUser baseStudentUser) {
|
|
|
+ public Boolean update(UpdateBaseStudentUserDto dto) {
|
|
|
+
|
|
|
+ BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
|
|
|
+
|
|
|
studentbaseManagerBaseStudentUserMapper.updateById(baseStudentUser);
|
|
|
+
|
|
|
+ //先删除再新增
|
|
|
+ userDeptRelationService.remove(Wrappers.<UserDeptRelation>query().lambda().eq(UserDeptRelation::getUserId, baseStudentUser.getId()));
|
|
|
+ List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
|
|
|
+ if (StrUtil.isNotBlank(dto.getDepartmentIds())) {
|
|
|
+ String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
|
|
|
+ List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(departmentIds)) {
|
|
|
+ for (Long deptId : departmentIds) {
|
|
|
+ //将用户所选部门保存到关联表中
|
|
|
+ UserDeptRelation userDeptRelation = new UserDeptRelation();
|
|
|
+ userDeptRelation.setUserId(baseStudentUser.getId());
|
|
|
+ userDeptRelation.setDeptId(deptId);
|
|
|
+ userDeptRelationList.add(userDeptRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userDeptRelationService.saveBatch(userDeptRelationList);
|
|
|
+ }
|
|
|
+
|
|
|
//********************************* BaseStudent 增删改 开始 *******************************************/
|
|
|
{
|
|
|
// 查出所有子级的id
|