Browse Source

add:资源保障

caozixuan 1 year ago
parent
commit
f3778ddbc5

+ 6 - 4
sop-api/src/main/java/com/qmth/sop/server/api/TBUserArchivesAllocationController.java

@@ -126,15 +126,17 @@ public class TBUserArchivesAllocationController {
     @RequestMapping(value = "/free_engineer", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = ArchivesSourceResult.class)})
     @OperationLog
-    public Result findFreeEngineer(@ApiParam(value = "工程师类型", required = true) @RequestParam RoleTypeEnum roleType) {
-        return ResultUtil.ok(tbUserArchivesService.findFreeEngineerSourceByType(roleType));
+    public Result findFreeEngineer(@ApiParam(value = "工程师类型", required = true) @RequestParam RoleTypeEnum roleType,
+                                   @ApiParam(value = "派单号") @RequestParam(required = false) String crmNo) {
+        return ResultUtil.ok(tbUserArchivesService.findFreeEngineerSourceByType(roleType, crmNo));
     }
 
     @ApiOperation(value = "人员调配管理-查询空闲区域协调人")
     @RequestMapping(value = "/free_coordinator", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = ArchivesSourceResult.class)})
     @OperationLog
-    public Result findFreeCoordinator(@ApiParam(value = "服务单元id", required = true) @RequestParam String serviceUnitId) {
-        return ResultUtil.ok(tbUserArchivesService.findFreeCoordinatorByServiceId(SystemConstant.convertIdToLong(serviceUnitId)));
+    public Result findFreeCoordinator(@ApiParam(value = "服务单元id", required = true) @RequestParam String serviceUnitId,
+                                      @ApiParam(value = "派单号") @RequestParam(required = false) String crmNo) {
+        return ResultUtil.ok(tbUserArchivesService.findFreeCoordinatorByServiceId(SystemConstant.convertIdToLong(serviceUnitId), crmNo));
     }
 }

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

@@ -31,7 +31,6 @@ import javax.annotation.Resource;
 import javax.validation.Valid;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
-import java.text.ParseException;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;

+ 0 - 1
sop-business/src/main/java/com/qmth/sop/business/bean/params/UserArchivesAllocationParam.java

@@ -17,7 +17,6 @@ import java.util.List;
  */
 public class UserArchivesAllocationParam {
     @ApiModelProperty("分配参数")
-    @NotEmpty(message = "缺少分配参数")
     private List<AllocationParam> allocationParams;
 
     @JsonSerialize(using = ToStringSerializer.class)

+ 11 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/UserArchivesResult.java

@@ -55,6 +55,9 @@ public class UserArchivesResult {
     @ApiModelProperty(value = "底照保存地址")
     private String basePhotoPath;
 
+    @ApiModelProperty(value = "底照预览地址")
+    private String basePhotoPreviewPath;
+
     @ApiModelProperty(value = "供应商id")
     @JsonSerialize(using = ToStringSerializer.class)
     private Long supplierId;
@@ -191,6 +194,14 @@ public class UserArchivesResult {
         this.basePhotoPath = basePhotoPath;
     }
 
+    public String getBasePhotoPreviewPath() {
+        return basePhotoPreviewPath;
+    }
+
+    public void setBasePhotoPreviewPath(String basePhotoPreviewPath) {
+        this.basePhotoPreviewPath = basePhotoPreviewPath;
+    }
+
     public Long getSupplierId() {
         return supplierId;
     }

+ 2 - 6
sop-business/src/main/java/com/qmth/sop/business/mapper/TBDeviceInOutMapper.java

@@ -92,13 +92,11 @@ public interface TBDeviceInOutMapper extends BaseMapper<TBDeviceInOut> {
      * @param supplierId 供应商id
      * @param status     设备状态 -- 正常
      * @param inOutType  设备最后一次出入库记录状态 -- 入库
-     * @param dpr        数据权限
      * @return 可出库设备信息
      */
     List<DeviceInOutResult> findDeviceCanOutInfo(@Param("supplierId") Long supplierId,
                                                  @Param("status") DeviceStatusEnum status,
-                                                 @Param("inOutType") InOutTypeEnum inOutType,
-                                                 @Param("dpr") DataPermissionDto dpr);
+                                                 @Param("inOutType") InOutTypeEnum inOutType);
 
 
     /**
@@ -107,11 +105,9 @@ public interface TBDeviceInOutMapper extends BaseMapper<TBDeviceInOut> {
      * @param supplierId 供应商id
      * @param inOutType  设备最后一次出入库记录状态 -- 出库
      * @param crmNo      派单号
-     * @param dpr        数据权限
      * @return 可入库设备信息
      */
     List<DeviceInOutResult> findDeviceCanInInfo(@Param("supplierId") Long supplierId,
                                                 @Param("inOutType") InOutTypeEnum inOutType,
-                                                @Param("crmNo") String crmNo,
-                                                @Param("dpr") DataPermissionDto dpr);
+                                                @Param("crmNo") String crmNo);
 }

