|
@@ -1,7 +1,14 @@
|
|
|
package com.xy.utils;
|
|
|
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.xy.entity.SysCodeConfigureRedis;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -53,4 +60,133 @@ public class SysCodeConfigureUtils {
|
|
|
public static Map<String, SysCodeConfigureRedis> all() {
|
|
|
return getRedisService().getMap(SYS_CODE_CONFIGURE_PREFIX);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据父代码获取其子类(排除自身)
|
|
|
+ *
|
|
|
+ * @param parentCode 父代码
|
|
|
+ * @return {@link Map}<{@link String}, {@link SysCodeConfigureRedis}>
|
|
|
+ */
|
|
|
+ public static Map<String, SysCodeConfigureRedis> getChildrenByParentCode(String parentCode) {
|
|
|
+ Map<String, SysCodeConfigureRedis> all = all();
|
|
|
+ Map<String, SysCodeConfigureRedis> childrenMap = MapUtil.newHashMap();
|
|
|
+ all.forEach((k, v) -> {
|
|
|
+ if (!k.equals(parentCode) && k.contains(parentCode)) {
|
|
|
+ childrenMap.put(k, v);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return childrenMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取扩展参数
|
|
|
+ *
|
|
|
+ * @param expand 扩大
|
|
|
+ * @return {@link JSONObject}
|
|
|
+ */
|
|
|
+ public static JSONObject getExpand(String expand) {
|
|
|
+ return JSONUtil.parseObj(expand);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否展示给商户
|
|
|
+ *
|
|
|
+ * @param expand
|
|
|
+ * @return {@link Boolean}
|
|
|
+ */
|
|
|
+ public static Boolean getExpShow2Merc(String expand) {
|
|
|
+ JSONObject exp = getExpand(expand);
|
|
|
+ return exp.getBool("show2merc");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否推送给商户
|
|
|
+ *
|
|
|
+ * @param expand
|
|
|
+ * @return {@link Boolean}
|
|
|
+ */
|
|
|
+ public static Boolean getExpPush2Merc(String expand) {
|
|
|
+ JSONObject exp = getExpand(expand);
|
|
|
+ return exp.getBool("push2merc");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否可取消订阅
|
|
|
+ *
|
|
|
+ * @param expand
|
|
|
+ * @return {@link Boolean}
|
|
|
+ */
|
|
|
+ public static Boolean getExpCanUnSubscribe(String expand) {
|
|
|
+ JSONObject exp = getExpand(expand);
|
|
|
+ return exp.getBool("canUnsubscribe");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到标记
|
|
|
+ *
|
|
|
+ * @param expand
|
|
|
+ * @return {@link String}
|
|
|
+ */
|
|
|
+ public static String getMarker(String expand) {
|
|
|
+ JSONObject exp = getExpand(expand);
|
|
|
+ return exp.getStr("marker");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取是否可推送
|
|
|
+ *
|
|
|
+ * @param expand 扩大
|
|
|
+ * @return {@link Boolean}
|
|
|
+ */
|
|
|
+ public static Boolean getExpCanPush(String expand) {
|
|
|
+ JSONObject exp = getExpand(expand);
|
|
|
+ //禁止推送时间段,只针对公众号消息,短信等 (为了免打扰!)
|
|
|
+ String unPushTime = exp.getStr("unpushtime");
|
|
|
+ if (StrUtil.isEmpty(unPushTime)) {
|
|
|
+ //没有配置。默认可推送
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ //有配置按配置来,获取配置 如: "23:00-24:00,00:00-06:00"
|
|
|
+ String[] timeArray = unPushTime.split(StrUtil.COMMA);
|
|
|
+ if (timeArray.length == 1) {
|
|
|
+ //1个时间段
|
|
|
+ String timeStr = timeArray[0];
|
|
|
+ if (!timeCheck(timeStr)) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (timeArray.length == 2) {
|
|
|
+ //2个时间段
|
|
|
+ String timeStr = timeArray[0];
|
|
|
+ // 判断当前时间是否在时间范围内
|
|
|
+ if (!timeCheck(timeStr)) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+ String timeStr2 = timeArray[1];
|
|
|
+ if (!timeCheck(timeStr2)) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 时间检查
|
|
|
+ *
|
|
|
+ * @param timeStr
|
|
|
+ * @return {@link Boolean}
|
|
|
+ */
|
|
|
+ public static Boolean timeCheck(String timeStr) {
|
|
|
+ String monthDate = DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN) + " ";
|
|
|
+ String startTime = monthDate + timeStr.split(StrUtil.DASHED)[0] + ":00";
|
|
|
+ String endTime = monthDate + timeStr.split(StrUtil.DASHED)[1] + ":00";
|
|
|
+ // 判断当前时间是否在时间范围内
|
|
|
+ if (DateUtil.isIn(DateUtil.date(), DateUtil.parseDateTime(startTime), DateUtil.parseDateTime(endTime))) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|