diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java index b418f4bd..c239a759 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java @@ -220,27 +220,4 @@ public class XhpcChargingStationController extends BaseController { return xhpcChargingStationService.updateXhpcRateTime(request, xhpcChargingStationDto); } - - /** - * 场站监控列表 - * - * @param chargingStationId - * @return - */ - @GetMapping(value = "/getChargingStationMonitor") - public AjaxResult getChargingStationMonitor(String chargingStationId) { - - return xhpcChargingStationService.getChargingStationMonitor(chargingStationId); - } - /** - * 场站监控Token - * - * @return - */ - @GetMapping(value = "/getChargingStationEquipmenToken") - public AjaxResult getChargingStationEquipmenToken() { - Map map = new HashMap<>(); - map.put("accessToken","at.35peeqba81hltpja2c32fw8e9fhxwjes-7p2r9zyvtp-1016urx-bkfywfr2z"); - return AjaxResult.success(map); - } } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcEquipmenMonitorController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcEquipmenMonitorController.java index eb9020f8..1a3a8e73 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcEquipmenMonitorController.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcEquipmenMonitorController.java @@ -4,14 +4,12 @@ import com.xhpc.charging.station.service.IXhpcEquipmenMonitorService; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.page.TableDataInfo; -import com.xhpc.common.domain.XhpcChargingPile; import com.xhpc.common.domain.XhpcEquipmenMonitor; -import com.xhpc.common.log.annotation.Log; -import com.xhpc.common.log.enums.BusinessType; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -67,4 +65,26 @@ public class XhpcEquipmenMonitorController extends BaseController { return xhpcEquipmenMonitorService.remove(equipmenMonitorId); } + /** + * 场站监控列表 + * + * @param chargingStationId + * @return + */ + @GetMapping(value = "/getChargingStationMonitor") + public AjaxResult getChargingStationMonitor(String chargingStationId) { + + return xhpcEquipmenMonitorService.getChargingStationMonitor(chargingStationId); + } + /** + * 场站监控Token + * + * @return + */ + @GetMapping(value = "/getChargingStationEquipmenToken") + public AjaxResult getChargingStationEquipmenToken() { + //Map map = new HashMap<>(); + //map.put("accessToken","at.35peeqba81hltpja2c32fw8e9fhxwjes-7p2r9zyvtp-1016urx-bkfywfr2z"); + return xhpcEquipmenMonitorService.getChargingStationEquipmenToken(); + } } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java index 8d7b36e6..fac5b916 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java @@ -253,5 +253,5 @@ public interface IXhpcChargingStationService { Map activityDiscountTime(Long userId, Date startTime, Integer source, Long chargingStationId, String tenantId); - AjaxResult getChargingStationMonitor(String chargingStationId); + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcEquipmenMonitorService.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcEquipmenMonitorService.java index 659a6559..79d62a39 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcEquipmenMonitorService.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcEquipmenMonitorService.java @@ -23,6 +23,10 @@ public interface IXhpcEquipmenMonitorService { AjaxResult addEquipmenMonitor(XhpcEquipmenMonitor xhpcEquipmenMonitor); AjaxResult remove(Long equipmenMonitorId); + + AjaxResult getChargingStationMonitor(String chargingStationId); + + AjaxResult getChargingStationEquipmenToken(); } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java index b00bc6e9..37e37095 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java @@ -1547,65 +1547,6 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc return map; } - @Override - public AjaxResult getChargingStationMonitor(String chargingStationId) { - List> list =new ArrayList<>(); -// try{ -// String[] split = chargingStationId.split(","); -// //获取token -// String equipmenToken = redisService.getCacheObject("equipmen:token"); -// Map rm = new HashMap<>(); -// rm.put("appKey", "e87d64ac7c424d7bb37830055a21b57a"); -// rm.put("appSecret", "85d3ea44e86f940ac8274b43f6703803"); -// -// if(equipmenToken ==null || "".equals(equipmenToken)){ -// String resp = Utilitys.doPost("https://open.ys7.com/api/lapp/token/get", null, null, rm); -// JSONObject jsonObject = JSON.parseObject(resp); -// System.out.println("==========jsonObject============"); -// System.out.println("==========jsonObject============"+jsonObject.toString()); -// System.out.println("==========jsonObject============"); -// JSONObject data = jsonObject.getJSONObject("data"); -// String accessToken = data.getString("accessToken"); -// //String expireTime = data.getString("expireTime"); -// redisService.setCacheObject("equipmen:token",accessToken,259200L, TimeUnit.SECONDS); -// } -// if(chargingStationId ==null || chargingStationId.length()==0 || "".equals(chargingStationId)){ -// //所有场站 -// }else{ -// for (int i = 0; i map = new HashMap<>(); - map.put("chargingStationId",1); - map.put("equipmentNumber","C41675932"); - map.put("equipmentName","公司内部监控"); - map.put("url","ezopen://open.ys7.com/C41675932/1.hd.live"); - list.add(map); - - return AjaxResult.success(list); - } - - - public static void main(String[] args) { - String st="14:30:00"; - String end="15:30:00"; - - long sttime = DateUtil.parse(st, "HH:mm:ss").getTime(); - long endtime = DateUtil.parse(end, "HH:mm:ss").getTime(); - - System.out.println((endtime-sttime)/1800000); - - } } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcEquipmenMonitorServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcEquipmenMonitorServiceImpl.java index f5db3e65..d917cfae 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcEquipmenMonitorServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcEquipmenMonitorServiceImpl.java @@ -1,20 +1,27 @@ package com.xhpc.charging.station.service; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.xhpc.charging.station.mapper.XhpcEquipmenMonitorMapper; +import com.xhpc.charging.station.utils.img.HttpClientUtil; import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.domain.XhpcEquipmenMonitor; +import com.xhpc.common.redis.service.RedisService; import com.xhpc.common.security.service.TokenService; import com.xhpc.common.util.UserTypeUtil; import com.xhpc.system.api.domain.SysUser; import com.xhpc.system.api.model.LoginUser; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * @author yuyang @@ -27,6 +34,8 @@ public class XhpcEquipmenMonitorServiceImpl implements IXhpcEquipmenMonitorServi private TokenService tokenService; @Resource private XhpcEquipmenMonitorMapper xhpcEquipmenMonitorMapper; + @Autowired + private RedisService redisService; @Override public List> list(HttpServletRequest request, String equipmenName, String equipmenNumber, Long chargingStationId) { @@ -90,4 +99,86 @@ public class XhpcEquipmenMonitorServiceImpl implements IXhpcEquipmenMonitorServi } return AjaxResult.error(); } + + @Override + public AjaxResult getChargingStationMonitor(String chargingStationId) { + List> list =new ArrayList<>(); + Map map = new HashMap<>(); + map.put("chargingStationId",1); + map.put("equipmentNumber","C41675932"); + map.put("equipmentName","公司内部监控"); + map.put("url","ezopen://open.ys7.com/C41675932/1.hd.live"); + list.add(map); + return AjaxResult.success(list); + } + + @Override + public AjaxResult getChargingStationEquipmenToken() { + + try{ + //获取token + String equipmenToken = redisService.getCacheObject("equipmen:token"); + Map map = new HashMap<>(); + if(equipmenToken ==null || "".equals(equipmenToken)){ + String resp = HttpClientUtil.sendPost("https://open.ys7.com/api/lapp/token/get?appKey=e87d64ac7c424d7bb37830055a21b57a&appSecret=85d3ea44e86f940ac8274b43f6703803", null); + JSONObject jsonObject = JSON.parseObject(resp); + JSONObject data = jsonObject.getJSONObject("data"); + String accessToken = data.getString("accessToken"); + map.put("accessToken",accessToken); + redisService.setCacheObject("equipmen:token",accessToken,259200L, TimeUnit.SECONDS); + }else{ + map.put("accessToken",equipmenToken); + } + return AjaxResult.success(map); + }catch (Exception e){ + + return AjaxResult.error("获取监控token失败,请联系管理员"); + } + } + + public static void main(String[] args) { +//// String st="14:30:00"; +//// String end="15:30:00"; +//// +//// long sttime = DateUtil.parse(st, "HH:mm:ss").getTime(); +//// long endtime = DateUtil.parse(end, "HH:mm:ss").getTime(); +//// +//// System.out.println((endtime-sttime)/1800000); +// try{ +// +// //获取token +//// HashMap headers = new HashMap<>(3); +//// String requestUrl = "https://open.ys7.com/api/lapp/token/get"; +//// String jsonStr = "{\n" + +//// " \"appKey\":\"e87d64ac7c424d7bb37830055a21b57a\",\n" + +//// " \"appSecret\":\"85d3ea44e86f940ac8274b43f6703803\"\n" + +//// "}"; +//// headers.put("content-type", "application/json"); +//// // 发送post请求 +//// String resultData = HttpUtils.sendPostWithJson(requestUrl, jsonStr,headers); +//// // 并接收返回结果 +//// System.out.println(resultData); +// Map rm = new HashMap<>(); +// // rm.put("appKey", "e87d64ac7c424d7bb37830055a21b57a"); +// // rm.put("appSecret", "85d3ea44e86f940ac8274b43f6703803"); +// +// +// String resp = HttpClientUtil.sendPost("https://open.ys7.com/api/lapp/token/get?appKey=e87d64ac7c424d7bb37830055a21b57a&appSecret=85d3ea44e86f940ac8274b43f6703803", null); +// +// JSONObject jsonObject = JSON.parseObject(resp); +// System.out.println("==========jsonObject============"); +// System.out.println("==========jsonObject============"+jsonObject.toString()); +// System.out.println("==========jsonObject============"); +// JSONObject data = jsonObject.getJSONObject("data"); +// String accessToken = data.getString("accessToken"); +// System.out.println("accessToken:"+accessToken); +// String expireTime = data.getString("expireTime"); +// +// +// }catch (Exception e){ +// +// e.printStackTrace(); +// } + } + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/HttpClientUtil.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/HttpClientUtil.java new file mode 100644 index 00000000..1ef69c10 --- /dev/null +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/HttpClientUtil.java @@ -0,0 +1,63 @@ +package com.xhpc.charging.station.utils.img; + +import java.io.*; +import java.net.URL; +import java.net.URLConnection; + +public class HttpClientUtil { + + public static String sendPost(String url, String param) { + PrintWriter out = null; + BufferedReader in = null; + String result = ""; + try { + URL realUrl = new URL(url); + // 打开和URL之间的连接 + URLConnection conn = realUrl.openConnection(); + // 设置通用的请求属性 + conn.setRequestProperty("accept", "*/*"); + conn.setRequestProperty("connection", "Keep-Alive"); + conn.setRequestProperty("user-agent", + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + + conn.setRequestProperty("Accept-Charset", "UTF-8"); + conn.setRequestProperty("contentType", "UTF-8"); + + // 发送POST请求必须设置如下两行 + conn.setDoOutput(true); + conn.setDoInput(true); + // 获取URLConnection对象对应的输出流 + out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8")); + // 发送请求参数 + out.print(param); + // flush输出流的缓冲 + out.flush(); + // 定义BufferedReader输入流来读取URL的响应 + in = new BufferedReader( + new InputStreamReader(conn.getInputStream(),"UTF-8")); + String line; + while ((line = in.readLine()) != null) { + result += line; + } + } catch (Exception e) { + System.out.println("发送 POST 请求出现异常!"+e); + e.printStackTrace(); + } + //使用finally块来关闭输出流、输入流 + finally{ + try{ + if(out!=null){ + out.close(); + } + if(in!=null){ + in.close(); + } + } + catch(IOException ex){ + ex.printStackTrace(); + } + } + return result; + } + +}