ShipmentDetailMapper.xml 16.8 KB
<?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.huaheng.pc.shipment.shipmentDetail.mapper.ShipmentDetailMapper">
    <select id="SelectFirstStatus" resultType="java.util.Map">
        SELECT h.id, h.firstStatus
        FROM shipment_header h
        INNER JOIN shipment_detail d ON h.id = d.shipmentId AND d.id IN (#{ids})
        GROUP BY h.id,firstStatus
    </select>

    <select id="selectListDetail" resultType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail">
   SELECT d.id, d.warehouseId, d.warehouseCode, d.companyId, d.companyCode, d.sourceCode, d.sourceLine, d.shipmentId, d.shipmentCode, d.materialId, d.materialCode, d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.agingDate, d.inventoryStatus, d.qty, d.qtyCompleted, d.price, d.status, d.created, d.createdBy, d.lastUpdated, d.lastUpdatedBy, d.deleted, d.userDef1, d.userDef2, d.userDef3,
   d.zoneCode
   FROM shipment_detail d
   where d.shipmentCode=#{shipmentCode} and d.warehouseId=#{warehouseId} and (d.zoneCode&lt;>'QG' or d.zoneCode is null)
    </select>

    <select id="selectListAgvDetail" resultType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail">
   SELECT d.id, d.warehouseId, d.warehouseCode, d.companyId, d.companyCode, d.sourceCode, d.sourceLine, d.shipmentId, d.shipmentCode, d.materialId, d.materialCode, d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.agingDate, d.inventoryStatus, d.qty, d.qtyCompleted, d.price, d.status, d.created, d.createdBy, d.lastUpdated, d.lastUpdatedBy, d.deleted, d.userDef1, d.userDef2, d.userDef3
   FROM shipment_detail d
   where d.shipmentCode=#{shipmentCode} and d.warehouseId=#{warehouseId} and d.zoneCode="AGV"
    </select>

    <select id="selectEntity" resultType="java.util.Map">
   SELECT d.id, d.warehouseId, d.warehouseCode, d.companyId, d.companyCode, d.sourceCode, d.sourceLine, d.shipmentId, d.shipmentCode, d.materialId, d.materialCode, d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.agingDate, d.inventoryStatus, d.qty, d.qtyCompleted, d.price, d.status, d.created, d.createdBy, d.lastUpdated, d.lastUpdatedBy, d.deleted, d.userDef1, d.userDef2, d.userDef3,
   m.name as materialName,m.specification,  '个' unit
   FROM shipment_detail d
   INNER join material m on m.code=d.materialCode
   where d.shipmentCode=#{shipmentCode} and d.id=#{id} and d.warehouseId=#{warehouseId} and d.warehouseId=m.warehouseId and (d.zoneCode&lt;>"AGV" and d.zoneCode&lt;>"QG" or d.zoneCode is null)
    </select>

    <select id="selectListEntity" resultType="java.util.Map">
   SELECT d.id, d.warehouseId, d.warehouseCode, d.companyId, d.companyCode, d.sourceCode, d.sourceLine, d.shipmentId, d.shipmentCode, d.materialId, d.materialCode, d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.agingDate, d.inventoryStatus, d.qty, d.qtyCompleted, d.price, d.status, d.created, d.createdBy, d.lastUpdated, d.lastUpdatedBy, d.deleted, d.userDef1, d.userDef2, d.userDef3,
   m.name as materialName,m.specification,  m.masterUnit unit
   FROM shipment_detail d
   INNER join material m on m.code=d.materialCode
   where d.shipmentCode=#{shipmentCode} and d.warehouseId=#{warehouseId} and d.warehouseId=m.warehouseId and (d.zoneCode&lt;>"AGV" and d.zoneCode&lt;>"QG" or d.zoneCode is null) and m.deleted = 0
    </select>

    <select id="getAvgShipping" resultType="java.util.Map">
   SELECT d.id, d.warehouseId, d.warehouseCode, d.companyId, d.companyCode, d.sourceCode, d.sourceLine, d.shipmentId, d.shipmentCode, d.materialId, d.materialCode, d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.agingDate, d.inventoryStatus, d.qty, d.qtyCompleted, d.price, d.status, d.created, d.createdBy, d.lastUpdated, d.lastUpdatedBy, d.deleted, d.userDef1, d.userDef2, d.userDef3,
   m.name as materialName,m.specification,  m.masterUnit unit
   FROM shipment_detail d
   INNER join material m on m.code=d.materialCode
   where d.shipmentCode=#{shipmentCode} and d.id=#{id} and d.warehouseId=#{warehouseId} and d.warehouseId=m.warehouseId  and d.zoneCode="AGV"
    </select>

    <select id="getAvgShippings" resultType="java.util.Map">
   SELECT d.id, d.warehouseId, d.warehouseCode, d.companyId, d.companyCode, d.sourceCode, d.sourceLine, d.shipmentId, d.shipmentCode, d.materialId, d.materialCode, d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.agingDate, d.inventoryStatus, d.qty, d.qtyCompleted, d.price, d.status, d.created, d.createdBy, d.lastUpdated, d.lastUpdatedBy, d.deleted, d.userDef1, d.userDef2, d.userDef3,
   m.name as materialName,m.specification,  m.masterUnit unit
   FROM shipment_detail d
   INNER join material m on m.code=d.materialCode
   where d.shipmentCode=#{shipmentCode} and d.warehouseId=#{warehouseId} and d.warehouseId=m.warehouseId  and d.zoneCode="AGV"
    </select>

    <select id="selectLists" resultType="java.util.Map">
   SELECT d.id, d.materialCode, d.inventoryStatus,i.containerCode,i.locationCode,i.qty,
   m.name as materialName,m.specification
   FROM shipment_detail d
   INNER join inventory i on d.materialCode=i.materialCode and d.warehouseCode=i.warehouseCode
   INNER join material m on m.code=d.materialCode and d.warehouseCode=m.warehouseCode
   where d.shipmentCode=#{code} and d.warehouseCode=#{warehouseCode} and d.zoneCode="AGV" and i.zoneCode="AGV" and i.containerCode like CONCAT(#{shelfNo},'%') group by d.id
    </select>

    <delete id="batchDelete">
        DELETE FROM shipment_detail WHERE id IN
        <foreach item="idItem" collection="array" open="(" separator="," close=")">
            #{idItem}
        </foreach>
    </delete>

    <select id="countUnCompleted" resultType="java.lang.Integer">
         SELECT COUNT(*) FROM shipment_detail WHERE shipmentId=#{shipmentId} AND qty>qtyCompleted
    </select>

    <select id="getShipmentDetailListByLike" resultType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail">
        SELECT d.id,d.warehouseId,d.warehouseCode,d.companyId,d.companyCode,d.sourceCode,d.sourceLine,d.shipmentId,d.shipmentCode,
        d.materialId,d.materialCode,d.batch,d.lot,d.project,d.manufactureDate,d.expirationDate,d.agingDate,d.inventoryStatus,d.qty,d.qtyCompleted,
        d.price,d.status,d.created,d.createdBy,d.lastUpdated,d.lastUpdatedBy,d.deleted,d.userDef1,d.userDef2,d.userDef3,
        m.name as materialName, m.specification
        FROM shipment_detail d
        INNER JOIN material m
        ON d.materialCode = m.code  AND d.warehouseId = m.warehouseId AND d.deleted = FALSE AND m.deleted = FALSE
        <if test="id != null ">
            AND d.id = #{id}
        </if>
        <if test="warehouseId != null ">
            AND d.warehouseId = #{warehouseId}
        </if>
        <if test="warehouseCode != null and warehouseCode != ''">
            <bind name="warehouseCodePattern" value="'%' + warehouseCode + '%'" />
            AND d.warehouseCode like #{warehouseCodePattern}
        </if>
        <if test="sourceLine != null and sourceLine != ''">
            <bind name="sourceLinePattern" value="'%' + sourceLine + '%'" />
            AND d.sourceLine like #{sourceLinePattern}
        </if>
        <if test="shipmentId != null ">
            AND d.shipmentId = #{shipmentId}
        </if>
        <if test="shipmentCode != null and shipmentCode != ''">
            <bind name="shipmentCodePattern" value="'%' + shipmentCode + '%'" />
            AND d.shipmentCode like #{shipmentCodePattern}
        </if>
        <if test="materialId != null ">
            AND d.materialId = #{materialId}
        </if>
        <if test="materialCode != null and materialCode != ''">
            <bind name="materialCodePattern" value="'%' + materialCode + '%'" />
            AND d.materialCode like #{materialCodePattern}
        </if>
        <if test="batch != null and batch != ''">
            <bind name="batchPattern" value="'%' + batch + '%'" />
            AND d.batch like #{batchPattern}
        </if>
        <if test="lot != null and lot != ''">
            <bind name="lotPattern" value="'%' + lot + '%'" />
            AND d.lot like #{lotPattern}
        </if>
        <if test="project != null and project != ''">
            <bind name="projectPattern" value="'%' + project + '%'" />
            AND d.project like #{projectPattern}
        </if>
        <if test="params != null and params.manufactureDateBegin != null and params.manufactureDateBegin != ''">
            AND d.manufactureDate &gt;= #{params.manufactureDateBegin}
        </if>
        <if test="params != null and params.manufactureDateEnd != null and params.manufactureDateEnd != ''">
            AND d.manufactureDate &lt;= #{params.manufactureDateEnd}
        </if>
        <if test="params != null and params.expirationDateBegin != null and params.expirationDateBegin != ''">
            AND d.expirationDate &gt;= #{params.expirationDateBegin}
        </if>
        <if test="params != null and params.expirationDateEnd != null and params.expirationDateEnd != ''">
            AND d.expirationDate &lt;= #{params.expirationDateEnd}
        </if>
        <if test="inventoryStatus != null and inventoryStatus != ''">
            <bind name="inventoryStatusPattern" value="'%' + inventoryStatus + '%'" />
            AND d.inventoryStatus like #{inventoryStatusPattern}
        </if>
        <if test="qty != null ">
            AND d.qty = #{qty}
        </if>
        <if test="qtyCompleted != null ">
            AND d.qtyCompleted = #{qtyCompleted}
        </if>
        <if test="price != null ">
            AND d.price = #{price}
        </if>
        <if test="status != null ">
            AND d.status = #{status}
        </if>
        <if test="params != null and params.createdBegin != null and params.createdBegin != ''">
            AND d.created &gt;= #{params.createdBegin}
        </if>
        <if test="params != null and params.createdEnd != null and params.createdEnd != ''">
            AND d.created &lt;= #{params.createdEnd}
        </if>
        <if test="createdBy != null and createdBy != ''">
            <bind name="createdByPattern" value="'%' + createdBy + '%'" />
            AND d.createdBy like #{createdByPattern}
        </if>
        <if test="params != null and params.lastUpdatedBegin != null and params.lastUpdatedBegin != ''">
            AND d.lastUpdated &gt;= #{params.lastUpdatedBegin}
        </if>
        <if test="params != null and params.lastUpdatedEnd != null and params.lastUpdatedEnd != ''">
            AND d.lastUpdated &lt;= #{params.lastUpdatedEnd}
        </if>
        <if test="lastUpdatedBy != null and lastUpdatedBy != ''">
            <bind name="lastUpdatedByPattern" value="'%' + lastUpdatedBy + '%'" />
            AND d.lastUpdatedBy like #{lastUpdatedByPattern}
        </if>
        <if test="deleted != null ">
            AND d.deleted = #{deleted}
        </if>
        <if test="userDef1 != null and userDef1 != ''">
            <bind name="userDef1Pattern" value="'%' + userDef1 + '%'" />
            AND d.userDef1 like #{userDef1Pattern}
        </if>
        <if test="userDef2 != null and userDef2 != ''">
            <bind name="userDef2Pattern" value="'%' + userDef2 + '%'" />
            AND d.userDef2 like #{userDef2Pattern}
        </if>
        <if test="userDef3 != null and userDef3 != ''">
            <bind name="userDef3Pattern" value="'%' + userDef3 + '%'" />
            AND d.userDef3 like #{userDef3Pattern}
        </if>
    </select>

    <select id="StatisticalByReceiptId" resultType="java.util.Map">
       SELECT count(*) as 'totalLines',sum(qty) as 'totalQty'
       FROM shipment_detail
       WHERE shipmentId=#{receiptId} and deleted=FALSE
    </select>

    <update id="updateDetails" >
        update shipment_detail s inner join inventory i on s.shipmentCode=#{code} and s.materialCode=i.materialCode and s.warehouseCode=i.warehouseCode set s.zoneCode=i.zoneCode
    </update>

    <select id="getShipmentQtyLast7Days" resultType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail">
SELECT
	a.click_date AS lastUpdated,
	ifnull( b.taskQty, 0 ) AS qty
FROM
	(
	SELECT
		curdate( ) AS click_date UNION ALL
	SELECT
		date_sub( curdate( ), INTERVAL 1 DAY ) AS click_date UNION ALL
	SELECT
		date_sub( curdate( ), INTERVAL 2 DAY ) AS click_date UNION ALL
	SELECT
		date_sub( curdate( ), INTERVAL 3 DAY ) AS click_date UNION ALL
	SELECT
		date_sub( curdate( ), INTERVAL 4 DAY ) AS click_date UNION ALL
	SELECT
		date_sub( curdate( ), INTERVAL 5 DAY ) AS click_date UNION ALL
	SELECT
		date_sub( curdate( ), INTERVAL 6 DAY ) AS click_date
	) a
	LEFT JOIN (
	SELECT
		DATE( r.lastUpdated ) AS date,
		SUM( r.qtyCompleted ) AS taskQty
	FROM
		shipment_detail r
	WHERE
		r.lastUpdated >= DATE_SUB( CURDATE( ), INTERVAL 7 DAY )
		AND r.status=300
	GROUP BY
		DATE(r.lastUpdated )
	) b ON a.click_date = b.date
ORDER BY
	a.click_date;
    </select>


    <select id="getWarehouseShipment" resultType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail">
    SELECT ifnull(sum(r.qtyCompleted),0) as qty,w.name as warehouseName  from warehouse w
    left JOIN shipment_detail r on r.warehouseCode=w.code and r.status=300
    and date(r.lastUpdated)=CURDATE()  group by w.code
    </select>


    <select id="getCompanyShipment" resultType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail">
    SELECT ifnull(sum(r.qtyCompleted),0) as qty,c.name as companyName  from company c
    left JOIN shipment_detail r on r.companyCode=c.code and r.status=300
    and date(r.lastUpdated)=CURDATE()  group by c.code
    </select>
    <select id="selectEntityByIdWithMaterialName"
            resultType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail">
      SELECT d.id, d.warehouseId, d.warehouseCode, d.zoneCode, d.companyId, d.companyCode, d.sourceCode, d.sourceLine, d.shipmentId, d.shipmentCode, d.materialId, d.materialCode, d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.agingDate, d.inventoryStatus, d.qty, d.qtyCompleted, d.unit, d.price, d.status, d.created, d.createdBy, d.lastUpdated, d.lastUpdatedBy, d.deleted, d.userDef1, d.userDef2, d.userDef3,
 m.name as materialName, m.specification
         FROM shipment_detail d
         INNER JOIN material m
         ON d.materialCode = m.code  AND d.warehouseId = m.warehouseId AND d.deleted = FALSE AND m.deleted = FALSE AND d.shipmentId = #{shipmentId}
    </select>

    <insert id="insertBatch"  parameterType="com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail" keyProperty="id" useGeneratedKeys="true" >
        INSERT INTO shipment_detail
        (
            warehouseId,
            warehouseCode,
            zoneCode,
            companyId,
            companyCode,
            sourceCode,
            sourceLine,
            shipmentId,
            shipmentCode,
            materialId,
            materialCode,
            batch,
            lot,
            project,
            manufactureDate,
            expirationDate,
            agingDate,
            inventoryStatus,
            qty,
            qtyCompleted,
            unit,
            price,
            status,
            created,
            createdBy,
            lastUpdated,
            lastUpdatedBy,
            userDef1,
            userDef2,
            userDef3
        )VALUES
        <foreach collection="shipmentDetailList" item="item" index="index" separator=",">
            (
                #{item.warehouseId, jdbcType=INTEGER},
                #{item.warehouseCode, jdbcType=VARCHAR},
                #{item.zoneCode, jdbcType=VARCHAR},
                #{item.companyId, jdbcType=INTEGER},
                #{item.companyCode, jdbcType=VARCHAR},
                #{item.sourceCode, jdbcType=VARCHAR},
                #{item.sourceLine, jdbcType=VARCHAR},
                #{item.shipmentId, jdbcType=INTEGER},
                #{item.shipmentCode, jdbcType=VARCHAR},
                #{item.materialId, jdbcType=INTEGER},
                #{item.materialCode, jdbcType=VARCHAR},
                #{item.batch, jdbcType=VARCHAR},
                #{item.lot, jdbcType=VARCHAR},
                #{item.project, jdbcType=VARCHAR},
                #{item.manufactureDate, jdbcType=TIMESTAMP},
                #{item.expirationDate, jdbcType=TIMESTAMP},
                #{item.agingDate, jdbcType=TIMESTAMP},
                #{item.inventoryStatus, jdbcType=VARCHAR},
                #{item.qty, jdbcType=DECIMAL},
                #{item.qtyCompleted, jdbcType=DECIMAL},
                #{item.unit, jdbcType=VARCHAR},
                #{item.price, jdbcType=DECIMAL},
                #{item.status, jdbcType=SMALLINT},
                #{item.created, jdbcType=TIMESTAMP},
                #{item.createdBy, jdbcType=VARCHAR},
                #{item.lastUpdated, jdbcType=TIMESTAMP},
                #{item.lastUpdatedBy, jdbcType=VARCHAR},
                #{item.userDef1, jdbcType=VARCHAR},
                #{item.userDef2, jdbcType=VARCHAR},
                #{item.userDef3, jdbcType=VARCHAR}
            )
        </foreach>
    </insert>


</mapper>