package com.xzzn.web.controller.ems;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xzzn.common.annotation.Log;
import com.xzzn.common.core.controller.BaseController;
import com.xzzn.common.core.domain.AjaxResult;
import com.xzzn.common.enums.BusinessType;
import com.xzzn.ems.domain.EmsMqttTopicConfig;
import com.xzzn.ems.service.IEmsMqttTopicConfigService;
import com.xzzn.common.utils.poi.ExcelUtil;
import com.xzzn.common.core.page.TableDataInfo;

/**
 * 站点topic配置Controller
 *
 * @author xzzn
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/ems/mqttConfig")
public class EmsMqttTopicConfigController extends BaseController
{
    @Autowired
    private IEmsMqttTopicConfigService emsMqttTopicConfigService;

    /**
     * 查询站点topic配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsMqttTopicConfig emsMqttTopicConfig)
    {
        startPage();
        List<EmsMqttTopicConfig> list = emsMqttTopicConfigService.selectEmsMqttTopicConfigList(emsMqttTopicConfig);
        return getDataTable(list);
    }

    /**
     * 导出站点topic配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "站点topic配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsMqttTopicConfig emsMqttTopicConfig)
    {
        List<EmsMqttTopicConfig> list = emsMqttTopicConfigService.selectEmsMqttTopicConfigList(emsMqttTopicConfig);
        ExcelUtil<EmsMqttTopicConfig> util = new ExcelUtil<EmsMqttTopicConfig>(EmsMqttTopicConfig.class);
        util.exportExcel(response, list, "站点topic配置数据");
    }

    /**
     * 获取站点topic配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emsMqttTopicConfigService.selectEmsMqttTopicConfigById(id));
    }

    /**
     * 新增站点topic配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "站点topic配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsMqttTopicConfig emsMqttTopicConfig)
    {
        emsMqttTopicConfig.setCreateBy(getUsername());
        return toAjax(emsMqttTopicConfigService.insertEmsMqttTopicConfig(emsMqttTopicConfig));
    }

    /**
     * 修改站点topic配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "站点topic配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsMqttTopicConfig emsMqttTopicConfig)
    {
        emsMqttTopicConfig.setUpdateBy(getUsername());
        return toAjax(emsMqttTopicConfigService.updateEmsMqttTopicConfig(emsMqttTopicConfig));
    }

    /**
     * 删除站点topic配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "站点topic配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emsMqttTopicConfigService.deleteEmsMqttTopicConfigByIds(ids));
    }
}
