Browse Source

add:档案分配

caozixuan 1 năm trước cách đây
mục cha
commit
7c51f8dc16

+ 2 - 2
sop-business/src/main/java/com/qmth/sop/business/bean/dto/UserArchivesImportDto.java

@@ -83,8 +83,8 @@ public class UserArchivesImportDto extends BasicExcelRow implements Serializable
     private Double authenticationScore;
 
     @ExcelProperty(value = "认证有效期")
-    @NotBlank(message = "请选择入档时间")
-    @NotNull(message = "请选择入档时间")
+    @NotBlank(message = "请选择认证有效期")
+    @NotNull(message = "请选择认证有效期")
     private String authenticationValidTimeStr;
 
     @ExcelProperty(value = "备注")

+ 127 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/ArchivesSourceResult.java

@@ -0,0 +1,127 @@
+package com.qmth.sop.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.enums.GenderEnum;
+import com.qmth.sop.common.enums.UserArchivesStatusEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 人力资源查询结果
+ * @Author: CaoZixuan
+ * @Date: 2023-08-18
+ */
+public class ArchivesSourceResult {
+    @ApiModelProperty(value = "档案id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long archivesId;
+
+    @ApiModelProperty(value = "用户id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long userId;
+
+    @ApiModelProperty(value = "姓名")
+    private String name;
+
+    @ApiModelProperty(value = "省")
+    private String province;
+
+    @ApiModelProperty(value = "市")
+    private String city;
+
+    @ApiModelProperty(value = "性别")
+    private GenderEnum gender;
+
+    @ApiModelProperty(value = "资源状态")
+    private UserArchivesStatusEnum archivesStatus;
+
+    @ApiModelProperty(value = "供应商id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long supplierId;
+
+    @ApiModelProperty(value = "供应商名称")
+    private String supplierName;
+
+    @ApiModelProperty(value = "验证有效期")
+    private Long authenticationValidTime;
+
+    public Long getArchivesId() {
+        return archivesId;
+    }
+
+    public void setArchivesId(Long archivesId) {
+        this.archivesId = archivesId;
+    }
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    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 GenderEnum getGender() {
+        return gender;
+    }
+
+    public void setGender(GenderEnum gender) {
+        this.gender = gender;
+    }
+
+    public UserArchivesStatusEnum getArchivesStatus() {
+        return archivesStatus;
+    }
+
+    public void setArchivesStatus(UserArchivesStatusEnum archivesStatus) {
+        this.archivesStatus = archivesStatus;
+    }
+
+    public Long getSupplierId() {
+        return supplierId;
+    }
+
+    public void setSupplierId(Long supplierId) {
+        this.supplierId = supplierId;
+    }
+
+    public String getSupplierName() {
+        return supplierName;
+    }
+
+    public void setSupplierName(String supplierName) {
+        this.supplierName = supplierName;
+    }
+
+    public Long getAuthenticationValidTime() {
+        return authenticationValidTime;
+    }
+
+    public void setAuthenticationValidTime(Long authenticationValidTime) {
+        this.authenticationValidTime = authenticationValidTime;
+    }
+}

+ 112 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/CrmArchivesAllocationResult.java

@@ -0,0 +1,112 @@
+package com.qmth.sop.business.bean.result;
+
+import com.qmth.sop.common.enums.RoleTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.List;
+
+/**
+ * @Description: crm派单档案配给信息
+ * @Author: CaoZixuan
+ * @Date: 2023-08-18
+ */
+public class CrmArchivesAllocationResult {
+    @ApiModelProperty("分配角色类型")
+    private RoleTypeEnum type;
+
+    @ApiModelProperty("档案id")
+    private Long archivesId;
+
+    @ApiModelProperty("档案名称")
+    private String archiverName;
+
+    @ApiModelProperty("供应商id")
+    private Long supplierId;
+
+    @ApiModelProperty("供应商名称")
+    private String supplierName;
+
+    @ApiModelProperty("档案人省")
+    private String archivesProvince;
+
+    @ApiModelProperty("档案人市")
+    private String archivesCity;
+
+    @ApiModelProperty("用户id")
+    private Long userId;
+
+    @ApiModelProperty("该用户认证的所有角色")
+    private List<RoleTypeEnum> authRoles;
+
+    public RoleTypeEnum getType() {
+        return type;
+    }
+
+    public void setType(RoleTypeEnum type) {
+        this.type = type;
+    }
+
+    public Long getArchivesId() {
+        return archivesId;
+    }
+
+    public void setArchivesId(Long archivesId) {
+        this.archivesId = archivesId;
+    }
+
+    public String getArchiverName() {
+        return archiverName;
+    }
+
+    public void setArchiverName(String archiverName) {
+        this.archiverName = archiverName;
+    }
+
+    public Long getSupplierId() {
+        return supplierId;
+    }
+
+    public void setSupplierId(Long supplierId) {
+        this.supplierId = supplierId;
+    }
+
+    public String getSupplierName() {
+        return supplierName;
+    }
+
+    public void setSupplierName(String supplierName) {
+        this.supplierName = supplierName;
+    }
+
+    public String getArchivesProvince() {
+        return archivesProvince;
+    }
+
+    public void setArchivesProvince(String archivesProvince) {
+        this.archivesProvince = archivesProvince;
+    }
+
+    public String getArchivesCity() {
+        return archivesCity;
+    }
+
+    public void setArchivesCity(String archivesCity) {
+        this.archivesCity = archivesCity;
+    }
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    public List<RoleTypeEnum> getAuthRoles() {
+        return authRoles;
+    }
+
+    public void setAuthRoles(List<RoleTypeEnum> authRoles) {
+        this.authRoles = authRoles;
+    }
+}

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

@@ -2,6 +2,7 @@ package com.qmth.sop.business.mapper;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.sop.business.bean.result.CrmArchivesAllocationResult;
 import com.qmth.sop.business.bean.result.SysLogResult;
 import com.qmth.sop.business.bean.result.UserArchivesAllocationResult;
 import com.qmth.sop.business.entity.TBUserArchivesAllocation;
@@ -56,4 +57,6 @@ public interface TBUserArchivesAllocationMapper extends BaseMapper<TBUserArchive
                                                                  @Param("area") String area,
                                                                  @Param("customName") String customName,
                                                                  @Param("gap") Integer gap);
+
+    List<CrmArchivesAllocationResult> findAllocationByCrmNo(@Param("crmNo") String crmNo);
 }

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

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.sop.business.bean.dto.UserArchivesImportDto;
+import com.qmth.sop.business.bean.result.ArchivesSourceResult;
 import com.qmth.sop.business.bean.result.UserArchivesResult;
 import com.qmth.sop.business.entity.TBUserArchives;
 import com.qmth.sop.common.enums.RoleTypeEnum;
@@ -41,6 +42,23 @@ public interface TBUserArchivesMapper extends BaseMapper<TBUserArchives> {
                                                @Param("remainValidTime") Long remainValidTime,
                                                @Param("currentTime") Long currentTime);
 
+    /**
+     * 根据用户id或档案id查询档案详情
+     *
+     * @param archivesId 档案id
+     * @param userId     用户id
+     * @return 档案详情
+     */
+    List<UserArchivesResult> findUserArchivesById(@Param("archivesId") Long archivesId, @Param("userId") Long userId);
+
+    /**
+     * 根据角色类型查询该角色的档案资源
+     *
+     * @param roleType 角色类型
+     * @return 档案资源
+     */
+    List<ArchivesSourceResult> findArchivesSourceByType(@Param("roleType") RoleTypeEnum roleType);
+
     /**
      * 档案小计
      *

+ 7 - 6
sop-business/src/main/java/com/qmth/sop/business/service/TBCrmService.java

@@ -60,12 +60,6 @@ public interface TBCrmService extends IService<TBCrm> {
      */
     List<CrmServiceResult> findCrmOrderByServiceIdList(List<Long> serviceIdList);
 
-    /**
-     * 服务范围管理 - 批量划定派单和服务单元关系
-     *
-     * @param crmIdList     派单id集合
-     * @param serviceUnitId 服务单元id
-     */
     /**
      * 服务范围管理 - 批量划定派单和服务单元关系
      *
@@ -87,6 +81,13 @@ public interface TBCrmService extends IService<TBCrm> {
      */
     CrmSubTotalResult findCrmSubTotalData();
 
+    /**
+     * 根据编号查询crm
+     * @param crmNo crm单号
+     * @return crm
+     */
+    TBCrm findByCrmNo(String crmNo);
+
 
 
     /**

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

@@ -1,11 +1,14 @@
 package com.qmth.sop.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.params.UserArchivesAllocationParam;
+import com.qmth.sop.business.bean.result.CrmArchivesAllocationResult;
 import com.qmth.sop.business.bean.result.UserArchivesAllocationResult;
 import com.qmth.sop.business.bean.result.UserArchivesAllocationSubTotalResult;
 import com.qmth.sop.business.entity.TBUserArchivesAllocation;
-import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
 
 /**
  * <p>
@@ -52,6 +55,15 @@ public interface TBUserArchivesAllocationService extends IService<TBUserArchives
      */
     void editCrmAllocation(UserArchivesAllocationParam userArchivesAllocationParam);
 
+
+    /**
+     * 根据派单号查询派单分配信息
+     *
+     * @param crmNo 派单号
+     * @return 分配信息
+     */
+    List<CrmArchivesAllocationResult> findAllocationByCrmNo(String crmNo);
+
     /**
      * 自动批量调配派单和人员
      *

+ 26 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBUserArchivesService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.dto.UserArchivesImportDto;
 import com.qmth.sop.business.bean.params.UserArchivesParam;
+import com.qmth.sop.business.bean.result.ArchivesSourceResult;
 import com.qmth.sop.business.bean.result.UserArchivesResult;
 import com.qmth.sop.business.bean.result.UserArchivesSubTotalResult;
 import com.qmth.sop.business.entity.SysUser;
@@ -72,4 +73,29 @@ public interface TBUserArchivesService extends IService<TBUserArchives> {
      */
     List<UserArchivesImportDto> findExportData(String city, Long supplierId, String archivesName, RoleTypeEnum roleType, Boolean authenticationStatus,
                                                Long archivesTimeStart, Long archivesTimeEnd, Integer remainValidDay);
+
+    /**
+     * 根据用户id查询档案信息
+     *
+     * @param userId 用户id
+     * @return 档案
+     */
+    TBUserArchives findByUserId(Long userId);
+
+    /**
+     * 根据用户id或档案id查询档案详情
+     *
+     * @param archivesId 档案id
+     * @param userId     用户id
+     * @return 档案详情
+     */
+    UserArchivesResult findUserArchivesByArchivesIdORUserId(Long archivesId, Long userId);
+
+    /**
+     * 查询空闲的工程师档案资源
+     *
+     * @param roleType 角色类型
+     * @return 档案资源
+     */
+    List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType);
 }

