<?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.usoft.fin.grpc.dal.mapper.CreditApplyMapper">

    <select id="findByCode" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_credit_apply
        where code = #{code}
    </select>

    <select id="findByParentCode" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_credit_apply
        where parent_code = #{parentCode}
    </select>


    <select id="findByProductCodeAndEnuu" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_credit_apply
        where product_code = #{productCode} and enuu = #{enuu}
    </select>

    <resultMap id="CreditApplyVOResultMap" type="com.usoft.fin.grpc.dal.entity.vo.CreditApplyVO"
               extends="BaseResultMap">
        <result column="product_name" property="productName" jdbcType="VARCHAR"/>
        <result column="credit_code" property="creditCode" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="findCreditApplyVOByEnuuAndPage" resultMap="CreditApplyVOResultMap">
        select
        <include refid="Table_Base_Column_List"/>,t_product.name as product_name, t_credit.code as credit_code
        from t_credit_apply
        LEFT JOIN t_product on t_credit_apply.product_code = t_product.code
        LEFT JOIN t_credit on t_credit_apply.code = t_credit.credit_apply_code
        where t_credit_apply.enuu = #{enuu} and <![CDATA[ t_credit_apply.status <> 103 ]]>  limit #{start},
        #{pageSize}
    </select>

    <select id="countByEnuu" resultType="java.lang.Integer">
        select count(1)
        from t_credit_apply
        where enuu = #{enuu}
    </select>


</mapper>