From 29746d14593120165956eeeeef8e5d4d526c3727 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 09:04:47 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91MySQL?= =?UTF-8?q?=20jdbc=20=E8=BF=9E=E6=8E=A5=205.7=20=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yaml | 13 +++++------ .../src/main/resources/application-local.yaml | 22 ++++++------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/yudao-server/src/main/resources/application-dev.yaml b/yudao-server/src/main/resources/application-dev.yaml index ead65d51e..936aaae69 100644 --- a/yudao-server/src/main/resources/application-dev.yaml +++ b/yudao-server/src/main/resources/application-dev.yaml @@ -40,17 +40,14 @@ spring: primary: master datasource: master: - name: ruoyi-vue-pro - url: jdbc:mysql://400-infra.server.iocoder.cn:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=CTT&allowPublicKeyRetrieval=true - driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 username: root - password: 3WLiVUBEwTbvAfsh + password: 123456 slave: # 模拟从库,可根据自己需要修改 # 模拟从库,可根据自己需要修改 - name: ruoyi-vue-pro - url: jdbc:mysql://400-infra.server.iocoder.cn:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=CTT&allowPublicKeyRetrieval=true - driver-class-name: com.mysql.jdbc.Driver + lazy: true # 开启懒加载,保证启动速度 + url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 username: root - password: 3WLiVUBEwTbvAfsh + password: 123456 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 data: diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index ea1a7e809..96e6cda35 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -46,31 +46,23 @@ spring: primary: master datasource: master: - name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 - # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 - # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例 + url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 + # url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例 + # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 - # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 + # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ruoyi-vue-pro # SQLServer 连接的示例 # url: jdbc:dm://10.211.55.4:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 username: root password: 123456 - # username: sa - # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W + # username: sa # SQL Server 连接的示例 + # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # SQL Server 连接的示例 # username: SYSDBA # DM 连接的示例 # password: SYSDBA # DM 连接的示例 slave: # 模拟从库,可根据自己需要修改 - name: ruoyi-vue-pro lazy: true # 开启懒加载,保证启动速度 - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 - # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 - # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 - # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 - # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 + url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true username: root password: 123456 - # username: sa - # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 data: From 88ac5be882915c44ae6c064d9d245a96fc219581 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 09:37:49 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91ApiAcce?= =?UTF-8?q?ssLogInterceptor=20=E5=A4=84=E7=90=86=20request=20body=20?= =?UTF-8?q?=E4=B8=BA=20""=20=E7=A9=BA=E4=B8=B2=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apilog/core/interceptor/ApiAccessLogInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/interceptor/ApiAccessLogInterceptor.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/interceptor/ApiAccessLogInterceptor.java index 1cd43916f..04296ec57 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/interceptor/ApiAccessLogInterceptor.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/interceptor/ApiAccessLogInterceptor.java @@ -43,7 +43,7 @@ public class ApiAccessLogInterceptor implements HandlerInterceptor { log.info("[preHandle][开始请求 URL({}) 无参数]", request.getRequestURI()); } else { log.info("[preHandle][开始请求 URL({}) 参数({})]", request.getRequestURI(), - StrUtil.nullToDefault(requestBody, queryString.toString())); + StrUtil.blankToDefault(requestBody, queryString.toString())); } // 计时 StopWatch stopWatch = new StopWatch(); From ee3e507f07f4284dfbcf09dd222fca9c03228a64 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 09:55:04 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91GlobalE?= =?UTF-8?q?xceptionHandler=20=E6=96=B0=E5=A2=9E=20IGNORE=5FERROR=5FMESSAGE?= =?UTF-8?q?S=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=BF=BD=E7=95=A5=E2=80=9C?= =?UTF-8?q?=E6=97=A0=E6=95=88=E7=9A=84=E5=88=B7=E6=96=B0=E4=BB=A4=E7=89=8C?= =?UTF-8?q?=E2=80=9D=E7=AD=89=E9=9D=9E=E5=85=B3=E9=94=AE=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/core/handler/GlobalExceptionHandler.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java index 7c6014195..d86f353bc 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; @@ -32,6 +33,7 @@ import org.springframework.web.servlet.NoHandlerFoundException; import java.time.LocalDateTime; import java.util.Map; +import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*; @@ -45,6 +47,11 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC @Slf4j public class GlobalExceptionHandler { + /** + * 忽略的 ServiceException 错误提示,避免打印过多 logger + */ + public static final Set IGNORE_ERROR_MESSAGES = SetUtils.asSet("无效的刷新令牌"); + @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") private final String applicationName; @@ -199,7 +206,10 @@ public class GlobalExceptionHandler { */ @ExceptionHandler(value = ServiceException.class) public CommonResult serviceExceptionHandler(ServiceException ex) { - log.info("[serviceExceptionHandler]", ex); + if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) { + // 不包含的时候,才进行打印,避免 ex 堆栈过多 + log.info("[serviceExceptionHandler]", ex); + } return CommonResult.error(ex.getCode(), ex.getMessage()); } From 022238758cc1860e32846f00c88f4e88143f6e06 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 10:12:40 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E3=80=90=E5=AE=8C=E5=96=84=E3=80=91?= =?UTF-8?q?=E9=80=82=E9=85=8D=20jimu=20=E6=8A=A5=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jmreport/config/JmReportConfiguration.java | 7 +++++-- .../core/service/JmReportTokenServiceImpl.java | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/config/JmReportConfiguration.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/config/JmReportConfiguration.java index 3c99b2858..1946d052e 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/config/JmReportConfiguration.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/config/JmReportConfiguration.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.report.framework.jmreport.config; import cn.iocoder.yudao.framework.security.config.SecurityProperties; import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; import cn.iocoder.yudao.module.report.framework.jmreport.core.service.JmReportTokenServiceImpl; +import cn.iocoder.yudao.module.system.api.permission.PermissionApi; import org.jeecg.modules.jmreport.api.JmReportTokenServiceI; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -19,8 +20,10 @@ public class JmReportConfiguration { @Bean @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") - public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi, SecurityProperties securityProperties) { - return new JmReportTokenServiceImpl(oAuth2TokenApi, securityProperties); + public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi, + PermissionApi permissionApi, + SecurityProperties securityProperties) { + return new JmReportTokenServiceImpl(oAuth2TokenApi, permissionApi, securityProperties); } } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java index f4685432f..6d3225164 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java @@ -11,12 +11,13 @@ import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; -import cn.iocoder.yudao.module.system.api.permission.RoleApi; +import cn.iocoder.yudao.module.system.api.permission.PermissionApi; +import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.jeecg.modules.jmreport.api.JmReportTokenServiceI; import org.springframework.http.HttpHeaders; -import jakarta.servlet.http.HttpServletRequest; import java.util.Objects; /** @@ -37,6 +38,7 @@ public class JmReportTokenServiceImpl implements JmReportTokenServiceI { private static final String AUTHORIZATION_FORMAT = SecurityFrameworkUtils.AUTHORIZATION_BEARER + " %s"; private final OAuth2TokenApi oauth2TokenApi; + private final PermissionApi permissionApi; private final SecurityProperties securityProperties; @@ -130,9 +132,12 @@ public class JmReportTokenServiceImpl implements JmReportTokenServiceI { } @Override - public String[] getRoles(String s) { - // 暂时不用实现,因为不用 JmReport 的角色 - return null; + public String[] getRoles(String token) { + // 参见文档 https://help.jeecg.com/jimureport/prodSafe.html 文档 + // 适配:如果是本系统的管理员,则转换成 jimu 报表的管理员 + Long userId = SecurityFrameworkUtils.getLoginUserId(); + return permissionApi.hasAnyRoles(userId, RoleCodeEnum.SUPER_ADMIN.getCode()) + ? new String[]{"admin"} : null; } @Override From f381568f6b5b02f45142b91af1195d0bc0945db3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 10:35:58 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91CRM?= =?UTF-8?q?=EF=BC=9A=E5=95=86=E6=9C=BA=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=97=B6=EF=BC=8CbusinessProducts=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=8C=E5=BA=94=E8=AF=A5=E6=98=AF=20produc?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/business/vo/business/CrmBusinessSaveReqVO.java | 2 +- .../module/crm/service/business/CrmBusinessServiceImpl.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java index fa86692e7..102fcba9b 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java @@ -66,7 +66,7 @@ public class CrmBusinessSaveReqVO { private Long contactId; // 使用场景,在【联系人详情】添加商机时,如果需要关联两者,需要传递 contactId 字段 @Schema(description = "产品列表") - private List businessProducts; + private List products; @Schema(description = "产品列表") @Data diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java index 9d80a31ac..2da3eb150 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java @@ -89,7 +89,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { success = CRM_BUSINESS_CREATE_SUCCESS) public Long createBusiness(CrmBusinessSaveReqVO createReqVO, Long userId) { // 1.1 校验产品项的有效性 - List businessProducts = validateBusinessProducts(createReqVO.getBusinessProducts()); + List businessProducts = validateBusinessProducts(createReqVO.getProducts()); // 1.2 校验关联字段 validateRelationDataExists(createReqVO); @@ -130,7 +130,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { // 1.1 校验存在 CrmBusinessDO oldBusiness = validateBusinessExists(updateReqVO.getId()); // 1.2 校验产品项的有效性 - List businessProducts = validateBusinessProducts(updateReqVO.getBusinessProducts()); + List businessProducts = validateBusinessProducts(updateReqVO.getProducts()); // 1.3 校验关联字段 validateRelationDataExists(updateReqVO); From 290a981cae0c99a506caac543bb1c4797e219c6b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 10:38:05 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91?= =?UTF-8?q?=E5=85=A8=E5=B1=80=EF=BC=9A=E7=A7=BB=E9=99=A4=20Druid=20?= =?UTF-8?q?=E5=B9=BF=E5=91=8A=E9=80=BB=E8=BE=91=E6=9C=AA=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E6=9C=9F=E6=9C=9B=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/config/YudaoDataSourceAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/datasource/config/YudaoDataSourceAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/datasource/config/YudaoDataSourceAutoConfiguration.java index 99c7f0945..879a19aae 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/datasource/config/YudaoDataSourceAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/datasource/config/YudaoDataSourceAutoConfiguration.java @@ -23,7 +23,7 @@ public class YudaoDataSourceAutoConfiguration { * 创建 DruidAdRemoveFilter 过滤器,过滤 common.js 的广告 */ @Bean - @ConditionalOnProperty(name = "spring.datasource.druid.web-stat-filter.enabled", havingValue = "true") + @ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true") public FilterRegistrationBean druidAdRemoveFilterFilter(DruidStatProperties properties) { // 获取 druid web 监控页面的参数 DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); From ffac294fbd67c6a83e469260e47b676f09c8086f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 22:11:22 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91?= =?UTF-8?q?=E5=85=A8=E5=B1=80=EF=BC=9A=E5=85=BC=E5=AE=B9=20MyBatis=20Plus?= =?UTF-8?q?=20=E9=92=88=E5=AF=B9=20SQL=20Server=20=E7=9A=84=20saveBatch=20?= =?UTF-8?q?=E4=B8=8D=E5=85=BC=E5=AE=B9=E7=9A=84=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/mybatis/core/mapper/BaseMapperX.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index d6bbe922b..e7767c6f1 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -5,7 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.SortablePageParam; import cn.iocoder.yudao.framework.common.pojo.SortingField; +import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; +import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -20,6 +22,7 @@ import org.apache.ibatis.annotations.Param; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力 @@ -147,6 +150,11 @@ public interface BaseMapperX extends MPJBaseMapper { * @param entities 实体们 */ default Boolean insertBatch(Collection entities) { + // 特殊:SQL Server 批量插入后,获取 id 会报错,因此通过循环处理 + if (Objects.equals(SqlConstants.DB_TYPE, DbType.SQL_SERVER)) { + entities.forEach(this::insert); + return CollUtil.isNotEmpty(entities); + } return Db.saveBatch(entities); } @@ -157,6 +165,11 @@ public interface BaseMapperX extends MPJBaseMapper { * @param size 插入数量 Db.saveBatch 默认为 1000 */ default Boolean insertBatch(Collection entities, int size) { + // 特殊:SQL Server 批量插入后,获取 id 会报错,因此通过循环处理 + if (Objects.equals(SqlConstants.DB_TYPE, DbType.SQL_SERVER)) { + entities.forEach(this::insert); + return CollUtil.isNotEmpty(entities); + } return Db.saveBatch(entities, size); } From 93e8e9c7af61903c9a7a3bc2d98f139be4cd8e38 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 22:37:15 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91?= =?UTF-8?q?=E5=85=A8=E5=B1=80=EF=BC=9AJobController=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20sync=20=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=B0=86=20infra=5Fjob=20=E5=90=8C=E6=AD=A5=E5=88=B0=20Quartz?= =?UTF-8?q?=20=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/job/JobController.http | 5 ++++ .../controller/admin/job/JobController.java | 8 ++++++ .../module/infra/service/job/JobService.java | 7 ++++++ .../infra/service/job/JobServiceImpl.java | 25 +++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.http diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.http b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.http new file mode 100644 index 000000000..62f8dd606 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.http @@ -0,0 +1,5 @@ +### 请求 /infra/job/sync 接口 => 成功 +POST {{baseUrl}}/infra/job/sync +Content-Type: application/json +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java index 1881db53a..372b6391b 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java @@ -90,6 +90,14 @@ public class JobController { return success(true); } + @PostMapping("/sync") + @Operation(summary = "同步定时任务") + @PreAuthorize("@ss.hasPermission('infra:job:create')") + public CommonResult syncJob() throws SchedulerException { + jobService.syncJob(); + return success(true); + } + @GetMapping("/get") @Operation(summary = "获得定时任务") @Parameter(name = "id", description = "编号", required = true, example = "1024") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java index 882c21112..971fd1b62 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java @@ -45,6 +45,13 @@ public interface JobService { */ void triggerJob(Long id) throws SchedulerException; + /** + * 同步定时任务 + * + * 目的:自己存储的 Job 信息,强制同步到 Quartz 中 + */ + void syncJob() throws SchedulerException; + /** * 删除定时任务 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java index dd887e165..cfc52d29d 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java @@ -12,11 +12,15 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobMapper; import cn.iocoder.yudao.module.infra.enums.job.JobStatusEnum; import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; import org.quartz.SchedulerException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.util.List; +import java.util.Objects; + import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.containsAny; import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; @@ -28,6 +32,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; */ @Service @Validated +@Slf4j public class JobServiceImpl implements JobService { @Resource @@ -129,6 +134,26 @@ public class JobServiceImpl implements JobService { schedulerManager.triggerJob(job.getId(), job.getHandlerName(), job.getHandlerParam()); } + @Override + @Transactional(rollbackFor = Exception.class) + public void syncJob() throws SchedulerException { + // 1. 查询 Job 配置 + List jobList = jobMapper.selectList(); + + // 2. 遍历处理 + for (JobDO job : jobList) { + // 2.1 先删除,再创建 + schedulerManager.deleteJob(job.getHandlerName()); + schedulerManager.addJob(job.getId(), job.getHandlerName(), job.getHandlerParam(), job.getCronExpression(), + job.getRetryCount(), job.getRetryInterval()); + // 2.2 如果 status 为暂停,则需要暂停 + if (Objects.equals(job.getStatus(), JobStatusEnum.STOP.getStatus())) { + schedulerManager.pauseJob(job.getHandlerName()); + } + log.info("[syncJob][id({}) handlerName({}) 同步完成]", job.getId(), job.getHandlerName()); + } + } + @Override @Transactional(rollbackFor = Exception.class) public void deleteJob(Long id) throws SchedulerException {