+ 3 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/TBUserArchivesAllocationMapper.java

@@ -8,6 +8,7 @@ import com.qmth.sop.business.bean.result.SysLogResult;
 import com.qmth.sop.business.bean.result.UserArchivesAllocationResult;
 import com.qmth.sop.business.entity.TBUserArchivesAllocation;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.sop.common.enums.CrmStatusEnum;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -53,6 +54,7 @@ public interface TBUserArchivesAllocationMapper extends BaseMapper<TBUserArchive
      * @param customName    客户名称
      * @param gap           差额
      * @param crmIdList     派单id集合
+     * @param crmStatus 派单状态枚举
      * @param dpr           数据权限
      * @return 查询结果
      */
@@ -63,6 +65,7 @@ public interface TBUserArchivesAllocationMapper extends BaseMapper<TBUserArchive
                                                                  @Param("customName") String customName,
                                                                  @Param("gap") Integer gap,
                                                                  @Param("crmIdList") List<Long> crmIdList,
+                                                                 @Param("crmStatus") CrmStatusEnum crmStatus,
                                                                  @Param("dpr") DataPermissionDto dpr);
 
     List<CrmArchivesAllocationResult> findAllocationByCrmNo(@Param("crmNo") String crmNo);

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

@@ -59,6 +59,16 @@ public interface TBUserArchivesMapper extends BaseMapper<TBUserArchives> {
      */
     List<ArchivesSourceResult> findArchivesSourceByType(@Param("roleType") RoleTypeEnum roleType);
 
+    /**
+     * 查询已用档案
+     *
+     * @param roleType 角色类型
+     * @param crmNo    派单号
+     * @return 派单已分配档案
+     */
+    List<ArchivesSourceResult> findArchivesUsed(@Param("roleType") RoleTypeEnum roleType,
+                                                @Param("crmNo") String crmNo);
+
 
     List<UserArchivesResult> findUserArchivesList(@Param("city") String city,
                                                   @Param("supplierId") Long supplierId,

+ 4 - 2
sop-business/src/main/java/com/qmth/sop/business/service/TBUserArchivesService.java

@@ -105,15 +105,17 @@ public interface TBUserArchivesService extends IService<TBUserArchives> {
      * 查询空闲的工程师档案资源
      *
      * @param roleType 角色类型
+     * @param crmNo    派单号(调配选人列表的特殊查询)
      * @return 档案资源
      */
-    List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType);
+    List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType, String crmNo);
 
     /**
      * 根据服务单元id查询可用的区域负责人
      *
      * @param serviceUnitId 服务单元id
+     * @param crmNo         派单号(调配选人列表的特殊查询)
      * @return 区域负责人
      */
-    List<ArchivesSourceResult> findFreeCoordinatorByServiceId(Long serviceUnitId);
+    List<ArchivesSourceResult> findFreeCoordinatorByServiceId(Long serviceUnitId, String crmNo);
 }

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

