<?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.backendsys.mapper.B2c.B2cGoodUnitMapper">

    <sql id="includeGoodsUnit">
        id,
        id good_unit_id,
        unit_name,
        sort
    </sql>
    <resultMap id="resultMapGoodsUnit" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="good_unit_id" column="good_unit_id" javaType="java.lang.Long"/>
        <result property="unit_name" column="unit_name" />
        <result property="sort" column="sort" javaType="java.lang.Integer" />
    </resultMap>

    <select id="queryGoodUnitList" resultMap="resultMapGoodsUnit">
        SELECT
        <include refid="includeGoodsUnit" />
        FROM b2c_goods_unit
        <where>
            <if test="unit_name != null and unit_name != ''">
                AND unit_name LIKE CONCAT('%', #{unit_name}, '%')
            </if>
        </where>
        ORDER BY sort DESC
    </select>

    <select id="queryGoodUnitDetail" resultMap="resultMapGoodsUnit">
        SELECT
        <include refid="includeGoodsUnit" />
        FROM b2c_goods_unit
        WHERE id = #{good_unit_id}
    </select>

    <insert id="insertGoodUnit" parameterType="com.backendsys.entity.B2c.B2cGoodUnitDTO"
        useGeneratedKeys="true" keyProperty="good_unit_id">
        INSERT INTO b2c_goods_unit (unit_name
        <if test="sort != null and sort != ''">, sort</if>
        )
        VALUES (#{unit_name}
        <if test="sort != null and sort != ''">, #{sort}</if>
        )
    </insert>

    <update id="updateGoodUnit" parameterType="com.backendsys.entity.B2c.B2cGoodUnitDTO"
        useGeneratedKeys="true" keyProperty="good_unit_id">
        UPDATE b2c_goods_unit
        SET unit_name = #{unit_name}
            <if test="sort != null and sort != ''">, sort = #{sort}</if>
        WHERE id = #{good_unit_id}
    </update>

    <delete id="deleteGoodUnit">
        DELETE FROM b2c_goods_unit WHERE id = #{good_unit_id}
    </delete>

</mapper>