This commit is contained in:
2025-01-07 14:52:54 +08:00
parent ab08f7e169
commit d7b004ea80
4 changed files with 117 additions and 9 deletions

View File

@@ -1,9 +1,13 @@
package tcpserver
import (
"DT/model"
"DT/repository"
"encoding/json"
"errors"
"fmt"
"gorm.io/gorm"
"strconv"
"time"
)
@@ -46,16 +50,16 @@ func (s *Server) HandleAuth(client *Client, message []byte) error {
return fmt.Errorf("unauthorized")
}
model, err := repository.GroupRepositorys.Device.GetDevice(map[string]interface{}{"imei": msg.Imei})
mod, err := repository.GroupRepositorys.Device.GetDevice(map[string]interface{}{"imei": msg.Imei})
if err != nil {
return fmt.Errorf("设备不存在")
}
if msg.Pwd != model.DriverPass {
if msg.Pwd != mod.DriverPass {
return fmt.Errorf("设备密码不正确")
}
model.DriverVer = msg.Ver
err = repository.GroupRepositorys.Device.UpdateDevice(model)
mod.DriverVer = msg.Ver
err = repository.GroupRepositorys.Device.UpdateDevice(mod)
if err != nil {
return fmt.Errorf("更新设备版本号失败")
}
@@ -129,6 +133,29 @@ func (s *Server) TimingReporting(client *Client, message []byte) error {
if msg.Type != "up" {
return fmt.Errorf("unauthorized")
}
mod, err := repository.GroupRepositorys.DevUpData.GetDevUpData(map[string]interface{}{"imei": client.Imei})
fmt.Println(mod)
if err == nil {
mod.Mile = strconv.Itoa(msg.MessageUpData.Mile)
mod.Sum = strconv.Itoa(msg.MessageUpData.Sum)
mod.Time = strconv.Itoa(msg.MessageUpData.Time)
err = repository.GroupRepositorys.DevUpData.UpdateDevUpData(mod)
if err != nil {
return fmt.Errorf("更新设备定时上报信息错误\n")
}
} else if errors.Is(err, gorm.ErrRecordNotFound) {
devUpData := &model.DevUpData{}
devUpData.Imei = client.Imei
devUpData.Mile = strconv.Itoa(msg.MessageUpData.Mile)
devUpData.Sum = strconv.Itoa(msg.MessageUpData.Sum)
devUpData.Time = strconv.Itoa(msg.MessageUpData.Time)
err = repository.GroupRepositorys.DevUpData.CreateDevUpData(devUpData)
if err != nil {
return fmt.Errorf("设备定时上报存储失败\n")
}
}
fmt.Printf("设备定时上报数据:%v\r\n", msg.MessageUpData)
return nil
}