diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/board/PlanTypeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/board/PlanTypeController.java new file mode 100644 index 00000000..4b9ff556 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/board/PlanTypeController.java @@ -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 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 list = planTypeService.list(); + ExcelUtil util = new ExcelUtil(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 ids) { + return toAjax(planTypeService.removeByIds(ids)); + } + + + /** + * 获取类型树列表 + */ + @PreAuthorize("@ss.hasPermi('plan:type:list')") + @GetMapping("/planTree") + public AjaxResult deptTree(PlanType planType) { + return success(planTypeService.listPlanTree(planType)); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/board/domain/PlanType.java b/ruoyi-system/src/main/java/com/ruoyi/board/domain/PlanType.java new file mode 100644 index 00000000..599fffa2 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/board/domain/PlanType.java @@ -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 children = new ArrayList<>(); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/board/mapper/PlanTypeMapper.java b/ruoyi-system/src/main/java/com/ruoyi/board/mapper/PlanTypeMapper.java new file mode 100644 index 00000000..3e752389 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/board/mapper/PlanTypeMapper.java @@ -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 { +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/board/service/IPlanTypeService.java b/ruoyi-system/src/main/java/com/ruoyi/board/service/IPlanTypeService.java new file mode 100644 index 00000000..17027aa2 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/board/service/IPlanTypeService.java @@ -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{ + + List listPlanTree(PlanType planType); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/board/service/impl/PlanTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/board/service/impl/PlanTypeServiceImpl.java new file mode 100644 index 00000000..ded9c1f9 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/board/service/impl/PlanTypeServiceImpl.java @@ -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 implements IPlanTypeService { + + private static final Logger log = LoggerFactory.getLogger(PlanTypeServiceImpl.class); + + @Override + public List listPlanTree(PlanType planType) { + List list = list(); + List planTypes = buildPlanTree(list); + return planTypes.stream().map(this::buildTreeSelect).collect(Collectors.toList()); + } + + private TreeSelect buildTreeSelect(PlanType planType){ + List 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 buildPlanTree(List list) { + List returnList = new ArrayList<>(); + List 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 list, PlanType t) + { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (PlanType tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, PlanType t) + { + List 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 list, PlanType t) + { + return !getChildList(list, t).isEmpty(); + } +} diff --git a/ruoyi-system/src/main/resources/mapper/board/PlanTypeMapper.xml b/ruoyi-system/src/main/resources/mapper/board/PlanTypeMapper.xml new file mode 100644 index 00000000..efab543a --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/board/PlanTypeMapper.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file