zhou zhou
14 小时以前 eb49fb9a98d6dd4e4361daf4eac4f9313236b8e8
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.vincent.rsf.server.ai.controller;
 
import com.vincent.rsf.framework.common.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.server.ai.dto.AiMcpToolTestRequest;
import com.vincent.rsf.server.ai.entity.AiMcpMount;
import com.vincent.rsf.server.ai.service.AiMcpMountService;
import com.vincent.rsf.server.common.annotation.OperationLog;
import com.vincent.rsf.server.common.domain.BaseParam;
import com.vincent.rsf.server.common.domain.PageParam;
import com.vincent.rsf.server.common.utils.ExcelUtil;
import com.vincent.rsf.server.system.controller.BaseController;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
 
@RestController
public class AiMcpMountController extends BaseController {
 
    @Autowired
    private AiMcpMountService aiMcpMountService;
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:list')")
    @PostMapping("/aiMcpMount/page")
    public R page(@RequestBody Map<String, Object> map) {
        BaseParam baseParam = buildParam(map, BaseParam.class);
        PageParam<AiMcpMount, BaseParam> pageParam = new PageParam<>(baseParam, AiMcpMount.class);
        return R.ok().add(aiMcpMountService.page(pageParam, pageParam.buildWrapper(true)
                .eq("tenant_id", getTenantId())
                .eq("deleted", 0)));
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:list')")
    @PostMapping("/aiMcpMount/list")
    public R list(@RequestBody Map<String, Object> map) {
        return R.ok().add(aiMcpMountService.list(new LambdaQueryWrapper<AiMcpMount>()
                .eq(AiMcpMount::getTenantId, getTenantId())
                .eq(AiMcpMount::getDeleted, 0)
                .orderByAsc(AiMcpMount::getSort)
                .orderByDesc(AiMcpMount::getId)));
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:list')")
    @PostMapping({"/aiMcpMount/many/{ids}", "/aiMcpMounts/many/{ids}"})
    public R many(@PathVariable Long[] ids) {
        return R.ok().add(aiMcpMountService.list(new LambdaQueryWrapper<AiMcpMount>()
                .eq(AiMcpMount::getTenantId, getTenantId())
                .eq(AiMcpMount::getDeleted, 0)
                .in(AiMcpMount::getId, Arrays.asList(ids))));
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:list')")
    @GetMapping("/aiMcpMount/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok().add(aiMcpMountService.getOne(new LambdaQueryWrapper<AiMcpMount>()
                .eq(AiMcpMount::getId, id)
                .eq(AiMcpMount::getTenantId, getTenantId())
                .eq(AiMcpMount::getDeleted, 0)
                .last("limit 1")));
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:list')")
    @GetMapping("/aiMcpMount/{id}/tools")
    public R previewTools(@PathVariable("id") Long id) {
        return R.ok().add(aiMcpMountService.previewTools(id, getLoginUserId(), getTenantId()));
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:update')")
    @PostMapping("/aiMcpMount/{id}/tool/test")
    public R testTool(@PathVariable("id") Long id, @RequestBody AiMcpToolTestRequest request) {
        return R.ok().add(aiMcpMountService.testTool(id, getLoginUserId(), getTenantId(), request));
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:save')")
    @OperationLog("Create AiMcpMount")
    @PostMapping("/aiMcpMount/save")
    public R save(@RequestBody AiMcpMount aiMcpMount) {
        aiMcpMount.setTenantId(getTenantId());
        aiMcpMountService.validateBeforeSave(aiMcpMount, getTenantId());
        aiMcpMount.setCreateBy(getLoginUserId());
        aiMcpMount.setCreateTime(new Date());
        aiMcpMount.setUpdateBy(getLoginUserId());
        aiMcpMount.setUpdateTime(new Date());
        if (!aiMcpMountService.save(aiMcpMount)) {
            return R.error("Save Fail");
        }
        return R.ok("Save Success").add(aiMcpMount);
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:update')")
    @OperationLog("Update AiMcpMount")
    @PostMapping("/aiMcpMount/update")
    public R update(@RequestBody AiMcpMount aiMcpMount) {
        aiMcpMount.setTenantId(getTenantId());
        aiMcpMountService.validateBeforeUpdate(aiMcpMount, getTenantId());
        aiMcpMount.setUpdateBy(getLoginUserId());
        aiMcpMount.setUpdateTime(new Date());
        if (!aiMcpMountService.updateById(aiMcpMount)) {
            return R.error("Update Fail");
        }
        return R.ok("Update Success").add(aiMcpMount);
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:remove')")
    @OperationLog("Delete AiMcpMount")
    @PostMapping("/aiMcpMount/remove/{ids}")
    public R remove(@PathVariable Long[] ids) {
        if (!aiMcpMountService.removeByIds(Arrays.asList(ids))) {
            return R.error("Delete Fail");
        }
        return R.ok("Delete Success").add(ids);
    }
 
    @PreAuthorize("hasAuthority('system:aiMcpMount:list')")
    @PostMapping("/aiMcpMount/export")
    public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
        ExcelUtil.build(ExcelUtil.create(aiMcpMountService.list(new LambdaQueryWrapper<AiMcpMount>()
                .eq(AiMcpMount::getTenantId, getTenantId())
                .eq(AiMcpMount::getDeleted, 0)
                .orderByAsc(AiMcpMount::getSort)
                .orderByDesc(AiMcpMount::getId)), AiMcpMount.class), response);
    }
}