<?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.sqmy.mapper.FzrhyInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="fzrhyInfoResultMap" type="org.springblade.modules.sqmy.pojo.entity.FzrhyInfoEntity">
        <result column="hyzt" property="hyzt"/>
        <result column="hynr" property="hynr"/>
        <result column="fj" property="fj"/>
    </resultMap>

    <select id="selectFzrhyInfoPage" resultMap="fzrhyInfoResultMap">
        SELECT
            fi.*
        FROM
            sqmy.fzrhy_info fi
        LEFT JOIN jdrh.blade_dept dept ON dept.id = fi.create_dept
        WHERE
            fi.is_deleted = 0
        AND (#{params.deptId} LIKE '%' || dept.id || '%' OR dept.ancestors LIKE '%' || #{params.deptId} || '%')
    </select>

    <select id="exportFzrhyInfo" resultType="org.springblade.modules.sqmy.excel.FzrhyInfoExcel">
        SELECT * FROM fzrhy_info ${ew.customSqlSegment}
    </select>

    <select id="getByFzrhy" resultType="org.springblade.modules.sqmy.pojo.entity.FzrhyInfoEntity">
        SELECT
            fi.*
        FROM
            sqmy.fzrhy_info fi
        LEFT JOIN jdrh.blade_dept dept ON dept.id = fi.create_dept
        WHERE
            fi.is_deleted = 0
          AND (#{params.deptId} LIKE '%' || dept.id || '%' OR dept.ancestors LIKE '%' || #{params.deptId} || '%')
          AND fi.create_time BETWEEN DATE_TRUNC('month', CURRENT_DATE) AND (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month')
        ORDER BY fi.create_time DESC
        LIMIT 1
    </select>
</mapper>
