树形字典
This commit is contained in:
parent
318df402f5
commit
1126edb3c0
@ -1,13 +1,7 @@
|
|||||||
package com.ruoyi.system.controller;
|
package com.ruoyi.system.controller;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -25,39 +19,35 @@ import com.ruoyi.common.enums.BusinessType;
|
|||||||
import com.ruoyi.system.domain.SysTreeDict;
|
import com.ruoyi.system.domain.SysTreeDict;
|
||||||
import com.ruoyi.system.service.ISysTreeDictService;
|
import com.ruoyi.system.service.ISysTreeDictService;
|
||||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 树形字典Controller
|
* 树形字典Controller
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
* @date 2025-02-03
|
* @date 2025-03-05
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/system/dict")
|
@RequestMapping("/system/treeDict")
|
||||||
public class SysTreeDictController extends BaseController
|
public class SysTreeDictController extends BaseController
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysTreeDictService sysTreeDictService;
|
private ISysTreeDictService sysTreeDictService;
|
||||||
@Autowired
|
|
||||||
private SysUnitConvertController sysUnitConvertController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询树形字典列表
|
* 查询树形字典列表
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:dict:list')")
|
@PreAuthorize("@ss.hasPermi('system:treeDict:list')")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(SysTreeDict sysTreeDict)
|
public AjaxResult list(SysTreeDict sysTreeDict)
|
||||||
{
|
{
|
||||||
startPage();
|
|
||||||
List<SysTreeDict> list = sysTreeDictService.selectSysTreeDictList(sysTreeDict);
|
List<SysTreeDict> list = sysTreeDictService.selectSysTreeDictList(sysTreeDict);
|
||||||
return getDataTable(list);
|
return success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出树形字典列表
|
* 导出树形字典列表
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:dict:export')")
|
@PreAuthorize("@ss.hasPermi('system:treeDict:export')")
|
||||||
@Log(title = "树形字典", businessType = BusinessType.EXPORT)
|
@Log(title = "树形字典", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response, SysTreeDict sysTreeDict)
|
public void export(HttpServletResponse response, SysTreeDict sysTreeDict)
|
||||||
@ -67,12 +57,10 @@ public class SysTreeDictController extends BaseController
|
|||||||
util.exportExcel(response, list, "树形字典数据");
|
util.exportExcel(response, list, "树形字典数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取树形字典详细信息
|
* 获取树形字典详细信息
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:dict:query')")
|
@PreAuthorize("@ss.hasPermi('system:treeDict:query')")
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||||
{
|
{
|
||||||
@ -82,7 +70,7 @@ public class SysTreeDictController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 新增树形字典
|
* 新增树形字典
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:dict:add')")
|
@PreAuthorize("@ss.hasPermi('system:treeDict:add')")
|
||||||
@Log(title = "树形字典", businessType = BusinessType.INSERT)
|
@Log(title = "树形字典", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody SysTreeDict sysTreeDict)
|
public AjaxResult add(@RequestBody SysTreeDict sysTreeDict)
|
||||||
@ -93,7 +81,7 @@ public class SysTreeDictController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 修改树形字典
|
* 修改树形字典
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:dict:edit')")
|
@PreAuthorize("@ss.hasPermi('system:treeDict:edit')")
|
||||||
@Log(title = "树形字典", businessType = BusinessType.UPDATE)
|
@Log(title = "树形字典", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody SysTreeDict sysTreeDict)
|
public AjaxResult edit(@RequestBody SysTreeDict sysTreeDict)
|
||||||
@ -104,53 +92,11 @@ public class SysTreeDictController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 删除树形字典
|
* 删除树形字典
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:dict:remove')")
|
@PreAuthorize("@ss.hasPermi('system:treeDict:remove')")
|
||||||
@Log(title = "树形字典", businessType = BusinessType.DELETE)
|
@Log(title = "树形字典", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public AjaxResult remove(@PathVariable Long[] ids)
|
public AjaxResult remove(@PathVariable Long[] ids)
|
||||||
{
|
{
|
||||||
return toAjax(sysTreeDictService.deleteSysTreeDictByIds(ids));
|
return toAjax(sysTreeDictService.deleteSysTreeDictByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
//生成树形菜单的形式
|
|
||||||
|
|
||||||
@PreAuthorize("@ss.hasPermi('system:dict:remove')")
|
|
||||||
@Log(title = "树形字典", businessType = BusinessType.DELETE)
|
|
||||||
@GetMapping("/getTree")
|
|
||||||
public List<SysTreeDict> buildDictTree(List<SysTreeDict> list) {
|
|
||||||
List<SysTreeDict> returnList = new ArrayList<>();
|
|
||||||
List<Long> tempList = list.stream().map(SysTreeDict::getId).collect(Collectors.toList());
|
|
||||||
for (SysTreeDict dict : list) {
|
|
||||||
if (!tempList.contains(dict.getPid())) {
|
|
||||||
recursionFn(list, dict);
|
|
||||||
returnList.add(dict);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (returnList.isEmpty()) {
|
|
||||||
returnList = list;
|
|
||||||
}
|
|
||||||
return returnList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void recursionFn(List<SysTreeDict> list, SysTreeDict dict) {
|
|
||||||
List<SysTreeDict> childList = getChildList(list, dict);
|
|
||||||
dict.setChildren(childList);
|
|
||||||
for (SysTreeDict child : childList) {
|
|
||||||
if (hasChild(list, child)) {
|
|
||||||
recursionFn(list, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<SysTreeDict> getChildList(List<SysTreeDict> list, SysTreeDict dict) {
|
|
||||||
return list.stream()
|
|
||||||
.filter(d -> d.getPid() != null && d.getPid().equals(dict.getId()))
|
|
||||||
.sorted(Comparator.comparingInt(SysTreeDict::getDictSort))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasChild(List<SysTreeDict> list, SysTreeDict dict) {
|
|
||||||
return list.stream().anyMatch(d -> d.getPid() != null && d.getPid().equals(dict.getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,17 @@
|
|||||||
package com.ruoyi.system.domain;
|
package com.ruoyi.system.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import lombok.Data;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.annotation.Excel;
|
import com.ruoyi.common.annotation.Excel;
|
||||||
import com.ruoyi.common.core.domain.BaseEntity;
|
import com.ruoyi.common.core.domain.TreeEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 树形字典对象 sys_tree_dict
|
* 树形字典对象 sys_tree_dict
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
* @date 2025-02-03
|
* @date 2025-03-05
|
||||||
*/
|
*/
|
||||||
|
public class SysTreeDict extends TreeEntity
|
||||||
@Data
|
|
||||||
@TableName("sys_tree_dict")
|
|
||||||
public class SysTreeDict extends BaseEntity
|
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ -115,15 +106,6 @@ public class SysTreeDict extends BaseEntity
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TableField(exist = false)
|
|
||||||
private List<SysTreeDict> children = new ArrayList<>();
|
|
||||||
|
|
||||||
// 显式补充 children 的 setter 方法
|
|
||||||
public void setChildren(List<SysTreeDict> children) {
|
|
||||||
this.children = children;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
@ -7,7 +7,7 @@ import com.ruoyi.system.domain.SysTreeDict;
|
|||||||
* 树形字典Mapper接口
|
* 树形字典Mapper接口
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
* @date 2025-02-03
|
* @date 2025-03-05
|
||||||
*/
|
*/
|
||||||
public interface SysTreeDictMapper
|
public interface SysTreeDictMapper
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ import com.ruoyi.system.domain.SysTreeDict;
|
|||||||
* 树形字典Service接口
|
* 树形字典Service接口
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
* @date 2025-02-03
|
* @date 2025-03-05
|
||||||
*/
|
*/
|
||||||
public interface ISysTreeDictService
|
public interface ISysTreeDictService
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ import com.ruoyi.system.service.ISysTreeDictService;
|
|||||||
* 树形字典Service业务层处理
|
* 树形字典Service业务层处理
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
* @date 2025-02-03
|
* @date 2025-03-05
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysTreeDictServiceImpl implements ISysTreeDictService
|
public class SysTreeDictServiceImpl implements ISysTreeDictService
|
||||||
|
Loading…
Reference in New Issue
Block a user