<?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.product.mapper.WarehouseAreaMapper">
  <resultMap id="warehouseAreaMap" type="com.tmerclub.cloud.product.model.WarehouseArea">
    <id column="warehouse_area_id" property="warehouseAreaId" />
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="warehouse_id" property="warehouseId"/>
    <result column="area_id" property="areaId"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `warehouse_area_id`,`create_time`,`update_time`,`warehouse_id`,`area_id`
  </sql>
  <select id="list" resultMap="warehouseAreaMap">
    select <include refid="Vo_Column_List"/> from warehouse_area order by warehouse_area_id desc
  </select>
  <select id="getByWarehouseAreaId" resultMap="warehouseAreaMap">
    select <include refid="Vo_Column_List"/> from warehouse_area where warehouse_area_id = #{warehouseAreaId}
  </select>
  <insert id="save">
    insert into warehouse_area (`warehouse_id`,`area_id`)
    values (#{warehouseArea.warehouseId},#{warehouseArea.areaId});
  </insert>
  <update id="update">
    update warehouse_area
    <set>
      <if test="warehouseArea.warehouseId != null">
        `warehouse_id` = #{warehouseArea.warehouseId},
      </if>
      <if test="warehouseArea.areaId != null">
        `area_id` = #{warehouseArea.areaId},
      </if>
    </set>
    where warehouse_area_id = #{warehouseArea.warehouseAreaId}
  </update>
  <delete id="deleteById">
    delete from warehouse_area where warehouse_area_id = #{warehouseAreaId}
  </delete>

  <insert id="batchSave" >
    insert into warehouse_area (`warehouse_id`,`area_id`) values
    <foreach collection="warehouseAreaList" item="warehouseArea" separator=",">
      (#{warehouseArea.warehouseId},#{warehouseArea.areaId})
    </foreach>
  </insert>

  <select id="deleteByWarehouseId">
    delete from warehouse_area where warehouse_id = #{warehouseId}
  </select>
</mapper>
