|
@@ -2,6 +2,7 @@ package eventServer
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/xml"
|
|
"encoding/xml"
|
|
|
|
+ "errors"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sirupsen/logrus"
|
|
mail "github.com/xhit/go-simple-mail/v2"
|
|
mail "github.com/xhit/go-simple-mail/v2"
|
|
@@ -35,9 +36,32 @@ func StartEventServer() {
|
|
go func() {
|
|
go func() {
|
|
for {
|
|
for {
|
|
l, w, h := CalcCap()
|
|
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)
|
|
fmt.Println("长", l, "宽", w, "高", h)
|
|
|
|
+ time.Sleep(500 * time.Millisecond)
|
|
|
|
+
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
http.HandleFunc("/event", handler)
|
|
http.HandleFunc("/event", handler)
|
|
@@ -98,7 +122,9 @@ func handleMultipart(r *http.Request) {
|
|
var eventAlert EventNotificationAlert
|
|
var eventAlert EventNotificationAlert
|
|
for {
|
|
for {
|
|
part, err := multipartReader.NextPart()
|
|
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
|
|
break
|
|
}
|
|
}
|
|
if err != nil {
|
|
if err != nil {
|