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

    <resultMap type="Product" id="ProductResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="compute" column="compute"/>
        <result property="modes" column="modes" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>
        <result property="calculateEnum" column="calculate_enum"
                typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>
        <result property="computeStr" column="compute_str"/>
        <result property="basics" column="basics"/>
        <result property="formula" column="formula"/>
        <result property="styleCompute" column="style_compute"/>
        <result property="isShow" column="is_show"/>
        <result property="isMore" column="is_more"/>
        <result property="isParity" column="is_parity"/>
        <result property="power" column="power"/>
        <result property="remark" column="remark"/>
        <result property="images" column="images" typeHandler="com.ruoyi.common.handler.ListToVarcharTypeHandler"/>
        <result property="imageText" column="image_text"/>
        <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="selectProductVo">
        select id,
               title,
               compute,
               create_by,
               modes,
               compute_str,
               calculate_enum,
               formula,
               power,
               is_parity,
               basics,
               images,
               image_text,
               remark,
               style_compute,
               is_show,
               is_more,
               create_time
        from product
    </sql>

    <select id="selectFrontProductList" parameterType="Product" resultMap="ProductResult">
        <include refid="selectProductVo"/>
        <where>
            <if test="delFlag != null  and delFlag != ''">and del_flag = #{delFlag}</if>
            <if test="isShow != null  and isShow != ''">and is_show = #{isShow}</if>
            and del_flag='0'
        </where>

    </select>

    <select id="selectProductList" parameterType="Product" resultMap="ProductResult">
        <include refid="selectProductVo"/>
        <where>
            <if test="title != null  and title != ''">and title like concat('%',#{title},'%')</if>
            <if test="compute != null  and compute != ''">and compute = #{compute}</if>
            and del_flag='0'
        </where>

    </select>

    <select id="selectProductById" parameterType="Long" resultMap="ProductResult">
        <include refid="selectProductVo"/>
        where id = #{id} and del_flag='0'
    </select>

    <insert id="insertProduct" parameterType="Product" useGeneratedKeys="true" keyProperty="id">
        insert into product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="compute != null">compute,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="modes != null">modes,</if>
            <if test="calculateEnum != null">calculate_enum,</if>
            <if test="computeStr != null">compute_str,</if>
            <if test="images != null">images,</if>
            <if test="imageText != null">image_text,</if>
            <if test="formula != null">formula,</if>
            <if test="remark != null">remark,</if>
            <if test="isParity != null">is_parity,</if>
            <if test="power != null">power,</if>
            <if test="basics != null">basics,</if>
            <if test="styleCompute != null">style_compute,</if>
            <if test="isShow != null">is_show,</if>
            <if test="isMore != null">is_more,</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="compute != null">#{compute},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="modes != null">#{modes.code},</if>
            <if test="calculateEnum != null">#{calculateEnum.code},</if>
            <if test="computeStr != null">#{computeStr},</if>
            <if test="images != null">#{images,typeHandler=com.ruoyi.common.handler.ListToVarcharTypeHandler},</if>
            <if test="imageText != null">#{imageText},</if>
            <if test="formula != null">#{formula},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isParity != null">#{isParity},</if>
            <if test="power != null">#{power},</if>
            <if test="basics != null">#{basics},</if>
            <if test="styleCompute != null">#{style_compute},</if>
            <if test="isShow != null">#{isShow},</if>
            <if test="isMore != null">#{isMore},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            sysdate(),sysdate()
        </trim>
    </insert>

    <update id="updateProduct" parameterType="Product">
        update product
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="compute != null">compute = #{compute},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="modes != null">modes = #{modes.code},</if>
            <if test="calculateEnum != null">calculate_enum = #{calculateEnum.code},</if>
            <if test="computeStr != null">compute_str = #{computeStr},</if>
            <if test="images != null">images =
                #{images,typeHandler=com.ruoyi.common.handler.ListToVarcharTypeHandler},
            </if>
            <if test="imageText != null">image_text = #{imageText},</if>
            <if test="formula != null">formula = #{formula},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isParity != null">is_parity = #{isParity},</if>
            <if test="power != null">power = #{power},</if>
            <if test="basics != null">basics = #{basics},</if>
            <if test="styleCompute != null">style_compute = #{styleCompute},</if>
            <if test="isShow != null">is_show = #{isShow},</if>
            <if test="isMore != null">is_more = #{isMore},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate()
        </trim>
        where id = #{id}
    </update>

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

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