From b1012d23b8ae65e45902900c687bf68f39840ac2 Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期一, 17 十一月 2025 09:24:37 +0800
Subject: [PATCH] 高并发下库位抢占导致的数据错乱

---
 src/main/resources/mapper/LocDetlMapper.xml |  357 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 349 insertions(+), 8 deletions(-)

diff --git a/src/main/resources/mapper/LocDetlMapper.xml b/src/main/resources/mapper/LocDetlMapper.xml
index 2a54395..3298208 100644
--- a/src/main/resources/mapper/LocDetlMapper.xml
+++ b/src/main/resources/mapper/LocDetlMapper.xml
@@ -119,6 +119,156 @@
             </otherwise>
         </choose>
     </sql>
+    <sql id="batchSeqA">
+        <choose>
+            <when test="batch != null and batch != ''">
+                and a.batch = #{batch}
+            </when>
+            <otherwise>
+                and (a.batch IS NULL OR a.batch = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="brand != null and brand != ''">
+                and a.brand = #{brand}
+            </when>
+            <otherwise>
+                and (a.brand IS NULL OR a.brand = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="standby1 != null and standby1 != ''">
+                and a.standby1 = #{standby1}
+            </when>
+            <otherwise>
+                and (a.standby1 IS NULL OR a.standby1 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="standby2 != null and standby2 != ''">
+                and a.standby2 = #{standby2}
+            </when>
+            <otherwise>
+                and (a.standby2 IS NULL OR a.standby2 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="standby3 != null and standby3 != ''">
+                and a.standby3 = #{standby3}
+            </when>
+            <otherwise>
+                and (a.standby3 IS NULL OR a.standby3 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="boxType1 != null and boxType1 != ''">
+                and a.box_type1 = #{boxType1}
+            </when>
+            <otherwise>
+                and (a.box_type1 IS NULL OR a.box_type1 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="boxType2 != null and boxType2 != ''">
+                and a.box_type2 = #{boxType2}
+            </when>
+            <otherwise>
+                and (a.box_type2 IS NULL OR a.box_type2 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="boxType3 != null and boxType3 != ''">
+                and a.box_type3 = #{boxType3}
+            </when>
+            <otherwise>
+                and (a.box_type3 IS NULL OR a.box_type3 = '')
+            </otherwise>
+        </choose>
+    </sql>
+    <sql id="batchSeqB">
+        <choose>
+            <when test="batch != null and batch != ''">
+                and a.batch = #{batch}
+            </when>
+            <otherwise>
+                and (a.batch IS NULL OR a.batch = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="model != null and model != ''">
+                and a.model = #{model}
+            </when>
+            <otherwise>
+                and (a.model IS NULL OR a.model = '')
+            </otherwise>
+        </choose>
+    </sql>
+    <sql id="batchSeqNew">
+        <choose>
+            <when test="batch != null and batch != ''">
+                and batch = #{batch}
+            </when>
+            <otherwise>
+                and (batch IS NULL OR batch = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="brand != null and brand != ''">
+                and brand = #{brand}
+            </when>
+            <otherwise>
+                and (brand IS NULL OR brand = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="standby1 != null and standby1 != ''">
+                and standby1 = #{standby1}
+            </when>
+            <otherwise>
+                and (standby1 IS NULL OR standby1 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="standby2 != null and standby2 != ''">
+                and standby2 = #{standby2}
+            </when>
+            <otherwise>
+                and (standby2 IS NULL OR standby2 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="standby3 != null and standby3 != ''">
+                and standby3 = #{standby3}
+            </when>
+            <otherwise>
+                and (standby3 IS NULL OR standby3 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="boxType1 != null and boxType1 != ''">
+                and box_type1 = #{boxType1}
+            </when>
+            <otherwise>
+                and (box_type1 IS NULL OR box_type1 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="boxType2 != null and boxType2 != ''">
+                and box_type2 = #{boxType2}
+            </when>
+            <otherwise>
+                and (box_type2 IS NULL OR box_type2 = '')
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="boxType3 != null and boxType3 != ''">
+                and box_type3 = #{boxType3}
+            </when>
+            <otherwise>
+                and (box_type3 IS NULL OR box_type3 = '')
+            </otherwise>
+        </choose>
+    </sql>
 
     <sql id="selectAllSql">
         <if test="locNo!=null and locNo!='' ">
@@ -160,7 +310,7 @@
 
     <select id="selectItem" resultMap="BaseResultMap">
         select top 1 *
-        from asr_loc_detl
+        from asr_loc_detl d
         where 1=1
         and loc_no = #{locNo}
         and matnr = #{matnr}
@@ -172,7 +322,7 @@
         where 1=1
         and loc_no = #{locNo}
         and matnr = #{matnr}
-        <include refid="batchSeq"></include>
+        <include refid="batchSeqNew"></include>
     </delete>
 
     <update id="updateAnfme">
@@ -182,7 +332,7 @@
         where 1=1
         and loc_no = #{locNo}
         and matnr = #{matnr}
-        <include refid="batchSeq"></include>
+        <include refid="batchSeqNew"></include>
     </update>
 
     <sql id="stockOutCondition">
@@ -209,6 +359,12 @@
         </if>
         <if test="specs!=null and specs!='' ">
             and a.specs like '%' + #{specs} + '%'
+        </if>
+        <if test="model!=null and model!='' ">
+            and a.model like '%' + #{model} + '%'
+        </if>
+        <if test="volume!=null and volume!='' ">
+            and a.volume like '%' + #{volume} + '%'
         </if>
     </sql>
 
@@ -240,14 +396,20 @@
         select * from
         (
             select
-            ROW_NUMBER() over (order by sum(a.anfme) desc) as row
+            ROW_NUMBER() over (order by matnr desc) as row
             , a.matnr
-            , a.batch
+            , a.maktx
+            , a.model
+            , a.volume
+            ,manu_date manuDate
+            ,batch
             , sum(a.anfme) as anfme
+            ,sum(a.weight) weight
+            ,sum(a.man_length) manLength
             from asr_loc_detl a
             where 1=1
             <include refid="stockOutCondition"></include>
-            group by a.matnr, a.batch
+            group by a.matnr,a.maktx,a.model,a.volume,manu_date,batch
          ) t where t.row between ((#{pageNumber}-1)*#{pageSize}+1) and (#{pageNumber}*#{pageSize})
     </select>
 
@@ -256,10 +418,15 @@
         (
         select
         a.matnr
+        , a.maktx
+        , a.model
+        , a.volume
+        ,manu_date manuDate
+        ,batch
         from asr_loc_detl a
         where 1=1
         <include refid="stockOutCondition"></include>
-        group by a.matnr
+        group by a.matnr,a.maktx,a.model,a.volume,manu_date,batch
      ) b
     </select>
 
@@ -267,10 +434,17 @@
         select
         ROW_NUMBER() over (order by sum(a.anfme) desc) as row
         , a.matnr
+        , a.maktx
+        , a.model
+        , a.volume
+        ,manu_date manuDate
+        ,batch
         , sum(a.anfme) as anfme
+        ,sum(a.weight) weight
+        ,sum(a.man_length) manLength
         from asr_loc_detl a
         where 1=1
-        group by a.matnr
+        group by a.matnr,a.maktx,a.model,a.volume,manu_date,batch
     </select>
 
     <select id="selectPakoutByRule" resultMap="BaseResultMap">
@@ -390,6 +564,173 @@
         desc
     </select>
 
+    <select id="queryStockAll" resultMap="BaseResultMap">
+        select a.*
+        from asr_loc_detl a
+        left join asr_loc_mast b on a.loc_no = b.loc_no
+        where 1=1
+        and b.loc_sts = 'F'
+        and a.matnr = #{matnr}
+        <!--        <choose>-->
+        <!--            <when test="batch != null and batch != ''">-->
+        <!--                and a.batch = #{batch}-->
+        <!--            </when>-->
+        <!--            <otherwise>-->
+        <!--                and (a.batch IS NULL OR a.batch = '')-->
+        <!--            </otherwise>-->
+        <!--        </choose>-->
+        <if test="orderNo != null and orderNo != ''">
+            and a.order_no = #{orderNo}
+        </if>
+
+        <include refid="batchSeqA"></include>
+
+
+        <if test="locNos != null and locNos.size > 0">
+            and b.loc_no not in
+            <foreach item="item" collection="locNos" index="index"  separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+
+        order by
+        DATEPART(yyyy,a.modi_time),DATEPART(mm,a.modi_time),DATEPART(dd,a.modi_time), a.anfme
+        desc,
+        NEWID(),
+        case
+        when (left(a.loc_no, 2) = '01') then 0
+        when (left(a.loc_no, 2) = '02') then 1
+        when (left(a.loc_no, 2) = '03') then 1
+        when (left(a.loc_no, 2) = '04') then 0
+        when (left(a.loc_no, 2) = '05') then 0
+        when (left(a.loc_no, 2) = '06') then 1
+        when (left(a.loc_no, 2) = '07') then 1
+        when (left(a.loc_no, 2) = '08') then 0
+        when (left(a.loc_no, 2) = '09') then 0
+        when (left(a.loc_no, 2) = '10') then 1
+        when (left(a.loc_no, 2) = '11') then 1
+        when (left(a.loc_no, 2) = '12') then 0
+        when (left(a.loc_no, 2) = '13') then 0
+        when (left(a.loc_no, 2) = '14') then 1
+        when (left(a.loc_no, 2) = '15') then 1
+        when (left(a.loc_no, 2) = '16') then 0
+        when (left(a.loc_no, 2) = '17') then 0
+        when (left(a.loc_no, 2) = '18') then 1
+        when (left(a.loc_no, 2) = '19') then 1
+        when (left(a.loc_no, 2) = '20') then 0
+        when (left(a.loc_no, 2) = '21') then 0
+        when (left(a.loc_no, 2) = '22') then 1
+        when (left(a.loc_no, 2) = '23') then 1
+        when (left(a.loc_no, 2) = '24') then 0
+        when (left(a.loc_no, 2) = '25') then 0
+        when (left(a.loc_no, 2) = '26') then 1
+        when (left(a.loc_no, 2) = '27') then 1
+        when (left(a.loc_no, 2) = '28') then 0
+        when (left(a.loc_no, 2) = '29') then 0
+        when (left(a.loc_no, 2) = '30') then 1
+        when (left(a.loc_no, 2) = '31') then 1
+        when (left(a.loc_no, 2) = '32') then 0
+        when (left(a.loc_no, 2) = '33') then 0
+        when (left(a.loc_no, 2) = '34') then 1
+        when (left(a.loc_no, 2) = '35') then 1
+        when (left(a.loc_no, 2) = '36') then 0
+        when (left(a.loc_no, 2) = '37') then 0
+        when (left(a.loc_no, 2) = '38') then 1
+        when (left(a.loc_no, 2) = '39') then 1
+        when (left(a.loc_no, 2) = '40') then 0
+        when (left(a.loc_no, 2) = '41') then 0
+        when (left(a.loc_no, 2) = '42') then 1
+        when (left(a.loc_no, 2) = '43') then 1
+        when (left(a.loc_no, 2) = '44') then 0
+        when (left(a.loc_no, 2) = '45') then 0
+        when (left(a.loc_no, 2) = '46') then 1
+        when (left(a.loc_no, 2) = '47') then 1
+        when (left(a.loc_no, 2) = '48') then 0
+        else 0
+        end
+        desc
+    </select>
+
+    <select id="queryStockAllNew" resultMap="BaseResultMap">
+        select a.*
+        from asr_loc_detl a
+        left join asr_loc_mast b on a.loc_no = b.loc_no
+        where 1=1
+        and b.loc_sts = 'F'
+        and a.matnr = #{matnr}
+        and a.volume = #{volume}
+        <if test="orderNo != null and orderNo != ''">
+            and a.order_no = #{orderNo}
+        </if>
+
+        <include refid="batchSeqB"></include>
+
+
+        <if test="locNos != null and locNos.size > 0">
+            and b.loc_no not in
+            <foreach item="item" collection="locNos" index="index"  separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+
+        order by
+        DATEPART(yyyy,a.modi_time),DATEPART(mm,a.modi_time),DATEPART(dd,a.modi_time), a.anfme
+        desc,
+        NEWID(),
+        case
+        when (left(a.loc_no, 2) = '01') then 0
+        when (left(a.loc_no, 2) = '02') then 1
+        when (left(a.loc_no, 2) = '03') then 1
+        when (left(a.loc_no, 2) = '04') then 0
+        when (left(a.loc_no, 2) = '05') then 0
+        when (left(a.loc_no, 2) = '06') then 1
+        when (left(a.loc_no, 2) = '07') then 1
+        when (left(a.loc_no, 2) = '08') then 0
+        when (left(a.loc_no, 2) = '09') then 0
+        when (left(a.loc_no, 2) = '10') then 1
+        when (left(a.loc_no, 2) = '11') then 1
+        when (left(a.loc_no, 2) = '12') then 0
+        when (left(a.loc_no, 2) = '13') then 0
+        when (left(a.loc_no, 2) = '14') then 1
+        when (left(a.loc_no, 2) = '15') then 1
+        when (left(a.loc_no, 2) = '16') then 0
+        when (left(a.loc_no, 2) = '17') then 0
+        when (left(a.loc_no, 2) = '18') then 1
+        when (left(a.loc_no, 2) = '19') then 1
+        when (left(a.loc_no, 2) = '20') then 0
+        when (left(a.loc_no, 2) = '21') then 0
+        when (left(a.loc_no, 2) = '22') then 1
+        when (left(a.loc_no, 2) = '23') then 1
+        when (left(a.loc_no, 2) = '24') then 0
+        when (left(a.loc_no, 2) = '25') then 0
+        when (left(a.loc_no, 2) = '26') then 1
+        when (left(a.loc_no, 2) = '27') then 1
+        when (left(a.loc_no, 2) = '28') then 0
+        when (left(a.loc_no, 2) = '29') then 0
+        when (left(a.loc_no, 2) = '30') then 1
+        when (left(a.loc_no, 2) = '31') then 1
+        when (left(a.loc_no, 2) = '32') then 0
+        when (left(a.loc_no, 2) = '33') then 0
+        when (left(a.loc_no, 2) = '34') then 1
+        when (left(a.loc_no, 2) = '35') then 1
+        when (left(a.loc_no, 2) = '36') then 0
+        when (left(a.loc_no, 2) = '37') then 0
+        when (left(a.loc_no, 2) = '38') then 1
+        when (left(a.loc_no, 2) = '39') then 1
+        when (left(a.loc_no, 2) = '40') then 0
+        when (left(a.loc_no, 2) = '41') then 0
+        when (left(a.loc_no, 2) = '42') then 1
+        when (left(a.loc_no, 2) = '43') then 1
+        when (left(a.loc_no, 2) = '44') then 0
+        when (left(a.loc_no, 2) = '45') then 0
+        when (left(a.loc_no, 2) = '46') then 1
+        when (left(a.loc_no, 2) = '47') then 1
+        when (left(a.loc_no, 2) = '48') then 0
+        else 0
+        end
+        desc
+    </select>
+
     <select id="queryStockAnfme" resultType="java.lang.Double">
         select sum(anfme) as count from man_loc_detl
          where 1=1

--
Gitblit v1.9.1