浏览代码

add:派单作废和重新划定的条件

caozixuan 1 年之前
父节点
当前提交
c9df4f0e76

+ 1 - 0
sop-api/src/main/java/com/qmth/sop/server/api/TBCrmController.java

@@ -89,6 +89,7 @@ public class TBCrmController {
 
     //批量划定服务单元
 
+    @Deprecated
     @ApiOperation(value = "批量划定服务单元接口")
     @RequestMapping(value = "/batchZone", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})

+ 1 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBCrmService.java

@@ -121,6 +121,7 @@ public interface TBCrmService extends IService<TBCrm> {
      */
     Boolean delete(Long id);
 
+    @Deprecated
     boolean batchZone(long serviceId, long[] crmIds);
 
     boolean batchDisable(long[] crmIds);

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

@@ -85,4 +85,13 @@ 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);
 }

+ 24 - 2
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBCrmServiceImpl.java

@@ -99,9 +99,16 @@ 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)) {
@@ -132,6 +139,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
                 .set(TBCrm::getLeadId, null)
                 .eq(TBCrm::getId, tbCrm.getId());
         this.update(updateWrapper);
+        tbUserArchivesAllocationService.crmReBindServiceUnit(tbCrm.getCrmNo(), serviceUnitId, null);
     }
 
     @Override
@@ -180,6 +188,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
     @Transactional
     public Boolean saveTBCrm(TBCrm tBCrm) {
         try {
+            Long oldServiceUnitId = null;
             tBCrm.setSync(false);
             tBCrm.setEnable(true);
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
@@ -187,6 +196,11 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
                 tBCrm.setStatus(CrmStatusEnum.UN_PUBLISH);
                 tBCrm.insertInfo(sysUser.getId());
             } else { // 修改
+                TBCrm dbTBCrm = this.getById(tBCrm.getId());
+                if (Objects.isNull(dbTBCrm)) {
+                    throw ExceptionResultEnum.ERROR.exception("未找到派单信息");
+                }
+                oldServiceUnitId = dbTBCrm.getServiceId();
                 tBCrm.updateInfo(sysUser.getId());
             }
             boolean result = saveOrUpdate(tBCrm);
@@ -194,9 +208,10 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
             if (result && 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);
+                updateWrapper.lambda().eq(TBCrm::getId, tBCrm.getId()).set(TBCrm::getLeadId, regionLeaderId);
                 this.update(updateWrapper);
             }
+            tbUserArchivesAllocationService.crmReBindServiceUnit(tBCrm.getCrmNo(), oldServiceUnitId, serviceId);
             return result;
         } catch (Exception e) {
             if (e instanceof DuplicateKeyException) {
@@ -247,7 +262,14 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
         //批量修改
         List<Long> crmIdList = Arrays.stream(crmIds).boxed().collect(Collectors.toList());
         List<TBCrm> tbCrmList = this.listByIds(crmIdList);
-        tbCrmList.forEach(e -> e.setEnable(false));
+        for (TBCrm tbCrm : tbCrmList) {
+            Long serviceId = tbCrm.getServiceId();
+            if (serviceId != null && serviceId > 0){
+                throw ExceptionResultEnum.ERROR.exception(String.format("已经划分的派单[%s]不能作废",tbCrm.getCrmNo()));
+            }
+            tbCrm.setEnable(false);
+        }
+
         return this.updateBatchById(tbCrmList);
     }
 

+ 42 - 2
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesAllocationServiceImpl.java

@@ -186,8 +186,8 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
         // 更新区域负责人
         UpdateWrapper<TBCrm> coordinatorUpdateWrapper = new UpdateWrapper<>();
         coordinatorUpdateWrapper.lambda()
-                .set(TBCrm::getRegionCoordinatorId,regionUserId)
-                .eq(TBCrm::getId,tbCrm.getId());
+                .set(TBCrm::getRegionCoordinatorId, regionUserId)
+                .eq(TBCrm::getId, tbCrm.getId());
         tbCrmService.update(coordinatorUpdateWrapper);
 
         // 新增前删除派单关系
@@ -500,6 +500,46 @@ 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) {
+            if (newServiceUnitId != null && newServiceUnitId > 0) {
+                // 更新派单分配详情
+                UpdateWrapper<TBUserArchivesAllocation> allocationUpdateWrapper = new UpdateWrapper<>();
+                allocationUpdateWrapper.lambda()
+                        .eq(TBUserArchivesAllocation::getCrmNo, crmNo)
+                        .eq(TBUserArchivesAllocation::getServiceId, oldServiceUnitId)
+                        .set(TBUserArchivesAllocation::getServiceId, newServiceUnitId);
+                this.update(allocationUpdateWrapper);
+            } else {
+                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()));
+                }
+
+            }
+        }
+    }
+
     /**
      * 处理临时新增的分配名单
      *