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.BaseWaterThreshold;
import com.hw.ems.base.service.IBaseWaterThresholdService;
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("/threshold")
public class BaseWaterThresholdController extends BaseController {
    @Autowired
    private IBaseWaterThresholdService baseWaterThresholdService;

    /**
     * 查询水阈值信息列表
     */
    @RequiresPermissions("energy:threshold:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseWaterThreshold baseWaterThreshold) {
        startPage();
        List<BaseWaterThreshold> list = baseWaterThresholdService.selectBaseWaterThresholdList(baseWaterThreshold);
        return getDataTable(list);
    }

    /**
     * 导出水阈值信息列表
     */
    @RequiresPermissions("energy:threshold:export")
    @Log(title = "水阈值信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseWaterThreshold baseWaterThreshold) {
        List<BaseWaterThreshold> list = baseWaterThresholdService.selectBaseWaterThresholdList(baseWaterThreshold);
        ExcelUtil<BaseWaterThreshold> util = new ExcelUtil<BaseWaterThreshold>(BaseWaterThreshold.class);
        util.exportExcel(response, list, "水阈值信息数据");
    }

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

    /**
     * 新增水阈值信息
     */
    @RequiresPermissions("energy:threshold:add")
    @Log(title = "水阈值信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseWaterThreshold baseWaterThreshold) {
        return toAjax(baseWaterThresholdService.insertBaseWaterThreshold(baseWaterThreshold));
    }

    /**
     * 修改水阈值信息
     */
    @RequiresPermissions("energy:threshold:edit")
    @Log(title = "水阈值信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseWaterThreshold baseWaterThreshold) {
        return toAjax(baseWaterThresholdService.updateBaseWaterThreshold(baseWaterThreshold));
    }

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