<?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.TPanOrderMapper">

    <resultMap type="TPanOrder" id="TPanOrderResult">
            <result property="id"    column="id"    />
            <result property="panId"    column="pan_id"    />
            <result property="orderId"    column="order_id"    />
            <result property="storageId"    column="storage_id"    />
            <result property="storageAreaId"    column="storage_area_id"    />
            <result property="total"    column="total"    />
            <result property="muchNum"    column="much_num"    />
            <result property="lessNum"    column="less_num"    />
            <result property="justNum"    column="just_num"    />
            <result property="status"    column="status"    />
            <result property="createBy"    column="create_by"    />
            <result property="auditMan"    column="audit_man"    />
            <result property="auditDate"    column="audit_date"    />
            <result property="confirmStatus"    column="confirm_status"    />
            <result property="recordPerson"    column="record_person"    />
            <result property="recordDate"    column="record_date"    />
            <result property="taskId"    column="task_id"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateTime"    column="update_time"    />
            <result property="updateBy"    column="update_by"    />
            <result property="storageShortName"    column="storage_short_name"    />
    </resultMap>

    <sql id="selectTPanOrderVo">
        select id, pan_id, order_id, storage_id, storage_area_id, total, much_num, less_num, just_num, status, create_by, audit_man, audit_date, confirm_status, record_person, record_date, task_id, create_time, update_time, update_by,storage_short_name from t_pan_order
    </sql>

    <select id="selectTPanOrderList" parameterType="TPanOrder" resultMap="TPanOrderResult">
        <include refid="selectTPanOrderVo"/>
        <where>
                        <if test="panId != null  and panId != ''"> and pan_id = #{panId}</if>
                        <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
                        <if test="storageId != null  and storageId != ''"> and storage_id = #{storageId}</if>
                        <if test="storageShortName != null  and storageShortName != ''"> and storage_short_name like concat('%', #{storageShortName}, '%')</if>
                        <if test="storageAreaId != null  and storageAreaId != ''"> and storage_area_id = #{storageAreaId}</if>
                        <if test="total != null "> and total = #{total}</if>
                        <if test="muchNum != null "> and much_num = #{muchNum}</if>
                        <if test="lessNum != null "> and less_num = #{lessNum}</if>
                        <if test="justNum != null "> and just_num = #{justNum}</if>
                        <if test="status != null  and status != ''"> and status = #{status}</if>
                        <if test="auditMan != null  and auditMan != ''"> and audit_man = #{auditMan}</if>
                        <if test="auditDate != null "> and audit_date = #{auditDate}</if>
                        <if test="confirmStatus != null  and confirmStatus != ''"> and confirm_status = #{confirmStatus}</if>
                        <if test="recordPerson != null  and recordPerson != ''"> and record_person = #{recordPerson}</if>
                        <if test="recordDate != null "> and record_date = #{recordDate}</if>
                        <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
            ${params.dataScope}
        </where>
    </select>

    <select id="selectTPanOrderById" parameterType="Long" resultMap="TPanOrderResult">
            <include refid="selectTPanOrderVo"/>
            where id = #{id}
    </select>

    <insert id="insertTPanOrder" parameterType="TPanOrder" useGeneratedKeys="true" keyProperty="id">
        insert into t_pan_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null and id != ''">id,</if>
                    <if test="panId != null and panId != ''">pan_id,</if>
                    <if test="orderId != null">order_id,</if>
                    <if test="storageId != null">storage_id,</if>
                    <if test="storageAreaId != null">storage_area_id,</if>
                    <if test="total != null">total,</if>
                    <if test="muchNum != null">much_num,</if>
                    <if test="lessNum != null">less_num,</if>
                    <if test="justNum != null">just_num,</if>
                    <if test="status != null">status,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="auditMan != null">audit_man,</if>
                    <if test="auditDate != null">audit_date,</if>
                    <if test="confirmStatus != null">confirm_status,</if>
                    <if test="recordPerson != null">record_person,</if>
                    <if test="recordDate != null">record_date,</if>
                    <if test="taskId != null">task_id,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="updateBy != null">update_by,</if>
                    <if test="storageShortName != null">storage_short_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null and id != ''">#{panId},</if>
                    <if test="panId != null and panId != ''">#{panId},</if>
                    <if test="orderId != null">#{orderId},</if>
                    <if test="storageId != null">#{storageId},</if>
                    <if test="storageAreaId != null">#{storageAreaId},</if>
                    <if test="total != null">#{total},</if>
                    <if test="muchNum != null">#{muchNum},</if>
                    <if test="lessNum != null">#{lessNum},</if>
                    <if test="justNum != null">#{justNum},</if>
                    <if test="status != null">#{status},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="auditMan != null">#{auditMan},</if>
                    <if test="auditDate != null">#{auditDate},</if>
                    <if test="confirmStatus != null">#{confirmStatus},</if>
                    <if test="recordPerson != null">#{recordPerson},</if>
                    <if test="recordDate != null">#{recordDate},</if>
                    <if test="taskId != null">#{taskId},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="updateBy != null">#{updateBy},</if>
                    <if test="storageShortName != null">#{storageShortName},</if>
        </trim>
    </insert>

    <update id="updateTPanOrder" parameterType="TPanOrder">
        update t_pan_order
        <trim prefix="SET" suffixOverrides=",">
                    <if test="panId != null and panId != ''">pan_id = #{panId},</if>
                    <if test="orderId != null">order_id = #{orderId},</if>
                    <if test="storageId != null">storage_id = #{storageId},</if>
                    <if test="storageAreaId != null">storage_area_id = #{storageAreaId},</if>
                    <if test="total != null">total = #{total},</if>
                    <if test="muchNum != null">much_num = #{muchNum},</if>
                    <if test="lessNum != null">less_num = #{lessNum},</if>
                    <if test="justNum != null">just_num = #{justNum},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="auditMan != null">audit_man = #{auditMan},</if>
                    <if test="auditDate != null">audit_date = #{auditDate},</if>
                    <if test="confirmStatus != null">confirm_status = #{confirmStatus},</if>
                    <if test="recordPerson != null">record_person = #{recordPerson},</if>
                    <if test="recordDate != null">record_date = #{recordDate},</if>
                    <if test="taskId != null">task_id = #{taskId},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="storageShortName != null">storage_short_name = #{storageShortName},</if>
        </trim>
        where id = #{id}
    </update>

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

    <delete id="deleteTPanOrderById" parameterType="Long">
        delete from t_pan_order  where id = #{id}
    </delete>

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