From 2f8e70ad2884d2b6b7443dfae0af11ae9cfc8b99 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 28 二月 2025 17:44:10 +0800
Subject: [PATCH] bug修改

---
 manage/src/main/java/com/jilongda/manage/service/impl/TLensGoodsServiceImpl.java |   75 +++++++++++++++----------------------
 1 files changed, 31 insertions(+), 44 deletions(-)

diff --git a/manage/src/main/java/com/jilongda/manage/service/impl/TLensGoodsServiceImpl.java b/manage/src/main/java/com/jilongda/manage/service/impl/TLensGoodsServiceImpl.java
index 283931c..19c4c89 100644
--- a/manage/src/main/java/com/jilongda/manage/service/impl/TLensGoodsServiceImpl.java
+++ b/manage/src/main/java/com/jilongda/manage/service/impl/TLensGoodsServiceImpl.java
@@ -19,7 +19,10 @@
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * <p>
@@ -35,6 +38,7 @@
 
     @Resource
     private SecSettingMapper secSettingMapper;
+    private Map<String, Map<String, JSONObject>> cachedSphereMaps = new ConcurrentHashMap<>();
     @Override
     public PageInfo<TLensGoodsVO> lensReceiptList(TLensGoodsQuery query) {
         PageInfo<TLensGoodsVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
@@ -44,60 +48,43 @@
             if (tFrameGoodsVO.getTotal() < secSetting.getLensThreshold()) {
                 tFrameGoodsVO.setIsWarning(1);
             }
-            switch (tFrameGoodsVO.getLensType()){
+            String sphere = null;
+            switch (tFrameGoodsVO.getLensType()) {
                 case 1:
-                    String sphere = tFrameGoodsVO.getSphere();
-                    if (sphere.contains("cost")){
-                        JSONArray objects = JSONObject.parseArray(sphere);
-                        // 遍历这个数组
-                        for (Object object : objects) {
-                            JSONObject jsonObject = (JSONObject) object;
-                            String cost = jsonObject.getString("refractiveIndex");
-                            if (tFrameGoodsVO.getRefractiveIndex().equals(cost)){
-                                tFrameGoodsVO.setSale(jsonObject.getString("sales"));
-                                tFrameGoodsVO.setCost(jsonObject.getString("cost"));
-                                break;
-                            }
-                        }
-                    }
+                    sphere = tFrameGoodsVO.getSphere();
                     break;
                 case 2:
-                    String sphere1 = tFrameGoodsVO.getAsphericSurface();
-                    if (sphere1.contains("cost")){
-                        JSONArray objects = JSONObject.parseArray(sphere1);
-                        // 遍历这个数组
-                        for (Object object : objects) {
-                            JSONObject jsonObject = (JSONObject) object;
-                            String cost = jsonObject.getString("refractiveIndex");
-                            if (tFrameGoodsVO.getRefractiveIndex().equals(cost)){
-                                tFrameGoodsVO.setSale(jsonObject.getString("sales"));
-                                tFrameGoodsVO.setCost(jsonObject.getString("cost"));
-                                break;
-                            }
-                        }
-                    }
+                    sphere = tFrameGoodsVO.getAsphericSurface();
                     break;
                 case 3:
-                    String sphere2 = tFrameGoodsVO.getDoubleNon();
-                    if (sphere2.contains("cost")){
-                        JSONArray objects = JSONObject.parseArray(sphere2);
-                        // 遍历这个数组
-                        for (Object object : objects) {
-                            JSONObject jsonObject = (JSONObject) object;
-                            String cost = jsonObject.getString("refractiveIndex");
-                            if (tFrameGoodsVO.getRefractiveIndex().equals(cost)){
-                                tFrameGoodsVO.setSale(jsonObject.getString("sales"));
-                                tFrameGoodsVO.setCost(jsonObject.getString("cost"));
-                                break;
-                            }
-                        }
-                    }
+                    sphere = tFrameGoodsVO.getDoubleNon();
                     break;
             }
 
-
+            if (sphere != null && sphere.contains("cost")) {
+                updateSaleAndCost(tFrameGoodsVO, sphere);
+            }
         }
         pageInfo.setRecords(list);
         return pageInfo;
     }
+    private void updateSaleAndCost(TLensGoodsVO tFrameGoodsVO, String sphere) {
+        Map<String, JSONObject> costMap = cachedSphereMaps.get(sphere);
+        if (costMap == null) {
+            costMap = new HashMap<>();
+            JSONArray objects = JSONObject.parseArray(sphere);
+            for (Object object : objects) {
+                JSONObject jsonObject = (JSONObject) object;
+                costMap.put(jsonObject.getString("refractiveIndex"), jsonObject);
+            }
+            cachedSphereMaps.put(sphere, costMap);
+        }
+
+        JSONObject matchingObject = costMap.get(tFrameGoodsVO.getRefractiveIndex());
+        if (matchingObject != null) {
+            tFrameGoodsVO.setSale(matchingObject.getString("sales"));
+            tFrameGoodsVO.setCost(matchingObject.getString("cost"));
+        }
+    }
+
 }

--
Gitblit v1.7.1