package org.dromara.ems.base.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.base.domain.EmsBaseMonitorThreshold;
import org.dromara.ems.base.service.IEmsBaseMonitorThresholdService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    private final IEmsBaseMonitorThresholdService emsBaseMonitorThresholdService;

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

    /**
     * 导出计量设备阈值维护列表
     */
    @SaCheckPermission("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.exportExcel(list, "计量设备阈值维护数据", EmsBaseMonitorThreshold.class, response);
    }

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

    /**
     * 新增计量设备阈值维护
     */
    @SaCheckPermission("ems/base:baseMonitorThreshold:add")
    @Log(title = "计量设备阈值维护", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseMonitorThreshold emsBaseMonitorThreshold) {
        return toAjax(emsBaseMonitorThresholdService.insertEmsBaseMonitorThreshold(emsBaseMonitorThreshold));
    }

    /**
     * 修改计量设备阈值维护
     */
    @SaCheckPermission("ems/base:baseMonitorThreshold:edit")
    @Log(title = "计量设备阈值维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseMonitorThreshold emsBaseMonitorThreshold) {
        return toAjax(emsBaseMonitorThresholdService.updateEmsBaseMonitorThreshold(emsBaseMonitorThreshold));
    }

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