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

    <!-- 通用查询映射结果 -->
    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.XmWwxmEntity">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="XM_ID" property="xmId"/>
        <result column="year_and_month" property="yearAndMonth"/>
        <result column="STFQC" property="stfqc"/>
        <result column="STFLX" property="stflx"/>
        <result column="HTMC" property="htmc"/>
        <result column="WWFYJE" property="wwfyje"/>
        <result column="SFWCJSHTDJ" property="sfwcjshtdj"/>
        <result column="JSHTDJLX" property="jshtdjlx"/>
        <result column="JSHTDJJE" property="jshtdjje"/>
        <result column="JSHTXY" property="jshtxy"/>
        <result column="WWFYFP" property="wwfyfp"/>
        <result column="JSHTDJZM" property="jshtdjzm"/>
        <result column="STFJFCG" property="stfjfcg"/>
        <result column="QTZL" property="qtzl"/>
        <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="ResultVoMap" type="org.sky.scientific.pojo.vo.XmWwxmVO" extends="ResultMap">
        <result column="XMMC" property="xmmc"/>
    </resultMap>

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


    <select id="selectXmWwxmPage" resultMap="ResultVoMap">
        SELECT w.*
        FROM kd_xm_wwxm w
        WHERE w.year_and_month = #{wwxm.yearAndMonth} and w.XM_ID = #{wwxm.xmId}
    </select>

    <select id="selectSimpleList" resultType="com.alibaba.fastjson.JSONObject">
        SELECT w.id as wwId, w.XM_ID as xmId,xm.XMMC as xmmc,w.STFQC as stfqc
        FROM kd_xm_wwxm w
        LEFT JOIN (
            SELECT
                temp.id as xm_id, XMBH,
                COALESCE(get_xm_info(temp.id, 'XMMC', #{yearAndMonth}), temp.XMMC ) AS XMMC
            FROM kd_xm temp
        ) xm ON w.xm_id = xm.xm_id
        WHERE w.year_and_month = LEFT(#{yearAndMonth},4)
    </select>

</mapper>
