DataController.java 1.38 KB
package com.viontech.controller;

import com.viontech.model.BaseModel;
import com.viontech.netty.ChannelGroup;
import com.viontech.process.ProcessService;
import com.viontech.utils.VideoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * .
 *
 * @author 谢明辉
 * @date 2020/8/18
 */
@RestController
@Slf4j
public class DataController {

    @Resource
    private ProcessService processService;

    @PostMapping("/data")
    public Object receiveData(@RequestBody String dataStr) throws Exception {
        BaseModel data = processService.process(dataStr);
        if (data != null) {
            ChannelGroup.broadcast(data);
        }
        return "success";
    }

    @PostMapping("/video")
    public Object receiveVideo(@RequestParam(name = "file") MultipartFile file, MultipartHttpServletRequest request) throws IOException {
        String refid = request.getParameter("refid");
        VideoUtil.addVideo(refid, file.getBytes());
        return "success";
    }


}