package com.zc.business.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.zc.business.domain.*;
import com.zc.business.service.DcEmergencyPlansService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 事件预案Controller
 *
 * @author wangjiabao
 * @date 2024-02-21
 */
@Api(tags = "事件预案")
@RestController
@RequestMapping("/business/plans")
public class DcEmergencyPlansController extends BaseController {

    @Autowired
    private DcEmergencyPlansService dcEmergencyPlansService;

    /**
     * 查询事件预案列表
     */
    @ApiOperation("查询事件预案列表")
//    @PreAuthorize("@ss.hasPermi('business:plans:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcEmergencyPlans dcEmergencyPlans) {
        startPage();
        List<DcEmergencyPlans> list = dcEmergencyPlansService.selectDcEmergencyPlansList(dcEmergencyPlans);
        return getDataTable(list);
    }

    /**
     * 根据事件预案id查询事件预案列表
     */
    @ApiOperation("根据事件预案id查询事件预案列表")
//    @PreAuthorize("@ss.hasPermi('business:plans:list')")
    @GetMapping("/list/{id}")
    public AjaxResult list(@PathVariable @ApiParam(name = "id", value = "事件预案id", required = true) Integer id) {

        DcEmergencyPlans dcEmergencyPlans = dcEmergencyPlansService.selectDcEmergencyPlans(id);
        return AjaxResult.success(dcEmergencyPlans);
    }

    /**
     * 交通事件-根据事件数据查询事件预案列表
     */
    @ApiOperation("交通事件-根据事件数据查询事件预案列表")
    @PreAuthorize("@ss.hasPermi('business:plans:list')")
    @PostMapping("/list/event/type")
    public AjaxResult listByEventType(@RequestBody DcEvent dcEvent) {

        List<DcEmergencyPlans> dcEmergencyPlansList = dcEmergencyPlansService.selectDcEmergencyPlansByEventType(dcEvent);
        dcEmergencyPlansService.dispositionDeviceContent(dcEmergencyPlansList,dcEvent);
        return AjaxResult.success(dcEmergencyPlansList);
    }

    /**
     * 设备管控-确认按钮生成内容
     */
    @ApiOperation("设备管控-确认按钮生成内容")
//    @PreAuthorize("@ss.hasPermi('business:plans:list')")
    @PostMapping("/list/event/emergencyPlans")
    public AjaxResult switchIntelligentPublishingToContent(@RequestBody DcEventAnDcEmergencyPlans dcEventAnDcEmergencyPlans) {
        return AjaxResult.success(dcEmergencyPlansService.confirmButtonToGenerateContent(dcEventAnDcEmergencyPlans,dcEventAnDcEmergencyPlans.getDcEvent()));
    }

    /**
     * 交通事件-根据事件、单个执行操作筛选设备
     */
    @ApiOperation("交通事件-根据事件、单个执行操作筛选设备")
    @PostMapping("/list/event/deviceList")
    public AjaxResult selectDeviceListByEventDcExecuteAction(@RequestBody DcEventAnDcEmergencyPlans dcEventAnDcEmergencyPlans) {
        return AjaxResult.success(dcEmergencyPlansService.selectDeviceListByEventDcExecuteAction(dcEventAnDcEmergencyPlans));
    }

    /**
     * 交通事件-情报板确认回显原始模板
     */
    @ApiOperation("交通事件-情报板确认回显原始模板")
    @PreAuthorize("@ss.hasPermi('business:plans:list')")
    @PostMapping("/event/board/confirm")
    public AjaxResult eventBoardConfirm(@RequestBody DcEventAnDcEmergencyPlans dcEventAnDcEmergencyPlans) {
        return AjaxResult.success(dcEmergencyPlansService.eventBoardConfirm(dcEventAnDcEmergencyPlans));
    }

    /**
     * 交通事件-情报板自动生成文字
     */
//    @ApiOperation("交通事件-情报板自动生成文字")
    @PostMapping("/event/automatic")
    public AjaxResult eventAutomaticGeneration(@RequestBody DcEventAnDcEmergencyPlans dcEventAnDcEmergencyPlans) {
        return AjaxResult.success(dcEmergencyPlansService.eventAutomaticGeneration(dcEventAnDcEmergencyPlans));
    }

    /**
     * 交通事件确定
     */
    @ApiOperation("交通事件确定")
    @PreAuthorize("@ss.hasPermi('business:plans:edit')")
    @PostMapping("/event/confirm")
    public AjaxResult eventConfirm(@RequestBody DcEventAnDcEmergencyPlans dcEventAnDcEmergencyPlans) {
        return AjaxResult.success(dcEmergencyPlansService.executionEventConfirmation(dcEventAnDcEmergencyPlans));
    }

    /**
     * 根据事件id-查询预案事件关联表
     */
    @ApiOperation("根据事件id-查询预案事件关联表")
    @GetMapping("/event/assoc/{id}")
    public AjaxResult eventConfirmByEventId(@PathVariable("id") String id) {
        return AjaxResult.success(dcEmergencyPlansService.selectEventPlanAssocByEventId(id));
    }

    /**
     * 根据id-查询预案事件关联表
     */
    @ApiOperation("根据id-查询预案事件关联表")
    @GetMapping("/event/assocId/{assocId}")
    public AjaxResult eventConfirmById(@PathVariable("assocId") Long assocId) {
        return AjaxResult.success(dcEmergencyPlansService.selectEventPlanAssocById(assocId));
    }

    /**
     * 新增事件预案
     */
    @ApiOperation("新增预案")
    @PreAuthorize("@ss.hasPermi('business:plans:add')")
    @PostMapping
    public AjaxResult add(@RequestBody DcEmergencyPlans dcEmergencyPlans) {
        return toAjax(dcEmergencyPlansService.insertDcEmergencyPlans(dcEmergencyPlans));
    }

    /**
     * 修改事件预案
     */
    @ApiOperation("修改预案")
    @PreAuthorize("@ss.hasPermi('business:plans:edit')")
    @PutMapping
    public AjaxResult update(@RequestBody DcEmergencyPlans dcEmergencyPlans) {
        return toAjax(dcEmergencyPlansService.updateDcEmergencyPlans(dcEmergencyPlans));
    }

    /**
     * 批量删除事件预案
     */
    @ApiOperation("批量删除预案")
    @PreAuthorize("@ss.hasPermi('business:plans:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult update(@PathVariable String[] ids) {
        return toAjax(dcEmergencyPlansService.deleteDcEmergencyPlans(ids));
    }
}