<?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.ruoyi.project.system.mapper.ProductCraftMapper">

    <resultMap type="ProductCraft" id="ProductCraftResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="productId" column="product_id"/>
        <result property="materialId" column="material_id"/>
        <result property="cateId" column="cate_id"/>
        <result property="compute" column="compute"/>
        <result property="repel" column="repel"/>
        <result property="arg" column="arg"/>
        <result property="minPrice" column="min_price"/>
        <result property="openParams" column="open_params"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectProductCraftVo">
        select id,
               title,
               product_id,
               material_id,
               cate_id,
               compute,
               repel,
               arg,
               min_price,
               open_params,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from product_craft
    </sql>

    <select id="selectProductCraftList" parameterType="ProductCraft" resultMap="ProductCraftResult">
        <include refid="selectProductCraftVo"/>
        <where>
            <if test="title != null  and title != ''">and title = #{title}</if>
            <if test="productId != null ">and product_id = #{productId}</if>
            <if test="openParams != null ">and open_params = #{openParams}</if>
            <if test="materialId != null ">and material_id = #{materialId}</if>
            <if test="compute != null  and compute != ''">and compute = #{compute}</if>
            <if test="repel != null  and repel != ''">and repel = #{repel}</if>
            <if test="minPrice != null ">and min_price = #{minPrice}</if>
            and del_flag='0'
        </where>
    </select>

    <select id="selectProductCraftById" parameterType="Long" resultMap="ProductCraftResult">
        <include refid="selectProductCraftVo"/>
        where id = #{id} and del_flag='0'
    </select>

    <select id="selectProductCraftByIds" parameterType="List" resultMap="ProductCraftResult">
        <include refid="selectProductCraftVo"/>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
        and del_flag='0'
    </select>

    <insert id="insertProductCraft" parameterType="ProductCraft" useGeneratedKeys="true" keyProperty="id">
        insert into product_craft
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="productId != null">product_id,</if>
            <if test="materialId != null">material_id,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="openParams != null">open_params,</if>
            <if test="compute != null">compute,</if>
            <if test="repel != null">repel,</if>
            <if test="arg != null">arg,</if>
            <if test="minPrice != null">min_price,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            create_time,update_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="productId != null">#{productId},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="openParams != null">#{openParams},</if>
            <if test="compute != null">#{compute},</if>
            <if test="repel != null">#{repel},</if>
            <if test="arg != null">#{arg},</if>
            <if test="minPrice != null">#{minPrice},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            sysdate(),sysdate()
        </trim>
    </insert>

    <update id="updateProductCraft" parameterType="ProductCraft">
        update product_craft
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="openParams != null">open_params = #{openParams},</if>
            <if test="compute != null">compute = #{compute},</if>
            <if test="repel != null">repel = #{repel},</if>
            <if test="arg != null">arg = #{arg},</if>
            <if test="minPrice != null">min_price = #{minPrice},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate()
        </trim>
        where id = #{id}
    </update>

    <update id="deleteProductCraftById" parameterType="Long">
        update product_craft
        set del_flag = '2'
        where id = #{id}
    </update>

    <update id="deleteByProductId" parameterType="Long">
        update product_craft
        set del_flag = '2'
        <where>
            <if test="productId != null ">and product_id = #{productId}</if>
            <if test="materialId != null ">and material_id = #{materialId}</if>
            and del_flag = '0'
        </where>
    </update>

    <delete id="deleteProductCraftByIds" parameterType="String">
        update product_craft
        set del_flag = '2' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>