浏览代码

1.优化了资产取号的逻辑
2.修复同一意见书流程取不同报告后再次分叉后的流程查询出了非该报告的产品
3.修复产品列表查询出来了未仅取号未撰写的产品
4.资产业务派单新增轮单(待详细测试)
5.instanceCurrent SQL语句新增筛选条件按业务类型查找

GouGengquan 1 年之前
父节点
当前提交
8858be2da1

+ 4 - 6
dao/src/main/java/com/dayou/mapper/AssetsProductionMapper.java

@@ -40,22 +40,20 @@ public interface AssetsProductionMapper extends CustomBaseMapper<AssetsProductio
     List<String> getProductionNo(@Param("id") Long targetId);
 
     /**
-     * 新产品的产品号信息
+     * 新产品的产品号信息
      * @param businessId 业务id
      * @param productionType 产品类型
      * @param productionNo 产品号
      * @return Boolean
      */
-    Boolean updateProductionNo(@Param("businessId") Long businessId, @Param("productionType") String productionType, @Param("productionNo") String productionNo);
+    Boolean updateProductionNo(@Param("productionId") Long productionId, @Param("businessId") Long businessId, @Param("productionType") String productionType, @Param("productionNo") String productionNo);
 
     /**
      * 取子号情况下,再复制一份产品信息并添加
-     * @param businessId 业务id
-     * @param productionType 产品类型
-     * @param printCount 打印数量
+     * @param assetsProduction 产品基础信息
      * @return Boolean
      */
