From d88a0a8d9d8cd11cea0f7c7df17fcaa01da85510 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 09 十二月 2025 18:35:20 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/haizhentong

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java |  136 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 127 insertions(+), 9 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java
index 74ebc20..2e1f149 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java
+++ b/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;
     }
 
@@ -90,7 +91,9 @@
     @PostMapping(value = "/pageList")
     public R<PageInfo<TCrmBranchVO>> pageList(@RequestBody TCrmBranchQuery query) {
         Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
+        Long userId = tokenService.getLoginUser().getUserId();
         query.setRoleType(roleType);
+        query.setUserId(userId);
         return R.ok(crmBranchService.pageList(query));
     }
 
@@ -115,11 +118,33 @@
     /**
      * 获取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, personType)
+                .eq(TCrmBranch::getStatus, 1)
+                .orderByDesc(TCrmBranch::getCreateTime));
+        return R.ok(crmBranches);
+    }
+
+    /**
+     * 获取crm分公司管理管理列表
+     */
+    @ApiOperation(value = "获取crm分公司地区经理,城市经理管理列表")
+    @GetMapping(value = "/listCity")
+    public R<List<TCrmBranch>> listCity() {
+        Long userId = tokenService.getLoginUser().getUserId();
+        TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
+                .eq(TCrmBranch::getUserId, userId)
                 .eq(TCrmBranch::getPersonType, 1)
+                .eq(TCrmBranch::getStatus, 1)
+                .last("LIMIT 1"));
+        if(Objects.isNull(crmBranch)){
+            return R.ok(new ArrayList<>());
+        }
+        List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
+                .eq(TCrmBranch::getProvinceBranchId, crmBranch.getId())
                 .eq(TCrmBranch::getStatus, 1)
                 .orderByDesc(TCrmBranch::getCreateTime));
         return R.ok(crmBranches);
@@ -188,9 +213,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));
@@ -199,6 +231,48 @@
         }
         crmBranchVO.setCrmBranchSalaries(crmBranchSalaries);
         return R.ok(crmBranchVO);
+    }
+
+    /**
+     * 查看crm分公司管理详情
+     */
+    @ApiOperation(value = "查看crm分公司解绑详情")
+    @GetMapping(value = "/getDetailUnbindById")
+    public R<TCrmBranchLiftVO> getDetailUnbindById(@RequestParam String id) {
+
+        TCrmBranchLift crmBranchLift = crmBranchLiftService.getById(id);
+
+        if(Objects.isNull(crmBranchLift)){
+            return R.fail("未找到该解绑信息");
+        }
+
+        TCrmBranchLiftVO crmBranchLiftVO = new TCrmBranchLiftVO();
+        BeanUtils.copyProperties(crmBranchLift, crmBranchLiftVO);
+
+        TCrmBranch crmBranch = crmBranchService.getById(crmBranchLift.getBranchId());
+        TCrmBranchVO crmBranchVO = new TCrmBranchVO();
+        BeanUtils.copyProperties(crmBranch, crmBranchVO);
+        // 查询负责区域
+        List<TCrmBranchArea> crmBranchAreas = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class)
+                .eq(TCrmBranchArea::getAreaType, 1)
+                .eq(TCrmBranchArea::getBranchId, crmBranchLift.getBranchId()));
+        crmBranchVO.setCrmBranchAreas(crmBranchAreas);
+        // 查询管辖区域
+        List<TCrmBranchArea> jurisdictionBranchAreas = crmBranchAreaService.list(Wrappers.lambdaQuery(TCrmBranchArea.class)
+                .eq(TCrmBranchArea::getAreaType, 2)
+                .eq(TCrmBranchArea::getBranchId, crmBranchLift.getBranchId()));
+        crmBranchVO.setJurisdictionBranchAreas(jurisdictionBranchAreas);
+        // 职位薪资
+        List<TCrmPosition> crmPositions = crmPositionService.list();
+        List<TCrmBranchSalary> crmBranchSalaries = crmBranchSalaryService.list(Wrappers.lambdaQuery(TCrmBranchSalary.class).eq(TCrmBranchSalary::getBranchId, id));
+        for (TCrmBranchSalary crmBranchSalary : crmBranchSalaries) {
+            crmPositions.stream().filter(crmPosition -> Objects.equals(crmPosition.getId(), crmBranchSalary.getPositionId())).findFirst().ifPresent(crmPosition -> crmBranchSalary.setPositionName(crmPosition.getPositionName()));
+        }
+        crmBranchVO.setCrmBranchSalaries(crmBranchSalaries);
+
+        crmBranchLiftVO.setCrmBranchVO(crmBranchVO);
+
+        return R.ok(crmBranchLiftVO);
     }
 
     /**
@@ -386,7 +460,7 @@
         }
 
         TCrmBranchLift crmBranchLift = new TCrmBranchLift();
-        crmBranchLift.setBranchId(crmBranch.getId());
+        crmBranchLift.setBranchId(dto.getBranchId());
         crmBranchLift.setChargePhone(dto.getChargePhone());
         crmBranchLift.setLiftReason(dto.getLiftReason());
         crmBranchLiftService.save(crmBranchLift);
@@ -438,5 +512,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);
+    }
+
 }
 

--
Gitblit v1.7.1