+ 12 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBCrmServiceImpl.java

@@ -132,6 +132,18 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
         return crmSubTotalResult;
     }
 
+    @Override
+    public TBCrm findByCrmNo(String crmNo) {
+        List<TBCrm> tbCrmList = this.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getCrmNo, crmNo));
+        if (CollectionUtils.isEmpty(tbCrmList)) {
+            throw ExceptionResultEnum.ERROR.exception("派单不存在[" + crmNo + "]");
+        }
+        if (tbCrmList.size() > 1) {
+            throw ExceptionResultEnum.ERROR.exception("有重复派单号[" + crmNo + "]");
+        }
+        return tbCrmList.get(0);
+    }
+
     @Override
     public IPage<TBCrmResult> query(IPage<Map> iPage, Long serviceId, Long leadId, Long crmUserId, ProductTypeEnum type, String custom, String crmNo, Long startTime, Long endTime) {
         return this.baseMapper.query(iPage ,serviceId,leadId,crmUserId,Objects.nonNull(type)?type.name():null,custom,crmNo,startTime,endTime);

+ 95 - 14
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesAllocationServiceImpl.java

@@ -6,24 +6,25 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.bean.params.AllocationParam;
 import com.qmth.sop.business.bean.params.UserArchivesAllocationParam;
+import com.qmth.sop.business.bean.result.CrmArchivesAllocationResult;
 import com.qmth.sop.business.bean.result.UserArchivesAllocationResult;
 import com.qmth.sop.business.bean.result.UserArchivesAllocationSubTotalResult;
-import com.qmth.sop.business.entity.SysRole;
-import com.qmth.sop.business.entity.TBCrm;
-import com.qmth.sop.business.entity.TBService;
-import com.qmth.sop.business.entity.TBUserArchivesAllocation;
+import com.qmth.sop.business.bean.result.UserArchivesResult;
+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.ExceptionResultEnum;
 import com.qmth.sop.common.enums.RoleTypeEnum;
+import com.qmth.sop.common.enums.UserArchivesStatusEnum;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -46,6 +47,8 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
     private SysRoleService sysRoleService;
     @Resource
     private SysUserRoleService sysUserRoleService;
+    @Resource
+    private TBUserArchivesService tbUserArchivesService;
 
     @Override
     public IPage<UserArchivesAllocationResult> findCrmAllocationPage(Long serviceUnitId, String province, String city, String area, String customName, Integer gap, Integer pageNumber, Integer pageSize) {
@@ -106,6 +109,8 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
         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));