@@ -61,6 +61,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         try {
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
             if (Objects.isNull(sysDevice.getId())) {// 新增
+                sysDevice.setBound(InOutTypeEnum.IN);
                 sysDevice.insertInfo(sysUser.getId());
             } else { // 修改
                 sysDevice.updateInfo(sysUser.getId());

+ 2 - 6
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBDeviceInOutServiceImpl.java

@@ -61,16 +61,12 @@ public class TBDeviceInOutServiceImpl extends ServiceImpl<TBDeviceInOutMapper, T
 
     @Override
     public List<DeviceInOutResult> findDeviceCanOutInfo(Long supplierId) {
-        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-        return this.baseMapper.findDeviceCanOutInfo(supplierId, DeviceStatusEnum.NORMAL, InOutTypeEnum.IN, dpr);
+        return this.baseMapper.findDeviceCanOutInfo(supplierId, DeviceStatusEnum.NORMAL, InOutTypeEnum.IN);
     }
 
     @Override
     public List<DeviceInOutResult> findDeviceCanInInfo(Long supplierId, String crmNo) {
-        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-        return this.baseMapper.findDeviceCanInInfo(supplierId, InOutTypeEnum.OUT, crmNo, dpr);
+        return this.baseMapper.findDeviceCanInInfo(supplierId, InOutTypeEnum.OUT, crmNo);
     }
 
 

+ 41 - 19
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesAllocationServiceImpl.java

@@ -1,6 +1,7 @@
 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;
@@ -79,7 +80,7 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
         city = SystemConstant.translateSpecificSign(city);
         area = SystemConstant.translateSpecificSign(area);
         customName = SystemConstant.translateSpecificSign(customName);
-        List<UserArchivesAllocationResult> list = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, province, city, area, customName, gap, null, dpr);
+        List<UserArchivesAllocationResult> list = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, province, city, area, customName, gap, null, null, dpr);
         Integer publishedCrmCount = Math.toIntExact(list.stream().filter(e -> CrmStatusEnum.PUBLISH.equals(e.getCrmStatus())).count());
         Integer totalCrmCount = list.size();
 
@@ -166,11 +167,10 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
                         if (Objects.isNull(occupiedCrm)) {
                             throw ExceptionResultEnum.ERROR.exception("人员占用状态异常");
                         }
-                        throw ExceptionResultEnum.ERROR.exception(String.format("该工程师已经被派单号为[%s],名称为[%s],状态为[%s]的派单占用,请先将工程师从派单中移出", occupiedCrm.getCrmNo(), occupiedCrm.getName(), occupiedCrm.getStatus()));
+                        if (!crmNo.equals(occupiedCrm.getCrmNo())) {
+                            throw ExceptionResultEnum.ERROR.exception(String.format("工程师[%s]已经被派单号为[%s],名称为[%s],状态为[%s]的派单占用,请先将工程师从派单中移出", tbUserArchives.getName(), occupiedCrm.getCrmNo(), occupiedCrm.getName(), occupiedCrm.getStatus()));
+                        }
                     }
-                    tbUserArchives.setStatus(UserArchivesStatusEnum.OCCUPIED);
-                    tbUserArchivesService.updateById(tbUserArchives);
-
                     TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
                     tbUserArchivesAllocation.setCrmNo(crmNo);
                     tbUserArchivesAllocation.setArchivesId(tbUserArchives.getId());
@@ -189,12 +189,31 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
             tbCrmService.updateById(tbCrm);
         }
 
-        // 如果存在要分配的记录则根据crm单号删除原先数据并新增
+
+        // 新增前删除派单关系
+        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()));
+        }
+
+
         if (CollectionUtils.isNotEmpty(tbUserArchivesAllocationList)) {
-            // 新增前删除派单关系
-            if (CollectionUtils.isNotEmpty(dbList)) {
-                this.removeByIds(dbList);
-            }
+            // 新增前先将工程师的状态设置为非空闲
+            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);
         }
@@ -228,7 +247,7 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
     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, null);
+        List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, null, null, crmIdList, CrmStatusEnum.UN_PUBLISH, null);
         // crm按照差额倒序
         crmSourceList = crmSourceList.stream().filter(e -> e.getUnDistributed() > 0)
                 .sorted(Comparator.comparing(UserArchivesAllocationResult::getUnDistributed).reversed())
@@ -267,17 +286,17 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
                     .collect(Collectors.toList());
 
             // 可分配的人力资源
-            List<ArchivesSourceResult> effectFree = tbUserArchivesService.findFreeEngineerSourceByType(RoleTypeEnum.EFFECT_ENGINEER)
+            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)
+            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)
+            List<ArchivesSourceResult> coordinatorFree = tbUserArchivesService.findFreeCoordinatorByServiceId(serviceUnitId, null)
                     .stream()
                     .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
                     .collect(Collectors.toList());
