From 1eeb950cf8c7fbafad0b15743e7665514188e078 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Tue, 4 Jul 2023 11:07:13 +0800 Subject: [PATCH] review code. --- .../mybatis/generator/CodeGenerator.java | 21 ++++++++------ .../mybatis/{cache => query}/CacheQuery.java | 28 +++++++++++++++---- .../framework/mybatis/query/Conditions.java | 12 +++++++- .../mybatis/query/ValidateLambdaWrapper.java | 11 ++++++++ 4 files changed, 57 insertions(+), 15 deletions(-) rename orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/{cache => query}/CacheQuery.java (73%) diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/generator/CodeGenerator.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/generator/CodeGenerator.java index 9edbdd98..16f9291d 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/generator/CodeGenerator.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/generator/CodeGenerator.java @@ -13,10 +13,13 @@ import com.baomidou.mybatisplus.generator.config.rules.DbColumnType; import com.baomidou.mybatisplus.generator.config.rules.IColumnType; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import com.orion.lang.constant.Const; +import com.orion.lang.utils.ext.yml.YmlExt; import com.orion.ops.framework.mybatis.domain.BaseDO; import com.orion.ops.framework.mybatis.mapper.IMapper; import org.apache.ibatis.annotations.Mapper; +import java.io.File; + /** * @author Jiahang Li */ @@ -25,14 +28,16 @@ public class CodeGenerator { public static void main(String[] args) { String outputDir = "D:/MP/"; String author = Const.ORION_AUTHOR; - String url = "jdbc:mysql://127.0.0.1:3306/orion-ops-pro?characterEncoding=utf8"; - String username = "root"; - String password = "Data@123456"; - // 表名 String[] tables = {"user_info"}; // 模块 String module = "user"; + // 连接 + File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml"); + YmlExt yaml = YmlExt.load(yamlFile); + String url = yaml.getValue("spring.datasource.druid.url"); + String username = yaml.getValue("spring.datasource.druid.username"); + String password = yaml.getValue("spring.datasource.druid.password"); // 执行 runGenerator(outputDir, author, @@ -140,11 +145,11 @@ public class CodeGenerator { // 映射文件的包 .xml("mapper") // service接口的包 - .service("ignore.service") + .service("service") // serviceImpl接口的包 - .serviceImpl("ignore.service.impl") + .serviceImpl("service.impl") // controller接口的包 - .controller("ignore.controller") + .controller("controller") // 构建 .build(); @@ -156,7 +161,7 @@ public class CodeGenerator { .strategy(stConfig) // 整合包名策略 .packageInfo(pkConfig) - // TODO 自定义convert文件 + // TODO 自定义convert文件 request VO // .injection() // TODO 自定义模板以及convert文件 // .template() diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/cache/CacheQuery.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/CacheQuery.java similarity index 73% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/cache/CacheQuery.java rename to orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/CacheQuery.java index c2198c7c..8b13b7a7 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/cache/CacheQuery.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/CacheQuery.java @@ -1,8 +1,9 @@ -package com.orion.ops.framework.mybatis.cache; +package com.orion.ops.framework.mybatis.query; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.orion.lang.define.wrapper.Store; import com.orion.lang.utils.Valid; +import com.orion.ops.framework.mybatis.cache.RowCacheHolder; import java.io.Serializable; @@ -23,6 +24,8 @@ public class CacheQuery { private Serializable id; + private boolean force; + private CacheQuery(BaseMapper dao, Serializable id) { this.dao = dao; this.id = id; @@ -50,6 +53,16 @@ public class CacheQuery { return this; } + /** + * 强制查询 + * + * @return this + */ + public CacheQuery force() { + this.force = true; + return this; + } + @SuppressWarnings("unchecked") public R get(Class c) { T row = this.get(); @@ -60,11 +73,14 @@ public class CacheQuery { @SuppressWarnings("unchecked") public T get() { Class> mapperClass = (Class>) dao.getClass(); - // 从缓存中获取 - Store store = RowCacheHolder.get(mapperClass, id); - // 设置过缓存 - if (store != null) { - return store.get(); + // 不查询缓存 + if (!force) { + // 从缓存中获取 + Store store = RowCacheHolder.get(mapperClass, id); + // 设置过缓存 + if (store != null) { + return store.get(); + } } // 查询 T row = dao.selectById(id); diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/Conditions.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/Conditions.java index b3a287c6..6d16d28d 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/Conditions.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/Conditions.java @@ -20,8 +20,18 @@ public class Conditions { * @param T * @return wrapper */ - public static LambdaQueryWrapper validateWrapper() { + public static LambdaQueryWrapper wrapper() { return new ValidateLambdaWrapper<>(); } + /** + * 条件有效性验证 wrapper + * + * @param T + * @return wrapper + */ + public static LambdaQueryWrapper wrapper(Class clazz) { + return new ValidateLambdaWrapper<>(clazz); + } + } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/ValidateLambdaWrapper.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/ValidateLambdaWrapper.java index b6080558..d49544af 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/ValidateLambdaWrapper.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/query/ValidateLambdaWrapper.java @@ -17,6 +17,17 @@ import java.util.Collection; */ public class ValidateLambdaWrapper extends LambdaQueryWrapper { + public ValidateLambdaWrapper() { + } + + public ValidateLambdaWrapper(T entity) { + super(entity); + } + + public ValidateLambdaWrapper(Class entityClass) { + super(entityClass); + } + /** * 有效性验证 *