EventController.java 3.2 KB
package vion.controller.monitor;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.data.id.IdUtil;
import org.springframework.web.bind.annotation.*;
import vion.dto.monitor.EventDTO;
import vion.model.monitor.Event;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IEventService;
import vion.service.monitor.IRAgentEventService;
import vion.vo.monitor.EventVO;

import java.util.List;

/**
 * 事件管理
 */
@RestController
@RequestMapping("/api/event")
@RequiredArgsConstructor
public class EventController {

    private final IEventService eventService;
    private final IRAgentEventService agentEventService;

    @GetMapping
    @SaCheckPermission(value = "event:list", orRole = "admin")
    public Page<Event> list(Event event) {
        return eventService.lambdaQuery(event)
                .in(CollUtil.isNotEmpty(event.getTypeList()), Event::getType, event.getTypeList())
                .orderByDesc(Event::getCreateTime)
                .page(Page.of(event.getPageNum(), event.getPageSize()));
    }

    @GetMapping("/{id}")
    @SaCheckPermission(value = "event:query", orRole = "admin")
    public Event get(@PathVariable Long id) {
        return eventService.getById(id);
    }

    @PostMapping
    @SaCheckPermission(value = "event:save", orRole = "admin")
    public String save(@RequestBody Event event) {
        event.setUid(IdUtil.nanoId(20));
        return eventService.save(event) ? "事件添加成功" : "事件添加失败";
    }

    @PostMapping("/{id}")
    @SaCheckPermission(value = "event:edit", orRole = "admin")
    public String update(@PathVariable Long id, @RequestBody Event event) {
        event.setId(id);
        return eventService.updateById(event) ? "事件更新成功" : "事件更新失败";
    }

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

    @GetMapping("/bind")
    @SaCheckPermission(value = "event:bind:list", orRole = "admin")
    public Page<EventVO> listAgentEvent(EventDTO dto) {
        return eventService.list(dto);
    }

    @PostMapping("/bind/{agentUid}/{mallUid}")
    @SaCheckPermission(value = "event:bind", orRole = "admin")
    public String bind(@PathVariable String agentUid, @PathVariable String mallUid, @RequestBody List<RAgentEvent> dtoList) {
        return agentEventService.bind(agentUid, mallUid, dtoList);
    }

    @PostMapping("/unbind/{agentUid}/{mallUid}")
    @SaCheckPermission(value = "event:unbind", orRole = "admin")
    public String unbind(@PathVariable String agentUid, @PathVariable String mallUid, List<Long> idList) {
        return agentEventService.unbind(agentUid, mallUid, idList);
    }

    @PostMapping("/bind/batch/{agentUid}")
    @SaCheckPermission(value = "event:bind:batch", orRole = "admin")
    public String bindBatch(@PathVariable String agentUid, @RequestBody RAgentEvent dto) {
        return agentEventService.bindBatch(agentUid, dto);
    }
}