Commit 997d98bb authored by fangxinjiang's avatar fangxinjiang

字典删除调整

parent 02c3f3d8
......@@ -151,4 +151,13 @@ public interface ErrorCodes {
* 已存在对应值的字典项
*/
String SYS_DICT_ITEM_ADD_VALUE_EXIST = "sys.dict.item.add.value.exist";
/**
* 存在下级字典,禁止删除
*/
String SYS_DICT_DELETE_EXIST_CHILD = "sys.dict.delete.exist.child";
/**
* 存在下级字典项值,禁止删除
*/
String SYS_DICT_ITEM_DELETE_EXIST_CHILD = "sys.dict.item.delete.exist.child";
}
......@@ -30,6 +30,8 @@ sys.dict.update.system=\u7CFB\u7EDF\u5185\u7F6E\u5B57\u5178\u9879\u76EE\u4E0D\u8
sys.dict.delete.existing=\u5B57\u5178\u5B58\u5728\u4E0B\u7EA7\u8282\u70B9\u4E0D\u80FD\u5220\u9664
sys.dict.add.type.exist=\u5DF2\u5B58\u5728\u5BF9\u5E94\u7F16\u7801\u7684\u5B57\u5178
sys.dict.item.add.value.exist=\u5DF2\u5B58\u5728\u5BF9\u5E94\u503C\u7684\u5B57\u5178\u9879
sys.dict.delete.exist.child=\u5B58\u5728\u4E0B\u7EA7\u5B57\u5178\uFF0C\u7981\u6B62\u5220\u9664
sys.dict.item.delete.exist.child=\u5B58\u5728\u4E0B\u7EA7\u5B57\u5178\u9879\u503C\uFF0C\u7981\u6B62\u5220\u9664
sys.role.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u89D2\u8272\u4E0D\u80FD\u5220\u9664
sys.role.update.system=\u7CFB\u7EDF\u5185\u7F6E\u89D2\u8272\u4E0D\u80FD\u4FEE\u6539
......
......@@ -124,6 +124,16 @@ public class DictController {
@DeleteMapping("/{id:\\d+}")
@PreAuthorize("@pms.hasPermission('sys_dict_del')")
public R removeById(@PathVariable Long id) {
SysDict sysDict = sysDictService.getById(id);
if (Common.isNotNull(sysDict)){
SysDict dict = sysDictService.getOne(Wrappers.<SysDict>query().lambda()
.eq(SysDict::getParentItemType,sysDict.getType())
.eq(SysDict::getDelFlag,CommonConstants.ZERO_STRING)
.last(CommonConstants.LAST_ONE_SQL));
if (Common.isNotNull(dict)){
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_DICT_DELETE_EXIST_CHILD));
}
}
sysDictService.removeDict(id);
return R.ok();
}
......@@ -157,7 +167,7 @@ public class DictController {
*/
@GetMapping("/item/page")
public R<IPage<SysDictItem>> getSysDictItemPage(Page page, SysDictItem sysDictItem) {
return R.ok(sysDictItemService.page(page, Wrappers.query(sysDictItem)));
return R.ok(sysDictItemService.pageItem(page, sysDictItem));
}
/**
......@@ -242,6 +252,13 @@ public class DictController {
@SysLog("删除字典项")
@DeleteMapping("/item/{id:\\d+}")
public R removeDictItemById(@PathVariable Long id) {
SysDictItem item = sysDictItemService.getOne(Wrappers.<SysDictItem>query().lambda()
.eq(SysDictItem::getParentId,id)
.eq(SysDictItem::getDelFlag,CommonConstants.ZERO_STRING)
.last(CommonConstants.LAST_ONE_SQL));
if (Common.isNotNull(item)){
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_DICT_ITEM_DELETE_EXIST_CHILD));
}
return R.ok(sysDictItemService.removeDictItem(id));
}
......
......@@ -16,6 +16,8 @@
package com.yifu.cloud.plus.v1.yifu.admin.service;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDictItem;
......@@ -50,4 +52,6 @@ public interface SysDictItemService extends IService<SysDictItem> {
* @return
*/
List<Tree<Long>> treeMenu(boolean lazy, Long parentId);
IPage<SysDictItem> pageItem(Page page, SysDictItem sysDictItem);
}
......@@ -19,10 +19,15 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.StrUtil;
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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDict;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDictItem;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRole;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDictItemMapper;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysDictItemService;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysDictService;
......@@ -31,6 +36,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.enums.DictTypeEnum;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
......@@ -117,6 +123,25 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi
return TreeUtil.build(collect, parent);
}
@Override
public IPage<SysDictItem> pageItem(Page page, SysDictItem sysDictItem) {
return baseMapper.selectPage(page, buildQueryWrapper(sysDictItem));
}
/**
* 构建查询的 wrapper
* @param sysDictItem 查询条件
* @return LambdaQueryWrapper
*/
private LambdaQueryWrapper buildQueryWrapper(SysDictItem sysDictItem) {
LambdaQueryWrapper<SysDictItem> wrapper = Wrappers.lambdaQuery();
if (StrUtil.isNotBlank(sysDictItem.getType())){
wrapper.likeRight(SysDictItem::getType,sysDictItem.getType());
}
wrapper.orderByAsc(SysDictItem::getSortOrder);
return wrapper;
}
@NotNull
private Function<SysDictItem, TreeNode<Long>> getNodeFunction() {
return sysDictItem -> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment