<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.loanpricing.mapper.LoanPricingWorkflowMapper">

    <select id="selectWorkflowPageWithRates" resultType="com.ruoyi.loanpricing.domain.vo.LoanPricingWorkflowListVO">
        SELECT
            lpw.serial_num AS serialNum,
            lpw.cust_name AS custName,
            lpw.cust_type AS custType,
            lpw.guar_type AS guarType,
            lpw.apply_amt AS applyAmt,
            CASE
                WHEN lpw.cust_type = '个人' THEN mr.final_calculate_rate
                WHEN lpw.cust_type = '企业' THEN mc.calculate_rate
                ELSE NULL
            END AS calculateRate,
            lpw.execute_rate AS executeRate,
            lpw.create_time AS createTime,
            lpw.create_by AS createBy
        FROM loan_pricing_workflow lpw
        LEFT JOIN model_retail_output_fields mr ON lpw.model_output_id = mr.id
        LEFT JOIN model_corp_output_fields mc ON lpw.model_output_id = mc.id
        <where>
            <if test="query != null and query.createBy != null and query.createBy != ''">
                AND lpw.create_by LIKE CONCAT('%', #{query.createBy}, '%')
            </if>
            <if test="query != null and query.custIsn != null and query.custIsn != ''">
                AND lpw.cust_isn LIKE CONCAT('%', #{query.custIsn}, '%')
            </if>
            <if test="query != null and query.orgCode != null and query.orgCode != ''">
                AND lpw.org_code LIKE CONCAT('%', #{query.orgCode}, '%')
            </if>
        </where>
        ORDER BY lpw.update_time DESC
    </select>

</mapper>
