<?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.xingxi.business.CopyrightApproval.mapper.CopyrightApprovalMapper">
    <resultMap type="CopyrightApproval" id="CopyrightApprovalResult">
        <result property="approvalId"    column="approvalId"    />
        <result property="approvalNo"    column="approvalNo"    />
        <result property="approvalStatus"    column="approvalStatus"    />
        <result property="prodId"    column="prodId"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectCopyrightApproval">
        select approvalId, approvalNo, approvalStatus, prodId, delFlag, createUser, createTime, updateUser, updateTime from t_copyright_approval
    </sql>

    <sql id="selectCopyrightApprovalExt">
        select
            ${tableAlias}.approvalId,
            ${tableAlias}.approvalNo,
            ${tableAlias}.approvalStatus,
            ${tableAlias}.prodId,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_copyright_approval ${tableAlias}
    </sql>

    <select id="selectCopyrightApprovalList" parameterType="CopyrightApproval" resultMap="CopyrightApprovalResult">
        <include refid="selectCopyrightApproval"/>
        <where>  
            <if test="approvalNo != null  and approvalNo != ''"> and approvalNo = #{approvalNo}</if>
            <if test="approvalStatus != null  and approvalStatus != ''"> and approvalStatus = #{approvalStatus}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectCopyrightApprovalByApprovalId" parameterType="Long" resultMap="CopyrightApprovalResult">
        <include refid="selectCopyrightApproval"/>
        where approvalId = #{approvalId}
    </select>
        
    <insert id="insertCopyrightApproval" parameterType="CopyrightApproval" useGeneratedKeys="true" keyProperty="approvalId">
        insert into t_copyright_approval
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="approvalNo != null">approvalNo,</if>
            <if test="approvalStatus != null">approvalStatus,</if>
            <if test="prodId != null">prodId,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="approvalNo != null">#{approvalNo},</if>
            <if test="approvalStatus != null">#{approvalStatus},</if>
            <if test="prodId != null">#{prodId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertCopyrightApproval">
        insert into t_copyright_approval( approvalNo, approvalStatus, prodId, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.approvalNo}, #{item.approvalStatus}, #{item.prodId}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateCopyrightApproval" parameterType="CopyrightApproval">
        update t_copyright_approval
        <trim prefix="SET" suffixOverrides=",">
            <if test="approvalNo != null">approvalNo = #{approvalNo},</if>
            <if test="approvalStatus != null">approvalStatus = #{approvalStatus},</if>
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where approvalId = #{approvalId}
    </update>

    <delete id="deleteCopyrightApprovalByApprovalId" parameterType="Long">
        delete from t_copyright_approval where approvalId = #{approvalId}
    </delete>

    <delete id="deleteCopyrightApprovalByApprovalIds" parameterType="String">
        delete from t_copyright_approval where approvalId in 
        <foreach item="approvalId" collection="array" open="(" separator="," close=")">
            #{approvalId}
        </foreach>
    </delete>

    <update id="logicDeleteCopyrightApprovalByApprovalId" parameterType="Long">
        update t_copyright_approval
            set delFlag = '1'
        where approvalId = #{approvalId}
    </update>

    <update id="logicDeleteCopyrightApprovalByApprovalIds" parameterType="String">
        update t_copyright_approval
        set delFlag = '1'
        where approvalId in
        <foreach item="approvalId" collection="array" open="(" separator="," close=")">
            #{approvalId}
        </foreach>
    </update>

    <update id="logicDeleteCopyrightApprovalByCondition" parameterType="CopyrightApproval">
        update t_copyright_approval
        set delFlag = '1'
        <where>
            <if test="approvalNo != null  and approvalNo != ''"> and approvalNo = #{approvalNo}</if>
            <if test="approvalStatus != null  and approvalStatus != ''"> and approvalStatus = #{approvalStatus}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>