Просмотр исходного кода

库存预警查询方法提取

liuyao 1 год назад
Родитель
Сommit
95dc5504ff

+ 11 - 0
src/main/java/com/dk/mdm/controller/ivt/inventory/InventoryController.java

@@ -41,4 +41,15 @@ public class InventoryController{
         return inventoryService.selectByCond(query);
     }
 
+    /**
+     * @desc   : 库存预警条件查询
+     * @date   : 2024/6/13 15:33
+     * @author : 刘尧
+     */
+    @ApiOperation(value = "库存预警条件查询", notes = "库存预警条件查询")
+    @PostMapping({"warning_list_by"})
+    public ResponseResultVO<PageList<InventoryResponse>> warningSelectByCond(@RequestBody InventoryQuery query) {
+        return inventoryService.warningSelectByCond(query);
+    }
+
 }

+ 13 - 0
src/main/java/com/dk/mdm/mapper/ivt/InventoryMapper.java

@@ -42,6 +42,13 @@ public interface InventoryMapper extends BaseMapper<Inventory>{
     Long countByCond(InventoryQuery inventoryQuery);
 
     /**
+     * @desc   : 库存预警条件查询个数
+     * @date   : 2024/6/13 17:04
+     * @author : 刘尧
+     */
+    Long warningCountByCond(InventoryQuery inventoryQuery);
+
+    /**
      * @desc   : 条件查询--查单条
      * @date   : 2024/3/20 17:00
      * @author : 寇珊珊
@@ -79,5 +86,11 @@ public interface InventoryMapper extends BaseMapper<Inventory>{
      */
     int updateCost(Inventory inventory);
 
+    /**
+     * @desc   : 库存预警条件查询
+     * @date   : 2024/6/13 17:04
+     * @author : 刘尧
+     */
+    List<InventoryResponse> warningSelectByCond(InventoryQuery inboundQuery);
 }
 

+ 164 - 1
src/main/java/com/dk/mdm/mapper/ivt/InventoryMapper.xml

@@ -138,7 +138,6 @@
             </if>
             <if test="invQtyFlag != null and invQtyFlag = true">
                 and tpi.inv_qty != 0
-
             </if>
         </where>
     </sql>
@@ -305,6 +304,170 @@
             </if>
         </where>
     </select>