@@ -141,8 +146,16 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
                     if (!sysRoleIdList.contains(roleId)) {
                         throw ExceptionResultEnum.ERROR.exception("所选用户不包含认证角色[" + role.getType().getDesc() + "]");
                     }
+                    TBUserArchives tbUserArchives = tbUserArchivesService.findByUserId(userId);
+                    if (UserArchivesStatusEnum.FREE.equals(tbUserArchives.getStatus())) {
+                        throw ExceptionResultEnum.ERROR.exception("不能分配非空闲状态的用户");
+                    }
+                    tbUserArchives.setStatus(UserArchivesStatusEnum.NON_EXECUTION_SOP);
+                    tbUserArchivesService.updateById(tbUserArchives);
+
                     TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
                     tbUserArchivesAllocation.setCrmNo(crmNo);
+                    tbUserArchivesAllocation.setArchivesId(tbUserArchives.getId());
                     tbUserArchivesAllocation.setServiceId(serviceUnitId);
                     tbUserArchivesAllocation.setUserId(userId);
                     tbUserArchivesAllocation.setRoleId(roleId);
@@ -152,15 +165,10 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
             }
         }
 
-        // 如果实施和助理工程师都不存在,但是区域负责人存在,也新增一条记录
-        if (CollectionUtils.isEmpty(tbUserArchivesAllocationList)) {
-            if (regionUserId != null && regionUserId > 0) {
-                TBUserArchivesAllocation tbUserArchivesAllocation = new TBUserArchivesAllocation();
-                tbUserArchivesAllocation.setCrmNo(crmNo);
-                tbUserArchivesAllocation.setServiceId(serviceUnitId);
-                tbUserArchivesAllocation.setRegionUserId(regionUserId);
-                tbUserArchivesAllocationList.add(tbUserArchivesAllocation);
-            }
+        // 更新区域负责人
+        if (regionUserId != null && regionUserId > 0) {
+            tbCrm.setRegionCoordinatorId(regionUserId);
+            tbCrmService.updateById(tbCrm);
         }
 
         // 如果存在要分配的记录则根据crm单号删除原先数据并新增
@@ -174,8 +182,81 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
         }
     }
 
