package com.ruoyi.ems.base.controller;

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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ems.base.domain.EmsBaseMonitorThreshold;
import com.ruoyi.ems.base.service.IEmsBaseMonitorThresholdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计量设备阈值维护Controller
 *
 * @author Yinq
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/ems/base/baseMonitorThreshold")
public class EmsBaseMonitorThresholdController extends BaseController {
    @Autowired
    private IEmsBaseMonitorThresholdService emsBaseMonitorThresholdService;

    /**
     * 查询计量设备阈值维护列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorThreshold:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsBaseMonitorThreshold emsBaseMonitorThreshold) {
        startPage();
        List<EmsBaseMonitorThreshold> list = emsBaseMonitorThresholdService.selectEmsBaseMonitorThresholdList(emsBaseMonitorThreshold);
        return getDataTable(list);
    }

    /**
     * 导出计量设备阈值维护列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorThreshold:export')")
    @Log(title = "计量设备阈值维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseMonitorThreshold emsBaseMonitorThreshold) {
        List<EmsBaseMonitorThreshold> list = emsBaseMonitorThresholdService.selectEmsBaseMonitorThresholdList(emsBaseMonitorThreshold);
        ExcelUtil<EmsBaseMonitorThreshold> util = new ExcelUtil<EmsBaseMonitorThreshold>(EmsBaseMonitorThreshold.class);
        util.exportExcel(response, list, "计量设备阈值维护数据");
    }

    /**
     * 获取计量设备阈值维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorThreshold:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(emsBaseMonitorThresholdService.selectEmsBaseMonitorThresholdByObjId(objId));
    }

    /**
     * 新增计量设备阈值维护
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorThreshold:add')")
    @Log(title = "计量设备阈值维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsBaseMonitorThreshold emsBaseMonitorThreshold) {
        emsBaseMonitorThreshold.setCreateBy(getUsername());
        return toAjax(emsBaseMonitorThresholdService.insertEmsBaseMonitorThreshold(emsBaseMonitorThreshold));
    }

    /**
     * 修改计量设备阈值维护
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorThreshold:edit')")
    @Log(title = "计量设备阈值维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsBaseMonitorThreshold emsBaseMonitorThreshold) {
        emsBaseMonitorThreshold.setUpdateBy(getUsername());
        return toAjax(emsBaseMonitorThresholdService.updateEmsBaseMonitorThreshold(emsBaseMonitorThreshold));
    }

    /**
     * 删除计量设备阈值维护
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorThreshold:remove')")
    @Log(title = "计量设备阈值维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(emsBaseMonitorThresholdService.deleteEmsBaseMonitorThresholdByObjIds(objIds));
    }
}
