|
|
@ -1,30 +1,59 @@ |
|
|
|
package com.huoran.iasf.service.impl; |
|
|
|
package com.huoran.iasf.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
|
|
import com.google.common.collect.Maps; |
|
|
|
import com.huoran.iasf.common.exception.BusinessException; |
|
|
|
import com.huoran.iasf.common.exception.BusinessException; |
|
|
|
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
|
|
|
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
|
|
|
|
|
|
|
import com.huoran.iasf.common.utils.ExcelImportHelper; |
|
|
|
|
|
|
|
import com.huoran.iasf.common.utils.ExcelStyleUtil; |
|
|
|
import com.huoran.iasf.common.utils.PasswordUtils; |
|
|
|
import com.huoran.iasf.common.utils.PasswordUtils; |
|
|
|
import com.huoran.iasf.entity.SysDept; |
|
|
|
import com.huoran.iasf.common.utils.R; |
|
|
|
import com.huoran.iasf.entity.SysRole; |
|
|
|
import com.huoran.iasf.entity.*; |
|
|
|
import com.huoran.iasf.entity.SysUser; |
|
|
|
|
|
|
|
import com.huoran.iasf.mapper.SysDeptMapper; |
|
|
|
import com.huoran.iasf.mapper.SysDeptMapper; |
|
|
|
import com.huoran.iasf.mapper.SysUserMapper; |
|
|
|
import com.huoran.iasf.mapper.SysUserMapper; |
|
|
|
|
|
|
|
import com.huoran.iasf.mapper.UserDeptMapper; |
|
|
|
|
|
|
|
import com.huoran.iasf.mapper.UserGroupMapper; |
|
|
|
import com.huoran.iasf.service.*; |
|
|
|
import com.huoran.iasf.service.*; |
|
|
|
|
|
|
|
import com.huoran.iasf.vo.ImportUserFailureVo; |
|
|
|
|
|
|
|
import com.huoran.iasf.vo.req.ExcelImpUserReq; |
|
|
|
|
|
|
|
import com.huoran.iasf.vo.req.UserListReq; |
|
|
|
import com.huoran.iasf.vo.req.UserRoleOperationReqVO; |
|
|
|
import com.huoran.iasf.vo.req.UserRoleOperationReqVO; |
|
|
|
import com.huoran.iasf.vo.resp.LoginRespVO; |
|
|
|
import com.huoran.iasf.vo.resp.LoginRespVO; |
|
|
|
|
|
|
|
import com.huoran.iasf.vo.resp.PermissionRespNode; |
|
|
|
|
|
|
|
import com.huoran.iasf.vo.resp.UserListResp; |
|
|
|
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; |
|
|
|
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
|
|
|
|
import org.springframework.data.redis.core.ValueOperations; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.List; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 用户 服务类 |
|
|
|
* 用户 服务类 |
|
|
@ -45,6 +74,9 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
private PermissionService permissionService; |
|
|
|
private PermissionService permissionService; |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private UserRoleService userRoleService; |
|
|
|
private UserRoleService userRoleService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private UserDeptMapper userDeptMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private SysDeptMapper sysDeptMapper; |
|
|
|
private SysDeptMapper sysDeptMapper; |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
@ -53,6 +85,12 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private RedisService redisService; |
|
|
|
private RedisService redisService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private UserGroupMapper userGroupMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
StringRedisTemplate stringRedisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${spring.redis.allowMultipleLogin}") |
|
|
|
@Value("${spring.redis.allowMultipleLogin}") |
|
|
|
private Boolean allowMultipleLogin; |
|
|
|
private Boolean allowMultipleLogin; |
|
|
|
@Value("${spring.profiles.active}") |
|
|
|
@Value("${spring.profiles.active}") |
|
|
@ -62,7 +100,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
public void register(SysUser sysUser) { |
|
|
|
public void register(SysUser sysUser) { |
|
|
|
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername())); |
|
|
|
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername())); |
|
|
|
if (sysUserOne != null) { |
|
|
|
if (sysUserOne != null) { |
|
|
|
throw new BusinessException("用户名已存在!"); |
|
|
|
throw new BusinessException(BaseResponseCode.USERNAME_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
sysUser.setSalt(PasswordUtils.getSalt()); |
|
|
|
sysUser.setSalt(PasswordUtils.getSalt()); |
|
|
|
String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt()); |
|
|
|
String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt()); |
|
|
@ -85,6 +123,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
throw new BusinessException(BaseResponseCode.PASSWORD_ERROR); |
|
|
|
throw new BusinessException(BaseResponseCode.PASSWORD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
LoginRespVO respVO = new LoginRespVO(); |
|
|
|
LoginRespVO respVO = new LoginRespVO(); |
|
|
|
|
|
|
|
sysUser.setLastLoginTime(new Date()); |
|
|
|
|
|
|
|
sysUserMapper.updateById(sysUser); |
|
|
|
BeanUtils.copyProperties(sysUser, respVO); |
|
|
|
BeanUtils.copyProperties(sysUser, respVO); |
|
|
|
|
|
|
|
|
|
|
|
//是否删除之前token, 此处控制是否支持多登陆端;
|
|
|
|
//是否删除之前token, 此处控制是否支持多登陆端;
|
|
|
@ -92,15 +132,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
if (!allowMultipleLogin) { |
|
|
|
if (!allowMultipleLogin) { |
|
|
|
httpSessionService.abortUserById(sysUser.getId()); |
|
|
|
httpSessionService.abortUserById(sysUser.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(sysUser.getDeptId())) { |
|
|
|
List<PermissionRespNode> menus = permissionService.permissionTreeList(sysUser.getId()); |
|
|
|
SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId()); |
|
|
|
|
|
|
|
if (sysDept != null) { |
|
|
|
|
|
|
|
sysUser.setDeptNo(sysDept.getDeptNo()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId())); |
|
|
|
String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId())); |
|
|
|
respVO.setAccessToken(token); |
|
|
|
respVO.setAccessToken(token); |
|
|
|
|
|
|
|
respVO.setList(menus); |
|
|
|
return respVO; |
|
|
|
return respVO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -115,11 +151,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
String value = redisService.get(random); |
|
|
|
String value = redisService.get(random); |
|
|
|
//验证码已过期
|
|
|
|
//验证码已过期
|
|
|
|
if (StringUtils.isEmpty(value)) { |
|
|
|
if (StringUtils.isEmpty(value)) { |
|
|
|
throw new BusinessException(10004, "验证码已过期"); |
|
|
|
throw new BusinessException(BaseResponseCode.VERIFICATION_CODE_EXPIRED); |
|
|
|
} |
|
|
|
} |
|
|
|
//验证码错误
|
|
|
|
//验证码错误
|
|
|
|
if (!code.equals(value)) { |
|
|
|
if (!code.equals(value)) { |
|
|
|
throw new BusinessException(10005, "验证码错误"); |
|
|
|
throw new BusinessException(BaseResponseCode.VERIFICATION_CODE_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
redisService.del(random); |
|
|
|
redisService.del(random); |
|
|
|
} |
|
|
|
} |
|
|
@ -127,7 +163,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void updateUserInfo(SysUser vo) { |
|
|
|
public void updateUserInfo(SysUser vo) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysUser sysUser = sysUserMapper.selectById(vo.getId()); |
|
|
|
SysUser sysUser = sysUserMapper.selectById(vo.getId()); |
|
|
|
if (null == sysUser) { |
|
|
|
if (null == sysUser) { |
|
|
|
throw new BusinessException(BaseResponseCode.DATA_ERROR); |
|
|
|
throw new BusinessException(BaseResponseCode.DATA_ERROR); |
|
|
@ -137,7 +172,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
if (!sysUser.getUsername().equals(vo.getUsername())) { |
|
|
|
if (!sysUser.getUsername().equals(vo.getUsername())) { |
|
|
|
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername())); |
|
|
|
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername())); |
|
|
|
if (sysUserOne != null) { |
|
|
|
if (sysUserOne != null) { |
|
|
|
throw new BusinessException("用户名已存在!"); |
|
|
|
throw new BusinessException(BaseResponseCode.USERNAME_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -155,6 +190,30 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
vo.setPassword(null); |
|
|
|
vo.setPassword(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//删除所有部门
|
|
|
|
|
|
|
|
userDeptMapper.delete(Wrappers.<UserDept>lambdaQuery().eq(UserDept::getUserId, vo.getId())); |
|
|
|
|
|
|
|
//更新部门
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) { |
|
|
|
|
|
|
|
List<String> deptArchitectureId = vo.getDeptArchitectureId(); |
|
|
|
|
|
|
|
for (String deptId : deptArchitectureId) { |
|
|
|
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
|
|
|
userDept.setUserId(vo.getId()); |
|
|
|
|
|
|
|
userDept.setDeptId(deptId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<SysUserRole> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
queryWrapper.eq(SysUserRole::getUserId, vo.getId()); |
|
|
|
|
|
|
|
userRoleService.remove(queryWrapper); |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(vo.getRoleIds())) { |
|
|
|
|
|
|
|
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); |
|
|
|
|
|
|
|
reqVO.setUserId(vo.getId()); |
|
|
|
|
|
|
|
reqVO.setRoleIds(vo.getRoleIds()); |
|
|
|
|
|
|
|
userRoleService.addUserRoleInfo(reqVO); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//刷新权限
|
|
|
|
|
|
|
|
httpSessionService.refreshUerId(vo.getId()); |
|
|
|
|
|
|
|
|
|
|
|
vo.setUpdateId(httpSessionService.getCurrentUserId()); |
|
|
|
vo.setUpdateId(httpSessionService.getCurrentUserId()); |
|
|
|
sysUserMapper.updateById(vo); |
|
|
|
sysUserMapper.updateById(vo); |
|
|
|
|
|
|
|
|
|
|
@ -180,55 +239,85 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public IPage<SysUser> pageInfo(SysUser vo) { |
|
|
|
public UserListResp detailInfo(String id) { |
|
|
|
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
return baseMapper.detailInfo(id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public R resetPwd(String userId) { |
|
|
|
|
|
|
|
SysUser sysUser = baseMapper.selectById(userId); |
|
|
|
|
|
|
|
sysUser.setSalt(PasswordUtils.getSalt()); |
|
|
|
|
|
|
|
String encode = PasswordUtils.encode("111aaa", sysUser.getSalt()); |
|
|
|
|
|
|
|
sysUser.setPassword(encode); |
|
|
|
|
|
|
|
int update = baseMapper.updateById(sysUser); |
|
|
|
|
|
|
|
return update>0 ? R.success("重置成功") : R.fail("重置失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public R pageInfo(UserListReq userListReq) { |
|
|
|
|
|
|
|
/*LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
if (!StringUtils.isEmpty(vo.getUsername())) { |
|
|
|
if (!StringUtils.isEmpty(vo.getUsername())) { |
|
|
|
queryWrapper.like(SysUser::getUsername, vo.getUsername()); |
|
|
|
queryWrapper.like(SysUser::getUsername, vo.getUsername()); |
|
|
|
} |
|
|
|
} |
|
|
|
/* if (!StringUtils.isEmpty(vo.getStartTime())) { |
|
|
|
*//* if (!StringUtils.isEmpty(vo.getStartTime())) {
|
|
|
|
queryWrapper.gt(SysUser::getCreateTime, vo.getStartTime()); |
|
|
|
queryWrapper.gt(SysUser::getCreateTime, vo.getStartTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!StringUtils.isEmpty(vo.getEndTime())) { |
|
|
|
if (!StringUtils.isEmpty(vo.getEndTime())) { |
|
|
|
queryWrapper.lt(SysUser::getCreateTime, vo.getEndTime()); |
|
|
|
queryWrapper.lt(SysUser::getCreateTime, vo.getEndTime()); |
|
|
|
}*/ |
|
|
|
}*//*
|
|
|
|
if (!StringUtils.isEmpty(vo.getNickName())) { |
|
|
|
*//* if (!StringUtils.isEmpty(vo.getNickName())) {
|
|
|
|
queryWrapper.like(SysUser::getNickName, vo.getNickName()); |
|
|
|
queryWrapper.like(SysUser::getNickName, vo.getNickName()); |
|
|
|
} |
|
|
|
}*//*
|
|
|
|
if (null != vo.getStatus()) { |
|
|
|
if (null != vo.getStatus()) { |
|
|
|
queryWrapper.eq(SysUser::getStatus, vo.getStatus()); |
|
|
|
queryWrapper.eq(SysUser::getStatus, vo.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!StringUtils.isEmpty(vo.getDeptNo())) { |
|
|
|
// if (!StringUtils.isEmpty(vo.getDeptNo())) {
|
|
|
|
LambdaQueryWrapper<SysDept> queryWrapperDept = Wrappers.lambdaQuery(); |
|
|
|
// LambdaQueryWrapper<SysDept> queryWrapperDept = Wrappers.lambdaQuery();
|
|
|
|
queryWrapperDept.select(SysDept::getId).like(SysDept::getRelationCode, vo.getDeptNo()); |
|
|
|
// queryWrapperDept.select(SysDept::getId).like(SysDept::getRelationCode, vo.getDeptNo());
|
|
|
|
List<Object> list = sysDeptMapper.selectObjs(queryWrapperDept); |
|
|
|
// List<Object> list = sysDeptMapper.selectObjs(queryWrapperDept);
|
|
|
|
queryWrapper.in(SysUser::getDeptId, list); |
|
|
|
// queryWrapper.in(SysUser::getDeptId, list);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
queryWrapper.orderByDesc(SysUser::getCreateTime); |
|
|
|
queryWrapper.orderByDesc(SysUser::getCreateTime); |
|
|
|
IPage<SysUser> iPage = sysUserMapper.selectPage(vo.getQueryPage(), queryWrapper); |
|
|
|
IPage<SysUser> iPage = sysUserMapper.selectPage(vo.getQueryPage(), queryWrapper); |
|
|
|
if (!CollectionUtils.isEmpty(iPage.getRecords())) { |
|
|
|
if (!CollectionUtils.isEmpty(iPage.getRecords())) { |
|
|
|
for (SysUser sysUser : iPage.getRecords()) { |
|
|
|
for (SysUser sysUser : iPage.getRecords()) { |
|
|
|
SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId()); |
|
|
|
*//*SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
|
|
|
|
if (sysDept != null) { |
|
|
|
if (sysDept != null) { |
|
|
|
sysUser.setDeptName(sysDept.getName()); |
|
|
|
sysUser.setDeptName(sysDept.getName()); |
|
|
|
|
|
|
|
}*//*
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
//查询未加入部门的员工,部门id一定清空
|
|
|
|
|
|
|
|
if (userListReq.getType()==2){ |
|
|
|
|
|
|
|
userListReq.setDeptArchitectureId(null); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return iPage; |
|
|
|
Page<UserListResp> page = new Page<UserListResp>(userListReq.getPageNum(), userListReq.getPageSize()); |
|
|
|
|
|
|
|
IPage<UserListResp> userList = baseMapper.userList(page, userListReq); |
|
|
|
|
|
|
|
return R.success(userList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void addUser(SysUser vo) { |
|
|
|
public void addUser(SysUser vo) { |
|
|
|
|
|
|
|
|
|
|
|
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername())); |
|
|
|
|
|
|
|
if (sysUserOne != null) { |
|
|
|
|
|
|
|
throw new BusinessException("用户已存在,请勿重复添加!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
vo.setSalt(PasswordUtils.getSalt()); |
|
|
|
vo.setSalt(PasswordUtils.getSalt()); |
|
|
|
String encode = PasswordUtils.encode(vo.getPassword(), vo.getSalt()); |
|
|
|
String encode = PasswordUtils.encode("111aaa", vo.getSalt()); |
|
|
|
vo.setPassword(encode); |
|
|
|
vo.setPassword(encode); |
|
|
|
vo.setStatus(1); |
|
|
|
vo.setStatus(1); |
|
|
|
vo.setCreateWhere(1); |
|
|
|
vo.setCreateWhere(1); |
|
|
|
sysUserMapper.insert(vo); |
|
|
|
sysUserMapper.insert(vo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) { |
|
|
|
|
|
|
|
List<String> deptArchitectureId = vo.getDeptArchitectureId(); |
|
|
|
|
|
|
|
for (String deptId : deptArchitectureId) { |
|
|
|
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
|
|
|
userDept.setUserId(vo.getId()); |
|
|
|
|
|
|
|
userDept.setDeptId(deptId); |
|
|
|
|
|
|
|
userDeptMapper.insert(userDept); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户账号赋予角色
|
|
|
|
if (!CollectionUtils.isEmpty(vo.getRoleIds())) { |
|
|
|
if (!CollectionUtils.isEmpty(vo.getRoleIds())) { |
|
|
|
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); |
|
|
|
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); |
|
|
|
reqVO.setUserId(vo.getId()); |
|
|
|
reqVO.setUserId(vo.getId()); |
|
|
@ -252,7 +341,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
throw new BusinessException(BaseResponseCode.OLD_PASSWORD_ERROR); |
|
|
|
throw new BusinessException(BaseResponseCode.OLD_PASSWORD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
if (sysUser.getPassword().equals(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()))) { |
|
|
|
if (sysUser.getPassword().equals(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()))) { |
|
|
|
throw new BusinessException("新密码不能与旧密码相同"); |
|
|
|
throw new BusinessException(BaseResponseCode.CANNOT_SAME); |
|
|
|
} |
|
|
|
} |
|
|
|
sysUser.setPassword(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt())); |
|
|
|
sysUser.setPassword(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt())); |
|
|
|
sysUserMapper.updateById(sysUser); |
|
|
|
sysUserMapper.updateById(sysUser); |
|
|
@ -270,4 +359,541 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
vo.setOwnRoles(roleIdsByUserId); |
|
|
|
vo.setOwnRoles(roleIdsByUserId); |
|
|
|
return vo; |
|
|
|
return vo; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
|
|
public Map<String, String> importStaff(MultipartFile file) { |
|
|
|
|
|
|
|
List<ExcelImpUserReq> impStaffReqList = ExcelImportHelper.readUser(file); |
|
|
|
|
|
|
|
if (impStaffReqList.size() <= 0) { |
|
|
|
|
|
|
|
//小于等于0为上传空模板的情况下 抛出异常
|
|
|
|
|
|
|
|
throw new BusinessException(BaseResponseCode.EXCEL_FILE_FORMAT_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int count = 0; |
|
|
|
|
|
|
|
List<ImportUserFailureVo> failVo1 = new ArrayList<ImportUserFailureVo>(); |
|
|
|
|
|
|
|
// 参数合法性校验,只能上传.xlsx后缀的文件
|
|
|
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(file.getOriginalFilename()) |
|
|
|
|
|
|
|
|| !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(".xlsx")) { |
|
|
|
|
|
|
|
throw new BusinessException(BaseResponseCode.EXCEL_FILE_INVALID); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int size = impStaffReqList.size(); |
|
|
|
|
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
|
|
|
|
Long ii = 1L;//用于记录序列号
|
|
|
|
|
|
|
|
Integer countNum = 0;//用于失败原因排序 eg:1、XXXXX 2、XXXXXXX
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Integer countSuccess = 0;//统计成功次数
|
|
|
|
|
|
|
|
Integer countError = 0;//统计失败次数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> workNumberList = new ArrayList<>();//用来储存新增前用户在excel中输入的所有学号用于excel中的数据判重
|
|
|
|
|
|
|
|
List<String> accountList = new ArrayList<>();//用来储存新增前用户在excel中输入的所有账号用于excel中的数据判重
|
|
|
|
|
|
|
|
for (int i = 0; i < impStaffReqList.size(); i++) { |
|
|
|
|
|
|
|
boolean ret = true; |
|
|
|
|
|
|
|
++ii; |
|
|
|
|
|
|
|
ExcelImpUserReq req = impStaffReqList.get(i); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImportUserFailureVo vo1 = new ImportUserFailureVo(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String errMsg = ""; |
|
|
|
|
|
|
|
//去除Excel中的全角半角空格
|
|
|
|
|
|
|
|
String realName = req.getRealName().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
String username = req.getUserName().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
String getRoleName = req.getRoleName().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
String jobNumber = req.getJobNumber().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
String dept = req.getDept().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
String getPhone = req.getPhone().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
String getEmail = req.getEmail().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
String groupName = req.getGroupName().replaceAll("\\u00A0", "").trim(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!workNumberList.contains(req.getJobNumber())) { |
|
|
|
|
|
|
|
workNumberList.add(req.getJobNumber()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//包含excel数据中存在相同学号
|
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setJobNumber(jobNumber + " *必填项:(当前Excel数据中该工号已存在重复的!)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(当前Excel数据中该工号号已存在重复的)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!accountList.contains(req.getUserName())) { |
|
|
|
|
|
|
|
accountList.add(req.getUserName()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//包含excel数据中存在相同账号
|
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setUserName(username + " *必填项:(当前Excel数据中该账号已存在重复的)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(当前Excel数据中该账号已存在重复的)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//账号id
|
|
|
|
|
|
|
|
String usernameId = "0"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vo1.setIndex(ii); |
|
|
|
|
|
|
|
//检验姓名
|
|
|
|
|
|
|
|
if ("".equals(realName)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setUserName(realName + " *必填项:(姓名不能为空) "); |
|
|
|
|
|
|
|
errMsg += countNum + "必填项:(姓名不能为空)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
vo1.setUserName(realName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//检验账号
|
|
|
|
|
|
|
|
if ("".equals(username)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setUserName(username + " *必填项:(账号不能为空)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(账号不能为空)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
queryWrapper.eq(SysUser::getUsername, username); |
|
|
|
|
|
|
|
SysUser selectOne = baseMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
//账号存在,验证该账号相关信息
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(selectOne)) { |
|
|
|
|
|
|
|
if (username.equals(selectOne.getUsername())&&jobNumber.equals(selectOne.getJobNumber())){ |
|
|
|
|
|
|
|
usernameId=selectOne.getId(); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setUserName(username + " *必填项:(账号已有重复的)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(账号已有重复的)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
vo1.setUserName(username + ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> roleIds = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//检验角色
|
|
|
|
|
|
|
|
if ("".equals(getRoleName)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setRoleName(getRoleName + " *必填项:(角色不能为空)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(角色不能为空)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//分隔多个角色
|
|
|
|
|
|
|
|
String[] roleNames = getRoleName.split("/"); |
|
|
|
|
|
|
|
for (int r = 0; r < roleNames.length; r++) { |
|
|
|
|
|
|
|
// 查询多个角色是否存在
|
|
|
|
|
|
|
|
LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
queryWrapper.eq(SysRole::getName, roleNames[r]); |
|
|
|
|
|
|
|
SysRole role = roleService.getOne(queryWrapper); |
|
|
|
|
|
|
|
if (role != null && !"超级管理员".equals(role.getName())) { |
|
|
|
|
|
|
|
roleIds.add(role.getId()); |
|
|
|
|
|
|
|
//存在
|
|
|
|
|
|
|
|
vo1.setRoleName(getRoleName); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//不存在
|
|
|
|
|
|
|
|
vo1.setRoleName(getRoleName + " *必填项:(请输入系统中存在的角色)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(请输入系统中存在的角色)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//检验工号
|
|
|
|
|
|
|
|
if ("".equals(jobNumber)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setJobNumber(jobNumber + " *必填项:(工号不能为空)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(工号不能为空)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
queryWrapper.eq(SysUser::getJobNumber, jobNumber); |
|
|
|
|
|
|
|
SysUser selectOne = baseMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(selectOne)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setJobNumber(jobNumber + " *必填项:(工号已经存在重复的)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(工号已经存在重复的)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
vo1.setJobNumber(jobNumber + ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer groupId = 0; |
|
|
|
|
|
|
|
//检验用户组
|
|
|
|
|
|
|
|
if (!"".equals(groupName)) { |
|
|
|
|
|
|
|
LambdaQueryWrapper<UserGroup> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
queryWrapper.eq(UserGroup::getGroupName, groupName); |
|
|
|
|
|
|
|
UserGroup userGroup1 = userGroupMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(userGroup1)) { |
|
|
|
|
|
|
|
groupId=userGroup1.getId(); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
UserGroup userGroup = new UserGroup(); |
|
|
|
|
|
|
|
userGroup.setGroupName(groupName); |
|
|
|
|
|
|
|
int insert = userGroupMapper.insert(userGroup); |
|
|
|
|
|
|
|
groupId=userGroup.getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!"".equals(getPhone)) { |
|
|
|
|
|
|
|
//校验手机号格式
|
|
|
|
|
|
|
|
if (!validPhoneNum("0", getPhone)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setPhone(getPhone + " *请输入正确的手机号!"); |
|
|
|
|
|
|
|
errMsg += countNum + " *请输入正确的手机号!"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//用户账号存在,手机号邮箱则跳过效验
|
|
|
|
|
|
|
|
if ("0".equals(usernameId)){ |
|
|
|
|
|
|
|
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
queryWrapper.eq(SysUser::getPhone, getPhone); |
|
|
|
|
|
|
|
SysUser selectOne = baseMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(selectOne)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setPhone(getPhone + " *该手机号已被绑定!"); |
|
|
|
|
|
|
|
errMsg += countNum + " *该手机号已被绑定!"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
vo1.setPhone(getPhone); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
vo1.setPhone(getPhone); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!"".equals(getEmail)) { |
|
|
|
|
|
|
|
//校验邮箱格式
|
|
|
|
|
|
|
|
if (!isValidEmail(getEmail)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setEmail(getEmail + "*请输入正确的邮箱格式!"); |
|
|
|
|
|
|
|
errMsg += countNum + " *请输入正确的邮箱格式!"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if ("0".equals(usernameId)){ |
|
|
|
|
|
|
|
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
queryWrapper.eq(SysUser::getEmail, getEmail); |
|
|
|
|
|
|
|
SysUser selectOne = baseMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(selectOne)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setEmail(getEmail + " *该邮箱已被绑定!"); |
|
|
|
|
|
|
|
errMsg += countNum + " *该邮箱已被绑定!"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
vo1.setEmail(getEmail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
vo1.setEmail(getEmail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<String> architectureIds = new ArrayList<>(); |
|
|
|
|
|
|
|
//检验所在部门
|
|
|
|
|
|
|
|
if ("".equals(dept)) { |
|
|
|
|
|
|
|
++countNum; |
|
|
|
|
|
|
|
vo1.setDept(dept + " *必填项:(请输入正确的员工架构!)"); |
|
|
|
|
|
|
|
errMsg += countNum + " *必填项:(请输入正确的员工架构!)"; |
|
|
|
|
|
|
|
ret = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (ret){ |
|
|
|
|
|
|
|
//检验是否有多部门
|
|
|
|
|
|
|
|
String[] multi = dept.split(","); |
|
|
|
|
|
|
|
//多部门进行循环添加每个部门
|
|
|
|
|
|
|
|
if (multi.length>1){ |
|
|
|
|
|
|
|
for (int d = 0; d < multi.length; d++) { |
|
|
|
|
|
|
|
HashMap<String, Object> hashMap = automaticAddArchitecture(multi[d], countNum, dept, vo1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object countNum1 = hashMap.get("countNum"); |
|
|
|
|
|
|
|
//存在错误数据
|
|
|
|
|
|
|
|
if (countNum1!=null){ |
|
|
|
|
|
|
|
countNum = (Integer) countNum1; |
|
|
|
|
|
|
|
Object vo11 = hashMap.get("vo1"); |
|
|
|
|
|
|
|
vo1 = (ImportUserFailureVo) vo11; |
|
|
|
|
|
|
|
Object errMsg1 = hashMap.get("errMsg"); |
|
|
|
|
|
|
|
errMsg = (String) errMsg1; |
|
|
|
|
|
|
|
Object ret1 = hashMap.get("ret"); |
|
|
|
|
|
|
|
ret = (boolean) ret1; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
//保存架构id
|
|
|
|
|
|
|
|
Object architectureId = hashMap.get("architectureId"); |
|
|
|
|
|
|
|
String id = "0"; |
|
|
|
|
|
|
|
if (architectureId!=null){ |
|
|
|
|
|
|
|
id = (String) architectureId; |
|
|
|
|
|
|
|
architectureIds.add(id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
HashMap<String, Object> hashMap = automaticAddArchitecture(dept, countNum, dept, vo1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object countNum1 = hashMap.get("countNum"); |
|
|
|
|
|
|
|
//存在错误数据
|
|
|
|
|
|
|
|
if (countNum1!=null){ |
|
|
|
|
|
|
|
countNum = (Integer) countNum1; |
|
|
|
|
|
|
|
Object vo11 = hashMap.get("vo1"); |
|
|
|
|
|
|
|
vo1 = (ImportUserFailureVo) vo11; |
|
|
|
|
|
|
|
Object errMsg1 = hashMap.get("errMsg"); |
|
|
|
|
|
|
|
errMsg = (String) errMsg1; |
|
|
|
|
|
|
|
Object ret1 = hashMap.get("ret"); |
|
|
|
|
|
|
|
ret = (boolean) ret1; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
//保存架构id
|
|
|
|
|
|
|
|
Object architectureId = hashMap.get("architectureId"); |
|
|
|
|
|
|
|
String id = "0"; |
|
|
|
|
|
|
|
if (architectureId!=null){ |
|
|
|
|
|
|
|
id = (String) architectureId; |
|
|
|
|
|
|
|
architectureIds.add(id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vo1.setFailureMsg(errMsg); |
|
|
|
|
|
|
|
countNum = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
failVo1.add(vo1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//ret判断 新增成功的插入到数据库 否则则不新增至数据库
|
|
|
|
|
|
|
|
if (ret) { |
|
|
|
|
|
|
|
//用户账号不存在
|
|
|
|
|
|
|
|
if ("0".equals(usernameId)){ |
|
|
|
|
|
|
|
SysUser vo = new SysUser(); |
|
|
|
|
|
|
|
vo.setSalt(PasswordUtils.getSalt()); |
|
|
|
|
|
|
|
String encode = PasswordUtils.encode("111aaa", vo.getSalt()); |
|
|
|
|
|
|
|
vo.setPassword(encode); |
|
|
|
|
|
|
|
vo.setStatus(1); |
|
|
|
|
|
|
|
vo.setCreateWhere(1); |
|
|
|
|
|
|
|
if (groupId!=0){ |
|
|
|
|
|
|
|
vo.setGroupId(groupId.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sysUserMapper.insert(vo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(architectureIds)) { |
|
|
|
|
|
|
|
for (String deptId : architectureIds) { |
|
|
|
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
|
|
|
userDept.setUserId(vo.getId()); |
|
|
|
|
|
|
|
userDept.setDeptId(deptId); |
|
|
|
|
|
|
|
userDeptMapper.insert(userDept); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户账号赋予角色
|
|
|
|
|
|
|
|
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); |
|
|
|
|
|
|
|
reqVO.setUserId(vo.getId()); |
|
|
|
|
|
|
|
reqVO.setRoleIds(roleIds); |
|
|
|
|
|
|
|
userRoleService.addUserRoleInfo(reqVO); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
//导入新部门、赋予新角色
|
|
|
|
|
|
|
|
List<UserDept> userDepts = userDeptMapper. |
|
|
|
|
|
|
|
selectList(new QueryWrapper<UserDept>().eq("user_id", usernameId)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<String> staffDepartmentIds = new ArrayList<>(); |
|
|
|
|
|
|
|
for ( UserDept userDept : userDepts) { |
|
|
|
|
|
|
|
staffDepartmentIds.add(userDept.getDeptId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (String architectureId : architectureIds) { |
|
|
|
|
|
|
|
if (!staffDepartmentIds.contains(architectureId)){ |
|
|
|
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
|
|
|
userDept.setUserId(usernameId); |
|
|
|
|
|
|
|
userDept.setDeptId(architectureId); |
|
|
|
|
|
|
|
userDeptMapper.insert(userDept); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户账号赋予角色
|
|
|
|
|
|
|
|
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); |
|
|
|
|
|
|
|
reqVO.setUserId(usernameId); |
|
|
|
|
|
|
|
reqVO.setRoleIds(roleIds); |
|
|
|
|
|
|
|
userRoleService.addUserRoleInfo(reqVO); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//countSuccess:统计累计成功次数
|
|
|
|
|
|
|
|
countSuccess++; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//countError:累计失败次数
|
|
|
|
|
|
|
|
countError++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String exportCode = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 有导入失败的数据,才会存入redis
|
|
|
|
|
|
|
|
if (countError > 0) { |
|
|
|
|
|
|
|
//生成token
|
|
|
|
|
|
|
|
exportCode = "FAILURE_IMPORT" + UUID.randomUUID().toString().replace("-", ""); |
|
|
|
|
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ImportUserFailureVo> collect = failVo1.stream().filter(importStaffFailureVo -> { |
|
|
|
|
|
|
|
return !importStaffFailureVo.getFailureMsg().equals(""); |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String failureVOJson = JSON.toJSONString(collect); |
|
|
|
|
|
|
|
ops.set(exportCode, failureVOJson, 30 * 60, TimeUnit.SECONDS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
map.put("exportCode", exportCode);//返回导出code
|
|
|
|
|
|
|
|
map.put("successNum", countSuccess + "");//本次新增成功数量
|
|
|
|
|
|
|
|
map.put("failureNum", countError + "");//本次新增失败数量
|
|
|
|
|
|
|
|
return map; |
|
|
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
|
|
|
System.err.println(e.getMessage()); |
|
|
|
|
|
|
|
throw new RuntimeException(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 组织架构判重,返回下一层级的父id |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String checkArchitectureRepeat(String name ,String pid){ |
|
|
|
|
|
|
|
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
|
|
queryWrapper.eq("name",name).eq("pid",pid); |
|
|
|
|
|
|
|
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
if (sysDept!=null){ |
|
|
|
|
|
|
|
return sysDept.getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 根据导入部门自动添加组织架构 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public HashMap<String, Object> automaticAddArchitecture(String architectureName,Integer countNum, |
|
|
|
|
|
|
|
String dept,ImportUserFailureVo vo1){ |
|
|
|
|
|
|
|
HashMap<String, Object> map = Maps.newHashMap(); |
|
|
|
|
|
|
|
//获取部门层级
|
|
|
|
|
|
|
|
String[] split = architectureName.split("/"); |
|
|
|
|
|
|
|
if (split.length>6){ |
|
|
|
|
|
|
|
map.put("countNum",++countNum); |
|
|
|
|
|
|
|
map.put("vo1",vo1.setDept(dept + " 员工架构暂不支持第7层级")); |
|
|
|
|
|
|
|
map.put("errMsg",countNum + " 员工架构暂不支持第7层级"); |
|
|
|
|
|
|
|
map.put("ret",false); |
|
|
|
|
|
|
|
return map; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 检验输入的一级部门是否存在
|
|
|
|
|
|
|
|
//查询一级部门信息
|
|
|
|
|
|
|
|
QueryWrapper<SysDept> queryWrapper1 = new QueryWrapper<>(); |
|
|
|
|
|
|
|
queryWrapper1.eq("name", split[0]); |
|
|
|
|
|
|
|
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper1); |
|
|
|
|
|
|
|
if (sysDept == null) { |
|
|
|
|
|
|
|
//为空表示不存在该部门,一级部门不存在,表示子级部门都能直接新增,达底端返回部门id
|
|
|
|
|
|
|
|
String pid = "0"; |
|
|
|
|
|
|
|
for (int j = 0; j < split.length; j++) { |
|
|
|
|
|
|
|
SysDept sysDept1 = new SysDept(); |
|
|
|
|
|
|
|
sysDept1.setName(split[j]); |
|
|
|
|
|
|
|
sysDept1.setPid(pid); |
|
|
|
|
|
|
|
int insert = sysDeptMapper.insert(sysDept1); |
|
|
|
|
|
|
|
//添加成功后id赋值给下一层级父id
|
|
|
|
|
|
|
|
if (insert>0){ |
|
|
|
|
|
|
|
pid = sysDept1.getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//最后返回部门id
|
|
|
|
|
|
|
|
if (split.length-1==j){ |
|
|
|
|
|
|
|
map.put("architectureId",pid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
String nextLevelPid = sysDept.getId(); |
|
|
|
|
|
|
|
//存在一级部门,循环查询下一层级,存在则继续向下判断,否则进行新增,到达底端返回部门id
|
|
|
|
|
|
|
|
int pid = 1; |
|
|
|
|
|
|
|
for (int j = 1; j < split.length; j++) { |
|
|
|
|
|
|
|
String nextPid = checkArchitectureRepeat(split[j],nextLevelPid); |
|
|
|
|
|
|
|
//都存在,最后一次循环返回部门id
|
|
|
|
|
|
|
|
if (split.length-1==j){ |
|
|
|
|
|
|
|
map.put("architectureId",nextPid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//层级已存在,进入下次循环
|
|
|
|
|
|
|
|
if (nextPid!=null){ |
|
|
|
|
|
|
|
nextLevelPid = nextPid; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//该层级不存在,进行新增
|
|
|
|
|
|
|
|
SysDept sysDept1 = new SysDept(); |
|
|
|
|
|
|
|
sysDept1.setName(split[j]); |
|
|
|
|
|
|
|
sysDept1.setPid(nextLevelPid); |
|
|
|
|
|
|
|
int insert = sysDeptMapper.insert(sysDept1); |
|
|
|
|
|
|
|
//添加成功后id赋值给下一层级父id
|
|
|
|
|
|
|
|
if (insert>0){ |
|
|
|
|
|
|
|
nextLevelPid = sysDept1.getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//最后返回部门id
|
|
|
|
|
|
|
|
if (split.length-1==j){ |
|
|
|
|
|
|
|
map.put("architectureId",nextLevelPid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return map; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @Description : 校验手机号 |
|
|
|
|
|
|
|
* @Param checkType 校验类型:0校验手机号码,1校验座机号码,2两者都校验满足其一就可 |
|
|
|
|
|
|
|
* @Param phoneNum |
|
|
|
|
|
|
|
* @Author Rong---2021/10/18 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static boolean validPhoneNum(String checkType, String phoneNum) { |
|
|
|
|
|
|
|
boolean flag = false; |
|
|
|
|
|
|
|
Pattern p1 = null; |
|
|
|
|
|
|
|
Pattern p2 = null; |
|
|
|
|
|
|
|
Matcher m = null; |
|
|
|
|
|
|
|
p1 = Pattern.compile("^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\\d{8})?$"); |
|
|
|
|
|
|
|
p2 = Pattern.compile("^(0[0-9]{2,3}\\-)?([1-9][0-9]{6,7})$"); |
|
|
|
|
|
|
|
if ("0".equals(checkType)) { |
|
|
|
|
|
|
|
System.out.println(phoneNum.length()); |
|
|
|
|
|
|
|
if (phoneNum.length() != 11) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
m = p1.matcher(phoneNum); |
|
|
|
|
|
|
|
flag = m.matches(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if ("1".equals(checkType)) { |
|
|
|
|
|
|
|
if (phoneNum.length() < 11 || phoneNum.length() >= 16) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
m = p2.matcher(phoneNum); |
|
|
|
|
|
|
|
flag = m.matches(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if ("2".equals(checkType)) { |
|
|
|
|
|
|
|
if (!((phoneNum.length() == 11 && p1.matcher(phoneNum).matches()) || (phoneNum.length() < 16 && p2.matcher(phoneNum).matches()))) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
flag = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return flag; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @Description : 校验邮箱 |
|
|
|
|
|
|
|
* @Param email |
|
|
|
|
|
|
|
* @Author Rong---2021/10/18 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static boolean isValidEmail(String email) { |
|
|
|
|
|
|
|
if ((email != null) && (!email.isEmpty())) { |
|
|
|
|
|
|
|
return Pattern.matches("^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$", email); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void exportFailureRecord(HttpServletResponse response, String token) throws IOException { |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(token)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
|
|
|
|
//获取数据
|
|
|
|
|
|
|
|
String record = ops.get(token); |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(record)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<ImportUserFailureVo> parse = JSON.parseObject(record, new TypeReference<List<ImportUserFailureVo>>() { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parse.sort(Comparator.comparing(ImportUserFailureVo::getIndex)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 告诉浏览器用什么软件可以打开此文件
|
|
|
|
|
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
|
|
|
|
|
// 下载文件的默认名称
|
|
|
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("员工导入失败数据表", "UTF-8") + ".xls"); |
|
|
|
|
|
|
|
//编码
|
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ImportUserFailureVo.class, parse); |
|
|
|
|
|
|
|
ExportParams exportParams = new ExportParams(null, "delivery", ExcelType.XSSF); |
|
|
|
|
|
|
|
exportParams.setStyle(ExcelStyleUtil.class); |
|
|
|
|
|
|
|
workbook.write(response.getOutputStream()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|