+    @Override
+    public List<CrmArchivesAllocationResult> findAllocationByCrmNo(String crmNo) {
+        List<CrmArchivesAllocationResult> list = this.baseMapper.findAllocationByCrmNo(crmNo);
+        TBCrm tbCrm = tbCrmService.findByCrmNo(crmNo);
+        Long regionCoordinatorId = tbCrm.getRegionCoordinatorId();
+
+        if (regionCoordinatorId != null && regionCoordinatorId > 0) {
+
+            UserArchivesResult userArchivesResult = tbUserArchivesService.findUserArchivesByArchivesIdORUserId(null, regionCoordinatorId);
+            CrmArchivesAllocationResult region = new CrmArchivesAllocationResult();
+            region.setType(RoleTypeEnum.REGION_COORDINATOR);
+            region.setArchivesId(userArchivesResult.getUserArchivesId());
+            region.setArchiverName(userArchivesResult.getName());
+            region.setSupplierId(userArchivesResult.getSupplierId());
+            region.setSupplierName(userArchivesResult.getSupplierName());
+            region.setArchivesProvince(userArchivesResult.getProvince());
+            region.setArchivesCity(userArchivesResult.getCity());
+            region.setUserId(userArchivesResult.getUserId());
+            list.add(region);
+        }
+        return list;
+    }
+
     @Transactional
     @Override
     public void autoEditCrmAllocationBatch(Long serviceUnitId) {
+        List<UserArchivesAllocationResult> crmSourceList = this.baseMapper.findCrmAllocationSubTotal(serviceUnitId, null, null, null, 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();
+
+            // 区域协调人差额
+            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());
+
+            // 先分实施工程师
+            if (effectUnDistributed > 0) {
+                // 如果存在区域协调人,则要分配的实施工程师必须跟区域协调人处于相同的供应商
+                if (CollectionUtils.isNotEmpty(coordinatorList)){
+                    CrmArchivesAllocationResult coordinator = coordinatorList.get(0);
+                    Long supplierId = coordinator.getSupplierId();
+
+                }
+            }
+
+        }
+
     }
