Răsfoiți Sursa

Merge remote-tracking branch 'origin/dev_v1.0.0' into dev_v1.0.0

wangliang 1 an în urmă
părinte
comite
3380fadb2d
16 a modificat fișierele cu 348 adăugiri și 211 ștergeri
  1. 8 21
      sop-api/src/main/java/com/qmth/sop/server/api/TBCrmController.java
  2. 126 0
      sop-business/src/main/java/com/qmth/sop/business/bean/result/ServiceRegionDetailResult.java
  3. 33 9
      sop-business/src/main/java/com/qmth/sop/business/entity/TBCrm.java
  4. 15 1
      sop-business/src/main/java/com/qmth/sop/business/mapper/TBServiceRegionDetailMapper.java
  5. 0 10
      sop-business/src/main/java/com/qmth/sop/business/mapper/TBServiceRegionMapper.java
  6. 10 3
      sop-business/src/main/java/com/qmth/sop/business/service/TBCrmService.java
  7. 11 0
      sop-business/src/main/java/com/qmth/sop/business/service/TBServiceRegionDetailService.java
  8. 0 10
      sop-business/src/main/java/com/qmth/sop/business/service/TBServiceRegionService.java
  9. 0 9
      sop-business/src/main/java/com/qmth/sop/business/service/TBUserArchivesAllocationService.java
  10. 66 69
      sop-business/src/main/java/com/qmth/sop/business/service/impl/TBCrmServiceImpl.java
  11. 16 0
      sop-business/src/main/java/com/qmth/sop/business/service/impl/TBServiceRegionDetailServiceImpl.java
  12. 13 13
      sop-business/src/main/java/com/qmth/sop/business/service/impl/TBServiceRegionServiceImpl.java
  13. 0 36
      sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesAllocationServiceImpl.java
  14. 8 0
      sop-business/src/main/resources/db/log/caozixuan_update_log.sql
  15. 42 0
      sop-business/src/main/resources/mapper/TBServiceRegionDeatilMapper.xml
  16. 0 30
      sop-business/src/main/resources/mapper/TBServiceRegionMapper.xml

+ 8 - 21
sop-api/src/main/java/com/qmth/sop/server/api/TBCrmController.java

