package com.tongran.mtragent.controller;

import com.tongran.common.core.utils.poi.ExcelUtil;
import com.tongran.common.core.web.controller.BaseController;
import com.tongran.common.core.web.domain.AjaxResult;
import com.tongran.common.core.web.page.PageDomain;
import com.tongran.common.core.web.page.TableDataInfo;
import com.tongran.common.log.annotation.Log;
import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.mtragent.domain.RmMtrPolicyConfig;
import com.tongran.mtragent.service.IRmMtrPolicyConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * mtr探测策略配置Controller
 * 
 * @author tongran
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/mtrPolicyConfig")
@RequiresPermissions("mtragent:mtrPolicyConfig")
public class RmMtrPolicyConfigController extends BaseController
{
    @Autowired
    private IRmMtrPolicyConfigService rmMtrPolicyConfigService;

    /**
     * 查询mtr探测策略配置列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmMtrPolicyConfig.getPageNum());
        pageDomain.setPageSize(rmMtrPolicyConfig.getPageSize());
        startPage(pageDomain);
        List<RmMtrPolicyConfig> list = rmMtrPolicyConfigService.selectRmMtrPolicyConfigList(rmMtrPolicyConfig);
        return getDataTable(list);
    }

    /**
     * 导出mtr探测策略配置列表
     */
    @Log(title = "mtr探测策略配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmMtrPolicyConfig rmMtrPolicyConfig)
    {
        List<RmMtrPolicyConfig> list = rmMtrPolicyConfigService.selectRmMtrPolicyConfigList(rmMtrPolicyConfig);
        ExcelUtil<RmMtrPolicyConfig> util = new ExcelUtil<RmMtrPolicyConfig>(RmMtrPolicyConfig.class);
        util.showColumn(rmMtrPolicyConfig.getProperties());
        util.exportExcel(response, list, "mtr探测策略配置数据");
    }

    /**
     * 获取mtr探测策略配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmMtrPolicyConfigService.selectRmMtrPolicyConfigById(id));
    }

    /**
     * 新增mtr探测策略配置
     */
    @Log(title = "mtr探测策略配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
    {
        int rows = rmMtrPolicyConfigService.insertRmMtrPolicyConfig(rmMtrPolicyConfig);
        return toAjax(rows);
    }

    /**
     * 修改mtr探测策略配置
     */
    @Log(title = "mtr探测策略配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
    {
        return toAjax(rmMtrPolicyConfigService.updateRmMtrPolicyConfig(rmMtrPolicyConfig));
    }

    /**
     * 删除mtr探测策略配置
     */
    @Log(title = "mtr探测策略配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmMtrPolicyConfigService.deleteRmMtrPolicyConfigByIds(ids));
    }
}
