From bf4ac3ad7a20fadd5aaa92ea0b6abde452c232ee Mon Sep 17 00:00:00 2001
From: 若依 <yzz_ivy@163.com>
Date: 星期二, 30 十一月 2021 11:03:08 +0800
Subject: [PATCH] !378 fix: crontab组件bug Merge pull request !378 from fuzui/fix_cron_tool
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java | 115 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 91 insertions(+), 24 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java
index cdc6f6f..16e7fca 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java
@@ -15,6 +15,11 @@
public class DictUtils
{
/**
+ * 分隔符
+ */
+ public static final String SEPARATOR = ",";
+
+ /**
* 设置字典缓存
*
* @param key 参数键
@@ -36,8 +41,8 @@
Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
if (StringUtils.isNotNull(cacheObj))
{
- List<SysDictData> DictDatas = StringUtils.cast(cacheObj);
- return DictDatas;
+ List<SysDictData> dictDatas = StringUtils.cast(cacheObj);
+ return dictDatas;
}
return null;
}
@@ -51,21 +56,7 @@
*/
public static String getDictLabel(String dictType, String dictValue)
{
- if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotEmpty(dictValue))
- {
- List<SysDictData> datas = getDictCache(dictType);
- if (StringUtils.isNotEmpty(datas))
- {
- for (SysDictData dict : datas)
- {
- if (dictValue.equals(dict.getDictValue()))
- {
- return dict.getDictLabel();
- }
- }
- }
- }
- return dictValue;
+ return getDictLabel(dictType, dictValue, SEPARATOR);
}
/**
@@ -77,21 +68,97 @@
*/
public static String getDictValue(String dictType, String dictLabel)
{
- if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotEmpty(dictLabel))
+ return getDictValue(dictType, dictLabel, SEPARATOR);
+ }
+
+ /**
+ * 根据字典类型和字典值获取字典标签
+ *
+ * @param dictType 字典类型
+ * @param dictValue 字典值
+ * @param separator 分隔符
+ * @return 字典标签
+ */
+ public static String getDictLabel(String dictType, String dictValue, String separator)
+ {
+ StringBuilder propertyString = new StringBuilder();
+ List<SysDictData> datas = getDictCache(dictType);
+
+ if (StringUtils.containsAny(separator, dictValue) && StringUtils.isNotEmpty(datas))
{
- List<SysDictData> datas = getDictCache(dictType);
- if (StringUtils.isNotEmpty(datas))
+ for (SysDictData dict : datas)
{
- for (SysDictData dict : datas)
+ for (String value : dictValue.split(separator))
{
- if (dictLabel.equals(dict.getDictLabel()))
+ if (value.equals(dict.getDictValue()))
{
- return dict.getDictValue();
+ propertyString.append(dict.getDictLabel() + separator);
+ break;
}
}
}
}
- return dictLabel;
+ else
+ {
+ for (SysDictData dict : datas)
+ {
+ if (dictValue.equals(dict.getDictValue()))
+ {
+ return dict.getDictLabel();
+ }
+ }
+ }
+ return StringUtils.stripEnd(propertyString.toString(), separator);
+ }
+
+ /**
+ * 根据字典类型和字典标签获取字典值
+ *
+ * @param dictType 字典类型
+ * @param dictLabel 字典标签
+ * @param separator 分隔符
+ * @return 字典值
+ */
+ public static String getDictValue(String dictType, String dictLabel, String separator)
+ {
+ StringBuilder propertyString = new StringBuilder();
+ List<SysDictData> datas = getDictCache(dictType);
+
+ if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas))
+ {
+ for (SysDictData dict : datas)
+ {
+ for (String label : dictLabel.split(separator))
+ {
+ if (label.equals(dict.getDictLabel()))
+ {
+ propertyString.append(dict.getDictValue() + separator);
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ for (SysDictData dict : datas)
+ {
+ if (dictLabel.equals(dict.getDictLabel()))
+ {
+ return dict.getDictValue();
+ }
+ }
+ }
+ return StringUtils.stripEnd(propertyString.toString(), separator);
+ }
+
+ /**
+ * 删除指定字典缓存
+ *
+ * @param key 字典键
+ */
+ public static void removeDictCache(String key)
+ {
+ SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
}
/**
--
Gitblit v1.9.2