<?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.hw.wms.mapper.WmsBasePositionMapper">
    
    <resultMap type="WmsBasePosition" id="WmsBasePositionResult">
        <result property="basePositionId"    column="base_position_id"    />
        <result property="basePositionName"    column="base_position_name"    />
        <result property="xCoordinate"    column="x_coordinate"    />
        <result property="yCoordinate"    column="y_coordinate"    />
        <result property="zCoordinate"    column="z_coordinate"    />
        <result property="basePostionType"    column="base_postion_type"    />
        <result property="positionTargetId"    column="position_target_id"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectWmsBasePositionVo">
        select base_position_id, base_position_name, x_coordinate, y_coordinate, z_coordinate, base_postion_type, position_target_id, remark, create_by, create_time, update_by, update_time from wms_base_position
    </sql>

    <select id="selectWmsBasePositionList" parameterType="WmsBasePosition" resultMap="WmsBasePositionResult">
        <include refid="selectWmsBasePositionVo"/>
        <where>  
            <if test="basePositionName != null  and basePositionName != ''"> and base_position_name like concat('%', #{basePositionName}, '%')</if>
            <if test="xCoordinate != null "> and x_coordinate = #{xCoordinate}</if>
            <if test="yCoordinate != null "> and y_coordinate = #{yCoordinate}</if>
            <if test="zCoordinate != null "> and z_coordinate = #{zCoordinate}</if>
            <if test="basePostionType != null  and basePostionType != ''"> and base_postion_type = #{basePostionType}</if>
            <if test="positionTargetId != null "> and position_target_id = #{positionTargetId}</if>
        </where>
    </select>
    
    <select id="selectWmsBasePositionByBasePositionId" parameterType="Long" resultMap="WmsBasePositionResult">
        <include refid="selectWmsBasePositionVo"/>
        where base_position_id = #{basePositionId}
    </select>
        
    <insert id="insertWmsBasePosition" parameterType="WmsBasePosition" useGeneratedKeys="true" keyProperty="basePositionId">
        insert into wms_base_position
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="basePositionName != null and basePositionName != ''">base_position_name,</if>
            <if test="xCoordinate != null">x_coordinate,</if>
            <if test="yCoordinate != null">y_coordinate,</if>
            <if test="zCoordinate != null">z_coordinate,</if>
            <if test="basePostionType != null">base_postion_type,</if>
            <if test="positionTargetId != null">position_target_id,</if>
            <if test="remark != null">remark,</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="basePositionName != null and basePositionName != ''">#{basePositionName},</if>
            <if test="xCoordinate != null">#{xCoordinate},</if>
            <if test="yCoordinate != null">#{yCoordinate},</if>
            <if test="zCoordinate != null">#{zCoordinate},</if>
            <if test="basePostionType != null">#{basePostionType},</if>
            <if test="positionTargetId != null">#{positionTargetId},</if>
            <if test="remark != null">#{remark},</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="updateWmsBasePosition" parameterType="WmsBasePosition">
        update wms_base_position
        <trim prefix="SET" suffixOverrides=",">
            <if test="basePositionName != null and basePositionName != ''">base_position_name = #{basePositionName},</if>
            <if test="xCoordinate != null">x_coordinate = #{xCoordinate},</if>
            <if test="yCoordinate != null">y_coordinate = #{yCoordinate},</if>
            <if test="zCoordinate != null">z_coordinate = #{zCoordinate},</if>
            <if test="basePostionType != null">base_postion_type = #{basePostionType},</if>
            <if test="positionTargetId != null">position_target_id = #{positionTargetId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where base_position_id = #{basePositionId}
    </update>

    <delete id="deleteWmsBasePositionByBasePositionId" parameterType="Long">
        delete from wms_base_position where base_position_id = #{basePositionId}
    </delete>

    <delete id="deleteWmsBasePositionByBasePositionIds" parameterType="String">
        delete from wms_base_position where base_position_id in 
        <foreach item="basePositionId" collection="array" open="(" separator="," close=")">
            #{basePositionId}
        </foreach>
    </delete>
</mapper>