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

    <resultMap type="TPanDetail" id="TPanDetailResult">
            <result property="id"    column="id"    />
            <result property="storageId"    column="storage_id"    />
            <result property="storageAreaId"    column="storage_area_id"    />
            <result property="locationId"    column="location_id"    />
            <result property="goodsId"    column="goods_id"    />
            <result property="stockNum"    column="stock_num"    />
            <result property="checkNum"    column="check_num"    />
            <result property="remark"    column="remark"    />
            <result property="version"    column="version"    />
            <result property="doctNumber"    column="doct_number"    />
            <result property="wareDate"    column="ware_date"    />
            <result property="barcode"    column="barcode"    />
            <result property="goodsName"    column="goods_name"    />
            <result property="goodsStatus"    column="goods_status"    />
            <result property="batchNo"    column="batch_no"    />
            <result property="scaleUnit"    column="scale_unit"    />
            <result property="goodsSku"    column="goods_sku"    />
            <result property="unit"    column="unit"    />
            <result property="specification"    column="specification"    />
            <result property="goodsTypeId"    column="goods_type_id"    />
            <result property="brand"    column="brand"    />
            <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"    />
            <result property="stockId"    column="stock_id"    />
    </resultMap>

    <sql id="selectTPanDetailVo">
        select id, storage_id,storage_short_name, storage_area_id, location_id, goods_id, stock_num, check_num, remark, version, doct_number, ware_date, barcode, goods_name, goods_status, batch_no, scale_unit, goods_sku, unit, specification, goods_type_id, brand, status, create_by, audit_man, audit_date, confirm_status, record_person, record_date, task_id, create_time, update_time, update_by,stock_id from t_pan_detail
    </sql>

    <select id="selectTPanDetailList" parameterType="TPanDetail" resultMap="TPanDetailResult">
        <include refid="selectTPanDetailVo"/>
        <where>
                        <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="locationId != null  and locationId != ''"> and location_id = #{locationId}</if>
                        <if test="goodsId != null  and goodsId != ''"> and goods_id = #{goodsId}</if>
                        <if test="stockNum != null "> and stock_num = #{stockNum}</if>
                        <if test="checkNum != null "> and check_num = #{checkNum}</if>
                        <if test="version != null  and version != ''"> and version = #{version}</if>
                        <if test="doctNumber != null  and doctNumber != ''"> and doct_number = #{doctNumber}</if>
                        <if test="wareDate != null  and wareDate != ''"> and ware_date = #{wareDate}</if>
                        <if test="barcode != null  and barcode != ''"> and barcode = #{barcode}</if>
                        <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
                        <if test="goodsStatus != null  and goodsStatus != ''"> and goods_status = #{goodsStatus}</if>
                        <if test="batchNo != null  and batchNo != ''"> and batch_no = #{batchNo}</if>
                        <if test="scaleUnit != null  and scaleUnit != ''"> and scale_unit = #{scaleUnit}</if>
                        <if test="goodsSku != null  and goodsSku != ''"> and goods_sku = #{goodsSku}</if>
                        <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
                        <if test="specification != null  and specification != ''"> and specification = #{specification}</if>
                        <if test="goodsTypeId != null  and goodsTypeId != ''"> and goods_type_id = #{goodsTypeId}</if>
                        <if test="brand != null  and brand != ''"> and brand = #{brand}</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>
        </where>
    </select>

    <select id="selectTPanDetailById" parameterType="Long" resultMap="TPanDetailResult">
            <include refid="selectTPanDetailVo"/>
            where id = #{id}
    </select>

    <select id="getList" parameterType="String" resultMap="TPanDetailResult">
        <include refid="selectTPanDetailVo"/>
        where stock_id = #{stockId}
    </select>


    <insert id="insertTPanDetail" parameterType="TPanDetail" useGeneratedKeys="true" keyProperty="id">
        insert into t_pan_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="storageId != null">storage_id,</if>
                    <if test="storageAreaId != null">storage_area_id,</if>
                    <if test="locationId != null">location_id,</if>
                    <if test="goodsId != null">goods_id,</if>
                    <if test="stockNum != null">stock_num,</if>
                    <if test="checkNum != null">check_num,</if>
                    <if test="remark != null">remark,</if>
                    <if test="version != null">version,</if>
                    <if test="doctNumber != null">doct_number,</if>
                    <if test="wareDate != null">ware_date,</if>
                    <if test="barcode != null">barcode,</if>
                    <if test="goodsName != null">goods_name,</if>
                    <if test="goodsStatus != null">goods_status,</if>
                    <if test="batchNo != null">batch_no,</if>
                    <if test="scaleUnit != null">scale_unit,</if>
                    <if test="goodsSku != null">goods_sku,</if>
                    <if test="unit != null">unit,</if>
                    <if test="specification != null">specification,</if>
                    <if test="goodsTypeId != null">goods_type_id,</if>
                    <if test="brand != null">brand,</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="storageId != null">#{storageId},</if>
                    <if test="storageAreaId != null">#{storageAreaId},</if>
                    <if test="locationId != null">#{locationId},</if>
                    <if test="goodsId != null">#{goodsId},</if>
                    <if test="stockNum != null">#{stockNum},</if>
                    <if test="checkNum != null">#{checkNum},</if>
                    <if test="remark != null">#{remark},</if>
                    <if test="version != null">#{version},</if>
                    <if test="doctNumber != null">#{doctNumber},</if>
                    <if test="wareDate != null">#{wareDate},</if>
                    <if test="barcode != null">#{barcode},</if>
                    <if test="goodsName != null">#{goodsName},</if>
                    <if test="goodsStatus != null">#{goodsStatus},</if>
                    <if test="batchNo != null">#{batchNo},</if>
                    <if test="scaleUnit != null">#{scaleUnit},</if>
                    <if test="goodsSku != null">#{goodsSku},</if>
                    <if test="unit != null">#{unit},</if>
                    <if test="specification != null">#{specification},</if>
                    <if test="goodsTypeId != null">#{goodsTypeId},</if>
                    <if test="brand != null">#{brand},</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="updateTPanDetail" parameterType="TPanDetail">
        update t_pan_detail
        <trim prefix="SET" suffixOverrides=",">
                    <if test="storageId != null">storage_id = #{storageId},</if>
                    <if test="storageAreaId != null">storage_area_id = #{storageAreaId},</if>
                    <if test="locationId != null">location_id = #{locationId},</if>
                    <if test="goodsId != null">goods_id = #{goodsId},</if>
                    <if test="stockNum != null">stock_num = #{stockNum},</if>
                    <if test="checkNum != null">check_num = #{checkNum},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="version != null">version = #{version},</if>
                    <if test="doctNumber != null">doct_number = #{doctNumber},</if>
                    <if test="wareDate != null">ware_date = #{wareDate},</if>
                    <if test="barcode != null">barcode = #{barcode},</if>
                    <if test="goodsName != null">goods_name = #{goodsName},</if>
                    <if test="goodsStatus != null">goods_status = #{goodsStatus},</if>
                    <if test="batchNo != null">batch_no = #{batchNo},</if>
                    <if test="scaleUnit != null">scale_unit = #{scaleUnit},</if>
                    <if test="goodsSku != null">goods_sku = #{goodsSku},</if>
                    <if test="unit != null">unit = #{unit},</if>
                    <if test="specification != null">specification = #{specification},</if>
                    <if test="goodsTypeId != null">goods_type_id = #{goodsTypeId},</if>
                    <if test="brand != null">brand = #{brand},</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="enableTPanDetailByIds" parameterType="String">
        update t_pan_detail set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTPanDetailByIds" parameterType="String">
        update t_pan_detail set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTPanDetailById" parameterType="Long">
        delete from t_pan_detail  where id = #{id}
    </delete>

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

    <insert id="batchInsertTPanDetail">
        INSERT INTO t_pan_detail (
        id, storage_id, storage_area_id, location_id, goods_id, stock_num, check_num, remark, version,
        doct_number, ware_date, barcode, goods_name, goods_status, batch_no, scale_unit, goods_sku,
        unit, specification, goods_type_id, brand, status, create_by, audit_man, audit_date,
        confirm_status, record_person, record_date, task_id, create_time, update_time, storage_short_name, stock_id
        ) VALUES
        <foreach item="item" index="index" collection="list" separator=",">
            (
            #{item.id}, #{item.storageId}, #{item.storageAreaId}, #{item.locationId}, #{item.goodsId},
            #{item.stockNum}, #{item.checkNum}, #{item.remark}, #{item.version}, #{item.doctNumber},
            #{item.wareDate}, #{item.barcode}, #{item.goodsName}, #{item.goodsStatus}, #{item.batchNo},
            #{item.scaleUnit}, #{item.goodsSku}, #{item.unit}, #{item.specification}, #{item.goodsTypeId},
            #{item.brand}, #{item.status}, #{item.createBy}, #{item.auditMan}, #{item.auditDate},
            #{item.confirmStatus}, #{item.recordPerson}, #{item.recordDate}, #{item.taskId},
            #{item.createTime}, #{item.updateTime}, #{item.storageShortName}, #{item.stockId}
            )
        </foreach>
    </insert>
    <sql id="xx">
        select  * from t_pan_detail
    </sql>
</mapper>
