diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysMenu.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysMenu.java index 9983ed1a..3f9b11e8 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysMenu.java +++ b/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; diff --git a/zc-business/src/main/java/com/zc/business/controller/DcEventController.java b/zc-business/src/main/java/com/zc/business/controller/DcEventController.java index 4f7ceb6d..c9b6d5fe 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcEventController.java +++ b/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 list = dcEventService.selectDcEventList(dcEvent); ExcelUtil util = new ExcelUtil(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()); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java index 0c9631fd..f69f2428 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java +++ b/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 refreshAccessToken() { + CompletableFuture 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; }