Parcourir la Source

站点工具类

duhongyu il y a 2 semaines
Parent
commit
8761f9f432

+ 3 - 30
smart-steward-common/src/main/java/com/smartSteward/common/config/serializer/FieldSerializer.java

@@ -10,6 +10,7 @@ import com.smartSteward.common.annotation.Station;
10 10
 import com.smartSteward.common.core.redis.RedisCache;
11 11
 import com.smartSteward.common.core.text.Convert;
12 12
 import com.smartSteward.common.utils.DictUtils;
13
+import com.smartSteward.common.utils.StationUtil;
13 14
 import com.smartSteward.common.utils.StringUtils;
14 15
 import com.smartSteward.common.utils.spring.SpringUtils;
15 16
 import org.slf4j.Logger;
@@ -40,8 +41,7 @@ public class FieldSerializer extends JsonSerializer<Object> {
40 41
 
41 42
     private final MinioUtil minioUtil = new MinioUtil();
42 43
 
43
-    // 使用线程安全的缓存
44
-    private final Map<String, String> stationCache = new ConcurrentHashMap<>();
44
+
45 45
     private final Map<String, String> dictCache = new ConcurrentHashMap<>();
46 46
 
47 47
     @Override
@@ -124,7 +124,7 @@ public class FieldSerializer extends JsonSerializer<Object> {
124 124
             return;
125 125
         }
126 126
 
127
-        String stationName = getStationNameSafely(valueStr);
127
+        String stationName = StationUtil.getStationNameSafely(valueStr);
128 128
         gen.writeStringField(STATION_NAME_FIELD, stationName);
129 129
     }
130 130
 
@@ -200,34 +200,7 @@ public class FieldSerializer extends JsonSerializer<Object> {
200 200
         });
201 201
     }
202 202
 
203
-    /**
204
-     * 获取站点名称
205
-     */
206
-    private String getStationNameSafely(String stationCode) {
207
-        if (stationCode == null || stationCode.isEmpty()) {
208
-            return EMPTY_STRING;
209
-        }
210
-
211
-        // 优先从缓存获取
212
-        if (!stationCache.isEmpty()) {
213
-            return stationCache.getOrDefault(stationCode, EMPTY_STRING);
214
-        }
215
-
216
-        // 缓存为空时从Redis加载
217
-        try {
218
-            RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
219
-            if (redisCache.hasKey(STATION_MAP_KEY)) {
220
-                Map<String, String> redisStationMap = redisCache.getCacheMap(STATION_MAP_KEY);
221
-                stationCache.putAll(redisStationMap);
222
-                return stationCache.getOrDefault(stationCode, EMPTY_STRING);
223
-            }
224
-        } catch (Exception e) {
225
-            logger.warn("Failed to get station name for code: {}", stationCode, e);
226
-            return ERROR_VALUE;
227
-        }
228 203
 
229
-        return EMPTY_STRING;
230
-    }
231 204
 
