| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.project.common.annotation.DataScope; |
| | | import com.project.common.constant.UserConstants; |
| | | import com.project.common.core.domain.entity.SysDept; |
| | | import com.project.common.core.domain.entity.SysRole; |
| | | import com.project.common.core.domain.entity.SysUser; |
| | | import com.project.common.core.domain.model.ImportError; |
| | | import com.project.common.exception.ServiceException; |
| | | import com.project.common.exception.base.BaseException; |
| | | import com.project.common.utils.SecurityUtils; |
| | | import com.project.common.utils.StringUtils; |
| | | import com.project.common.utils.bean.BeanValidators; |
| | | import com.project.common.utils.spring.SpringUtils; |
| | | import com.project.system.domain.SysPost; |
| | | import com.project.system.domain.SysUserPost; |
| | | import com.project.system.domain.SysUserRole; |
| | | import com.project.system.domain.*; |
| | | import com.project.system.domain.vo.SysUserResultVo; |
| | | import com.project.system.domain.vo.SysUserVo; |
| | | import com.project.system.mapper.*; |
| | | import com.project.system.service.ISysConfigService; |
| | | import com.project.system.service.ISysDeptService; |
| | | import com.project.system.service.ISysUserDeptService; |
| | | import com.project.system.service.ISysUserService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.slf4j.Logger; |
| | |
| | | private final SysUserRoleMapper userRoleMapper; |
| | | private final SysUserPostMapper userPostMapper; |
| | | private final ISysConfigService configService; |
| | | private final ISysUserDeptService userDeptService; |
| | | private final ISysDeptService deptService; |
| | | protected final Validator validator; |
| | | |
| | | /** |
| | |
| | | insertUserPost(user); |
| | | // 新增用户与角色管理 |
| | | insertUserRole(user); |
| | | // 新增用户与部门管理 |
| | | if (!"02".equals(user.getUserType())){ |
| | | insertUserDept(user); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | |
| | | // 新增用户与岗位管理 |
| | | insertUserPost(user); |
| | | |
| | | // 新增用户与部门管理 |
| | | if (!"02".equals(user.getUserType())){ |
| | | insertUserDept(user); |
| | | } |
| | | return userMapper.updateUser(user); |
| | | } |
| | | |
| | |
| | | public void insertUserRole(SysUser user) |
| | | { |
| | | this.insertUserRole(user.getUserId(), user.getRoleIds()); |
| | | } |
| | | |
| | | /** |
| | | * 新增用户部门 |
| | | * |
| | | * @param user 用户对象 |
| | | */ |
| | | public void insertUserDept(SysUser user) |
| | | { |
| | | userDeptService.remove(userDeptService.lq() |
| | | .eq(SysUserDept::getUserId, user.getUserId()) |
| | | .eq(SysUserDept::getDeptId, user.getDeptId()) |
| | | ); |
| | | SysUserDept userDept = new SysUserDept().setUserId(user.getUserId()).setDeptId(user.getDeptId()); |
| | | userDeptService.save(userDept); |
| | | } |
| | | |
| | | /** |
| | |
| | | public int resetPhone(Long userId, String phone) { |
| | | return userMapper.resetPhone(userId, phone); |
| | | } |
| | | |
| | | @Override |
| | | public SysUserResultVo doImport(List<SysUserVo> list, Long deptId) |
| | | { |
| | | if (list==null || list.size()<1){ |
| | | throw new BaseException("未获取到导入信息!"); |
| | | } |
| | | |
| | | SysUserResultVo resultVo = new SysUserResultVo(); |
| | | list.forEach(sysUserVo -> { |
| | | sysUserVo.setDeptId(deptId); |
| | | }); |
| | | resultVo.setVoList(list); |
| | | return this.checkImport(resultVo); |
| | | } |
| | | |
| | | @Override |
| | | public SysUserResultVo checkImport(SysUserResultVo resultVo) |
| | | { |
| | | if (resultVo==null || StringUtils.isEmpty(resultVo.getVoList())){ |
| | | throw new BaseException("未获取到导入信息!"); |
| | | } |
| | | for (SysUserVo vo : resultVo.getVoList()) { |
| | | List<ImportError> errors = new ArrayList<>(); |
| | | validEntityBeforeImport(vo, errors); |
| | | vo.setErrorList(errors); |
| | | } |
| | | return resultVo; |
| | | } |
| | | |
| | | private void validEntityBeforeImport(SysUserVo entity, List<ImportError> errorList) |
| | | { |
| | | if (StringUtils.isEmpty(entity.getNickName())){ |
| | | errorList.add(new ImportError(0, "请填姓名!")); |
| | | } |
| | | if (StringUtils.isEmpty(entity.getDeptName())){ |
| | | errorList.add(new ImportError(1, "请填写部门信息!")); |
| | | } else { |
| | | SysDept sysDept = deptService.selectDeptById(entity.getDeptId()); |
| | | if (sysDept==null || !sysDept.getDeptName().equals(entity.getDeptName())){ |
| | | errorList.add(new ImportError(1, "部门信息不匹配!")); |
| | | } |
| | | } |
| | | if (StringUtils.isEmpty(entity.getPhonenumber())){ |
| | | errorList.add(new ImportError(2, "请填写手机号!")); |
| | | } else { |
| | | SysUser user = this.selectUserByUserName(entity.getPhonenumber()); |
| | | if (user!=null){ |
| | | entity.setUserId(user.getUserId()); |
| | | } else { |
| | | SysUser check = new SysUser(); |
| | | check.setPhonenumber(entity.getPhonenumber()); |
| | | String s = checkPhoneUnique(check); |
| | | if (UserConstants.NOT_UNIQUE.equals(s)) { |
| | | errorList.add(new ImportError(2, "手机号已存在!")); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Boolean saveImport(SysUserResultVo resultVo) { |
| | | return null; |
| | | } |
| | | } |