字典ztree;

字典模块引入系统模块;
pull/3/head
huangyao 2021-01-12 22:50:19 +08:00
parent c7e145d607
commit 8a7dbedb3c
5 changed files with 85 additions and 2 deletions

View File

@ -40,6 +40,14 @@
<version>1.0.0</version>
</dependency>
<!--系统api模块-->
<!--用在业务,系统常量-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>system-api</artifactId>
<version>1.0.0</version>
</dependency>
<!--数据库sdk-->
<!--数据库初始化-->
<dependency>

View File

@ -11,10 +11,12 @@ import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@ -154,4 +156,18 @@ public class DictController {
return new SuccessResponseData(flag);
}
/**
*
*
* @param
* @return
* @author huangyao
* @date 2021/1/10 17:31
*/
@GetResource(name = "获取zTree形式的字典树layui版本", path = "/dict/zTree")
@ResponseBody
public List<ZTreeNode> layuiSelectParentMenuTreeList(@Validated(DictRequest.dictZTree.class) DictRequest dictRequest) {
return this.dictService.dictZTree(dictRequest);
}
}

View File

@ -65,7 +65,7 @@ public class DictRequest extends BaseRequest {
/**
*
*/
@NotBlank(message = "字典类型编码不能为空", groups = {add.class, edit.class, treeList.class})
@NotBlank(message = "字典类型编码不能为空", groups = {add.class, edit.class, treeList.class, dictZTree.class})
private String dictTypeCode;
/**
@ -119,4 +119,11 @@ public class DictRequest extends BaseRequest {
}
/**
* ztree
*/
public @interface dictZTree {
}
}

View File

@ -5,6 +5,7 @@ import cn.stylefeng.roses.kernel.dict.api.DictApi;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.pojo.TreeDictInfo;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -113,4 +114,13 @@ public interface DictService extends IService<SysDict>, DictApi {
*/
List<SysDict> getDictListExcludeSub(Long dictId);
/**
* ztree
*
* @param
* @return
* @author huangyao
* @date 2021/1/12 14:27
*/
List<ZTreeNode> dictZTree(DictRequest dictRequest);
}

View File

@ -21,6 +21,8 @@ import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -153,7 +155,15 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
@Override
public SysDict findDetail(Long dictId) {
return this.baseMapper.findDetail(dictId);
SysDict dict = this.baseMapper.findDetail(dictId);
// 获取父节点字典名称
if (dict.getDictParentId().equals(SystemConstants.DEFAULT_PARENT_ID)) {
dict.setParentName("顶级");
} else {
SysDict parentDict = this.getById(dict.getDictParentId());
dict.setParentName(ObjectUtil.isNotEmpty(parentDict) ? parentDict.getDictName() : "");
}
return dict;
}
@Override
@ -228,6 +238,38 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
return baseMapper.findList(null, new DictRequest());
}
@Override
public List<ZTreeNode> dictZTree(DictRequest dictRequest) {
// 根据字典类型编码获取字典
LambdaQueryWrapper<SysDict> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysDict::getDictTypeCode, dictRequest.getDictTypeCode());
List<SysDict> dictList = this.list(queryWrapper);
// 构建ztree
ArrayList<ZTreeNode> zTreeNodes = new ArrayList<>();
for (SysDict dict : dictList) {
ZTreeNode zTreeNode = new ZTreeNode();
zTreeNode.setId(dict.getDictId());
zTreeNode.setpId(dict.getDictParentId());
zTreeNode.setName(dict.getDictName());
zTreeNode.setOpen(true);
zTreeNodes.add(zTreeNode);
}
// 创建顶级节点
zTreeNodes.add(ZTreeNode.createParent());
// 构建已选中的状态
if (ObjectUtil.isNotEmpty(dictRequest.getDictId())) {
for (ZTreeNode zTreeNode : zTreeNodes) {
if (zTreeNode.getId().equals(dictRequest.getDictId())) {
zTreeNode.setChecked(true);
}
}
}
return zTreeNodes;
}
@Override
public String getDictNameByDictCode(String dictCode) {
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();