package com.dcsoft.system.ladder.controller;

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

import com.dcsoft.system.ladder.domain.TLadderConfig;
import com.dcsoft.system.ladder.service.ITLadderConfigService;
import com.dcsoft.system.uniubi.domain.EventResult;
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.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 梯控基础配置Controller
 *
 * @author dcsoft
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/ladder")
public class TLadderConfigController extends BaseController {

    @Resource
    private ITLadderConfigService tLadderConfigService;

    /**
     * 查询梯控基础配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TLadderConfig tLadderConfig) {
        List<TLadderConfig> list = tLadderConfigService.selectTLadderConfigList(tLadderConfig);
        return getDataTable(list);
    }

    /**
     * 导出梯控基础配置列表
     */
    @Log(title = "梯控基础配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TLadderConfig tLadderConfig) {
        List<TLadderConfig> list = tLadderConfigService.selectTLadderConfigList(tLadderConfig);
        ExcelUtil<TLadderConfig> util = new ExcelUtil<TLadderConfig>(TLadderConfig.class);
        util.exportExcel(response, list, "梯控基础配置数据");
    }

    /**
     * 获取梯控基础配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tLadderConfigService.selectTLadderConfigById(id));
    }

    /**
     * 新增梯控基础配置
     */
    @Log(title = "梯控基础配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TLadderConfig tLadderConfig) {
        return toAjax(tLadderConfigService.insertTLadderConfig(tLadderConfig));
    }

    /**
     * 修改梯控基础配置
     */
    @Log(title = "梯控基础配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TLadderConfig tLadderConfig) {
        return toAjax(tLadderConfigService.updateTLadderConfig(tLadderConfig));
    }

    /**
     * 删除梯控基础配置
     */
    @Log(title = "梯控基础配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tLadderConfigService.deleteTLadderConfigByIds(ids));
    }

    /**
     * 查询设备树形数据
     */
    @PostMapping("/queryDeviceTree")
    public AjaxResult queryDeviceTree() {
        return success(tLadderConfigService.queryDeviceTree());
    }

    /**
     * 设备初始化
     */
    @PostMapping("/deviceInitialize")
    public void deviceInitialize(TLadderConfig ladderConfig) {
        tLadderConfigService.deviceInitialize(ladderConfig);
    }


}
