| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CacheConstant; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.enums.RoleIndexConfigEnum; |
| | | import org.jeecg.common.desensitization.annotation.SensitiveEncode; |
| | | import org.jeecg.common.system.vo.DictModel; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.system.vo.SysUserCacheInfo; |
| | | import org.jeecg.common.util.DateUtils; |
| | | import org.jeecg.common.util.PasswordUtil; |
| | | import org.jeecg.common.util.UUIDGenerator; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | |
| | | import org.jeecg.modules.system.entity.*; |
| | | import org.jeecg.modules.system.mapper.*; |
| | | import org.jeecg.modules.system.model.SysUserSysDepartModel; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.vo.MdcUserProVo; |
| | | import org.jeecg.modules.system.vo.SysUserDepVo; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | |
| | | @Service |
| | | @Slf4j |
| | | public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { |
| | | |
| | | |
| | | @Autowired |
| | | private SysUserMapper userMapper; |
| | | @Autowired |
| | |
| | | SysRoleIndexMapper sysRoleIndexMapper; |
| | | @Resource |
| | | MdcUserProductionMapper mdcUserProductionMapper; |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | |
| | | @Override |
| | | @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true) |
| | |
| | | if (!newpassword.equals(confirmpassword)) { |
| | | return Result.error("两次输入密码不一致!"); |
| | | } |
| | | //设置密码更新时间 |
| | | //sysUser.setPasswordTime(new Date()); |
| | | //设置密码首次登录失效 |
| | | //sysUser.setPasswordFlag(CommonConstant.DEL_FLAG_0); |
| | | String password = PasswordUtil.encrypt(username, newpassword, user.getSalt()); |
| | | this.userMapper.update(new SysUser().setPassword(password), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId())); |
| | | this.userMapper.update(new SysUser().setPassword(password).setPasswordTime(new Date()).setPasswordFlag(CommonConstant.DEL_FLAG_0), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId())); |
| | | return Result.ok("密码重置成功!"); |
| | | } |
| | | |
| | |
| | | public Result<?> changePassword(SysUser sysUser) { |
| | | String salt = oConvertUtils.randomGen(8); |
| | | sysUser.setSalt(salt); |
| | | //设置密码更新时间 |
| | | sysUser.setPasswordTime(new Date()); |
| | | //管理员修改密码,设置用户首次登录 |
| | | //sysUser.setPasswordFlag(); |
| | | String password = sysUser.getPassword(); |
| | | String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt); |
| | | sysUser.setPassword(passwordEncode); |
| | |
| | | public SysUser getUserByName(String username) { |
| | | return userMapper.getUserByName(username); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addUserWithRole(SysUser user, String roles) { |
| | |
| | | roleIndex = list.get(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | //如果componentUrl为空,则返回空 |
| | | if(oConvertUtils.isEmpty(roleIndex.getComponent())){ |
| | | return null; |
| | |
| | | info.setSysUserName(sysUser.getRealname()); |
| | | info.setSysOrgCode(sysUser.getOrgCode()); |
| | | } |
| | | |
| | | |
| | | //多部门支持in查询 |
| | | List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId()); |
| | | List<String> sysMultiOrgCode = new ArrayList<String>(); |
| | |
| | | } |
| | | } |
| | | info.setSysMultiOrgCode(sysMultiOrgCode); |
| | | |
| | | |
| | | return info; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username) { |
| | | return userMapper.getUserByRoleId(page,roleId,username); |
| | | } |
| | | |
| | | /** |
| | | * 根据设备车间管理Id查询 |
| | | * @param page |
| | | * @param workShopDepartId 设备车间管理Id |
| | | * @return |
| | | */ |
| | | public IPage<SysUser> getUserByworkShopDepartId(Page<SysUser> page,String workShopDepartId,String username){ |
| | | return userMapper.getUserByWorkShopDepartId(page,workShopDepartId,username); |
| | | } |
| | | |
| | | |
| | |
| | | baseCommonService.addLog("用户登录失败,用户名:" + sysUser.getUsername() + "已冻结!", CommonConstant.LOG_TYPE_1, null); |
| | | result.error500("该用户已冻结"); |
| | | return result; |
| | | } |
| | | //情况4:根据用户信息查询,该用户密码系首次使用,需修改密码 |
| | | List<DictModel> dictList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_USER_FIRST_LOGIN); |
| | | if (dictList != null && !dictList.isEmpty()) { |
| | | if (CommonConstant.DEL_FLAG_1.equals(Integer.valueOf(dictList.get(0).getValue())) && CommonConstant.DEL_FLAG_1.equals(sysUser.getPasswordFlag())) { |
| | | baseCommonService.addLog("用户登录失败,用户名:" + sysUser.getUsername() + "系首次登录系统,请重置密码!", CommonConstant.LOG_TYPE_1, null); |
| | | result.setCode(5001); |
| | | result.setMessage("用户密码系默认密码,需重置密码后重新登录密码!"); |
| | | result.setSuccess(false); |
| | | return result; |
| | | } |
| | | } |
| | | //情况5:根据用户信息查询,该用户密码是否已过更改周期 |
| | | Date passwordTime = sysUser.getPasswordTime(); |
| | | //Integer passwordExpirationPeriod = CommonConstant.PASSWORD_EXPIRATION_PERIOD; |
| | | List<DictModel> dictModelList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_PASSWORD_EXPIRATION); |
| | | if (dictModelList != null && !dictModelList.isEmpty()) { |
| | | Integer passwordExpirationPeriod = Integer.valueOf(dictModelList.get(0).getValue()); |
| | | Date dayAfter = DateUtils.getDayAfter(passwordTime, passwordExpirationPeriod); |
| | | if (new Date().after(dayAfter)) { |
| | | baseCommonService.addLog("用户登录失败,用户名:" + sysUser.getUsername() + "密码已过有效期,请重置密码!", CommonConstant.LOG_TYPE_1, null); |
| | | result.setCode(5002); |
| | | result.setMessage("用户密码已过有效期,请重置密码!"); |
| | | result.setSuccess(false); |
| | | return result; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | |
| | | public List<String> getUserByRoleCode(String roleCode) { |
| | | return this.baseMapper.getUserByRoleCode(roleCode); |
| | | } |
| | | |
| | | /** |
| | | * 根据角色编码列表查询用户id集合 |
| | | */ |
| | | @Override |
| | | public List<SysUser> getUserByRoleCodeList(List<String> roleCodeList) { |
| | | return this.baseMapper.getUserByRoleCodeList(roleCodeList); |
| | | } |
| | | |
| | | /** |
| | | * 根据角色编码和设备编号查询用户 |
| | | */ |
| | | @Override |
| | | public List<SysUser> getEquipmentAdmin(String roleCode, String equipmentId) { |
| | | return this.baseMapper.getEquipmentAdmin(roleCode, equipmentId); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserSelector> selectOperatorList(String equipmentCode, String productionId, String positionCode) { |
| | | LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(SysUser::getPost, positionCode); |
| | | if(StringUtils.isNotBlank(equipmentCode)) { |
| | | queryWrapper.and(q -> q.isNull(SysUser::getEquipmentIds).or().eq(SysUser::getEquipmentIds, "").or().like(SysUser::getEquipmentIds, equipmentCode)); |
| | | } |
| | | if(StringUtils.isNotBlank(productionId)) { |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id=sys_user.id and t.pro_id={0}", productionId); |
| | | } |
| | | queryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | queryWrapper.eq(SysUser::getStatus, CommonConstant.DEL_FLAG_1); |
| | | queryWrapper.orderByDesc(SysUser::getId); |
| | | List<SysUser> sysUsers = userMapper.selectList(queryWrapper); |
| | | List<UserSelector> collect = sysUsers.stream().map(user -> new UserSelector(user.getId(), user.getUsername(), user.getRealname())).collect(Collectors.toList()); |
| | | return collect; |
| | | } |
| | | |
| | | @Override |
| | | public List<UserSelector> selectOperatorList(String positionCode) { |
| | | LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(SysUser::getPost, positionCode); |
| | | queryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | queryWrapper.eq(SysUser::getStatus, CommonConstant.DEL_FLAG_1); |
| | | queryWrapper.orderByDesc(SysUser::getId); |
| | | List<SysUser> sysUsers = userMapper.selectList(queryWrapper); |
| | | List<UserSelector> collect = sysUsers.stream().map(user -> new UserSelector(user.getId(), user.getUsername(), user.getRealname())).collect(Collectors.toList()); |
| | | return collect; |
| | | } |
| | | } |