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.AllMtrClient;
import com.tongran.mtragent.domain.RmMtrClientRegistration;
import com.tongran.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 tongran
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/mtrClientRegistration")
@RequiresPermissions("mtragent:mtrClientRegistration")
public class RmMtrClientRegistrationController extends BaseController
{
    @Autowired
    private IRmMtrClientRegistrationService rmMtrClientRegistrationService;

    /**
     * 查询MTR客户端注册列表
     */
    @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客户端注册列表
     */
    @Log(title = "MTR客户端注册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody 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客户端注册详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmMtrClientRegistrationService.selectRmMtrClientRegistrationById(id));
    }

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

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

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

    /**
     * 查询所有MTR客户端注册
     */
    @PostMapping("/getAllMtrMsg")
    public AjaxResult getAllMtrMsg(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
    {
        List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
        return success(list);
    }
    /**
     * 查询所有标识
     */
    @GetMapping("/getAllLogicalNode")
    public AjaxResult getAllLogicalNode()
    {
        List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.getAllLogicalNode();
        return success(list);
    }
    /**
     * 根据mtrClientId查询包含的clientId
     * @param rmMtrClientRegistration
     * @return
     */
    @PostMapping("/getClientIdByMtrClientId")
    public AjaxResult getClientIdByMtrClientId(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
    {
        List<AllMtrClient> list = rmMtrClientRegistrationService.getClientIdByMtrClientId(rmMtrClientRegistration);
        return success(list);
    }
}
