From b8d1f25f4fdb9d8bc109c103e84307d6925ce218 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期三, 21 十二月 2022 17:16:04 +0800
Subject: [PATCH] 优化代码
---
java110-core/src/main/java/com/java110/core/factory/CommunitySettingFactory.java | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 111 insertions(+), 5 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 f281839..3710dc8 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
@@ -2,11 +2,14 @@
import com.java110.dto.communitySetting.CommunitySettingDto;
import com.java110.intf.community.ICommunitySettingInnerServiceSMO;
+import com.java110.po.communitySetting.CommunitySettingPo;
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 com.java110.core.log.LoggerFactory;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import redis.clients.jedis.Jedis;
import java.util.List;
@@ -15,6 +18,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;
/**
@@ -48,6 +54,37 @@
return communitySettingDto.getSettingValue();
}
+ /**
+ * 鏌ヨ璁剧疆鍊�
+ *
+ * @param communityId
+ * @param key
+ * @return
+ */
+ public static String getRemark(String communityId, String key) {
+ Jedis redis = null;
+ CommunitySettingDto communitySettingDto = null;
+ try {
+ redis = getJedis();
+ Object object = SerializeUtil.unserialize(redis.get((communityId + "_" + key + "_community_setting").getBytes()));
+ if (object == null) {//杩欓噷瀛樺湪骞跺彂闂锛屼絾鏄� 绛変簬鏌ヨ浜嗗娆� 鐒跺悗澶氭鍐欑紦瀛橈紝浣滆�呰涓� 杩欑搴旇姣斿姞鍏ㄥ眬閿佹晥鐜囬珮浜�
+ communitySettingDto = getCommunitySettingFromDb(communityId, key, redis);
+ } else {
+ communitySettingDto = (CommunitySettingDto) object;
+ }
+ } finally {
+ if (redis != null) {
+ redis.close();
+ }
+ }
+
+ if (communitySettingDto == null) {
+ return null;
+ }
+
+ return communitySettingDto.getRemark();
+ }
+
public static CommunitySettingDto getCommunitySettingFromDb(String communityId, String key) {
Jedis redis = null;
try {
@@ -58,13 +95,15 @@
redis.close();
}
}
-
-
}
private static CommunitySettingDto getCommunitySettingFromDb(String communityId, String key, Jedis redis) {
- ICommunitySettingInnerServiceSMO communitySettingInnerServiceSMOImpl
- = ApplicationContextFactory.getBean(ICommunitySettingInnerServiceSMO.class.getName(), ICommunitySettingInnerServiceSMO.class);
+ ICommunitySettingInnerServiceSMO communitySettingInnerServiceSMOImpl = null;
+ try {
+ communitySettingInnerServiceSMOImpl = ApplicationContextFactory.getBean(ICommunitySettingInnerServiceSMO.class.getName(), ICommunitySettingInnerServiceSMO.class);
+ } catch (NoSuchBeanDefinitionException e) {
+ communitySettingInnerServiceSMOImpl = ApplicationContextFactory.getBean("communitySettingInnerServiceSMOImpl", ICommunitySettingInnerServiceSMO.class);
+ }
CommunitySettingDto communitySettingDto = new CommunitySettingDto();
communitySettingDto.setCommunityId(communityId);
communitySettingDto.setSettingKey(key);
@@ -75,6 +114,40 @@
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();
+ }
+ }
+ }
+
+ /**
+ * 鎵嬪伐淇濆瓨鏁版嵁
+ *
+ * @param communitySettingDto
+ */
+ public static void deleteCommunitySetting(CommunitySettingPo communitySettingPo) {
+ Jedis redis = null;
+ try {
+ redis = getJedis();
+ redis.del((communitySettingPo.getCommunityId() + "_" + communitySettingPo.getSettingKey() + "_community_setting").getBytes());
+ } finally {
+ if (redis != null) {
+ redis.close();
+ }
+ }
}
/**
@@ -107,4 +180,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