package com.aucma.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.aucma.base.domain.BaseMonitorInfo;
import com.aucma.base.domain.BaseWorkUnit;
import com.aucma.base.service.IBaseMonitorInfoService;
import com.aucma.base.service.IBaseWorkUnitService;
import com.aucma.common.utils.DateUtils;
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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.base.domain.BaseMonitorWorkUnit;
import com.aucma.base.service.IBaseMonitorWorkUnitService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 统计计量信息Controller
 *
 * @author Yinq
 * @date 2023-10-12
 */
@RestController
@RequestMapping("/base/monitorWorkUnit" )
public class BaseMonitorWorkUnitController extends BaseController {
    @Autowired
    private IBaseMonitorWorkUnitService baseMonitorWorkUnitService;

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

    /**
     * 导出统计计量信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:monitorWorkUnit:export')" )
    @Log(title = "统计计量信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BaseMonitorWorkUnit baseMonitorWorkUnit) {
        List<BaseMonitorWorkUnit> list = baseMonitorWorkUnitService.selectBaseMonitorWorkUnitList(baseMonitorWorkUnit);
        ExcelUtil<BaseMonitorWorkUnit> util = new ExcelUtil<BaseMonitorWorkUnit>(BaseMonitorWorkUnit. class);
        util.exportExcel(response, list, "统计计量信息数据" );
    }

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

    /**
     * 新增统计计量信息
     */
    @PreAuthorize("@ss.hasPermi('base:monitorWorkUnit:add')" )
    @Log(title = "统计计量信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseMonitorWorkUnit baseMonitorWorkUnit) {
        baseMonitorWorkUnit.setCreatedBy(getUsername());
        return toAjax(baseMonitorWorkUnitService.insertBaseMonitorWorkUnit(baseMonitorWorkUnit));
    }

    /**
     * 修改统计计量信息
     */
    @PreAuthorize("@ss.hasPermi('base:monitorWorkUnit:edit')" )
    @Log(title = "统计计量信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseMonitorWorkUnit baseMonitorWorkUnit) {
        baseMonitorWorkUnit.setUpdatedBy(getUsername());
        return toAjax(baseMonitorWorkUnitService.updateBaseMonitorWorkUnit(baseMonitorWorkUnit));
    }

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