<?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.master.product.mapper.ProdMapper">
    <resultMap type="Prod" id="ProdResult">
        <result property="id"    column="id"    />
        <result property="prodClassId"    column="prodClassId"    />
        <result property="prodName"    column="prodName"    />
        <result property="ipId"    column="ipId"    />
        <result property="designerId"    column="designerId"    />
        <result property="description"    column="description"    />
        <result property="prodStatus"    column="prodStatus"    />
        <result property="thirdIdConfirmFlag"    column="thirdIdConfirmFlag"    />
        <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="selectProd">
        select id, prodClassId, prodName, ipId, designerId, description, prodStatus, thirdIdConfirmFlag, delFlag, createUser, createTime, updateUser, updateTime from m_prod
    </sql>

    <select id="selectProdList" parameterType="Prod" resultMap="ProdResult">
        <include refid="selectProd"/>
        <where>  
            <if test="prodClassId != null "> and prodClassId = #{prodClassId}</if>
            <if test="prodName != null  and prodName != ''"> and prodName like concat('%', #{prodName}, '%')</if>
            <if test="ipId != null "> and ipId = #{ipId}</if>
            <if test="designerId != null "> and designerId = #{designerId}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="prodStatus != null  and prodStatus != ''"> and prodStatus = #{prodStatus}</if>
            <if test="thirdIdConfirmFlag != null  and thirdIdConfirmFlag != ''"> and thirdIdConfirmFlag = #{thirdIdConfirmFlag}</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="selectProdById" parameterType="Long" resultMap="ProdResult">
        <include refid="selectProd"/>
        where id = #{id}
    </select>
        
    <insert id="insertProd" parameterType="Prod" useGeneratedKeys="true" keyProperty="id">
        insert into m_prod
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prodClassId != null">prodClassId,</if>
            <if test="prodName != null">prodName,</if>
            <if test="ipId != null">ipId,</if>
            <if test="designerId != null">designerId,</if>
            <if test="description != null">description,</if>
            <if test="prodStatus != null">prodStatus,</if>
            <if test="thirdIdConfirmFlag != null">thirdIdConfirmFlag,</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="prodClassId != null">#{prodClassId},</if>
            <if test="prodName != null">#{prodName},</if>
            <if test="ipId != null">#{ipId},</if>
            <if test="designerId != null">#{designerId},</if>
            <if test="description != null">#{description},</if>
            <if test="prodStatus != null">#{prodStatus},</if>
            <if test="thirdIdConfirmFlag != null">#{thirdIdConfirmFlag},</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="batchInsertProd">
        insert into m_prod( prodClassId, prodName, ipId, designerId, description, prodStatus, thirdIdConfirmFlag, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.prodClassId}, #{item.prodName}, #{item.ipId}, #{item.designerId}, #{item.description}, #{item.prodStatus}, #{item.thirdIdConfirmFlag}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProd" parameterType="Prod">
        update m_prod
        <trim prefix="SET" suffixOverrides=",">
            <if test="prodClassId != null">prodClassId = #{prodClassId},</if>
            <if test="prodName != null">prodName = #{prodName},</if>
            <if test="ipId != null">ipId = #{ipId},</if>
            <if test="designerId != null">designerId = #{designerId},</if>
            <if test="description != null">description = #{description},</if>
            <if test="prodStatus != null">prodStatus = #{prodStatus},</if>
            <if test="thirdIdConfirmFlag != null">thirdIdConfirmFlag = #{thirdIdConfirmFlag},</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 id = #{id}
    </update>

    <delete id="deleteProdById" parameterType="Long">
        delete from m_prod where id = #{id}
    </delete>

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

    <update id="logicDeleteProdById" parameterType="Long">
        update m_prod
            set delFlag = '1'
        where id = #{id}
    </update>

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

    <update id="logicDeleteProdByCondition" parameterType="Prod">
        update m_prod
        set delFlag = '1'
        <where>
            <if test="prodClassId != null "> and prodClassId = #{prodClassId}</if>
            <if test="prodName != null  and prodName != ''"> and prodName like concat('%', #{prodName}, '%')</if>
            <if test="ipId != null "> and ipId = #{ipId}</if>
            <if test="designerId != null "> and designerId = #{designerId}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="prodStatus != null  and prodStatus != ''"> and prodStatus = #{prodStatus}</if>
            <if test="thirdIdConfirmFlag != null  and thirdIdConfirmFlag != ''"> and thirdIdConfirmFlag = #{thirdIdConfirmFlag}</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>