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

    <!-- 通用查询映射结果 -->
    <resultMap id="sqmyInfoResultMap" type="org.springblade.modules.sqmy.pojo.entity.SqmyInfoEntity">
        <result column="xslx" property="xslx"/>
        <result column="fxsj" property="fxsj"/>
        <result column="fxdd" property="fxdd"/>
        <result column="xsnr" property="xsnr"/>
        <result column="fj" property="fj"/>
    </resultMap>

    <select id="selectSqmyInfoPage" resultType="org.springblade.modules.sqmy.pojo.vo.SqmyInfoVO">
        SELECT
            si.*
        FROM
            sqmy.sqmy_info si
        LEFT JOIN jdrh.blade_dept dept ON dept.id = si.create_dept
        WHERE
            si.is_deleted = 0
          AND (#{params.deptId} LIKE '%' || dept.id || '%' OR dept.ancestors LIKE '%' || #{params.deptId} || '%')
    </select>

    <select id="exportSqmyInfo" resultType="org.springblade.modules.sqmy.excel.SqmyInfoExcel">
        SELECT * FROM sqmy_info ${ew.customSqlSegment}
    </select>

    <select id="countByType" resultType="int">
        SELECT
            count(*)
        FROM
            sqmy.sqmy_info si
        LEFT JOIN jdrh.blade_dept dept ON dept.id = si.create_dept
        WHERE
            si.is_deleted = 0
          AND (#{params.deptId} LIKE '%' || dept.id || '%' OR dept.ancestors LIKE '%' || #{params.deptId} || '%')
        <if test="1 == type">
            AND si.create_time BETWEEN DATE_TRUNC( 'year', CURRENT_DATE ) AND DATE_TRUNC( 'year', CURRENT_DATE ) + INTERVAL '1 year'
        </if>
        <if test="2 == type">
            AND si.create_time BETWEEN DATE_TRUNC( 'quarter', CURRENT_DATE ) AND DATE_TRUNC( 'quarter', CURRENT_DATE ) + INTERVAL '3 months'
        </if>
        <if test="3 == type">
            AND si.create_time :: DATE = CURRENT_DATE
        </if>
    </select>
</mapper>
