无关风月
2025-04-11 64bbbd0b310f645f29fbe3b142e16ef6abb87594
cloud-server-activity/src/main/java/com/dsh/activity/controller/HuiminAgreementController.java
@@ -34,8 +34,7 @@
    /**
     * 根据当前用户类型查询惠民卡协议
     * @param objectType
     * @param operatorId
     * @param query
     * @return
     */
    @ResponseBody
@@ -56,7 +55,7 @@
            //查询协议配置
            List<THuiminAgreementSetting> tHuiminAgreementSettingList = huiminAgreementSettingService.list(new LambdaQueryWrapper<THuiminAgreementSetting>()
                    .eq(THuiminAgreementSetting::getAgreementId, huiminAgreement.getId()));
            huiminAgreement.setTHuiminAgreementSettingList(tHuiminAgreementSettingList);
            huiminAgreement.setSettingList(tHuiminAgreementSettingList);
        }
        return huiminAgreement;
    }
@@ -68,40 +67,42 @@
    @Transactional(rollbackFor = Exception.class)
    public void insert(@RequestBody THuiminAgreement tHuiminAgreement){
        Integer operatorId = tHuiminAgreement.getOperatorId();
        if (tHuiminAgreement.getObjectType().equals(1)) {
            tHuiminAgreement.setOperatorId(null);
        }
        huiminAgreementService.saveOrUpdate(tHuiminAgreement);
        List<THuiminAgreementSetting> tHuiminAgreementSettingList = tHuiminAgreement.getTHuiminAgreementSettingList();
        if (CollUtil.isNotEmpty(tHuiminAgreementSettingList)) {
            if (tHuiminAgreement.getObjectType().equals(2) || tHuiminAgreement.getObjectType().equals(1) && Objects.isNull(operatorId)) {
                //删除之前的协议配置
                huiminAgreementSettingService.remove(new LambdaQueryWrapper<THuiminAgreementSetting>().eq(THuiminAgreementSetting::getAgreementId, tHuiminAgreement.getId()));
                //保存协议配置
                tHuiminAgreementSettingList.forEach(t -> {
                    t.setAgreementId(tHuiminAgreement.getId());
                });
                huiminAgreementSettingService.saveBatch(tHuiminAgreementSettingList);
            } else {
                THuiminAgreement agreement = huiminAgreementService.lambdaQuery()
                        .eq(THuiminAgreement::getOperatorId, operatorId)
                        .last("LIMIT 1").one();
                if (Objects.isNull(agreement)) {
                    agreement = new THuiminAgreement();
                    agreement.setOperatorId(operatorId);
                    huiminAgreementService.save(agreement);
                }
                //删除之前的协议配置
                huiminAgreementSettingService.remove(new LambdaQueryWrapper<THuiminAgreementSetting>()
                        .eq(THuiminAgreementSetting::getAgreementId, agreement.getId()));
                //保存协议配置
                THuiminAgreement finalAgreement = agreement;
                tHuiminAgreementSettingList.forEach(t -> {
                    t.setAgreementId(finalAgreement.getId());
                });
                huiminAgreementSettingService.saveBatch(tHuiminAgreementSettingList);
        //如果是平台账号,需要设置operatorId为null
        List<THuiminAgreementSetting> tHuiminAgreementSettingList = tHuiminAgreement.getSettingList();
        //如果是运营商账号或平台账号默认配置
        if (tHuiminAgreement.getObjectType().equals(2) || tHuiminAgreement.getObjectType().equals(1) && Objects.isNull(operatorId)) {
            if (tHuiminAgreement.getObjectType().equals(1)) {
                tHuiminAgreement.setOperatorId(null);
            }
            huiminAgreementService.saveOrUpdate(tHuiminAgreement);
            //删除之前的协议配置
            huiminAgreementSettingService.remove(new LambdaQueryWrapper<THuiminAgreementSetting>().eq(THuiminAgreementSetting::getAgreementId, tHuiminAgreement.getId()));
            //保存协议配置
            tHuiminAgreementSettingList.forEach(t -> {
                t.setAgreementId(tHuiminAgreement.getId());
            });
        } else {
            //平台配置运营商的协议配置
            THuiminAgreement agreement = huiminAgreementService.lambdaQuery()
                    .eq(THuiminAgreement::getOperatorId, operatorId)
                    .last("LIMIT 1").one();
            if (Objects.isNull(agreement)) {
                agreement = new THuiminAgreement();
                agreement.setOperatorId(operatorId);
            }
            agreement.setStoreNoHuiminCardIntro(tHuiminAgreement.getStoreNoHuiminCardIntro());
            huiminAgreementService.saveOrUpdate(agreement);
            //删除之前的协议配置
            huiminAgreementSettingService.remove(new LambdaQueryWrapper<THuiminAgreementSetting>()
                    .eq(THuiminAgreementSetting::getAgreementId, agreement.getId()));
            //保存协议配置
            THuiminAgreement finalAgreement = agreement;
            tHuiminAgreementSettingList.forEach(t -> {
                t.setAgreementId(finalAgreement.getId());
            });
        }
        if (CollUtil.isNotEmpty(tHuiminAgreementSettingList)) {
            huiminAgreementSettingService.saveBatch(tHuiminAgreementSettingList);
        }
    }
}