Ver código fonte

统计车的体积

engineerper 1 ano atrás
pai
commit
c596bf5b22
4 arquivos alterados com 56 adições e 29 exclusões
  1. 24 16
      config.yaml
  2. 2 9
      config/config.go
  3. 29 3
      eventServer/eventServer.go
  4. 1 1
      model/app/carinfo.go

+ 24 - 16
config.yaml

@@ -67,19 +67,27 @@ camera2:
   a: [500, 450, 400, 350, 300, 250, 200, 150, 100, 50]
 #泥头车的长宽高和体积
 dump:
-  #20尺柜,毛重17.5吨
-  a: [5.69,2.13,2.18,26]
-  #40尺柜,毛重22吨
-  b: [11.8,2.13,2.18,54]
-  #40尺高柜,毛重22吨
-  c: [11.8,2.13,2.72,68]
-  #45尺高柜,毛重29吨
-  d: [13.58,2.34,2.71,86]
-  #20尺开顶柜,毛重20吨
-  e: [5.89,2.32,2.31,31.5]
-  #40尺开顶柜,毛重30.4吨
-  f: [12.01,2.33,2.15,65]
-  #20尺平底柜,毛重23吨
-  g: [5.85,2.23,2.15,28]
-  #40尺平底柜,毛重36吨
-  h: [12.05,2.12,1.96,50]
+    #20尺柜,毛重17.5吨
+   -
+    [5.69,2.13,2.18,26]
+    #40尺柜,毛重22吨
+   -
+     [11.8,2.13,2.18,54]
+    #40尺高柜,毛重22吨
+   -
+     [11.8,2.13,2.72,68]
+     #45尺高柜,毛重29吨
+   -
+    [13.58,2.34,2.71,86]
+    #20尺开顶柜,毛重20吨
+   -
+    [5.89,2.32,2.31,31.5]
+    #40尺开顶柜,毛重30.4吨
+   -
+    [12.01,2.33,2.15,65]
+    #20尺平底柜,毛重23吨
+   -
+    [5.85,2.23,2.15,28]
+    #40尺平底柜,毛重36吨
+   -
+    [12.05,2.12,1.96,50]

+ 2 - 9
config/config.go

@@ -37,7 +37,7 @@ type config struct {
 	Foreign                  Foreign                  `mapstructure:"foreign" yaml:"foreign" json:"foreign"`
 	Hikvision                Hikvision                `mapstructure:"hikvision" yaml:"hikvision" json:"hikvision"`
 	Metering                 Metering                 `mapstructure:"metering" yaml:"metering" json:"metering"`
-	Dump                     Dump                     `mapstructure:"dump" yaml:"dump" json:"dump"`
+	Dump                     [][]float64              `mapstructure:"dump" yaml:"dump" json:"dump"`
 }
 
 type System struct {
@@ -152,12 +152,5 @@ type Metering struct {
 }
 
 type Dump struct {
-	A []float64 `yaml:"a"`
-	B []float64 `yaml:"b"`
-	C []float64 `yaml:"c"`
-	D []float64 `yaml:"d"`
-	E []float64 `yaml:"e"`
-	F []float64 `yaml:"f"`
-	G []float64 `yaml:"g"`
-	H []float64 `yaml:"h"`
+	Dump [][]float64 `yaml:"dump"`
 }

+ 29 - 3
eventServer/eventServer.go

@@ -2,6 +2,7 @@ package eventServer
 
 import (
 	"encoding/xml"
+	"errors"
 	"fmt"
 	"github.com/sirupsen/logrus"
 	mail "github.com/xhit/go-simple-mail/v2"
@@ -35,9 +36,32 @@ func StartEventServer() {
 	go func() {
 		for {
 			l, w, h := CalcCap()
-			time.Sleep(500 * time.Millisecond)
-			//todo 根据长宽高估计车厢体积
+			dumps := []Constant{
+				{l, w, h, l * w * h},
+			}
+			// 遍历结构体并进行比对
+			for _, variable := range global.Config.Dump {
+				bestMatch := FindBestMatch(dumps, Constant{
+					variable[0], variable[1], variable[2], variable[3],
+				})
+				fmt.Println("最匹配的常量数据:", bestMatch)
+				//todo 保存数据库
+				var cars []*app.CarInfo
+				newCar := &app.CarInfo{
+					Height: bestMatch.Height,
+					Width:  bestMatch.Width,
+					Length: bestMatch.Length,
+					Volume: bestMatch.Volume,
+					Count:  1,
+					Time:   time.Now(),
+				}
+				cars = append(cars, newCar) //将新创建的车辆信息添加到cars切片的末尾
+				// 保存到数据库
+				carInfoService.Save(cars)
+			}
 			fmt.Println("长", l, "宽", w, "高", h)
+			time.Sleep(500 * time.Millisecond)
+
 		}
 	}()
 	http.HandleFunc("/event", handler)
@@ -98,7 +122,9 @@ func handleMultipart(r *http.Request) {
 	var eventAlert EventNotificationAlert
 	for {
 		part, err := multipartReader.NextPart()
-		if err == io.EOF {
+		fmt.Println("is", errors.Is(err, io.EOF))
+		fmt.Println("as", errors.As(err, &io.EOF))
+		if errors.Is(err, io.EOF) {
 			break
 		}
 		if err != nil {

+ 1 - 1
model/app/carinfo.go

@@ -10,7 +10,7 @@ type CarInfo struct {
 	global.GVA_MODEL
 	PlateNumber string `json:"plateNumber" form:"plateNumber" gorm:"column:plate_number;comment:车牌号;"`
 	//CarType     string    `json:"carType" form:"carType" gorm:"column:car_type;comment:车类型;"`
-	Long   float64   `json:"long" form:"long" gorm:"column:long;comment:长度;"`
+	Length float64   `json:"Length" form:"Length" gorm:"column:Length;comment:长度;"`
 	Width  float64   `json:"width" form:"width" gorm:"column:width;comment:宽度;"`
 	Height float64   `json:"height" form:"height" gorm:"column:height;comment:高度;"`
 	Time   time.Time `json:"time" form:"time" gorm:"column:time;comment:出现时间;"`