@@ -46,14 +46,14 @@ public class TBCrmController {
     @RequestMapping(value = "/query", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "派单信息表查询结果", response = TBCrmResult.class)})
     public Result query(
-            @ApiParam(value = "服务单元", required = false) @RequestParam(required = false) Long serviceId,
-            @ApiParam(value = "大区经理", required = false) @RequestParam(required = false) Long leadId,
-            @ApiParam(value = "派单人", required = false) @RequestParam(required = false) Long crmUserId,
-            @ApiParam(value = "客户类型", required = false) @RequestParam(required = false) ProductTypeEnum type,
-            @ApiParam(value = "客户名称(模糊查询)", required = false) @RequestParam(required = false) String custom,
-            @ApiParam(value = "项目单号(模糊查询) ", required = false) @RequestParam(required = false) String crmNo,
-            @ApiParam(value = "派单时间开始", required = false) @RequestParam(required = false) Long startTime,
-            @ApiParam(value = "派单时间结束", required = false) @RequestParam(required = false) Long endTime,
+            @ApiParam(value = "服务单元") @RequestParam(required = false) Long serviceId,
+            @ApiParam(value = "大区经理") @RequestParam(required = false) Long leadId,
+            @ApiParam(value = "派单人") @RequestParam(required = false) Long crmUserId,
+            @ApiParam(value = "客户类型") @RequestParam(required = false) ProductTypeEnum type,
+            @ApiParam(value = "客户名称(模糊查询)") @RequestParam(required = false) String custom,
+            @ApiParam(value = "项目单号(模糊查询) ") @RequestParam(required = false) String crmNo,
+            @ApiParam(value = "派单时间开始") @RequestParam(required = false) Long startTime,
+            @ApiParam(value = "派单时间结束") @RequestParam(required = false) Long endTime,
             @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
             @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
         IPage<TBCrmResult> resultIPage = tBCrmService.query(new Page<>(pageNumber, pageSize), serviceId, leadId, crmUserId, type, custom, crmNo, startTime, endTime);
@@ -90,20 +90,7 @@ public class TBCrmController {
         return ResultUtil.ok(tBCrmService.getById(id));
     }
 
-    //批量划定服务单元
-
-    @Deprecated
-    @ApiOperation(value = "批量划定服务单元接口")
-    @RequestMapping(value = "/batchZone", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
-    @OperationLog(logType = LogTypeEnum.UPDATE)
-    public Result batchZone(@ApiParam(value = "服务单元id", required = true) @RequestParam(required = true) long serviceId,
-                            @ApiParam(value = "派单信息表id", required = true) @RequestParam(required = true) long[] crmIds) {
-        return ResultUtil.ok(tBCrmService.batchZone(serviceId, crmIds));
-    }
-
     //批量禁用
-
     @ApiOperation(value = "批量禁用接口")
     @RequestMapping(value = "/batchDisable", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})

+ 126 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/ServiceRegionDetailResult.java

@@ -0,0 +1,126 @@
+package com.qmth.sop.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 服务区域规划明细结果
+ * @Author: CaoZixuan
+ * @Date: 2023-11-17
+ */
+public class ServiceRegionDetailResult {
+    @ApiModelProperty(value = "服务区域规划明细id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long serviceRegionDetailId;
+
+    @ApiModelProperty(value = "国家")
+    private String county;
+
+    @ApiModelProperty(value = "省份")
+    private String province;
+
+    @ApiModelProperty(value = "城市")
+    private String city;
+
+    @ApiModelProperty(value = "区县")
+    private String area;
+
+    @ApiModelProperty(value = "地址")
+    private String address;
+
+    @ApiModelProperty(value = "服务区域规划id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long serviceRegionId;
+
+    @ApiModelProperty(value = "大区经理id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long leadId;
+
+    @ApiModelProperty(value = "大区经理名称")
+    private String leadName;
+
+    @ApiModelProperty(value = "大区名称")
+    private String regionName;
+
+
+    public Long getServiceRegionDetailId() {
+        return serviceRegionDetailId;
+    }
+
+    public void setServiceRegionDetailId(Long serviceRegionDetailId) {
+        this.serviceRegionDetailId = serviceRegionDetailId;
+    }
+
+    public String getCounty() {
+        return county;
+    }
+
+    public void setCounty(String county) {
+        this.county = county;
+    }
+
+    public String getProvince() {
+        return province;
+    }
+
+    public void setProvince(String province) {
+        this.province = province;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getArea() {
+        return area;
+    }
+
+    public void setArea(String area) {
+        this.area = area;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public Long getServiceRegionId() {
+        return serviceRegionId;
+    }
+
+    public void setServiceRegionId(Long serviceRegionId) {
+        this.serviceRegionId = serviceRegionId;
+    }
+
+    public Long getLeadId() {
+        return leadId;
+    }
+
+    public void setLeadId(Long leadId) {
+        this.leadId = leadId;
+    }
+
+    public String getLeadName() {
+        return leadName;
+    }
+
+    public void setLeadName(String leadName) {
+        this.leadName = leadName;
+    }
+
+    public String getRegionName() {
+        return regionName;
+    }
+
+    public void setRegionName(String regionName) {
+        this.regionName = regionName;
+    }
+}

+ 33 - 9
sop-business/src/main/java/com/qmth/sop/business/entity/TBCrm.java

@@ -65,7 +65,15 @@ public class TBCrm extends BaseEntity implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long leadId;
 
-    @ApiModelProperty(value = "区域协调人id")
+    @ApiModelProperty(value = "大区经理id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long regionId;
+
+    @ApiModelProperty(value = "服务区域规划id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long regionDetailId;
+
+    @ApiModelProperty(value = "服务区域规划明细id")
     @JsonSerialize(using = ToStringSerializer.class)
     private Long regionCoordinatorId;
 
@@ -165,20 +173,20 @@ public class TBCrm extends BaseEntity implements Serializable {
         this.leadId = leadId;
     }
 
-    public Boolean getSync() {
-        return sync;
+    public Long getRegionId() {
+        return regionId;
     }
 
-    public void setSync(Boolean sync) {
-        this.sync = sync;
+    public void setRegionId(Long regionId) {
+        this.regionId = regionId;
     }
 
-    public Boolean getEnable() {
-        return enable;
+    public Long getRegionDetailId() {
+        return regionDetailId;
     }
 
-    public void setEnable(Boolean enable) {
-        this.enable = enable;
+    public void setRegionDetailId(Long regionDetailId) {
+        this.regionDetailId = regionDetailId;
     }
 
     public Long getRegionCoordinatorId() {
@@ -189,6 +197,22 @@ public class TBCrm extends BaseEntity implements Serializable {
         this.regionCoordinatorId = regionCoordinatorId;
     }
 
+    public Boolean getSync() {
+        return sync;
+    }
+
+    public void setSync(Boolean sync) {
+        this.sync = sync;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
     public CrmStatusEnum getStatus() {
         return status;
     }

+ 15 - 1
sop-business/src/main/java/com/qmth/sop/business/mapper/TBServiceRegionDetailMapper.java

@@ -1,7 +1,11 @@
 package com.qmth.sop.business.mapper;
 
+import com.qmth.sop.business.bean.result.ServiceRegionDetailResult;
 import com.qmth.sop.business.entity.TBServiceRegionDetail;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +17,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface TBServiceRegionDetailMapper extends BaseMapper<TBServiceRegionDetail> {
 
-}
+    /**
+     * 根据服务单元id和派单号查询所对应的服务区域规划明细信息(大区经理,明细id等)
+     *
+     * @param serviceUnitId 服务单元id
+     * @param crmNo         派单号
+     * @return 大区经理id集合
+     */
+    List<ServiceRegionDetailResult> findRegionDetailByServiceUnitIdAndCrmNo(@Param("serviceUnitId") Long serviceUnitId,
+                                                                            @Param("crmNo") String crmNo);
+
+}

+ 0 - 10
sop-business/src/main/java/com/qmth/sop/business/mapper/TBServiceRegionMapper.java

@@ -39,14 +39,4 @@ public interface TBServiceRegionMapper extends BaseMapper<TBServiceRegion> {
                                                      @Param("city") String city,
                                                      @Param("serviceStatus") ServiceStatusEnum serviceStatus,
                                                      @Param("dpr") DataPermissionDto dpr);
-
-    /**
-     * 根据服务单元id和派单号查询大区经理
-     *
-     * @param serviceUnitId 服务单元id
-     * @param crmNo         派单号
-     * @return 大区经理id集合
-     */
-    List<Long> findRegionLeaderByServiceUnitIdAndCrmNo(@Param("serviceUnitId") Long serviceUnitId,
-                                                       @Param("crmNo") String crmNo);
 }

+ 10 - 3
sop-business/src/main/java/com/qmth/sop/business/service/TBCrmService.java

@@ -121,9 +121,6 @@ public interface TBCrmService extends IService<TBCrm> {
      */
     Boolean delete(Long id);
 
-    @Deprecated
-    boolean batchZone(long serviceId, long[] crmIds);
-
     boolean batchDisable(long[] crmIds);
 
     /**
@@ -170,6 +167,16 @@ public interface TBCrmService extends IService<TBCrm> {
      */
     List<TBCrm> findByTBCrmListByServiceUnitIdAndAddress(Long serviceUnitId, String province, String city);
 
+
+    /**
+     * 派单重新划定服务单元
+     *
+     * @param crmNo            派单号
+     * @param oldServiceUnitId 划定前派单的服务单元id
+     * @param newServiceUnitId 划定后派单的服务单元id
+     */
+    void crmReBindServiceUnit(String crmNo, Long oldServiceUnitId, Long newServiceUnitId);
+
     /**
      * 从纷享销客同步派单信息
      */

+ 11 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBServiceRegionDetailService.java

@@ -1,8 +1,10 @@
 package com.qmth.sop.business.service;
 
 import com.qmth.sop.business.bean.dto.AreaDto;
+import com.qmth.sop.business.bean.result.ServiceRegionDetailResult;
 import com.qmth.sop.business.entity.TBServiceRegionDetail;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -22,4 +24,13 @@ public interface TBServiceRegionDetailService extends IService<TBServiceRegionDe
      * @param areaDtoList     区域信息
      */
     void bindServiceRegionAreas(Long serviceRegionId, List<AreaDto> areaDtoList);
+
+    /**
+     * 根据服务单元和派单号查询区域规划明细
+     *
+     * @param serviceUnitId 服务单元id
+     * @param crmNo         派单号
+     * @return 服务区域规划明细
+     */
+    ServiceRegionDetailResult findRegionDetail(Long serviceUnitId, String crmNo);
 }

+ 0 - 10
sop-business/src/main/java/com/qmth/sop/business/service/TBServiceRegionService.java

@@ -49,16 +49,6 @@ public interface TBServiceRegionService extends IService<TBServiceRegion> {
      */
     void removeServiceRegion(List<Long> serviceRegionIdList);
 
-
-    /**
-     * 查询大区经理
-     *
-     * @param serviceUnitId 服务单元id
-     * @param crmNo         crmNo
-     * @return 符合条件的大区经理id
-     */
-    Long findRegionLeader(Long serviceUnitId, String crmNo);
-
     /**
      * 根据服务单元id查询可以被选择的大区经理
      *

+ 0 - 9
sop-business/src/main/java/com/qmth/sop/business/service/TBUserArchivesAllocationService.java

@@ -85,13 +85,4 @@ public interface TBUserArchivesAllocationService extends IService<TBUserArchives
      * @param crmNo crmNo
      */
     void unPublishSop(String crmNo);
-
-    /**
-     * 派单重新划定服务单元
-     *
-     * @param crmNo            派单号
-     * @param oldServiceUnitId 划定前派单的服务单元id
-     * @param newServiceUnitId 划定后派单的服务单元id
-     */
-    void crmReBindServiceUnit(String crmNo, Long oldServiceUnitId, Long newServiceUnitId);
 }

+ 66 - 69
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBCrmServiceImpl.java

@@ -17,7 +17,6 @@ import com.qmth.sop.business.mapper.TBCrmMapper;
 import com.qmth.sop.business.service.*;
 import com.qmth.sop.business.sync.FxxkApiUtils;
 import com.qmth.sop.business.sync.been.fxxk.FxxkCrm;
-import com.qmth.sop.common.base.BaseEntity;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
 import com.qmth.sop.common.util.ResultUtil;
@@ -51,7 +50,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
     @Resource
     private TBUserArchivesService tbUserArchivesService;
     @Resource
-    private TBServiceRegionService tbServiceRegionService;
+    private TBServiceRegionDetailService tbServiceRegionDetailService;
     @Resource
     private SysUserService sysUserService;
     @Resource
@@ -111,29 +110,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
         List<TBCrm> tbCrmList = this.listByIds(crmIdList);
         // 派单调配资源变换
         for (TBCrm dbCrm : tbCrmList) {
-            tbUserArchivesAllocationService.crmReBindServiceUnit(dbCrm.getCrmNo(), dbCrm.getServiceId(), serviceUnitId);
-        }
-
-        // 绑定服务单元
-        tbCrmList = tbCrmList.stream().peek(e -> e.setServiceId(serviceUnitId)).collect(Collectors.toList());
-        this.updateBatchById(tbCrmList);
-
-        // 自动匹配派单对应的大区经理
-        tbCrmList = tbCrmList.stream().peek(e -> {
-            Long regionLeaderId = tbServiceRegionService.findRegionLeader(serviceUnitId, e.getCrmNo());
-            if (Objects.nonNull(regionLeaderId)) {
-                e.setLeadId(regionLeaderId);
-            }
-        }).collect(Collectors.toList());
-        this.updateBatchById(tbCrmList);
-
-        // 解绑区域协调人
-        for (TBCrm tbCrm : tbCrmList) {
-            UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
-            updateWrapper.lambda()
-                    .in(TBCrm::getId, tbCrm.getId())
-                    .set(TBCrm::getRegionCoordinatorId, null);
-            this.update(updateWrapper);
+            this.crmReBindServiceUnit(dbCrm.getCrmNo(), dbCrm.getServiceId(), serviceUnitId);
         }
     }
 
@@ -152,13 +129,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
                 throw ExceptionResultEnum.ERROR.exception("服务单元的当前状态更新为" + ServiceStatusEnum.FINISH.name() + "不允许移除");
             }
         }
-        UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.lambda()
-                .set(TBCrm::getServiceId, null)
-                .set(TBCrm::getLeadId, null)
-                .eq(TBCrm::getId, tbCrm.getId());
-        this.update(updateWrapper);
-        tbUserArchivesAllocationService.crmReBindServiceUnit(tbCrm.getCrmNo(), serviceUnitId, null);
+        this.crmReBindServiceUnit(tbCrm.getCrmNo(), serviceUnitId, null);
     }
 
     @Override
@@ -201,7 +172,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
     /**
      * 新增修改派单信息表
      *
-     * @param tBCrm
+     * @param tBCrm tBCrm
      */
     @Override
     @Transactional
@@ -225,28 +196,14 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
             boolean result = saveOrUpdate(tBCrm);
             Long serviceId = tBCrm.getServiceId();
             if (result) {
-                if (serviceId != null && serviceId > 0) {
-                    // 有服务单元 -> 绑定服务单元和大区经理
-                    Long regionLeaderId = tbServiceRegionService.findRegionLeader(serviceId, tBCrm.getCrmNo());
-                    UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
-                    updateWrapper.lambda().eq(TBCrm::getId, tBCrm.getId()).set(TBCrm::getLeadId, regionLeaderId);
-                    this.update(updateWrapper);
-                } else {
-                    // 有服务单元 -> 解绑服务单元和大区经理
-                    UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
-                    updateWrapper.lambda()
-                            .eq(TBCrm::getId, tBCrm.getId())
-                            .set(TBCrm::getLeadId, null)
-                            .set(TBCrm::getServiceId, null);
-                    this.update(updateWrapper);
-                }
+                this.crmReBindServiceUnit(tBCrm.getCrmNo(), oldServiceUnitId, serviceId);
             }
-            tbUserArchivesAllocationService.crmReBindServiceUnit(tBCrm.getCrmNo(), oldServiceUnitId, serviceId);
+
             return result;
         } catch (Exception e) {
             if (e instanceof DuplicateKeyException) {
                 String errorColumn = e.getCause().toString();
-                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3).replaceAll("'", "");
                 throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
             } else if (e instanceof ApiException) {
                 ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
@@ -255,13 +212,12 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
             }
         }
         return null;
-
     }
 
     /**
      * 删除派单信息表
      *
-     * @param id
+     * @param id id
      */
     @Override
     @Transactional
@@ -269,23 +225,6 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
         return this.removeById(id);
     }
 
-    @Override
-    @Transactional
-    public boolean batchZone(long serviceId, long[] crmIds) {
-        List<Long> crmIdList = Arrays.stream(crmIds).boxed().collect(Collectors.toList());
-        List<TBCrm> tbCrmList = this.listByIds(crmIdList);
-        tbCrmList.forEach(e -> e.setServiceId(serviceId));
-        this.updateBatchById(tbCrmList);
-
-        tbCrmList.forEach(e -> {
-            Long regionLeaderId = tbServiceRegionService.findRegionLeader(serviceId, e.getCrmNo());
-            if (Objects.nonNull(regionLeaderId)) {
-                e.setLeadId(regionLeaderId);
-            }
-        });
-        return this.updateBatchById(tbCrmList);
-    }
-
     @Override
     @Transactional
     public boolean batchDisable(long[] crmIds) {
@@ -417,6 +356,64 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
         return this.baseMapper.findByTBCrmListByServiceUnitIdAndAddress(serviceUnitId, province, city);
     }
 
+    @Transactional
+    @Override
+    public void crmReBindServiceUnit(String crmNo, Long oldServiceUnitId, Long newServiceUnitId) {
+        TBCrm tbCrm = this.findByCrmNo(crmNo);
+        if (CrmStatusEnum.PUBLISH.equals(tbCrm.getStatus())) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("已发布的派单[%s]不能重新划分,请先撤销发布", tbCrm.getCrmNo()));
+        }
+
+        if (oldServiceUnitId != null && oldServiceUnitId > 0) {
+            // 之前派单有划定在服务单元 -> 解绑派单所有资源信息
+            List<TBUserArchivesAllocation> dbAllocationList = tbUserArchivesAllocationService.list(new QueryWrapper<TBUserArchivesAllocation>().lambda()
+                    .eq(TBUserArchivesAllocation::getCrmNo, crmNo)
+                    .eq(TBUserArchivesAllocation::getServiceId, oldServiceUnitId));
+
+            if (CollectionUtils.isNotEmpty(dbAllocationList)) {
+                // 释放工程师资源
+                List<Long> archivesIdList = dbAllocationList.stream().map(TBUserArchivesAllocation::getArchivesId).distinct().collect(Collectors.toList());
+                if (CollectionUtils.isNotEmpty(archivesIdList)) {
+                    UpdateWrapper<TBUserArchives> archivesUpdateWrapper = new UpdateWrapper<>();
+                    archivesUpdateWrapper.lambda()
+                            .in(TBUserArchives::getId, archivesIdList)
+                            .set(TBUserArchives::getStatus, UserArchivesStatusEnum.FREE);
+                    tbUserArchivesService.update(archivesUpdateWrapper);
+                }
+                // 删除之前的派单分配详情
+                tbUserArchivesAllocationService.removeByIds(dbAllocationList.stream().map(TBUserArchivesAllocation::getId).distinct().collect(Collectors.toList()));
+            }
+            UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
+            updateWrapper.lambda()
+                    .eq(TBCrm::getId, tbCrm.getId())
+                    .set(TBCrm::getServiceId, null)
+                    .set(TBCrm::getLeadId, null)
+                    .set(TBCrm::getRegionId, null)
+                    .set(TBCrm::getRegionDetailId, null)
+                    .set(TBCrm::getRegionCoordinatorId, null);
+            this.update(updateWrapper);
+        }
+        if (newServiceUnitId != null && newServiceUnitId > 0) {
+            // 为派单划定的新服务单元绑定大区信息
+            UpdateWrapper<TBCrm> bindServiceWrapper = new UpdateWrapper<>();
+            bindServiceWrapper.lambda()
+                    .eq(TBCrm::getId, tbCrm.getId())
+                    .set(TBCrm::getServiceId, newServiceUnitId);
+            this.update(bindServiceWrapper);
+
+            ServiceRegionDetailResult regionDetail = tbServiceRegionDetailService.findRegionDetail(newServiceUnitId, crmNo);
+            if (Objects.nonNull(regionDetail)) {
+                UpdateWrapper<TBCrm> matchWrapper = new UpdateWrapper<>();
+                matchWrapper.lambda()
+                        .eq(TBCrm::getId, tbCrm.getId())
+                        .set(TBCrm::getLeadId, regionDetail.getLeadId())
+                        .set(TBCrm::getRegionId, regionDetail.getServiceRegionId())
+                        .set(TBCrm::getRegionDetailId, regionDetail.getServiceRegionDetailId());
+                this.update(matchWrapper);
+            }
+        }
+    }
+
     @Transactional
     @Override
     public Map<String, Object> syncCrmFromFxxk(Map<String, Object> map) {

+ 16 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBServiceRegionDetailServiceImpl.java

@@ -3,6 +3,7 @@ package com.qmth.sop.business.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.bean.dto.AreaDto;
+import com.qmth.sop.business.bean.result.ServiceRegionDetailResult;
 import com.qmth.sop.business.entity.TBCrm;
 import com.qmth.sop.business.entity.TBServiceRegion;
 import com.qmth.sop.business.entity.TBServiceRegionDetail;
@@ -11,6 +12,8 @@ import com.qmth.sop.business.service.TBCrmService;
 import com.qmth.sop.business.service.TBServiceRegionDetailService;
 import com.qmth.sop.business.service.TBServiceRegionService;
 import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -65,4 +68,17 @@ public class TBServiceRegionDetailServiceImpl extends ServiceImpl<TBServiceRegio
         }).collect(Collectors.toList());
         this.saveBatch(tbServiceRegionDetailList);
     }
