xuhy
2025-12-08 15390be24bf324886bc82eb289268070e5221310
bug修改
3个文件已修改
107 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCrmBranchServiceImpl.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/vo/TCrmBranchVO.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java
@@ -44,8 +44,7 @@
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -69,9 +68,10 @@
    private final TCrmPositionService crmPositionService;
    private final TCrmSalespersonService crmSalespersonService;
    private final TCrmBranchLiftService crmBranchLiftService;
    private final TRegionService regionService;
    private final TokenService tokenService;
    @Autowired
    public TCrmBranchController(TCrmBranchService crmBranchService, TCrmBranchAreaService crmBranchAreaService, TCrmBranchSalaryService crmBranchSalaryService, ISysUserService sysUserService, TCrmChangePointsService crmChangePointsService, TCrmPositionService crmPositionService, TCrmSalespersonService crmSalespersonService, TCrmBranchLiftService crmBranchLiftService, TokenService tokenService) {
    public TCrmBranchController(TCrmBranchService crmBranchService, TCrmBranchAreaService crmBranchAreaService, TCrmBranchSalaryService crmBranchSalaryService, ISysUserService sysUserService, TCrmChangePointsService crmChangePointsService, TCrmPositionService crmPositionService, TCrmSalespersonService crmSalespersonService, TCrmBranchLiftService crmBranchLiftService, TRegionService regionService, TokenService tokenService) {
        this.crmBranchService = crmBranchService;
        this.crmBranchAreaService = crmBranchAreaService;
        this.crmBranchSalaryService = crmBranchSalaryService;
@@ -80,6 +80,7 @@
        this.crmPositionService = crmPositionService;
        this.crmSalespersonService = crmSalespersonService;
        this.crmBranchLiftService = crmBranchLiftService;
        this.regionService = regionService;
        this.tokenService = tokenService;
    }
@@ -115,11 +116,11 @@
    /**
     * 获取crm分公司管理管理列表
     */
    @ApiOperation(value = "获取crm分公司省公司管理列表")
    @PostMapping(value = "/listProvince")
    public R<List<TCrmBranch>> listProvince() {
    @ApiOperation(value = "获取crm分公司省公司,地区经理管理列表")
    @GetMapping(value = "/listProvince")
    public R<List<TCrmBranch>> listProvince(@RequestParam Integer personType) {
        List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                .eq(TCrmBranch::getPersonType, 1)
                .eq(TCrmBranch::getPersonType, personType)
                .eq(TCrmBranch::getStatus, 1)
                .orderByDesc(TCrmBranch::getCreateTime));
        return R.ok(crmBranches);
@@ -188,9 +189,16 @@
        TCrmBranch crmBranch = crmBranchService.getById(id);
        TCrmBranchVO crmBranchVO = new TCrmBranchVO();
        BeanUtils.copyProperties(crmBranch, crmBranchVO);
        // 查询区域
        List<TCrmBranchArea> crmBranchAreas = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class).eq(TCrmBranchArea::getBranchId, id));
        // 查询负责区域
        List<TCrmBranchArea> crmBranchAreas = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class)
                .eq(TCrmBranchArea::getAreaType, 1)
                .eq(TCrmBranchArea::getBranchId, id));
        crmBranchVO.setCrmBranchAreas(crmBranchAreas);
        // 查询管辖区域
        List<TCrmBranchArea> jurisdictionBranchAreas = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class)
                .eq(TCrmBranchArea::getAreaType, 2)
                .eq(TCrmBranchArea::getBranchId, id));
        crmBranchVO.setJurisdictionBranchAreas(jurisdictionBranchAreas);
        // 职位薪资
        List<TCrmPosition> crmPositions = crmPositionService.list();
        List<TCrmBranchSalary> crmBranchSalaries = crmBranchSalaryService.list(Wrappers.lambdaQuery(TCrmBranchSalary.class).eq(TCrmBranchSalary::getBranchId, id));
