Browse Source

路由限制,交通流token ,事件导出

develop
王兴琳 5 months ago
parent
commit
e19b389594
  1. 2
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysMenu.java
  2. 28
      zc-business/src/main/java/com/zc/business/controller/DcEventController.java
  3. 54
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

2
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysMenu.java

@ -130,7 +130,7 @@ public class SysMenu extends BaseEntity
this.orderNum = orderNum;
}
@Size(min = 0, max = 200, message = "路由地址不能超过200个字符")
@Size(min = 0, max = 1000, message = "路由地址不能超过1000个字符")
public String getPath()
{
return path;

28
zc-business/src/main/java/com/zc/business/controller/DcEventController.java

@ -14,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
@ -72,10 +75,31 @@ public class DcEventController extends BaseController
//@PreAuthorize("@ss.hasPermi('system:event:export')")
@Log(title = "事件信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response,@RequestBody DcEvent dcEvent)
{
public void export(HttpServletResponse response,@RequestBody DcEvent dcEvent) throws UnsupportedEncodingException {
List<DcEvent> list = dcEventService.selectDcEventList(dcEvent);
ExcelUtil<DcEvent> util = new ExcelUtil<DcEvent>(DcEvent.class);
int eventState = Math.toIntExact(dcEvent.getEventState());
String name="";
if (eventState==UniversalEnum.ZERO.getNumber()){
name="待确认事件.xlsx";
}if (eventState==UniversalEnum.ONE.getNumber()){
name="处置中事件.xlsx";
}if (eventState==UniversalEnum.TWO.getNumber()){
name="已处置事件.xlsx";
}
String percentEncodedFileName = URLEncoder.encode(name, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20");
StringBuilder contentDispositionValue = new StringBuilder();
contentDispositionValue.append("attachment; filename=")
.append(percentEncodedFileName)
.append(";")
.append("filename*=")
.append("utf-8''")
.append(percentEncodedFileName);
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
response.setHeader("Content-disposition", contentDispositionValue.toString());
response.setHeader("download-filename", percentEncodedFileName);
util.exportExcel(response, list, UniversalEnum.EVENT_INFORMATION_DATA.getValue());
}

54
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

@ -37,6 +37,8 @@ import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -79,6 +81,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
* 3. 在请求成功时解析响应体中的令牌信息并更新本地存储的令牌
*/
//@Scheduled(cron = "0 0 */5 * * ?")
/*
public static void refreshAccessToken() {
OkHttp okHttp = new OkHttp();
try {
@ -114,7 +117,42 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
}
}
*/
public static CompletableFuture<String> refreshAccessToken() {
CompletableFuture<String> future = new CompletableFuture<>();
OkHttp okHttp = new OkHttp();
try {
okHttp.url(baseUrl + UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_OBTAIN_THE_TOKEN_URI.getValue())
.post(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
future.completeExceptionally(e);
}
@Override
public void onResponse(Call call, Response response) {
try {
if (response.isSuccessful() && response.body() != null) {
JSONObject token = JSON.parseObject(response.body().string());
String accessToken = token.getString("access_token");
// 将 access token 存储到 Redis
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
redisCache.setCacheObject(RedisKeyConstants.TRAFFIC_FLOW, token.getString("token_type") + " " + accessToken, token.getInteger("expires_in"), TimeUnit.SECONDS);
future.complete(accessToken);
} else {
future.completeExceptionally(new IOException("意外响应码:" + response.code()));
}
} catch (IOException e) {
future.completeExceptionally(e);
}
}
});
} catch (HttpException e) {
future.completeExceptionally(e);
}
return future;
}
/**
* 获取访问令牌
@ -128,13 +166,21 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
String token = redisCache.getCacheObject(RedisKeyConstants.TRAFFIC_FLOW);
// 检查token是否存在
if (token == null) {
// 组合并返回token类型和访问令牌
refreshAccessToken();
token = redisCache.getCacheObject(RedisKeyConstants.TRAFFIC_FLOW);
// // 组合并返回token类型和访问令牌
// refreshAccessToken();
// token = redisCache.getCacheObject(RedisKeyConstants.TRAFFIC_FLOW);
// 异步获取新token,并更新缓存
try {
// 异步获取新token,并更新缓存
token = refreshAccessToken().get(); // 等待异步操作完成
} catch (InterruptedException | ExecutionException e) {
// 处理异常情况
e.printStackTrace();
}
}
// 如果token不存在,返回null
return token;
}

Loading…
Cancel
Save