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.EmsBaseMonitorInfo;
import com.ruoyi.ems.base.service.IEmsBaseMonitorInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 计量设备信息Controller
 *
 * @author Yinq
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/ems/base/baseMonitorInfo")
public class EmsBaseMonitorInfoController extends BaseController
{
    @Autowired
    private IEmsBaseMonitorInfoService emsBaseMonitorInfoService;

    /**
     * 查询计量设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorInfo:list')")
    @GetMapping("/list")
    public AjaxResult list(EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        List<EmsBaseMonitorInfo> list = emsBaseMonitorInfoService.selectEmsBaseMonitorInfoList(emsBaseMonitorInfo);
        return success(list);
    }

    /**
     * 查询计量设备信息下拉树结构
     * */
    @PostMapping("/monitorInfoTree")
    public AjaxResult getMonitorInfoTree(@RequestBody  EmsBaseMonitorInfo baseMonitorInfo) {
        List<TreeSelects> list = emsBaseMonitorInfoService.selectBaseMonitorInfoTreeList(baseMonitorInfo);
        return success(list);
    }

    /**
     * 导出计量设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorInfo:export')")
    @Log(title = "计量设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        List<EmsBaseMonitorInfo> list = emsBaseMonitorInfoService.selectEmsBaseMonitorInfoList(emsBaseMonitorInfo);
        ExcelUtil<EmsBaseMonitorInfo> util = new ExcelUtil<EmsBaseMonitorInfo>(EmsBaseMonitorInfo.class);
        util.exportExcel(response, list, "计量设备信息数据");
    }

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

    /**
     * 新增计量设备信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorInfo:add')")
    @Log(title = "计量设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        emsBaseMonitorInfo.setCreateBy(getUsername());
        return toAjax(emsBaseMonitorInfoService.insertEmsBaseMonitorInfo(emsBaseMonitorInfo));
    }

    /**
     * 修改计量设备信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseMonitorInfo:edit')")
    @Log(title = "计量设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        emsBaseMonitorInfo.setUpdateBy(getUsername());
        return toAjax(emsBaseMonitorInfoService.updateEmsBaseMonitorInfo(emsBaseMonitorInfo));
    }

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