|
|
|
@ -16,23 +16,19 @@ 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.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.R; |
|
|
|
|
import com.huoran.iasf.common.utils.*; |
|
|
|
|
import com.huoran.iasf.entity.*; |
|
|
|
|
import com.huoran.iasf.mapper.SysDeptMapper; |
|
|
|
|
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.vo.CheckVo; |
|
|
|
|
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.UEditorResultVO; |
|
|
|
|
import com.huoran.iasf.vo.req.*; |
|
|
|
|
import com.huoran.iasf.vo.resp.LoginRespVO; |
|
|
|
|
import com.huoran.iasf.vo.resp.UserListResp; |
|
|
|
|
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
@ -78,6 +74,10 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private SysDeptMapper sysDeptMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private SysFilesService sysFilesService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HttpSessionService httpSessionService; |
|
|
|
|
|
|
|
|
@ -92,8 +92,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
|
|
|
|
|
@Value("${spring.redis.allowMultipleLogin}") |
|
|
|
|
private Boolean allowMultipleLogin; |
|
|
|
|
@Value("${spring.profiles.active}") |
|
|
|
|
private String env; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void register(SysUser sysUser) { |
|
|
|
@ -184,18 +182,27 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
httpSessionService.abortUserById(vo.getId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(vo.getPassword())) { |
|
|
|
|
if (StringUtils.isNotEmpty(vo.getPassword())) { |
|
|
|
|
String newPassword = PasswordUtils.encode(vo.getPassword(), sysUser.getSalt()); |
|
|
|
|
vo.setPassword(newPassword); |
|
|
|
|
} else { |
|
|
|
|
vo.setPassword(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(vo.getEmail())) { |
|
|
|
|
vo.setEmail(vo.getEmail()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(vo.getPhone())) { |
|
|
|
|
vo.setEmail(vo.getPhone()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//删除所有部门
|
|
|
|
|
userDeptMapper.delete(Wrappers.<UserDept>lambdaQuery().eq(UserDept::getUserId, vo.getId())); |
|
|
|
|
//更新部门
|
|
|
|
|
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) { |
|
|
|
|
List<String> deptArchitectureId = vo.getDeptArchitectureId(); |
|
|
|
|
for (String deptId : deptArchitectureId) { |
|
|
|
|
List<Integer> deptArchitectureId = vo.getDeptArchitectureId(); |
|
|
|
|
for (Integer deptId : deptArchitectureId) { |
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
userDept.setUserId(vo.getId()); |
|
|
|
|
userDept.setDeptId(deptId); |
|
|
|
@ -220,25 +227,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void updateUserInfoMy(SysUser vo) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysUser user = sysUserMapper.selectById(httpSessionService.getCurrentUserId()); |
|
|
|
|
if (null == user) { |
|
|
|
|
throw new BusinessException(BaseResponseCode.DATA_ERROR); |
|
|
|
|
} |
|
|
|
|
if (!StringUtils.isEmpty(vo.getPassword())) { |
|
|
|
|
String newPassword = PasswordUtils.encode(vo.getPassword(), user.getSalt()); |
|
|
|
|
vo.setPassword(newPassword); |
|
|
|
|
} else { |
|
|
|
|
vo.setPassword(null); |
|
|
|
|
} |
|
|
|
|
vo.setUpdateId(httpSessionService.getCurrentUserId()); |
|
|
|
|
sysUserMapper.updateById(vo); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public UserListResp detailInfo(String id) { |
|
|
|
|
return baseMapper.detailInfo(id); |
|
|
|
@ -277,8 +265,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
sysUserMapper.insert(vo); |
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) { |
|
|
|
|
List<String> deptArchitectureId = vo.getDeptArchitectureId(); |
|
|
|
|
for (String deptId : deptArchitectureId) { |
|
|
|
|
List<Integer> deptArchitectureId = vo.getDeptArchitectureId(); |
|
|
|
|
for (Integer deptId : deptArchitectureId) { |
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
userDept.setUserId(vo.getId()); |
|
|
|
|
userDept.setDeptId(deptId); |
|
|
|
@ -315,16 +303,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public UserOwnRoleRespVO getUserOwnRole(String userId) { |
|
|
|
|
List<String> roleIdsByUserId = userRoleService.getRoleIdsByUserId(userId); |
|
|
|
|
List<SysRole> list = roleService.list(); |
|
|
|
|
UserOwnRoleRespVO vo = new UserOwnRoleRespVO(); |
|
|
|
|
vo.setAllRole(list); |
|
|
|
|
vo.setOwnRoles(roleIdsByUserId); |
|
|
|
|
return vo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public Map<String, String> importStaff(MultipartFile file) { |
|
|
|
@ -389,7 +367,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//账号id
|
|
|
|
|
String usernameId = "0"; |
|
|
|
|
Integer usernameId = 0; |
|
|
|
|
|
|
|
|
|
vo1.setIndex(ii); |
|
|
|
|
//检验姓名
|
|
|
|
@ -426,7 +404,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<String> roleIds = new ArrayList<>(); |
|
|
|
|
List<Integer> roleIds = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
//检验角色
|
|
|
|
|
if ("".equals(getRoleName)) { |
|
|
|
@ -545,7 +523,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
vo1.setEmail(getEmail); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ArrayList<String> architectureIds = new ArrayList<>(); |
|
|
|
|
ArrayList<Integer> architectureIds = new ArrayList<>(); |
|
|
|
|
//检验所在部门
|
|
|
|
|
if ("".equals(dept)) { |
|
|
|
|
++countNum; |
|
|
|
@ -574,9 +552,9 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
}else { |
|
|
|
|
//保存架构id
|
|
|
|
|
Object architectureId = hashMap.get("architectureId"); |
|
|
|
|
String id = "0"; |
|
|
|
|
Integer id = 0; |
|
|
|
|
if (architectureId!=null){ |
|
|
|
|
id = (String) architectureId; |
|
|
|
|
id = (Integer)architectureId; |
|
|
|
|
architectureIds.add(id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -598,9 +576,9 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
}else { |
|
|
|
|
//保存架构id
|
|
|
|
|
Object architectureId = hashMap.get("architectureId"); |
|
|
|
|
String id = "0"; |
|
|
|
|
Integer id = 0; |
|
|
|
|
if (architectureId!=null){ |
|
|
|
|
id = (String) architectureId; |
|
|
|
|
id = (Integer) architectureId; |
|
|
|
|
architectureIds.add(id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -629,12 +607,12 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
vo.setStatus(1); |
|
|
|
|
vo.setCreateWhere(1); |
|
|
|
|
if (groupId!=0){ |
|
|
|
|
vo.setGroupId(groupId.toString()); |
|
|
|
|
vo.setGroupId(groupId); |
|
|
|
|
} |
|
|
|
|
sysUserMapper.insert(vo); |
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(architectureIds)) { |
|
|
|
|
for (String deptId : architectureIds) { |
|
|
|
|
for (Integer deptId : architectureIds) { |
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
userDept.setUserId(vo.getId()); |
|
|
|
|
userDept.setDeptId(deptId); |
|
|
|
@ -653,11 +631,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
List<UserDept> userDepts = userDeptMapper. |
|
|
|
|
selectList(new QueryWrapper<UserDept>().eq("user_id", usernameId)); |
|
|
|
|
|
|
|
|
|
ArrayList<String> staffDepartmentIds = new ArrayList<>(); |
|
|
|
|
ArrayList<Integer> staffDepartmentIds = new ArrayList<>(); |
|
|
|
|
for ( UserDept userDept : userDepts) { |
|
|
|
|
staffDepartmentIds.add(userDept.getDeptId()); |
|
|
|
|
} |
|
|
|
|
for (String architectureId : architectureIds) { |
|
|
|
|
for (Integer architectureId : architectureIds) { |
|
|
|
|
if (!staffDepartmentIds.contains(architectureId)){ |
|
|
|
|
UserDept userDept = new UserDept(); |
|
|
|
|
userDept.setUserId(usernameId); |
|
|
|
@ -709,7 +687,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
* 组织架构判重,返回下一层级的父id |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
public String checkArchitectureRepeat(String name ,String pid){ |
|
|
|
|
public Integer checkArchitectureRepeat(String name ,Integer pid){ |
|
|
|
|
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("name",name).eq("pid",pid); |
|
|
|
|
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper); |
|
|
|
@ -741,7 +719,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper1); |
|
|
|
|
if (sysDept == null) { |
|
|
|
|
//为空表示不存在该部门,一级部门不存在,表示子级部门都能直接新增,达底端返回部门id
|
|
|
|
|
String pid = "0"; |
|
|
|
|
Integer pid = 0; |
|
|
|
|
for (int j = 0; j < split.length; j++) { |
|
|
|
|
SysDept sysDept1 = new SysDept(); |
|
|
|
|
sysDept1.setName(split[j]); |
|
|
|
@ -757,11 +735,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
String nextLevelPid = sysDept.getId(); |
|
|
|
|
Integer nextLevelPid = sysDept.getId(); |
|
|
|
|
//存在一级部门,循环查询下一层级,存在则继续向下判断,否则进行新增,到达底端返回部门id
|
|
|
|
|
int pid = 1; |
|
|
|
|
for (int j = 1; j < split.length; j++) { |
|
|
|
|
String nextPid = checkArchitectureRepeat(split[j],nextLevelPid); |
|
|
|
|
Integer nextPid = checkArchitectureRepeat(split[j],nextLevelPid); |
|
|
|
|
//都存在,最后一次循环返回部门id
|
|
|
|
|
if (split.length-1==j){ |
|
|
|
|
map.put("architectureId",nextPid); |
|
|
|
@ -866,4 +844,102 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme |
|
|
|
|
exportParams.setStyle(ExcelStyleUtil.class); |
|
|
|
|
workbook.write(response.getOutputStream()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R sendCheckPhoneCode(CheckVo checkVo) { |
|
|
|
|
boolean re = false; |
|
|
|
|
boolean isSend; |
|
|
|
|
String phoneOrEmail = ""; |
|
|
|
|
|
|
|
|
|
String msg = ""; |
|
|
|
|
if (checkVo.getTypes().equals(1)) {//邮箱验证码
|
|
|
|
|
phoneOrEmail = checkVo.getEmail(); |
|
|
|
|
Integer count = baseMapper.selectCount(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getEmail, checkVo.getEmail())); |
|
|
|
|
if (count>0){ |
|
|
|
|
msg = "邮箱已存在!"; |
|
|
|
|
re = true; |
|
|
|
|
} |
|
|
|
|
} else {//手机验证码
|
|
|
|
|
phoneOrEmail = checkVo.getPhone(); |
|
|
|
|
Integer count = baseMapper.selectCount(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, checkVo.getPhone())); |
|
|
|
|
if (count>0){ |
|
|
|
|
msg = "手机号已存在!"; |
|
|
|
|
re = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (re) { |
|
|
|
|
return R.fail(msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//先从redis中查询该手机号的验证码是否过期,未过期直接返回发送成功,防重放
|
|
|
|
|
//为了保证该手机号5分钟内在其他场景下内正常使用,存入的key需要与短信模板进行拼接
|
|
|
|
|
String key = org.apache.commons.lang3.StringUtils.join(phoneOrEmail, SMSTemplate.AUTHENTICATION_CODE); |
|
|
|
|
System.out.println(key); |
|
|
|
|
String code = stringRedisTemplate.opsForValue().get(key); |
|
|
|
|
if (!StringUtils.isEmpty(code)) { |
|
|
|
|
return R.success("验证码已发,请勿重复操作!"); |
|
|
|
|
} |
|
|
|
|
code = RandomUtil.getSixBitRandom(); |
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
|
param.put("code", code); |
|
|
|
|
if (checkVo.getTypes().equals(1)) {//邮箱验证码
|
|
|
|
|
isSend = EmailUtils.sendEmail(phoneOrEmail, code); |
|
|
|
|
} else {//手机验证码
|
|
|
|
|
isSend = SendSMSUtils.send(phoneOrEmail, SMSTemplate.AUTHENTICATION_CODE, param); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isSend) { |
|
|
|
|
stringRedisTemplate.opsForValue().set(key, code, 5, TimeUnit.MINUTES); |
|
|
|
|
CheckVo checkVo1 = new CheckVo(); |
|
|
|
|
checkVo1.setOpener(key); |
|
|
|
|
return R.success(checkVo1); |
|
|
|
|
} else { |
|
|
|
|
return R.fail("短信发送失败,请稍后重试!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R updatePhoneOrEmail(UpdatePhoneOrEmailReq updatePhoneOrEmailReq) { |
|
|
|
|
String phoneOrEmail = ""; |
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
|
user.setId(updatePhoneOrEmailReq.getUserId()); |
|
|
|
|
if (updatePhoneOrEmailReq.getTypes().equals(1)) {//邮箱验证码
|
|
|
|
|
phoneOrEmail = updatePhoneOrEmailReq.getEmail(); |
|
|
|
|
user.setEmail(updatePhoneOrEmailReq.getEmail()); |
|
|
|
|
} else {//手机验证码
|
|
|
|
|
phoneOrEmail = updatePhoneOrEmailReq.getPhone(); |
|
|
|
|
user.setPhone(updatePhoneOrEmailReq.getPhone()); |
|
|
|
|
} |
|
|
|
|
//从redis中查询该手机号的验证码是否过期
|
|
|
|
|
//为了保证该手机号5分钟内在其他场景下内正常使用,存入的key需要与短信模板进行拼接
|
|
|
|
|
String key = org.apache.commons.lang3.StringUtils.join(phoneOrEmail, SMSTemplate.AUTHENTICATION_CODE); |
|
|
|
|
System.out.println(key); |
|
|
|
|
String code = stringRedisTemplate.opsForValue().get(key); |
|
|
|
|
if (StringUtils.isEmpty(code)) { |
|
|
|
|
return R.fail("验证码已过期!"); |
|
|
|
|
} |
|
|
|
|
if (code.equals(updatePhoneOrEmailReq.getCode())){ |
|
|
|
|
//更新用户手机号
|
|
|
|
|
baseMapper.updateById(user); |
|
|
|
|
return R.success(); |
|
|
|
|
} |
|
|
|
|
return R.fail("验证码错误!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R updateUserAvatars(String userId, MultipartFile file) { |
|
|
|
|
SysUser sysUser = baseMapper.selectById(userId); |
|
|
|
|
|
|
|
|
|
FileParameters fileParameters = new FileParameters(); |
|
|
|
|
fileParameters.setQuote("个人资料"); |
|
|
|
|
fileParameters.setSite("管理后台"); |
|
|
|
|
fileParameters.setUploader(sysUser.getRealName()); |
|
|
|
|
UEditorResultVO uEditorResultVO = sysFilesService.saveFile(file, fileParameters); |
|
|
|
|
|
|
|
|
|
sysUser.setUserAvatars(uEditorResultVO.getUrl()); |
|
|
|
|
int update = baseMapper.updateById(sysUser); |
|
|
|
|
|
|
|
|
|
return update > 0 ? R.success(uEditorResultVO.getUrl()) : R.fail("更新失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|