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.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.RmMtrProbeResult;
import com.tongran.mtragent.service.IRmMtrProbeResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 网络mtr探测结果Controller
 * 
 * @author tongran
 * @date 2025-11-20
 */
@RestController
@RequestMapping("/mtrProbeResult")
@RequiresPermissions("mtragent:mtrClientRegistration")
public class RmMtrProbeResultController extends BaseController
{
    @Autowired
    private IRmMtrProbeResultService rmMtrProbeResultService;

    /**
     * 查询网络mtr探测结果列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RmMtrProbeResult rmMtrProbeResult)
    {
        startPage();
        List<RmMtrProbeResult> list = rmMtrProbeResultService.selectRmMtrProbeResultList(rmMtrProbeResult);
        return getDataTable(list);
    }

    /**
     * 导出网络mtr探测结果列表
     */
    @Log(title = "网络mtr探测结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmMtrProbeResult rmMtrProbeResult)
    {
        List<RmMtrProbeResult> list = rmMtrProbeResultService.selectRmMtrProbeResultList(rmMtrProbeResult);
        ExcelUtil<RmMtrProbeResult> util = new ExcelUtil<RmMtrProbeResult>(RmMtrProbeResult.class);
        util.exportExcel(response, list, "网络mtr探测结果数据");
    }

    /**
     * 获取网络mtr探测结果详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmMtrProbeResultService.selectRmMtrProbeResultById(id));
    }

    /**
     * 新增网络mtr探测结果
     */
    @Log(title = "网络mtr探测结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmMtrProbeResult rmMtrProbeResult)
    {
        return toAjax(rmMtrProbeResultService.insertRmMtrProbeResult(rmMtrProbeResult));
    }

    /**
     * 修改网络mtr探测结果
     */
    @Log(title = "网络mtr探测结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmMtrProbeResult rmMtrProbeResult)
    {
        return toAjax(rmMtrProbeResultService.updateRmMtrProbeResult(rmMtrProbeResult));
    }

    /**
     * 删除网络mtr探测结果
     */
    @Log(title = "网络mtr探测结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmMtrProbeResultService.deleteRmMtrProbeResultByIds(ids));
    }

    /**
     * 查看丢包率趋势
     */
    @PostMapping("/getLossRateByMtrClientId")
    public AjaxResult getLossRateByMtrClientId(@RequestBody RmMtrProbeResult rmMtrProbeResult)
    {
        Map<String, Object> list = rmMtrProbeResultService.getLossRateByMtrClientId(rmMtrProbeResult);
        return success(list);
    }
}
