|
@@ -7,11 +7,14 @@ import (
|
|
mail "github.com/xhit/go-simple-mail/v2"
|
|
mail "github.com/xhit/go-simple-mail/v2"
|
|
"io"
|
|
"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
+ "lc-fangdaosha/global"
|
|
"lc-fangdaosha/model/app"
|
|
"lc-fangdaosha/model/app"
|
|
"lc-fangdaosha/service"
|
|
"lc-fangdaosha/service"
|
|
"log"
|
|
"log"
|
|
|
|
+ "math"
|
|
"mime/multipart"
|
|
"mime/multipart"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
@@ -68,6 +71,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|
var eventService = service.ServiceGroupApp.AppServiceGroup.EventService
|
|
var eventService = service.ServiceGroupApp.AppServiceGroup.EventService
|
|
var carInfoService = service.ServiceGroupApp.AppServiceGroup.CarInfoService
|
|
var carInfoService = service.ServiceGroupApp.AppServiceGroup.CarInfoService
|
|
|
|
|
|
|
|
+// 保留小数
|
|
|
|
+func round(num float64, places int) float64 {
|
|
|
|
+ shift := math.Pow(10, float64(places))
|
|
|
|
+ return math.Round(num*shift) / shift
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var bulk = make(map[string][]float64)
|
|
|
|
+
|
|
// 处理多文件事件
|
|
// 处理多文件事件
|
|
func handleMultipart(r *http.Request) {
|
|
func handleMultipart(r *http.Request) {
|
|
// todo 远程联动
|
|
// todo 远程联动
|
|
@@ -103,7 +114,45 @@ func handleMultipart(r *http.Request) {
|
|
eventCode := part.Header.Get("Content-ID")
|
|
eventCode := part.Header.Get("Content-ID")
|
|
picName := timeFmt(eventAlert.DateTime) + ".jpeg"
|
|
picName := timeFmt(eventAlert.DateTime) + ".jpeg"
|
|
data, _ := ioutil.ReadAll(part)
|
|
data, _ := ioutil.ReadAll(part)
|
|
- if strings.Contains(eventAlert.ChannelName, "PlateNumber") {
|
|
|
|
|
|
+ if strings.Contains(eventAlert.ChannelName, "plateNumber") {
|
|
|
|
+ //todo 识别车牌,记录次数
|
|
|
|
+ number, err := CallLicensePlateRecognitionAPI(data)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("车牌识别失败:", err)
|
|
|
|
+ //time.Sleep(1000)
|
|
|
|
+ }
|
|
|
|
+ //todo 处理车牌号
|
|
|
|
+ carInfoService.ProcessPlateNumber(number)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if strings.Contains(eventAlert.ChannelName, "metering1") {
|
|
|
|
+ //todo 测量车的长度和高度
|
|
|
|
+ targetRect := eventAlert.DetectionRegionList.DetectionRegionEntry[0].TargetRect
|
|
|
|
+ //x, _ := strconv.ParseFloat(targetRect.X, 64)
|
|
|
|
+ y, _ := strconv.ParseFloat(targetRect.Y, 64)
|
|
|
|
+ h, _ := strconv.ParseFloat(targetRect.Height, 64)
|
|
|
|
+ w, _ := strconv.ParseFloat(targetRect.Width, 64)
|
|
|
|
+ n := int(round(y+h, 1) * 10)
|
|
|
|
+ b := float64(global.Config.Metering.Camera1.B[n])
|
|
|
|
+ a := float64(global.Config.Metering.Camera1.A[n])
|
|
|
|
+ rh := h / (y + h) * b
|
|
|
|
+ rl := w * a
|
|
|
|
+ dateTime := eventAlert.DateTime
|
|
|
|
+ bulk[dateTime] = append(bulk[dateTime], rh, rl)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if strings.Contains(eventAlert.ChannelName, "metering2") {
|
|
|
|
+ //todo 测量车的宽度
|
|
|
|
+ targetRect := eventAlert.DetectionRegionList.DetectionRegionEntry[0].TargetRect
|
|
|
|
+ //x, _ := strconv.ParseFloat(targetRect.X, 64)
|
|
|
|
+ y, _ := strconv.ParseFloat(targetRect.Y, 64)
|
|
|
|
+ h, _ := strconv.ParseFloat(targetRect.Height, 64)
|
|
|
|
+ w, _ := strconv.ParseFloat(targetRect.Width, 64)
|
|
|
|
+ n := int(round(y+h, 1) * 10)
|
|
|
|
+ a := float64(global.Config.Metering.Camera2.A[n])
|
|
|
|
+ rw := w * a
|
|
|
|
+ dateTime := eventAlert.DateTime
|
|
|
|
+ bulk[dateTime] = append(bulk[dateTime], rw)
|
|
//todo 识别车牌,记录次数
|
|
//todo 识别车牌,记录次数
|
|
number, err := CallLicensePlateRecognitionAPI(data)
|
|
number, err := CallLicensePlateRecognitionAPI(data)
|
|
if err != nil {
|
|
if err != nil {
|