review code.

This commit is contained in:
lijiahang
2023-07-04 11:07:13 +08:00
parent f1959946f5
commit 1eeb950cf8
4 changed files with 57 additions and 15 deletions

View File

@@ -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()

View File

@@ -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<T> {
private Serializable id;
private boolean force;
private CacheQuery(BaseMapper<T> dao, Serializable id) {
this.dao = dao;
this.id = id;
@@ -50,6 +53,16 @@ public class CacheQuery<T> {
return this;
}
/**
* 强制查询
*
* @return this
*/
public CacheQuery<T> force() {
this.force = true;
return this;
}
@SuppressWarnings("unchecked")
public <R> R get(Class<R> c) {
T row = this.get();
@@ -60,11 +73,14 @@ public class CacheQuery<T> {
@SuppressWarnings("unchecked")
public T get() {
Class<? extends BaseMapper<T>> mapperClass = (Class<? extends BaseMapper<T>>) dao.getClass();
// 从缓存中获取
Store<T> store = RowCacheHolder.get(mapperClass, id);
// 设置过缓存
if (store != null) {
return store.get();
// 不查询缓存
if (!force) {
// 从缓存中获取
Store<T> store = RowCacheHolder.get(mapperClass, id);
// 设置过缓存
if (store != null) {
return store.get();
}
}
// 查询
T row = dao.selectById(id);

View File

@@ -20,8 +20,18 @@ public class Conditions {
* @param <T> T
* @return wrapper
*/
public static <T> LambdaQueryWrapper<T> validateWrapper() {
public static <T> LambdaQueryWrapper<T> wrapper() {
return new ValidateLambdaWrapper<>();
}
/**
* 条件有效性验证 wrapper
*
* @param <T> T
* @return wrapper
*/
public static <T> LambdaQueryWrapper<T> wrapper(Class<T> clazz) {
return new ValidateLambdaWrapper<>(clazz);
}
}

View File

@@ -17,6 +17,17 @@ import java.util.Collection;
*/
public class ValidateLambdaWrapper<T> extends LambdaQueryWrapper<T> {
public ValidateLambdaWrapper() {
}
public ValidateLambdaWrapper(T entity) {
super(entity);
}
public ValidateLambdaWrapper(Class<T> entityClass) {
super(entityClass);
}
/**
* 有效性验证
*