Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -1,7 +1,15 @@
|
|||||||
package com.czg.config;
|
package com.czg.config;
|
||||||
|
|
||||||
import com.mybatisflex.core.audit.AuditManager;
|
import com.mybatisflex.core.audit.AuditManager;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,4 +29,50 @@ public class MybatisFlexConfig {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理 Spring 容器管理的 Page Bean
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public BeanPostProcessor pageBeanPostProcessor() {
|
||||||
|
return new BeanPostProcessor() {
|
||||||
|
@Override
|
||||||
|
public Object postProcessAfterInitialization(@NotNull Object bean, @NotNull String beanName) throws BeansException {
|
||||||
|
if (bean instanceof Page<?> page) {
|
||||||
|
resetPageDefaultValue(page);
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AOP 拦截所有 Page 实例的构造方法,重置初始值
|
||||||
|
* 覆盖手动 new Page() 的场景
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
public static class PageConstructorAspect {
|
||||||
|
|
||||||
|
// 切入点:匹配 Page 类的所有构造方法执行后
|
||||||
|
@Pointcut("execution(com.mybatisflex.core.pagination.Page+.new(..))")
|
||||||
|
public void pageConstructorPointcut() {}
|
||||||
|
|
||||||
|
// 构造方法执行后重置值
|
||||||
|
@AfterReturning(pointcut = "pageConstructorPointcut()", returning = "page")
|
||||||
|
public void afterPageConstruct(Page<?> page) {
|
||||||
|
resetPageDefaultValue(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用方法:重置 Page 初始值为 0
|
||||||
|
*/
|
||||||
|
private static void resetPageDefaultValue(Page<?> page) {
|
||||||
|
if (page.getTotalPage() == -1) {
|
||||||
|
page.setTotalPage(0);
|
||||||
|
}
|
||||||
|
if (page.getTotalRow() == -1) {
|
||||||
|
page.setTotalRow(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,7 @@
|
|||||||
left join tb_shop_info s on o.shop_id = s.id
|
left join tb_shop_info s on o.shop_id = s.id
|
||||||
left join pp_package p on o.package_id = p.id
|
left join pp_package p on o.package_id = p.id
|
||||||
left join tb_user_info u on o.user_id = u.id
|
left join tb_user_info u on o.user_id = u.id
|
||||||
where 1=1
|
where o.shop_id = #{shopId}
|
||||||
<if test="shopId != null">
|
|
||||||
and o.shop_id = #{shopId}
|
|
||||||
</if>
|
|
||||||
<choose>
|
<choose>
|
||||||
<!-- userId为空时:拼接 and o.status != 'ing' -->
|
<!-- userId为空时:拼接 and o.status != 'ing' -->
|
||||||
<when test="userId == null or userId == ''">
|
<when test="userId == null or userId == ''">
|
||||||
|
|||||||
Reference in New Issue
Block a user