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

/**
 * 采集设备信息Controller
 *
 * @author Yinq
 * @date 2024-05-20
 */
@RestController
@RequestMapping("/ems/base/baseCollectDeviceInfo")
public class EmsBaseCollectDeviceInfoController extends BaseController {
    @Autowired
    private IEmsBaseCollectDeviceInfoService emsBaseCollectDeviceInfoService;

    /**
     * 查询采集设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseCollectDeviceInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsBaseCollectDeviceInfo emsBaseCollectDeviceInfo) {
        startPage();
        List<EmsBaseCollectDeviceInfo> list = emsBaseCollectDeviceInfoService.selectEmsBaseCollectDeviceInfoList(emsBaseCollectDeviceInfo);
        return getDataTable(list);
    }

    /**
     * 查询采集设备信息下拉框列表
     */
    @GetMapping("/getCollectDeviceInfo")
    public AjaxResult getCollectDeviceInfo(EmsBaseCollectDeviceInfo emsBaseCollectDeviceInfo) {
        List<EmsBaseCollectDeviceInfo> list = emsBaseCollectDeviceInfoService.selectEmsBaseCollectDeviceInfoList(emsBaseCollectDeviceInfo);
        return success(list);
    }

    /**
     * 导出采集设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseCollectDeviceInfo:export')")
    @Log(title = "采集设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseCollectDeviceInfo emsBaseCollectDeviceInfo) {
        List<EmsBaseCollectDeviceInfo> list = emsBaseCollectDeviceInfoService.selectEmsBaseCollectDeviceInfoList(emsBaseCollectDeviceInfo);
        ExcelUtil<EmsBaseCollectDeviceInfo> util = new ExcelUtil<EmsBaseCollectDeviceInfo>(EmsBaseCollectDeviceInfo.class);
        util.exportExcel(response, list, "采集设备信息数据");
    }

    /**
     * 获取采集设备信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseCollectDeviceInfo:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(emsBaseCollectDeviceInfoService.selectEmsBaseCollectDeviceInfoByObjId(objId));
    }

    /**
     * 新增采集设备信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseCollectDeviceInfo:add')")
    @Log(title = "采集设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsBaseCollectDeviceInfo emsBaseCollectDeviceInfo) {
        emsBaseCollectDeviceInfo.setCreateBy(getUsername());
        return toAjax(emsBaseCollectDeviceInfoService.insertEmsBaseCollectDeviceInfo(emsBaseCollectDeviceInfo));
    }

    /**
     * 修改采集设备信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseCollectDeviceInfo:edit')")
    @Log(title = "采集设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsBaseCollectDeviceInfo emsBaseCollectDeviceInfo) {
        emsBaseCollectDeviceInfo.setUpdateBy(getUsername());
        return toAjax(emsBaseCollectDeviceInfoService.updateEmsBaseCollectDeviceInfo(emsBaseCollectDeviceInfo));
    }

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