<?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.mall.mapper.MallAppGoodsUnitMapper">

    <resultMap type="MallAppGoodsUnit" id="MallAppGoodsUnitResult">
        <result property="goodsUnitId"    column="goods_unit_id"    />
        <result property="name"    column="name"    />
        <result property="status"    column="status"    />
        <result property="remarks"    column="remarks"    />
        <result property="content"    column="content"    />
        <result property="sort"    column="sort"    />
        <result property="createAt"    column="create_at"    />
        <result property="updateAt"    column="update_at"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMallAppGoodsUnitVo">
        select goods_unit_id, name, status, remarks, content, sort, create_at, update_at, del_flag from mall_app_goods_unit
    </sql>

    <select id="selectMallAppGoodsUnitList" parameterType="MallAppGoodsUnit" resultMap="MallAppGoodsUnitResult">
        <include refid="selectMallAppGoodsUnitVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="createAt != null  and createAt != ''"> and create_at = #{createAt}</if>
            <if test="updateAt != null  and updateAt != ''"> and update_at = #{updateAt}</if>
            <if test="delFlag != null  and delFlag != ''"> and del_flag = #{delFlag}</if>
        </where>
        order by create_at desc
    </select>

    <select id="selectMallAppGoodsUnitByGoodsUnitId" parameterType="Long" resultMap="MallAppGoodsUnitResult">
        <include refid="selectMallAppGoodsUnitVo"/>
        where goods_unit_id = #{goodsUnitId}
    </select>

    <insert id="insertMallAppGoodsUnit" parameterType="MallAppGoodsUnit" useGeneratedKeys="true" keyProperty="goodsUnitId">
        insert into mall_app_goods_unit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="status != null">status,</if>
            <if test="remarks != null">remarks,</if>
            <if test="content != null">content,</if>
            <if test="sort != null">sort,</if>
            <if test="createAt != null">create_at,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="status != null">#{status},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="content != null">#{content},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateMallAppGoodsUnit" parameterType="MallAppGoodsUnit">
        update mall_app_goods_unit
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="content != null">content = #{content},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="updateAt != null">update_at = #{updateAt},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where goods_unit_id = #{goodsUnitId}
    </update>

    <delete id="deleteMallAppGoodsUnitByGoodsUnitId" parameterType="Long">
        delete from mall_app_goods_unit where goods_unit_id = #{goodsUnitId}
    </delete>

    <delete id="deleteMallAppGoodsUnitByGoodsUnitIds" parameterType="String">
        delete from mall_app_goods_unit where goods_unit_id in
        <foreach item="goodsUnitId" collection="array" open="(" separator="," close=")">
            #{goodsUnitId}
        </foreach>
    </delete>
</mapper>
