修改监控设备获取token
This commit is contained in:
parent
720ff83ee5
commit
761a216aee
@ -220,27 +220,4 @@ public class XhpcChargingStationController extends BaseController {
|
|||||||
return xhpcChargingStationService.updateXhpcRateTime(request, xhpcChargingStationDto);
|
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<String, Object> map = new HashMap<>();
|
|
||||||
map.put("accessToken","at.35peeqba81hltpja2c32fw8e9fhxwjes-7p2r9zyvtp-1016urx-bkfywfr2z");
|
|
||||||
return AjaxResult.success(map);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.controller.BaseController;
|
||||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||||
import com.xhpc.common.core.web.page.TableDataInfo;
|
import com.xhpc.common.core.web.page.TableDataInfo;
|
||||||
import com.xhpc.common.domain.XhpcChargingPile;
|
|
||||||
import com.xhpc.common.domain.XhpcEquipmenMonitor;
|
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 org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -67,4 +65,26 @@ public class XhpcEquipmenMonitorController extends BaseController {
|
|||||||
return xhpcEquipmenMonitorService.remove(equipmenMonitorId);
|
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<String, Object> map = new HashMap<>();
|
||||||
|
//map.put("accessToken","at.35peeqba81hltpja2c32fw8e9fhxwjes-7p2r9zyvtp-1016urx-bkfywfr2z");
|
||||||
|
return xhpcEquipmenMonitorService.getChargingStationEquipmenToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -253,5 +253,5 @@ public interface IXhpcChargingStationService {
|
|||||||
|
|
||||||
Map<String,Object> activityDiscountTime(Long userId, Date startTime, Integer source, Long chargingStationId, String tenantId);
|
Map<String,Object> activityDiscountTime(Long userId, Date startTime, Integer source, Long chargingStationId, String tenantId);
|
||||||
|
|
||||||
AjaxResult getChargingStationMonitor(String chargingStationId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,10 @@ public interface IXhpcEquipmenMonitorService {
|
|||||||
AjaxResult addEquipmenMonitor(XhpcEquipmenMonitor xhpcEquipmenMonitor);
|
AjaxResult addEquipmenMonitor(XhpcEquipmenMonitor xhpcEquipmenMonitor);
|
||||||
|
|
||||||
AjaxResult remove(Long equipmenMonitorId);
|
AjaxResult remove(Long equipmenMonitorId);
|
||||||
|
|
||||||
|
AjaxResult getChargingStationMonitor(String chargingStationId);
|
||||||
|
|
||||||
|
AjaxResult getChargingStationEquipmenToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1547,65 +1547,6 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public AjaxResult getChargingStationMonitor(String chargingStationId) {
|
|
||||||
List<Map<String, Object>> list =new ArrayList<>();
|
|
||||||
|
|
||||||
// try{
|
|
||||||
// String[] split = chargingStationId.split(",");
|
|
||||||
// //获取token
|
|
||||||
// String equipmenToken = redisService.getCacheObject("equipmen:token");
|
|
||||||
// Map<String, String> 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 <split.length ; i++) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }catch (Exception e){
|
|
||||||
//
|
|
||||||
// return AjaxResult.error("场站id错误");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,27 @@
|
|||||||
package com.xhpc.charging.station.service;
|
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.mapper.XhpcEquipmenMonitorMapper;
|
||||||
|
import com.xhpc.charging.station.utils.img.HttpClientUtil;
|
||||||
import com.xhpc.common.core.utils.SecurityUtils;
|
import com.xhpc.common.core.utils.SecurityUtils;
|
||||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||||
import com.xhpc.common.domain.XhpcEquipmenMonitor;
|
import com.xhpc.common.domain.XhpcEquipmenMonitor;
|
||||||
|
import com.xhpc.common.redis.service.RedisService;
|
||||||
import com.xhpc.common.security.service.TokenService;
|
import com.xhpc.common.security.service.TokenService;
|
||||||
import com.xhpc.common.util.UserTypeUtil;
|
import com.xhpc.common.util.UserTypeUtil;
|
||||||
import com.xhpc.system.api.domain.SysUser;
|
import com.xhpc.system.api.domain.SysUser;
|
||||||
import com.xhpc.system.api.model.LoginUser;
|
import com.xhpc.system.api.model.LoginUser;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yuyang
|
* @author yuyang
|
||||||
@ -27,6 +34,8 @@ public class XhpcEquipmenMonitorServiceImpl implements IXhpcEquipmenMonitorServi
|
|||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
@Resource
|
@Resource
|
||||||
private XhpcEquipmenMonitorMapper xhpcEquipmenMonitorMapper;
|
private XhpcEquipmenMonitorMapper xhpcEquipmenMonitorMapper;
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> list(HttpServletRequest request, String equipmenName, String equipmenNumber, Long chargingStationId) {
|
public List<Map<String, Object>> list(HttpServletRequest request, String equipmenName, String equipmenNumber, Long chargingStationId) {
|
||||||
@ -90,4 +99,86 @@ public class XhpcEquipmenMonitorServiceImpl implements IXhpcEquipmenMonitorServi
|
|||||||
}
|
}
|
||||||
return AjaxResult.error();
|
return AjaxResult.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult getChargingStationMonitor(String chargingStationId) {
|
||||||
|
List<Map<String, Object>> list =new ArrayList<>();
|
||||||
|
Map<String, Object> 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<String, Object> 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<String, String> 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<String, String> 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();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user