232 205
     /**
233 206
      * 解析字典值

+ 85 - 0
smart-steward-common/src/main/java/com/smartSteward/common/utils/StationUtil.java

@@ -0,0 +1,85 @@
1
+package com.smartSteward.common.utils;
2
+
3
+import com.smartSteward.common.core.redis.RedisCache;
4
+import com.smartSteward.common.utils.spring.SpringUtils;
5
+import lombok.extern.slf4j.Slf4j;
6
+
7
+import java.util.Arrays;
8
+import java.util.Map;
9
+import java.util.concurrent.ConcurrentHashMap;
10
+import java.util.stream.Collectors;
11
+
12
+/**
13
+ * 站点工具类
14
+ * @author smart_Steward
15
+ */
16
+@Slf4j
17
+public class StationUtil {
18
+    // 使用线程安全的缓存
19
+    private static final Map<String, String> STATION_CACHE = new ConcurrentHashMap<>();
20
+    private static final String EMPTY_STRING = "";
21
+    private static final String STATION_MAP_KEY = "stationMap";
22
+
23
+    private static final String DEFAULT_SEPARATOR = ",";
24
+    /**
25
+     * 获取单个站点名称
26
+     */
27
+    public static String getStationNameSafely(String stationCode) {
28
+        if (stationCode == null || stationCode.isEmpty()) {
29
+            return EMPTY_STRING;
30
+        }
31
+
32
+        // 优先从缓存获取
33
+        if (!STATION_CACHE.isEmpty()) {
34
+            return STATION_CACHE.getOrDefault(stationCode, EMPTY_STRING);
35
+        }
36
+
37
+        // 缓存为空时从Redis加载
38
+        try {
39
+            RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
40
+            if (redisCache.hasKey(STATION_MAP_KEY)) {
41
+                Map<String, String> redisStationMap = redisCache.getCacheMap(STATION_MAP_KEY);
42
+                STATION_CACHE.putAll(redisStationMap);
43
+                return STATION_CACHE.getOrDefault(stationCode, EMPTY_STRING);
44
+            }
45
+        } catch (Exception e) {
46
+            log.warn("Failed to load station map from Redis for code: {}", stationCode, e);
47
+            return EMPTY_STRING;
48
+        }
49
+
50
+        return EMPTY_STRING;
51
+    }
52
+
53
+    /**
54
+     * 获取多个站点名称,中间逗号分割
55
+     */
56
+    public static String getStationNamesSafely(String stationCodes) {
57
+        if (stationCodes == null || stationCodes.isEmpty()) {
58
+            return EMPTY_STRING;
59
+        }
60
+
61
+        // 优先从缓存获取
62
+        if (!STATION_CACHE.isEmpty()) {
63
+            return Arrays.stream(stationCodes.split(DEFAULT_SEPARATOR))
64
+                    .map(code -> STATION_CACHE.getOrDefault(code, EMPTY_STRING))
65
+                    .collect(Collectors.joining(DEFAULT_SEPARATOR));
66
+        }
67
+
68
+        // 缓存为空时从 Redis 加载
69
+        try {
70
+            RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
71
+            if (redisCache.hasKey(STATION_MAP_KEY)) {
72
+                Map<String, String> redisStationMap = redisCache.getCacheMap(STATION_MAP_KEY);
73
+                STATION_CACHE.putAll(redisStationMap);
74
+                return Arrays.stream(stationCodes.split(DEFAULT_SEPARATOR))
75
+                        .map(code -> STATION_CACHE.getOrDefault(code, EMPTY_STRING))
76
+                        .collect(Collectors.joining(DEFAULT_SEPARATOR));
77
+            }
78
+        } catch (Exception e) {
79
+            log.warn("Failed to load station map from Redis for codes: {}", stationCodes, e);
80
+            return EMPTY_STRING;
81
+        }
82
+
83
+        return EMPTY_STRING;
84
+    }
85
+}

+ 5 - 1
smart-steward-entity/src/main/java/com/smartSteward/entity/database/schedule/ScheduleShiftManagement.java

@@ -73,11 +73,15 @@ public class ScheduleShiftManagement extends BaseEntity
73 73
    private String isCommon;
74 74
 
75 75
    /** 适用油站(存储油站ID,逗号分隔) */
76
-   @Excel(name = "适用油站(存储油站ID,逗号分隔)")
77 76
    @ApiModelProperty("适用油站(存储油站ID,逗号分隔)")
78 77
    private String applicableStations;
79 78
 
80 79
    /** 逻辑删除标识 */
81 80
    @ApiModelProperty("逻辑删除标识")
82 81
    private Long delFlag;
82
+
83
+   /** 适用油站(存储油站ID,逗号分隔) */
84
+   @Excel(name = "适用油站(存储油站ID,逗号分隔)")
85
+   @ApiModelProperty("适用油站(存储油站ID,逗号分隔)")
86
+   private String applicableStationsName;
83 87
 }

+ 2 - 0
smart-steward-mapper/src/main/resources/mapper/schedule/ScheduleDutyMapper.xml

@@ -25,6 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
25 25
         <where>
26 26
             <if test="stationId != null "> and station_id = #{stationId}</if>
27 27
             <if test="dutyPosition != null "> and duty_position = #{dutyPosition}</if>
