From 7aa20d949aeb4fbae03722e2a9a3edfce3a98d8a Mon Sep 17 00:00:00 2001
From: zyx <zyx123456>
Date: 星期五, 22 十二月 2023 13:37:35 +0800
Subject: [PATCH] 合并订单

---
 src/main/java/com/zy/asrs/utils/Utils.java |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/Utils.java b/src/main/java/com/zy/asrs/utils/Utils.java
index d456395..c1c4613 100644
--- a/src/main/java/com/zy/asrs/utils/Utils.java
+++ b/src/main/java/com/zy/asrs/utils/Utils.java
@@ -1,6 +1,8 @@
 package com.zy.asrs.utils;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.Arith;
@@ -494,4 +496,57 @@
         }
     }
 
+    public static String getOrderNo(String orderNo, double anfme){
+        JSONArray orderArray = new JSONArray();
+        //濡傛灉璁㈠崟鍙蜂负jsonString
+        if(orderNo.contains("{")){
+            JSONArray jsonArray = JSON.parseArray(orderNo);
+            //閬嶅巻鎵�鏈夎鍗曞彿鍙婅鍗曟暟閲�
+            for (Object o : jsonArray){
+                JSONObject orderJson = (JSONObject) o;
+                Double orderAnfme = orderJson.getDouble("anfme");
+                //濡傛灉璁㈠崟鏁伴噺涓�0锛屽垯璺宠繃
+                if(orderAnfme <= 0){
+                    continue;
+                }
+                if(orderAnfme > anfme){
+                    //濡傛灉璁㈠崟鏁伴噺澶т簬璇ュ簱瀛樻暟閲忥紝涓旇鍗曟暟缁勪负绌猴紝鍒欑洿鎺ヨ繑鍥炶璁㈠崟鍙凤紝鍚﹀垯灏卞皢璇ヨ鍗曟坊鍔犲埌璁㈠崟鏁扮粍
+                    if(orderArray.isEmpty()){
+                        return orderJson.getString("orderNo");
+                    }else {
+                        orderJson.put("anfme",anfme);
+                        orderArray.add(orderJson);
+                    }
+                }else {
+                    anfme -= orderAnfme;
+                    orderArray.add(orderJson);
+                }
+            }
+            return orderArray.toJSONString();
+        }else {
+            return orderNo;
+        }
+
+    }
+
+    public static String orderMergeUpdate(String orderNo, double anfme){
+        if(orderNo.contains("{")){
+            JSONArray jsonArray = JSON.parseArray(orderNo);
+            for(int i=0; i<jsonArray.size(); i++){
+                JSONObject orderJson = (JSONObject)jsonArray.get(i);
+                Double orderAnfme = orderJson.getDouble("anfme");
+                if(orderAnfme > anfme){
+                    ((JSONObject) jsonArray.get(i)).put("anfme",orderAnfme - anfme);
+                    return jsonArray.toJSONString();
+                }else {
+                    ((JSONObject) jsonArray.get(i)).put("anfme",0);
+                    anfme -= orderAnfme;
+                }
+            }
+            return jsonArray.toJSONString();
+        }else {
+            return orderNo;
+        }
+    }
+
 }

--
Gitblit v1.9.1