瀏覽代碼

add:人员调配保存

caozixuan 1 年之前
父節點
當前提交
428cd5e4d8

+ 2 - 1
sop-api/src/main/java/com/qmth/sop/server/api/TBUserArchivesAllocationController.java

@@ -86,7 +86,8 @@ public class TBUserArchivesAllocationController {
     @RequestMapping(value = "/edit", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "更新成功", response = Result.class)})
     @OperationLog(logType = LogTypeEnum.EDIT)
-    public Result edit(@Valid @RequestBody UserArchivesAllocationParam userArchivesAllocationParam, BindingResult bindingResult) {
+    public Result edit(@Valid @RequestBody UserArchivesAllocationParam userArchivesAllocationParam, BindingResult bindingResult)
+            throws InterruptedException {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }

+ 25 - 12
sop-business/src/main/java/com/qmth/sop/business/bean/params/AllocationParam.java

@@ -2,6 +2,7 @@ package com.qmth.sop.business.bean.params;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.enums.SopRoleTypeEnum;
 import io.swagger.annotations.ApiModelProperty;
 import org.hibernate.validator.constraints.Range;
 
@@ -15,29 +16,41 @@ import java.util.List;
  * @Date: 2023-08-16
  */
 public class AllocationParam {
+
     @ApiModelProperty("角色id")
     @JsonSerialize(using = ToStringSerializer.class)
     @NotNull(message = "请提供调配的身份")
     @Range(min = 1L, message = "请提供调配的身份")
-    private Long roleId;
+    private SopRoleTypeEnum sopRoleType;
+
+    @ApiModelProperty("档案id集合")
+    @NotEmpty(message = "请提供调配的档案id")
+    private List<Long> archivesIdList;
+
+    @ApiModelProperty("备注(为同批次新增全部人员赋值备注信息)")
+    private String remark;
 
-    @ApiModelProperty("用户集合")
-    @NotEmpty(message = "请提供调配的用户")
-    private List<Long> userIdList;
+    public SopRoleTypeEnum getSopRoleType() {
+        return sopRoleType;
+    }
+
+    public void setSopRoleType(SopRoleTypeEnum sopRoleType) {
+        this.sopRoleType = sopRoleType;
+    }
 
-    public Long getRoleId() {
-        return roleId;
+    public List<Long> getArchivesIdList() {
+        return archivesIdList;
     }
 
-    public void setRoleId(Long roleId) {
-        this.roleId = roleId;
+    public void setArchivesIdList(List<Long> archivesIdList) {
+        this.archivesIdList = archivesIdList;
     }
 
-    public List<Long> getUserIdList() {
-        return userIdList;
+    public String getRemark() {
+        return remark;
     }
 
-    public void setUserIdList(List<Long> userIdList) {
-        this.userIdList = userIdList;
+    public void setRemark(String remark) {
+        this.remark = remark;
     }
 }

+ 6 - 29
sop-business/src/main/java/com/qmth/sop/business/bean/params/UserArchivesAllocationParam.java

@@ -16,6 +16,7 @@ import java.util.List;
  * @Date: 2023-08-16
  */
 public class UserArchivesAllocationParam {
+
     @ApiModelProperty("分配参数")
     private List<AllocationParam> allocationParams;
 
@@ -23,15 +24,7 @@ public class UserArchivesAllocationParam {
     @ApiModelProperty("服务单元id")
     @NotNull(message = "请提供服务单元id")
     @Range(min = 1L, message = "请提供服务单元id")
-    private Long serviceUnitId;
-
-    @ApiModelProperty("派单号")
-    @NotBlank(message = "缺少派单信息")
-    private String crmNo;
-
-    @JsonSerialize(using = ToStringSerializer.class)
-    @ApiModelProperty("区域协调人id")
-    private Long regionUserId;
+    private Long crmDetailId;
 
     public List<AllocationParam> getAllocationParams() {
         return allocationParams;
@@ -41,27 +34,11 @@ public class UserArchivesAllocationParam {
         this.allocationParams = allocationParams;
     }
 
-    public Long getServiceUnitId() {
-        return serviceUnitId;
-    }
-
-    public void setServiceUnitId(Long serviceUnitId) {
-        this.serviceUnitId = serviceUnitId;
-    }
-
-    public String getCrmNo() {
-        return crmNo;
-    }
-
-    public void setCrmNo(String crmNo) {
-        this.crmNo = crmNo;
-    }
-
-    public Long getRegionUserId() {
-        return regionUserId;
+    public Long getCrmDetailId() {
+        return crmDetailId;
     }
 
-    public void setRegionUserId(Long regionUserId) {
-        this.regionUserId = regionUserId;
+    public void setCrmDetailId(Long crmDetailId) {
+        this.crmDetailId = crmDetailId;
     }
 }

+ 2 - 13
sop-business/src/main/java/com/qmth/sop/business/entity/TBUserArchivesAllocation.java

@@ -2,6 +2,7 @@ package com.qmth.sop.business.entity;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.base.BaseEntity;
 import com.qmth.sop.common.enums.SopRoleTypeEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -17,14 +18,10 @@ import java.io.Serializable;
  * @since 2023-08-01
  */
 @ApiModel(value="TBUserArchivesAllocation对象", description="人员分配表")
-public class TBUserArchivesAllocation implements Serializable {
+public class TBUserArchivesAllocation extends BaseEntity implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @ApiModelProperty(value = "主键")
-    @JsonSerialize(using = ToStringSerializer.class)
-    private Long id;
-
     @ApiModelProperty(value = "派单明细id")
     @JsonSerialize(using = ToStringSerializer.class)
     private Long crmDetailId;
@@ -50,14 +47,6 @@ public class TBUserArchivesAllocation implements Serializable {
     @ApiModelProperty(value = "备注")
     private String remark;
 
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
     public Long getCrmDetailId() {
         return crmDetailId;
     }

+ 4 - 3
sop-business/src/main/java/com/qmth/sop/business/entity/TBUserArchivesAllocationLog.java

@@ -1,6 +1,7 @@
 package com.qmth.sop.business.entity;
 
 import com.qmth.sop.common.base.BaseEntity;
+import com.qmth.sop.common.enums.SopRoleTypeEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -21,7 +22,7 @@ public class TBUserArchivesAllocationLog extends BaseEntity {
     private Long crmDetailId;
 
     @ApiModelProperty(value = "sop角色类型")
-    private String sopRoleType;
+    private SopRoleTypeEnum sopRoleType;
 
     @ApiModelProperty(value = "用户id")
     private Long userId;
@@ -46,11 +47,11 @@ public class TBUserArchivesAllocationLog extends BaseEntity {
         this.crmDetailId = crmDetailId;
     }
 
-    public String getSopRoleType() {
+    public SopRoleTypeEnum getSopRoleType() {
         return sopRoleType;
     }
 
-    public void setSopRoleType(String sopRoleType) {
+    public void setSopRoleType(SopRoleTypeEnum sopRoleType) {
         this.sopRoleType = sopRoleType;
     }
 

+ 10 - 2
sop-business/src/main/java/com/qmth/sop/business/service/SysUserService.java

@@ -9,7 +9,6 @@ import com.qmth.sop.business.bean.dto.UserDto;
 import com.qmth.sop.business.bean.result.*;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.sync.been.rtzf.RtzfResult;
-import com.qmth.sop.business.sync.been.rtzf.RtzfUserInfo;
 import com.qmth.sop.common.enums.*;
 
 import java.security.NoSuchAlgorithmException;
@@ -202,9 +201,18 @@ public interface SysUserService extends IService<SysUser> {
 
     /**
      * 软通智服更新用户
-     * @param requestUser 请求的用户
+     *
+     * @param requestUser    请求的用户
      * @param willUpdateUser 将要更新的用户
      * @return 更新结果
      */
     RtzfResult rtzfUpdateUser(SysUser requestUser, SysUser willUpdateUser);
+
+    /**
+     * 根据档案id查询用户
+     *
+     * @param archivesId 档案id
+     * @return 用户
+     */
+    SysUser findByArchivesId(Long archivesId);
 }

+ 2 - 1
sop-business/src/main/java/com/qmth/sop/business/service/TBUserArchivesAllocationService.java

@@ -60,7 +60,7 @@ public interface TBUserArchivesAllocationService extends IService<TBUserArchives
      *
      * @param userArchivesAllocationParam 派单参数
      */
-    void editCrmAllocation(UserArchivesAllocationParam userArchivesAllocationParam);
+    void editCrmAllocation(UserArchivesAllocationParam userArchivesAllocationParam) throws InterruptedException;
 
     /**
      * 根据派单号查询派单分配信息
@@ -75,6 +75,7 @@ public interface TBUserArchivesAllocationService extends IService<TBUserArchives
      *
      * @param autoAllocationParam 自动调配参数
      */
+    @Deprecated
     void autoEditCrmAllocationBatch(AutoAllocationParam autoAllocationParam);
 
     /**

+ 14 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysUserServiceImpl.java

@@ -656,4 +656,18 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         }
         return rtzfResult;
     }
+
+    @Override
+    public SysUser findByArchivesId(Long archivesId) {
+        TBUserArchives tbUserArchives = tbUserArchivesService.getById(archivesId);
+        if (Objects.isNull(tbUserArchives)) {
+            throw ExceptionResultEnum.ERROR.exception("未找到档案信息");
+        }
+        String mobileNumber = tbUserArchives.getMobileNumber();
+        SysUser sysUser = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getMobileNumber, mobileNumber).last(SystemConstant.LIMIT1));
+        if (Objects.isNull(sysUser)) {
+            throw ExceptionResultEnum.ERROR.exception("未找到用户信息");
+        }
+        return sysUser;
+    }
 }

+ 251 - 288
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesAllocationServiceImpl.java

@@ -1,7 +1,6 @@
 package com.qmth.sop.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -17,7 +16,6 @@ import com.qmth.sop.business.bean.result.*;
 import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.TBUserArchivesAllocationMapper;
 import com.qmth.sop.business.service.*;
-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.ServletUtil;
@@ -26,7 +24,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -43,18 +43,12 @@ public class TBUserArchivesAllocationServiceImpl
         extends ServiceImpl<TBUserArchivesAllocationMapper, TBUserArchivesAllocation>
         implements TBUserArchivesAllocationService {
 
-    @Resource
-    private TBServiceService tbServiceService;
-
     @Resource
     private TBCrmService tbCrmService;
 
     @Resource
     private SysRoleService sysRoleService;
 
-    @Resource
-    private SysUserRoleService sysUserRoleService;
-
     @Resource
     private TBUserArchivesService tbUserArchivesService;
 
@@ -73,6 +67,9 @@ public class TBUserArchivesAllocationServiceImpl
     @Resource
     private TBUserArchivesAllocationLogService tbUserArchivesAllocationLogService;
 
+    @Resource
+    private TBCrmDetailService tbCrmDetailService;
+
     @Override
     public IPage<UserArchivesAllocationResult> findCrmAllocationPage(Long serviceUnitId, String province, String city,
             String area, String customName, Integer gap, Long regionId, Integer pageNumber, Integer pageSize) {
@@ -130,113 +127,77 @@ public class TBUserArchivesAllocationServiceImpl
 
     @Transactional
     @Override
-    public void editCrmAllocation(UserArchivesAllocationParam userArchivesAllocationParam) {
-        Long serviceUnitId = userArchivesAllocationParam.getServiceUnitId();
-        TBService tbService = tbServiceService.getById(serviceUnitId);
-        if (Objects.isNull(tbService)) {
-            throw ExceptionResultEnum.ERROR.exception("服务单元不存在");
-        }
-
-        String crmNo = userArchivesAllocationParam.getCrmNo();
-        Long regionUserId = userArchivesAllocationParam.getRegionUserId();
-
-        List<TBCrm> tbCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getCrmNo, crmNo));
-        if (CollectionUtils.isEmpty(tbCrmList)) {
-            throw ExceptionResultEnum.ERROR.exception("派单不存在");
-        }
-        if (tbCrmList.size() > 1) {
-            throw ExceptionResultEnum.ERROR.exception("存在多个相同派单号的派单[" + crmNo + "]");
-        }
-        TBCrm tbCrm = tbCrmList.get(0);
-
-        List<TBUserArchivesAllocation> dbList = this.list(
-                new QueryWrapper<TBUserArchivesAllocation>().lambda().eq(TBUserArchivesAllocation::getCrmNo, crmNo));
-
-        //        if (dbList.stream().anyMatch(e -> Objects.nonNull(e.getSopNo()))) {
-        //            throw ExceptionResultEnum.ERROR.exception("已发布的派单不能调配");
-        //        }
-
-        // 新增关系
+    public void editCrmAllocation(UserArchivesAllocationParam userArchivesAllocationParam) throws InterruptedException {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         List<AllocationParam> allocationParamList = userArchivesAllocationParam.getAllocationParams();
+        Long crmDetailId = userArchivesAllocationParam.getCrmDetailId();
+        TBCrmDetail crmDetail = tbCrmDetailService.getById(crmDetailId);
+        if (Objects.isNull(crmDetail)) {
+            throw ExceptionResultEnum.ERROR.exception("未找到派单详情");
+        }
 
-        List<TBUserArchivesAllocation> tbUserArchivesAllocationList = new ArrayList<>();
-        // 处理实施工程师或助理工程师
-        if (CollectionUtils.isNotEmpty(allocationParamList)) {
-            for (AllocationParam allocationParam : allocationParamList) {
-                Long roleId = allocationParam.getRoleId();
-                List<Long> userIdList = allocationParam.getUserIdList();
-                SysRole role = sysRoleService.getById(roleId);
-                if (Objects.isNull(role)) {
-                    throw ExceptionResultEnum.ERROR.exception("认证角色不存在");
-                } else {
-                    if (!RoleTypeEnum.EFFECT_ENGINEER.equals(role.getType()) && !RoleTypeEnum.ASSISTANT_ENGINEER.equals(
-                            role.getType())) {
-                        throw ExceptionResultEnum.ERROR.exception(
-                                String.format("认证角色类型为[%s]不属于[%s]或[%s]", role.getType().getDesc(),
-                                        RoleTypeEnum.EFFECT_ENGINEER.getDesc(),
-                                        RoleTypeEnum.ASSISTANT_ENGINEER.getDesc()));
-                    }
-                }
+        String crmNo = crmDetail.getCrmNo();
+        TBCrm tbCrm = tbCrmService.findByCrmNo(crmNo);
 
-                for (Long userId : userIdList) {
-                    List<Long> sysRoleIdList = sysUserRoleService.listRoleByUserId(userId).stream()
-                            .map(BaseEntity::getId).distinct().collect(Collectors.toList());
-                    if (!sysRoleIdList.contains(roleId)) {
-                        throw ExceptionResultEnum.ERROR.exception("所选用户不包含认证角色[" + role.getType().getDesc() + "]");
-                    }
-                    TBUserArchives tbUserArchives = tbUserArchivesService.findByUserId(userId);
-                    if (!UserArchivesStatusEnum.FREE.equals(tbUserArchives.getStatus())) {
-                        List<TBCrm> occupiedCrm = tbCrmService.findOccupiedCrm(userId, null);
-                        if (CollectionUtils.isEmpty(occupiedCrm)) {
-                            throw ExceptionResultEnum.ERROR.exception("人员占用状态异常");
-                        }
-                        if (!occupiedCrm.stream().map(TBCrm::getCrmNo).collect(Collectors.toList()).contains(crmNo)) {
-                            throw ExceptionResultEnum.ERROR.exception(
-                                    String.format("工程师[%s]已经被派单号为[%s]的派单占用,请先将工程师从派单中移出", tbUserArchives.getName(),
-                                            occupiedCrm.stream().map(TBCrm::getCrmNo).collect(Collectors.joining())));
-                        }
-                    }
-                    TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
-                    tbUserArchivesAllocation.setCrmNo(crmNo);
-                    tbUserArchivesAllocation.setArchivesId(tbUserArchives.getId());
-                    tbUserArchivesAllocation.setServiceId(serviceUnitId);
-                    tbUserArchivesAllocation.setUserId(userId);
-                    tbUserArchivesAllocationList.add(tbUserArchivesAllocation);
+        // 该派单详情全部的人员分配关系
+        List<TBUserArchivesAllocation> allocatedDatasource = this.list(
+                new QueryWrapper<TBUserArchivesAllocation>().lambda().eq(TBUserArchivesAllocation::getCrmDetailId, crmDetailId));
+
+        for (AllocationParam allocationParam : allocationParamList) {
+            SopRoleTypeEnum sopRoleType = allocationParam.getSopRoleType();
+            String remark = allocationParam.getRemark();
+            // 本次要分配的人员档案id集合
+            List<Long> archivesIdList = allocationParam.getArchivesIdList();
+
+            List<TBUserArchivesAllocation> allocatedList = allocatedDatasource.stream()
+                    .filter(e -> e.getSopRoleType().equals(sopRoleType)).collect(Collectors.toList());
+            // 之前已分配的人员档案id集合
+            List<Long> allocatedIdList = allocatedList.stream().map(TBUserArchivesAllocation::getArchivesId).distinct().collect(Collectors.toList());
+
+            // 经过对比要删除的人员档案id集合
+            List<Long> removeList = allocatedIdList.stream().filter(e -> !archivesIdList.contains(e)).distinct().collect(Collectors.toList());
+            // 对删除的档案人员添加历史记录
+            List<TBUserArchivesAllocationLog> historicList = removeList.stream().flatMap(e -> {
+                UserArchivesResult userArchivesResult = tbUserArchivesService.findUserArchivesByArchivesIdORUserId(e,
+                        null);
+                TBUserArchivesAllocationLog historic = new TBUserArchivesAllocationLog();
+                historic.setCrmDetailId(crmDetailId);
+                historic.setSopRoleType(sopRoleType);
+                historic.setUserId(userArchivesResult.getUserId());
+                historic.setArchivesId(e);
+                historic.setArchivesName(userArchivesResult.getName());
+                historic.setSupplierName(userArchivesResult.getSupplierName());
+                historic.setCity(userArchivesResult.getCity());
+                historic.insertInfo(requestUser.getId());
+                return Stream.of(historic);
+            }).collect(Collectors.toList());
+            tbUserArchivesAllocationLogService.saveBatch(historicList);
+            this.remove(new QueryWrapper<TBUserArchivesAllocation>().lambda()
+                    .eq(TBUserArchivesAllocation::getArchivesId, removeList)
+                    .eq(TBUserArchivesAllocation::getCrmDetailId, crmDetailId));
+
+            // 经过对比要新增的人员档案id集合
+            List<Long> addList = archivesIdList.stream().filter(e -> !allocatedIdList.contains(e)).distinct().collect(Collectors.toList());
+            List<TBUserArchivesAllocation> addListData = addList.stream().flatMap(e -> {
+                TBUserArchivesAllocation allocation = new TBUserArchivesAllocation();
+                allocation.setCrmDetailId(crmDetailId);
+                allocation.setArchivesId(e);
+                // TODO: 2024/5/20 服务单元id有可能要去掉(感觉调配和划定没有关系) - czx
+
+                allocation.setServiceId(tbCrm.getServiceId());
+                allocation.setCrmNo(crmNo);
+                allocation.setSopRoleType(sopRoleType);
+                allocation.setUserId(sysUserService.findByArchivesId(e).getId());
+                allocation.setArchivesId(e);
+                if (remark != null && remark.length() > 0) {
+                    allocation.setRemark(remark);
                 }
-            }
-        }
-
-        // 更新区域负责人
-        UpdateWrapper<TBCrm> coordinatorUpdateWrapper = new UpdateWrapper<>();
-        coordinatorUpdateWrapper.lambda().set(TBCrm::getRegionCoordinatorId, regionUserId)
-                .eq(TBCrm::getId, tbCrm.getId());
-        tbCrmService.update(coordinatorUpdateWrapper);
-
-        // 新增前删除派单关系
-        if (CollectionUtils.isNotEmpty(dbList)) {
-            // 删除关系前先将工程师状态更改为空闲
-            List<Long> engineerDbIdList = dbList.stream().map(TBUserArchivesAllocation::getArchivesId).distinct()
-                    .collect(Collectors.toList());
-            UpdateWrapper<TBUserArchives> archivesUpdateWrapper = new UpdateWrapper<>();
-            archivesUpdateWrapper.lambda().set(TBUserArchives::getStatus, UserArchivesStatusEnum.FREE)
-                    .in(TBUserArchives::getId, engineerDbIdList);
-            tbUserArchivesService.update(archivesUpdateWrapper);
-
-            // 删除派单关系
-            this.removeByIds(dbList.stream().map(TBUserArchivesAllocation::getId).collect(Collectors.toList()));
-        }
+                allocation.insertInfo(requestUser.getId());
+                return Stream.of(allocation);
+            }).collect(Collectors.toList());
+            this.saveBatch(addListData);
 
-        if (CollectionUtils.isNotEmpty(tbUserArchivesAllocationList)) {
-            // 新增前先将工程师的状态设置为非空闲
-            List<Long> engineerAddIdLIst = tbUserArchivesAllocationList.stream()
-                    .map(TBUserArchivesAllocation::getArchivesId).distinct().collect(Collectors.toList());
-            UpdateWrapper<TBUserArchives> archivesUpdateWrapper = new UpdateWrapper<>();
-            archivesUpdateWrapper.lambda().set(TBUserArchives::getStatus, UserArchivesStatusEnum.OCCUPIED)
-                    .in(TBUserArchives::getId, engineerAddIdLIst);
-            tbUserArchivesService.update(archivesUpdateWrapper);
-
-            // 新增分配关系
-            this.saveBatch(tbUserArchivesAllocationList);
+            tbSopInfoService.sopApproverExchange(crmDetailId);
         }
     }
 
@@ -271,183 +232,185 @@ public class TBUserArchivesAllocationServiceImpl
     @Transactional
     @Override
     public void autoEditCrmAllocationBatch(AutoAllocationParam autoAllocationParam) {
-        Long serviceUnitId = autoAllocationParam.getServiceUnitId();
-        List<Long> crmIdList = autoAllocationParam.getCrmIdList();
-        List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId,
-                null, null, null, null, null, crmIdList, CrmStatusEnum.UN_PUBLISH, null, null);
-        // crm按照差额倒序
-        crmSourceList = crmSourceList.stream().filter(e -> e.getUnDistributed() > 0)
-                .sorted(Comparator.comparing(UserArchivesAllocationResult::getUnDistributed).reversed())
-                .collect(Collectors.toList());
-
-        for (UserArchivesAllocationResult crmSource : crmSourceList) {
-            String crmNo = crmSource.getCrmNo();
-            String city = crmSource.getCity();
-            String province = crmSource.getProvince();
-
-            // 区域协调人差额
-            Integer coordinatorUnDistributed = crmSource.getCoordinatorUnDistributed();
-
-            // 实施工程师差额
-            Integer effectUnDistributed = crmSource.getEffectUnDistributed();
-
-            // 助理工程师差额
-            Integer assistantUnDistributed = crmSource.getAssistantUnDistributed();
-
-            // 该派单已经分配的人员名单
-            List<CrmArchivesAllocationResult> crmArchivesAllocationResultList = this.findAllocationByCrmNo(crmNo);
-            // 区域协调人
-            List<CrmArchivesAllocationResult> coordinatorList = crmArchivesAllocationResultList.stream()
-                    .filter(e -> RoleTypeEnum.REGION_COORDINATOR.equals(e.getType())).collect(Collectors.toList());
-            // 实施工程师
-            List<CrmArchivesAllocationResult> effectList = crmArchivesAllocationResultList.stream()
-                    .filter(e -> RoleTypeEnum.EFFECT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
-            // 助理工程师
-            List<CrmArchivesAllocationResult> assistantList = crmArchivesAllocationResultList.stream()
-                    .filter(e -> RoleTypeEnum.ASSISTANT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
-
-            // 可分配的人力资源
-            List<ArchivesSourceResult> effectFree = tbUserArchivesService.findFreeEngineerSourceByType(
-                            RoleTypeEnum.EFFECT_ENGINEER, null).stream()
-                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
-                    .collect(Collectors.toList());
-
-            List<ArchivesSourceResult> assistantFree = tbUserArchivesService.findFreeEngineerSourceByType(
-                            RoleTypeEnum.ASSISTANT_ENGINEER, null).stream()
-                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
-                    .collect(Collectors.toList());
-
-            List<ArchivesSourceResult> coordinatorFree = tbUserArchivesService.findFreeCoordinatorByServiceId(
-                            serviceUnitId, null, true).stream()
-                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
-                    .collect(Collectors.toList());
-
-            List<AllocationParam> allocationParamList = new ArrayList<>();
-
-            // 先分实施工程师
-            if (effectUnDistributed > 0) {
-                SysRole effectRole = sysRoleService.list(
-                        new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.EFFECT_ENGINEER)).get(0);
-                Long effectRoleId = effectRole.getId();
-                List<Long> userIdList = new ArrayList<>();
-                if (CollectionUtils.isNotEmpty(coordinatorList)) {
-                    // 实施工程师和区域协调人同供应商,实施工程师和crm客户同城市
-                    CrmArchivesAllocationResult coordinator = coordinatorList.get(0);
-                    Long supplierId = coordinator.getSupplierId();
-                    effectFree = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
-                            .limit(effectUnDistributed).collect(Collectors.toList());
-                    userIdList.addAll(effectFree.stream().map(ArchivesSourceResult::getUserId).distinct()
-                            .collect(Collectors.toList()));
-                    this.addDistributeTemp(effectList, effectFree);
-                } else {
-                    // 不存在区域协调人,实施工程师和crm客户同城市,且实施工程师尽可能集中在同一个供应商中
-
-                    // 供应商和实施工程师数量键值对
-                    Map<Long, Integer> supplierMap = effectFree.stream()
-                            .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
-                    supplierMap = SystemConstant.sortMapByValues(supplierMap);
-                    for (Long supplierId : supplierMap.keySet()) {
-                        Integer count = supplierMap.get(supplierId);
-                        int effectDivide = effectUnDistributed - count;
-                        List<ArchivesSourceResult> cell;
-                        if (effectDivide > 0) {
-                            // 该供应商的不够分配配额
-                            cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
-                                    .collect(Collectors.toList());
-                            userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
-                                    .collect(Collectors.toList()));
-                            this.addDistributeTemp(effectList, cell);
-                            // 进入下一个供应商循环
-                            effectUnDistributed = effectUnDistributed - count;
-                        } else {
-                            // 该供应商的足够分配配额
-                            cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
-                                    .limit(effectUnDistributed).collect(Collectors.toList());
-                            userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
-                                    .collect(Collectors.toList()));
-                            this.addDistributeTemp(effectList, cell);
-                            break;
-                        }
-                    }
-                }
-                AllocationParam allocationParam = new AllocationParam();
-                allocationParam.setRoleId(effectRoleId);
-                allocationParam.setUserIdList(userIdList);
-                allocationParamList.add(allocationParam);
-            }
-            // 再分助理工程师
-            if (assistantUnDistributed > 0) {
-                SysRole assistantRole = sysRoleService.list(
-                                new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.ASSISTANT_ENGINEER))
-                        .get(0);
-                Long assistantRoleId = assistantRole.getId();
-                List<Long> userIdList = new ArrayList<>();
-                Map<Long, Integer> supplierMap = assistantFree.stream()
-                        .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
-                supplierMap = SystemConstant.sortMapByValues(supplierMap);
-                for (Long supplierId : supplierMap.keySet()) {
-                    Integer count = supplierMap.get(supplierId);
-                    int assistantDivide = assistantUnDistributed - count;
-                    List<ArchivesSourceResult> cell;
-                    if (assistantDivide > 0) {
-                        // 该供应商的不够分配配额
-                        cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
-                                .collect(Collectors.toList());
-                        userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
-                                .collect(Collectors.toList()));
-                        this.addDistributeTemp(assistantList, cell);
-                        assistantUnDistributed = assistantUnDistributed - count;
-                    } else {
-                        // 该供应商的足够分配配额
-                        cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
-                                .limit(assistantUnDistributed).collect(Collectors.toList());
-                        userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
-                                .collect(Collectors.toList()));
-                        this.addDistributeTemp(assistantList, cell);
-                        break;
-                    }
-                }
-                AllocationParam allocationParam = new AllocationParam();
-                allocationParam.setRoleId(assistantRoleId);
-                allocationParam.setUserIdList(userIdList);
-                allocationParamList.add(allocationParam);
-            }
-
-            // 最后分配区域协调人
-            Long regionUserId = null;
-            if (coordinatorUnDistributed > 0) {
-                if (CollectionUtils.isNotEmpty(effectList)) {
-                    // 存在已经分配的实施工程师
-                    List<Long> supplierIdList = effectList.stream().map(CrmArchivesAllocationResult::getSupplierId)
-                            .distinct().collect(Collectors.toList());
-                    if (supplierIdList.size() == 1) {
-                        Long supplierId = supplierIdList.get(0);
-                        List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
-                                .filter(e -> supplierId.equals(e.getSupplierId()))
-                                .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
-                                .collect(Collectors.toList());
-                        if (CollectionUtils.isNotEmpty(coordinator)) {
-                            regionUserId = coordinator.get(0).getUserId();
-                        }
-                    }
-                } else {
-                    // 不存在实施工程师
-                    List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
-                            .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
-                            .collect(Collectors.toList());
-                    if (CollectionUtils.isNotEmpty(coordinator)) {
-                        regionUserId = coordinator.get(0).getUserId();
-                    }
-
-                }
-            }
-            UserArchivesAllocationParam userArchivesAllocationParam = new UserArchivesAllocationParam();
-            userArchivesAllocationParam.setAllocationParams(allocationParamList);
-            userArchivesAllocationParam.setServiceUnitId(serviceUnitId);
-            userArchivesAllocationParam.setCrmNo(crmNo);
-            userArchivesAllocationParam.setRegionUserId(regionUserId);
-            this.editCrmAllocation(userArchivesAllocationParam);
-        }
+        // TODO: 2024/5/20 先取消自动调配
+
+        //        Long serviceUnitId = autoAllocationParam.getServiceUnitId();
+        //        List<Long> crmIdList = autoAllocationParam.getCrmIdList();
+        //        List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId,
+        //                null, null, null, null, null, crmIdList, CrmStatusEnum.UN_PUBLISH, null, null);
+        //        // crm按照差额倒序
+        //        crmSourceList = crmSourceList.stream().filter(e -> e.getUnDistributed() > 0)
+        //                .sorted(Comparator.comparing(UserArchivesAllocationResult::getUnDistributed).reversed())
+        //                .collect(Collectors.toList());
+        //
+        //        for (UserArchivesAllocationResult crmSource : crmSourceList) {
+        //            String crmNo = crmSource.getCrmNo();
+        //            String city = crmSource.getCity();
+        //            String province = crmSource.getProvince();
+        //
+        //            // 区域协调人差额
+        //            Integer coordinatorUnDistributed = crmSource.getCoordinatorUnDistributed();
+        //
+        //            // 实施工程师差额
+        //            Integer effectUnDistributed = crmSource.getEffectUnDistributed();
+        //
+        //            // 助理工程师差额
+        //            Integer assistantUnDistributed = crmSource.getAssistantUnDistributed();
+        //
+        //            // 该派单已经分配的人员名单
+        //            List<CrmArchivesAllocationResult> crmArchivesAllocationResultList = this.findAllocationByCrmNo(crmNo);
+        //            // 区域协调人
+        //            List<CrmArchivesAllocationResult> coordinatorList = crmArchivesAllocationResultList.stream()
+        //                    .filter(e -> RoleTypeEnum.REGION_COORDINATOR.equals(e.getType())).collect(Collectors.toList());
+        //            // 实施工程师
+        //            List<CrmArchivesAllocationResult> effectList = crmArchivesAllocationResultList.stream()
+        //                    .filter(e -> RoleTypeEnum.EFFECT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
+        //            // 助理工程师
+        //            List<CrmArchivesAllocationResult> assistantList = crmArchivesAllocationResultList.stream()
+        //                    .filter(e -> RoleTypeEnum.ASSISTANT_ENGINEER.equals(e.getType())).collect(Collectors.toList());
+        //
+        //            // 可分配的人力资源
+        //            List<ArchivesSourceResult> effectFree = tbUserArchivesService.findFreeEngineerSourceByType(
+        //                            RoleTypeEnum.EFFECT_ENGINEER, null).stream()
+        //                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
+        //                    .collect(Collectors.toList());
+        //
+        //            List<ArchivesSourceResult> assistantFree = tbUserArchivesService.findFreeEngineerSourceByType(
+        //                            RoleTypeEnum.ASSISTANT_ENGINEER, null).stream()
+        //                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
+        //                    .collect(Collectors.toList());
+        //
+        //            List<ArchivesSourceResult> coordinatorFree = tbUserArchivesService.findFreeCoordinatorByServiceId(
+        //                            serviceUnitId, null, true).stream()
+        //                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
+        //                    .collect(Collectors.toList());
+        //
+        //            List<AllocationParam> allocationParamList = new ArrayList<>();
+        //
+        //            // 先分实施工程师
+        //            if (effectUnDistributed > 0) {
+        //                SysRole effectRole = sysRoleService.list(
+        //                        new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.EFFECT_ENGINEER)).get(0);
+        //                Long effectRoleId = effectRole.getId();
+        //                List<Long> userIdList = new ArrayList<>();
+        //                if (CollectionUtils.isNotEmpty(coordinatorList)) {
+        //                    // 实施工程师和区域协调人同供应商,实施工程师和crm客户同城市
+        //                    CrmArchivesAllocationResult coordinator = coordinatorList.get(0);
+        //                    Long supplierId = coordinator.getSupplierId();
+        //                    effectFree = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
+        //                            .limit(effectUnDistributed).collect(Collectors.toList());
+        //                    userIdList.addAll(effectFree.stream().map(ArchivesSourceResult::getUserId).distinct()
+        //                            .collect(Collectors.toList()));
+        //                    this.addDistributeTemp(effectList, effectFree);
+        //                } else {
+        //                    // 不存在区域协调人,实施工程师和crm客户同城市,且实施工程师尽可能集中在同一个供应商中
+        //
+        //                    // 供应商和实施工程师数量键值对
+        //                    Map<Long, Integer> supplierMap = effectFree.stream()
+        //                            .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
+        //                    supplierMap = SystemConstant.sortMapByValues(supplierMap);
+        //                    for (Long supplierId : supplierMap.keySet()) {
+        //                        Integer count = supplierMap.get(supplierId);
+        //                        int effectDivide = effectUnDistributed - count;
+        //                        List<ArchivesSourceResult> cell;
+        //                        if (effectDivide > 0) {
+        //                            // 该供应商的不够分配配额
+        //                            cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
+        //                                    .collect(Collectors.toList());
+        //                            userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
+        //                                    .collect(Collectors.toList()));
+        //                            this.addDistributeTemp(effectList, cell);
+        //                            // 进入下一个供应商循环
+        //                            effectUnDistributed = effectUnDistributed - count;
+        //                        } else {
+        //                            // 该供应商的足够分配配额
+        //                            cell = effectFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
+        //                                    .limit(effectUnDistributed).collect(Collectors.toList());
+        //                            userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
+        //                                    .collect(Collectors.toList()));
+        //                            this.addDistributeTemp(effectList, cell);
+        //                            break;
+        //                        }
+        //                    }
+        //                }
+        //                AllocationParam allocationParam = new AllocationParam();
+        //                allocationParam.setRoleId(effectRoleId);
+        //                allocationParam.setUserIdList(userIdList);
+        //                allocationParamList.add(allocationParam);
+        //            }
+        //            // 再分助理工程师
+        //            if (assistantUnDistributed > 0) {
+        //                SysRole assistantRole = sysRoleService.list(
+        //                                new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.ASSISTANT_ENGINEER))
+        //                        .get(0);
+        //                Long assistantRoleId = assistantRole.getId();
+        //                List<Long> userIdList = new ArrayList<>();
+        //                Map<Long, Integer> supplierMap = assistantFree.stream()
+        //                        .collect(Collectors.toMap(ArchivesSourceResult::getSupplierId, e -> 1, Integer::sum));
+        //                supplierMap = SystemConstant.sortMapByValues(supplierMap);
+        //                for (Long supplierId : supplierMap.keySet()) {
+        //                    Integer count = supplierMap.get(supplierId);
+        //                    int assistantDivide = assistantUnDistributed - count;
+        //                    List<ArchivesSourceResult> cell;
+        //                    if (assistantDivide > 0) {
+        //                        // 该供应商的不够分配配额
+        //                        cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId())).limit(count)
+        //                                .collect(Collectors.toList());
+        //                        userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
+        //                                .collect(Collectors.toList()));
+        //                        this.addDistributeTemp(assistantList, cell);
+        //                        assistantUnDistributed = assistantUnDistributed - count;
+        //                    } else {
+        //                        // 该供应商的足够分配配额
+        //                        cell = assistantFree.stream().filter(e -> supplierId.equals(e.getSupplierId()))
+        //                                .limit(assistantUnDistributed).collect(Collectors.toList());
+        //                        userIdList.addAll(cell.stream().map(ArchivesSourceResult::getUserId).distinct()
+        //                                .collect(Collectors.toList()));
+        //                        this.addDistributeTemp(assistantList, cell);
+        //                        break;
+        //                    }
+        //                }
+        //                AllocationParam allocationParam = new AllocationParam();
+        //                allocationParam.setRoleId(assistantRoleId);
+        //                allocationParam.setUserIdList(userIdList);
+        //                allocationParamList.add(allocationParam);
+        //            }
+        //
+        //            // 最后分配区域协调人
+        //            Long regionUserId = null;
+        //            if (coordinatorUnDistributed > 0) {
+        //                if (CollectionUtils.isNotEmpty(effectList)) {
+        //                    // 存在已经分配的实施工程师
+        //                    List<Long> supplierIdList = effectList.stream().map(CrmArchivesAllocationResult::getSupplierId)
+        //                            .distinct().collect(Collectors.toList());
+        //                    if (supplierIdList.size() == 1) {
+        //                        Long supplierId = supplierIdList.get(0);
+        //                        List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
+        //                                .filter(e -> supplierId.equals(e.getSupplierId()))
+        //                                .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
+        //                                .collect(Collectors.toList());
+        //                        if (CollectionUtils.isNotEmpty(coordinator)) {
+        //                            regionUserId = coordinator.get(0).getUserId();
+        //                        }
+        //                    }
+        //                } else {
+        //                    // 不存在实施工程师
+        //                    List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
+        //                            .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
+        //                            .collect(Collectors.toList());
+        //                    if (CollectionUtils.isNotEmpty(coordinator)) {
+        //                        regionUserId = coordinator.get(0).getUserId();
+        //                    }
+        //
+        //                }
+        //            }
+        //            UserArchivesAllocationParam userArchivesAllocationParam = new UserArchivesAllocationParam();
+        //            userArchivesAllocationParam.setAllocationParams(allocationParamList);
+        //            userArchivesAllocationParam.setServiceUnitId(serviceUnitId);
+        //            userArchivesAllocationParam.setCrmNo(crmNo);
+        //            userArchivesAllocationParam.setRegionUserId(regionUserId);
+        //            this.editCrmAllocation(userArchivesAllocationParam);
+        //        }
     }
 
     @Override

+ 7 - 1
sop-business/src/main/resources/db/log/caozixuan_update_log.sql

@@ -55,4 +55,10 @@ UPDATE sys_privilege SET name = '服务范围管理-划定派单和服务单元
 
 -- 2024-05-20
 ALTER TABLE t_b_user_archives_allocation
-    ADD COLUMN remark VARCHAR(45) NULL COMMENT '备注' AFTER archives_id;
+    ADD COLUMN remark VARCHAR(45) NULL COMMENT '备注' AFTER archives_id;
+
+ALTER TABLE t_b_user_archives_allocation
+    ADD COLUMN create_id BIGINT NULL COMMENT '创建人' AFTER remark,
+    ADD COLUMN create_time BIGINT NULL COMMENT '创建时间' AFTER create_id,
+    ADD COLUMN update_id BIGINT NULL COMMENT '更新人' AFTER create_time,
+    ADD COLUMN update_time BIGINT NULL COMMENT '更新时间' AFTER update_id;