From 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 19 七月 2022 21:49:55 +0800
Subject: [PATCH] 优化添加设备 功能
---
java110-core/src/main/java/com/java110/core/factory/CommunitySettingFactory.java | 91 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 87 insertions(+), 4 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..1a95799 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,8 +5,9 @@
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;
@@ -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;
/**
@@ -49,6 +53,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 {
@@ -59,15 +94,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 +113,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 +162,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