Browse Source

优化字典列表接口

test
smallchill 5 years ago
parent
commit
36ca1888fc
  1. 8
      blade-service/blade-system/src/main/java/org/springblade/system/controller/DictBizController.java
  2. 9
      blade-service/blade-system/src/main/java/org/springblade/system/controller/DictController.java
  3. 20
      blade-service/blade-system/src/main/java/org/springblade/system/service/IDictBizService.java
  4. 19
      blade-service/blade-system/src/main/java/org/springblade/system/service/IDictService.java
  5. 19
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DictBizServiceImpl.java
  6. 18
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DictServiceImpl.java

8
blade-service/blade-system/src/main/java/org/springblade/system/controller/DictBizController.java

@ -19,7 +19,6 @@ package org.springblade.system.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
@ -89,8 +88,7 @@ public class DictBizController extends BladeController {
@ApiOperationSupport(order = 3)
@ApiOperation(value = "列表", notes = "传入dict")
public R<IPage<DictBizVO>> parentList(@ApiIgnore @RequestParam Map<String, Object> dict, Query query) {
IPage<DictBiz> page = dictService.page(Condition.getPage(query), Condition.getQueryWrapper(dict, DictBiz.class).lambda().eq(DictBiz::getParentId, CommonConstant.TOP_PARENT_ID).orderByAsc(DictBiz::getSort));
return R.data(DictBizWrapper.build().pageVO(page));
return R.data(dictService.parentList(dict, query));
}
/**
@ -105,9 +103,7 @@ public class DictBizController extends BladeController {
@ApiOperationSupport(order = 4)
@ApiOperation(value = "列表", notes = "传入dict")
public R<IPage<DictBizVO>> childList(@ApiIgnore @RequestParam Map<String, Object> dict, @RequestParam(required = false, defaultValue = "-1") Long parentId, Query query) {
dict.remove("parentId");
IPage<DictBiz> page = dictService.page(Condition.getPage(query), Condition.getQueryWrapper(dict, DictBiz.class).lambda().eq(DictBiz::getParentId, parentId).orderByAsc(DictBiz::getSort));
return R.data(DictBizWrapper.build().pageVO(page));
return R.data(dictService.childList(dict, parentId, query));
}
/**

9
blade-service/blade-system/src/main/java/org/springblade/system/controller/DictController.java

@ -19,7 +19,6 @@ package org.springblade.system.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
@ -75,7 +74,6 @@ public class DictController extends BladeController {
@ApiOperationSupport(order = 2)
@ApiOperation(value = "列表", notes = "传入dict")
public R<List<INode>> list(@ApiIgnore @RequestParam Map<String, Object> dict) {
@SuppressWarnings("unchecked")
List<Dict> list = dictService.list(Condition.getQueryWrapper(dict, Dict.class).lambda().orderByAsc(Dict::getSort));
DictWrapper dictWrapper = new DictWrapper();
return R.data(dictWrapper.listNodeVO(list));
@ -92,8 +90,7 @@ public class DictController extends BladeController {
@ApiOperationSupport(order = 3)
@ApiOperation(value = "列表", notes = "传入dict")
public R<IPage<DictVO>> parentList(@ApiIgnore @RequestParam Map<String, Object> dict, Query query) {
IPage<Dict> page = dictService.page(Condition.getPage(query), Condition.getQueryWrapper(dict, Dict.class).lambda().eq(Dict::getParentId, CommonConstant.TOP_PARENT_ID).orderByAsc(Dict::getSort));
return R.data(DictWrapper.build().pageVO(page));
return R.data(dictService.parentList(dict, query));
}
/**
@ -108,9 +105,7 @@ public class DictController extends BladeController {
@ApiOperationSupport(order = 4)
@ApiOperation(value = "列表", notes = "传入dict")
public R<IPage<DictVO>> childList(@ApiIgnore @RequestParam Map<String, Object> dict, @RequestParam(required = false, defaultValue = "-1") Long parentId, Query query) {
dict.remove("parentId");
IPage<Dict> page = dictService.page(Condition.getPage(query), Condition.getQueryWrapper(dict, Dict.class).lambda().eq(Dict::getParentId, parentId).orderByAsc(Dict::getSort));
return R.data(DictWrapper.build().pageVO(page));
return R.data(dictService.childList(dict, parentId, query));
}
/**

20
blade-service/blade-system/src/main/java/org/springblade/system/service/IDictBizService.java

@ -17,11 +17,14 @@
package org.springblade.system.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.core.mp.support.Query;
import org.springblade.system.entity.DictBiz;
import org.springblade.system.vo.DictBizVO;
import java.util.List;
import java.util.Map;
/**
* 服务类
@ -77,4 +80,21 @@ public interface IDictBizService extends IService<DictBiz> {
*/
boolean removeDict(String ids);
/**
* 顶级列表
* @param dict
* @param query
* @return
*/
IPage<DictBizVO> parentList(Map<String, Object> dict, Query query);
/**
* 子列表
* @param dict
* @param parentId
* @param query
* @return
*/
IPage<DictBizVO> childList(Map<String, Object> dict, Long parentId, Query query);
}