+
+    @Override
+    public ServiceRegionDetailResult findRegionDetail(Long serviceUnitId, String crmNo) {
+        ServiceRegionDetailResult result = null;
+        List<ServiceRegionDetailResult> resultList = this.baseMapper.findRegionDetailByServiceUnitIdAndCrmNo(serviceUnitId, crmNo);
+        if (CollectionUtils.isNotEmpty(resultList)) {
+            if (resultList.size() > 1) {
+                throw ExceptionResultEnum.ERROR.exception(String.format("派单号为[%s]的派单可匹配多个大区详细信息", crmNo));
+            }
+            result = resultList.get(0);
+        }
+        return result;
+    }
 }

+ 13 - 13
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBServiceRegionServiceImpl.java

@@ -125,6 +125,7 @@ public class TBServiceRegionServiceImpl extends ServiceImpl<TBServiceRegionMappe
     @Transactional
     @Override
     public Long editServiceRegion(ServiceRegionParam serviceRegionParam) {
+        // TODO: 2023/11/16  范围更改的时候删除调配数据 
         Long serviceRegionId = serviceRegionParam.getServiceRegionId();
         Long serviceUnitId = serviceRegionParam.getServiceUnitId();
         String regionName = serviceRegionParam.getRegionName();
@@ -173,6 +174,13 @@ public class TBServiceRegionServiceImpl extends ServiceImpl<TBServiceRegionMappe
         } else {
             // 编辑
             TBServiceRegion db = this.getById(serviceRegionId);
+            List<TBServiceRegionDetail> tbServiceRegionDetailList = tbServiceRegionDetailService
+                    .list(new QueryWrapper<TBServiceRegionDetail>()
+                            .lambda()
+                            .eq(TBServiceRegionDetail::getServiceRegionId,serviceRegionId));
+
+
+
             Long dbLeadId = db.getLeadId();
             Long dbServiceUnitId = db.getServiceId();
             tbServiceRegion.setId(serviceRegionId);
@@ -223,6 +231,11 @@ public class TBServiceRegionServiceImpl extends ServiceImpl<TBServiceRegionMappe
             }
             // 同时清除派单和大区经理的关系
             Long serviceId = tbServiceRegion.getServiceId();
