CacheServiceImpl.java
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.huaheng.control.management.service.impl;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import com.alibaba.fastjson.TypeReference;
import com.huaheng.control.management.dto.Zone;
import com.huaheng.control.management.service.CacheService;
import com.huaheng.control.management.utils.OkHttpUtils;
import com.huaheng.control.management.utils.config.ApplicationConfig;
import com.huaheng.control.management.vo.Result;
@Service
public class CacheServiceImpl implements CacheService {
@Resource
private ApplicationConfig applicationConfig;
@Override
@Cacheable(cacheNames = "getZoneMap#60", key = "#root.methodName", unless = "#result == null")
public Map<String, Zone> getZoneMap() {
Map<String, Zone> zoneMap = new LinkedHashMap<String, Zone>();
String url = applicationConfig.getWms_url() + "/api/cmc/getZones";
Map<String, String> headers = new LinkedHashMap<>();
headers.put("token", applicationConfig.getWms_token());
Result<List<Zone>> result = OkHttpUtils.sendPostByJsonStr(url, headers, "{}", new TypeReference<Result<List<Zone>>>() {});
if (result == null || !result.getCode().equals(200) || CollectionUtils.isEmpty(result.getResult())) {
return null;
}
for (Zone zone : result.getResult()) {
zoneMap.put(zone.getCode(), zone);
}
return zoneMap;
}
}