puzhibing
4 天以前 a0e03b646f2c444b0f09687d24e9995112b99017
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppUserWhitelistServiceImpl.java
@@ -21,6 +21,7 @@
import com.ruoyi.account.api.vo.AppUserWhitelistImportErrorVO;
import com.ruoyi.account.api.vo.AppUserWhitelistImportResultVO;
import com.ruoyi.account.mapper.TAppUserWhitelistMapper;
import com.ruoyi.account.service.PartnerAppUserAccessService;
import com.ruoyi.account.service.TAppUserService;
import com.ruoyi.account.service.TAppUserWhitelistService;
import com.ruoyi.account.service.TAppUserWhitelistSiteService;
@@ -140,6 +141,9 @@
    @Resource
    private TCompanyAllocateRecordService companyAllocateRecordService;
    @Resource
    private PartnerAppUserAccessService partnerAppUserAccessService;
    @Override
    public Page<TAppUserWhitelist> pageList(AppUserWhitelistQueryDTO queryDTO) {
        AppUserWhitelistQueryDTO safeQuery = queryDTO == null ? new AppUserWhitelistQueryDTO() : queryDTO;
@@ -156,6 +160,8 @@
     */
    private LambdaQueryChainWrapper<TAppUserWhitelist> buildListQuery(AppUserWhitelistQueryDTO queryDTO) {
        AppUserWhitelistQueryDTO safeQuery = queryDTO == null ? new AppUserWhitelistQueryDTO() : queryDTO;
        // 公司账号强制按所属公司过滤,覆盖前端传入的公司筛选
        safeQuery.setCompanyId(partnerAppUserAccessService.resolveCompanyFilter(safeQuery.getCompanyId()));
        Integer currentPartnerId = getCurrentPartnerId();
        String username = getUsername();
        LambdaQueryChainWrapper<TAppUserWhitelist> query = this.lambdaQuery()
@@ -229,6 +235,8 @@
            throw new ServiceException("白名单用户不存在或已删除");
        }
        assertPartnerVisible(existing);
        // 公司账号越权校验:只能操作本公司数据
        partnerAppUserAccessService.assertCompanyVisible(existing.getCompanyId());
        if (Objects.equals(existing.getStatus(), statusDTO.getStatus())) {
            // 状态未变化视为幂等成功,避免无意义的更新人与更新时间变更
            return true;
@@ -254,6 +262,8 @@
            throw new ServiceException("白名单用户不存在");
        }
        assertPartnerVisible(whitelist);
        // 公司账号越权校验:只能查看本公司数据
        partnerAppUserAccessService.assertCompanyVisible(whitelist.getCompanyId());
        fillDisplay(Collections.singletonList(whitelist));
        return whitelist;
    }
@@ -285,6 +295,8 @@
                continue;
            }
            assertPartnerVisible(whitelist);
            // 公司账号越权校验:只能删除本公司数据
            partnerAppUserAccessService.assertCompanyVisible(whitelist.getCompanyId());
            this.removeById(whitelistId);
            whitelistSiteService.remove(Wrappers.lambdaQuery(TAppUserWhitelistSite.class)
                    .eq(TAppUserWhitelistSite::getWhitelistId, whitelistId));
@@ -311,6 +323,8 @@
        }
        for (TAppUserWhitelist record : records) {
            assertPartnerVisible(record);
            // 公司账号越权校验:只能解绑本公司数据
            partnerAppUserAccessService.assertCompanyVisible(record.getCompanyId());
        }
        List<Long> boundIds = records.stream()
                .filter(record -> record.getFleetId() != null)
@@ -523,6 +537,8 @@
    @Override
    public AppUserWhitelistAllocateVO getAllocateOverview(Integer companyId) {
        // 公司账号只能查看本公司额度概览,覆盖前端传入的公司
        companyId = partnerAppUserAccessService.resolveCompanyFilter(companyId);
        if (companyId == null) {
            throw new ServiceException("请选择公司");
        }
@@ -536,6 +552,8 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AppUserWhitelistAllocateVO allocateQuota(AppUserWhitelistAllocateDTO allocateDTO) {
        // 公司账号只能给本公司分配额度,覆盖前端传入的公司
        allocateDTO.setCompanyId(partnerAppUserAccessService.resolveCompanyFilter(allocateDTO.getCompanyId()));
        Map<Long, BigDecimal> amounts = validateAllocateRequest(allocateDTO);
        Integer companyId = allocateDTO.getCompanyId();
        // 公司必须存在、启用且为分配模式(共享模式不支持额度分配)
@@ -682,6 +700,13 @@
        if (Objects.equals(scopeType, SCOPE_PARTNER) && saveDTO.getPartnerId() == null) {
            throw new ServiceException("请选择加盟商");
        }
        // 所属公司与所属车队必填:白名单用户归属企业,充电完全按企业优惠结算
        if (saveDTO.getCompanyId() == null) {
            throw new ServiceException("请选择所属公司");
        }
        if (saveDTO.getFleetId() == null) {
            throw new ServiceException("请选择所属车队");
        }
        validatePartnerDataScope(saveDTO);
        TAppUserWhitelist exists = getByPhone(saveDTO.getPhone());
        if (saveDTO.getId() == null && exists != null) {
@@ -766,6 +791,8 @@
            throw new ServiceException("白名单用户不存在");
        }
        assertPartnerVisible(existing);
        // 公司账号越权校验:只能编辑本公司数据
        partnerAppUserAccessService.assertCompanyVisible(existing.getCompanyId());
        // 同白名单并发编辑串行化:额度差额计算、公司余额扣减/退还必须在临界区内,防止重复扣减或重复退还
        RLock lock = redissonClient.getLock(QUOTA_LOCK_PREFIX + saveDTO.getId());
        boolean locked = tryQuotaLock(lock, "该白名单额度正在处理中,请稍后重试");
@@ -1133,6 +1160,8 @@
    /** 校验并回填所属公司与车队:车队必须归属所选公司;未选公司时按车队自动带出公司 */
    private Integer resolveRelationCompanyId(AppUserWhitelistSaveDTO saveDTO) {
        // 公司账号新增/编辑白名单用户时强制归属本公司,覆盖前端传入的公司
        saveDTO.setCompanyId(partnerAppUserAccessService.resolveCompanyFilter(saveDTO.getCompanyId()));
        Integer companyId = saveDTO.getCompanyId();
        if (companyId != null && loadCompany(companyId) == null) {
            throw new ServiceException("所属公司不存在或已删除");