<?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.zbf.system.mapper.TBasePalletMapper">

    <resultMap type="TBasePallet" id="TBasePalletResult">
            <result property="id"    column="id"    />
            <result property="palletId"    column="pallet_id"    />
            <result property="palletName"    column="pallet_name"    />
            <result property="pyName"    column="py_name"    />
            <result property="palletType"    column="pallet_type"    />
            <result property="type"    column="type"    />
            <result property="palletLong"    column="pallet_long"    />
            <result property="palletWidth"    column="pallet_width"    />
            <result property="palletHeight"    column="pallet_height"    />
            <result property="volume"    column="volume"    />
            <result property="bearWeight"    column="bear_weight"    />
            <result property="status"    column="status"    />
            <result property="remark"    column="remark"    />
            <result property="version"    column="version"    />
            <result property="userId"    column="user_id"    />
            <result property="workType"    column="work_type"    />
            <result property="createTime"    column="create_time"    />
            <result property="createBy"    column="create_by"    />
            <result property="updateTime"    column="update_time"    />
            <result property="updateBy"    column="update_by"    />
            <result property="storageId"    column="storage_id"    />
            <result property="isLock"    column="is_lock"    />
    </resultMap>

    <sql id="selectTBasePalletVo">
        select id, pallet_id, pallet_name, py_name, pallet_type,type, pallet_long, pallet_width, pallet_height, volume, bear_weight, status, remark, version, user_id, work_type, create_time, create_by, update_time, update_by,storage_id,is_lock from t_base_pallet
    </sql>

    <select id="selectTBasePalletList" parameterType="TBasePallet" resultMap="TBasePalletResult">
        <include refid="selectTBasePalletVo"/>
        <where>
                        <if test="palletId != null  and palletId != ''"> and pallet_id = #{palletId}</if>
                        <if test="palletName != null  and palletName != ''"> and pallet_name like concat('%', #{palletName}, '%')</if>
                        <if test="pyName != null  and pyName != ''"> and py_name like concat('%', #{pyName}, '%')</if>
                        <if test="palletType != null  and palletType != ''"> and pallet_type = #{palletType}</if>
                        <if test="type != null  and type != ''"> and type = #{type}</if>
                        <if test="palletLong != null "> and pallet_long = #{palletLong}</if>
                        <if test="palletWidth != null "> and pallet_width = #{palletWidth}</if>
                        <if test="palletHeight != null "> and pallet_height = #{palletHeight}</if>
                        <if test="volume != null "> and volume = #{volume}</if>
                        <if test="bearWeight != null "> and bear_weight = #{bearWeight}</if>
                        <if test="status != null  and status != ''"> and status = #{status}</if>
                        <if test="workType != null  and workType != ''"> and work_type = #{workType}</if>
                        <if test="storageId != null  and storageId != ''"> and storage_id = #{storageId}</if>
                        <if test="isLock != null  and isLock != ''"> and is_lock = #{isLock}</if>
                        <if test="selectIds !=null and selectIds.length>0">
                            and id in
                            <foreach collection="selectIds" item="itemId" open="(" close=")" separator=",">
                                #{itemId}
                            </foreach>
                        </if>
        </where>
        order by id asc
    </select>

    <select id="selectTBasePalletById" parameterType="Long" resultMap="TBasePalletResult">
            <include refid="selectTBasePalletVo"/>
            where id = #{id}
    </select>

    <insert id="insertTBasePallet" parameterType="TBasePallet" useGeneratedKeys="true" keyProperty="id">
        insert into t_base_pallet
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="palletId != null and palletId != ''">pallet_id,</if>
                    <if test="palletName != null">pallet_name,</if>
                    <if test="pyName != null">py_name,</if>
                    <if test="palletType != null">pallet_type,</if>
                    <if test="palletLong != null">pallet_long,</if>
                    <if test="palletWidth != null">pallet_width,</if>
                    <if test="palletHeight != null">pallet_height,</if>
                    <if test="volume != null">volume,</if>
                    <if test="bearWeight != null">bear_weight,</if>
                    <if test="status != null">status,</if>
                    <if test="type != null">type,</if>
                    <if test="remark != null">remark,</if>
                    <if test="version != null">version,</if>
                    <if test="userId != null">user_id,</if>
                    <if test="workType != null">work_type,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="updateBy != null">update_by,</if>
                    <if test="storageId != null">storage_id,</if>
                    <if test="isLock != null">is_lock,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="palletId != null and palletId != ''">#{palletId},</if>
                    <if test="palletName != null">#{palletName},</if>
                    <if test="pyName != null">#{pyName},</if>
                    <if test="palletType != null">#{palletType},</if>
                    <if test="palletLong != null">#{palletLong},</if>
                    <if test="palletWidth != null">#{palletWidth},</if>
                    <if test="palletHeight != null">#{palletHeight},</if>
                    <if test="volume != null">#{volume},</if>
                    <if test="bearWeight != null">#{bearWeight},</if>
                    <if test="status != null">#{status},</if>
                    <if test="type != null">#{type},</if>
                    <if test="remark != null">#{remark},</if>
                    <if test="version != null">#{version},</if>
                    <if test="userId != null">#{userId},</if>
                    <if test="workType != null">#{workType},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="updateBy != null">#{updateBy},</if>
                    <if test="storageId != null">#{storageId},</if>
                    <if test="isLock != null">#{isLock},</if>
        </trim>
    </insert>

    <update id="updateTBasePallet" parameterType="TBasePallet">
        update t_base_pallet
        <trim prefix="SET" suffixOverrides=",">
                    <if test="palletId != null and palletId != ''">pallet_id = #{palletId},</if>
                    <if test="palletName != null">pallet_name = #{palletName},</if>
                    <if test="pyName != null">py_name = #{pyName},</if>
                    <if test="palletType != null">pallet_type = #{palletType},</if>
                    <if test="palletLong != null">pallet_long = #{palletLong},</if>
                    <if test="palletWidth != null">pallet_width = #{palletWidth},</if>
                    <if test="palletHeight != null">pallet_height = #{palletHeight},</if>
                    <if test="volume != null">volume = #{volume},</if>
                    <if test="bearWeight != null">bear_weight = #{bearWeight},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="type != null">type = #{type},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="version != null">version = #{version},</if>
                    <if test="userId != null">user_id = #{userId},</if>
                    <if test="workType != null">work_type = #{workType},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="storageId != null">storage_id = #{storageId},</if>
                    <if test="isLock != null">is_lock = #{isLock},</if>
        </trim>
        where id = #{id}
    </update>



    <update id="updateEcp" parameterType="TBasePallet">
        update t_base_pallet
        <trim prefix="SET" suffixOverrides=",">
            <if test="palletId != null and palletId != ''">pallet_id = #{palletId},</if>
            <if test="palletEpc != null">pallet_Epc = #{palletEpc},</if>
        </trim>
        where pallet_id = #{palletId}
    </update>

    <update id="enableTBasePalletByIds" parameterType="String">
        update t_base_pallet set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTBasePalletByIds" parameterType="String">
        update t_base_pallet set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTBasePalletById" parameterType="Long">
        delete from t_base_pallet  where id = #{id}
    </delete>

    <delete id="deleteTBasePalletByIds" parameterType="String">
        delete from t_base_pallet where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateLockStatus" parameterType="TBasePallet">
        update t_base_pallet set is_lock=#{isLock} where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
