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.BaseCollectCommunicate;
import com.hw.ems.base.service.IBaseCollectCommunicateService;
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("/communicate")
public class BaseCollectCommunicateController extends BaseController {
    @Autowired
    private IBaseCollectCommunicateService baseCollectCommunicateService;

    /**
     * 查询集中器通讯信息列表
     */
    @RequiresPermissions("energy:communicate:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseCollectCommunicate baseCollectCommunicate) {
        startPage();
        List<BaseCollectCommunicate> list = baseCollectCommunicateService.selectBaseCollectCommunicateList(baseCollectCommunicate);
        return getDataTable(list);
    }

    /**
     * 导出集中器通讯信息列表
     */
    @RequiresPermissions("energy:communicate:export")
    @Log(title = "集中器通讯信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseCollectCommunicate baseCollectCommunicate) {
        List<BaseCollectCommunicate> list = baseCollectCommunicateService.selectBaseCollectCommunicateList(baseCollectCommunicate);
        ExcelUtil<BaseCollectCommunicate> util = new ExcelUtil<BaseCollectCommunicate>(BaseCollectCommunicate.class);
        util.exportExcel(response, list, "集中器通讯信息数据");
    }

    /**
     * 获取集中器通讯信息详细信息
     */
    @RequiresPermissions("energy:communicate:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid) {
        return success(baseCollectCommunicateService.selectBaseCollectCommunicateByObjid(objid));
    }

    /**
     * 新增集中器通讯信息
     */
    @RequiresPermissions("energy:communicate:add")
    @Log(title = "集中器通讯信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseCollectCommunicate baseCollectCommunicate) {
        return toAjax(baseCollectCommunicateService.insertBaseCollectCommunicate(baseCollectCommunicate));
    }

    /**
     * 修改集中器通讯信息
     */
    @RequiresPermissions("energy:communicate:edit")
    @Log(title = "集中器通讯信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseCollectCommunicate baseCollectCommunicate) {
        return toAjax(baseCollectCommunicateService.updateBaseCollectCommunicate(baseCollectCommunicate));
    }

    /**
     * 删除集中器通讯信息
     */
    @RequiresPermissions("energy:communicate:remove")
    @Log(title = "集中器通讯信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids) {
        return toAjax(baseCollectCommunicateService.deleteBaseCollectCommunicateByObjids(objids));
    }
}
