caozixuan 1 рік тому
батько
коміт
7df92657c9

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

@@ -45,6 +45,9 @@ public class ArchivesSourceResult {
     @ApiModelProperty(value = "验证有效期")
     private Long authenticationValidTime;
 
+    @ApiModelProperty(value = "剩余可用")
+    private Integer remainCount;
+
     public Long getArchivesId() {
         return archivesId;
     }
@@ -124,4 +127,12 @@ public class ArchivesSourceResult {
     public void setAuthenticationValidTime(Long authenticationValidTime) {
         this.authenticationValidTime = authenticationValidTime;
     }
+
+    public Integer getRemainCount() {
+        return remainCount;
+    }
+
+    public void setRemainCount(Integer remainCount) {
+        this.remainCount = remainCount;
+    }
 }

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

@@ -98,4 +98,12 @@ public interface TBUserArchivesService extends IService<TBUserArchives> {
      * @return 档案资源
      */
     List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType);
+
+    /**
+     * 根据服务单元id查询可用的区域负责人
+     *
+     * @param serviceUnitId 服务单元id
+     * @return 区域负责人
+     */
+    List<ArchivesSourceResult> findFreeCoordinatorByServiceId(Long serviceUnitId);
 }

+ 140 - 12
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesAllocationServiceImpl.java

@@ -6,10 +6,7 @@ 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.bean.result.UserArchivesResult;
+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.*;
@@ -23,11 +20,9 @@ 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.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * <p>
@@ -209,7 +204,6 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
     @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())
@@ -218,6 +212,7 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
         for (UserArchivesAllocationResult crmSource : crmSourceList) {
             String crmNo = crmSource.getCrmNo();
             String city = crmSource.getCity();
+            String province = crmSource.getProvince();
 
             // 区域协调人差额
             Integer coordinatorUnDistributed = crmSource.getCoordinatorUnDistributed();
@@ -246,17 +241,150 @@ public class TBUserArchivesAllocationServiceImpl extends ServiceImpl<TBUserArchi
                     .filter(e -> RoleTypeEnum.ASSISTANT_ENGINEER.equals(e.getType()))
                     .collect(Collectors.toList());
 
+            // 可分配的人力资源
+            List<ArchivesSourceResult> effectFree = tbUserArchivesService.findFreeEngineerSourceByType(RoleTypeEnum.EFFECT_ENGINEER)
+                    .stream()
+                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
+                    .collect(Collectors.toList());
+
+            List<ArchivesSourceResult> assistantFree = tbUserArchivesService.findFreeEngineerSourceByType(RoleTypeEnum.ASSISTANT_ENGINEER)
+                    .stream()
+                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
+                    .collect(Collectors.toList());
+
+            List<ArchivesSourceResult> coordinatorFree = tbUserArchivesService.findFreeCoordinatorByServiceId(serviceUnitId)
+                    .stream()
+                    .filter(e -> province.equals(e.getProvince()) && city.equals(e.getCity()))
+                    .collect(Collectors.toList());
+
+            List<AllocationParam> allocationParamList = new ArrayList<>();
+
             // 先分实施工程师
             if (effectUnDistributed > 0) {
-                // 如果存在区域协调人,则要分配的实施工程师必须跟区域协调人处于相同的供应商
-                if (CollectionUtils.isNotEmpty(coordinatorList)){
+                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);
+                        effectUnDistributed = effectUnDistributed - count;
+                        List<ArchivesSourceResult> cell;
+                        if (effectUnDistributed > 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);
+                        } 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);
+                    assistantUnDistributed = assistantUnDistributed - count;
+                    List<ArchivesSourceResult> cell;
+                    if (assistantUnDistributed > 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);
+                    } 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()) && e.getRemainCount() > 0)
+                                .sorted(Comparator.comparing(ArchivesSourceResult::getRemainCount).reversed())
+                                .collect(Collectors.toList());
+                        if (CollectionUtils.isNotEmpty(coordinator)) {
+                            regionUserId = coordinator.get(0).getUserId();
+                        }
+                    }
+                } else {
+                    // 不存在实施工程师
+                    List<ArchivesSourceResult> coordinator = coordinatorFree.stream()
+                            .filter(e -> e.getRemainCount() > 0)
+                            .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);
         }
+    }
 
