<?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.ProductCraftParamsMapper">

    <resultMap type="ProductCraftParams" id="ProductCraftParamsResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="craftId" column="craft_id"/>
        <result property="productId" column="product_id"/>
        <result property="materialId" column="material_id"/>
        <result property="compute" column="compute"/>
        <result property="arg" column="arg"/>
        <result property="minPrice" column="min_price"/>
        <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="selectProductCraftParamsVo">
        select id,
               title,
               craft_id,
               compute,
               arg,
               product_id,
               material_id,
               min_price,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from product_craft_params
    </sql>

    <select id="selectProductCraftParamsList" parameterType="ProductCraftParams" resultMap="ProductCraftParamsResult">
        <include refid="selectProductCraftParamsVo"/>
        <where>
            <if test="title != null  and title != ''">and title = #{title}</if>
            <if test="craftId != null ">and craft_id = #{craftId}</if>
            <if test="productId != null ">and product_id = #{productId}</if>
            <if test="materialId != null ">and material_id = #{materialId}</if>
            <if test="compute != null  and compute != ''">and compute = #{compute}</if>
            <if test="minPrice != null ">and min_price = #{minPrice}</if>
            and del_flag='0'
        </where>
    </select>

    <select id="selectProductCraftParamsById" parameterType="Long" resultMap="ProductCraftParamsResult">
        <include refid="selectProductCraftParamsVo"/>
        where id = #{id} and del_flag='0'
    </select>
    <select id="selectProductCraftParamsByIds" parameterType="List" resultMap="ProductCraftParamsResult">
        <include refid="selectProductCraftParamsVo"/>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
        and del_flag='0'
    </select>

    <insert id="insertProductCraftParams" parameterType="ProductCraftParams">
        insert into product_craft_params
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null">title,</if>
            <if test="craftId != null">craft_id,</if>
            <if test="productId != null">product_id,</if>
            <if test="materialId != null">material_id,</if>
            <if test="compute != null">compute,</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="id != null">#{id},</if>
            <if test="title != null">#{title},</if>
            <if test="craftId != null">#{craftId},</if>
            <if test="productId != null">#{productId},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="compute != null">#{compute},</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="updateProductCraftParams" parameterType="ProductCraftParams">
        update product_craft_params
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="craftId != null">craft_id = #{craftId},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="compute != null">compute = #{compute},</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>

    <delete id="deleteProductCraftParamsById" parameterType="Long">
        update product_craft_params
        set del_flag = '2'
        where id = #{id}
    </delete>

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

    <update id="deleteByProductId" parameterType="Long">
        update product_craft_params
        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>
</mapper>