| | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | 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.account.model.query.XpOperationsUserQuery; |
| | | import com.xiaopeng.account.service.*; |
| | | import com.xiaopeng.account.util.AliOssDownloadUtil; |
| | | import com.xiaopeng.api.dto.account.XpOperationsUserQueryDTO; |
| | | import com.xiaopeng.api.feignClient.maintenance.XpClockInClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetOperationsClient; |
| | |
| | | import com.xiaopeng.api.model.account.XpOperationsUser; |
| | | import com.xiaopeng.api.model.account.XpQualificationAudit; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpFleet; |
| | | import com.xiaopeng.api.query.account.OptionalUsersPageListQuery; |
| | | import com.xiaopeng.api.query.account.OptionalUsersPageListQuery; |
| | | 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; |
| | | import com.xiaopeng.common.security.utils.SecurityUtils; |
| | | import com.xiaopeng.evi.oss.service.AliOssService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.Serializable; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.Serializable; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.time.LocalDateTime; |
| | |
| | | private AliOssDownloadUtil aliOssDownloadUtil; |
| | | @Autowired |
| | | private ISysGroupService sysGroupService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Override |
| | | public XpOperationsUser getById(Serializable userId){ |
| | | XpOperationsUser user = baseMapper.selectById(userId); |
| | | //获取登录用户权限信息 |
| | | user.setPhoneNumber(sysGroupService.getPhoneDesensitization(user.getPhoneNumber())); |
| | | decryptPhone(user); |
| | | return user; |
| | | } |
| | | |
| | |
| | | } |
| | | List<XpOperationsUser> list = lambdaQuery().like(XpOperationsUser::getNickName, nickName).list(); |
| | | for (XpOperationsUser obj : list) { |
| | | obj.setPhoneNumber(sysGroupService.getPhoneDesensitization(obj.getPhoneNumber())); |
| | | decryptPhone(obj); |
| | | obj.setPhoneNumber(DesensitizedUtil.mobilePhone(obj.getPhoneNumber())); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<XpOperationsUserWithRoleVO> selectUserPageByConditions(XpOperationsUserPageQuery query) { |
| | | query.setPhoneNumberQueryValues(SensitiveDataCryptoUtil.queryValues(query.getPhoneNumber())); |
| | | 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); |
| | | for (XpOperationsUserWithRoleVO record : page.getRecords()) { |
| | | record.setPhoneNumber(sysGroupService.getPhoneDesensitization(record.getPhoneNumber())); |
| | | decryptWithRolePhones(page.getRecords()); |
| | | decryptWithRolePhones(page.getRecords()); |
| | | if(!loginUser.getPhoneDesensitizationExempt()){ |
| | | for (XpOperationsUserWithRoleVO record : page.getRecords()) { |
| | | record.setPhoneNumber(DesensitizedUtil.mobilePhone(record.getPhoneNumber())); |
| | | } |
| | | } |
| | | pageInfo.setRecords(page.getRecords()); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public List<XpOperationsUserWithRoleVO> findList(XpOperationsUserQueryDTO 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(sysGroupService.getPhoneDesensitization(vo.getPhoneNumber())); |
| | | vo.setPhoneNumber(SensitiveDataCryptoUtil.decryptIfPossible(vo.getPhoneNumber())); |
| | | vo.setAvatar(aliOssDownloadUtil.getPictureJSONObject(vo.getAvatar())); |
| | | // 2. 查询关联的车队ID列表(一个运维人员只能关联一个车队) |
| | | R<List<Long>> fleetIdsResult = xpFleetOperationsClient.getFleetIdsByUserId(userId); |
| | |
| | | @Transactional |
| | | @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public void saveCertificate(XpOperationsUserDTO dto) { |
| | | XpOperationsUser xpOperationsUser = BeanUtil.copyProperties(dto, XpOperationsUser.class); |
| | | updateById(xpOperationsUser); |
| | | // XpOperationsUser xpOperationsUser = BeanUtil.copyProperties(dto, XpOperationsUser.class); |
| | | // updateById(xpOperationsUser); |
| | | //保存审核记录 |
| | | XpQualificationAudit xpQualificationAudit = BeanUtil.copyProperties(dto, XpQualificationAudit.class, "id"); |
| | | xpQualificationAudit.setAuditStatus(1); |
| | |
| | | |
| | | @Override |
| | | public PageInfo<XpOperationsUserVO> pageList(XpOperationsUserQuery query) { |
| | | 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) { |
| | | xpOperationsUserVO.setPhoneNumber(sysGroupService.getPhoneDesensitization(xpOperationsUserVO.getPhoneNumber())); |
| | | if(StringUtils.isNotEmpty(xpOperationsUserVO.getPhoneNumber())){ |
| | | xpOperationsUserVO.setPhoneNumber(DesensitizedUtil.mobilePhone(xpOperationsUserVO.getPhoneNumber())); |
| | | } |
| | | |
| | | String avatar = xpOperationsUserVO.getAvatar(); |
| | | // 处理空的情况 |
| | | if (avatar == null) { |
| | |
| | | |
| | | @Override |
| | | public R<String> addOperationsUser(XpOperationsUserAddDTO dto) { |
| | | long userCount = this.count(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .eq(XpOperationsUser::getPhoneNumber, dto.getPhoneNumber())); |
| | | long userCount = StringUtils.isBlank(dto.getPhoneNumber()) ? 0 : this.count(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .eq(XpOperationsUser::getPhoneNumber, SensitiveDataCryptoUtil.encrypt(dto.getPhoneNumber()))); |
| | | if (StringUtils.isNotBlank(dto.getPhoneNumber()) && userCount>0) { |
| | | throw new ServiceException("登录账号重复", I18nKeyConstant.ACCOUNT_DUPLICATE); |
| | | } |
| | |
| | | } |
| | | // 密码加密 |
| | | dto.setPassword(SecurityUtils.encryptPassword(dto.getPassword())); |
| | | dto.setPhoneNumber(SensitiveDataCryptoUtil.encrypt(dto.getPhoneNumber())); |
| | | // 保存 |
| | | this.save(dto); |
| | | // 存储角色 |
| | |
| | | |
| | | @Override |
| | | public R<String> editOperationsUser(XpOperationsUserAddDTO dto) { |
| | | XpOperationsUser operationsUser = this.getOne(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .eq(XpOperationsUser::getPhoneNumber, dto.getPhoneNumber()) |
| | | XpOperationsUser operationsUser = StringUtils.isBlank(dto.getPhoneNumber()) ? null : this.getOne(Wrappers.lambdaQuery(XpOperationsUser.class) |
| | | .eq(XpOperationsUser::getPhoneNumber, SensitiveDataCryptoUtil.encrypt(dto.getPhoneNumber())) |
| | | .last("LIMIT 1")); |
| | | |
| | | if (StringUtils.isNotBlank(dto.getPhoneNumber()) && (Objects.nonNull(operationsUser) && !dto.getId().equals(operationsUser.getId()) )) { |
| | |
| | | if (dto.getPassword() != null && !dto.getPassword().isEmpty()) { |
| | | dto.setPassword(null); |
| | | } |
| | | dto.setPhoneNumber(SensitiveDataCryptoUtil.encrypt(dto.getPhoneNumber())); |
| | | this.updateById(dto); |
| | | |
| | | //删除旧的角色数据,添加新的角色 |
| | |
| | | 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()))); |
| | | } |
| | | } |
| | | } |