From 1fbcc2ecf1c296e295467bc2f0dfeecdfbcbfb9d Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Mon, 26 Aug 2024 20:20:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E5=A4=A7=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=BE=B7=E4=BA=91=E7=89=A9=E8=81=94=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=AD=96=E7=95=A5=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../delian/service/impl/DeLianServiceImpl.java | 42 +++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) 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("获取权限失败,请稍后重试!"); } } - }