[重大更新] 增加mybatis-plus扩展工具 大幅简化整体业务代码写法 优雅舒适
This commit is contained in:
+9
-6
@@ -8,7 +8,6 @@ import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -66,9 +65,10 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
*/
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
||||
return genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
|
||||
return genTableColumnMapper.lambda()
|
||||
.eq(GenTableColumn::getTableId, tableId)
|
||||
.orderByAsc(GenTableColumn::getSort));
|
||||
.orderByAsc(GenTableColumn::getSort)
|
||||
.list();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +246,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
public void deleteGenTableByIds(Long[] tableIds) {
|
||||
List<Long> ids = Arrays.asList(tableIds);
|
||||
baseMapper.deleteByIds(ids);
|
||||
genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, ids));
|
||||
genTableColumnMapper.lambda()
|
||||
.in(GenTableColumn::getTableId, ids)
|
||||
.deleteCount();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -551,10 +553,11 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
return tables;
|
||||
}
|
||||
List<Long> tableIds = StreamUtils.toList(tables, GenTable::getTableId);
|
||||
List<GenTableColumn> columns = genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
|
||||
List<GenTableColumn> columns = genTableColumnMapper.lambda()
|
||||
.in(GenTableColumn::getTableId, tableIds)
|
||||
.orderByAsc(GenTableColumn::getTableId)
|
||||
.orderByAsc(GenTableColumn::getSort));
|
||||
.orderByAsc(GenTableColumn::getSort)
|
||||
.list();
|
||||
Map<Long, List<GenTableColumn>> columnMap = StreamUtils.groupByKey(columns, GenTableColumn::getTableId);
|
||||
tables.forEach(table -> table.setColumns(columnMap.getOrDefault(table.getTableId(), new ArrayList<>())));
|
||||
return tables;
|
||||
|
||||
@@ -8,11 +8,11 @@ import org.dromara.common.core.domain.PageResult;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
#end
|
||||
#if($enableStatus || $enableSort)
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
#end
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
#if($enableUnique)
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
#end
|
||||
import org.dromara.common.mybatis.core.query.QueryBuilder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -134,7 +134,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
#if($hasBetween)
|
||||
Map<String, Object> params = bo.getParams();
|
||||
#end
|
||||
LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery();
|
||||
return QueryBuilder.lambda(${ClassName}.class)
|
||||
#foreach($column in $columns)
|
||||
#if($column.query)
|
||||
#set($queryType=$column.queryType)
|
||||
@@ -144,29 +144,47 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
#if($queryType != 'BETWEEN')
|
||||
#if($javaType == 'String')
|
||||
#set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())')
|
||||
#if($queryType == 'LIKE')
|
||||
.likeIfText(${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#elseif($queryType == 'EQ')
|
||||
.eqIfText(${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#elseif($queryType == 'NE')
|
||||
.neIfText(${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#else
|
||||
.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#end
|
||||
#else
|
||||
#set($condition='bo.get'+$AttrName+'() != null')
|
||||
#end
|
||||
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName());
|
||||
#if($queryType == 'EQ')
|
||||
.eqIfPresent(${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#elseif($queryType == 'NE')
|
||||
.neIfPresent(${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#elseif($queryType == 'GT')
|
||||
.gtIfPresent(${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#elseif($queryType == 'LT')
|
||||
.ltIfPresent(${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#else
|
||||
lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null,
|
||||
${ClassName}::get$AttrName, params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||
.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName())
|
||||
#end
|
||||
#end
|
||||
#else
|
||||
.betweenParams(${ClassName}::get$AttrName, params, "begin$AttrName", "end$AttrName")
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($table.tree && "" != $treeAncestorsField)
|
||||
lqw.orderByAsc(${ClassName}::get${TreeAncestorsCap});
|
||||
.orderByAsc(${ClassName}::get${TreeAncestorsCap})
|
||||
#end
|
||||
#if($table.tree && "" != $treeParentCode)
|
||||
lqw.orderByAsc(${ClassName}::get${TreeParentCap});
|
||||
.orderByAsc(${ClassName}::get${TreeParentCap})
|
||||
#end
|
||||
#if($table.tree && "" != $treeOrderField)
|
||||
lqw.orderByAsc(${ClassName}::get${TreeOrderCap});
|
||||
.orderByAsc(${ClassName}::get${TreeOrderCap})
|
||||
#elseif($enableSort)
|
||||
lqw.orderByAsc(${ClassName}::get${sortColumn.capJavaField});
|
||||
.orderByAsc(${ClassName}::get${sortColumn.capJavaField})
|
||||
#end
|
||||
lqw.orderByAsc(${ClassName}::get${pkColumn.capJavaField});
|
||||
return lqw;
|
||||
.orderByAsc(${ClassName}::get${pkColumn.capJavaField})
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,9 +233,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateStatus(${pkColumn.javaType} ${pkColumn.javaField}, ${statusColumn.javaType} status) {
|
||||
return baseMapper.update(null, new LambdaUpdateWrapper<${ClassName}>()
|
||||
return baseMapper.lambda()
|
||||
.set(${ClassName}::get${statusColumn.capJavaField}, status)
|
||||
.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField})) > 0;
|
||||
.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField})
|
||||
.update();
|
||||
}
|
||||
#end
|
||||
|
||||
@@ -231,9 +250,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateSort(${pkColumn.javaType} ${pkColumn.javaField}, ${sortColumn.javaType} sortValue) {
|
||||
return baseMapper.update(null, new LambdaUpdateWrapper<${ClassName}>()
|
||||
return baseMapper.lambda()
|
||||
.set(${ClassName}::get${sortColumn.capJavaField}, sortValue)
|
||||
.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField})) > 0;
|
||||
.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField})
|
||||
.update();
|
||||
}
|
||||
#end
|
||||
|
||||
@@ -296,12 +316,14 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
}
|
||||
|
||||
private void updateChildrenAncestors(${pkColumn.javaType} currentId, String newAncestors, String oldAncestors) {
|
||||
List<${ClassName}> children = baseMapper.selectList(new LambdaQueryWrapper<${ClassName}>()
|
||||
.select(${ClassName}::get${pkColumn.capJavaField}, ${ClassName}::get${TreeAncestorsCap}()));
|
||||
List<${ClassName}> children = baseMapper.lambda()
|
||||
.select(${ClassName}::get${pkColumn.capJavaField}, ${ClassName}::get${TreeAncestorsCap})
|
||||
.findInSet(currentId, ${ClassName}::get${TreeAncestorsCap})
|
||||
.list();
|
||||
List<${ClassName}> updateList = new ArrayList<>();
|
||||
for (${ClassName} child : children) {
|
||||
String ancestors = child.get${TreeAncestorsCap}();
|
||||
if (StringUtils.isBlank(ancestors) || !containsAncestor(ancestors, currentId)) {
|
||||
if (StringUtils.isBlank(ancestors)) {
|
||||
continue;
|
||||
}
|
||||
${ClassName} update = new ${ClassName}();
|
||||
|
||||
Reference in New Issue
Block a user