From efec800478214f3a412f879d2b51c2968515995d Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期六, 25 十一月 2023 17:04:25 +0800 Subject: [PATCH] plc断开连接时获取工序最后一次报工数量作为加工数 --- service/device_plc.go | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/service/device_plc.go b/service/device_plc.go index c4f46a1..d76e781 100644 --- a/service/device_plc.go +++ b/service/device_plc.go @@ -19,8 +19,9 @@ } func (slf DevicePlcService) GetDevicePlc() (*model.DevicePlc, int) { - DevicePlc, err := model.NewDevicePlcSearch().SetDeviceId(conf.Conf.System.DeviceId).First() + DevicePlc, err := model.NewDevicePlcSearch().SetDeviceId(conf.Conf.CurrentDeviceID).First() if err == gorm.ErrRecordNotFound { + logx.Errorf("GetDevicePlc failed:%v", err) return &model.DevicePlc{ DeviceID: "", Brand: "", @@ -37,6 +38,7 @@ }, ecode.OK } if err != nil { + logx.Errorf("GetDevicePlc failed:%v", err) return nil, ecode.DBErr } @@ -46,9 +48,11 @@ func (slf DevicePlcService) GetDeviceChannelAmount() (int, error) { plcConfig, code := slf.GetDevicePlc() if code != ecode.OK || plcConfig.ID == 0 { + logx.Errorf("GetDeviceChannelAmount failed:%v, code:%v", plcConfig, code) return 0, errors.New("鏈幏鍙栧埌PLC鍦板潃锛岃鍦ㄥ伐鑹烘ā鍨嬪簱涓笂浼狅紒") } if len(plcConfig.Details) == 0 { + logx.Errorf("GetDeviceChannelAmount failed, addressList == 0, %+v", plcConfig) return 0, errors.New("鏈幏鍙栧埌PLC鍦板潃锛岃鍦ㄥ伐鑹烘ā鍨嬪簱涓笂浼狅紒") } return len(plcConfig.Details) / 2, nil @@ -67,11 +71,10 @@ return ecode.ParamsErr } record.Detail = string(detail) - - if plc.Id == 0 { + if record.ID == 0 { err = model.NewDevicePlcSearch().Create(&record) } else { - err = model.NewDevicePlcSearch().SetId(plc.Id).Save(&record) + err = model.NewDevicePlcSearch().Save(&record) } if err != nil { -- Gitblit v1.8.0