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

    <!-- 通用查询映射结果 -->
    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.XmFinanceEntity">
        <id column="id" property="id"/>
        <result column="xm_id" property="xmId"/>
        <result column="XMBH" property="xmbh"/>
        <result column="XMMC" property="xmmc"/>
        <result column="lxpw" property="lxpw"/>
        <result column="lxbg" property="lxbg"/>
        <result column="qtzl" property="qtzl"/>
        <result column="type" property="type"/>
        <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>

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

    <select id="selectXmFinanceList" resultMap="ResultMap">
        SELECT kxf.*, xm.XMBH, xm.XMMC,xm.lxpw,xm.lxbg,xm.qtzl
        FROM kd_xm_finance kxf
        LEFT JOIN
        (
           SELECT
              xm.id,
              xm.XMBH,
              COALESCE(get_xm_info(xm.id, 'XMMC', #{ew.yearAndMonth}),XMMC) AS XMMC,
              xm.XMKSSJ,
              COALESCE(get_xm_info(xm.id, 'XMJSSJ', #{ew.yearAndMonth}),XMJSSJ) AS XMJSSJ,
              xm.lxpw,
              xm.lxbg,
              xm.qtzl
           FROM kd_xm xm
        ) xm ON xm.id = kxf.xm_id
        WHERE kxf.year_and_month = #{ew.yearAndMonth} and kxf.type = #{ew.type}
        <if test="ew.xmmc!=null and ew.xmmc!=''">and xm.XMMC like concat('%',#{ew.xmmc},'%')</if>
        order by xm.XMKSSJ asc
    </select>
</mapper>
