feat(添加计划类型相关表内容):

This commit is contained in:
fuhao 2024-09-03 15:03:51 +08:00
parent 0e2c1386bb
commit 47351f643c
No known key found for this signature in database
6 changed files with 258 additions and 0 deletions

View File

@ -0,0 +1,99 @@
package com.ruoyi.web.controller.board;
import com.ruoyi.board.domain.PlanType;
import com.ruoyi.board.service.IPlanTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 计划发布中的类型Controller
*
* @author fuhao
* @date 2024-09-02
*/
@RestController
@RequestMapping("/plan/type")
public class PlanTypeController extends BaseController {
@Autowired
private IPlanTypeService planTypeService;
/**
* 查询计划发布中的类型列表
*/
@PreAuthorize("@ss.hasPermi('plan:type:list')")
@GetMapping("/list")
public AjaxResult list(PlanType planType) {
List<PlanType> list = planTypeService.list();
return success(list);
}
/**
* 导出计划发布中的类型列表
*/
@PreAuthorize("@ss.hasPermi('plan:type:export')")
@Log(title = "计划发布中的类型", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, PlanType planType) {
List<PlanType> list = planTypeService.list();
ExcelUtil<PlanType> util = new ExcelUtil<PlanType>(PlanType.class);
util.exportExcel(response, list, "计划发布中的类型数据");
}
/**
* 获取计划发布中的类型详细信息
*/
@PreAuthorize("@ss.hasPermi('plan:type:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(planTypeService.getById(id));
}
/**
* 新增计划发布中的类型
*/
@PreAuthorize("@ss.hasPermi('plan:type:add')")
@Log(title = "计划发布中的类型", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody PlanType planType) {
return toAjax(planTypeService.save(planType));
}
/**
* 修改计划发布中的类型
*/
@PreAuthorize("@ss.hasPermi('plan:type:edit')")
@Log(title = "计划发布中的类型", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody PlanType planType) {
return toAjax(planTypeService.saveOrUpdate(planType));
}
/**
* 删除计划发布中的类型
*/
@PreAuthorize("@ss.hasPermi('plan:type:remove')")
@Log(title = "计划发布中的类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable List<Integer> ids) {
return toAjax(planTypeService.removeByIds(ids));
}
/**
* 获取类型树列表
*/
@PreAuthorize("@ss.hasPermi('plan:type:list')")
@GetMapping("/planTree")
public AjaxResult deptTree(PlanType planType) {
return success(planTypeService.listPlanTree(planType));
}
}

View File

@ -0,0 +1,40 @@
package com.ruoyi.board.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 计划发布中的类型对象 pub_plan_type
*
* @author fuhao
* @date 2024-09-02
*/
@Data
@TableName(value = "pub_plan_type")
public class PlanType implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 唯一标识
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/** 类型名称 */
@TableField(value = "type_name")
private String typeName;
/** 类型父级id */
@TableField(value = "parent_id")
private Long parentId;
@TableField(select = false)
private List<PlanType> children = new ArrayList<>();
}

View File

@ -0,0 +1,7 @@
package com.ruoyi.board.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.ruoyi.board.domain.PlanType;
public interface PlanTypeMapper extends MPJBaseMapper<PlanType> {
}

View File

@ -0,0 +1,12 @@
package com.ruoyi.board.service;
import com.github.yulichang.base.MPJBaseService;
import com.ruoyi.board.domain.PlanType;
import com.ruoyi.common.core.domain.TreeSelect;
import java.util.List;
public interface IPlanTypeService extends MPJBaseService<PlanType>{
List<TreeSelect> listPlanTree(PlanType planType);
}

View File

@ -0,0 +1,96 @@
package com.ruoyi.board.service.impl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.ruoyi.board.domain.PlanType;
import com.ruoyi.board.mapper.PlanTypeMapper;
import com.ruoyi.board.service.IPlanTypeService;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class PlanTypeServiceImpl extends MPJBaseServiceImpl<PlanTypeMapper, PlanType> implements IPlanTypeService {
private static final Logger log = LoggerFactory.getLogger(PlanTypeServiceImpl.class);
@Override
public List<TreeSelect> listPlanTree(PlanType planType) {
List<PlanType> list = list();
List<PlanType> planTypes = buildPlanTree(list);
return planTypes.stream().map(this::buildTreeSelect).collect(Collectors.toList());
}
private TreeSelect buildTreeSelect(PlanType planType){
List<TreeSelect> childTreeSelectList = planType.getChildren().stream().map(this::buildTreeSelect).collect(Collectors.toList());
TreeSelect treeSelect = new TreeSelect();
treeSelect.setId(planType.getId());
treeSelect.setLabel(planType.getTypeName());
treeSelect.setChildren(childTreeSelectList);
return treeSelect;
};
private List<PlanType> buildPlanTree(List<PlanType> list) {
List<PlanType> returnList = new ArrayList<>();
List<Long> tempList = list.stream().map(PlanType::getId).collect(Collectors.toList());
for (PlanType planType : list)
{
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(planType.getParentId()))
{
recursionFn(list, planType);
returnList.add(planType);
}
}
if (returnList.isEmpty())
{
returnList = list;
}
return returnList;
}
/**
* 递归列表
*/
private void recursionFn(List<PlanType> list, PlanType t)
{
// 得到子节点列表
List<PlanType> childList = getChildList(list, t);
t.setChildren(childList);
for (PlanType tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<PlanType> getChildList(List<PlanType> list, PlanType t)
{
List<PlanType> tlist = new ArrayList<>();
for (PlanType n : list) {
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) {
tlist.add(n);
}
}
return tlist;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<PlanType> list, PlanType t)
{
return !getChildList(list, t).isEmpty();
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.board.mapper.PlanTypeMapper">
</mapper>