ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml
@@ -53,6 +53,8 @@
        tc.name as contractName,
        tcr.which_year,
        tcr.which_month,
        tcr.which_day,
        MAX(tcr.which_day) AS latest_day,
        SUM(tcr.deduct_money) AS deductMoney,
        MAX(tcr.which_month) AS latest_month,
        (
@@ -73,7 +75,7 @@
                AND tcr.status = #{query.status}
            </if>
        </where>
        group by contract_id,which_year
        group by contract_id, which_year,which_month
    </select>
    <resultMap id="DetailResultMap" type="com.ycl.platform.domain.vo.CalculateReportDetailVO">
        <result column="id" property="id"/>
@@ -83,10 +85,11 @@
        <result column="name" property="contractName"/>
        <result column="contract_id" property="contractId"/>
        <result column="which_year" property="whichYear"/>
        <result column="which_month" property="whichMonth"/>
        <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,status=status}" ofType="com.ycl.platform.domain.vo.CalculateRecordVO"
        <collection property="recordList" column="{contractId=contract_id, whichYear=which_year,status=status,whichMonth=which_month}" ofType="com.ycl.platform.domain.vo.CalculateRecordVO"
                    select="selectRecordByContractId"/>
    </resultMap>
@@ -107,6 +110,7 @@
        tcr.deduct_money as deductMoney,
        tcr.which_year as whichYear,
        tcr.which_month as whichMonth,
        tcr.which_day as whichDay,
        tcr.status
        FROM
        t_calculate_record tcr
@@ -117,11 +121,12 @@
                   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
            tcr.contract_id = #{contractId} AND tcr.which_year = #{whichYear} AND tcr.deleted = 0 AND tcr.which_month=#{whichMonth}
            <if test="status!=null">
                AND tcr.status=#{status}
            </if>
        </where>
        group by tcr.id
        ORDER BY
        tcr.create_time
    </select>
@@ -135,25 +140,42 @@
        tcr.create_time,
        tcr.update_time,
        tcr.which_year,
        tcr.which_month,
        #{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}
            tcr.contract_id = #{query.contractId} AND tcr.which_year = #{query.whichYear} AND tcr.which_month = #{query.whichMonth}
        </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(b.score), 0) AS score
        SELECT
        a.rule_name as ruleName,
        a.rule_condition as detailName,
        COUNT(b.id) AS num,
        a.calc_fraction as calcFraction,
        IFNULL(-SUM(b.score), 0) AS score
        FROM t_calculate_rule a
        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
        LEFT JOIN t_calculate_record tcr ON a.contract_id = tcr.contract_id
        LEFT JOIN t_contract_score b ON b.rule_id = a.id AND auditing_status = 'PASS' AND b.deleted = 0
            AND MONTH(b.create_time) = tcr.which_month
            AND YEAR(b.create_time) = tcr.which_year
        <where>
            a.deleted = 0 and a.contract_id = #{contractId}
            <if test="whichMonth!=null">
                and tcr.which_month = #{whichMonth}
            </if>
            <if test="whichYear!=null">
                and tcr.which_year = #{whichYear}
            </if>
            <if test="whichDay!=null">
                and tcr.which_day = #{whichDay}
            </if>
        </where>
        GROUP BY a.id
    </select>
</mapper>