|  |  |  | 
|---|
|  |  |  | package com.doumee.biz.system.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.biz.system.SystemUserBiz; | 
|---|
|  |  |  | import com.doumee.config.jwt.JwtProperties; | 
|---|
|  |  |  | import com.doumee.core.annotation.excel.ExcelImporter; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.PwdCheckUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.system.SystemDepartmentUserMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.dto.*; | 
|---|
|  |  |  | import com.doumee.dao.system.dto.UpdatePwdDto; | 
|---|
|  |  |  | import com.doumee.dao.system.model.*; | 
|---|
|  |  |  | import com.doumee.service.system.*; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.RandomStringUtils; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.apache.shiro.SecurityUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class SystemUserBizImpl implements SystemUserBiz { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisTemplate<String,Object> redisTemplate; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemUserService systemUserService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private JwtProperties jwtProperties; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemUserRoleService systemUserRoleService; | 
|---|
|  |  |  | 
|---|
|  |  |  | if(StringUtils.isBlank(dto.getNewPwd()) | 
|---|
|  |  |  | ||dto.getNewPwd().length()>20 | 
|---|
|  |  |  | ||dto.getNewPwd().length()<6 | 
|---|
|  |  |  | ||PwdCheckUtil.checkPassword(dto.getNewPwd())){ | 
|---|
|  |  |  | ||!PwdCheckUtil.checkPassword(dto.getNewPwd())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,密码复杂度不满足要求:6-20个字符,至少包含字母、数字及特殊字符2种"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SystemUser user = systemUserService.findById(dto.getUserId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | newUser.setPassword(Utils.Secure.encryptPassword(dto.getNewPwd(), user.getSalt())); | 
|---|
|  |  |  | newUser.setNeedChangePwd(Constants.ONE); | 
|---|
|  |  |  | systemUserService.updateById(newUser); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("===================更新信息"); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //            log.error("redisTemplate:["+redisTemplate+"]\njwtProperties=:["+jwtProperties+"]\n"+"token:["+dto.getToken()+"]\nuser:"+dto.getLoginUserInfo()); | 
|---|
|  |  |  | if(redisTemplate!=null&&dto.getToken() !=null &&dto.getLoginUserInfo()!=null && jwtProperties!=null){ | 
|---|
|  |  |  | dto.getLoginUserInfo().setNeedChangePwd(Constants.ONE); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(Constants.REDIS_TOKEN_KEY+dto.getToken(),JSONObject.toJSONString(dto.getLoginUserInfo()),jwtProperties.getExpiration(), TimeUnit.MILLISECONDS); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | //            log.error("redisTemplate:["+redisTemplate+"]\njwtProperties=:["+jwtProperties+"]\n"+"token:["+dto.getToken()+"]\nuser:"+dto.getLoginUserInfo()); | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | updateUserDto.setId(dto.getId()); | 
|---|
|  |  |  | updateUserDto.setUpdateUser(dto.getOperaUserId()); | 
|---|
|  |  |  | updateUserDto.setPassword(Utils.Secure.encryptPassword(dto.getPassword(), systemUser.getSalt())); | 
|---|
|  |  |  | updateUserDto.setNeedChangePwd(Constants.ZERO); | 
|---|
|  |  |  | updateUserDto.setNeedChangePwd(dto.getNeedChangePwd()); | 
|---|
|  |  |  | systemUserService.updateById(updateUserDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | user = systemUserService.findOne(queryUserDto); | 
|---|
|  |  |  | if (user != null) { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "工号【"+systemUser.getEmpNo()+"】已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //验证手机号 | 
|---|
|  |  |  | if (StringUtils.isNotBlank(systemUser.getMobile())) { | 
|---|
|  |  |  | queryUserDto = new SystemUser(); | 
|---|
|  |  |  | queryUserDto.setDeleted(Boolean.FALSE); | 
|---|
|  |  |  | queryUserDto.setMobile(systemUser.getMobile()); | 
|---|
|  |  |  | user = systemUserService.findOne(queryUserDto); | 
|---|
|  |  |  | if (user != null) { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "手机号【"+systemUser.getMobile()+"】已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成密码盐 | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "工号【"+systemUser.getEmpNo()+"】已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //验证手机号 | 
|---|
|  |  |  | if (StringUtils.isNotBlank(systemUser.getMobile())) { | 
|---|
|  |  |  | queryUserDto = new SystemUser(); | 
|---|
|  |  |  | queryUserDto.setMobile(systemUser.getMobile()); | 
|---|
|  |  |  | queryUserDto.setDeleted(Boolean.FALSE); | 
|---|
|  |  |  | user = systemUserService.findOne(queryUserDto); | 
|---|
|  |  |  | if (user != null && !user.getId().equals(systemUser.getId())) { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "手机号【"+systemUser.getMobile()+"】已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改用户 | 
|---|
|  |  |  | systemUserService.updateById(systemUser); | 
|---|
|  |  |  | // 设置部门 | 
|---|