liujie
2025-12-03 a96bf618330cf23208e77cf3107b335891eb8237
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCrmBranchServiceImpl.java
@@ -93,21 +93,37 @@
            return R.fail(dto.getPhone()+"-账号已存在");
        }
        List<TCrmBranchArea> branchAreas = dto.getBranchAreas();
        // 判断是否已存在这些区域
        if(!CollectionUtils.isEmpty(branchAreas)){
            List<String> branchAreaCityCodes = branchAreas.stream().map(TCrmBranchArea::getCityCode).collect(Collectors.toList());
        if(dto.getPersonType() != 1 && CollectionUtils.isEmpty(branchAreas)){
            return R.fail("请选择管辖区域");
        }
        List<TCrmBranchArea> responsibleBranchAreas = dto.getResponsibleBranchAreas();
        if(dto.getPersonType() != 3 && CollectionUtils.isEmpty(responsibleBranchAreas)){
            return R.fail("请选择负责区域");
        }
        if(dto.getPersonType() != 3){
            // 判断是否已存在这些区域
            List<String> branchAreaCityCodes = responsibleBranchAreas.stream().map(TCrmBranchArea::getCityCode).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(branchAreaCityCodes)){
                long count = crmBranchAreaService.count(Wrappers.lambdaQuery(TCrmBranchArea.class).in(TCrmBranchArea::getCityCode, branchAreaCityCodes));
                long count = crmBranchAreaService.count(Wrappers.lambdaQuery(TCrmBranchArea.class)
                        .in(TCrmBranchArea::getCityCode, branchAreaCityCodes)
                        .eq(TCrmBranchArea::getAreaType,1));
                if(count > 0){
                    return R.fail("区域已存在");
                    return R.fail("负责区域已存在");
                }
            }
        }
        this.save(dto);
        // 添加区域
        branchAreas.forEach(t -> t.setBranchId(dto.getId()));
        for (TCrmBranchArea branchArea : branchAreas) {
            branchArea.setBranchId(dto.getId());
            branchArea.setAreaType(2);
        }
        for (TCrmBranchArea responsibleBranchArea : responsibleBranchAreas) {
            responsibleBranchArea.setBranchId(dto.getId());
            responsibleBranchArea.setAreaType(1);
        }
        branchAreas.addAll(responsibleBranchAreas);
        crmBranchAreaService.saveBatch(branchAreas);
        // 添加职位薪资
        List<TCrmBranchSalary> branchSalaries = dto.getBranchSalaries();
@@ -152,20 +168,40 @@
        }
        SysUser user = sysUserService.selectUserById(dto.getUserId());
        List<TCrmBranchArea> branchAreas = dto.getBranchAreas();
        // 判断是否已存在这些区域
        if(!CollectionUtils.isEmpty(branchAreas)){
            List<String> branchAreaCityCodes = branchAreas.stream().map(TCrmBranchArea::getCityCode).collect(Collectors.toList());
            long count = crmBranchAreaService.count(Wrappers.lambdaQuery(TCrmBranchArea.class).in(TCrmBranchArea::getCityCode, branchAreaCityCodes)
                    .ne(TCrmBranchArea::getBranchId, dto.getId()));
            if(count > 0){
                return R.fail("区域存在重复");
        if(dto.getPersonType() != 1 && CollectionUtils.isEmpty(branchAreas)){
            return R.fail("请选择管辖区域");
        }
        List<TCrmBranchArea> responsibleBranchAreas = dto.getResponsibleBranchAreas();
        if(dto.getPersonType() != 3 && CollectionUtils.isEmpty(responsibleBranchAreas)){
            return R.fail("请选择负责区域");
        }
        if(dto.getPersonType() != 3){
            // 判断是否已存在这些区域
            List<String> branchAreaCityCodes = responsibleBranchAreas.stream().map(TCrmBranchArea::getCityCode).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(branchAreaCityCodes)){
                long count = crmBranchAreaService.count(Wrappers.lambdaQuery(TCrmBranchArea.class)
                        .in(TCrmBranchArea::getCityCode, branchAreaCityCodes)
                        .eq(TCrmBranchArea::getAreaType,1)
                        .ne(TCrmBranchArea::getBranchId, dto.getId()));
                if(count > 0){
                    return R.fail("负责区域已存在");
                }
            }
        }
        this.updateById(dto);
        // 删除区域
        crmBranchAreaService.remove(Wrappers.lambdaQuery(TCrmBranchArea.class).eq(TCrmBranchArea::getBranchId, dto.getId()));
        // 添加区域
        branchAreas.forEach(t -> t.setBranchId(dto.getId()));
        // 添加区域
        for (TCrmBranchArea branchArea : branchAreas) {
            branchArea.setBranchId(dto.getId());
            branchArea.setAreaType(2);
        }
        for (TCrmBranchArea responsibleBranchArea : responsibleBranchAreas) {
            responsibleBranchArea.setBranchId(dto.getId());
            responsibleBranchArea.setAreaType(1);
        }
        branchAreas.addAll(responsibleBranchAreas);
        crmBranchAreaService.saveBatch(branchAreas);
        // 删除职位薪资
        crmBranchSalaryService.remove(Wrappers.lambdaQuery(TCrmBranchSalary.class).eq(TCrmBranchSalary::getBranchId, dto.getId()));
@@ -219,13 +255,23 @@
                .in(TCrmBranchSalary::getBranchId, branchIds));
        for (TCrmBranchExport crmBranchExport : list) {
            List<TCrmBranchArea> tCrmBranchAreas = crmBranchAreaList.stream().filter(t -> t.getBranchId().equals(crmBranchExport.getId())).collect(Collectors.toList());
            // 管辖区域
            StringBuilder stringBuilder = new StringBuilder();
            // 特殊区域
            StringBuilder stringBuilderResponsible = new StringBuilder();
            for (TCrmBranchArea tCrmBranchArea : tCrmBranchAreas) {
                stringBuilder.append(tCrmBranchArea.getProvinceName()).append("-").append(tCrmBranchArea.getCityName()).append(",");
                if(tCrmBranchArea.getAreaType() == 1){
                    stringBuilderResponsible.append(tCrmBranchArea.getProvinceName()).append("-").append(tCrmBranchArea.getCityName()).append(",");
                }else {
                    stringBuilder.append(tCrmBranchArea.getProvinceName()).append("-").append(tCrmBranchArea.getCityName()).append(",");
                }
            }
            // 去除','
            stringBuilder.deleteCharAt(stringBuilder.length()-1);
            crmBranchExport.setAreaNames(stringBuilder.toString());
            stringBuilderResponsible.deleteCharAt(stringBuilderResponsible.length()-1);
            crmBranchExport.setResponsibleAreaNames(stringBuilderResponsible.toString());
            // 职位薪资
            List<TCrmBranchSalary> crmBranchSalariesList = crmBranchSalaries.stream().filter(t -> t.getBranchId().equals(crmBranchExport.getId())).collect(Collectors.toList());
            crmBranchExport.setCrmBranchSalaries(crmBranchSalariesList);