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.EmsBaseMonitorWorkUnit;
import com.ruoyi.ems.base.service.IEmsBaseMonitorWorkUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 统计计量信息Controller
 *
 * @author Yinq
 * @date 2024-05-09
 */
@RestController
@RequestMapping("/ems/base/baseMonitorWorkUnit")
public class EmsBaseMonitorWorkUnitController extends BaseController {
    @Autowired
    private IEmsBaseMonitorWorkUnitService emsBaseMonitorWorkUnitService;

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

    /**
     * 导出统计计量信息列表
     */
    @PreAuthorize("@ss.hasPermi('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<EmsBaseMonitorWorkUnit> util = new ExcelUtil<EmsBaseMonitorWorkUnit>(EmsBaseMonitorWorkUnit.class);
        util.exportExcel(response, list, "统计计量信息数据");
    }

    /**
     * 获取统计计量信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorWorkUnit:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(emsBaseMonitorWorkUnitService.selectEmsBaseMonitorWorkUnitByObjId(objId));
    }

    /**
     * 新增统计计量信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorWorkUnit:add')")
    @Log(title = "统计计量信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsBaseMonitorWorkUnit emsBaseMonitorWorkUnit) {
        emsBaseMonitorWorkUnit.setCreateBy(getUsername());
        return toAjax(emsBaseMonitorWorkUnitService.insertEmsBaseMonitorWorkUnit(emsBaseMonitorWorkUnit));
    }

    /**
     * 修改统计计量信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorWorkUnit:edit')")
    @Log(title = "统计计量信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsBaseMonitorWorkUnit emsBaseMonitorWorkUnit) {
        emsBaseMonitorWorkUnit.setUpdateBy(getUsername());
        return toAjax(emsBaseMonitorWorkUnitService.updateEmsBaseMonitorWorkUnit(emsBaseMonitorWorkUnit));
    }

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