<?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="com.chinaweal.aiccs.aiccs.abnormal.mapper.TSWritMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.TSWrit">
        <id column="WRITSID" property="writsid" />
        <result column="BIZSEQ" property="bizseq" />
        <result column="PRIPID" property="pripid" />
        <result column="WRITSNO" property="writsno" />
        <result column="WRITSNAME" property="writsname" />
        <result column="WRITSTYPE" property="writstype" />
        <result column="PATH" property="path" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="CONTENT" property="content" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="CREATETIME" property="createtime" />
    </resultMap>
    <resultMap id="EntWritsMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.EntWritsDto">
        <id column="WRITSID" property="writsid" />
        <result column="BIZSEQ" property="bizseq" />
        <result column="PRIPID" property="pripid" />
        <result column="WRITSNO" property="writsno" />
        <result column="WRITSNAME" property="writsname" />
        <result column="WRITSTYPE" property="writstype" />
        <result column="PATH" property="path" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="CREATETIME" property="createtime" />
        <result column="UNISCID" property="uniscid" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        WRITSID, BIZSEQ, PRIPID, WRITSNO, WRITSNAME, WRITSTYPE, PATH, LAUPTIME, AREA_CODE, CREATETIME, CONTENT
    </sql>

    <select id="listTswrit" resultMap="BaseResultMap" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSWrit">
        select
        <include refid="Base_Column_List"/>
        from tswrit WHERE 1=1
        <if test="writsid != null">
            AND WRITSID = #{writsid}
        </if>
        <if test="bizseq != null">
            AND BIZSEQ = #{bizseq}
        </if>
        <if test="pripid != null">
            AND PRIPID = #{pripid}
        </if>
        <if test="writsno != null">
            AND WRITSNO = #{writsno}
        </if>
        <if test="writstype != null">
            AND WRITSTYPE = #{writstype}
        </if>
        <if test="writsname != null">
            AND WRITSNAME = #{writsname}
        </if>
        <if test="lauptime != null">
            AND LAUPTIME = #{lauptime}
        </if>

        order by lauptime desc
    </select>
    <select id="selectEntWrits" resultMap="EntWritsMap" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.EntWritsDto">
        SELECT w.WRITSID, w.BIZSEQ, w.PRIPID, w.WRITSNO, w.WRITSNAME, w.WRITSTYPE, w.PATH, w.CREATETIME
        FROM tswrit w
        <where>
<!--            <if test="entWritsModel.regno != '' and entWritsModel.regno != null">-->
<!--                and e.REGNO = #{entWritsModel.regno}-->
<!--            </if>-->
<!--            <if test="entWritsModel.uniscid != '' and entWritsModel.uniscid != null">-->
<!--                and e.UNISCID = #{entWritsModel.uniscid}-->
<!--            </if>-->
<!--            <if test="entWritsModel.entname != '' and entWritsModel.entname != null">-->
<!--                and e.ENTNAME like concat('%',#{entWritsModel.entname},'%')-->
<!--            </if>-->
            <if test="entWritsModel.writsno != '' and entWritsModel.writsno != null">
                and w.WRITSNO like concat('%',#{entWritsModel.writsno},'%')
            </if>
            <if test="entWritsModel.pripids != null and entWritsModel.pripids != '' ">
                and w.pripid in
                <foreach collection="entWritsModel.pripids" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
            </if>
        </where>
        ORDER BY w.CREATETIME DESC
    </select>


    <select id="selectTsWritByMap" resultMap="BaseResultMap" parameterType="java.util.HashMap">
        select
        <include refid="Base_Column_List"/>
        from tswrit WHERE 1=1
        <if test="paramTwr.bizseq != null and paramTwr.bizseq != ''">
            AND BIZSEQ = #{paramTwr.bizseq,jdbcType=VARCHAR}
        </if>
        <if test="paramTwr.pripid != null and paramTwr.pripid != ''">
            AND PRIPID = #{paramTwr.pripid,jdbcType=VARCHAR}
        </if>
    </select>

    <select id="selectWnbBatchPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.EntWritsDto">
        select <include refid="Base_Column_List"/>
        from tswrit
        <where>
            WRITSTYPE = '17'
        </where>
        order by CREATETIME desc
    </select>

    <insert id="saveBatchWithList" parameterType="java.util.List">
        insert into tswrit (WRITSID,BIZSEQ,AREA_CODE,WRITSNO,WRITSTYPE,PRIPID,WRITSNAME,CREATETIME,CONTENT) values
        <foreach collection="list" index="index" item="item" separator=",">
            ( #{item.writsid,jdbcType=VARCHAR},
            #{item.bizseq,jdbcType=VARCHAR},
            #{item.areaCode,jdbcType=VARCHAR},
            #{item.writsno,jdbcType=VARCHAR},
            #{item.writstype,jdbcType=VARCHAR},
            #{item.pripid,jdbcType=VARCHAR},
            #{item.writsname,jdbcType=VARCHAR},
            #{item.createtime,jdbcType=TIMESTAMP},
            #{item.content,jdbcType=VARCHAR}
            )
        </foreach>
    </insert>

    <select id="queryByEntParam" resultMap="EntWritsMap" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.EntWritsDto">
        SELECT eb.regno, eb.uniscid, eb.entname, ts.* FROM aiccs.tswrit ts
        LEFT JOIN aiccs.e_baseinfo eb ON ts.pripid = eb.pripid
        WHERE ts.bizseq = #{customParamMap.bizseq}
        <if test="customParamMap.writstype != null and customParamMap.writstype != '' ">
            AND ts.writstype = #{customParamMap.writstype}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            AND eb.uniscid = #{customParamMap.uniscid}
        </if>
        <if test="customParamMap.entname != null and customParamMap.entname != '' ">
            AND eb.entname like concat('%', #{customParamMap.entname}, '%')
        </if>
    </select>
</mapper>
