From 9e2fbcdc62bc4b45519715c8243446a11ee011cf Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 20 十二月 2023 17:26:27 +0800
Subject: [PATCH] goborrow rtu地址-1

---
 crontask/cron_task.go |   19 ++++++-------------
 1 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/crontask/cron_task.go b/crontask/cron_task.go
index 24ffc22..da24026 100644
--- a/crontask/cron_task.go
+++ b/crontask/cron_task.go
@@ -38,15 +38,15 @@
 		}
 		for _, addressItem := range plcConfig.Details {
 			if addressItem.FieldName == constvar.PlcStartAddressTypeFinishNumber {
-				value, err := service.PlcReadDirect(plcConfig, addressItem.StartAddress, addressItem.Length, addressItem.Type)
+				value, err := service.PlcReadDirect(plcConfig, addressItem)
 				if err != nil {
 					logx.Infof("plc read finish number err: %v", err)
 					continue
 				}
-				finishNumber := cast.ToInt64(value)
+				finishNumber := cast.ToInt(value)
 				if finishNumber != 0 {
 					service.PlcCacheSet(conf.Conf.CurrentDeviceID, addressItem.Channel, constvar.PlcCacheKeyFinishNumber, finishNumber)
-					_ = service.NewProgressService().UpdateProgress(conf.Conf.CurrentDeviceID, addressItem.Channel, cast.ToInt64(finishNumber))
+					_ = service.NewProgressService().UpdateProgress(conf.Conf.CurrentDeviceID, addressItem.Channel, finishNumber)
 				}
 				logx.Infof("plc read finish number: %v", finishNumber)
 			}
@@ -64,7 +64,7 @@
 		}
 		for _, addressItem := range plcConfig.Details {
 			if addressItem.FieldName == constvar.PlcStartAddressTypeTotalNumber {
-				value, err := service.PlcReadDirect(plcConfig, addressItem.StartAddress, addressItem.Length, addressItem.Type)
+				value, err := service.PlcReadDirect(plcConfig, addressItem)
 				if err != nil {
 					logx.Infof("plc read total number err: %v", err)
 					continue
@@ -115,20 +115,13 @@
 	}
 	syncOkIds := make([]uint, 0, len(records))
 	for _, record := range records {
-		var finishAmount int
-		if record.IsFinish {
-			progress, err := model.NewProductionProgressSearch(nil).SetWorkOrderId(record.WorkOrderId).SetProductProcedureId(record.ProductProcedureID).First()
-			if err == nil {
-				finishAmount = int(progress.FinishedQuantity)
-			}
-		}
 		msg := &common.MsgTaskStatusUpdate{
 			WorkOrderId:        record.WorkOrderId,
 			ProcedureID:        record.ProcedureID,
 			DeviceId:           record.DeviceId,
 			IsProcessing:       record.IsProcessing,
 			IsFinish:           record.IsFinish,
-			FinishAmount:       finishAmount,
+			FinishAmount:       record.FinishedQuantity,
 			ProductProcedureID: record.ProductProcedureID,
 			StartTs:            record.StartTs,
 			FinishTs:           record.FinishTs,
@@ -142,7 +135,7 @@
 		syncOkIds = append(syncOkIds, record.ID)
 	}
 	if len(syncOkIds) > 0 {
-		err = service.NewTaskService().RemoveTaskStatusSync(syncOkIds)
+		err = service.NewTaskService().FinishTaskStatusSync(syncOkIds)
 		if err != nil {
 			logx.Errorf("sync task status delete sync ok records error:%v", err)
 		}

--
Gitblit v1.8.0