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

    <!-- 通用查询映射结果 -->
    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.CgKylwEntity">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="LWMC" property="lwmc"/>
        <result column="ZZXM" property="zzxm"/>
        <result column="TXZZ" property="txzz"/>
        <result column="DYZZDW" property="dyzzdw"/>
        <result column="FBRQ" property="fbrq"/>
        <result column="QKMC" property="qkmc"/>
        <result column="KJH" property="kjh"/>
        <result column="QKLX" property="qklx"/>
        <result column="QKJB" property="qkjb"/>
        <result column="attachment" property="attachment"/>
        <result column="XMBH" property="xmbh"/>
        <result column="XMMC" property="xmmc"/>
        <result column="XM_ID" property="xmId"/>
        <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>

    <select id="selectPageByCondition" resultMap="ResultMap" parameterType="org.sky.scientific.pojo.entity.CgKylwEntity">
        SELECT
            k.id,k.tenant_id,k.LWMC,k.ZZXM,k.TXZZ,k.DYZZDW,k.FBRQ,k.QKMC,k.KJH,k.QKLX,k.QKJB,k.XMBH,k.XM_ID,k.attachment,
            xm.XMMC
        FROM kd_cg_kylw k
        left join
        (
            select
                m.id,
                COALESCE(get_xm_info(m.id,'XMMC',null), XMMC) as XMMC
            from kd_xm m
        ) xm on xm.id = k.xm_id
        where k.tenant_id = #{ew.tenantId}
        <if test="ew.lwmc != null and ew.lwmc != ''">and k.lwmc like concat('%',#{ew.lwmc},'%')</if>
        <if test="ew.zzxm != null and ew.zzxm != ''">and k.zzxm like concat('%',#{ew.zzxm},'%')</if>
        <if test="ew.txzz != null and ew.txzz != ''">and k.txzz like concat('%',#{ew.txzz},'%')</if>
        <if test="ew.dyzzdw != null and ew.dyzzdw != ''">and k.dyzzdw like concat('%',#{ew.dyzzdw},'%')</if>
        <if test="ew.qklx != null and ew.qklx != ''">and k.qklx = #{ew.qklx}</if>
        <if test="ew.xmmc != null and ew.xmmc!=''">and xm.XMMC like concat('%',#{ew.xmmc},'%')</if>
        <if test="ew.xmbh != null and ew.xmbh!=''">and k.XMBH like concat('%',#{ew.xmbh},'%')</if>
        <if test="ew.xmIdList!=null and ew.xmIdList.size()>0">and k.xm_id in <foreach item="xmId" collection="ew.xmIdList" separator="," open="(" close=")">#{xmId}</foreach></if>
    </select>

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

</mapper>