-}
+}

+ 45 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.bean.dto.UserArchivesImportDto;
 import com.qmth.sop.business.bean.params.UserArchivesParam;
+import com.qmth.sop.business.bean.result.ArchivesSourceResult;
 import com.qmth.sop.business.bean.result.UserArchivesResult;
 import com.qmth.sop.business.bean.result.UserArchivesSubTotalResult;
 import com.qmth.sop.business.entity.SysSupplier;
@@ -161,6 +162,7 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
         Long userId = null;
         if (id == null || id == 0) {
             // 新增
+            tbUserArchives.setStatus(UserArchivesStatusEnum.FREE);
             tbUserArchives.setCreateId(requestUser.getId());
             this.save(tbUserArchives);
             id = tbUserArchives.getId();
@@ -316,4 +318,47 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
         }
         return userArchivesImportDtoList;
     }
+
+    @Override
+    public TBUserArchives findByUserId(Long userId) {
+        SysUser sysUser = sysUserService.getById(userId);
+        if (Objects.isNull(sysUser)) {
+            throw ExceptionResultEnum.ERROR.exception("用户不存在");
+        }
+        String mobileNumber = sysUser.getMobileNumber();
+
+        List<TBUserArchives> tbUserArchivesList = this.list(new QueryWrapper<TBUserArchives>().lambda().eq(TBUserArchives::getMobileNumber, mobileNumber));
+        if (CollectionUtils.isEmpty(tbUserArchivesList)) {
+            throw ExceptionResultEnum.ERROR.exception("不存在档案");
+        }
+        if (tbUserArchivesList.size() > 1) {
+            throw ExceptionResultEnum.ERROR.exception("存在多个相同手机号的档案异常[" + mobileNumber + "]");
+        }
+        return tbUserArchivesList.get(0);
+    }
+
+    @Override
+    public UserArchivesResult findUserArchivesByArchivesIdORUserId(Long archivesId, Long userId) {
+        List<UserArchivesResult> result = this.baseMapper.findUserArchivesById(archivesId, userId);
+        if (CollectionUtils.isEmpty(result)) {
+            throw ExceptionResultEnum.ERROR.exception("档案信息不存在");
+        }
+        if (result.size() > 1) {
+            throw ExceptionResultEnum.ERROR.exception("档案数据异常");
+        }
+        return result.get(0);
+    }
+
+    @Override
+    public List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType) {
+        if (!RoleTypeEnum.EFFECT_ENGINEER.equals(roleType) && !RoleTypeEnum.ASSISTANT_ENGINEER.equals(roleType)){
+            throw ExceptionResultEnum.ERROR.exception("该方法只支持查询实施工程师和助理工程师");
+        }
+        Long currentTime = System.currentTimeMillis();
+        List<ArchivesSourceResult> list = this.baseMapper.findArchivesSourceByType(roleType);
+        list = list.stream()
+                .filter(e -> e.getAuthenticationValidTime() >= currentTime && UserArchivesStatusEnum.FREE.equals(e.getArchivesStatus()))
+                .collect(Collectors.toList());
+        return list;
+    }
 }

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

