package com.dcsoft.system.ladder.controller;

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

import com.dcsoft.system.ladder.domain.TLadderRule;
import com.dcsoft.system.ladder.service.ITLadderRuleService;
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("/ladderRule")
public class TLadderRuleController extends BaseController {

    @Autowired
    private ITLadderRuleService tLadderRuleService;

    /**
     * 查询梯控规则列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TLadderRule tLadderRule) {
        startPage();
        List<TLadderRule> list = tLadderRuleService.selectTLadderRuleList(tLadderRule);
        return getDataTable(list);
    }

    /**
     * 导出梯控规则列表
     */
    @Log(title = "梯控规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TLadderRule tLadderRule) {
        List<TLadderRule> list = tLadderRuleService.selectTLadderRuleList(tLadderRule);
        ExcelUtil<TLadderRule> util = new ExcelUtil<TLadderRule>(TLadderRule.class);
        util.exportExcel(response, list, "梯控规则数据");
    }

    /**
     * 获取梯控规则详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tLadderRuleService.selectTLadderRuleById(id));
    }

    /**
     * 新增梯控规则
     */
    @Log(title = "梯控规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TLadderRule tLadderRule) {
        return toAjax(tLadderRuleService.insertTLadderRule(tLadderRule));
    }

    /**
     * 修改梯控规则
     */
    @Log(title = "梯控规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TLadderRule tLadderRule) {
        return toAjax(tLadderRuleService.updateTLadderRule(tLadderRule));
    }

    /**
     * 删除梯控规则
     */
    @Log(title = "梯控规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tLadderRuleService.deleteTLadderRuleByIds(ids));
    }

    /**
     * 查询设备位置信息
     */
    @PostMapping("/queryDevicePositionTree")
    public AjaxResult queryDevicePositionTree() {
        return success(tLadderRuleService.queryDevicePositionTree());
    }


}
