ServiceController.java 1.91 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.data.id.IdUtil;
import org.springframework.web.bind.annotation.*;
import vion.model.monitor.ServiceInfo;
import vion.service.monitor.IServiceInfoService;

/**
 * 服务
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/service")
public class ServiceController {

    private final IServiceInfoService serviceInfoService;

    @GetMapping
    @SaCheckPermission(value = "service:list", orRole = "admin")
    public Page<ServiceInfo> list(ServiceInfo dto) {
        return serviceInfoService.lambdaQuery(dto)
                .orderByAsc(ServiceInfo::getCreateTime)
                .orderByDesc(ServiceInfo::getUpdateTime)
                .page(Page.of(dto.getPageNum(), dto.getPageSize()));
    }

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

    @PostMapping
    @SaCheckPermission(value = "service:save", orRole = "admin")
    public String save(@RequestBody ServiceInfo serviceInfo) {
        serviceInfo.setUid(IdUtil.nanoId(16));
        serviceInfoService.save(serviceInfo);
        return "服务添加成功";
    }

    @PostMapping("/{id}")
    @SaCheckPermission(value = "service:edit", orRole = "admin")
    public String update(@PathVariable Long id, @RequestBody ServiceInfo serviceInfo) {
        serviceInfo.setId(id);
        serviceInfoService.updateById(serviceInfo);
        return "服务更新成功";
    }

    @DeleteMapping("/{id}")
    @SaCheckPermission(value = "service:remove", orRole = "admin")
    public String remove(@PathVariable Long id) {
        serviceInfoService.removeById(id);
        return "服务删除成功";
    }

}