From 15f3bd3cdf6828181e2a5ea9c230a37570f13417 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 19 十一月 2021 09:17:41 +0800
Subject: [PATCH] 优化查询

---
 java110-core/src/main/java/com/java110/core/factory/CommunitySettingFactory.java |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/java110-core/src/main/java/com/java110/core/factory/CommunitySettingFactory.java b/java110-core/src/main/java/com/java110/core/factory/CommunitySettingFactory.java
index 1dde9c0..95d7c82 100644
--- a/java110-core/src/main/java/com/java110/core/factory/CommunitySettingFactory.java
+++ b/java110-core/src/main/java/com/java110/core/factory/CommunitySettingFactory.java
@@ -5,6 +5,7 @@
 import com.java110.utils.cache.BaseCache;
 import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.util.SerializeUtil;
+import com.java110.utils.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -16,6 +17,9 @@
 
     //鏃ュ織
     private static Logger logger = LoggerFactory.getLogger(CommunitySettingFactory.class);
+
+    public static final String KEY_FEE_SCALE = "SCALE";
+    public static final int DEFAULE_FEE_SCALE = 2;
 
 
     /**
@@ -59,15 +63,13 @@
                 redis.close();
             }
         }
-
-
     }
 
     private static CommunitySettingDto getCommunitySettingFromDb(String communityId, String key, Jedis redis) {
         ICommunitySettingInnerServiceSMO communitySettingInnerServiceSMOImpl = null;
         try {
             communitySettingInnerServiceSMOImpl = ApplicationContextFactory.getBean(ICommunitySettingInnerServiceSMO.class.getName(), ICommunitySettingInnerServiceSMO.class);
-        }catch (NoSuchBeanDefinitionException e){
+        } catch (NoSuchBeanDefinitionException e) {
             communitySettingInnerServiceSMOImpl = ApplicationContextFactory.getBean("communitySettingInnerServiceSMOImpl", ICommunitySettingInnerServiceSMO.class);
         }
         CommunitySettingDto communitySettingDto = new CommunitySettingDto();
@@ -80,6 +82,23 @@
 
         redis.set((communityId + "_" + key + "_community_setting").getBytes(), SerializeUtil.serialize(communitySettingDtos.get(0)));
         return communitySettingDtos.get(0);
+    }
+
+    /**
+     * 鎵嬪伐淇濆瓨鏁版嵁
+     *
+     * @param communitySettingDto
+     */
+    public static void saveCommunitySetting(CommunitySettingDto communitySettingDto) {
+        Jedis redis = null;
+        try {
+            redis = getJedis();
+            redis.set((communitySettingDto.getCommunityId() + "_" + communitySettingDto.getSettingKey() + "_community_setting").getBytes(), SerializeUtil.serialize(communitySettingDto));
+        } finally {
+            if (redis != null) {
+                redis.close();
+            }
+        }
     }
 
     /**
@@ -112,4 +131,37 @@
 
         return communitySettingDto;
     }
+
+    /**
+     * 鏌ヨ灏忔暟鐐� 浣嶆暟
+     *
+     * @param communityId
+     * @return
+     */
+    public static int getFeeScale(String communityId) {
+        String scale = getValue(communityId, KEY_FEE_SCALE);
+        if (StringUtil.isEmpty(scale)) {
+            //闃叉姣忔閮介渶瑕� 鏌ヨ鏁版嵁搴� 澧炲姞 鍘嬪姏锛岃繖閲屽儚缂撳瓨涓啓鍏ラ粯璁ゅ��
+            CommunitySettingDto communitySettingDto = new CommunitySettingDto();
+            communitySettingDto.setCommunityId(communityId);
+            communitySettingDto.setSettingKey(KEY_FEE_SCALE);
+            communitySettingDto.setSettingName("灏忔暟鐐逛綅鏁�");
+            communitySettingDto.setCsId("-1");
+            communitySettingDto.setSettingValue(DEFAULE_FEE_SCALE + "");
+            communitySettingDto.setSettingType(CommunitySettingDto.SETTING_TYPE_FEE);
+            communitySettingDto.setRemark("璐圭敤璁$畻灏忔暟鐐逛綅鏁�,0鑷�4鏁存暟");
+            saveCommunitySetting(communitySettingDto);
+            return DEFAULE_FEE_SCALE;
+        }
+
+        if (!StringUtil.isInteger(scale)) {
+            return DEFAULE_FEE_SCALE;
+        }
+
+        int scaleInt = Integer.parseInt(scale);
+        if (scaleInt > 4 || scaleInt < 0) {
+            return DEFAULE_FEE_SCALE;
+        }
+        return scaleInt;
+    }
 }

--
Gitblit v1.8.0