package com.ruoyi.ems.base.controller;

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

import com.ruoyi.ems.base.domain.TreeSelects;
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.EmsBaseWorkUnit;
import com.ruoyi.ems.base.service.IEmsBaseWorkUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 统计单元信息Controller
 * 
 * @author Yinq
 * @date 2024-05-09
 */
@RestController
@RequestMapping("/ems/base/baseWorkUnit")
public class EmsBaseWorkUnitController extends BaseController
{
    @Autowired
    private IEmsBaseWorkUnitService emsBaseWorkUnitService;

    /**
     * 查询统计单元信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseWorkUnit:list')")
    @GetMapping("/list")
    public AjaxResult list(EmsBaseWorkUnit emsBaseWorkUnit)
    {
        List<EmsBaseWorkUnit> list = emsBaseWorkUnitService.selectEmsBaseWorkUnitList(emsBaseWorkUnit);
        return success(list);
    }

    /**
     * 查询计量设备信息下拉树结构
     */
    @PostMapping("/workUnitTree")
    public AjaxResult getMonitorInfoTree(EmsBaseWorkUnit baseWorkUnit) {
        List<TreeSelects> list = emsBaseWorkUnitService.selectBaseWorkUnitTreeList(baseWorkUnit);
        return success(list);
    }

    /**
     * 导出统计单元信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseWorkUnit:export')")
    @Log(title = "统计单元信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseWorkUnit emsBaseWorkUnit)
    {
        List<EmsBaseWorkUnit> list = emsBaseWorkUnitService.selectEmsBaseWorkUnitList(emsBaseWorkUnit);
        ExcelUtil<EmsBaseWorkUnit> util = new ExcelUtil<EmsBaseWorkUnit>(EmsBaseWorkUnit.class);
        util.exportExcel(response, list, "统计单元信息数据");
    }

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

    /**
     * 新增统计单元信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseWorkUnit:add')")
    @Log(title = "统计单元信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsBaseWorkUnit emsBaseWorkUnit)
    {
        emsBaseWorkUnit.setCreateBy(getUsername());
        return toAjax(emsBaseWorkUnitService.insertEmsBaseWorkUnit(emsBaseWorkUnit));
    }

    /**
     * 修改统计单元信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseWorkUnit:edit')")
    @Log(title = "统计单元信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsBaseWorkUnit emsBaseWorkUnit)
    {
        emsBaseWorkUnit.setUpdateBy(getUsername());
        return toAjax(emsBaseWorkUnitService.updateEmsBaseWorkUnit(emsBaseWorkUnit));
    }

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