+            TBService tbService = tbServiceService.getById(serviceId);
+            if (ServiceStatusEnum.FINISH.equals(tbService.getStatus())){
+                throw ExceptionResultEnum.ERROR.exception(ServiceStatusEnum.FINISH.getTitle() + "的服务单元不能作废");
+            }
+
             Long leadId = tbServiceRegion.getLeadId();
             UpdateWrapper<TBCrm> crmUpdateWrapper = new UpdateWrapper<>();
             crmUpdateWrapper.lambda()
@@ -240,19 +253,6 @@ public class TBServiceRegionServiceImpl extends ServiceImpl<TBServiceRegionMappe
         }
     }
 
-    @Override
-    public Long findRegionLeader(Long serviceUnitId, String crmNo) {
-        Long result = null;
-        List<Long> regionLeaderId = this.baseMapper.findRegionLeaderByServiceUnitIdAndCrmNo(serviceUnitId, crmNo);
-        if (CollectionUtils.isNotEmpty(regionLeaderId)) {
-            if (regionLeaderId.size() > 1) {
-                throw ExceptionResultEnum.ERROR.exception(String.format("派单号为[%s]的派单可匹配多个大区经理", crmNo));
-            }
-            result = regionLeaderId.get(0);
-        }
-        return result;
-    }
-
     @Override
     public List<SysUserBriefResult> findCanChooseLeader(Long serviceUnitId) {
         List<SysUserBriefResult> regionLeaderList = sysUserService.findUserListByRoleType(RoleTypeEnum.REGION_MANAGER);

+ 0 - 36
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesAllocationServiceImpl.java

@@ -504,42 +504,6 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
         activitiService.flowEnd(crmNo);
     }
 
