From af6d49bdd82e1f1dc2d68a88944c5754d857d860 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Mon, 22 Jan 2024 14:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B7=AF=E6=B5=8B=E5=B9=BF?= =?UTF-8?q?=E6=92=AD=E8=AE=BE=E5=A4=87=E5=8A=9F=E8=83=BD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BroadcastController.java | 111 ++++++++++++++++++ .../com/zc/business/domain/DcStakeMark.java | 2 + 2 files changed, 113 insertions(+) create mode 100644 zc-business/src/main/java/com/zc/business/controller/BroadcastController.java diff --git a/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java b/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java new file mode 100644 index 00000000..711cbe34 --- /dev/null +++ b/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 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; + } + + ///** + +} diff --git a/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java b/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java index 4ad7c187..f69b5840 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java +++ b/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; }