Browse Source

实收款认领bug修复

wucl 1 year ago
parent
commit
52ebcccef4

+ 11 - 1
biz-base/src/main/java/com/dayou/controller/BusinessProductionController.java

@@ -81,7 +81,7 @@ public class BusinessProductionController{
 
 
     /**
-     * 实收款认领
+     * 实收款认领到 产品
      * @return
      */
     @PostMapping("/allotRealAmount/major")
@@ -91,6 +91,16 @@ public class BusinessProductionController{
     }
 
     /**
+     * 实收款认领到 订单
+     * @return
+     */
+    @PostMapping("/allotRealAmountOrder/major")
+    public RestResponse<Boolean> allotRealAmountToOrder(@RequestBody List<OrderReportDTO> claimOrders){
+        Boolean ret = majorProductionService.allotRealAmountToOrder(claimOrders);
+        return RestResponse.data(ret);
+    }
+
+    /**
      * 实收款分配到产品
      * @return
      */

+ 3 - 0
dao/src/main/java/com/dayou/mapper/ProductionFundMapper.java

@@ -6,6 +6,7 @@ import com.dayou.dao.CustomBaseMapper;
 import com.dayou.vo.MajorOrderVO;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -21,4 +22,6 @@ public interface ProductionFundMapper extends CustomBaseMapper<ProductionFund> {
    List<ReportDTO> getProductionFundByOrderFundId(@Param("orderFundId") Long orderFundId);
 
     List<ProductionFund> deepQueryProductionFund(@Param("majorIds") List<Long> majorIds);
+
+    void updateRealAmount(@Param("id") Long id, @Param("thisTimeAmount") BigDecimal thisTimeAmount);
 }

+ 95 - 54
dao/src/main/resources/mapper/CommissionDeclareMapper.xml

@@ -212,72 +212,113 @@
             where cd.deleted = 0 and bcr.deleted = 0 and cd.id =#{id}
     </select>
 
+    <resultMap id="majorDeclareTodoCheckMap" type="com.dayou.vo.CommissionDeclareTodoCheckVO">
+        <id property="id" column="id"></id>
+        <result property="taskId" column="taskId"></result>
+        <result property="currentNodeId" column="currentNodeId"></result>
+        <result property="businessId" column="business_id"></result>
+        <result property="businessType" column="business_type"></result>
+        <result property="orderName" column="orderName"></result>
+        <result property="name" column="name"></result>
+        <result property="reportNo" column="report_no"></result>
+        <result property="orderId" column="order_id"></result>
+        <result property="nodeName" column="nodeName"></result>
+        <result property="nodeCode" column="nodeCode"></result>
+        <result property="handler" column="handler"></result>
+        <result property="declareUser" column="declareUser"></result>
+        <result property="businessCate" column="businessCate"></result>
+        <result property="userType" column="userType"></result>
+        <result property="ratio" column="ratio"></result>
+        <result property="created" column="created"></result>
+        <result property="prodId" column="prodId"></result>
+        <result property="majorId" column="majorId"></result>
+        <association property="majorSimple" column="{majorId=majorId,prodId=prodId}" javaType="com.dayou.dto.MajorDeclareSimpleDTO"
+                     select="selectMajorSimple" ></association>
+    </resultMap>
     <sql id="majorDeclareTodoCheck">
         SELECT
-            wfni.id,
-            wtr.id AS taskId,
-            wfni.id AS currentNodeId,
-            wfni.business_id,
-            wfni.business_type,
-            mm.orderName,
-            mm.NAME,
-            mm.report_no,
-            mm.order_id,
-            wfni.NAME AS nodeName,
-            wfni.CODE AS nodeCode,
-            u.NAME AS handler,
-            u1.name as declareUser,
-            dd.name as businessCate,
-            (case bcr.user_type when 'MARKETER' then '市场人员' when 'EVALUATOR' then '评估人员' else '--' end) as userType,
-            bcr.min_ratio as ratio,
-            cd.created,
-            mm.prodId
+            t.*,
+            u.NAME AS HANDLER,
+            u1.NAME AS declareUser,
+            dd.NAME AS businessCate,
+            ( CASE bcr.user_type WHEN 'MARKETER' THEN '市场人员' WHEN 'EVALUATOR' THEN '评估人员' ELSE '--' END ) AS userType,
+            bcr.min_ratio AS ratio
         FROM
-            work_task_record wtr
-                INNER JOIN (
+            (
                 SELECT
-                    wn.NAME,
-                    wn.CODE,
                     wfni.id,
+                    wtr.id AS taskId,
+                    wfni.id AS currentNodeId,
                     wfni.business_id,
-                    wfni.state,
-                    wfni.business_type
+                    wfni.business_type,
+                    wfni.NAME AS nodeName,
+                    wfni.CODE AS nodeCode,
+                    cd.majorId,
+                    cd.production_id as prodId,
+                    cd.id AS cId,
+                    wtr.handler_id,
+                    cd.commission_rate_id,
+                    cd.declare_user_id,
+                    cd.created
                 FROM
-                    work_flow_node_instance wfni
-                        LEFT JOIN work_node wn ON wn.id = wfni.node_id
+                    work_task_record wtr
+                        INNER JOIN (
+                        SELECT
+                            wn.NAME,
+                            wn.CODE,
+                            wfni.id,
+                            wfni.business_id,
+                            wfni.state,
+                            wfni.business_type
+                        FROM
+                            work_flow_node_instance wfni
+                                LEFT JOIN work_node wn ON wn.id = wfni.node_id
+                        WHERE
+                                wfni.business_type IN ( 'COMMISSION_DECLARE_MAJOR_MARKET', 'COMMISSION_DECLARE_MAJOR_EVALUATE' )
+                          AND wfni.state = 'PENDING'
+                          AND wfni.deleted = 0
+                          AND wn.deleted = 0
+                    ) wfni ON wtr.instance_id = wfni.id
+                        INNER JOIN ( SELECT id, production_id, business_id AS majorId, commission_rate_id, declare_result, declare_user_id, created FROM commission_declare WHERE deleted = 0 AND declare_result = '审核中' ) cd ON cd.id = wfni.business_id
                 WHERE
-                        wfni.business_type IN ( 'COMMISSION_DECLARE_MAJOR_MARKET', 'COMMISSION_DECLARE_MAJOR_EVALUATE' )
-                  AND wfni.state = 'PENDING'
-                  AND wfni.deleted = 0
-                  AND wn.deleted = 0
-            ) wfni ON wtr.instance_id = wfni.id
-                INNER JOIN ( SELECT id, ifnull( production_id, business_id ) AS xId, commission_rate_id, declare_result, declare_user_id,created FROM commission_declare WHERE deleted = 0 ) cd ON cd.id = wfni.business_id
-                LEFT JOIN (
-                SELECT
-                    ifnull( mp.id, m.id ) AS mId,
-                    m.NAME AS orderName,
-                    m.order_id,
-                    mp.NAME,
-                    mp.report_no ,
-                    mp.id as prodId
-                FROM
-                    major m
-                        LEFT JOIN ( SELECT id, NAME, major_id, report_no FROM major_production WHERE deleted = 0 ) mp ON m.id = mp.major_id
-            ) mm ON mm.mId = cd.xId
-                LEFT JOIN user u ON u.id = wtr.handler_id
-                left join business_commission_rate bcr on bcr.id = cd.commission_rate_id
-                left join dict_data dd on dd.id = bcr.business_cate_id
-                left join user u1 on u1.id = cd.declare_user_id
-        WHERE
-            wtr.handler_id = #{checkVO.handlerId}
-          AND u.deleted = 0
-          AND wtr.deleted = 0
+                    wtr.handler_id = #{checkVO.handlerId}
+            ) t
+                LEFT JOIN user u ON u.id = t.handler_id
+                LEFT JOIN business_commission_rate bcr ON bcr.id = t.commission_rate_id
+                LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
+                LEFT JOIN user u1 ON u1.id = t.declare_user_id
     </sql>
-    <select id="todoCheckPage" parameterType="com.dayou.vo.CommissionDeclareTodoCheckVO"  resultType="com.dayou.vo.CommissionDeclareTodoCheckVO">
+
+    <select id="selectMajorSimple" resultType="com.dayou.dto.MajorDeclareSimpleDTO">
+        <if test="majorId!=null and prodId!=null">
+            SELECT
+            m.id as majorId,
+            m.NAME AS orderName,
+            m.order_id as orderId,
+            mp.NAME as name,
+            mp.report_no as reportNo,
+            mp.id as prodId
+            FROM
+            major m
+            LEFT JOIN ( SELECT id, name, major_id, report_no FROM major_production WHERE deleted = 0 ) mp ON
+            m.id = mp.major_id
+            where m.id = #{majorId} and mp.id= #{prodId}
+        </if>
+        <if test="majorId!=null and prodId==null">
+            SELECT
+            m.id as majorId,
+            m.NAME AS orderName,
+            m.order_id as orderId
+            FROM
+            major m
+            where m.id = #{majorId}
+        </if>
+    </select>
+    <select id="todoCheckPage" parameterType="com.dayou.vo.CommissionDeclareTodoCheckVO"  resultMap="majorDeclareTodoCheckMap">
         <include refid="majorDeclareTodoCheck"/>
     </select>
 
-    <select id="todoCheckList" resultType="com.dayou.vo.CommissionDeclareTodoCheckVO">
+    <select id="todoCheckList" resultMap="majorDeclareTodoCheckMap">
         <include refid="majorDeclareTodoCheck"/>
         limit 8
     </select>

+ 53 - 30
dao/src/main/resources/mapper/FinanceClaimMapper.xml

@@ -10,7 +10,7 @@
         <result column="modified" property="modified" />
         <result column="real_fund_id" property="realFundId" />
         <result column="production_fund_id" property="productionFundId" />
-        <result column="claim_id" property="claimId" />
+        <result column="claim_user_id" property="claimUserId" />
         <result column="claim_datetime" property="claimDatetime" />
         <result column="claim_amount" property="claimAmount" />
     </resultMap>
@@ -21,7 +21,7 @@
         created,
         deleted,
         modified,
-        real_fund_id, production_fund_id, claim_id, claim_datetime, claim_amount
+        real_fund_id, production_fund_id, claim_user_id, claim_datetime, claim_amount
     </sql>
 
     <select id="getList" parameterType="com.dayou.entity.FinanceClaim" resultType="com.dayou.vo.FinanceClaimVO">
@@ -39,7 +39,7 @@
         FROM
             finance_claim fc
                 LEFT JOIN order_fund orf ON fc.order_fund_id = orf.id
-                LEFT JOIN user u ON u.id = fc.claim_id
+                LEFT JOIN user u ON u.id = fc.claim_user_id
         WHERE
             fc.real_fund_id = #{realFundId}
           AND fc.deleted = 0
@@ -61,70 +61,93 @@
 
     <sql id="majorStatQuery">
         SELECT
-        f.*,
-        mp.NAME,
+        fc.*,
+        f.production_no as reportNo,
+        f.order_id,
+        f.should_amount,
         m.financial,
         m.members,
+        m.bailor,
+        m.NAME AS orderName,
+        mp.NAME,
         mp.if_save_file,
         mp.evaluate_amount,
+        mp.production as productionType,
         u.NAME AS clientManager,
         u1.NAME AS principal,
         cc1.NAME AS clientName,
         cc2.NAME AS clientSubName,
-        m.bailor,
         frf.pay_datetime,
         frf.payer,
         u2.NAME AS claimUser,
-        d.name as evaluateDepartment,
-        (select GROUP_CONCAT(name SEPARATOR '、') from department where id in (select department_id from post where id in (select post_id from user_post where user_id = u.id))) as marketDepartment
+        d.NAME AS evaluateDepartment,
+        (
+        SELECT
+        GROUP_CONCAT( NAME SEPARATOR '、' )
+        FROM
+        department
+        WHERE
+        id IN (
+        SELECT
+        department_id
+        FROM
+        post
+        WHERE
+        id IN ( SELECT post_id FROM user_post WHERE user_id = u.id ))) AS marketDepartment
         FROM
         (
         SELECT
+        of.id AS oId,
+        pf.id AS pId,
+        of.business_id,
         of.order_id,
-        pf.real_amount AS claimAmount,
-        pf.production_no as reportNo,
-        pf.production_type,
-        pf.created as claimDatetime,
-        pf.claim_id,
-        of.business_id
+        pf.production_no,
+        of.should_amount
         FROM
-        ( SELECT id, real_amount, production_no, production_type, order_fund_id, claim_id, created FROM production_fund WHERE business_type = "MAJOR_BUSINESS" AND deleted = 0 ) pf
-        LEFT JOIN order_fund of ON pf.order_fund_id = of.id
+        order_fund of
+        LEFT JOIN ( SELECT id, real_amount, production_no, production_type, order_fund_id, created FROM production_fund WHERE business_type = "MAJOR_BUSINESS" AND deleted = 0 AND real_amount != 0 ) pf ON pf.order_fund_id = of.id
         WHERE
         of.business_type = 'MAJOR_BUSINESS'
         AND of.deleted = 0
-        AND pf.real_amount != 0
         ) f
+        INNER JOIN finance_claim fc ON
+        IF
+        (
+        f.pId IS NULL,(
+        fc.order_fund_id = f.oId
+        ),(
+        fc.order_fund_id = f.oId
+        AND fc.production_fund_id = f.pId
+        )
+        )
         LEFT JOIN major m ON f.business_id = m.id
-        LEFT JOIN USER u ON u.id = m.client_manager_id
-        LEFT JOIN USER u1 ON u1.id = m.principal_id
+        LEFT JOIN user u ON u.id = m.client_manager_id
+        LEFT JOIN user u1 ON u1.id = m.principal_id
         LEFT JOIN department d ON d.id = m.department_id
         LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
         LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
         LEFT JOIN customer_linkman cl1 ON cl1.id = m.clientele_contact_id
-        LEFT JOIN finance_claim fc ON fc.id = f.claim_id
         LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
-        LEFT JOIN ( SELECT major_id, report_no, evaluate_amount, if_save_file, NAME FROM major_production WHERE deleted = 0 ) mp ON ( mp.major_id = m.id AND mp.report_no = f.reportNo )
-        LEFT JOIN USER u2 ON u2.id = fc.claim_id
-        WHERE
-        m.deleted = 0
+        LEFT JOIN ( SELECT major_id, report_no,production, evaluate_amount, if_save_file, NAME FROM major_production WHERE deleted = 0 ) mp ON ( mp.major_id = m.id AND mp.report_no = f.production_no )
+        LEFT JOIN user u2 ON u2.id = fc.claim_user_id
+        where m.deleted = 0
         <if test="majorStat!=null and majorStat.orderId!=null and majorStat.orderId!='' ">
             and f.order_id like concat ('%',#{majorStat.orderId},'%')
         </if>
         <if test="majorStat!=null and majorStat.reportNo!=null and majorStat.reportNo!='' ">
-            and f.reportNo like concat ('%',#{majorStat.reportNo},'%')
+            and f.production_no like concat ('%',#{majorStat.reportNo},'%')
         </if>
         <if test="majorStat!=null and majorStat.startDate!=null and majorStat.startDate!='' ">
-            and f.claimDatetime &gt;= #{majorStat.startDate}
+            and fc.claim_datetime &gt;= #{majorStat.startDate}
         </if>
         <if test="majorStat!=null and majorStat.endDate!=null and majorStat.endDate!='' ">
-            and f.claimDatetime &lt;= #{majorStat.endDate}
+            and fc.claim_datetime &lt;= #{majorStat.endDate}
         </if>
         <if test="majorStat!=null and majorStat.principal!=null and majorStat.principal!='' ">
-            and u1.NAME like concat ('%',#{majorStat.principal},'%')
+            and u1.name like concat ('%',#{majorStat.principal},'%')
         </if>
         <if test="majorStat!=null and majorStat.claimAmount!=null and majorStat.claimAmount!='' ">
-            and f.claimAmount = #{majorStat.claimAmount}
+            and fc.claim_amount = #{majorStat.claimAmount}
         </if>
         <if test="majorStat!=null and majorStat.ifSaveFile!=null ">
             and mp.if_save_file = #{majorStat.ifSaveFile}
@@ -136,7 +159,7 @@
             and u2.NAME like concat ('%',#{majorStat.claimUser},'%')
         </if>
         ORDER BY
-        f.claimDatetime DESC
+        fc.claim_datetime DESC
     </sql>
     <select id="majorStat" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
         <include refid="majorStatQuery" />

+ 2 - 2
dao/src/main/resources/mapper/MajorProductionMapper.xml

@@ -449,9 +449,9 @@
             off.real_amount,
             off.standard_amount,
         ifnull(( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ),
-        ( SELECT declare_result FROM commission_declare WHERE business_id = m.id  AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 )) as mDeclareResult,
+        ( SELECT declare_result FROM commission_declare WHERE business_id = m.id  and production_id is null AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 )) as mDeclareResult,
         ifnull(( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ),
-        ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 )) as eDeclareResult
+        ( SELECT declare_result FROM commission_declare WHERE business_id = m.id  and production_id is null AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 )) as eDeclareResult
         FROM
             major_production mp
                 left join major m on m.id = mp.major_id

+ 4 - 0
dao/src/main/resources/mapper/ProductionFundMapper.xml

@@ -51,4 +51,8 @@
         GROUP BY mp.id
         order by  mp.report_no
     </select>
+
+    <update id="updateRealAmount">
+        update production_fund set real_amount = (ifnull(real_amount,0) + #{thisTimeAmount}) where id = #{id} and deleted = 0
+    </update>
 </mapper>

+ 26 - 0
domain/src/main/java/com/dayou/dto/MajorDeclareSimpleDTO.java

@@ -0,0 +1,26 @@
+package com.dayou.dto;
+
+import lombok.Data;
+
+/**
+ * 类说明:
+ *
+ * @author: wucl
+ * @since: 2024/5/23
+ * created with IntelliJ IDEA.
+ */
+@Data
+public class MajorDeclareSimpleDTO {
+
+    private Long majorId;
+
+    private Long prodId;
+
+    private String orderId;
+
+    private String orderName;
+
+    private String name;
+
+    private String reportNo;
+}

+ 2 - 0
domain/src/main/java/com/dayou/dto/OrderReportDTO.java

@@ -33,5 +33,7 @@ public class OrderReportDTO {
 
     private Long financeFundId;
 
+    private Long productionFundId;
+
     private List<ReportDTO> reports;
 }

+ 5 - 0
domain/src/main/java/com/dayou/vo/CommissionDeclareTodoCheckVO.java

@@ -1,5 +1,6 @@
 package com.dayou.vo;
 
+import com.dayou.dto.MajorDeclareSimpleDTO;
 import lombok.Data;
 
 import java.math.BigDecimal;
@@ -52,4 +53,8 @@ public class CommissionDeclareTodoCheckVO {
     private Long handlerId;
 
     private String businessType;
+
+    private Long majorId;
+
+    private MajorDeclareSimpleDTO majorSimple;
 }

+ 10 - 0
domain/src/main/java/com/dayou/vo/MajorProductionVO.java

@@ -137,4 +137,14 @@ public class MajorProductionVO {
 
     private Long clientManagerId;
 
+    /**
+     * 订单收款表
+     */
+    private Long orderFundId;
+
+    /**
+     * 订单收款表
+     */
+    private Long productionFundId;
+
 }

+ 2 - 0
domain/src/main/java/com/dayou/vo/RealFundMajorStatVO.java

@@ -37,6 +37,8 @@ public class RealFundMajorStatVO {
     @Excel(name = "项目编号")
     private String orderId;
 
+    private String orderName;
+
     /**
      * 报告号
      */

+ 3 - 0
service/src/main/java/com/dayou/service/IMajorProductionService.java

@@ -78,4 +78,7 @@ public interface IMajorProductionService extends IService<MajorProduction> {
     Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, MajorProductionPerformanceVO productionPerformance);
 
     Page<MajorProductionVO> waitingClaimProd(Page page, MajorProductionVO production);
+
+    Boolean allotRealAmountToOrder(List<OrderReportDTO> claimOrders);
+    Boolean doAllotRealAmountToOrder(List<OrderReportDTO> claimOrders);
 }

+ 64 - 53
service/src/main/java/com/dayou/service/impl/MajorProductionServiceImpl.java

@@ -60,9 +60,6 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
 
 
     @Autowired
-    private DfsConfig dfsConfig;
-
-    @Autowired
     private MajorProductionMapper majorProductionMapper;
 
     @Autowired
@@ -78,9 +75,6 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
     private IFinanceClaimService financeClaimService;
 
     @Autowired
-    private IFinanceRealFundService financeRealFundService;
-
-    @Autowired
     private OrderFundMapper orderFundMapper;
 
     @Autowired
@@ -105,6 +99,7 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
     private IBusinessProductionService businessProductionService;
 
 
+
     @Override
     @SuppressWarnings("unchecked")
     public List<MajorProduction> selectPage(MajorProduction majorProduction){
@@ -385,70 +380,83 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
                 return Boolean.FALSE;
             }
 
-            //再校验产品分配金额是否大于订单认领金额
-//            List<FinanceClaim> financeClaims = new ArrayList<>();
             for (OrderReportDTO orderReportDTO : claimOrders){
                 BigDecimal thisTimeAmount = orderReportDTO.getThisTimeAmount();
-                BigDecimal realAmount = orderFundMapper.selectById(orderReportDTO.getOrderFundId()).getRealAmount();
-                if (realAmount ==null){
-                    realAmount = BigDecimal.ZERO;
+                Long productionFundId = orderReportDTO.getProductionFundId();
+                if (productionFundId==null){
+                    MajorProduction production = majorProductionMapper.selectOne(new LambdaQueryWrapper<MajorProduction>().eq(BaseEntity::getId,orderReportDTO.getId()).eq(BaseEntity::getDeleted, Boolean.FALSE)
+                            .select(MajorProduction::getReportNo, MajorProduction::getMajorId, MajorProduction::getProduction, MajorProduction::getEvaluateAmount));
+                    ProductionFund productionFund = new ProductionFund();
+                    productionFund.setProductionType(production.getProduction());
+                    productionFund.setBusinessType(MainBusinessEnum.MAJOR_BUSINESS.name());
+                    productionFund.setOrderFundId(orderReportDTO.getOrderFundId());
+                    productionFund.setBusinessId(production.getMajorId());
+                    productionFund.setProductionNo(production.getReportNo());
+                    productionFund.setRealAmount(orderReportDTO.getThisTimeAmount());
+                    productionFund.setEvaluateAmount(production.getEvaluateAmount());
+                    productionFundService.add(productionFund);
+                    productionFundId = productionFund.getId();
+                }else {
+                    productionFundMapper.updateRealAmount(productionFundId,orderReportDTO.getThisTimeAmount());
                 }
 
+                //更新订单实收款
                 Long orderFundId = orderReportDTO.getOrderFundId();
+                orderFundMapper.updateRealAmount(orderFundId, thisTimeAmount);
 
                 //插入订单认领流水表
                 FinanceClaim financeClaim = new FinanceClaim();
-                if (thisTimeAmount.compareTo(BigDecimal.ZERO)>0){
-                    Long userId = LoginContext.getCurrentUserId();
-                    financeClaim.setClaimUserId(userId);
-                    financeClaim.setRealFundId(financeFundId);
-                    financeClaim.setOrderFundId(orderFundId);
-                    financeClaim.setClaimAmount(thisTimeAmount);
-                    financeClaim.setClaimDatetime(LocalDateTime.now());
-                    //financeClaims.add(financeClaim);
-                    financeClaimService.add(financeClaim);
-                }
-
-                BigDecimal targetAmount = realAmount.add(thisTimeAmount);
+                Long userId = LoginContext.getCurrentUserId();
+                financeClaim.setClaimUserId(userId);
+                financeClaim.setRealFundId(financeFundId);
+                financeClaim.setOrderFundId(orderFundId);
+                financeClaim.setClaimAmount(thisTimeAmount);
+                financeClaim.setClaimDatetime(LocalDateTime.now());
+                financeClaim.setProductionFundId(productionFundId);
+                financeClaimService.add(financeClaim);
+            }
+           return Boolean.TRUE;
+        }
+        return Boolean.FALSE;
+    }
 
-                List<ReportDTO> reports = orderReportDTO.getReports();
 
-                if (CollectionUtil.isNotEmpty(reports)){
-                    BigDecimal reduce = reports.stream().filter(x->x.getRealAmount()!=null).map(ReportDTO::getRealAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-                    if (reduce.compareTo(targetAmount)>0){
-                        ErrorCode.throwBusinessException(ErrorCode.P_AMOUNT_BIGGER_O_AMOUNT,orderReportDTO.getOrderId());
-                        return Boolean.FALSE;
-                    }
-                    //创建产品收款记录
-                    for (ReportDTO reportDTO : reports){
-                     //   if (reportDTO.getProductionFundId()==null){
-                            MajorProduction production = majorProductionMapper.selectOne(new LambdaQueryWrapper<MajorProduction>().eq(BaseEntity::getId,reportDTO.getId()).eq(BaseEntity::getDeleted, Boolean.FALSE)
-                                    .select(MajorProduction::getReportNo, MajorProduction::getMajorId, MajorProduction::getProduction, MajorProduction::getEvaluateAmount));
-                            ProductionFund productionFund = new ProductionFund();
-                            productionFund.setProductionType(production.getProduction());
-                            productionFund.setBusinessType(MainBusinessEnum.MAJOR_BUSINESS.name());
-                            productionFund.setOrderFundId(orderReportDTO.getOrderFundId());
-                            productionFund.setBusinessId(production.getMajorId());
-                            productionFund.setProductionNo(production.getReportNo());
-                            productionFund.setRealAmount(reportDTO.getRealAmount());
-                            productionFund.setEvaluateAmount(reportDTO.getEvaluateAmount());
-                            productionFundService.add(productionFund);
-                  //      }
-//                        else {
-//                            productionFundService.update(new LambdaUpdateWrapper<ProductionFund>().set(ProductionFund::getRealAmount,reportDTO.getRealAmount()).eq(BaseEntity::getId,reportDTO.getProductionFundId()));
-//                        }
-                    }
+    @Override
+    public synchronized Boolean allotRealAmountToOrder(List<OrderReportDTO> claimOrders) {
+        return majorProductionService.doAllotRealAmountToOrder(claimOrders);
+    }
+    @Override
+    public Boolean doAllotRealAmountToOrder(List<OrderReportDTO> claimOrders) {
+        if (CollectionUtil.isNotEmpty(claimOrders)){
+            //先校验各订单此次认领金额之和是否大于这笔实收款的剩余金额
+            Long financeFundId = claimOrders.get(0).getFinanceFundId();
+            BigDecimal residueAmount = financeClaimService.checkFinanceFound(financeFundId);
+            BigDecimal thisTimeTotalAmount = claimOrders.stream().map(OrderReportDTO::getThisTimeAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            if (thisTimeTotalAmount.compareTo(residueAmount)>0){
+                ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"本次订单认领之和大于实收款剩余金额,请检查后再认领。");
+                return Boolean.FALSE;
+            }
 
-                }
-                //更新订单收款变实收款金额
+            for (OrderReportDTO orderReportDTO : claimOrders){
+                BigDecimal thisTimeAmount = orderReportDTO.getThisTimeAmount();
+                //更新订单实收款
+                Long orderFundId = orderReportDTO.getOrderFundId();
                 orderFundMapper.updateRealAmount(orderFundId, thisTimeAmount);
-            }
 
+                //插入订单认领流水表
+                FinanceClaim financeClaim = new FinanceClaim();
+                Long userId = LoginContext.getCurrentUserId();
+                financeClaim.setClaimUserId(userId);
+                financeClaim.setRealFundId(financeFundId);
+                financeClaim.setOrderFundId(orderFundId);
+                financeClaim.setClaimAmount(thisTimeAmount);
+                financeClaim.setClaimDatetime(LocalDateTime.now());
+                financeClaimService.add(financeClaim);
+            }
             return Boolean.TRUE;
         }
         return Boolean.FALSE;
     }
-
     @Override
     public Page<TaskTodoVO> todoSaveFilePage(Page page, TaskTodoVO todoVO,String keyword) {
         todoVO.setHandlerId(LoginContext.getCurrentUserId());
@@ -537,6 +545,7 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
         return Boolean.FALSE;
     }
 
+
     @Override
     public Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, MajorProductionPerformanceVO productionPerformance) {
         Page<MajorProductionPerformanceVO> result = majorProductionMapper.performanceAllotPage(page,productionPerformance,LoginContext.getCurrentUserId());
@@ -550,6 +559,8 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
         return result;
     }
 
+
+
     @Override
     public Boolean repertoryIn(TaskRecordDTO<Long> taskRecordDTO) {
         Long productionId = taskRecordDTO.getTaskData();

+ 3 - 0
service/src/main/java/com/dayou/service/impl/MessageServiceImpl.java

@@ -158,6 +158,9 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
                 return Boolean.FALSE;
             }
             messageBO.setSender(originDeclare.getDeclareUserId());
+            if (order.getPrincipalId()==null){
+                return Boolean.FALSE;
+            }
             messageBO.setReceiver(order.getPrincipalId());
             String evaluator = userService.getOne(new LambdaQueryWrapper<User>().select(User::getName).eq(BaseEntity::getId, order.getPrincipalId())).getName();
             template  = evaluator + template;