-    @Transactional
-    @Override
-    public void crmReBindServiceUnit(String crmNo, Long oldServiceUnitId, Long newServiceUnitId) {
-        TBCrm tbCrm = tbCrmService.findByCrmNo(crmNo);
-        if (CrmStatusEnum.PUBLISH.equals(tbCrm.getStatus())) {
-            throw ExceptionResultEnum.ERROR.exception(String.format("已发布的派单[%s]不能重新划分,请先撤销发布", tbCrm.getCrmNo()));
-        }
-
-        if (oldServiceUnitId != null && oldServiceUnitId > 0) {
-            List<TBUserArchivesAllocation> dbAllocationList = this.list(new QueryWrapper<TBUserArchivesAllocation>().lambda()
-                    .eq(TBUserArchivesAllocation::getCrmNo, crmNo)
-                    .eq(TBUserArchivesAllocation::getServiceId, oldServiceUnitId));
-
-            if (CollectionUtils.isNotEmpty(dbAllocationList)) {
-                // 释放工程师资源
-                List<Long> archivesIdList = dbAllocationList.stream().map(TBUserArchivesAllocation::getArchivesId).distinct().collect(Collectors.toList());
-                if (CollectionUtils.isNotEmpty(archivesIdList)) {
-                    UpdateWrapper<TBUserArchives> archivesUpdateWrapper = new UpdateWrapper<>();
-                    archivesUpdateWrapper.lambda()
-                            .in(TBUserArchives::getId, archivesIdList)
-                            .set(TBUserArchives::getStatus, UserArchivesStatusEnum.FREE);
-                    tbUserArchivesService.update(archivesUpdateWrapper);
-                }
-                // 删除之前的派单分配详情
-                this.removeByIds(dbAllocationList.stream().map(TBUserArchivesAllocation::getId).distinct().collect(Collectors.toList()));
-            }
-
-            // 解绑区域协调人
-            UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
-            updateWrapper.lambda()
-                    .eq(TBCrm::getId, tbCrm.getId())
-                    .set(TBCrm::getRegionCoordinatorId, null);
-            tbCrmService.update(updateWrapper);
-        }
-    }
-
     /**
      * 处理临时新增的分配名单
      *

+ 8 - 0
sop-business/src/main/resources/db/log/caozixuan_update_log.sql

@@ -367,3 +367,11 @@ INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence
 ALTER TABLE t_b_ding_submit
     CHANGE COLUMN approach_time approach_time BIGINT NULL COMMENT '进场时间' ,
     CHANGE COLUMN departure_time departure_time BIGINT NULL COMMENT '出场时间' ;
+
+-- 2023-11-17
+ALTER TABLE t_b_crm
+    ADD COLUMN region_id BIGINT NULL COMMENT '服务区域规划id' AFTER lead_id,
+    ADD COLUMN region_detail_id BIGINT NULL COMMENT '服务区域规划明细id' AFTER region_id;
+
+DELETE FROM sys_privilege WHERE (id = '1033');
+UPDATE sys_privilege SET related = '1032,1035,1036,1037,1038' WHERE (id = '51');

+ 42 - 0
sop-business/src/main/resources/mapper/TBServiceRegionDeatilMapper.xml

@@ -2,4 +2,46 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.sop.business.mapper.TBServiceRegionDetailMapper">
 
+    <select id="findRegionDetailByServiceUnitIdAndCrmNo"
+            resultType="com.qmth.sop.business.bean.result.ServiceRegionDetailResult">
+        SELECT
+            tbsrd.id AS serviceRegionDetailId,
+            tbsrd.country AS county,
+            tbsrd.province AS province,
+            tbsrd.city AS city,
+            tbsrd.area AS area,
+            tbsrd.address AS address,
+            tbsr.id AS serviceRegionId,
+            tbsr.lead_id AS leadId,
+            su.real_name AS leadName,
+            tbsr.region_name AS regionName
+        FROM
+            t_b_service_region_detail tbsrd
+                LEFT JOIN
+            t_b_service_region tbsr ON tbsrd.service_region_id = tbsr.id
+                LEFT JOIN
+            t_b_service tbs ON tbsr.service_id = tbs.id AND tbs.enable
+                AND tbs.type != 'CANCEL'
+                LEFT JOIN
+            sys_user su ON tbsr.lead_id = su.id
+        <where>
+            <if test="crmNo != null and crmNo != '' and serviceUnitId != null">
+                AND EXISTS( SELECT
+                    1
+                FROM
+                (
+                SELECT
+                    tbc.crm_no,tbc.service_id, sc.province, sc.city
+                FROM
+                    t_b_crm tbc
+                LEFT JOIN sys_custom sc ON tbc.custom_id = sc.id) crmInfo
+                WHERE
+                    crmInfo.service_id = tbs.id
+                    AND crmInfo.province = tbsrd.province
+                    AND crmInfo.city = tbsrd.city
+                    AND crmInfo.service_id = #{serviceUnitId}
+                    AND crmInfo.crm_no = #{crmNo})
+            </if>
+        </where>
+    </select>
 </mapper>

+ 0 - 30
sop-business/src/main/resources/mapper/TBServiceRegionMapper.xml

@@ -49,34 +49,4 @@
         </where>
         ORDER BY tbsr.create_time DESC
     </select>
-    <select id="findRegionLeaderByServiceUnitIdAndCrmNo" resultType="java.lang.Long">
-        SELECT
-            tbsr.lead_id
-        FROM
-            t_b_service_region_detail tbsrd
-                LEFT JOIN
-            t_b_service_region tbsr ON tbsrd.service_region_id = tbsr.id
-                LEFT JOIN
-            t_b_service tbs ON tbsr.service_id = tbs.id AND tbs.enable
-                AND tbs.type != 'CANCEL'
-        <where>
-            <if test="crmNo != null and crmNo != '' and serviceUnitId != null">
-                AND EXISTS( SELECT
-                    1
-                FROM
-                (
-                SELECT
-                    tbc.crm_no,tbc.service_id, sc.province, sc.city
-                FROM
-                    t_b_crm tbc
-                LEFT JOIN sys_custom sc ON tbc.custom_id = sc.id) crmInfo
-                WHERE
-                    crmInfo.service_id = tbs.id
-                    AND crmInfo.province = tbsrd.province
-                    AND crmInfo.city = tbsrd.city
-                    AND crmInfo.service_id = #{serviceUnitId}
-                    AND crmInfo.crm_no = #{crmNo})
-            </if>
-        </where>
-    </select>
 </mapper>