From e5dd8d82153d8220798409a0244da23129892db7 Mon Sep 17 00:00:00 2001 From: Ziin Date: Mon, 23 Jun 2025 13:03:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=201.=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=BF=94=E5=9B=9E=E6=9F=A5=E8=AF=A2TK=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E7=BB=9F=E8=AE=A1=E6=AC=A1=E6=95=B0=202.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9F=A5=E8=AF=A2=E4=B8=BB=E6=92=AD=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=20sqlXML=20BUG=203.=E6=B7=BB=E5=8A=A0=E4=B8=BB=E6=92=ADHostInf?= =?UTF-8?q?o=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/SaTokenConfigure.java | 28 ++++++++++++++++++- .../controller/CommonController.java | 2 +- .../model/dto/host/HostInfoDTO.java | 2 ++ .../springbootinit/service/CommonService.java | 2 +- .../service/impl/CommonServiceImpl.java | 7 +++-- src/main/resources/mapper/NewHostsMapper.xml | 10 ++++--- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/yupi/springbootinit/config/SaTokenConfigure.java b/src/main/java/com/yupi/springbootinit/config/SaTokenConfigure.java index 9869280..8bf6627 100644 --- a/src/main/java/com/yupi/springbootinit/config/SaTokenConfigure.java +++ b/src/main/java/com/yupi/springbootinit/config/SaTokenConfigure.java @@ -1,14 +1,20 @@ package com.yupi.springbootinit.config; +import cn.dev33.satoken.fun.strategy.SaCorsHandleFunction; import cn.dev33.satoken.interceptor.SaInterceptor; +import cn.dev33.satoken.router.SaHttpMethod; +import cn.dev33.satoken.router.SaRouter; import cn.dev33.satoken.stp.StpUtil; import com.yupi.springbootinit.common.ErrorCode; import com.yupi.springbootinit.exception.BusinessException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration +@Slf4j public class SaTokenConfigure implements WebMvcConfigurer { @@ -17,7 +23,7 @@ public class SaTokenConfigure implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { // 注册Sa-Token的拦截器 registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())) - .addPathPatterns("/api/**") + .addPathPatterns("/**") .excludePathPatterns(getExcludePaths()); } @@ -41,4 +47,24 @@ public class SaTokenConfigure implements WebMvcConfigurer { "/tenant/get-id-by-name" }; } + + @Bean + public SaCorsHandleFunction corsHandle() { + return (req, res, sto) -> { + res. + // 允许指定域访问跨域资源 + setHeader("Access-Control-Allow-Origin", "*") + // 允许所有请求方式 + .setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE") + // 有效时间 + .setHeader("Access-Control-Max-Age", "3600") + // 允许的header参数 + .setHeader("Access-Control-Allow-Headers", "*"); + + // 如果是预检请求,则立即返回到前端 + SaRouter.match(SaHttpMethod.OPTIONS) + .back(); + }; + + } } \ No newline at end of file diff --git a/src/main/java/com/yupi/springbootinit/controller/CommonController.java b/src/main/java/com/yupi/springbootinit/controller/CommonController.java index 30d893b..d5c633d 100644 --- a/src/main/java/com/yupi/springbootinit/controller/CommonController.java +++ b/src/main/java/com/yupi/springbootinit/controller/CommonController.java @@ -35,7 +35,7 @@ public class CommonController { } @GetMapping("accountCount") - public BaseResponse getAccountCount(@RequestParam String accountName){ + public BaseResponse getAccountCount(@RequestParam String accountName){ return ResultUtils.success(commonService.getAccountCrawlCount(accountName)); } diff --git a/src/main/java/com/yupi/springbootinit/model/dto/host/HostInfoDTO.java b/src/main/java/com/yupi/springbootinit/model/dto/host/HostInfoDTO.java index fe262ff..f84d1b3 100644 --- a/src/main/java/com/yupi/springbootinit/model/dto/host/HostInfoDTO.java +++ b/src/main/java/com/yupi/springbootinit/model/dto/host/HostInfoDTO.java @@ -157,12 +157,14 @@ public class HostInfoDTO extends PageRequest implements Serializable { * 数据插入最大 */ @ApiModelProperty(value = "创建时间查询上限(yyyy-MM-dd)", example = "2023-12-31") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date createTimeMax; /** * 数据插入最小 */ @ApiModelProperty(value = "创建时间查询下限(yyyy-MM-dd)", example = "2023-01-01") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date createTimeMin; /** diff --git a/src/main/java/com/yupi/springbootinit/service/CommonService.java b/src/main/java/com/yupi/springbootinit/service/CommonService.java index c14f144..d74e8ff 100644 --- a/src/main/java/com/yupi/springbootinit/service/CommonService.java +++ b/src/main/java/com/yupi/springbootinit/service/CommonService.java @@ -7,5 +7,5 @@ import com.yupi.springbootinit.model.vo.common.AccountCrawlCount; * @date: 2025/6/16 14:07 */ public interface CommonService { - AccountCrawlCount getAccountCrawlCount(String accountName); + Integer getAccountCrawlCount(String accountName); } diff --git a/src/main/java/com/yupi/springbootinit/service/impl/CommonServiceImpl.java b/src/main/java/com/yupi/springbootinit/service/impl/CommonServiceImpl.java index cf078db..962e8eb 100644 --- a/src/main/java/com/yupi/springbootinit/service/impl/CommonServiceImpl.java +++ b/src/main/java/com/yupi/springbootinit/service/impl/CommonServiceImpl.java @@ -21,15 +21,16 @@ public class CommonServiceImpl implements CommonService { private RedisTemplate redisTemplate; @Override - public AccountCrawlCount getAccountCrawlCount(String accountName) { + public Integer getAccountCrawlCount(String accountName) { AccountCrawlCount accountCrawlCount = new AccountCrawlCount(); accountCrawlCount.setAccountName(accountName); Object o = redisTemplate.opsForValue().get("tkaccount:" + accountName); if (o != null) { accountCrawlCount.setCount(Integer.valueOf(o.toString())); - return accountCrawlCount; + return accountCrawlCount.getCount(); }else{ - throw new BusinessException(ErrorCode.NOT_FOUND_ERROR); + accountCrawlCount.setCount(0); + return accountCrawlCount.getCount(); } } diff --git a/src/main/resources/mapper/NewHostsMapper.xml b/src/main/resources/mapper/NewHostsMapper.xml index b246bd8..5fd7e18 100644 --- a/src/main/resources/mapper/NewHostsMapper.xml +++ b/src/main/resources/mapper/NewHostsMapper.xml @@ -245,9 +245,8 @@