From e23edcf2619ad46fd77a710fca6c21de78234bc0 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 07 一月 2025 17:33:06 +0800
Subject: [PATCH] 核算重构完成

---
 ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml |   70 +++++++++++++++++++++--------------
 1 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml
index 9733db3..67e03ba 100644
--- a/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml
+++ b/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml
@@ -52,8 +52,9 @@
         tyu.unit_name,
         tc.name as contractName,
         tcr.which_year,
+        tcr.which_month,
         SUM(tcr.deduct_money) AS deductMoney,
-        MAX(tcr.create_time) AS latest_time,
+        MAX(tcr.which_month) AS latest_month,
         (
         SELECT deduct_money
         FROM t_calculate_record
@@ -84,7 +85,7 @@
         <result column="status" property="status"/>
         <collection property="ruleList" column="contract_id" ofType="com.ycl.platform.domain.vo.CalculateMoneyRuleVO"
                     select="selectRuleByContractId"/>
-        <collection property="recordList" column="{contractId=contract_id, whichYear=which_year}" ofType="com.ycl.platform.domain.vo.CalculateRecordVO"
+        <collection property="recordList" column="{contractId=contract_id, whichYear=which_year,status=status}" ofType="com.ycl.platform.domain.vo.CalculateRecordVO"
                     select="selectRecordByContractId"/>
     </resultMap>
 
@@ -99,44 +100,57 @@
 
     <select id="selectRecordByContractId" resultType="com.ycl.platform.domain.vo.CalculateRecordVO">
         SELECT
-               id,
-               create_time  as createTime,
-               score,
-               deduct_money as deductMoney,
-               which_year as whichYear,
-               which_month as whichMonth,
-               status
+        tcr.id,
+        tcr.create_time as createTime,
+        (IFNULL(-SUM(tcs.score), 0) + 100) AS score,
+        tcr.deduct_money as deductMoney,
+        tcr.which_year as whichYear,
+        tcr.which_month as whichMonth,
+        tcr.status
         FROM
-             t_calculate_record
-        WHERE
-              contract_id = #{contractId} AND which_year = #{whichYear} AND deleted = 0
+        t_calculate_record tcr
+        LEFT JOIN t_contract_score tcs
+            ON tcr.contract_id =tcs.contract_id
+                   AND tcs.deleted=0
+                   AND YEAR(tcs.create_time) = #{whichYear}
+                   AND MONTH(tcs.create_time) = tcr.which_month
+                   AND tcs.auditing_status = 'PASS'
+        <where>
+            tcr.contract_id = #{contractId} AND tcr.which_year = #{whichYear} AND tcr.deleted = 0
+            <if test="status!=null">
+                AND tcr.status=#{status}
+            </if>
+        </where>
         ORDER BY
-            create_time
+        tcr.create_time
     </select>
 
     <select id="getById" resultMap="DetailResultMap">
         SELECT tyu.unit_name,
-               tc.name,
-               tcr.id,
-               tcr.contract_id,
-               tcr.create_time,
-               tcr.update_time,
-               tcr.which_year
+        tc.name,
+        tcr.id,
+        tcr.contract_id,
+        tcr.create_time,
+        tcr.update_time,
+        tcr.which_year,
+        #{query.status} as status
         FROM t_calculate_record tcr
-                 INNER JOIN t_contract tc ON tcr.contract_id = tc.id
-                 INNER JOIN t_yw_unit tyu ON tyu.id = tc.unit_id
-        WHERE tcr.contract_id = #{query.contractId} AND tcr.which_year = #{query.whichYear}
+        INNER JOIN t_contract tc ON tcr.contract_id = tc.id
+        INNER JOIN t_yw_unit tyu ON tyu.id = tc.unit_id
+        <where>
+            tcr.contract_id = #{query.contractId} AND tcr.which_year = #{query.whichYear}
+        </where>
         limit 1
     </select>
 
     <select id="exportData" resultType="com.ycl.platform.domain.excel.CalculateExport">
-        SELECT
-            a.rule_name,
-            COUNT(b.id) AS num,
-            IFNULL(-SUM(score), 0) AS score
+        SELECT a.rule_name,
+               COUNT(b.id)              AS num,
+               IFNULL(-SUM(b.score), 0) AS score
         FROM t_calculate_rule a
-        LEFT JOIN t_contract_score b ON b.rule_id = a.id AND auditing_status = 'PASS' AND b.deleted = 0
-        WHERE a.contract_id = #{contractId} AND a.deleted = 0
+        LEFT JOIN t_calculate_record tcr ON a.contract_id = tcr.contract_id And tcr.id = #{calculateId}
+        LEFT JOIN t_contract_score b ON b.rule_id = a.id AND auditing_status = 'PASS' AND b.deleted = 0 AND YEAR (b.create_time) = tcr.which_year
+        WHERE a.deleted = 0
         GROUP BY a.rule_name
     </select>
 

--
Gitblit v1.8.0