@@ -438,5 +446,49 @@
        return R.ok();
    }
    /**
     * 通过分公司上级id查询负责区域
     */
    @ApiOperation(value = "crm分公司管理信息-通过分公司上级id查询负责区域",notes = "branchId:分公司id")
    @GetMapping(value = "/getAreaByParentId")
    public R<Set<TRegion>> getAreaByParentId(@RequestParam String branchId) {
        List<TCrmBranchArea> list = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class)
                .eq(TCrmBranchArea::getBranchId, branchId)
                .eq(TCrmBranchArea::getAreaType, 1));
        if(CollectionUtils.isEmpty(list)){
            return R.fail("未查询到负责区域");
        }
        List<TRegion> regionList = regionService.list();
        // 匹配到省份
        Set<TRegion> regions = new HashSet<>();
        for (TCrmBranchArea tCrmBranchArea : list) {
            List<TRegion> parent = regionList.stream().filter(a -> a.getCode().equals(tCrmBranchArea.getProvinceCode())).collect(Collectors.toList());
            regions.add(parent.get(0));
        }
        // 匹配市区和区县
        for (TRegion region : regions) {
            List<String> cityCodes = list.stream().filter(a -> a.getProvinceCode().equals(region.getCode()))
                    .map(TCrmBranchArea::getCityCode)
                    .collect(Collectors.toList());
            List<TRegion> tRegionList = regionList.stream().filter(a -> a.getParentId().equals(region.getId())
                    && cityCodes.contains(a.getCode())).collect(Collectors.toList());
            for (TRegion child : tRegionList) {
                List<TRegion> children1 = regionList.stream().filter(a -> a.getParentId().equals(child.getId())).collect(Collectors.toList());
                child.setChildren(children1);
            }
            region.setChildren(tRegionList);
        }
        return R.ok(regions);
    }
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCrmBranchServiceImpl.java
@@ -157,17 +157,19 @@
        }
        this.save(dto);
        // 添加区域
        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);
        if(dto.getPersonType() != 1){
            // 添加区域
            for (TCrmBranchArea branchArea : branchAreas) {
                branchArea.setBranchId(dto.getId());
                branchArea.setAreaType(2);
            }
            responsibleBranchAreas.addAll(branchAreas);
        }
        crmBranchAreaService.saveBatch(responsibleBranchAreas);
        // 添加职位薪资
        List<TCrmBranchSalary> branchSalaries = dto.getBranchSalaries();
        branchSalaries.forEach(t -> t.setBranchId(dto.getId()));
@@ -235,17 +237,19 @@
        // 删除区域
        crmBranchAreaService.remove(Wrappers.lambdaQuery(TCrmBranchArea.class).eq(TCrmBranchArea::getBranchId, 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);
        if(dto.getPersonType() != 1){
            // 添加区域
            for (TCrmBranchArea branchArea : branchAreas) {
                branchArea.setBranchId(dto.getId());
                branchArea.setAreaType(2);
            }
            responsibleBranchAreas.addAll(branchAreas);
        }
        crmBranchAreaService.saveBatch(responsibleBranchAreas);
        // 删除职位薪资
        crmBranchSalaryService.remove(Wrappers.lambdaQuery(TCrmBranchSalary.class).eq(TCrmBranchSalary::getBranchId, dto.getId()));
        // 添加职位薪资
ruoyi-system/src/main/java/com/ruoyi/system/vo/TCrmBranchVO.java
@@ -16,9 +16,12 @@
    @ApiModelProperty(value = "省份")
    private String provinceName;
    @ApiModelProperty(value = "省市列表")
    @ApiModelProperty(value = "负责区域列表")
    private List<TCrmBranchArea> crmBranchAreas;
    @ApiModelProperty(value = "管辖区域列表")
    private List<TCrmBranchArea> jurisdictionBranchAreas;
    @ApiModelProperty(value = "职位薪资")
    private List<TCrmBranchSalary> crmBranchSalaries;