Jay
2024-10-15 1205f84f732610763d46935c0ec31757005376f4
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/FileMenuController.java
@@ -1,6 +1,8 @@
package com.iailab.module.model.mpk.controller.admin;
import com.iailab.framework.common.dto.TreeLabelDTO;
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.module.model.mpk.dto.FileMenuDTO;
import com.iailab.module.model.mpk.entity.FileMenuEntity;
import com.iailab.module.model.mpk.service.FileMenuService;
@@ -10,6 +12,7 @@
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import static com.iailab.framework.common.pojo.CommonResult.success;
@@ -34,13 +37,41 @@
        return success(list);
    }
    @GetMapping("/get")
    @Operation(summary = "获取详情")
    public CommonResult<FileMenuDTO> get(@RequestParam("id") String id) {
        FileMenuEntity data = fileMenuService.get(id);
        return success(ConvertUtils.sourceToTarget(data, FileMenuDTO.class));
    }
    @GetMapping("/tree")
    public CommonResult<List<TreeLabelDTO>> tree() {
        List<TreeLabelDTO> data = new ArrayList<>();
        List<FileMenuDTO> list = fileMenuService.list();
        list.forEach(menu -> {
            TreeLabelDTO tree0 = new TreeLabelDTO();
            tree0.setValue(menu.getName());
            tree0.setLabel(menu.getName());
            List<TreeLabelDTO> groups = new ArrayList<>();
            menu.getGroups().forEach(group -> {
                TreeLabelDTO tree1 = new TreeLabelDTO();
                tree1.setValue(group.getName());
                tree1.setLabel(group.getName());
                groups.add(tree1);
            });
            tree0.setChildren(groups);
            data.add(tree0);
        });
        return success(ConvertUtils.sourceToTarget(data, TreeLabelDTO.class));
    }
    @PostMapping("/create")
    public CommonResult<Boolean> create(@Valid @RequestBody FileMenuEntity entity) {
        fileMenuService.create(entity);
        return success(true);
    }
    @PostMapping("/update")
    @PutMapping("/update")
    public CommonResult<Boolean> update(@Valid @RequestBody FileMenuEntity entity) {
        fileMenuService.update(entity);
        return success(true);