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.EmsBaseMonitorWorkUnit;
import org.dromara.ems.base.service.IEmsBaseMonitorWorkUnitService;
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-05-09
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/base/baseMonitorWorkUnit")
public class EmsBaseMonitorWorkUnitController extends EmsBaseController {
    
    private final IEmsBaseMonitorWorkUnitService emsBaseMonitorWorkUnitService;

    /**
     * 查询统计计量信息列表
     */
    @SaCheckPermission("ems/base:baseMonitorWorkUnit:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsBaseMonitorWorkUnit emsBaseMonitorWorkUnit) {
        startPage();
        List<EmsBaseMonitorWorkUnit> list = emsBaseMonitorWorkUnitService.selectEmsBaseMonitorWorkUnitList(emsBaseMonitorWorkUnit);
        return getDataTable(list);
    }

    /**
     * 导出统计计量信息列表
     */
    @SaCheckPermission("ems/base:baseMonitorWorkUnit:export")
    @Log(title = "统计计量信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseMonitorWorkUnit emsBaseMonitorWorkUnit) {
        List<EmsBaseMonitorWorkUnit> list = emsBaseMonitorWorkUnitService.selectEmsBaseMonitorWorkUnitList(emsBaseMonitorWorkUnit);
        ExcelUtil.exportExcel(list, "统计计量信息数据", EmsBaseMonitorWorkUnit.class, response);
    }

    /**
     * 获取统计计量信息详细信息
     */
    @SaCheckPermission("ems/base:baseMonitorWorkUnit:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId) {
        return success(emsBaseMonitorWorkUnitService.selectEmsBaseMonitorWorkUnitByObjId(objId));
    }

    /**
     * 新增统计计量信息
     */
    @SaCheckPermission("ems/base:baseMonitorWorkUnit:add")
    @Log(title = "统计计量信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseMonitorWorkUnit emsBaseMonitorWorkUnit) {
        return toAjax(emsBaseMonitorWorkUnitService.insertEmsBaseMonitorWorkUnit(emsBaseMonitorWorkUnit));
    }

    /**
     * 修改统计计量信息
     */
    @SaCheckPermission("ems/base:baseMonitorWorkUnit:edit")
    @Log(title = "统计计量信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseMonitorWorkUnit emsBaseMonitorWorkUnit) {
        return toAjax(emsBaseMonitorWorkUnitService.updateEmsBaseMonitorWorkUnit(emsBaseMonitorWorkUnit));
    }

    /**
     * 删除统计计量信息
     */
    @SaCheckPermission("ems/base:baseMonitorWorkUnit:remove")
    @Log(title = "统计计量信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public R<?> remove(@PathVariable Long[] objIds) {
        return toAjax(emsBaseMonitorWorkUnitService.deleteEmsBaseMonitorWorkUnitByObjIds(objIds));
    }
}
