AgentController.java 3.54 KB
package vion.controller.monitor;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import vion.dto.monitor.AgentDTO;
import vion.model.monitor.AgentRecord;
import vion.model.monitor.RAgentService;
import vion.model.monitor.ServiceInfo;
import vion.service.monitor.IAgentService;
import vion.vo.monitor.AgentVO;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Agent
 */
@RestController
@RequestMapping("/api/agent")
@RequiredArgsConstructor
public class AgentController {

    private final IAgentService agentService;

    @GetMapping
    @SaCheckPermission(value = "agent:list", orRole = "admin")
    public Page<AgentVO> list(AgentDTO dto) {
        return agentService.list(dto);
    }

    @GetMapping("/{id}")
    @SaCheckPermission(value = "agent:query", orRole = "admin")
    private AgentVO get(@PathVariable Long id) {
        return agentService.getVOById(id);
    }

    @PostMapping("/{id}")
    @SaCheckPermission(value = "agent:edit", orRole = "admin")
    public String update(@PathVariable Long id, @RequestBody AgentDTO dto) {
        dto.setId(id);
        return agentService.update(dto);
    }

    @DeleteMapping("/{id}")
    @SaCheckPermission(value = "agent:remove", orRole = "admin")
    public String remove(@PathVariable Long id) {
        return agentService.removeById(id) ? "删除成功" : "删除失败";
    }

    @PostMapping("/upgrade/{uid}")
    @SaCheckPermission(value = "agent:upgrade", orRole = "admin")
    public String upgradeCommand(@PathVariable String uid, Long upgradeId) {
        return agentService.upgradeCommand(uid, upgradeId);
    }

    @GetMapping("/service/{uid}")
    @SaCheckPermission(value = "agent:service:query", orRole = "admin")
    public List<ServiceInfo> getServicesByUid(@PathVariable String uid) {
        return agentService.getServicesByUid(uid);
    }

    @PostMapping("/service/{uid}")
    @SaCheckPermission(value = "agent:service:save", orRole = "admin")
    public String saveServicesByUid(@PathVariable String uid, @RequestBody List<ServiceInfo> serviceInfoList) {
        return agentService.saveServicesByUid(uid, serviceInfoList);
    }

    @PostMapping("/service/edit/{id}")
    @SaCheckPermission(value = "agent:service:edit", orRole = "admin")
    public String updateAgent2ServiceById(@PathVariable Long id, @RequestBody RAgentService rAgentService) {
        return agentService.updateAgent2ServiceById(id, rAgentService);
    }

    @DeleteMapping("/service/{id}")
    @SaCheckPermission(value = "agent:service:remove", orRole = "admin")
    public String removeAgent2ServiceById(@PathVariable Long id) {
        return agentService.removeAgent2ServiceById(id);
    }

    @PostMapping("/service/assign/{uid}")
    @SaCheckPermission(value = "agent:service:assign", orRole = "admin")
    public String assign(@PathVariable String uid, @RequestBody List<ServiceInfo> serviceInfoList) {
        return agentService.assign(uid, serviceInfoList);
    }

    @GetMapping("/form/{uid}")
    @SaCheckPermission(value = "agent:form", orRole = "admin")
    public List<AgentRecord> getForm(@PathVariable String uid,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) {
        return agentService.getForm(uid, startTime, endTime);
    }
}