Merge remote-tracking branch 'origin/master'

This commit is contained in:
yitonglei 2022-05-17 17:06:12 +08:00
commit 256e989288
5 changed files with 196 additions and 106 deletions

View File

@ -5,6 +5,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
@Configuration @Configuration
public class RestClient { public class RestClient {
@ -16,9 +20,9 @@ public class RestClient {
requestFactory.setReadTimeout(30000); requestFactory.setReadTimeout(30000);
requestFactory.setOutputStreaming(false); requestFactory.setOutputStreaming(false);
// SocketAddress address = new InetSocketAddress("127.0.0.1", 8888); /*SocketAddress address = new InetSocketAddress("15.2.23.141", 8888);
// Proxy proxy = new Proxy(Proxy.Type.HTTP, address); Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
// requestFactory.setProxy(proxy); requestFactory.setProxy(proxy);*/
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(requestFactory); restTemplate.setRequestFactory(requestFactory);

View File

@ -122,11 +122,10 @@ public class Controller {
* @param * @param
* @return * @return
*/ */
@RequestMapping("selectAll") @GetMapping("selectAll")
@ApiOperation("查询所有摄像头")
public String selectAll(){ public String selectAll(){
return cameraChannelService.selectAll(); return cameraChannelService.selectAll();
} }
/** /**
@ -134,7 +133,9 @@ public class Controller {
* @param channelCode * @param channelCode
* @return * @return
*/ */
@RequestMapping("selectByChannelCode") @GetMapping("selectByChannelCode")
@ApiOperation("根据channelCode查询摄像头详细信息")
@ApiImplicitParam(name = "channelCode",value = "摄像头标识",required = true,dataType = "String")
public Result selectByChannelCode(String channelCode){ public Result selectByChannelCode(String channelCode){
List<CameraChannelDto1> list = cameraChannelMapper.selectByChannelCode(channelCode); List<CameraChannelDto1> list = cameraChannelMapper.selectByChannelCode(channelCode);
@ -151,7 +152,9 @@ public class Controller {
* @param channelName * @param channelName
* @return * @return
*/ */
@RequestMapping("selectByChannelName") @GetMapping("selectByChannelName")
@ApiOperation("根据摄像头名字模糊查询摄像头")
@ApiImplicitParam(name = "channelName",value = "摄像头名称",required = true,dataType = "String")
public Result selectByChannelName(String channelName){ public Result selectByChannelName(String channelName){
List<CameraChannel> labels = cameraChannelMapper.selectByChannelName(channelName); List<CameraChannel> labels = cameraChannelMapper.selectByChannelName(channelName);
@ -162,11 +165,16 @@ public class Controller {
} }
/** /**
* 根据parentId查询摄像头 * 根据parentId和checkStatus查询摄像头
* @param parentId * @param parentId
* @return * @return
*/ */
@RequestMapping("selectByParentId") @GetMapping("selectByParentId")
@ApiOperation("根据parentId和checkStatus查询摄像头")
@ApiImplicitParams({
@ApiImplicitParam(name = "parentId",value = "摄像头的组织Id",required = true,dataType = "String"),
@ApiImplicitParam(name = "checkStatus",value = "异常状态 1正常,0异常",required = true,dataType = "String")
})
public Result selectByParentId(String parentId,String checkStatus){ public Result selectByParentId(String parentId,String checkStatus){
List<CameraChannel> list = cameraChannelMapper.selectByParentId(parentId,checkStatus); List<CameraChannel> list = cameraChannelMapper.selectByParentId(parentId,checkStatus);
@ -181,7 +189,9 @@ public class Controller {
* 根据标签查询对应摄像头 * 根据标签查询对应摄像头
* @return * @return
*/ */
@RequestMapping("selectLabel") @GetMapping("selectLabel")
@ApiOperation("根据标签查询对应摄像头")
@ApiImplicitParam(name = "labelCode",value = "标签号",required = true,dataType = "String")
public Result selectLabel(String labelCode){ public Result selectLabel(String labelCode){
List<ChannelLabelDto> channelLabelDtos = cameraChannelMapper.selectLabel(labelCode); List<ChannelLabelDto> channelLabelDtos = cameraChannelMapper.selectLabel(labelCode);
@ -205,7 +215,7 @@ public class Controller {
* @param gpsY1 * @param gpsY1
* @return * @return
*/ */
@RequestMapping("selectAllByGps") @GetMapping ("selectAllByGps")
public Result selectAllByGps(String gpsX,String gpsX1,String gpsY,String gpsY1){ public Result selectAllByGps(String gpsX,String gpsX1,String gpsY,String gpsY1){
List<CameraChannelDto> gps = cameraChannelMapper.selectAllByGps(gpsX, gpsX1, gpsY, gpsY1); List<CameraChannelDto> gps = cameraChannelMapper.selectAllByGps(gpsX, gpsX1, gpsY, gpsY1);
@ -224,7 +234,8 @@ public class Controller {
* @param label * @param label
* @return * @return
*/ */
@RequestMapping("selectAllLabel") @GetMapping("selectAllLabel")
@ApiOperation("查询所有标签")
public Result selectAllLabel(Label label ){ public Result selectAllLabel(Label label ){
List<Label> labels = cameraChannelMapper.selectAllLabel(label); List<Label> labels = cameraChannelMapper.selectAllLabel(label);
@ -238,7 +249,7 @@ public class Controller {
* @param labelName * @param labelName
* @return * @return
*/ */
@RequestMapping("selectByLabelName") @GetMapping("selectByLabelName")
public Result selectByLabelName(String labelName){ public Result selectByLabelName(String labelName){
List<Label> labels = cameraChannelMapper.selectByLabelName(labelName); List<Label> labels = cameraChannelMapper.selectByLabelName(labelName);
@ -253,7 +264,9 @@ public class Controller {
* @param parentId * @param parentId
* @return * @return
*/ */
@RequestMapping("selectSubOrgan") @GetMapping("selectSubOrgan")
@ApiOperation("根据parentId查询组织")
@ApiImplicitParam(name = "parentId",value = "上级组织id",required = true,dataType = "String")
public Result selectSubOrganization(String parentId){ public Result selectSubOrganization(String parentId){
if (parentId == null){ if (parentId == null){
parentId = ""; parentId = "";
@ -266,26 +279,6 @@ public class Controller {
return success; return success;
} }
/**
* 订阅任务下发接口
* @return
*/
@RequestMapping("subscribe")
public JSONObject subscribe(){
return monitorService.subscribe();
}
/**
* 事件模板分页查询接口
* @return
*/
@RequestMapping("tamplate")
public JSONObject tamplate(){
return monitorService.template();
}
//查询视频点播巡检结果只取异常的 //查询视频点播巡检结果只取异常的
// @RequestMapping("listChannelPlayStates") // @RequestMapping("listChannelPlayStates")
// public Result listChannelPlayStates( // public Result listChannelPlayStates(

View File

@ -0,0 +1,71 @@
package com.hisense.monitormanage.controller;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.hisense.monitormanage.entity.Result;
import com.hisense.monitormanage.service.ShangTangService;
import io.swagger.annotations.ApiOperation;
import org.omg.CORBA.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("STapi/project")
public class ShangTangController {
@Autowired
private ShangTangService shangTangService;
/**
* 订阅任务下发接口
* @return
*/
@RequestMapping("subscribe")
public JSONObject subscribe(){
return shangTangService.subscribe();
}
/**
* 订阅任务下发接口
* @param request
* @return
* @throws IOException
*/
@RequestMapping("receive")
@ApiOperation("订阅任务下发接口")
public Result receive(HttpServletRequest request) throws IOException {
ServletInputStream ris = request.getInputStream();
StringBuilder content = new StringBuilder();
byte[] b = new byte[1024];
int lens = -1;
while ((lens = ris.read(b)) > 0) {
content.append(new String(b, 0, lens));
}
String strcont = content.toString();// 内容
System.out.println(strcont);
return Result.success(strcont);
}
/**
* 事件模板分页查询接口
* @return
*/
@RequestMapping("tamplate")
@ApiOperation("事件模板分页查询接口")
public JSONObject tamplate(){
return shangTangService.template();
}
}

View File

@ -455,77 +455,6 @@ public class MonitorService {
} }
} }
//1.登录
//2.获取token
public String shangtangToken () {
String url = "http://10.132.191.54:10270/whale-open-api/tenant/token";
Map<String,Object> map = new HashMap<>();
map.put("ksUserName","hisense");
map.put("ksUserPassWord","Admin@2022");
ResponseEntity<JSONObject> responseEntity;
try {
responseEntity = restTemplate.postForEntity(url,map,JSONObject.class);
JSONObject body = responseEntity.getBody();
JSONObject data = body.getJSONObject("data");
String token = data.getString("token");
return token;
} catch (Exception e) {
log.info("[shangtangToken] exception:{}", e.getMessage());
return null;
}
}
//订阅任务下发接口
public JSONObject subscribe(){
String token = this.shangtangToken();
String url = "http://10.132.191.54:10270/whale-open-api/subscribe";
HttpHeaders headers = new HttpHeaders();
headers.add("token", token);
headers.add("tid","default");
Map<String,Object> map = new HashMap<>();
map.put("callBackUrl","http://15.2.23.205:7009/api/project/subscribe");
// map.put("certPubKey","");
map.put("subscribeType",1);
// map.put("taskId","serial");
ResponseEntity<JSONObject> responseEntity;
try {
responseEntity = restTemplate.exchange(url,HttpMethod.POST,new HttpEntity<>(map,headers),JSONObject.class);
JSONObject body = responseEntity.getBody();
return body;
}catch (Exception e){
log.info( "[subscribe] exception:{}",e.getMessage());
return null;
}
}
//事件模板分页查询接口
public JSONObject template(){
//String token = this.shangtangToken();
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event/template?pageNum=1&pageSize=1000";
HttpHeaders headers = new HttpHeaders();
headers.add("token","506eaf5d5d4a4cddb18f0370d906e22f");
headers.add("tid","default");
ResponseEntity<JSONObject> responseEntity;
try {
responseEntity = restTemplate.exchange(url,HttpMethod.GET,new HttpEntity<>(headers),JSONObject.class);
JSONObject jsonObject = responseEntity.getBody();
return jsonObject;
} catch (Exception e) {
log.info("[template] exception:{}", e.getMessage());
return null;
}
}
//查询视频点播巡检结果 //查询视频点播巡检结果
@Scheduled(cron="0 5 6 * * ?") @Scheduled(cron="0 5 6 * * ?")
public Result listChannelPlayStates(){ public Result listChannelPlayStates(){

View File

@ -0,0 +1,93 @@
package com.hisense.monitormanage.service;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@Service
@Log4j2
public class ShangTangService {
@Autowired
private RestTemplate restTemplate;
//1.登录
//2.获取token
public String shangtangToken () {
String url = "http://10.132.191.54:10270/whale-open-api/tenant/token";
Map<String,Object> map = new HashMap<>();
map.put("accessKey","a1ddCV7z7Jhv0SBGx5O3hblO");
map.put("secretKey","glIixzORLgoFJz0VdF1aXICR");
ResponseEntity<JSONObject> responseEntity;
try {
responseEntity = restTemplate.postForEntity(url,map,JSONObject.class);
JSONObject body = responseEntity.getBody();
JSONObject data = body.getJSONObject("data");
String token = data.getString("token");
log.info("get token:{}", body.toJSONString());
return token;
} catch (Exception e) {
log.info("[shangtangToken] exception:{}", e.getMessage());
return null;
}
}
//订阅任务下发接口
public JSONObject subscribe(){
String token = this.shangtangToken();
String url = "http://10.132.191.54:10270/whale-open-api/subscribe";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("token", token);
headers.add("tid","default");
Map<String,Object> map = new HashMap<>();
map.put("callBackUrl","http://15.2.23.205:7009/STapi/project/receive");
// map.put("certPubKey","");
map.put("subscribeType",3);
// map.put("taskId","serial");
ResponseEntity<JSONObject> responseEntity;
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(map), headers);
try {
responseEntity = restTemplate.exchange(url, HttpMethod.POST,entity,JSONObject.class);
JSONObject body = responseEntity.getBody();
return body;
}catch (Exception e){
log.info( "[subscribe] exception:{}",e.getMessage());
return null;
}
}
//事件模板分页查询接口
public JSONObject template(){
String token = this.shangtangToken();
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event/template?pageNum=1&pageSize=1000";
HttpHeaders headers = new HttpHeaders();
headers.add("token",token);
headers.add("tid","default");
ResponseEntity<JSONObject> responseEntity;
try {
responseEntity = restTemplate.exchange(url,HttpMethod.GET,new HttpEntity<>(headers),JSONObject.class);
JSONObject jsonObject = responseEntity.getBody();
return jsonObject;
} catch (Exception e) {
log.info("[template] exception:{}", e.getMessage());
return null;
}
}
}