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

    <!-- 通用查询映射结果 -->
    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.XmJtbEntity">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="XM_ID" property="xmId"/>
        <result column="YSBG" property="ysbg"/>
        <result column="JSBG" property="jsbg"/>
        <result column="CGBG" property="cgbg"/>
        <result column="XYBG" property="xybg"/>
        <result column="YSPW" property="yspw"/>
        <result column="TBSJ" property="tbsj"/>
        <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.XmJtbVO" extends="ResultMap">

    </resultMap>

    <select id="selectByCondition" resultMap="ResultVoMap">
        SELECT
            kxj.id, kxj.XM_ID, kxj.tbsj, kxj.ysbg,kxj.jsbg,kxj.cgbg,kxj.xybg,kxj.yspw,kxj.status,
            xm.xmbh as 'xmEntity.xmbh',
            COALESCE(get_xm_info(kxj.XM_ID,'XMMC',date_format(kxj.tbsj,'%Y%m%d')), xm.XMMC ) AS 'xmEntity.xmmc',
            COALESCE(get_xm_info(kxj.XM_ID,'XMFZR',date_format(kxj.tbsj,'%Y%m%d')),xm.XMFZR) AS 'xmEntity.xmfzr',
            COALESCE(get_xm_info(kxj.XM_ID,'XMSQDWID',date_format(kxj.tbsj,'%Y%m%d')),xm.XMSQDWID) AS 'xmEntity.xmsqdwid',
            xm.XMKSSJ as 'xmEntity.xmkssj',
            COALESCE(get_xm_info(kxj.XM_ID,'XMJSSJ',date_format(kxj.tbsj,'%Y%m%d')),xm.XMJSSJ) AS 'xmEntity.xmjssj',
            xm.YJLX as 'xmEntity.yjlx',
            xm.XMLY as 'xmEntity.xmly',
            xm.XMKZXS as 'xmEntity.xmkzxs',
            xm.YQCGXS as 'xmEntity.yqcgxs',
            xm.XMJSJJMB as 'xmEntity.xmjsjjmb'
        FROM kd_xm_jtb kxj
        left join kd_xm xm on kxj.xm_id = xm.id
        WHERE kxj.xm_id = #{xmId}
    </select>

    <select id="getStatusByXmId" resultType="java.lang.Integer" parameterType="java.lang.Long">
        select status from kd_xm_jtb where xm_id = #{xmId}
    </select>

</mapper>
