| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | this.crmPositionService = crmPositionService; |
| | | this.crmSalespersonService = crmSalespersonService; |
| | | this.crmBranchLiftService = crmBranchLiftService; |
| | | this.regionService = regionService; |
| | | this.tokenService = tokenService; |
| | | } |
| | | |
| | |
| | | /** |
| | | * 获取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); |
| | |
| | | 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)); |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | |