统一 boot 和 cloud 代码

This commit is contained in:
YunaiV 2023-10-24 13:39:31 +08:00
parent f7d264eff7
commit 51f96686f8
29 changed files with 253 additions and 222 deletions

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.bpm.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* bpm 模块的 web 组件的 Configuration
*
* @author 芋道源码
*/
@Configuration(proxyBeanMethods = false)
public class BpmWebConfiguration {
/**
* bpm 模块的 API 分组
*/
@Bean
public GroupedOpenApi bpmGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("bpm");
}
}

View File

@ -1,4 +0,0 @@
/**
* bpm 模块的 web 配置
*/
package cn.iocoder.yudao.module.bpm.framework.web;

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.infra.controller.app.file;
import cn.hutool.core.io.IoUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO;
import cn.iocoder.yudao.module.infra.service.file.FileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "用户 App - 文件存储")
@RestController
@RequestMapping("/infra/file")
@Validated
@Slf4j
public class AppFileController {
@Resource
private FileService fileService;
@PostMapping("/upload")
@Operation(summary = "上传文件")
public CommonResult<String> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception {
MultipartFile file = uploadReqVO.getFile();
String path = uploadReqVO.getPath();
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
}
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.infra.controller.app.file.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotNull;
@Schema(description = "用户 App - 上传文件 Request VO")
@Data
public class AppFileUploadReqVO {
@Schema(description = "文件附件", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "文件附件不能为空")
private MultipartFile file;
@Schema(description = "文件附件", example = "yudaoyuanma.png")
private String path;
}

View File

@ -6,8 +6,11 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -44,4 +47,14 @@ public interface ApiAccessLogMapper extends BaseMapperX<ApiAccessLogDO> {
);
}
/**
* 物理删除指定时间之前的日志
*
* @param createTime 最大时间
* @param limit 删除条数防止一次删除太多
* @return 删除条数
*/
@Delete("DELETE FROM infra_api_access_log WHERE create_time < #{createTime} LIMIT #{limit}")
Integer deleteByCreateTimeLt(@Param("createTime") LocalDateTime createTime, @Param("limit") Integer limit);
}

View File

@ -6,8 +6,11 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -42,4 +45,14 @@ public interface ApiErrorLogMapper extends BaseMapperX<ApiErrorLogDO> {
);
}
/**
* 物理删除指定时间之前的日志
*
* @param createTime 最大时间
* @param limit 删除条数防止一次删除太多
* @return 删除条数
*/
@Delete("DELETE FROM infra_api_error_log WHERE create_time < #{createTime} LIMIT #{limit}")
Integer deleteByCreateTimeLt(@Param("createTime") LocalDateTime createTime, @Param("limit")Integer limit);
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.infra.job.logger;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.infra.service.logger.ApiAccessLogService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* 物理删除 N 天前的访问日志的 Job
*
* @author j-sentinel
*/
@Component
@Slf4j
public class AccessLogCleanJob {
@Resource
private ApiAccessLogService apiAccessLogService;
/**
* 清理超过14天的日志
*/
private static final Integer JOB_CLEAN_RETAIN_DAY = 14;
/**
* 每次删除间隔的条数如果值太高可能会造成数据库的压力过大
*/
private static final Integer DELETE_LIMIT = 100;
@XxlJob("accessLogCleanJob")
@TenantIgnore
public void execute() {
Integer count = apiAccessLogService.cleanAccessLog(JOB_CLEAN_RETAIN_DAY, DELETE_LIMIT);
log.info("[execute][定时执行清理访问日志数量 ({}) 个]", count);
}
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.infra.job.logger;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.infra.service.logger.ApiErrorLogService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* 物理删除 N 天前的错误日志的 Job
*
* @author j-sentinel
*/
@Slf4j
@Component
public class ErrorLogCleanJob {
@Resource
private ApiErrorLogService apiErrorLogService;
/**
* 清理超过14天的日志
*/
private static final Integer JOB_CLEAN_RETAIN_DAY = 14;
/**
* 每次删除间隔的条数如果值太高可能会造成数据库的压力过大
*/
private static final Integer DELETE_LIMIT = 100;
@XxlJob("errorLogCleanJob")
@TenantIgnore
public void execute() {
Integer count = apiErrorLogService.cleanErrorLog(JOB_CLEAN_RETAIN_DAY,DELETE_LIMIT);
log.info("[execute][定时执行清理错误日志数量 ({}) 个]", count);
}
}

View File

@ -0,0 +1,4 @@
/**
* 占位无特殊含义
*/
package cn.iocoder.yudao.module.infra.job;

View File

@ -1,11 +1,9 @@
package cn.iocoder.yudao.module.infra.service.logger;
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog;
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
import java.util.List;
@ -40,4 +38,12 @@ public interface ApiAccessLogService {
*/
List<ApiAccessLogDO> getApiAccessLogList(ApiAccessLogExportReqVO exportReqVO);
/**
* 清理 exceedDay 天前的访问日志
*
* @param exceedDay 超过多少天就进行清理
* @param deleteLimit 清理的间隔条数
*/
Integer cleanAccessLog(Integer exceedDay, Integer deleteLimit);
}

View File

@ -1,18 +1,18 @@
package cn.iocoder.yudao.module.infra.service.logger;
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
import cn.iocoder.yudao.module.infra.convert.logger.ApiAccessLogConvert;
import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiAccessLogMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.scheduling.annotation.Async;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -20,6 +20,7 @@ import java.util.List;
*
* @author 芋道源码
*/
@Slf4j
@Service
@Validated
public class ApiAccessLogServiceImpl implements ApiAccessLogService {
@ -43,4 +44,21 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
return apiAccessLogMapper.selectList(exportReqVO);
}
@Override
@SuppressWarnings("DuplicatedCode")
public Integer cleanAccessLog(Integer exceedDay, Integer deleteLimit) {
int count = 0;
LocalDateTime expireDate = LocalDateTime.now().minusDays(exceedDay);
// 循环删除直到没有满足条件的数据
for (int i = 0; i < Short.MAX_VALUE; i++) {
int deleteCount = apiAccessLogMapper.deleteByCreateTimeLt(expireDate, deleteLimit);
count += deleteCount;
// 达到删除预期条数说明到底了
if (deleteCount < deleteLimit) {
break;
}
}
return count;
}
}

View File

@ -1,7 +1,5 @@
package cn.iocoder.yudao.module.infra.service.logger;
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLog;
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO;
@ -49,4 +47,12 @@ public interface ApiErrorLogService {
*/
void updateApiErrorLogProcess(Long id, Integer processStatus, Long processUserId);
/**
* 清理 exceedDay 天前的错误日志
*
* @param exceedDay 超过多少天就进行清理
* @param deleteLimit 清理的间隔条数
*/
Integer cleanErrorLog(Integer exceedDay, Integer deleteLimit);
}

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.infra.convert.logger.ApiErrorLogConvert;
import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiErrorLogMapper;
import cn.iocoder.yudao.module.infra.enums.logger.ApiErrorLogProcessStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -24,6 +25,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.API_ERROR_L
*
* @author 芋道源码
*/
@Slf4j
@Service
@Validated
public class ApiErrorLogServiceImpl implements ApiErrorLogService {
@ -62,4 +64,21 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
.processUserId(processUserId).processTime(LocalDateTime.now()).build());
}
@Override
@SuppressWarnings("DuplicatedCode")
public Integer cleanErrorLog(Integer exceedDay, Integer deleteLimit) {
int count = 0;
LocalDateTime expireDate = LocalDateTime.now().minusDays(exceedDay);
// 循环删除直到没有满足条件的数据
for (int i = 0; i < Short.MAX_VALUE; i++) {
int deleteCount = apiErrorLogMapper.deleteByCreateTimeLt(expireDate, deleteLimit);
count += deleteCount;
// 达到删除预期条数说明到底了
if (deleteCount < deleteLimit) {
break;
}
}
return count;
}
}

View File

@ -1,12 +1,10 @@
DELETE FROM "infra_config";
DELETE FROM "infra_file_config";
DELETE FROM "infra_file";
DELETE FROM "infra_job";
DELETE FROM "infra_job_log";
DELETE FROM "infra_api_access_log";
DELETE FROM "infra_api_error_log";
DELETE FROM "infra_api_access_log";
DELETE FROM "infra_file";
DELETE FROM "infra_api_error_log";
DELETE FROM "infra_test_demo";
DELETE FROM "infra_file_config";
DELETE FROM "infra_test_demo";
DELETE FROM "infra_data_source_config";

View File

@ -85,19 +85,6 @@ CREATE TABLE IF NOT EXISTS "infra_job_log" (
PRIMARY KEY ("id")
)COMMENT='定时任务日志表';
CREATE TABLE IF NOT EXISTS "inf_file" (
"id" varchar(188) NOT NULL,
"type" varchar(63) DEFAULT NULL,
"content" blob NOT NULL,
"creator" varchar(64) DEFAULT '',
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar(64) DEFAULT '',
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint not null default '0',
PRIMARY KEY ("id")
) COMMENT '文件表';
CREATE TABLE IF NOT EXISTS "infra_api_access_log" (
"id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
"trace_id" varchar(64) not null default '',

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.product.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* product 模块的 web 组件的 Configuration
*
* @author 芋道源码
*/
@Configuration(proxyBeanMethods = false)
public class ProductWebConfiguration {
/**
* product 模块的 API 分组
*/
@Bean
public GroupedOpenApi productGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("product");
}
}

View File

@ -1,4 +0,0 @@
/**
* product 模块的 web 配置
*/
package cn.iocoder.yudao.module.product.framework.web;

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.promotion.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* promotion 模块的 web 组件的 Configuration
*
* @author 芋道源码
*/
@Configuration(proxyBeanMethods = false)
public class PromotionWebConfiguration {
/**
* promotion 模块的 API 分组
*/
@Bean
public GroupedOpenApi promotionGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("promotion");
}
}

View File

@ -1,4 +0,0 @@
/**
* promotion 模块的 web 配置
*/
package cn.iocoder.yudao.module.promotion.framework.web;

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.trade.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* trade 模块的 web 组件的 Configuration
*
* @author 芋道源码
*/
@Configuration(proxyBeanMethods = false)
public class TradeWebConfiguration {
/**
* trade 模块的 API 分组
*/
@Bean
public GroupedOpenApi tradeGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("trade");
}
}

View File

@ -1,4 +0,0 @@
/**
* trade 模块的 web 配置
*/
package cn.iocoder.yudao.module.trade.framework.web;

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.member.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* member 模块的 web 组件的 Configuration
*
* @author 芋道源码
*/
@Configuration(proxyBeanMethods = false)
public class MemberWebConfiguration {
/**
* member 模块的 API 分组
*/
@Bean
public GroupedOpenApi memberGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("member");
}
}

View File

@ -1,4 +0,0 @@
/**
* member 模块的 web 配置
*/
package cn.iocoder.yudao.module.member.framework.web;

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.mp.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* mp 模块的 web 组件的 Configuration
*
* @author 芋道源码
*/
@Configuration(proxyBeanMethods = false)
public class MpWebConfiguration {
/**
* mp 模块的 API 分组
*/
@Bean
public GroupedOpenApi mpGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("mp");
}
}

View File

@ -1,4 +0,0 @@
/**
* mp 模块的 web 配置
*/
package cn.iocoder.yudao.module.mp.framework.web;

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.pay.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* pay 模块的 web 组件的 Configuration
*
* @author 芋道源码
*/
@Configuration(proxyBeanMethods = false)
public class PayWebConfiguration {
/**
* pay 模块的 API 分组
*/
@Bean
public GroupedOpenApi payGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("pay");
}
}

View File

@ -1,4 +0,0 @@
/**
* pay 模块的 web 配置
*/
package cn.iocoder.yudao.module.pay.framework.web;

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.system.enums.notify;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 通知模板类型枚举
*
* @author HUIHUI
*/
@Getter
@AllArgsConstructor
public enum NotifyTemplateTypeEnum {
/**
* 系统消息
*/
SYSTEM_MESSAGE(2),
/**
* 通知消息
*/
NOTIFICATION_MESSAGE(1);
private final Integer type;
}

View File

@ -15,7 +15,6 @@ tag: Yunai.local
POST {{baseUrl}}/system/auth/login
Content-Type: application/json
tenant-id: {{adminTenentId}}
tag: Yunai.local
{
"username": "admin",