diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/impl/DeLianServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/impl/DeLianServiceImpl.java index 8b7d3ce..6b8b2ba 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/impl/DeLianServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/impl/DeLianServiceImpl.java @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; @@ -30,6 +31,9 @@ public class DeLianServiceImpl implements IDeLianService { private String hostId; @Value("${deLian.passWord}") private String passWord; + private final RedisTemplate redisTemplate; + + private final static String load_strategys_key = "hzims:equipment:delian:strategys:key"; @Override public List getStrategys() { @@ -37,29 +41,42 @@ public class DeLianServiceImpl implements IDeLianService { HashMap requestData = new HashMap() {{ put("Strategy_Type", 0); }}; - param.put("request_data",requestData); - param.put("request_cmd",DeLianConstants.STRATEGYS.getCode()); + param.put("request_data", requestData); + param.put("request_cmd", DeLianConstants.STRATEGYS.getCode()); String jsonString = JSON.toJSONString(param); HttpResponse response = HttpRequest.post(deLianUrl).body(jsonString).execute(); - if(response.getStatus() == HttpServletResponse.SC_OK ) { + if (response.getStatus() == HttpServletResponse.SC_OK) { List responseData = JSONObject.parseArray(JSONObject.parseObject(response.body()).getString("response_data"), StrategyDataVO.class); + redisTemplate.opsForValue().set(load_strategys_key, responseData); return responseData; } - return new ArrayList<>(); + return new ArrayList<>(); } @Override public R executeScene(String key) { + long start = System.currentTimeMillis(); + log.info("executeScene接口请求开始------"); HashMap param = getOauthToken(); - param.put("request_cmd",DeLianConstants.EXECUTESCENE.getCode()); - List strategys = getStrategys(); + param.put("request_cmd", DeLianConstants.EXECUTESCENE.getCode()); + List strategys = new ArrayList<>(); + if (redisTemplate.hasKey(load_strategys_key)) { + strategys = (List) redisTemplate.opsForValue().get(load_strategys_key); + } else { + strategys = getStrategys(); + } for (StrategyDataVO strategy : strategys) { - if (key.equals(strategy.getSn())){ - param.put("request_data",strategy.getSID()); + if (key.equals(strategy.getSn())) { + param.put("request_data", strategy.getSID()); } } + long start1 = System.currentTimeMillis(); + log.info("deLian策略查询耗时:{}", start1 - start); + log.info("deLian一键执行接口请求开始------"); HttpResponse response = HttpRequest.post(deLianUrl).body(JSON.toJSONString(param)).execute(); - if(response.getStatus() == HttpServletResponse.SC_OK ) { + if (response.getStatus() == HttpServletResponse.SC_OK) { + long end = System.currentTimeMillis(); + log.info("deLian一键执行接口耗时:{}", end - start1); return R.success("执行成功"); } return R.fail("执行成功"); @@ -78,15 +95,14 @@ public class DeLianServiceImpl implements IDeLianService { String jsonString = JSON.toJSONString(param); HttpResponse response = HttpRequest.post(deLianUrl).body(jsonString).execute(); String token = JSONObject.parseObject(response.body()).getString("request_token"); - if(response.getStatus() == HttpServletResponse.SC_OK && + if (response.getStatus() == HttpServletResponse.SC_OK && StringUtils.isNotBlank(token)) { param.remove("request_data"); param.remove("request_cmd"); - param.put("request_token",token); + param.put("request_token", token); return param; - }else { + } else { throw new ServiceException("获取权限失败,请稍后重试!"); } } - }