@@ -307,13 +326,15 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
                     supplierMap = SystemConstant.sortMapByValues(supplierMap);
                     for (Long supplierId : supplierMap.keySet()) {
                         Integer count = supplierMap.get(supplierId);
-                        effectUnDistributed = effectUnDistributed - count;
+                        int effectDivide = effectUnDistributed - count;
                         List<ArchivesSourceResult> cell;
-                        if (effectUnDistributed > 0) {
+                        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());
@@ -337,13 +358,14 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
                 supplierMap = SystemConstant.sortMapByValues(supplierMap);
                 for (Long supplierId : supplierMap.keySet()) {
                     Integer count = supplierMap.get(supplierId);
-                    assistantUnDistributed = assistantUnDistributed - count;
+                    int assistantDivide = assistantUnDistributed - count;
                     List<ArchivesSourceResult> cell;
-                    if (assistantUnDistributed > 0) {
+                    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());
@@ -407,7 +429,7 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
         Long crmId = tbCrm.getId();
         List<Long> crmIdList = new ArrayList<>();
         crmIdList.add(crmId);
-        List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, null, null, crmIdList, null);
+        List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, null, null, crmIdList, null, null);
         if (CollectionUtils.isEmpty(crmSourceList)) {
             throw ExceptionResultEnum.ERROR.exception("未找到派单信息");
         } else if (crmSourceList.size() > 1) {

+ 30 - 7
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesServiceImpl.java

@@ -49,6 +49,8 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
     private SysRoleService sysRoleService;
     @Resource
     private BasicAttachmentService basicAttachmentService;
+    @Resource
+    private TBUserArchivesService tbUserArchivesService;
 
     @Override
     public IPage<UserArchivesResult> findUserArchivesPage(String city, Long supplierId, String archivesName, RoleTypeEnum roleType, Boolean authenticationStatus, Long archivesTimeStart, Long archivesTimeEnd, Integer remainValidDay, Integer pageNumber, Integer pageSize) throws Exception {
@@ -87,7 +89,7 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
             record.setRoleInfoList(roleResultList);
             record.setAge(this.getAgeByIdentity(record.getIdentity()));
             record.setAuthenticationStatus(record.getAuthenticationValidTime() != null && record.getAuthenticationValidTime() > currentTime);
-            record.setBasePhotoPath(basicAttachmentService.filePreviewPath(record.getBasePhotoPath()));
+            record.setBasePhotoPreviewPath(basicAttachmentService.filePreviewPath(record.getBasePhotoPath()));
         }
         return page;
     }
@@ -404,12 +406,17 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
     }
 
     @Override
-    public List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType) {
+    public List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType, String crmNo) {
         if (!RoleTypeEnum.EFFECT_ENGINEER.equals(roleType) && !RoleTypeEnum.ASSISTANT_ENGINEER.equals(roleType)) {
             throw ExceptionResultEnum.ERROR.exception("该方法只支持查询实施工程师和助理工程师");
         }
+        List<ArchivesSourceResult> list = new ArrayList<>();
+        if (crmNo != null && crmNo.length() > 0) {
+            list.addAll(this.baseMapper.findArchivesUsed(roleType, crmNo));
+        }
+        list.addAll(this.baseMapper.findArchivesSourceByType(roleType));
+
         Long currentTime = System.currentTimeMillis();
-        List<ArchivesSourceResult> list = this.baseMapper.findArchivesSourceByType(roleType);
         list = list.stream()
                 .filter(e -> e.getAuthenticationValidTime() >= currentTime && UserArchivesStatusEnum.FREE.equals(e.getArchivesStatus()))
                 .peek(e -> e.setRemainCount(1))
@@ -418,16 +425,14 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
     }
 
     @Override
-    public List<ArchivesSourceResult> findFreeCoordinatorByServiceId(Long serviceUnitId) {
+    public List<ArchivesSourceResult> findFreeCoordinatorByServiceId(Long serviceUnitId, String crmNo) {
         TBService tbService = tbServiceService.getById(serviceUnitId);
         if (Objects.isNull(tbService)) {
             throw ExceptionResultEnum.ERROR.exception("服务单元不存在");
         }
         int rate = tbService.getRegionProjectCount() / tbService.getRegionPeopleCount();
-
         List<TBCrm> tbCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getServiceId, serviceUnitId));
 
-
         Long currentTime = System.currentTimeMillis();
         List<ArchivesSourceResult> list = this.baseMapper.findArchivesSourceByType(RoleTypeEnum.REGION_COORDINATOR);
         list = list.stream()
@@ -438,6 +443,24 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
                     e.setRemainCount(rate - count);
                 })
                 .collect(Collectors.toList());
