|
@@ -2,6 +2,9 @@ package com.coffee.common.crud;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.db.sql.Direction;
|
|
|
|
|
+import cn.hutool.db.sql.Order;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
@@ -199,6 +202,10 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
public Page<E> list(QueryParamEntity<E> param) {
|
|
public Page<E> list(QueryParamEntity<E> param) {
|
|
|
//是否为分页查询
|
|
//是否为分页查询
|
|
|
if(ObjectUtil.isNotNull(param.getPage())){
|
|
if(ObjectUtil.isNotNull(param.getPage())){
|
|
|
|
|
+ param.getPage().setSearchCount(false);
|
|
|
|
|
+ QueryWrapper<E> wrapper = build(param);
|
|
|
|
|
+ Page<E> page = this.page(param.getPage(),wrapper);
|
|
|
|
|
+ page.setTotal(this.count(wrapper));
|
|
|
return this.page(param.getPage(),build(param));
|
|
return this.page(param.getPage(),build(param));
|
|
|
}else {
|
|
}else {
|
|
|
try {
|
|
try {
|
|
@@ -225,12 +232,28 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
QueryWrapper<E> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<E> queryWrapper = new QueryWrapper<>();
|
|
|
Set<String> includes = param.getIncludes();
|
|
Set<String> includes = param.getIncludes();
|
|
|
Set<Term> wheres = param.getWheres();
|
|
Set<Term> wheres = param.getWheres();
|
|
|
|
|
+ Set<Order> orders = param.getOrders();
|
|
|
if(CollectionUtil.isNotEmpty(includes)){
|
|
if(CollectionUtil.isNotEmpty(includes)){
|
|
|
queryWrapper.select(includes.toArray(new String[includes.size()+1]));
|
|
queryWrapper.select(includes.toArray(new String[includes.size()+1]));
|
|
|
}
|
|
}
|
|
|
if (CollectionUtil.isNotEmpty(wheres)) {
|
|
if (CollectionUtil.isNotEmpty(wheres)) {
|
|
|
wheres.forEach(term -> term.getType().build(queryWrapper,term));
|
|
wheres.forEach(term -> term.getType().build(queryWrapper,term));
|
|
|
}
|
|
}
|
|
|
|
|
+ if(CollectionUtil.isNotEmpty(orders)){
|
|
|
|
|
+ orders.forEach(order -> {
|
|
|
|
|
+ String field = order.getField();
|
|
|
|
|
+ String column = StrUtil.toUnderlineCase(field).toLowerCase();
|
|
|
|
|
+ Direction direction = order.getDirection();
|
|
|
|
|
+ if(Direction.ASC==direction){
|
|
|
|
|
+ queryWrapper.orderByAsc(column);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ queryWrapper.orderByDesc(column);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }else {
|
|
|
|
|
+ queryWrapper.orderByDesc("id");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return queryWrapper;
|
|
return queryWrapper;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -271,7 +294,7 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
* @Param [entity]
|
|
* @Param [entity]
|
|
|
* @return void
|
|
* @return void
|
|
|
**/
|
|
**/
|
|
|
- public abstract void validateBeforeUpdate(E entity) ;
|
|
|
|
|
|
|
+ public abstract void validateBeforeUpdate(E entity) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|