| | |
| | | import cn.hutool.core.util.DesensitizedUtil; |
| | | import cn.hutool.core.util.PhoneUtil; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.xiaopeng.api.vo.account.*; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.SensitiveDataCryptoUtil; |
| | | import com.xiaopeng.common.core.utils.poi.ExcelUtil; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.security.service.TokenService; |
| | |
| | | @Override |
| | | public XpOperationsUser getById(Serializable userId){ |
| | | XpOperationsUser user = baseMapper.selectById(userId); |
| | | decryptPhone(user); |
| | | return user; |
| | | } |
| | | |
| | |
| | | } |
| | | List<XpOperationsUser> list = lambdaQuery().like(XpOperationsUser::getNickName, nickName).list(); |
| | | for (XpOperationsUser obj : list) { |
| | | decryptPhone(obj); |
| | | obj.setPhoneNumber(DesensitizedUtil.mobilePhone(obj.getPhoneNumber())); |
| | | } |
| | | return list; |
| | |
| | | @Override |
| | | public PageInfo<XpOperationsUserWithRoleVO> selectUserPageByConditions(XpOperationsUserPageQuery query) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | query.setPhoneNumberQueryValues(SensitiveDataCryptoUtil.queryValues(query.getPhoneNumber())); |
| | | PageInfo<XpOperationsUserWithRoleVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | Page<XpOperationsUserWithRoleVO> page = baseMapper.selectUserPageByConditions(pageInfo, query); |
| | | decryptWithRolePhones(page.getRecords()); |
| | | if(!loginUser.getPhoneDesensitizationExempt()){ |
| | | for (XpOperationsUserWithRoleVO record : page.getRecords()) { |
| | | record.setPhoneNumber(DesensitizedUtil.mobilePhone(record.getPhoneNumber())); |
| | |
| | | |
| | | @Override |
| | | public List<XpOperationsUserWithRoleVO> findList(XpOperationsUserQueryDTO query){ |
| | | return baseMapper.selectUserPageByConditions(query); |
| | | query.setPhoneNumberQueryValues(SensitiveDataCryptoUtil.queryValues(query.getPhoneNumber())); |
| | | List<XpOperationsUserWithRoleVO> list = baseMapper.selectUserPageByConditions(query); |
| | | decryptWithRolePhones(list); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | XpOperationsUserProfileVO vo = new XpOperationsUserProfileVO(); |
| | | BeanUtils.copyProperties(user, vo); |
| | | vo.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(vo.getPhoneNumber())); |
| | | vo.setAvatar(aliOssDownloadUtil.getPictureJSONObject(vo.getAvatar())); |
| | | // 2. 查询关联的车队ID列表(一个运维人员只能关联一个车队) |
| | | R<List<Long>> fleetIdsResult = xpFleetOperationsClient.getFleetIdsByUserId(userId); |
| | |
| | | @Override |
| | | public PageInfo<XpOperationsUserVO> pageList(XpOperationsUserQuery query) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | query.setPhoneNumberQueryValues(SensitiveDataCryptoUtil.queryValues(query.getPhoneNumber())); |
| | | PageInfo<XpOperationsUserVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<XpOperationsUserVO> list = this.baseMapper.pageList(pageInfo, query); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | decryptVoPhones(list); |
| | | for (XpOperationsUserVO xpOperationsUserVO : list) { |
| | | if(!loginUser.getPhoneDesensitizationExempt()){ |
| | | xpOperationsUserVO.setPhoneNumber(DesensitizedUtil.mobilePhone(xpOperationsUserVO.getPhoneNumber())); |
| | |
| | | |
| | | @Override |
| | | public R<String> addOperationsUser(XpOperationsUserAddDTO dto) { |
| | | long userCount = this.count(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .eq(XpOperationsUser::getPhoneNumber, dto.getPhoneNumber())); |
| | | if (StringUtils.isNotBlank(dto.getPhoneNumber()) && userCount>0) { |
| | | throw new ServiceException("登录账号重复", I18nKeyConstant.ACCOUNT_DUPLICATE); |
| | | if (StringUtils.isNotBlank(dto.getPhoneNumber())) { |
| | | long userCount = this.count(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .in(XpOperationsUser::getPhoneNumber, SensitiveDataCryptoUtil.queryValues(dto.getPhoneNumber()))); |
| | | if (userCount > 0) { |
| | | throw new ServiceException("登录账号重复", I18nKeyConstant.ACCOUNT_DUPLICATE); |
| | | } |
| | | } |
| | | //校验编号是否唯一 |
| | | long numberCount = this.count(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | |
| | | |
| | | @Override |
| | | public R<String> editOperationsUser(XpOperationsUserAddDTO dto) { |
| | | XpOperationsUser operationsUser = this.getOne(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .eq(XpOperationsUser::getPhoneNumber, dto.getPhoneNumber()) |
| | | .last("LIMIT 1")); |
| | | |
| | | if (StringUtils.isNotBlank(dto.getPhoneNumber()) && (Objects.nonNull(operationsUser) && !dto.getId().equals(operationsUser.getId()) )) { |
| | | throw new ServiceException("手机号已开通账号", I18nKeyConstant.ACCOUNT_PHONE_DUPLICATE); |
| | | if (StringUtils.isNotBlank(dto.getPhoneNumber())) { |
| | | XpOperationsUser operationsUser = this.getOne(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .in(XpOperationsUser::getPhoneNumber, SensitiveDataCryptoUtil.queryValues(dto.getPhoneNumber())) |
| | | .last("LIMIT 1")); |
| | | if (Objects.nonNull(operationsUser) && !dto.getId().equals(operationsUser.getId())) { |
| | | throw new ServiceException("手机号已开通账号", I18nKeyConstant.ACCOUNT_PHONE_DUPLICATE); |
| | | } |
| | | } |
| | | if (dto.getPassword() != null && !dto.getPassword().isEmpty()) { |
| | | dto.setPassword(null); |
| | |
| | | XpOperationsUser xpOperationsUser = this.getById(id); |
| | | XpOperationsUserVO xpOperationsUserVO = new XpOperationsUserVO(); |
| | | BeanUtils.copyProperties(xpOperationsUser, xpOperationsUserVO); |
| | | xpOperationsUserVO.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(xpOperationsUserVO.getPhoneNumber())); |
| | | // 查询角色 |
| | | List<XpOperationsRole> xpOperationsRoles = xpOperationsRoleMapper.selectList(Wrappers.lambdaQuery(XpOperationsRole.class) |
| | | .eq(XpOperationsRole::getOperationsUserId, id)); |
| | |
| | | */ |
| | | @Override |
| | | public void exportOperationsUser(XpOperationsUserQuery query, HttpServletResponse response) { |
| | | query.setPhoneNumberQueryValues(SensitiveDataCryptoUtil.queryValues(query.getPhoneNumber())); |
| | | List<ExportOperationsUserVo> list = this.baseMapper.exportOperationsUser(query); |
| | | for (ExportOperationsUserVo item : list) { |
| | | item.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(item.getPhoneNumber())); |
| | | } |
| | | ExcelUtil<ExportOperationsUserVo> util = new ExcelUtil<ExportOperationsUserVo>(ExportOperationsUserVo.class); |
| | | util.exportExcel(response, list, "运维人员管理列表"); |
| | | } |
| | |
| | | } |
| | | // 判断账号是否已存在 |
| | | long count = this.count(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .eq(XpOperationsUser::getPhoneNumber, exportOperationsUserVo.getPhoneNumber())); |
| | | .in(XpOperationsUser::getPhoneNumber, SensitiveDataCryptoUtil.queryValues(exportOperationsUserVo.getPhoneNumber()))); |
| | | if (count > 0) { |
| | | throw new ServiceException("以下帐号已存在:", I18nKeyConstant.ACCOUNT_EXIST,new Object[]{exportOperationsUserVo.getPhoneNumber()}); |
| | | } |
| | | xpOperationsUser.setPhoneNumber(exportOperationsUserVo.getPhoneNumber()); |
| | | xpOperationsUser.setPhoneNumber(SensitiveDataCryptoUtil.encrypt(exportOperationsUserVo.getPhoneNumber())); |
| | | xpOperationsUser.setPassword(SecurityUtils.encryptPassword("a123456")); |
| | | xpOperationsUser.setRemarks(exportOperationsUserVo.getRemarks()); |
| | | xpOperationsUser.setStatus(true); |
| | |
| | | |
| | | // 根据你的 VO 字段调整 |
| | | XpOperationsUserWithRoleVO vo = BeanUtil.copyProperties(u, XpOperationsUserWithRoleVO.class); |
| | | vo.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(vo.getPhoneNumber())); |
| | | vo.setRoles(roles); |
| | | |
| | | return vo; |
| | |
| | | if (StringUtils.isBlank(phoneNumber)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return lambdaQuery().like(XpOperationsUser::getPhoneNumber, phoneNumber).list(); |
| | | List<XpOperationsUser> list = lambdaQuery() |
| | | .in(XpOperationsUser::getPhoneNumber, SensitiveDataCryptoUtil.queryValues(phoneNumber)) |
| | | .list(); |
| | | decryptPhones(list); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<XpOperationsUserWithRoleVO> pageListByIds(OptionalUsersPageListQuery q) { |
| | | PageInfo<XpOperationsUserWithRoleVO> pageInfo = new PageInfo<>(q.getPageNum(), q.getPageSize()); |
| | | List<XpOperationsUserWithRoleVO> list = baseMapper.pageListByIds(pageInfo, q); |
| | | decryptWithRolePhones(list); |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public boolean save(XpOperationsUser entity) { |
| | | encryptPhone(entity); |
| | | try { |
| | | return super.save(entity); |
| | | } finally { |
| | | decryptPhone(entity); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateById(XpOperationsUser entity) { |
| | | encryptPhone(entity); |
| | | try { |
| | | return super.updateById(entity); |
| | | } finally { |
| | | decryptPhone(entity); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<XpOperationsUser> list() { |
| | | List<XpOperationsUser> list = super.list(); |
| | | decryptPhones(list); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<XpOperationsUser> list(Wrapper<XpOperationsUser> queryWrapper) { |
| | | List<XpOperationsUser> list = super.list(queryWrapper); |
| | | decryptPhones(list); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<XpOperationsUser> listByIds(Collection<? extends Serializable> idList) { |
| | | List<XpOperationsUser> list = super.listByIds(idList); |
| | | decryptPhones(list); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public XpOperationsUser getOne(Wrapper<XpOperationsUser> queryWrapper) { |
| | | XpOperationsUser user = super.getOne(queryWrapper); |
| | | decryptPhone(user); |
| | | return user; |
| | | } |
| | | |
| | | private void encryptPhone(XpOperationsUser user) { |
| | | if (user != null) { |
| | | user.setPhoneNumber(SensitiveDataCryptoUtil.encrypt(user.getPhoneNumber())); |
| | | } |
| | | } |
| | | |
| | | private void decryptPhone(XpOperationsUser user) { |
| | | if (user != null) { |
| | | user.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(user.getPhoneNumber())); |
| | | } |
| | | } |
| | | |
| | | private void decryptPhones(Collection<XpOperationsUser> users) { |
| | | if (users != null) { |
| | | users.forEach(this::decryptPhone); |
| | | } |
| | | } |
| | | |
| | | private void decryptVoPhones(Collection<XpOperationsUserVO> users) { |
| | | if (users != null) { |
| | | users.forEach(user -> user.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(user.getPhoneNumber()))); |
| | | } |
| | | } |
| | | |
| | | private void decryptWithRolePhones(Collection<XpOperationsUserWithRoleVO> users) { |
| | | if (users != null) { |
| | | users.forEach(user -> user.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(user.getPhoneNumber()))); |
| | | } |
| | | } |
| | | } |