ReceiptDetailMapper.xml 13.5 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.receipt.receiptDetail.mapper.ReceiptDetailMapper">
    <select id="SelectFirstStatus" resultType="java.util.Map">
        SELECT h.firstStatus,h.id
        FROM receipt_header h
        INNER JOIN receipt_detail d ON h.id = d.receiptId AND d.id IN
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        GROUP BY h.id, h.firstStatus
    </select>

    <select id="getReceiptDetailListByLike" resultType="com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail">
         SELECT d.id, d.warehouseId, d.warehouseCode, d.sourceLine, d.receiptId, d.receiptCode, d.materialId, d.materialCode,d.zoneCode,
                 d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.inventoryStatus, d.qty, d.qtyCompleted,d.price,d.unit,
                 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 receipt_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="receiptId != null ">
            AND d.receiptId = #{receiptId}
        </if>
        <if test="receiptCode != null and receiptCode != ''">
            <bind name="receiptCodePattern" value="'%' + receiptCode + '%'" />
            AND d.receiptCode like #{receiptCodePattern}
        </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>

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

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

    <select id="selectListAgvEntity" resultType="com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail">
    SELECT *
    FROM receipt_detail
   where receiptCode=#{receiptCode} and warehouseCode=#{warehouseCode} and 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 receipt_detail d
   INNER join inventory i on d.materialCode=i.materialCode
   INNER join material m on m.code=d.materialCode
   where d.receiptCode=#{code} and d.warehouseCode=#{warehouseCode} and d.zoneCode="AGV" and i.zoneCode="AGV" and i.containerCode like CONCAT(#{shelfNo},'%')
    </select>

    <select id="rossDoccking" resultType="com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail">
        SELECT r.id, r.warehouseId, r.warehouseCode, r.companyId, r.companyCode, r.sourceCode, r.sourceLine, r.receiptId, r.receiptCode, r.materialId,
        r.materialCode, r.batch, r.lot, r.project, r.manufactureDate, r.expirationDate, r.inventoryStatus, r.qty, r.qtyCompleted, r.price, r.status, r.created,
        r.createdBy, r.lastUpdated, r.lastUpdatedBy, r.deleted, r.userDef1,
        ABS(r.qty-(s.qtyCompleted-s.qty)) temp
        from receipt_detail r
        INNER JOIN shipment_detail s on s.materialCode=r.materialCode and s.id =#{id} and r.created >= DATE_SUB( CURDATE(), INTERVAL 5 DAY )
        <where>
            r.status &lt; 200
            <if test="condition.warehouseId != null ">
                AND r.warehouseId = #{condition.warehouseId}
            </if>
            <if test="condition.materialCode != null">
                AND r.materialCode = #{condition.materialCode}
            </if>
            <if test="condition.qtyCompleted != null ">
                AND r.qtyCompleted = #{condition.qtyCompleted}
            </if>
            <if test="condition.inventoryStatus != null ">
                AND r.inventoryStatus = #{condition.inventoryStatus}
            </if>
            <if test="condition.deleted != null ">
                AND r.deleted = #{condition.deleted}
            </if>

        </where>
        ORDER BY temp asc
        Limit 1
    </select>


    <select id="getReceiptQtyLast7Days" resultType="com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail">
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
		receipt_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="getWarehouseReceipt" resultType="com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail">
    SELECT ifnull(sum(r.qtyCompleted),0) as qty,w.name as warehouseName  from warehouse w
    left JOIN receipt_detail r on r.warehouseCode=w.code and r.status=300
    and date(r.lastUpdated)=CURDATE()  group by w.code

    </select>


    <select id="getCompanyReceipt" resultType="com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail">
    SELECT ifnull(sum(r.qtyCompleted),0) as qty,c.name as companyName  from company c
    left JOIN receipt_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.receipt.receiptDetail.domain.ReceiptDetail">
                 SELECT d.id, d.warehouseId, d.warehouseCode, d.sourceLine, d.receiptId, d.receiptCode, d.materialId, d.materialCode,d.zoneCode,
                 d.batch, d.lot, d.project, d.manufactureDate, d.expirationDate, d.inventoryStatus, d.qty, d.qtyCompleted,d.price,d.unit,
                 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 receipt_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.receiptId = #{receiptId}
    </select>


    <insert id="insertBatch"  parameterType="com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail" keyProperty="id" useGeneratedKeys="true" >
        INSERT INTO receipt_detail
        (
        warehouseId,
        warehouseCode,
        zoneCode,
        companyId,
        companyCode,
        sourceCode,
        sourceLine,
        receiptId,
        receiptCode,
        materialId,
        materialCode,
        batch,
        lot,
        project,
        manufactureDate,
        expirationDate,
        inventoryStatus,
        qty,
        qtyCompleted,
        unit,
        price,
        status,
        created,
        createdBy,
        lastUpdated,
        lastUpdatedBy,
        deleted,
        userDef1,
        userDef2,
        userDef3
        )VALUES
        <foreach collection="receiptDetailList" 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.receiptId,jdbcType=INTEGER},
            #{item.receiptCode,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.inventoryStatus,jdbcType=VARCHAR},
            #{item.qty, jdbcType=DECIMAL},
            #{item.qtyCompleted, jdbcType=DECIMAL},
            #{item.unit,jdbcType=VARCHAR},
            #{item.price, jdbcType=DECIMAL},
            #{item.status, jdbcType=VARCHAR},
            #{item.created, jdbcType=TIMESTAMP},
            #{item.createdBy, jdbcType=VARCHAR},
            #{item.lastUpdated, jdbcType=TIMESTAMP},
            #{item.lastUpdatedBy, jdbcType=VARCHAR},
            #{item.deleted, jdbcType=BIT},
            #{item.userDef1, jdbcType=VARCHAR},
            #{item.userDef2, jdbcType=VARCHAR},
            #{item.userDef3, jdbcType=VARCHAR}
            )
        </foreach>
    </insert>










</mapper>