Initial commit of secondary development sample code

This commit is contained in:
2026-01-19 10:39:22 +08:00
commit c2697affd9
66 changed files with 17277 additions and 0 deletions

View File

@ -0,0 +1,37 @@
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping(path = "")
public class AlertController {
/**
* 目标平台接收告警及告警图片
*
* @param alertMsg
*/
@PostMapping(path = "/alert")
public void getAlertMsg(@RequestBody AlertMsg alertMsg) {
log.info("示例接收告警及告警图片:{}", alertMsg);
}
/**
* 目标平台接收告警及告警视频
*
* @param alertVideo
*/
@PostMapping(path = "/video")
public void getAlertVideo(@RequestBody AlertVideo alertVideo) {
log.info("示例接收告警及告警视频:{}", alertVideo);
}
}

View File

@ -0,0 +1,21 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class AlertMsg {
private String id;
@JsonProperty("alert_time")
private Double alertTime;
private Object device;
private Object source;
private Object alg;
private String image;
@JsonProperty("reserved_data")
private Object reservedData;
@JsonProperty("hazard_leve")
private String hazardLeve;
}

View File

@ -0,0 +1,19 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class AlertVideo {
private String id;
@JsonProperty("alert_time")
private Double alertTime;
private Object device;
private Object source;
private Object alg;
private String video;
@JsonProperty("hazard_leve")
private String hazardLeve;
}

View File

@ -0,0 +1,23 @@
import os
import sys
from flask import Flask
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
sys.path.append(CURRENT_PATH)
url_prefix = '/'
from app import alert
def create_app():
# 初始化Flask对象
app_ = Flask(__name__)
# 注册蓝图
app_.register_blueprint(alert.bp)
return app_
app = create_app()

View File

@ -0,0 +1,28 @@
import base64
import json
from flask import Blueprint, request
from app import url_prefix
bp = Blueprint('alert', __name__, url_prefix=url_prefix)
@bp.route('alert', methods=['POST'])
def post_alert():
data = json.loads(request.get_data().decode('utf-8'))
image = data.pop('image')
print(data)
with open('image.jpg', 'wb') as f:
f.write(base64.b64decode(image.encode('utf-8')))
return data
@bp.route('alert/video', methods=['POST'])
def post_alert_video():
data = json.loads(request.get_data().decode('utf-8'))
video = data.pop('video')
print(data)
with open('video.mp4', 'wb') as f:
f.write(base64.b64decode(video.encode('utf-8')))
return data

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

View File

@ -0,0 +1,4 @@
from app import app
if '__main__' == __name__:
app.run(host='0.0.0.0', port=10000, debug=False)