<?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.warehouse.mapper.WarehouseAreaMapper">
    <resultMap type="WarehouseArea" id="WarehouseAreaResult">
        <id property="id" column="id"/>
        <result property="areaCode" column="area_code"/>
        <result property="areaName" column="area_name"/>
        <result property="remark" column="remark"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectWarehouseAreaVo">
        select id, area_code, area_name, remark, create_time, update_time from warehouse_area
    </sql>

    <select id="selectWarehouseAreaList" parameterType="WarehouseArea" resultMap="WarehouseAreaResult">
        <include refid="selectWarehouseAreaVo"/>
        <where>
            <if test="areaCode != null and areaCode != ''">and area_code like concat('%', #{areaCode}, '%')</if>
            <if test="areaName != null and areaName != ''">and area_name like concat('%', #{areaName}, '%')</if>
        </where>
        order by id desc
    </select>

    <select id="selectWarehouseAreaAll" resultMap="WarehouseAreaResult">
        <include refid="selectWarehouseAreaVo"/> order by area_code
    </select>

    <select id="selectWarehouseAreaById" parameterType="Long" resultMap="WarehouseAreaResult">
        <include refid="selectWarehouseAreaVo"/> where id = #{id}
    </select>

    <select id="checkAreaCodeUnique" parameterType="String" resultMap="WarehouseAreaResult">
        <include refid="selectWarehouseAreaVo"/> where area_code = #{areaCode} limit 1
    </select>

    <insert id="insertWarehouseArea" parameterType="WarehouseArea" useGeneratedKeys="true" keyProperty="id">
        insert into warehouse_area(area_code, area_name, remark, create_time)
        values(#{areaCode}, #{areaName}, #{remark}, sysdate())
    </insert>

    <update id="updateWarehouseArea" parameterType="WarehouseArea">
        update warehouse_area
        <set>
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="areaName != null and areaName != ''">area_name = #{areaName},</if>
            <if test="remark != null">remark = #{remark},</if>
            update_time = sysdate()
        </set>
        where id = #{id}
    </update>

    <delete id="deleteWarehouseAreaByIds" parameterType="Long">
        delete from warehouse_area where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">#{id}</foreach>
    </delete>
</mapper>
