Browse Source

新增路测广播设备功能接口

develop
zhaoxianglong 1 year ago
parent
commit
af6d49bdd8
  1. 111
      zc-business/src/main/java/com/zc/business/controller/BroadcastController.java
  2. 2
      zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java

111
zc-business/src/main/java/com/zc/business/controller/BroadcastController.java

@ -0,0 +1,111 @@
package com.zc.business.controller;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.zc.common.core.httpclient.OkHttp;
import com.zc.common.core.httpclient.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import okhttp3.Response;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import static com.ruoyi.common.constant.Constants.HTTP;
/**
* License
*
* @author Athena-xiepufeng
*/
@Api(tags = "广播接口")
@RestController
@RequestMapping("/broadcast")
public class BroadcastController extends BaseController {
@Resource
private RedisCache redisCache;
private static final String ID = "admin";
private static final String SECRET = "21232f297a57a5a743894a0e4a801fc3";
private static final String CALLBACKURL = "http://10.0.81.209/broadcast/logIn";
private final static String URL = HTTP + "10.0.81.106/api/REST-API/";
private final static String TOKENKEY = "tokenRoadTestBroadcastPlatform";
/**
* 广播平台事件回调函数
*
* @param returnParameters 事件回参
* @return 更新结果
*/
@PostMapping(value = "/event/{event}")
public AjaxResult logIn(@PathVariable String event, HashMap<String, Object> returnParameters) {
Object accessToken = returnParameters.get("accessToken");
System.out.println(accessToken);
//todo
return null;
}
/*
* 调用功能
* */
@ApiOperation("广播功能调用")
@PostMapping(value = "/broadcastFunctionCall")
public JSONObject nearCamListDistance(@RequestBody JSONObject params) throws HttpException, IOException {
JSONObject jsonResult = null;
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(params);
String tokenRoadTestBroadcastPlatform = redisCache.getCacheObject(TOKENKEY);
if (tokenRoadTestBroadcastPlatform == null) {
tokenRoadTestBroadcastPlatform = getToken();
}
Response response // 请求响应
= okHttp
.headers(new HashMap<>())
.url(URL + params.getString("functionType") + ".do?accessToken=" + tokenRoadTestBroadcastPlatform) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
}
return jsonResult;
}
public String getToken() throws HttpException, IOException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("id", ID);
requestParams.put("secret", SECRET);
requestParams.put("callbackUrl", CALLBACKURL);
Response response // 请求响应
= okHttp
.headers(new HashMap<>())
.url("http://10.0.81.106/api/REST-API/login.do") // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
if (response.body() != null) {
//accessToken
String accessToken = JSONObject.parseObject(response.body().string()).getString("accessToken");
//RedisCache redisCache = new RedisCache();
redisCache.setCacheObject(TOKENKEY, accessToken, 100, TimeUnit.MINUTES);
return accessToken;
}
return null;
}
///**
}

2
zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java

@ -27,5 +27,7 @@ public class DcStakeMark {
private Date createTime;
@ApiModelProperty("修改时间")
private Date updateTime;
@ApiModelProperty("所属辖区")
private Long sectionId;
}

Loading…
Cancel
Save