<?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.tmerclub.cloud.cuerecycle.mapper.CueFlawMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap id="cueFlawVOMap" type="com.tmerclub.cloud.cuerecycle.model.vo.CueFlawVO">
        <result property="flawId" column="flaw_id"/>
        <result property="flawName" column="flaw_name"/>
        <result property="flawPrice" column="flaw_price"/>
        <result property="flawSeq" column="flaw_seq"/>
        <result property="flawStatus" column="flaw_status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="Vo_Column_List">
        flaw_id,flaw_name,flaw_price,flaw_seq,flaw_status,deleted,create_time,update_time
    </sql>

    <select id="list" resultMap="cueFlawVOMap">
        SELECT
        <include refid="Vo_Column_List" />
        FROM cue_flaw
        <where>
            deleted = 0
            <if test="dto.flawName != null and dto.flawName != ''">
                AND flaw_name LIKE CONCAT('%', #{dto.flawName}, '%')
            </if>
            <if test="dto.flawStatus != null">
                AND flaw_status = #{dto.flawStatus}
            </if>
        </where>
        ORDER BY
            flaw_seq ASC,
            flaw_id DESC
    </select>

    <select id="getById" resultMap="cueFlawVOMap">
        SELECT
            <include refid="Vo_Column_List" />
        FROM
            cue_flaw
        WHERE flaw_id = #{flawId}
    </select>

    <insert id="save" useGeneratedKeys="true" keyProperty="flawId">
        INSERT INTO cue_flaw
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="flawName != null">flaw_name,</if>
            <if test="flawPrice != null">flaw_price,</if>
            <if test="flawSeq != null">flaw_seq,</if>
            <if test="flawStatus != null">flaw_status,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="flawName != null">#{flawName},</if>
            <if test="flawPrice != null">#{flawPrice},</if>
            <if test="flawSeq != null">#{flawSeq},</if>
            <if test="flawStatus != null">#{flawStatus},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="update">
        UPDATE cue_flaw
        <set>
            <if test="flawName != null">
                flaw_name = #{flawName},
            </if>
            <if test="flawPrice != null">
                flaw_price = #{flawPrice},
            </if>
            <if test="flawSeq != null">
                flaw_seq = #{flawSeq},
            </if>
            <if test="flawStatus != null">
                flaw_status = #{flawStatus},
            </if>
            <if test="deleted != null">
                deleted = #{deleted},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where flaw_id = #{flawId}
    </update>
</mapper>