19
blade-service/blade-system/src/main/java/org/springblade/system/service/IDictService.java

@ -18,10 +18,12 @@ package org.springblade.system.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.core.mp.support.Query;
import org.springblade.system.entity.Dict;
import org.springblade.system.vo.DictVO;
import java.util.List;
import java.util.Map;
/**
* 服务类
@ -85,4 +87,21 @@ public interface IDictService extends IService<Dict> {
*/
boolean removeDict(String ids);
/**
* 顶级列表
* @param dict
* @param query
* @return
*/
IPage<DictVO> parentList(Map<String, Object> dict, Query query);
/**
* 子列表
* @param dict
* @param parentId
* @param query
* @return
*/
IPage<DictVO> childList(Map<String, Object> dict, Long parentId, Query query);
}

19
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DictBizServiceImpl.java

@ -17,9 +17,13 @@
package org.springblade.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.exceptions.ApiException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.utils.Func;
@ -28,10 +32,12 @@ import org.springblade.system.entity.DictBiz;
import org.springblade.system.mapper.DictBizMapper;
import org.springblade.system.service.IDictBizService;
import org.springblade.system.vo.DictBizVO;
import org.springblade.system.wrapper.DictBizWrapper;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import static org.springblade.core.cache.constant.CacheConstant.DICT_CACHE;
@ -86,4 +92,17 @@ public class DictBizServiceImpl extends ServiceImpl<DictBizMapper, DictBiz> impl
}
return removeByIds(Func.toLongList(ids));
}
@Override
public IPage<DictBizVO> parentList(Map<String, Object> dict, Query query) {
IPage<DictBiz> page = this.page(Condition.getPage(query), Condition.getQueryWrapper(dict, DictBiz.class).lambda().eq(DictBiz::getParentId, CommonConstant.TOP_PARENT_ID).orderByAsc(DictBiz::getSort));
return DictBizWrapper.build().pageVO(page);
}
@Override
public IPage<DictBizVO> childList(Map<String, Object> dict, Long parentId, Query query) {
dict.remove("parentId");
IPage<DictBiz> page = this.page(Condition.getPage(query), Condition.getQueryWrapper(dict, DictBiz.class).lambda().eq(DictBiz::getParentId, parentId).orderByAsc(DictBiz::getSort));
return DictBizWrapper.build().pageVO(page);
}
}

18
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DictServiceImpl.java

@ -21,6 +21,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.exceptions.ApiException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.utils.Func;
@ -29,10 +32,12 @@ import org.springblade.system.entity.Dict;
import org.springblade.system.mapper.DictMapper;
import org.springblade.system.service.IDictService;
import org.springblade.system.vo.DictVO;
import org.springblade.system.wrapper.DictWrapper;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import static org.springblade.core.cache.constant.CacheConstant.DICT_CACHE;
@ -93,4 +98,17 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements ID
}
return removeByIds(Func.toLongList(ids));
}
@Override
public IPage<DictVO> parentList(Map<String, Object> dict, Query query) {
IPage<Dict> page = this.page(Condition.getPage(query), Condition.getQueryWrapper(dict, Dict.class).lambda().eq(Dict::getParentId, CommonConstant.TOP_PARENT_ID).orderByAsc(Dict::getSort));
return DictWrapper.build().pageVO(page);
}
@Override
public IPage<DictVO> childList(Map<String, Object> dict, Long parentId, Query query) {
dict.remove("parentId");
IPage<Dict> page = this.page(Condition.getPage(query), Condition.getQueryWrapper(dict, Dict.class).lambda().eq(Dict::getParentId, parentId).orderByAsc(Dict::getSort));
return DictWrapper.build().pageVO(page);
}
}

Loading…
Cancel
Save