package com.yuchen.saas.park.service.controller.security;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.security.WarningAddDTO;
import com.yuchen.saas.park.api.dto.security.WarningPageQueryDTO;
import com.yuchen.saas.park.api.vo.park.security.*;
import com.yuchen.saas.park.service.service.PmgBatSecurityWarningService;
import com.yuchen.saas.park.service.service.PmgBatSmartEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 颜艺波
 * @date 2022/6/20 10:55
 * @Description
 */
@RestController
@RequestMapping("/security")
@Api(value = "火炬安防", tags = "火炬安防")
public class SecurityWarningController {

    @Autowired
    PmgBatSmartEquipmentService equipmentService;

    @Autowired
    PmgBatSecurityWarningService securityWarningService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "安防设备在线统计", notes = "安防设备在线统计")
    @GetMapping("/onlineStatistic/{parkId}")
    public R<OnlineStatisticVO> onlineStatistic(@PathVariable("parkId") Long parkId) {
        return R.data(equipmentService.onlineStatistic(parkId, 6));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "安防设备列表查询", notes = "安防设备列表查询")
    @GetMapping("/deviceList")
    public R<List<DeviceListVO>> deviceList(@RequestParam("parkId") Long parkId, String name) {
        return R.data(equipmentService.deviceList(parkId, 6, name));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "安防今日预警行为趋势", notes = "安防今日预警行为趋势")
    @GetMapping("/warningTrendToday/{parkId}")
    public R<List<WarningTrendVO>> warningTrendToday(@PathVariable("parkId") Long parkId) {
        return R.data(securityWarningService.warningTrendToday(parkId));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "安防最新预警行为查询", notes = "安防最新预警行为查询")
    @GetMapping("/latestWarningQuery/{parkId}")
    public R<LatestWarningQueryVO> latestWarningQuery(@PathVariable("parkId") Long parkId) {
        return R.data(securityWarningService.latestWarningQuery(parkId));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "安防预警行为分页查询", notes = "安防预警行为分页查询")
    @GetMapping("/warningPageQuery")
    public R<IPage<SecurityWarningVO>> warningPageQuery(@Valid WarningPageQueryDTO warningPageQueryDTO, Query query) {
        return R.data(securityWarningService.warningPageQuery(warningPageQueryDTO, query));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "安防预警行为新增", notes = "安防预警行为新增")
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody WarningAddDTO warningAddDTO) {
        warningAddDTO.setTriggerTime(System.currentTimeMillis());
        return R.data(securityWarningService.add(warningAddDTO));
    }
}