28
+            <if test="startTime != null and startTime != ''"> and duty_date >= #{startTime}</if>
29
+            <if test="endTime != null and endTime != ''"> and duty_date <![CDATA[<=]]> #{endTime}</if>
28 30
             <!-- 如果有station_id字段,则增加站点集合查询条件 -->
29 31
             <if test="stationCollection != null and stationCollection.size() > 0">
30 32
                 and station_id in

+ 20 - 2
smart-steward-service/src/main/java/com/smartSteward/service/schedule/impl/ScheduleShiftManagementServiceImpl.java

@@ -3,6 +3,8 @@ import java.util.Date;
3 3
 import java.util.List;
4 4
 import com.smartSteward.common.core.SecurityUtils;
5 5
 import com.smartSteward.common.utils.DateUtils;
6
+import com.smartSteward.common.utils.StationUtil;
7
+import com.smartSteward.common.utils.StringUtils;
6 8
 import org.springframework.beans.factory.annotation.Autowired;
7 9
 import org.springframework.stereotype.Service;
8 10
 import com.smartSteward.mapper.schedule.ScheduleShiftManagementMapper;
@@ -29,7 +31,14 @@ public class ScheduleShiftManagementServiceImpl implements IScheduleShiftManagem
29 31
     @Override
30 32
     public ScheduleShiftManagement selectScheduleShiftManagementById(Long id)
31 33
     {
32
-        return scheduleShiftManagementMapper.selectScheduleShiftManagementById(id);
34
+        ScheduleShiftManagement scheduleShiftManagement = scheduleShiftManagementMapper.selectScheduleShiftManagementById(id);
35
+        if (scheduleShiftManagement != null) {
36
+            if(StringUtils.isNotEmpty(scheduleShiftManagement.getApplicableStations()))
37
+            {
38
+                scheduleShiftManagement.setApplicableStationsName(StationUtil.getStationNamesSafely(scheduleShiftManagement.getApplicableStations()));
39
+            }
40
+        }
41
+        return scheduleShiftManagement;
33 42
     }
34 43
 
35 44
     /**
@@ -41,7 +50,16 @@ public class ScheduleShiftManagementServiceImpl implements IScheduleShiftManagem
41 50
     @Override
42 51
     public List<ScheduleShiftManagement> selectScheduleShiftManagementList(ScheduleShiftManagement scheduleShiftManagement)
43 52
     {
44
-        return scheduleShiftManagementMapper.selectScheduleShiftManagementList(scheduleShiftManagement);
53
+        List<ScheduleShiftManagement> scheduleShiftManagementList = scheduleShiftManagementMapper.selectScheduleShiftManagementList(scheduleShiftManagement);
54
+        if (scheduleShiftManagementList != null) {
55
+            for (ScheduleShiftManagement item : scheduleShiftManagementList) {
56
+                if(StringUtils.isNotEmpty(item.getApplicableStations()))
57
+                {
58
+                  item.setApplicableStationsName(StationUtil.getStationNamesSafely(item.getApplicableStations()));
59
+                }
60
+            }
61
+        }
62
+        return scheduleShiftManagementList;
45 63
     }
46 64
 
47 65
     /**

+ 4 - 1
smart-steward-service/src/main/java/com/smartSteward/service/system/impl/SysDictTypeServiceImpl.java

@@ -1,10 +1,13 @@
1 1
 package com.smartSteward.service.system.impl;
2 2
 
3
+import java.text.ParseException;
3 4
 import java.util.Comparator;
4 5
 import java.util.List;
5 6
 import java.util.Map;
6 7
 import java.util.stream.Collectors;
7 8
 import javax.annotation.PostConstruct;
9
+
10
+import com.smartSteward.common.exception.ParameterException;
8 11
 import org.springframework.beans.factory.annotation.Autowired;
9 12
 import org.springframework.stereotype.Service;
10 13
 import org.springframework.transaction.annotation.Transactional;
@@ -124,7 +127,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
124 127
             SysDictType dictType = selectDictTypeById(dictId);
125 128
             if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0)
126 129
             {
127
-                throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
130
+                throw new ParameterException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
128 131
             }
129 132
             dictTypeMapper.deleteDictTypeById(dictId);
130 133
             DictUtils.removeDictCache(dictType.getDictType());