<?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.yunfeiyun.agmp.fms.mapper.TssSourceperiodMapper">
    
    <resultMap type="TssSourceperiod" id="TssSourceperiodResult">
        <result property="sourceperiodId"    column="sourceperiodId"    />
        <result property="sourceinfoId"    column="sourceinfoId"    />
        <result property="sourceperiodStartdate"    column="sourceperiodStartdate"    />
        <result property="sourceperiodEnddate"    column="sourceperiodEnddate"    />
        <result property="sourceperiodType"    column="sourceperiodType"    />
        <result property="sourceperiodParentid"    column="sourceperiodParentid"    />
        <result property="sourceperiodFmstaskrcdcreateddate"    column="sourceperiodFmstaskrcdcreateddate"    />
        <result property="sourceperiodFmstaskrcdremark"    column="sourceperiodFmstaskrcdremark"    />
        <result property="sourceperiodFmstaskrcdmanagername"    column="sourceperiodFmstaskrcdmanagername"    />
        <result property="sourceperiodName"    column="sourceperiodName"    />
    </resultMap>

    <sql id="selectTssSourceperiodVo">
        select sourceperiodId, sourceinfoId, sourceperiodStartdate, sourceperiodEnddate, sourceperiodType, sourceperiodParentid, sourceperiodFmstaskrcdcreateddate, sourceperiodFmstaskrcdremark, sourceperiodFmstaskrcdmanagername, sourceperiodName from TssSourceperiod
    </sql>

    <select id="selectTssSourceperiodList" parameterType="TssSourceperiod" resultMap="TssSourceperiodResult">
        <include refid="selectTssSourceperiodVo"/>
        <where>  
            <if test="sourceinfoId != null  and sourceinfoId != ''"> and sourceinfoId = #{sourceinfoId}</if>
            <if test="sourceperiodType != null  and sourceperiodType != ''"> and sourceperiodType = #{sourceperiodType}</if>
            <if test="sourceperiodParentid != null  and sourceperiodParentid != ''"> and sourceperiodParentid = #{sourceperiodParentid}</if>
            <if test="sourceperiodFmstaskrcdcreateddate != null  and sourceperiodFmstaskrcdcreateddate != ''"> and sourceperiodFmstaskrcdcreateddate = #{sourceperiodFmstaskrcdcreateddate}</if>
            <if test="sourceperiodFmstaskrcdremark != null  and sourceperiodFmstaskrcdremark != ''"> and sourceperiodFmstaskrcdremark = #{sourceperiodFmstaskrcdremark}</if>
            <if test="sourceperiodFmstaskrcdmanagername != null  and sourceperiodFmstaskrcdmanagername != ''"> and sourceperiodFmstaskrcdmanagername like concat('%', #{sourceperiodFmstaskrcdmanagername}, '%')</if>
            <if test="sourceperiodName != null  and sourceperiodName != ''"> and sourceperiodName like concat('%', #{sourceperiodName}, '%')</if>
        </where>
    </select>
    <select id="selectTssSourceperiodWithResList" parameterType="Object" resultType="TssSourceperiod">
        SELECT
        tsp.*,
        <if test="isOssCloudPolicy == false">
            sr.resUrl as periodPreview
        </if>
        <if test="isOssCloudPolicy == true">
            sr.resOssUrl as periodPreview
        </if>
        FROM
        TssSourceperiod tsp LEFT JOIN SysRes sr on tsp.sourceperiodId = sr.resBusId
        <where>
            <if test="tssSourceperiod.sourceinfoId != null  and tssSourceperiod.sourceinfoId != ''"> and sourceinfoId = #{tssSourceperiod.sourceinfoId}</if>
            <if test="tssSourceperiod.sourceperiodType != null  and tssSourceperiod.sourceperiodType != ''"> and sourceperiodType = #{tssSourceperiod.sourceperiodType}</if>
            <if test="tssSourceperiod.sourceperiodParentid != null  and tssSourceperiod.sourceperiodParentid != ''"> and sourceperiodParentid = #{tssSourceperiod.sourceperiodParentid}</if>
            <if test="tssSourceperiod.sourceperiodFmstaskrcdcreateddate != null  and tssSourceperiod.sourceperiodFmstaskrcdcreateddate != ''"> and sourceperiodFmstaskrcdcreateddate = #{tssSourceperiod.sourceperiodFmstaskrcdcreateddate}</if>
            <if test="tssSourceperiod.sourceperiodFmstaskrcdremark != null  and tssSourceperiod.sourceperiodFmstaskrcdremark != ''"> and sourceperiodFmstaskrcdremark = #{tssSourceperiod.sourceperiodFmstaskrcdremark}</if>
            <if test="tssSourceperiod.sourceperiodFmstaskrcdmanagername != null  and tssSourceperiod.sourceperiodFmstaskrcdmanagername != ''"> and sourceperiodFmstaskrcdmanagername like concat('%', #{tssSourceperiod.sourceperiodFmstaskrcdmanagername}, '%')</if>
            <if test="tssSourceperiod.sourceperiodName != null  and tssSourceperiod.sourceperiodName != ''"> and sourceperiodName like concat('%', #{tssSourceperiod.sourceperiodName}, '%')</if>
        </where>
    </select>
    
    <select id="selectTssSourceperiodBySourceperiodId" parameterType="String" resultMap="TssSourceperiodResult">
        <include refid="selectTssSourceperiodVo"/>
        where sourceperiodId = #{sourceperiodId}
    </select>
        
    <insert id="insertTssSourceperiod" parameterType="TssSourceperiod">
        insert into TssSourceperiod
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sourceperiodId != null">sourceperiodId,</if>
            <if test="sourceinfoId != null">sourceinfoId,</if>
            <if test="sourceperiodStartdate != null">sourceperiodStartdate,</if>
            <if test="sourceperiodEnddate != null">sourceperiodEnddate,</if>
            <if test="sourceperiodType != null">sourceperiodType,</if>
            <if test="sourceperiodParentid != null">sourceperiodParentid,</if>
            <if test="sourceperiodFmstaskrcdcreateddate != null">sourceperiodFmstaskrcdcreateddate,</if>
            <if test="sourceperiodFmstaskrcdremark != null">sourceperiodFmstaskrcdremark,</if>
            <if test="sourceperiodFmstaskrcdmanagername != null">sourceperiodFmstaskrcdmanagername,</if>
            <if test="sourceperiodName != null">sourceperiodName,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sourceperiodId != null">#{sourceperiodId},</if>
            <if test="sourceinfoId != null">#{sourceinfoId},</if>
            <if test="sourceperiodStartdate != null">#{sourceperiodStartdate},</if>
            <if test="sourceperiodEnddate != null">#{sourceperiodEnddate},</if>
            <if test="sourceperiodType != null">#{sourceperiodType},</if>
            <if test="sourceperiodParentid != null">#{sourceperiodParentid},</if>
            <if test="sourceperiodFmstaskrcdcreateddate != null">#{sourceperiodFmstaskrcdcreateddate},</if>
            <if test="sourceperiodFmstaskrcdremark != null">#{sourceperiodFmstaskrcdremark},</if>
            <if test="sourceperiodFmstaskrcdmanagername != null">#{sourceperiodFmstaskrcdmanagername},</if>
            <if test="sourceperiodName != null">#{sourceperiodName},</if>
         </trim>
    </insert>

    <insert id="insertTssSourceperiodBatch" parameterType="TssSourceperiod">
        insert into TssSourceperiod
        <trim prefix="(" suffix=")" suffixOverrides=",">
            sourceperiodId,
            sourceinfoId,
            sourceperiodStartdate,
            sourceperiodEnddate,
            sourceperiodType,
            sourceperiodParentid,
            sourceperiodFmstaskrcdcreateddate,
            sourceperiodFmstaskrcdremark,
            sourceperiodFmstaskrcdmanagername,
            sourceperiodName,
        </trim>
        values
        <foreach item="data" collection="list" separator=",">
            (
            #{data.sourceperiodId},
            #{data.sourceinfoId},
            #{data.sourceperiodStartdate},
            #{data.sourceperiodEnddate},
            #{data.sourceperiodType},
            #{data.sourceperiodParentid},
            #{data.sourceperiodFmstaskrcdcreateddate},
            #{data.sourceperiodFmstaskrcdremark},
            #{data.sourceperiodFmstaskrcdmanagername},
            #{data.sourceperiodName}
            )
        </foreach>
    </insert>


    <update id="updateTssSourceperiod" parameterType="TssSourceperiod">
        update TssSourceperiod
        <trim prefix="SET" suffixOverrides=",">
            <if test="sourceinfoId != null">sourceinfoId = #{sourceinfoId},</if>
            <if test="sourceperiodStartdate != null">sourceperiodStartdate = #{sourceperiodStartdate},</if>
            <if test="sourceperiodEnddate != null">sourceperiodEnddate = #{sourceperiodEnddate},</if>
            <if test="sourceperiodType != null">sourceperiodType = #{sourceperiodType},</if>
            <if test="sourceperiodParentid != null">sourceperiodParentid = #{sourceperiodParentid},</if>
            <if test="sourceperiodFmstaskrcdcreateddate != null">sourceperiodFmstaskrcdcreateddate = #{sourceperiodFmstaskrcdcreateddate},</if>
            <if test="sourceperiodFmstaskrcdremark != null">sourceperiodFmstaskrcdremark = #{sourceperiodFmstaskrcdremark},</if>
            <if test="sourceperiodFmstaskrcdmanagername != null">sourceperiodFmstaskrcdmanagername = #{sourceperiodFmstaskrcdmanagername},</if>
            <if test="sourceperiodName != null">sourceperiodName = #{sourceperiodName},</if>
        </trim>
        where sourceperiodId = #{sourceperiodId}
    </update>

    <update id="updateTssSourceperiodBatch" parameterType="list">
        <foreach collection="list" item="period" separator=";">
            update TssSourceperiod
            <trim prefix="SET" suffixOverrides=",">
                <if test="period.sourceinfoId != null">sourceinfoId = #{period.sourceinfoId},</if>
                <if test="period.sourceperiodStartdate != null">sourceperiodStartdate = #{period.sourceperiodStartdate},</if>
                <if test="period.sourceperiodEnddate != null">sourceperiodEnddate = #{period.sourceperiodEnddate},</if>
                <if test="period.sourceperiodType != null">sourceperiodType = #{period.sourceperiodType},</if>
                <if test="period.sourceperiodParentid != null">sourceperiodParentid = #{period.sourceperiodParentid},</if>
                <if test="period.sourceperiodFmstaskrcdcreateddate != null">sourceperiodFmstaskrcdcreateddate = #{period.sourceperiodFmstaskrcdcreateddate},</if>
                <if test="period.sourceperiodFmstaskrcdremark != null">sourceperiodFmstaskrcdremark = #{period.sourceperiodFmstaskrcdremark},</if>
                <if test="period.sourceperiodFmstaskrcdmanagername != null">sourceperiodFmstaskrcdmanagername = #{period.sourceperiodFmstaskrcdmanagername},</if>
                <if test="period.sourceperiodName != null">sourceperiodName = #{period.sourceperiodName},</if>
            </trim>
            where sourceperiodId = #{period.sourceperiodId}
        </foreach>
    </update>

    <delete id="deleteTssSourceperiodBySourceperiodId" parameterType="String">
        delete from TssSourceperiod where sourceperiodId = #{sourceperiodId}
    </delete>

    <delete id="deleteTssSourceperiodBySourceinfoId" parameterType="String">
        delete from TssSourceperiod where sourceinfoId = #{sourceinfoId}
    </delete>

    <delete id="deleteTssSourceperiodBySourceperiodIds" parameterType="String">
        delete from TssSourceperiod where sourceperiodId in 
        <foreach item="sourceperiodId" collection="array" open="(" separator="," close=")">
            #{sourceperiodId}
        </foreach>
    </delete>
</mapper>