+    /**
+     * 处理临时新增的分配名单
+     *
+     * @param distribute 已分配的
+     * @param insert     临时分配的
+     */
+    private void addDistributeTemp(List<CrmArchivesAllocationResult> distribute, List<ArchivesSourceResult> insert) {
+        distribute.addAll(insert.stream().flatMap(e -> {
+            CrmArchivesAllocationResult result = new CrmArchivesAllocationResult();
+            result.setArchivesId(e.getArchivesId());
+            result.setUserId(e.getUserId());
+            result.setArchivesProvince(e.getProvince());
+            result.setArchivesCity(e.getCity());
+            result.setSupplierId(e.getSupplierId());
+            return Stream.of(result);
+        }).collect(Collectors.toList()));
     }
 }

+ 34 - 5
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBUserArchivesServiceImpl.java

@@ -9,10 +9,7 @@ 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;
-import com.qmth.sop.business.entity.SysUser;
-import com.qmth.sop.business.entity.TBUserArchives;
-import com.qmth.sop.business.entity.TBUserArchivesSupplier;
+import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.TBUserArchivesMapper;
 import com.qmth.sop.business.service.*;
 import com.qmth.sop.common.base.BaseEntity;
@@ -49,6 +46,10 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
     private TBUserArchivesSupplierService tbUserArchivesSupplierService;
     @Resource
     private SysUserService sysUserService;