-        return list.stream().filter(e -> e.getRemainCount() > 0).collect(Collectors.toList());
+
+        list = list.stream().filter(e -> e.getRemainCount() > 0).collect(Collectors.toList());
+
+        // 调配选人列表查询的特殊处理
+        if (crmNo != null && crmNo.length() > 0) {
+            List<TBCrm> temp = tbCrmList.stream().filter(e -> e.getCrmNo().equals(crmNo)).collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(temp)) {
+                throw ExceptionResultEnum.ERROR.exception(String.format("派单号[%s]不存在在服务单元[%s]下", crmNo, tbService.getName()));
+            }
+            TBCrm chooseCrm = temp.get(0);
+            Long coordinatorId = chooseCrm.getRegionCoordinatorId();
+            TBUserArchives chooseArchives = tbUserArchivesService.findByUserId(coordinatorId);
+            ArchivesSourceResult choose = new ArchivesSourceResult();
+            choose.setArchivesId(chooseArchives.getId());
+            choose.setUserId(coordinatorId);
+            choose.setName(chooseArchives.getName());
+            list.add(choose);
+        }
+        return list;
     }
 }

+ 5 - 2
sop-business/src/main/resources/mapper/TBUserArchivesAllocationMapper.xml

@@ -6,7 +6,7 @@
             resultType="com.qmth.sop.business.bean.result.UserArchivesAllocationResult">
         SELECT
             *,
-            (result.effectQuota + result.assistantQuota + result.coordinatorDistributed) AS quota,
+            (result.effectQuota + result.assistantQuota + result.coordinatorQuota) AS quota,
             (result.coordinatorUnDistributed + result.effectUnDistributed + result.assistantUnDistributed) AS unDistributed
         FROM
             (SELECT
@@ -109,7 +109,7 @@
             resultType="com.qmth.sop.business.bean.result.UserArchivesAllocationResult">
         SELECT
             *,
-            (result.effectQuota + result.assistantQuota + result.coordinatorDistributed) AS quota,
+            (result.effectQuota + result.assistantQuota + result.coordinatorQuota) AS quota,
             (result.coordinatorUnDistributed + result.effectUnDistributed + result.assistantUnDistributed) AS unDistributed
         FROM
             (SELECT
@@ -201,6 +201,9 @@
                 </foreach>
                 )
             </if>
+            <if test="crmStatus != null">
+                AND result.crmStatus = #{crmStatus}
+            </if>
             <if test="dpr != null and !dpr.hasAdmin and !dpr.hasPmo">
                 <choose>
                     <when test="dpr.hasBusiness">

+ 44 - 0
sop-business/src/main/resources/mapper/TBUserArchivesMapper.xml

@@ -225,6 +225,49 @@
             </if>
         </where>
     </select>
+
+    <select id="findArchivesUsed" resultType="com.qmth.sop.business.bean.result.ArchivesSourceResult">
+        SELECT
+            tbua.id AS archivesId,
+            su.id AS userId,
+            tbua.name AS name,
+            tbua.province AS province,
+            tbua.city AS city,
+            tbua.gender AS gender,
+            ss.id AS supplierId,
+            ss.name AS supplierName,
+            tbua.status AS archivesStatus,
+            tbuas.authentication_valid_time AS authenticationValidTime
+        FROM
+            t_b_user_archives tbua
+                LEFT JOIN
+            t_b_user_archives_supplier tbuas ON tbua.id = tbuas.user_archives_id
+                LEFT JOIN
+            sys_supplier ss ON tbuas.supplier_id = ss.id
+                LEFT JOIN
+            sys_user su ON tbua.mobile_number = su.mobile_number
+        <where>
+            <if test="roleType != null">
+                AND EXISTS( SELECT
+                    1
+                FROM
+                    sys_user_role sur
+                LEFT JOIN
+                    sys_role sr ON sur.role_id = sr.id
+                WHERE
+                    sur.user_id = su.id AND sr.type = #{roleType})
+            </if>
+            <if test="crmNo != null and crmNo != ''">
+                AND EXISTS( SELECT
+                    1
+                FROM
+                    t_b_user_archives_allocation tbuaa
+                WHERE
+                    tbuaa.archives_id = tbua.id AND tbuaa.crm_no = #{crmNo})
+            </if>
+        </where>
+    </select>
+
     <select id="findUserArchivesList" resultType="com.qmth.sop.business.bean.result.UserArchivesResult">
         SELECT
             tbua.id AS userArchivesId,
@@ -296,4 +339,5 @@
             </if>
         </where>
     </select>
+
 </mapper>