package com.ruoyi.mtragent.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mtragent.domain.RmMtrClientRegistration;
import com.ruoyi.mtragent.service.IRmMtrClientRegistrationService;
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 gyt
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/mtrClientRegistration")
public class RmMtrClientRegistrationController extends BaseController
{
    @Autowired
    private IRmMtrClientRegistrationService rmMtrClientRegistrationService;

    /**
     * 查询MTR客户端注册列表
     */
    @RequiresPermissions("mtragent:mtrClientRegistration:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmMtrClientRegistration.getPageNum());
        pageDomain.setPageSize(rmMtrClientRegistration.getPageSize());
        startPage(pageDomain);
        List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
        return getDataTable(list);
    }

    /**
     * 导出MTR客户端注册列表
     */
    @RequiresPermissions("mtragent:mtrClientRegistration:export")
    @Log(title = "MTR客户端注册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmMtrClientRegistration rmMtrClientRegistration)
    {
        List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
        ExcelUtil<RmMtrClientRegistration> util = new ExcelUtil<RmMtrClientRegistration>(RmMtrClientRegistration.class);
        util.showColumn(rmMtrClientRegistration.getProperties());
        util.exportExcel(response, list, "MTR客户端注册数据");
    }

    /**
     * 获取MTR客户端注册详细信息
     */
    @RequiresPermissions("mtragent:mtrClientRegistration:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmMtrClientRegistrationService.selectRmMtrClientRegistrationById(id));
    }

    /**
     * 新增MTR客户端注册
     */
    @RequiresPermissions("mtragent:mtrClientRegistration:add")
    @Log(title = "MTR客户端注册", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
    {
        return toAjax(rmMtrClientRegistrationService.insertRmMtrClientRegistration(rmMtrClientRegistration));
    }

    /**
     * 修改MTR客户端注册
     */
    @RequiresPermissions("mtragent:mtrClientRegistration:edit")
    @Log(title = "MTR客户端注册", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
    {
        return toAjax(rmMtrClientRegistrationService.updateRmMtrClientRegistration(rmMtrClientRegistration));
    }

    /**
     * 配置更新策略
     * @param rmMtrClientRegistration
     * @return
     */
    @RequiresPermissions("mtragent:mtrClientRegistration:add")
    @PostMapping("/addAgentUpdatePolicy")
    public AjaxResult addAgentUpdatePolicy(@RequestBody RmMtrClientRegistration rmMtrClientRegistration){
        int rows = rmMtrClientRegistrationService.addAgentUpdatePolicy(rmMtrClientRegistration);
        return toAjax(rows);
    }

}