+    <select id="warningCountByCond" resultType="java.lang.Long">
+        SELECT
+        count(1)
+        FROM dkic_b.t_psi_inventory tpi
+        <include refid="Join_Table"/>
+        <where>
+            (tmgs.warning_lower_limit &lt;&gt; 0 OR tmgs.warning_upper_limit &lt;&gt; 0)
+            AND (tpi.inv_qty > tmgs.warning_lower_limit OR tpi.inv_qty > tmgs.warning_upper_limit)
+            <if test="whId != null and whId != ''">
+                AND tpi.wh_id = #{whId}::UUID
+            </if>
+            <if test="whIds != null and whIds.size()>0">
+                AND tpi.wh_id =
+                any(#{whIds, typeHandler=UuidListTypeHandler})
+            </if>
+            <if test="skuId != null and skuId != ''">
+                AND tpi.sku_id = #{skuId}
+            </if>
+            <if test="nonStdCode != null and nonStdCode != ''">
+                AND tpi.non_std_code = #{nonStdCode}
+            </if>
+            <if test="invQty != null">
+                AND tpi.inv_qty = #{invQty}
+            </if>
+            <if test="outingQty != null">
+                AND tpi.outing_qty = #{outingQty}
+            </if>
+            <if test="usableQty != null">
+                AND tpi.usable_qty = #{usableQty}
+            </if>
+            <if test="costPrice != null">
+                AND tpi.cost_price = #{costPrice}
+            </if>
+            <if test="costAmt != null">
+                AND tpi.cost_amt = #{costAmt}
+            </if>
+            <if test="flgValid != null">
+                AND tpi.flg_valid = #{flgValid}
+            </if>
+            <if test="flgZero == true">
+                AND tpi.inv_qty != 0
+            </if>
+            <if test="cpId != null">
+                AND tpi.cp_id = #{cpId}
+            </if>
+            <if test="freezeQty != null">
+                AND tpi.freeze_qty = #{freezeQty}
+            </if>
+            <if test="categoryId != null and categoryId != ''">
+                AND tmgs.category_id = #{categoryId}::UUID
+            </if>
+            <if test="brandId != null and brandId != ''">
+                AND tmgs.brand_id = #{brandId}::UUID
+            </if>
+            <if test="searchText != null">
+                AND (tmgs.sku_model  like concat('%', my_ex.likequery(#{searchText}) , '%')
+                OR  tmgs.sku_name like concat('%', my_ex.likequery(#{searchText}) , '%')
+                OR  tpi.non_std_code like concat('%', my_ex.likequery(#{searchText}) , '%')
+                )
+            </if>
+            <if test="invQtyFlag != null and invQtyFlag = true">
+                and tpi.inv_qty != 0
+            </if>
+        </where>
+    </select>
+
+    <select id="warningSelectByCond" resultType="com.dk.mdm.model.response.ivt.InventoryResponse">
+        SELECT
+        <include refid="Base_Column_List_Response"/>
+        ,tmgs.sku_code
+        ,tmgs.sku_model
+        ,tmgs.sku_name
+        ,tmgs.sku_spec
+        ,tmgs.price_purchase
+        ,tmgs.price_standard
+        ,tmgs.price_wholesale
+        ,tmgs.price_other
+        ,tmgs.price_limited
+        ,tmgs.sku_images
+        ,tmgs.unit_id
+        ,tmgs.sub_unit_id
+        ,tmgs.warning_upper_limit
+        ,tmgs.warning_lower_limit
+        ,tmgs.pack_box
+        ,tmu.unit_name    AS "unitName"
+        ,subtmu.unit_name AS "subUnitName"
+        ,tmgs.flg_sub_unit
+        ,tmgb.brand_name
+        ,tmgb.short_name
+        ,tmw.wh_name
+        ,tmgc.cat_name as "catName"
+        ,tmgseries.series_name as "seriesName"
+        ,tmu.decimal_places    as "decimalPlaces"
+        FROM dkic_b.t_psi_inventory tpi
+        <include refid="Join_Table"/>
+        <where>
+            (tmgs.warning_lower_limit &lt;&gt; 0 OR tmgs.warning_upper_limit &lt;&gt; 0)
+            AND (tpi.inv_qty > tmgs.warning_lower_limit OR tpi.inv_qty > tmgs.warning_upper_limit)
+            <if test="whId != null and whId != ''">
+                AND tpi.wh_id = #{whId}::UUID
+            </if>
+            <if test="whIds != null and whIds.size()>0">
+                AND tpi.wh_id =
+                any(#{whIds, typeHandler=UuidListTypeHandler})
+            </if>
+            <if test="skuId != null and skuId != ''">
+                AND tpi.sku_id = #{skuId}
+            </if>
+            <if test="nonStdCode != null and nonStdCode != ''">
+                AND tpi.non_std_code = #{nonStdCode}
+            </if>
+            <if test="invQty != null">
+                AND tpi.inv_qty = #{invQty}
+            </if>
+            <if test="outingQty != null">
+                AND tpi.outing_qty = #{outingQty}
+            </if>
+            <if test="usableQty != null">
+                AND tpi.usable_qty = #{usableQty}
+            </if>
+            <if test="costPrice != null">
+                AND tpi.cost_price = #{costPrice}
+            </if>
+            <if test="costAmt != null">
+                AND tpi.cost_amt = #{costAmt}
+            </if>
+            <if test="flgValid != null">
+                AND tpi.flg_valid = #{flgValid}
+            </if>
+            <if test="flgZero == true">
+                AND tpi.inv_qty != 0
+            </if>
+            <if test="cpId != null">
+                AND tpi.cp_id = #{cpId}
+            </if>
+            <if test="freezeQty != null">
+                AND tpi.freeze_qty = #{freezeQty}
+            </if>
+            <if test="categoryId != null and categoryId != ''">
+                AND tmgs.category_id = #{categoryId}::UUID
+            </if>
+            <if test="brandId != null and brandId != ''">
+                AND tmgs.brand_id = #{brandId}::UUID
+            </if>
+            <if test="searchText != null">
+                AND (tmgs.sku_model  like concat('%', my_ex.likequery(#{searchText}) , '%')
+                OR  tmgs.sku_name like concat('%', my_ex.likequery(#{searchText}) , '%')
+                OR  tpi.non_std_code like concat('%', my_ex.likequery(#{searchText}) , '%')
+                )
+            </if>
+            <if test="invQtyFlag != null and invQtyFlag = true">
+                and tpi.inv_qty != 0
+            </if>
+        </where>
+        <if test="desc != null and desc != ''">
+            order by tpi.usable_qty desc
+        </if>
+        <if test="desc == null or desc == ''">
+            order by tpi.usable_qty
+        </if>
+        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
+            limit #{end} offset #{start}
+        </if>
+    </select>
 
     <!--修改库存数量金额-->
     <update id="updateAmountAndQuantity" parameterType="com.dk.mdm.model.vo.ivt.InventoryVO">

+ 24 - 28
src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java

@@ -101,34 +101,7 @@ public class InventoryService extends BaseService<Inventory> {
      */
     @Pagination
     public ResponseResultVO<PageList<InventoryResponse>> selectByCond(InventoryQuery inboundQuery) {
-
-        ResponseResultVO<PageList<InventoryResponse>> pageListResponseResultVO = super.mergeListWithCount(inboundQuery, inventoryMapper.selectByCond(inboundQuery), inventoryMapper.countByCond(inboundQuery));
-        if (inboundQuery.getWinning()!=null && inboundQuery.getWinning() == true){
-            PageList<InventoryResponse> data = pageListResponseResultVO.getData();
-            List<InventoryResponse> list = data.getList();
-            List<InventoryResponse> newList = list.stream().filter(item ->
-                    (
-                            item.getWarningLowerLimit()!= 0
-                            || item.getWarningUpperLimit() != 0)
-                            && (item.getInvQty().longValue()>item.getWarningLowerLimit()
-                            || item.getInvQty().longValue()>item.getWarningUpperLimit())
-                    ).collect(Collectors.toList());
-            newList.forEach(item -> {
-                int invQty = item.getInvQty().intValue();
-                Long warningLowerLimit = item.getWarningLowerLimit();
-                Long warningUpperLimit = item.getWarningUpperLimit();
-                if (invQty > warningLowerLimit){
-                    item.setWarningMsg("超出警戒上限");
-                }
-                if (invQty > warningUpperLimit){
-                    item.setWarningMsg("超出警戒下限");
-                }
-            });
-            data.setList(newList);
-            pageListResponseResultVO.setData(data);
-        }
-
-        return pageListResponseResultVO;
+        return super.mergeListWithCount(inboundQuery, inventoryMapper.selectByCond(inboundQuery), inventoryMapper.countByCond(inboundQuery));
     }
 
 
@@ -2238,4 +2211,27 @@ public class InventoryService extends BaseService<Inventory> {
     }
 
 
+    public ResponseResultVO<PageList<InventoryResponse>> warningSelectByCond(InventoryQuery inboundQuery) {
+        inboundQuery.setStart((inboundQuery.getCurrentPage() - 1) * inboundQuery.getPageSize());
+        inboundQuery.setEnd(inboundQuery.getPageSize());
+        ResponseResultVO<PageList<InventoryResponse>> pageListResponseResultVO = super.mergeListWithCount(
+                inboundQuery,
+                inventoryMapper.warningSelectByCond(inboundQuery),
+                inventoryMapper.warningCountByCond(inboundQuery));
+        PageList<InventoryResponse> data = pageListResponseResultVO.getData();
+        List<InventoryResponse> list = data.getList();
+        list.forEach(item -> {
+            int invQty = item.getInvQty().intValue();
+            Long warningLowerLimit = item.getWarningLowerLimit();
+            Long warningUpperLimit = item.getWarningUpperLimit();
+            if (invQty > warningLowerLimit){
+                item.setWarningMsg("超出警戒上限");
+            }
+            if (invQty > warningUpperLimit){
+                item.setWarningMsg("超出警戒下限");
+            }
+        });
+
+        return pageListResponseResultVO;
+    }
 }