VAServerController.java 4.25 KB
package com.viontech.fanxing.task.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.task.model.vaserver.VaServerInfo;
import com.viontech.fanxing.task.model.vaserver.VaServerOverViewModel;
import com.viontech.fanxing.task.service.VAServerService;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;

/**
 * .
 *
 * @author 谢明辉
 * @date 2021/7/13
 */

@RestController
@Slf4j
public class VAServerController {

    @Resource
    private VAServerService vaServerService;
    @Resource
    private VionConfig vionConfig;

    /**
     * 注册
     */
    @PostMapping("/register")
    public Object register(@RequestBody VaServerInfo vaServerInfo) {
        log.info("收到注册消息:{}", JSON.toJSONString(vaServerInfo));
        vaServerService.registerVAServer(vaServerInfo);
        HashMap<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "success");
        result.put("resultRecvUrl", vionConfig.getReceiveResultPrefixPath() + "/fanxing-forward/result");
        result.put("videoUploadUrl", vionConfig.getReceiveResultPrefixPath() + "/fanxing-forward/result/video");
        return result;
    }

    /**
     * 心跳
     */
    @GetMapping("/keepalive/{devId}")
    public Object keepalive(@PathVariable String devId) {
        log.info("收到心跳消息:{}", devId);
        vaServerService.keepalive(devId);
        return JsonMessageUtil.getSuccessJsonMsg("success");
    }

    @GetMapping("/vaServerInfo")
    public Object getVaServerInfo() {
        RMap<String, VaServerInfo> vaServerInfoMap = vaServerService.getVaServerRedisRepository().getVaServerInfoMap();
        return JsonMessageUtil.getSuccessJsonMsg(vaServerInfoMap.values());
    }

    /**
     * 获取分析视频点播地址
     */
    @GetMapping("/getAnalyzeStream")
    public Object getAnalyzeStream(@RequestParam String taskUnid) {
        return vaServerService.getAnalyzeStream(taskUnid);
    }

    /**
     * 输出分析流,每30秒调一次,不调用就不再输出视频流
     */
    @PostMapping("/startAnalyzeStream")
    public Object startAnalyzeStream(@RequestBody JSONObject object) {
        String taskUnid = object.getString("taskUnid");
        String s = vaServerService.startAnalyzeStream(taskUnid);
        return JsonMessageUtil.getSuccessJsonMsg("success", s);
    }

    /**
     * 获取vaServer运行状态,配置等信息
     */
    @GetMapping("/status")
    public Object status(@RequestParam String devId) {
        return vaServerService.getStatus(devId);
    }


    /**
     * 切换场景/预置位
     */
    @GetMapping("/switchScene")
    public Object switchScene(@RequestParam String taskUnid, String sceneId) {
        return vaServerService.switchScene(taskUnid, sceneId);
    }

    /**
     * 截图
     */
    @GetMapping("/snapshot")
    public Object snapshot(@RequestParam String taskUnid) {
        return vaServerService.snapshot(taskUnid);
    }

    @GetMapping("/updateRotationStatus")
    public Object updateRotationStatus(@RequestParam String taskUnid, @RequestParam Integer status) {
        return vaServerService.updateRotationStatus(taskUnid, status);
    }

    @GetMapping("/getRotationStatus")
    public Object getRotationStatus(@RequestParam String taskUnid) {
        return vaServerService.getRotationStatus(taskUnid);
    }

    @GetMapping("/getCurrentScene")
    public Object getCurrentScene(@RequestParam String taskUnid) {
        return vaServerService.getCurrentScene(taskUnid);
    }

    /**
     * @param type 任务的类型 0 交通, 1 客流, 2 安防, 3 违停, 4 人脸
     */
    @GetMapping("/getDefaultAlgorithmConfig")
    public Object getDefaultAlgorithmConfig(@RequestParam String type) {
        return vaServerService.getDefaultAlgorithmConfig(type);
    }

    @GetMapping("/vaServer/overview")
    public Object vaServerOverview() {
        Collection<VaServerOverViewModel> result = vaServerService.vaServerOverview();
        return JsonMessageUtil.getSuccessJsonMsg(result);
    }

}