package com.hw.ems.base.controller;

import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.web.page.TableDataInfo;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.ems.base.domain.BaseDnbThreshold;
import com.hw.ems.base.domain.BaseMonitorInfo;
import com.hw.ems.base.service.IBaseDnbThresholdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 电阈值信息Controller
 *
 * @author sf
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/dnbThreshold")
public class BaseDnbThresholdController extends BaseController {
    @Autowired
    private IBaseDnbThresholdService baseDnbThresholdService;

    /**
     * 查询电阈值信息列表
     */
    @RequiresPermissions("energy:dnbThreshold:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseDnbThreshold baseDnbThreshold) {
        startPage();
        List<BaseDnbThreshold> list = baseDnbThresholdService.selectBaseDnbThresholdList(baseDnbThreshold);
        return getDataTable(list);
    }

    /**
     * 导出电阈值信息列表
     */
    @RequiresPermissions("energy:dnbThreshold:export")
    @Log(title = "电阈值信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseDnbThreshold baseDnbThreshold) {
        List<BaseDnbThreshold> list = baseDnbThresholdService.selectBaseDnbThresholdList(baseDnbThreshold);
        ExcelUtil<BaseDnbThreshold> util = new ExcelUtil<BaseDnbThreshold>(BaseDnbThreshold.class);
        util.exportExcel(response, list, "电阈值信息数据");
    }

    /**
     * 获取电阈值信息详细信息
     */
    @RequiresPermissions("energy:dnbThreshold:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid) {
        return success(baseDnbThresholdService.selectBaseDnbThresholdByObjid(objid));
    }

    /**
     * 新增电阈值信息
     */
    @RequiresPermissions("energy:dnbThreshold:add")
    @Log(title = "电阈值信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseDnbThreshold baseDnbThreshold) {
        return toAjax(baseDnbThresholdService.insertBaseDnbThreshold(baseDnbThreshold));
    }

    /**
     * 修改电阈值信息
     */
    @RequiresPermissions("energy:dnbThreshold:edit")
    @Log(title = "电阈值信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseDnbThreshold baseDnbThreshold) {
        return toAjax(baseDnbThresholdService.updateBaseDnbThreshold(baseDnbThreshold));
    }

    /**
     * 删除电阈值信息
     */
    @RequiresPermissions("energy:dnbThreshold:remove")
    @Log(title = "电阈值信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids) {
        return toAjax(baseDnbThresholdService.deleteBaseDnbThresholdByObjids(objids));
    }

    /**
     * 获取计量设备树列表
     */
    @GetMapping("/monitorTree")
    public AjaxResult monitorTree(BaseMonitorInfo baseMonitorInfo) {
        return success(baseDnbThresholdService.selectMonitorTreeList(baseMonitorInfo));
    }
}
