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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgLogVideoEventsCount;
import com.yuchen.saas.park.service.service.PmgLogVideoEventsCountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
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.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 张逸飞
 * @Date: 2021/2/20 13:57
 * @Description: 视频行为
 */
@RestController
@AllArgsConstructor
@RequestMapping("/video_events")
@Api(value = "视频行为", tags = "视频行为接口")
public class PmgLogVideoEventsCountController {


    @Autowired
    private PmgLogVideoEventsCountService pmgLogVideoEventsCountService;

    /**
     * 新增 视频行为信息
     * @param pmgLogVideoEventsCount 视频行为信息
     * @return
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增 视频行为信息", notes = "新增 视频行为信息")
    public R save(@Valid @RequestBody PmgLogVideoEventsCount pmgLogVideoEventsCount) {
        return R.status(pmgLogVideoEventsCountService.save(pmgLogVideoEventsCount));
    }

    /**
     * 查询行为预警
     * @return
     */
    @GetMapping("/getBehaviorWarning")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查询行为预警", notes = "查询行为预警")
    public R<Map<String,Object>> getBehaviorWarning(){
        // 查询未处理的数据
        List<PmgLogVideoEventsCount> pmgLogVideoEventsCountList = pmgLogVideoEventsCountService.getNoProcessingList();
        // 获取事件的数据总数
        Integer total = pmgLogVideoEventsCountService.count();
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("noProcessingList",pmgLogVideoEventsCountList);
        resultMap.put("noProcessingNumber",pmgLogVideoEventsCountList.size());
        resultMap.put("total",total);
        return R.data(resultMap);
    }

    /**
     * 查询行为预警趋势
     * @return
     */
    @GetMapping("/getCountTime24")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "行为预警趋势", notes = "行为预警趋势")
    public R<Map<String, Object>> getCountTime24(){
        return R.data(pmgLogVideoEventsCountService.getCountTime24());
    }

    /**
     * 查询行为预警分页列表
     * @param pmgLogVideoEventsCount 需要查询的条件数据
     * @param query 分页数据
     * @return
     */
    @GetMapping("/getPage")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "查询行为预警分页列表", notes = "查询行为预警分页列表")
    public R<IPage<PmgLogVideoEventsCount>> getPage(PmgLogVideoEventsCount pmgLogVideoEventsCount, Query query){
        return R.data(pmgLogVideoEventsCountService.getListAbnormalBehavior(pmgLogVideoEventsCount, query));
    }

    /**
     * 处理行为预警
     * @param id 需要处理的行为事件ID
     * @param handlerName 处理人姓名
     * @return
     */
    @PostMapping("/handlingWarnings")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "处理行为预警", notes = "处理行为预警")
    public R handlingWarnings(@RequestParam String id, @RequestParam String handlerName){
        if (pmgLogVideoEventsCountService.handlingWarnings(id,handlerName) > 0){
            return R.status(true);
        }else{
            return R.status(false);
        }
    }

}
