<?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.sky.scientific.mapper.XmCqdtfyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.XmCqdtfyEntity">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="year_and_month" property="yearAndMonth"/>
        <result column="xm_id" property="xmId"/>
        <result column="ctdtfybm" property="ctdtfybm"/>
        <result column="ctdtfymc" property="ctdtfymc"/>
        <result column="yt" property="yt"/>
        <result column="txksrq" property="txksrq"/>
        <result column="sysm" property="sysm"/>
        <result column="ysyys" property="ysyys"/>
        <result column="zcyz" property="zcyz"/>
        <result column="ytxe" property="ytxe"/>
        <result column="syzb" property="syzb"/>
        <result column="zbyj" property="zbyj"/>
        <result column="ftyj" property="ftyj"/>
        <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>

    <resultMap id="ResutVoMap" type="org.sky.scientific.pojo.vo.XmCqdtfyVO">
        <result  column="xmbh" property="xmbh"/>
        <result  column="xmmc" property="xmmc"/>
    </resultMap>

    <delete id="physicalDeleteByIds">
        DELETE FROM kd_xm_cqdtfy
        WHERE id IN
        <foreach item="item" index="index" collection="list" separator="," close=")" open="(">
            #{item}
        </foreach>
    </delete>


    <select id="selectPageByCondition" resultMap="ResutVoMap" parameterType="org.sky.scientific.pojo.dto.XmCqdtfyDTO">
        select c.*,xm.xmbh, xm.xmmc
        FROM kd_xm_cqdtfy c
        LEFT JOIN
        (
            SELECT
                xm.id,
                xm.XMBH,
                COALESCE(get_xm_info(xm.id, 'XMMC',#{ew.yearAndMonth}),XMMC) AS XMMC
            FROM kd_xm xm
            WHERE xm.is_deleted = 0
        ) xm on xm.id = c.xm_id
        where left(c.year_and_month,6 ) = #{ew.yearAndMonth}
        <if test="ew.xmId != null">and c.xm_id = #{ew.xmId}</if>
        <if test="ew.xmmc != null and ew.xmmc != ''">and xm.xmmc like concat('%',#{ew.xmmc},'%')</if>
        <if test="ew.ctdtfymc != null and ew.ctdtfymc != ''">and c.ctdtfybm like concat('%',#{ew.ctdtfymc},'%')</if>
        <if test="ew.yt != null and ew.yt != ''">and c.yt = #{ew.yt}</if>
        <if test="ew.txksrqStart != null and ew.txksrqEnd">and c.txksrq between #{ew.txksrqStart} and #{ew.txksrqEnd}</if>
        <if test="ew.ysyysStart != null and ew.ysyysEnd!= null">and c.ysyys between #{ew.ysyysStart} and #{ew.ysyysEnd}</if>
        <if test="ew.zcyzStart != null and ew.zcyzEnd!= null">and c.zcyz between #{ew.zcyzStart} and #{ew.zcyzEnd}</if>
        <if test="ew.yzjeStart != null and ew.yzjeEnd!= null">and c.yzje between #{ew.yzjeStart} and #{ew.yzjeEnd}</if>
    </select>

</mapper>