+    @Resource
+    private TBServiceService tbServiceService;
+    @Resource
+    private TBCrmService tbCrmService;
 
     @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) {
@@ -351,13 +352,41 @@ public class TBUserArchivesServiceImpl extends ServiceImpl<TBUserArchivesMapper,
 
     @Override
     public List<ArchivesSourceResult> findFreeEngineerSourceByType(RoleTypeEnum roleType) {
-        if (!RoleTypeEnum.EFFECT_ENGINEER.equals(roleType) && !RoleTypeEnum.ASSISTANT_ENGINEER.equals(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()))
+                .peek(e -> e.setRemainCount(1))
+                .collect(Collectors.toList());
+        return list;
+    }
+
+    @Override
+    public List<ArchivesSourceResult> findFreeCoordinatorByServiceId(Long serviceUnitId) {
+        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()
+                .filter(e -> e.getAuthenticationValidTime() >= currentTime)
+                .peek(e -> {
+                    Long userId = e.getUserId();
+                    int count = Math.toIntExact(tbCrmList.stream().filter(c -> userId.equals(c.getRegionCoordinatorId())).count());
+                    if (count > rate) {
+                        throw ExceptionResultEnum.ERROR.exception("区域协调人分配超额异常");
+                    }
+                    e.setRemainCount(rate - count);
+                })
                 .collect(Collectors.toList());
         return list;
     }

+ 26 - 2
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -16,8 +16,8 @@ import java.nio.charset.Charset;
 import java.time.Duration;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
-import java.util.Objects;
-import java.util.StringJoiner;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 系统常量
@@ -132,6 +132,7 @@ public class SystemConstant {
     public static final String PREFIX_URL_COMMON = "/admin/common";
     public static final String PREFIX_URL_USER = "/admin/user";
     public static final String PREFIX_URL_USER_ARCHIVES = "/admin/user/archives";
+    public static final String PREFIX_URL_USER_ARCHIVES_ALLOCATION = "/admin/user/archives/allocation";
     public static final String PREFIX_URL_TASK = "/admin/task";
     public static final String PREFIX_URL_SYS = "/admin/sys";
     public static final String PREFIX_URL_ORG = "/admin/org";
@@ -418,4 +419,27 @@ public class SystemConstant {
         }
         return result;
     }
+
+    /**
+     * 根据键值对的值倒序排序
+     *
+     * @param map 键值对
+     * @param <K> 键
+     * @param <V> 值
+     * @return 排序结果
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    public static <K extends Comparable, V extends Comparable> Map<K, V> sortMapByValues(Map<K, V> map) {
+        HashMap<K, V> finalMap = new LinkedHashMap<K, V>();
+        //取出map键值对Entry<K,V>,然后按照值排序,最后组成一个新的列表集合
+        List<Map.Entry<K, V>> list = map.entrySet()
+                .stream()
+                .sorted((p1, p2) -> p2.getValue().compareTo(p1.getValue()))
+                .collect(Collectors.toList());
+        //遍历集合,将排好序的键值对Entry<K,V>放入新的map并返回
+        //因为HashMap默认是按照键排序,所以新的map还是HashMap,那么就还原了。达不到排序的效果。
+        //所以新的map需要LinkedHashMap类型。这里也可以看出LinkedHashMap是按照顺序存储。
+        list.forEach(ele -> finalMap.put(ele.getKey(), ele.getValue()));
+        return finalMap;
+    }
 }

+ 80 - 3
sop-server/src/main/java/com/qmth/sop/server/api/TBUserArchivesAllocationController.java

@@ -1,9 +1,24 @@
 package com.qmth.sop.server.api;
 
 
-import org.springframework.web.bind.annotation.RequestMapping;
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.business.annotation.OperationLog;
+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.service.TBUserArchivesAllocationService;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
 
-import org.springframework.web.bind.annotation.RestController;
+import javax.annotation.Resource;
+import javax.validation.Valid;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
 
 /**
  * <p>
@@ -13,8 +28,70 @@ import org.springframework.web.bind.annotation.RestController;
  * @author wangliang
  * @since 2023-08-01
  */
+
+@Api(tags = "人员档案Controller")
 @RestController
-@RequestMapping("/t-buser-archives-allocation")
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_USER_ARCHIVES_ALLOCATION)
 public class TBUserArchivesAllocationController {
+    @Resource
+    private TBUserArchivesAllocationService tbUserArchivesAllocationService;
+
+    @ApiOperation(value = "人员档案调配管理-分页查询")
+    @RequestMapping(value = "/page", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = UserArchivesAllocationResult.class)})
+    @OperationLog
+    public Result findUserArchivesAllocationPage(@ApiParam(value = "服务单元id") @RequestParam(required = false) String serviceUnitId,
+                                                 @ApiParam(value = "省") @RequestParam(required = false) String province,
+                                                 @ApiParam(value = "市") @RequestParam(required = false) String city,
+                                                 @ApiParam(value = "县") @RequestParam(required = false) String area,
+                                                 @ApiParam(value = "客户名称") @RequestParam(required = false) String customName,
+                                                 @ApiParam(value = "分配差额") @RequestParam(required = false) Integer gap,
+                                                 @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                                                 @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+
+        return ResultUtil.ok(tbUserArchivesAllocationService.findCrmAllocationPage(SystemConstant.convertIdToLong(serviceUnitId), province, city, area, customName, gap, pageNumber, pageSize));
+    }
+
+    @ApiOperation(value = "人员档案调配管理-小计查询")
+    @RequestMapping(value = "/sub_total", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = UserArchivesAllocationSubTotalResult.class)})
+    @OperationLog
+    public Result findUserArchivesAllocationSubTotal(@ApiParam(value = "服务单元id") @RequestParam(required = false) String serviceUnitId,
+                                                     @ApiParam(value = "省") @RequestParam(required = false) String province,
+                                                     @ApiParam(value = "市") @RequestParam(required = false) String city,
+                                                     @ApiParam(value = "县") @RequestParam(required = false) String area,
+                                                     @ApiParam(value = "客户名称") @RequestParam(required = false) String customName,
+                                                     @ApiParam(value = "分配差额") @RequestParam(required = false) Integer gap) {
+
+        return ResultUtil.ok(tbUserArchivesAllocationService.findCrmAllocationSubTotal(SystemConstant.convertIdToLong(serviceUnitId), province, city, area, customName, gap));
+    }
+
+    @ApiOperation(value = "人员档案调配管理-根据派单号查询派单分配信息")
+    @RequestMapping(value = "/detail_by_crm_no", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = CrmArchivesAllocationResult.class)})
+    @OperationLog
+    public Result findDetailByCrmNo(@ApiParam(value = "派单号", required = true) @RequestParam String crmNo) {
+        return ResultUtil.ok(tbUserArchivesAllocationService.findAllocationByCrmNo(crmNo));
+    }
+
+    @ApiOperation(value = "人员档案调配管理-调配")
+    @RequestMapping(value = "/edit", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "更新成功", response = Result.class)})
+    @OperationLog
+    public Result edit(@Valid @RequestBody UserArchivesAllocationParam userArchivesAllocationParam, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        tbUserArchivesAllocationService.editCrmAllocation(userArchivesAllocationParam);
+        return ResultUtil.ok();
+    }
 
+    @ApiOperation(value = "人员档案调配管理—自动调配")
+    @RequestMapping(value = "/auto_edit", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "更新成功", response = Result.class)})
+    @OperationLog
+    public Result autoEdit(@ApiParam(value = "服务单元id", required = true) @RequestParam String serviceUnitId) {
+        tbUserArchivesAllocationService.autoEditCrmAllocationBatch(SystemConstant.convertIdToLong(serviceUnitId));
+        return ResultUtil.ok();
+    }
 }

