package com.sooka.sponest.monitor.aideviceevent.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.sooka.sponest.monitor.aideviceevent.domain.CenterdataTAideviceevent;
import com.sooka.sponest.monitor.aideviceevent.service.ICenterdataTAideviceeventService;
import com.sooka.sponest.monitor.remoteapi.service.center.event.RemoteEventBaseService;
import com.sooka.sponest.monitor.remoteapi.service.center.event.domain.CentereventTEventtype;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * AI对应事件Controller
 *
 * @author yy
 * @date 2022-09-01
 */
@Api(tags = "AI对应事件控制器")
@RestController
@RequestMapping("/aideviceevent")
public class CenterdataTAideviceeventController extends BaseController {
    private final ICenterdataTAideviceeventService centerdataTAideviceeventService;

    private final RemoteEventBaseService remoteEventBaseService;

    public CenterdataTAideviceeventController(ICenterdataTAideviceeventService centerdataTAideviceeventService, RemoteEventBaseService remoteEventBaseService) {
        this.centerdataTAideviceeventService = centerdataTAideviceeventService;
        this.remoteEventBaseService = remoteEventBaseService;
    }

    /**
     * 查询AI对应事件列表
     */
    @Log(title = "AI对应事件", businessType = BusinessType.OTHER)
    @ApiOperation(value = "查询AI对应事件列表", notes = "查询AI对应事件列表")
    @RequiresPermissions("aideviceevent:aideviceevent:list")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id", dataType = "String"),
            @ApiImplicitParam(name = "deviceCode", value = "设备code", dataType = "String")
    })
    public TableDataInfo list(CenterdataTAideviceevent centerdataTAideviceevent) {
        startPage();
        List<CenterdataTAideviceevent> list = centerdataTAideviceeventService.selectCenterdataTAideviceeventList(centerdataTAideviceevent);
        return getDataTable(list);
    }

    /**
     * 导出AI对应事件列表
     */
    @ApiOperation(value = "导出AI对应事件列表", notes = "导出AI对应事件列表")
    @RequiresPermissions("aideviceevent:aideviceevent:export")
    @Log(title = "AI对应事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CenterdataTAideviceevent centerdataTAideviceevent) {
        List<CenterdataTAideviceevent> list = centerdataTAideviceeventService.selectCenterdataTAideviceeventList(centerdataTAideviceevent);
        ExcelUtil<CenterdataTAideviceevent> util = new ExcelUtil<>(CenterdataTAideviceevent.class);
        util.exportExcel(response, list, "AI对应事件数据");
    }

    /**
     * 获取AI对应事件详细信息
     */
    @Log(title = "AI对应事件", businessType = BusinessType.OTHER)
    @ApiOperation(value = "获取AI对应事件详细信息", notes = "获取AI对应事件详细信息")
    @RequiresPermissions("aideviceevent:aideviceevent:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(centerdataTAideviceeventService.selectCenterdataTAideviceeventById(id));
    }

    /**
     * 新增AI对应事件
     */
    @ApiOperation(value = "新增AI对应事件", notes = "新增AI对应事件")
    @RequiresPermissions("aideviceevent:aideviceevent:add")
    @Log(title = "AI对应事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CenterdataTAideviceevent centerdataTAideviceevent) {
        return toAjax(centerdataTAideviceeventService.insertCenterdataTAideviceevent(centerdataTAideviceevent));
    }

    /**
     * 修改AI对应事件
     */
    @ApiOperation(value = "修改AI对应事件", notes = "修改AI对应事件")
    @RequiresPermissions("aideviceevent:aideviceevent:edit")
    @Log(title = "AI对应事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CenterdataTAideviceevent centerdataTAideviceevent) {
        return toAjax(centerdataTAideviceeventService.updateCenterdataTAideviceevent(centerdataTAideviceevent));
    }

    /**
     * 删除AI对应事件
     */
    @ApiOperation(value = "删除AI对应事件", notes = "删除AI对应事件")
    @RequiresPermissions("aideviceevent:aideviceevent:remove")
    @Log(title = "AI对应事件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(centerdataTAideviceeventService.deleteCenterdataTAideviceeventByIds(ids));
    }

    /**
     * 查询事件类型选项
     */
    @Log(title = "AI对应事件", businessType = BusinessType.OTHER)
    @ApiOperation(value = "查询事件类型选项", notes = "查询事件类型选项")
    @RequiresPermissions("aideviceevent:aideviceevent:type")
    @RequestMapping(value = "/selectEventType",method = GET)
    public List<CentereventTEventtype> selectEventType() {
        return remoteEventBaseService.selectFirstEventType("0").getData();
    }
}
