package com.tongran.rocketmq.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.rocketmq.domain.RmFrpcConfigManage;
import com.tongran.rocketmq.service.IRmFrpcConfigManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * FRPC配置管理Controller
 * 
 * @author tongran
 * @date 2025-12-19
 */
@RestController
@RequestMapping("/frpcConfigManage")
@RequiresPermissions("rocketmq:frpcConfigManage")
public class RmFrpcConfigManageController extends BaseController
{
    @Autowired
    private IRmFrpcConfigManageService rmFrpcConfigManageService;

    /**
     * 查询FRPC配置管理列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmFrpcConfigManage.getPageNum());
        pageDomain.setPageSize(rmFrpcConfigManage.getPageSize());
        startPage(pageDomain);
        List<RmFrpcConfigManage> list = rmFrpcConfigManageService.selectRmFrpcConfigManageList(rmFrpcConfigManage);
        return getDataTable(list);
    }

    /**
     * 导出FRPC配置管理列表
     */
    @Log(title = "FRPC配置管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody RmFrpcConfigManage rmFrpcConfigManage)
    {
        List<RmFrpcConfigManage> list = rmFrpcConfigManageService.selectRmFrpcConfigManageList(rmFrpcConfigManage);
        ExcelUtil<RmFrpcConfigManage> util = new ExcelUtil<RmFrpcConfigManage>(RmFrpcConfigManage.class);
        util.showColumn(rmFrpcConfigManage.getProperties());
        util.exportExcel(response, list, "FRPC配置管理数据");
    }

    /**
     * 获取FRPC配置管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmFrpcConfigManageService.selectRmFrpcConfigManageById(id));
    }

    /**
     * 新增FRPC配置管理
     */
    @Log(title = "FRPC配置管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
    {
        return toAjax(rmFrpcConfigManageService.insertRmFrpcConfigManage(rmFrpcConfigManage));
    }

    /**
     * 修改FRPC配置管理
     */
    @Log(title = "FRPC配置管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
    {
        return toAjax(rmFrpcConfigManageService.updateRmFrpcConfigManage(rmFrpcConfigManage));
    }

    /**
     * 删除FRPC配置管理
     */
    @Log(title = "FRPC配置管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmFrpcConfigManageService.deleteRmFrpcConfigManageByIds(ids));
    }

    /**
     * 生成FRP连接
     */
    @Log(title = "生成FRP连接", businessType = BusinessType.OTHER)
    @PostMapping("/addFrpConnect")
    public AjaxResult addFrpConnect(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
    {
        return toAjax(rmFrpcConfigManageService.addFrpConnect(rmFrpcConfigManage));
    }

    /**
     * 根据clientid查询frp信息
     * @param rmFrpcConfigManage
     * @return
     */
    @PostMapping("/getFrpMsgByClientId")
    public AjaxResult getFrpMsgByClientId(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
    {
        RmFrpcConfigManage frpMsg = rmFrpcConfigManageService.getFrpMsgByClientId(rmFrpcConfigManage);
        return success(frpMsg);
    }
}
