<?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.ZatbInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="zatbInfoResultMap" type="org.springblade.modules.sqmy.pojo.entity.ZatbInfoEntity">
        <result column="tbbt" property="tbbt"/>
        <result column="bgqk" property="bgqk"/>
        <result column="jmyj" property="jmyj"/>
        <result column="fj" property="fj"/>
    </resultMap>

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

    <select id="exportZatbInfo" resultType="org.springblade.modules.sqmy.excel.ZatbInfoExcel">
        SELECT * FROM zatb_info ${ew.customSqlSegment}
    </select>

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

</mapper>
