|
@@ -2,7 +2,6 @@ package backend
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
- "encoding/json"
|
|
|
"fmt"
|
|
|
"kpt-pasture/model"
|
|
|
"kpt-pasture/util"
|
|
@@ -10,42 +9,49 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
- "go.uber.org/zap"
|
|
|
-
|
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- eidStart = 7
|
|
|
- eidEndLen = 64 + 7 - eidStart
|
|
|
+ eidEndLen = 8
|
|
|
+ eidStart = 63 + 7 - eidEndLen
|
|
|
)
|
|
|
|
|
|
// GEAMILK gea品牌实现
|
|
|
type GEAMILK struct {
|
|
|
store *StoreEntry
|
|
|
+ body *model.MilkHallBody
|
|
|
}
|
|
|
|
|
|
-func (a *GEAMILK) SaveData(ctx context.Context, body *model.MilkHallBody) error {
|
|
|
- gEAMilkHallOriginalList := make([]*model.GEAMilkHallOriginal, 0)
|
|
|
- if err := json.Unmarshal(body.Content, &gEAMilkHallOriginalList); err != nil {
|
|
|
- return xerr.WithStack(err)
|
|
|
+func (a *GEAMILK) SaveData(ctx context.Context) error {
|
|
|
+ if len(a.body.Content) <= 0 {
|
|
|
+ return nil
|
|
|
}
|
|
|
- nowTime := time.Now()
|
|
|
- zaplog.Info("GEAMILK", zap.String("nowTime", nowTime.Format(model.LayoutTime)), zap.Any("body", body))
|
|
|
- pastureData := &model.PastureList{}
|
|
|
- if err := a.store.DB.Model(new(model.PastureList)).
|
|
|
- Where("farm_id = ?", body.FarmId).
|
|
|
+
|
|
|
+ pastureData := &model.AppPastureList{}
|
|
|
+ if err := a.store.DB.Model(new(model.AppPastureList)).
|
|
|
+ Where("farm_id = ?", a.body.FarmId).
|
|
|
First(pastureData).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
+ nowTime := time.Now()
|
|
|
gEAOriginalList := make([]*model.MilkOriginal, 0)
|
|
|
- for _, gea := range gEAMilkHallOriginalList {
|
|
|
+ for _, v := range a.body.Content {
|
|
|
+ content, ok := v.(map[string]interface{})
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
- text := gea.Vstr
|
|
|
+ t, ok := content["vstr"]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ text := t.(string)
|
|
|
s1 := strings.TrimSpace(util.Substr(text, 0, 6))
|
|
|
- milkWeight, _ := strconv.ParseInt(strings.TrimSpace(util.Substr(text, 25, 4)), 10, 64)
|
|
|
+ milkWeight, _ := strconv.ParseFloat(strings.TrimSpace(util.Substr(text, 25, 4)), 64)
|
|
|
+
|
|
|
+ fmt.Println("milkWeight:", milkWeight, strings.TrimSpace(util.Substr(text, 25, 4)))
|
|
|
|
|
|
if len(s1) == 0 && milkWeight == 0 {
|
|
|
continue
|
|
@@ -63,25 +69,23 @@ func (a *GEAMILK) SaveData(ctx context.Context, body *model.MilkHallBody) error
|
|
|
hour2 := strings.TrimSpace(util.Substr(text, 44, 2))
|
|
|
minute2 := strings.TrimSpace(util.Substr(text, 46, 2))
|
|
|
second2 := strings.TrimSpace(util.Substr(text, 49, 2))
|
|
|
- if hour == "00" {
|
|
|
- if hour1 == "23" {
|
|
|
- milkDate = nowTime.AddDate(0, 0, -1).Format(model.LayoutDate2)
|
|
|
- } else {
|
|
|
- milkDate = nowTime.Format(model.LayoutDate2)
|
|
|
- }
|
|
|
-
|
|
|
- if hour2 == "23" {
|
|
|
- attachTime = nowTime.AddDate(0, 0, -1).Format(model.LayoutDate2)
|
|
|
- } else {
|
|
|
- attachTime = nowTime.Format(model.LayoutTime)
|
|
|
- }
|
|
|
+ if hour == "00" && hour1 == "23" {
|
|
|
+ milkDate = nowTime.AddDate(0, 0, -1).Format(model.LayoutDate2)
|
|
|
+ } else {
|
|
|
+ milkDate = nowTime.Format(model.LayoutDate2)
|
|
|
+ }
|
|
|
+
|
|
|
+ if hour == "00" && hour2 == "23" {
|
|
|
+ attachTime = nowTime.AddDate(0, 0, -1).Format(model.LayoutDate2)
|
|
|
+ } else {
|
|
|
+ attachTime = nowTime.Format(model.LayoutDate2)
|
|
|
}
|
|
|
- milkDate = fmt.Sprintf("%s %s:%s:%s", milkDate, hour1, minute1, second1)
|
|
|
- attachTime = fmt.Sprintf("%s %s:%s:%s", attachTime, hour2, minute2, second2)
|
|
|
|
|
|
- detachTime := fmt.Sprintf("%s %s:%s:%s", nowTime, hour, minute, second)
|
|
|
+ recognitionTime := fmt.Sprintf("%s %02s:%02s:%02s", nowTime.Format(model.LayoutDate2), hour1, minute1, second1)
|
|
|
+ attachTime = fmt.Sprintf("%s %02s:%02s:%02s", attachTime, hour2, minute2, second2)
|
|
|
+ detachTime := fmt.Sprintf("%s %02s:%02s:%02s", nowTime.Format(model.LayoutDate2), hour, minute, second)
|
|
|
earNumber := fmt.Sprintf("%s", strings.TrimSpace(util.Substr(text, 7, 6)))
|
|
|
- detacherAddress, _ := strconv.ParseInt(strings.TrimSpace(util.Substr(text, 20, 2)), 10, 64)
|
|
|
+ detachAddress, _ := strconv.ParseInt(strings.TrimSpace(util.Substr(text, 20, 2)), 10, 64)
|
|
|
|
|
|
duration, _ := strconv.ParseFloat(strings.TrimSpace(util.Substr(text, 31, 4)), 64)
|
|
|
peakFlow, _ := strconv.ParseFloat(strings.TrimSpace(util.Substr(text, 52, 4)), 64)
|
|
@@ -99,8 +103,9 @@ func (a *GEAMILK) SaveData(ctx context.Context, body *model.MilkHallBody) error
|
|
|
f60t120, _ := strconv.ParseInt(strings.TrimSpace(util.Substr(text, 105, 3)), 10, 64)
|
|
|
manualDetach, _ := strconv.ParseInt(strings.TrimSpace(util.Substr(text, 109, 1)), 10, 64)
|
|
|
|
|
|
- newGEAOriginal := model.NewGEAMilkOriginal(pastureData.Id, body.MilkHallNumber, detachTime, earNumber, milkDate, attachTime,
|
|
|
- milkWeight, detacherAddress, duration, peakFlow, int32(conductivity), eId, f0t15, f15t30, f30t60, f60t120, int8(manualDetach))
|
|
|
+ newGEAOriginal := model.NewGEAMilkOriginal(
|
|
|
+ pastureData.Id, a.body.Brand, a.body.MilkHallNumber, detachTime, earNumber, milkDate, attachTime, recognitionTime, milkWeight,
|
|
|
+ detachAddress, duration, peakFlow, int32(conductivity), eId, f0t15, f15t30, f30t60, f60t120, int8(manualDetach))
|
|
|
gEAOriginalList = append(gEAOriginalList, newGEAOriginal)
|
|
|
}
|
|
|
|