潘志宝
2024-09-30 303715d81f0c1cd8b32cd659b7734c01565369a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
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;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年09月22日
 */
@Tag(name = "模型服务 - 模型文件菜单管理")
@RestController
@RequestMapping("/model/mpk/menu")
public class FileMenuController {
 
    @Autowired
    private FileMenuService fileMenuService;
 
    @GetMapping("/list")
    @Operation(summary = "获得列表")
    public CommonResult<List<FileMenuDTO>> list() {
        List<FileMenuDTO> list = fileMenuService.list();
        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);
    }
 
    @PutMapping("/update")
    public CommonResult<Boolean> update(@Valid @RequestBody FileMenuEntity entity) {
        fileMenuService.update(entity);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    public CommonResult<Boolean> delete(@RequestParam("id") String id) {
        fileMenuService.deleteById(id);
        return success(true);
    }
}