package com.hw.ems.base.controller;

import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.web.page.TableDataInfo;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.ems.base.domain.BaseCollectDeviceInfo;
import com.hw.ems.base.service.IBaseCollectDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 采集设备信息Controller
 *
 * @author sf
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/info")
public class BaseCollectDeviceInfoController extends BaseController {
    @Autowired
    private IBaseCollectDeviceInfoService baseCollectDeviceInfoService;

    /**
     * 查询采集设备信息列表
     */
    @RequiresPermissions("energy:info:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseCollectDeviceInfo baseCollectDeviceInfo) {
        startPage();
        List<BaseCollectDeviceInfo> list = baseCollectDeviceInfoService.selectBaseCollectDeviceInfoList(baseCollectDeviceInfo);
        return getDataTable(list);
    }

    /**
     * 导出采集设备信息列表
     */
    @RequiresPermissions("energy:info:export")
    @Log(title = "采集设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseCollectDeviceInfo baseCollectDeviceInfo) {
        List<BaseCollectDeviceInfo> list = baseCollectDeviceInfoService.selectBaseCollectDeviceInfoList(baseCollectDeviceInfo);
        ExcelUtil<BaseCollectDeviceInfo> util = new ExcelUtil<BaseCollectDeviceInfo>(BaseCollectDeviceInfo.class);
        util.exportExcel(response, list, "采集设备信息数据");
    }

    /**
     * 获取采集设备信息详细信息
     */
    @RequiresPermissions("energy:info:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid) {
        return success(baseCollectDeviceInfoService.selectBaseCollectDeviceInfoByObjid(objid));
    }

    /**
     * 新增采集设备信息
     */
    @RequiresPermissions("energy:info:add")
    @Log(title = "采集设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseCollectDeviceInfo baseCollectDeviceInfo) {
        return toAjax(baseCollectDeviceInfoService.insertBaseCollectDeviceInfo(baseCollectDeviceInfo));
    }

    /**
     * 修改采集设备信息
     */
    @RequiresPermissions("energy:info:edit")
    @Log(title = "采集设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseCollectDeviceInfo baseCollectDeviceInfo) {
        return toAjax(baseCollectDeviceInfoService.updateBaseCollectDeviceInfo(baseCollectDeviceInfo));
    }

    /**
     * 删除采集设备信息
     */
    @RequiresPermissions("energy:info:remove")
    @Log(title = "采集设备信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids) {
        return toAjax(baseCollectDeviceInfoService.deleteBaseCollectDeviceInfoByObjids(objids));
    }
}
