package org.dromara.ems.base.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.base.domain.EmsBaseCollectDeviceInfo;
import org.dromara.ems.base.service.IEmsBaseCollectDeviceInfoService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集设备信息Controller
 *
 * @author Yinq
 * @date 2024-05-20
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/base/baseCollectDeviceInfo")
public class EmsBaseCollectDeviceInfoController extends EmsBaseController {
    
    private final IEmsBaseCollectDeviceInfoService emsBaseCollectDeviceInfoService;

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

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

    /**
     * 导出采集设备信息列表
     */
    @SaCheckPermission("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.exportExcel(list, "采集设备信息数据", EmsBaseCollectDeviceInfo.class, response);
    }

    /**
     * 获取采集设备信息详细信息
     */
    @SaCheckPermission("ems/base:baseCollectDeviceInfo:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId) {
        return success(emsBaseCollectDeviceInfoService.selectEmsBaseCollectDeviceInfoByObjId(objId));
    }

    /**
     * 新增采集设备信息
     */
    @SaCheckPermission("ems/base:baseCollectDeviceInfo:add")
    @Log(title = "采集设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseCollectDeviceInfo emsBaseCollectDeviceInfo) {
        return toAjax(emsBaseCollectDeviceInfoService.insertEmsBaseCollectDeviceInfo(emsBaseCollectDeviceInfo));
    }

    /**
     * 修改采集设备信息
     */
    @SaCheckPermission("ems/base:baseCollectDeviceInfo:edit")
    @Log(title = "采集设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseCollectDeviceInfo emsBaseCollectDeviceInfo) {
        return toAjax(emsBaseCollectDeviceInfoService.updateEmsBaseCollectDeviceInfo(emsBaseCollectDeviceInfo));
    }

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