<?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.bonus.canteen.core.warehouse.mapper.WareHouseCategoryMapper">

    <select id="selectWareHouseCategoryList" parameterType="com.bonus.canteen.core.warehouse.domain.WareHouseCategory" resultType="com.bonus.canteen.core.warehouse.domain.WareHouseCategory">
        select wc.category_id as  categoryid,wc.category_name as categoryname,wc.create_time as createtime,
        wc.update_time as updatetime,wc.area_id as areaid,aa.area_name as areaname
        from warehouse_category wc
        left join alloc_area aa on wc.area_id=aa.area_id
        <where>
            <if test="areaId != null  and areaId != ''"> and wc.area_id = #{areaId}</if>
            <if test="categoryName != null  and categoryName != ''"> and wh.category_name like concat('%', #{categoryName}, '%')</if>
        </where>
    </select>
        
    <insert id="insertWareHouseCategory" parameterType="com.bonus.canteen.core.warehouse.domain.WareHouseCategory">
        insert into warehouse_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaId         !=null"  >area_id              , </if>
            <if test="categoryName   !=null"  >category_name        , </if>
            <if test="createBy       !=null"  >create_by            , </if>
            <if test="createTime     !=null"  >create_time          , </if>
            <if test="updateBy       !=null"  >update_by            , </if>
            <if test="updateTime     !=null"  >update_time          , </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaId          !=null"  >#{areaId            },</if>
            <if test="categoryName    !=null"  >#{categoryName      },</if>
            <if test="createBy        !=null"  >#{createBy          },</if>
            <if test="createTime      !=null"  >#{createTime        },</if>
            <if test="updateBy        !=null"  >#{updateBy          },</if>
            <if test="updateTime      !=null"  >#{updateTime        },</if>
         </trim>
    </insert>

    <update id="updateWareHouseCategory" parameterType="com.bonus.canteen.core.warehouse.domain.WareHouseCategory">
        update warehouse_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaId          !=null"  >area_id            =#{areaId             },</if>
            <if test="categoryName    !=null"  >category_name      =#{categoryName       },</if>
            <if test="updateBy        !=null"  >update_by          =#{updateBy           },</if>
            <if test="updateTime      !=null"  >update_time        =#{updateTime         },</if>
        </trim>
        where category_id = #{categoryId}
    </update>

    <delete id="deleteWareHouseCategoryByWareHouseCategoryId" parameterType="com.bonus.canteen.core.warehouse.domain.WareHouseCategory">
        delete from warehouse_category where category_id = #{categoryId}
    </delete>

    <delete id="deleteWareHouseCategoryByWareHouseIds" parameterType="String">
        delete from warehouse_category where category_id in
        <foreach item="categoryId" collection="array" open="(" separator="," close=")">
            #{categoryId}
        </foreach>
    </delete>
</mapper>