<?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="org.springblade.modules.pfInfo.mapper.PfInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="infoResultMap" type="org.springblade.modules.pfInfo.entity.PfInfoEntity">
        <result column="id" property="id"/>
        <result column="sjhm" property="sjhm"/>
        <result column="yf" property="yf"/>
        <result column="pfx_id" property="pfxId"/>
        <result column="kfyy" property="kfyy"/>
        <result column="file" property="file"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>


    <select id="selectInfoPage" resultType="org.springblade.modules.pfInfo.vo.PfInfoVO">
        SELECT
            pi.id,
            bu.real_name,
            pi.sjhm,
            pi.yf,
            pi.pfx_id,
            pi.kfyy,
            pi.file,
            pi.create_time
        FROM
            pf_info pi
        LEFT JOIN blade_user bu ON bu.phone = pi.sjhm
        WHERE
            pi.sjhm = #{params.sjhm}
        AND pi.yf = substring(#{params.yf}, 1, 7)
          <if test="null != params.pfxId and '' != params.pfxId">
        AND pi.pfx_id :: text = #{params.pfxId}
          </if>
        AND pi.is_deleted = 0
    </select>

    <select id="pageApp" resultType="org.springblade.modules.pfInfo.vo.PfInfoVO">
        SELECT
            pi.id,
            bu.real_name,
            pi.sjhm,
            pi.yf,
            pi.pfx_id,
            pi.kfyy,
            pi.file,
            bdb.dict_value AS pfx,
            pi.create_time
        FROM
            pf_info pi
        LEFT JOIN blade_user bu ON bu.phone = pi.sjhm
        LEFT JOIN blade_dict_biz bdb ON bdb.id = pi.pfx_id
        WHERE
            pi.is_deleted = 0
        AND pi.create_user = #{params.userId}
    </select>

    <select id="exportInfo" resultType="org.springblade.modules.pfInfo.excel.PfInfoExcel">
        SELECT *
        FROM pf_info ${ew.customSqlSegment}
    </select>

    <select id="getDzbhdCs" resultType="int">
        SELECT
            COUNT ( ID )
        FROM
            pf_info
        WHERE
            sjhm = #{params.sjhm}
          AND yf = substring(#{params.yf}, 1, 7)
          AND pfx_id :: text = #{params.pfxId} :: text
          AND is_deleted = 0
    </select>
</mapper>