@@ -191,4 +191,34 @@
             </if>
         </where>
     </select>
+    <select id="findAllocationByCrmNo"
+            resultType="com.qmth.sop.business.bean.result.CrmArchivesAllocationResult">
+        SELECT
+            sr.type AS type,
+            tbua.id AS archivesId,
+            tbua.name AS archiverName,
+            tbuas.id AS supplierId,
+            ss.name AS supplierName,
+            tbua.province AS archivesProvince,
+            tbua.city AS archivesCity,
+            su.id AS userId
+        FROM
+            t_b_user_archives_allocation tbuaa
+                LEFT JOIN
+            sys_role sr ON tbuaa.role_id = sr.id
+                LEFT JOIN
+            t_b_user_archives tbua ON tbuaa.archives_id = tbua.id
+                LEFT JOIN
+            t_b_user_archives_supplier tbuas ON tbuas.user_archives_id = tbua.id
+                LEFT JOIN
+            sys_supplier ss ON ss.id = tbuas.supplier_id
+                LEFT JOIN
+            sys_user su ON su.mobile_number = tbua.mobile_number
+        <where>
+            <if test="crmNo != null and crmNo != ''">
+                AND tbuaa.crm_no = #{crmNo}
+            </if>
+        </where>
+        ORDER BY sr.type
+    </select>
 </mapper>

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

@@ -152,4 +152,74 @@
             </if>
         </where>
     </select>
+    <select id="findUserArchivesById" resultType="com.qmth.sop.business.bean.result.UserArchivesResult">
+        SELECT
+            tbua.id AS userArchivesId,
+            tbua.code,
+            tbua.name,
+            tbua.province,
+            tbua.city,
+            tbua.area,
+            tbua.identity,
+            tbua.gender,
+            education,
+            tbua.mobile_number AS mobileNumber,
+            tbua.email,
+            base_photo_path AS basePhotoPath,
+            tbuas.supplier_id AS supplierId,
+            ss.name AS supplierName,
+            tbuas.archives_time AS archivesTime,
+            tbuas.authentication_score AS authenticationScore,
+            tbuas.authentication_valid_time AS authenticationValidTime,
+            tbuas.remark,
+            su.id AS userId
+        FROM
+            t_b_user_archives tbua
+                LEFT JOIN
+            t_b_user_archives_supplier tbuas ON tbua.id = tbuas.supplier_id
+                LEFT JOIN
+            sys_supplier ss ON ss.id = tbuas.supplier_id
+                LEFT JOIN
+            sys_user su ON su.mobile_number = tbua.mobile_number
+        <where>
+            <if test="userId != null">
+                AND su.id = #{userId}
+            </if>
+            <if test="archivesId != null">
+                AND tbua.id = #{archivesId}
+            </if>
+        </where>
+    </select>
+
+    <select id="findArchivesSourceByType" 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 suplierId,
+            ss.name AS suplierName
+        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>
+        </where>
+    </select>
 </mapper>