+ 57 - 7
sop-server/src/main/java/com/qmth/sop/server/api/TBUserArchivesController.java

@@ -1,9 +1,15 @@
 package com.qmth.sop.server.api;
 
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.business.annotation.OperationLog;
+import com.qmth.sop.business.bean.params.UserArchivesParam;
 import com.qmth.sop.business.bean.query.UserArchivesQuery;
+import com.qmth.sop.business.bean.result.UserArchivesResult;
+import com.qmth.sop.business.bean.result.UserArchivesSubTotalResult;
+import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.entity.TBTask;
 import com.qmth.sop.business.service.TBTaskService;
+import com.qmth.sop.business.service.TBUserArchivesService;
 import com.qmth.sop.business.templete.execute.AsyncUserArchivesExportService;
 import com.qmth.sop.business.templete.execute.AsyncUserArchivesImportService;
 import com.qmth.sop.common.contant.SystemConstant;
@@ -11,14 +17,16 @@ import com.qmth.sop.common.enums.RoleTypeEnum;
 import com.qmth.sop.common.enums.TaskTypeEnum;
 import com.qmth.sop.common.util.Result;
 import com.qmth.sop.common.util.ResultUtil;
+import com.qmth.sop.common.util.ServletUtil;
 import io.swagger.annotations.*;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.validation.Valid;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
 import java.util.Map;
 
 /**
@@ -33,15 +41,57 @@ import java.util.Map;
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_USER_ARCHIVES)
 public class TBUserArchivesController {
+    @Resource
+    private TBTaskService tbTaskService;
 
     @Resource
-    TBTaskService tbTaskService;
+    private AsyncUserArchivesImportService asyncUserArchivesImportService;
 
     @Resource
-    AsyncUserArchivesImportService asyncUserArchivesImportService;
+    private AsyncUserArchivesExportService asyncUserArchivesExportService;
 
     @Resource
-    AsyncUserArchivesExportService asyncUserArchivesExportService;
+    private TBUserArchivesService tbUserArchivesService;
+
+
+    @ApiOperation(value = "人员档案管理-分页查询")
+    @RequestMapping(value = "/page", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = UserArchivesResult.class)})
+    @OperationLog
+    public Result findUserArchivesPage(@ApiParam(value = "城市") @RequestParam(required = false) String city,
+                                       @ApiParam(value = "供应商") @RequestParam(required = false) String supplierId,
+                                       @ApiParam(value = "档案名称") @RequestParam(required = false) String archivesName,
+                                       @ApiParam(value = "认证角色") @RequestParam(required = false) RoleTypeEnum roleType,
+                                       @ApiParam(value = "认证状态") @RequestParam(required = false) Boolean authenticationStatus,
+                                       @ApiParam(value = "入档时间-开始") @RequestParam(required = false) Long archivesTimeStart,
+                                       @ApiParam(value = "入档时间-截止") @RequestParam(required = false) Long archivesTimeEnd,
+                                       @ApiParam(value = "剩余有效天数") @RequestParam(required = false) Integer remainValidDay,
+                                       @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                                       @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+
+        return ResultUtil.ok(tbUserArchivesService.findUserArchivesPage(city, SystemConstant.convertIdToLong(supplierId), archivesName,
+                roleType, authenticationStatus, archivesTimeStart, archivesTimeEnd, remainValidDay, pageNumber, pageSize));
+    }
+
+    @ApiOperation(value = "人员档案管理-小计")
+    @RequestMapping(value = "/sub_total", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = UserArchivesSubTotalResult.class)})
+    @OperationLog
+    public Result findUserArchivesSubTotal() {
+        return ResultUtil.ok(tbUserArchivesService.findUserArchivesSubTotal());
+    }
+
+    @ApiOperation(value = "人员档案管理-编辑")
+    @RequestMapping(value = "/edit", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "更新成功", response = Result.class)})
+    @OperationLog
+    public Result editUserArchives(@Valid @RequestBody UserArchivesParam userArchivesParam, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        return ResultUtil.ok(tbUserArchivesService.editUserArchives(userArchivesParam, requestUser));
+    }
 
     @ApiOperation(value = "人员档案导入")
     @RequestMapping(value = "/import", method = RequestMethod.POST)