package com.zyc.web.controller.api;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zyc.common.annotation.Log;
import com.zyc.common.core.controller.BaseController;
import com.zyc.common.core.domain.AjaxResult;
import com.zyc.common.enums.BusinessType;
import com.zyc.system.domain.Microservices;
import com.zyc.system.service.IMicroservicesService;
import com.zyc.common.utils.poi.ExcelUtil;
import com.zyc.common.core.page.TableDataInfo;

/**
 * 微服务Controller
 * 
 * @author zyc
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/system/MicroservicesController")
public class MicroservicesController extends BaseController
{
    @Autowired
    private IMicroservicesService microservicesService;

    /**
     * 查询微服务列表
     */
    @PreAuthorize("@ss.hasPermi('system:microservices:list')")
    @GetMapping("/list")
    public TableDataInfo list(Microservices microservices)
    {
        startPage();
        List<Microservices> list = microservicesService.selectMicroservicesList(microservices);
        return getDataTable(list);
    }

    /**
     * 导出微服务列表
     */
    @PreAuthorize("@ss.hasPermi('system:microservices:export')")
    @Log(title = "微服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Microservices microservices)
    {
        List<Microservices> list = microservicesService.selectMicroservicesList(microservices);
        ExcelUtil<Microservices> util = new ExcelUtil<Microservices>(Microservices.class);
        util.exportExcel(response, list, "微服务数据");
    }

    /**
     * 获取微服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:microservices:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(microservicesService.selectMicroservicesById(id));
    }

    /**
     * 新增微服务
     */
    @PreAuthorize("@ss.hasPermi('system:microservices:add')")
    @Log(title = "微服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Microservices microservices)
    {
        return toAjax(microservicesService.insertMicroservices(microservices));
    }

    /**
     * 修改微服务
     */
    @PreAuthorize("@ss.hasPermi('system:microservices:edit')")
    @Log(title = "微服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Microservices microservices)
    {
        return toAjax(microservicesService.updateMicroservices(microservices));
    }

    /**
     * 删除微服务
     */
    @PreAuthorize("@ss.hasPermi('system:microservices:remove')")
    @Log(title = "微服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(microservicesService.deleteMicroservicesByIds(ids));
    }
}
