From 288d78f66ecd1b628e8d1df7a3da99fc5e6880ec Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 08 十二月 2023 14:13:37 +0800 Subject: [PATCH] debug --- service/report_work.go | 44 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 10 deletions(-) diff --git a/service/report_work.go b/service/report_work.go index 710b490..4d7a0cb 100644 --- a/service/report_work.go +++ b/service/report_work.go @@ -5,8 +5,12 @@ "apsClient/constvar" "apsClient/model" "apsClient/model/request" + "apsClient/pkg/logx" "apsClient/pkg/snowflake" + "encoding/json" "errors" + "github.com/jinzhu/gorm" + "github.com/spf13/cast" "time" ) @@ -30,22 +34,22 @@ for _, worker := range procedure.ProceduresInfo.Workers { if params.WorkerID == worker.WorkerID { workerName = worker.WorkerName - if worker.StartTime < nowTs { - startTs = worker.StartTime - } } } if workerName == "" { return errors.New("娌℃湁鎵惧埌褰撳墠鍊肩彮浜哄憳") } - if startTs == 0 { - return errors.New("娌℃湁鎵惧埌褰撳墠鍊肩彮浜哄憳寮�濮嬫椂闂�") - } + finishAmount := params.ReportAmount lastReportWork, err := GetLastReportWork(params.ProcedureId) if err == nil { + if params.ReportAmount < lastReportWork.ReportAmount { + return errors.New("鎶ュ伐鏁伴噺涓嶈兘灏戜簬涓婃鎶ュ伐鏁�") + } finishAmount = params.ReportAmount - lastReportWork.ReportAmount startTs = lastReportWork.EndTime + } else { + startTs = procedure.RealStartTime } record := &model.ReportWork{ @@ -55,7 +59,6 @@ DeviceID: procedure.DeviceID, DeviceName: procedure.ProceduresInfo.DeviceName, ProcedureID: procedure.ProcedureID, - Channel: procedure.Channel, StartTime: startTs, EndTime: nowTs, ReportAmount: params.ReportAmount, @@ -63,14 +66,35 @@ WorkerID: params.WorkerID, WorkerName: workerName, WorkerTime: nowTs - startTs, - BarCode: snowflake.GenerateIdStr(), + BarCode: cast.ToString(snowflake.GenerateID()), } + err = model.WithTransaction(func(db *gorm.DB) error { + err = model.NewReportWorkSearch(db).Create(record) + if err != nil { + return err + } - err = model.NewReportWorkSearch(nil).Create(record) + content, err := json.Marshal(record) + if err != nil { + return err + } + err = model.NewReportsToCloudSearch(db).Create(&model.ReportsToCloud{ + ReportType: constvar.ReportTypeReportWork, + Content: string(content), + }) + if err != nil { + return err + } + + return nil + }) if err != nil { + logx.Errorf("save report work transaction error: %v", err) return err } - PlcCacheSet(conf.Conf.CurrentDeviceID, procedure.Channel, constvar.PlcCacheKeyFinishNumber, params.ReportAmount) + + err = NewProgressService().UpdateProgressByProceduresId(procedure.ID, params.ReportAmount) + return nil } -- Gitblit v1.8.0