-    Boolean copyProductionInfo(@Param("businessId") Long businessId, @Param("productionType") String productionType, @Param("printCount") Integer printCount);
+    Boolean copyProductionInfo(AssetsProduction assetsProduction);
 
     /**
      * 撰写产品信息

+ 4 - 1
dao/src/main/resources/mapper/AssetsEvaluationTargetMapper.xml

@@ -63,7 +63,10 @@
 #         LEFT JOIN assets_production AS production ON production.production_no = target.statement_no OR production.production_no = target.report_no
         WHERE target.assets_id = #{id}
         <if test="(statementNo != null and statementNo != '') or (reportNo != null and reportNo != '') ">
-            AND (statement_no = #{statementNo} OR report_no = #{reportNo})
+            AND statement_no = #{statementNo}
+        </if>
+        <if test="reportNo != null and reportNo != '' ">
+            AND report_no = #{reportNo}
         </if>
         <!--        <if test="(statementNo == null or statementNo == '') and (reportNo == null or reportNo == '') ">-->
         <!--            AND create_production_date IS NULL-->

+ 11 - 5
dao/src/main/resources/mapper/AssetsProductionMapper.xml

@@ -75,13 +75,13 @@
           AND business_id = #{businessId}
           AND production_type = #{productionType}
           AND (production_no IS NULL OR production_no = '')
-        LIMIT 1
+          AND id = #{productionId}
     </update>
 
     <!--取子号情况下,再复制一份产品信息并添加-->
-    <insert id="copyProductionInfo">
+    <insert id="copyProductionInfo" useGeneratedKeys = "true" keyProperty = "id">
         INSERT INTO assets_production(id, business_id, production_type, print_count)
-            VALUE (NULL, #{businessId}, #{productionType}, #{printCount})
+        VALUE (NULL, #{businessId}, #{productionType}, #{printCount});
     </insert>
 
     <!--撰写产品信息-->
@@ -133,8 +133,14 @@
         <if test="statementNo != null and statementNo != ''">
             AND production_no = #{statementNo}
         </if>
-        <if test="reportNos != null">
-            OR production_no IN
+        <if test="(statementNo != null or statementNo != '') and (reportNos != null and reportNos.size() > 0) ">
+            OR
+        </if>
+        <if test="(statementNo == null or statementNo == '') and (reportNos != null and reportNos.size() > 0) ">
+            AND
+        </if>
+        <if test="reportNos != null and reportNos.size() > 0">
+            production_no IN
             <foreach collection="reportNos" index="index" item="item" open="(" separator="," close=")">
                 #{item}
             </foreach>

+ 1 - 1
dao/src/main/resources/mapper/WorkFlowNodeInstanceMapper.xml

@@ -113,7 +113,7 @@
             wn.terminable,
             wn.skippable
         FROM
-            ( SELECT id, flow_id, node_id, state,sequence FROM work_flow_node_instance WHERE deleted = 0 AND business_id =#{businessId} and state='PENDING'
+            ( SELECT id, flow_id, node_id, state,sequence FROM work_flow_node_instance WHERE deleted = 0 AND business_id =#{businessId} AND state='PENDING' AND business_type = #{mainBusiness}
         <if test="businessSubId!=null and businessSubId!='' and businessMinId!=null and businessMinId!=''">
             AND business_sub_id = #{businessSubId}
             AND business_min_id = #{businessMinId}

+ 2 - 1
domain/src/main/java/com/dayou/enums/GlobalConfigEnum.java

@@ -190,7 +190,8 @@ public enum GlobalConfigEnum implements CodeMsgEnumInterface<String,CodeMsgEnumI
     public enum DepartmentTurns  implements CodeMsgEnumInterface<String,String>{
 
         MAJOR_BUSINESS("MAJOR_BUSINESS",null,"大中型业务轮单部门下标"),
-        INWARD_STAFF_ROLL("INWARD_STAFF_ROLL",null,"个贷内业轮单")
+        INWARD_STAFF_ROLL("INWARD_STAFF_ROLL",null,"个贷内业轮单"),
+        ASSET_BUSINESS("ASSET_BUSINESS",null,"资产业务轮单部门下标")
         ;
 
         private String filed;

+ 108 - 19
service/src/main/java/com/dayou/service/impl/AssetsServiceImpl.java

@@ -1,10 +1,12 @@
 package com.dayou.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.dayou.entity.BusinessProductionChoiceLog;
-import com.dayou.entity.OrderFund;
-import com.dayou.service.IBusinessProductionChoiceLogService;
-import com.dayou.service.IOrderFundService;
+import com.dayou.entity.*;
+import com.dayou.enums.GlobalConfigEnum;
+import com.dayou.enums.MainBusinessEnum;
+import com.dayou.service.*;
 import com.dayou.utils.LoginContext;
 import com.dayou.vo.AssetsRepertoryVo;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -12,15 +14,11 @@ import com.fasterxml.jackson.core.type.TypeReference;
 import cn.hutool.core.util.ObjectUtil;
 import com.dayou.common.BaseEntity;
 import com.dayou.dto.*;
-import com.dayou.entity.Assets;
-import com.dayou.entity.BusinessNumber;
 import com.dayou.exception.ErrorCode;
 import com.dayou.mapper.AssetsEvaluationTargetMapper;
 import com.dayou.mapper.AssetsMapper;
 import com.dayou.mapper.AssetsProductionMapper;
-import com.dayou.service.IAssetsService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.dayou.service.IBusinessNumberService;
 import com.dayou.service.workflow.IWorkFlowService;
 import com.dayou.vo.AssetsBusinessMember;
 import com.dayou.vo.AssetsOrderFundInvoiceVO;
@@ -32,12 +30,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
+import static com.dayou.common.Constants.BY_TURNS;
 import static com.dayou.enums.MainBusinessEnum.ASSET_BUSINESS;
 import static com.dayou.enums.ProductionEnum.*;
 
@@ -73,6 +71,12 @@ public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> impleme
     @Autowired
     private IBusinessProductionChoiceLogService choiceLogService;
 
+    @Autowired
+    private IGlobalConfigService globalConfigService;
+
+    @Autowired
+    private ISortedDepartmentService sortedDepartmentService;
+
     /**
      * 条件查询资产任务列表
      *
@@ -166,6 +170,11 @@ public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> impleme
     public WorkNodeCommit add(Assets assets) {
         //获取项目编号
         assets.setOrderId(businessNumberService.takeOrderNumber());
+        // 判断分单类型
+        if (BY_TURNS.equals(assets.getAllotType())){
+            //获取轮单部门
+            assets.setDepartmentId(getAllotDepartmentId());
+        }
         //新增订单信息
         this.save(assets);
         //新增订单收款信息
@@ -230,26 +239,60 @@ public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> impleme
 
         // 取号时更新产品选择记录状态
         List<BusinessProductionChoiceLog> choiceLogList = new ArrayList<>();
+        // 循环取号的评估对象id集合
         for (Long targetId : dto.getTargetIdList()){
+            // 获取每一个取号评估对象的产品选择记录(同一个评估对象不可能同时存在两条状态为未取号的产品选择记录)
             BusinessProductionChoiceLog choiceLog = choiceLogService.getOne(new LambdaQueryWrapper<BusinessProductionChoiceLog>()
                     .eq(BusinessProductionChoiceLog::getTargetId, targetId)
                     .eq(BusinessProductionChoiceLog::getBusinessType, "ASSET_BUSINESS")
                     .eq(BusinessProductionChoiceLog::getBusinessId, dto.getBusinessId())
                     .eq(BusinessProductionChoiceLog::getTakeNoStatus, 0));
+            // 已取号的评估对象产品选择记录取号状态改为true
             choiceLog.setTakeNoStatus(true);
+            // 获取后将选择记录状态改为true并添加集合用于后续批量更新
             choiceLogList.add(choiceLog);
         }
-        choiceLogService.updateBatchById(choiceLogList);
+
+        // 获取产品选择记录的相关信息,并设置到dto(同一流程的所有评估对象只能选择同一种产品类型,所以此处直接下标获取)
         dto.setPrintCount(choiceLogList.get(0).getPrintCount());
         dto.setProductionType(choiceLogList.get(0).getProductionType());
         String productionNo = genProductionNo(dto);
-        //产品添加产品号
-        assetsProductionMapper.updateProductionNo(dto.getBusinessId(), dto.getProductionType(), productionNo);
-        //如果还有未取号评估对象,再添加一份同类型产品
+
+        //产品信息更新添加产品号
+        assetsProductionMapper.updateProductionNo(choiceLogList.get(0).getProductionId(), dto.getBusinessId(), dto.getProductionType(), productionNo);
+
+        //如果还有未取号评估对象
         if (dto.getHasNotTakeNumTargetSelect()) {
-            assetsProductionMapper.copyProductionInfo(dto.getBusinessId(), dto.getProductionType(), dto.getPrintCount());
+            // 有未取号对象,添加一份同类型产品
+            AssetsProduction copyProductionInfo = new AssetsProduction();
+            copyProductionInfo.setBusinessId(dto.getBusinessId());
+            copyProductionInfo.setProductionType(dto.getProductionType());
+            copyProductionInfo.setPrintCount(dto.getPrintCount());
+            assetsProductionMapper.copyProductionInfo(copyProductionInfo);
+            // 获取未取号的评估对象id
+            List<Long> unTakeNoTargetIdList = targetIdListDifference(dto.getAllTargetIdList(), dto.getTargetIdList());
+
+            // 将未取号对象的产品选择记录对应的产品id更新
+            if (ObjectUtil.isNotNull(unTakeNoTargetIdList) && ObjectUtil.isNotEmpty(unTakeNoTargetIdList)){
+                for (Long targetId : unTakeNoTargetIdList){
+                    // 获取每一个未评估对象的产品选择记录(同一个评估对象不可能同时存在两条状态为未取号的产品选择记录)
+                    BusinessProductionChoiceLog choiceLog = choiceLogService.getOne(new LambdaQueryWrapper<BusinessProductionChoiceLog>()
+                            .eq(BusinessProductionChoiceLog::getTargetId, targetId)
+                            .eq(BusinessProductionChoiceLog::getBusinessType, "ASSET_BUSINESS")
+                            .eq(BusinessProductionChoiceLog::getBusinessId, dto.getBusinessId())
+                            .eq(BusinessProductionChoiceLog::getTakeNoStatus, 0));
+                    // 将未取号的评估对象对应的产品选择记录的产品id改为新的
+                    choiceLog.setProductionId(copyProductionInfo.getId());
+                    // 获取后将选择记录对应的产品id改为前面新添加的产品信息
+                    choiceLogList.add(choiceLog);
+                }
+            }
         }
-        //评估对象添加产品号
+
+        // 批量更新产品选择记录
+        choiceLogService.updateBatchById(choiceLogList);
+
+        //评估对象信息更新添加产品号
         for (Long id : dto.getTargetIdList()) {
             //判断取号的产品类型
             if (dto.getProductionType().equals(STATEMENT.getCode())){ //意见书
@@ -282,7 +325,7 @@ public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> impleme
         //获取资产产品取号信息
         BusinessNumber businessNumber = assetsMapper.getBusinessNum(takeAssetsProductionNoDTO.getProductionType() + "_NUMBER", ASSET_BUSINESS.getCode(), nowYear);
 
-        //获取当前资产业务评估对象已经生成的产品号集合
+        //获取当前资产业务流程的评估对象已经生成的产品号集合
         List<String> productionNoList = null;
         //判断取号的产品类型
         if (takeAssetsProductionNoDTO.getProductionType().equals(STATEMENT.getCode())){ //意见书
@@ -351,7 +394,6 @@ public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> impleme
             }
 
             //判断取号产品类型
-
             if (takeAssetsProductionNoDTO.getProductionType().equals(STATEMENT.getCode())) { //取号产品为意见书
                 productionNo = "川友预报字" + productionNo;
             } else if (takeAssetsProductionNoDTO.getProductionType().equals(REPORT.getCode())) { //取号产品为评估报告
@@ -435,6 +477,22 @@ public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> impleme
     }
 
     /**
+     * 获取未取号的资产评估对象id
+     * @param allTargetIdList 本次资产流程的所有评估对象
+     * @param takeNoTargetIdList 本次资产流程的取号评估对象
+     * @return List<Long>
+     */
+    public List<Long> targetIdListDifference(List<Long> allTargetIdList, List<Long> takeNoTargetIdList){
+        // 将取号评估对象集合转换为Set,以便快速查找
+        Set<Long> takeNoTargetIdSet = new HashSet<>(takeNoTargetIdList);
+
+        // 使用Stream API找出只在allTargetIdList中但不在takeNoTargetIdSet中的元素
+        return allTargetIdList.stream()
+                .filter(value -> !takeNoTargetIdSet.contains(value))
+                .collect(Collectors.toList());
+    }
+
+    /**
      * 获取资产项目所有参与人
      * @param assetsBusinessMembersDTO 查询dto
      * @return List<AssetsBusinessMembers>
@@ -477,4 +535,35 @@ public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> impleme
 
         return assetsBusinessMemberList;
     }
+
+    /**
+     * 获取资产轮单部门id
+     *
+     * @return Long
+     */
+    private synchronized Long getAllotDepartmentId(){
+
+        List<SortedDepartment> departments = sortedDepartmentService.list(new LambdaQueryWrapper<SortedDepartment>().eq(SortedDepartment::getBusinessType, MainBusinessEnum.ASSET_BUSINESS.getCode()));
+
+        if (CollectionUtil.isEmpty(departments)){
+            ErrorCode.throwBusinessException(ErrorCode.SORTED_DEPARTMENT_NOT_EXISTS, MainBusinessEnum.ASSET_BUSINESS.getMsg());
+        }
+
+
+        GlobalConfig currentSorted = globalConfigService.getGlobalConfig(GlobalConfigEnum.DEPARTMENT_TURNS.name(), GlobalConfigEnum.DepartmentTurns.ASSET_BUSINESS.name());
+
+        Integer currentSortedIndex = Integer.valueOf(StrUtil.isBlank(currentSorted.getValue())?"0":currentSorted.getValue());
+
+        List<Integer> indexes = departments.stream().map(SortedDepartment::getSortedIndex).sorted(Integer::compareTo).collect(Collectors.toList());
+        for (int i=0;i<indexes.size();i++){
+            if (currentSortedIndex.equals(indexes.get(i))){
+                Integer waitingIndex = indexes.get((i + 1) % indexes.size());
+                currentSorted.setValue(String.valueOf(waitingIndex));
+                globalConfigService.update(currentSorted);
+                break;
+            }
+        }
+
+        return departments.stream().filter(d -> d.getSortedIndex().equals(currentSortedIndex)).findFirst().get().getDepartmentId();
+    }
 }