正在显示
4 个修改的文件
包含
27 行增加
和
29 行删除
@@ -124,7 +124,7 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | @@ -124,7 +124,7 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | ||
124 | //计算区间的产能 | 124 | //计算区间的产能 |
125 | 125 | ||
126 | if v, ok := newDeviceCollection.Values["Count"]; ok { | 126 | if v, ok := newDeviceCollection.Values["Count"]; ok { |
127 | - newDeviceCollection.Values["total"] = v // 记录原始值 | 127 | + newDeviceCollection.Values["Total"] = v // 记录原始值 |
128 | newDeviceCollection.Values["Count"] = 0 | 128 | newDeviceCollection.Values["Count"] = 0 |
129 | curCount, errCurCount := strconv.Atoi(utils.AssertString(v)) | 129 | curCount, errCurCount := strconv.Atoi(utils.AssertString(v)) |
130 | lastCount, errLastCount := strconv.Atoi(utils.AssertString(lastDeviceCollectionRecord.Values["Count"])) | 130 | lastCount, errLastCount := strconv.Atoi(utils.AssertString(lastDeviceCollectionRecord.Values["Count"])) |
@@ -143,29 +143,26 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | @@ -143,29 +143,26 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | ||
143 | newDeviceCollection.ProductCount = count | 143 | newDeviceCollection.ProductCount = count |
144 | } | 144 | } |
145 | } | 145 | } |
146 | - _, valErr := newDeviceCollection.Valid() | 146 | + if _, valErr := newDeviceCollection.Valid(); valErr != nil { |
147 | + newDeviceCollection.ResetProductCountToZero() | ||
148 | + } | ||
147 | // TODO:测试假数据,后期注释掉 | 149 | // TODO:测试假数据,后期注释掉 |
148 | //if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi { | 150 | //if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi { |
149 | // newDeviceCollection.Values["Count"] = rand.Intn(300) | 151 | // newDeviceCollection.Values["Count"] = rand.Intn(300) |
152 | + // newDeviceCollection.StartupStatus = 1 | ||
153 | + // newDeviceCollection.ComStatus = 1 | ||
150 | //} | 154 | //} |
151 | - deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection) | ||
152 | - if err != nil { | 155 | + if newDeviceCollection, err = deviceCollectionRepository.Save(newDeviceCollection); err != nil { |
153 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 156 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
154 | } | 157 | } |
155 | - if valErr == nil { | ||
156 | - err = domainService.SendWorkshopDeviceData(deviceCollection) | ||
157 | - } | ||
158 | - if err != nil { | 158 | + if err = domainService.SendWorkshopDeviceData(newDeviceCollection); err != nil { |
159 | log.Logger.Error("车间设备数据加入redis失败:" + err.Error()) | 159 | log.Logger.Error("车间设备数据加入redis失败:" + err.Error()) |
160 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 160 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
161 | } | 161 | } |
162 | - | ||
163 | if err := transactionContext.CommitTransaction(); err != nil { | 162 | if err := transactionContext.CommitTransaction(); err != nil { |
164 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 163 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
165 | } | 164 | } |
166 | - return map[string]interface{}{ | ||
167 | - "deviceCollection": deviceCollection, | ||
168 | - }, nil | 165 | + return nil, nil |
169 | 166 | ||
170 | } | 167 | } |
171 | 168 |
@@ -103,8 +103,6 @@ func (data *DeviceCollection) Valid() (bool, error) { | @@ -103,8 +103,6 @@ func (data *DeviceCollection) Valid() (bool, error) { | ||
103 | result = false | 103 | result = false |
104 | ) | 104 | ) |
105 | if data.ProductCount > DeviceMaxSingleProductCount { | 105 | if data.ProductCount > DeviceMaxSingleProductCount { |
106 | - data.ProductCount = 0 | ||
107 | - data.Values["Count"] = 0 | ||
108 | return result, fmt.Errorf("设备数据异常: 生产数量超过:%v", DeviceMaxSingleProductCount) | 106 | return result, fmt.Errorf("设备数据异常: 生产数量超过:%v", DeviceMaxSingleProductCount) |
109 | } | 107 | } |
110 | if data.StartupStatus == 0 { | 108 | if data.StartupStatus == 0 { |
@@ -115,3 +113,10 @@ func (data *DeviceCollection) Valid() (bool, error) { | @@ -115,3 +113,10 @@ func (data *DeviceCollection) Valid() (bool, error) { | ||
115 | } | 113 | } |
116 | return true, nil | 114 | return true, nil |
117 | } | 115 | } |
116 | + | ||
117 | +func (data *DeviceCollection) ResetProductCountToZero() { | ||
118 | + data.ProductCount = 0 | ||
119 | + if data.Values != nil { | ||
120 | + data.Values["Count"] = 0 | ||
121 | + } | ||
122 | +} |
@@ -53,15 +53,17 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) Update(data map[string | @@ -53,15 +53,17 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) Update(data map[string | ||
53 | return nil | 53 | return nil |
54 | } | 54 | } |
55 | 55 | ||
56 | -func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(t time.Time, data *DeviceRunningData) bool { | 56 | +func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(data *DeviceRunningData) bool { |
57 | + t := data.CollectionTime | ||
57 | deviceDailyRunningRecord.DeviceRunningRecordInfo.AddDeviceRunningData(t, data) | 58 | deviceDailyRunningRecord.DeviceRunningRecordInfo.AddDeviceRunningData(t, data) |
58 | now := time.Now().Unix() | 59 | now := time.Now().Unix() |
59 | if ok, _ := data.Valid(); !ok { | 60 | if ok, _ := data.Valid(); !ok { |
60 | return false | 61 | return false |
61 | } | 62 | } |
62 | - if t.Unix() > (now-DefaultCollectionTimeSpan) && t.Unix() < (now+DefaultCollectionTimeSpan) { | 63 | + ts := t.Local().Unix() |
64 | + if ts > (now-DefaultCollectionTimeSpan) && ts < (now+DefaultCollectionTimeSpan) { | ||
63 | deviceDailyRunningRecord.UpdatedAt = t | 65 | deviceDailyRunningRecord.UpdatedAt = t |
64 | - return false | 66 | + return true |
65 | } | 67 | } |
66 | deviceDailyRunningRecord.UpdatedAt = time.Now() | 68 | deviceDailyRunningRecord.UpdatedAt = time.Now() |
67 | return true | 69 | return true |
@@ -28,7 +28,6 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -28,7 +28,6 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
28 | planId int | 28 | planId int |
29 | err error | 29 | err error |
30 | plan *domain.ProductPlanDispatchRecord | 30 | plan *domain.ProductPlanDispatchRecord |
31 | - //datetime time.Time | ||
32 | ) | 31 | ) |
33 | var ( | 32 | var ( |
34 | deviceRepository, _ = repository.NewDeviceRepository(ptr.transactionContext) | 33 | deviceRepository, _ = repository.NewDeviceRepository(ptr.transactionContext) |
@@ -67,7 +66,6 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -67,7 +66,6 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
67 | 66 | ||
68 | var saveErr error | 67 | var saveErr error |
69 | if deviceDailyRecord, saveErr = ptr.saveDeviceDailyRunningRecord(companyId, orgId, workStation, device, planId, deviceRunningData); err != nil { | 68 | if deviceDailyRecord, saveErr = ptr.saveDeviceDailyRunningRecord(companyId, orgId, workStation, device, planId, deviceRunningData); err != nil { |
70 | - //log.Logger.Error(saveErr.Error()) | ||
71 | return nil, err | 69 | return nil, err |
72 | } | 70 | } |
73 | defer func() { | 71 | defer func() { |
@@ -94,20 +92,16 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -94,20 +92,16 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
94 | } | 92 | } |
95 | 93 | ||
96 | // 2.更新 设备每日运行记录(汇总) - redis更新 十分钟异步刷库 | 94 | // 2.更新 设备每日运行记录(汇总) - redis更新 十分钟异步刷库 |
97 | - if addSuccess := deviceDailyRecord.AddDeviceRunningData(deviceRunningData.CollectionTime, deviceRunningData); addSuccess { | 95 | + if addSuccess := deviceDailyRecord.AddDeviceRunningData(deviceRunningData); addSuccess { |
98 | // 3.保存设备生产记录 (统计车间、员工产能) 批次跟数量不为空 | 96 | // 3.保存设备生产记录 (统计车间、员工产能) 批次跟数量不为空 |
99 | if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 { | 97 | if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 { |
100 | - | ||
101 | productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan) | 98 | productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan) |
102 | - //SendProductRecordStaticsJob(productRecord) | ||
103 | - | ||
104 | productRecordService, _ := NewPGProductRecordService(ptr.transactionContext) | 99 | productRecordService, _ := NewPGProductRecordService(ptr.transactionContext) |
105 | productRecordService.EmployeeProductStatics(productRecord) | 100 | productRecordService.EmployeeProductStatics(productRecord) |
106 | productRecordService.WorkshopProductStatics(productRecord) | 101 | productRecordService.WorkshopProductStatics(productRecord) |
107 | } | 102 | } |
108 | } | 103 | } |
109 | if err = redis.SaveDeviceDailyRunningRecord(deviceDailyRecord); err != nil { | 104 | if err = redis.SaveDeviceDailyRunningRecord(deviceDailyRecord); err != nil { |
110 | - //log.Logger.Error(err.Error()) | ||
111 | return nil, err | 105 | return nil, err |
112 | } | 106 | } |
113 | return nil, nil | 107 | return nil, nil |
@@ -155,16 +149,16 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | @@ -155,16 +149,16 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | ||
155 | if err != nil { | 149 | if err != nil { |
156 | break | 150 | break |
157 | } | 151 | } |
158 | - data.Temp1 = deviceYouZhaJi.FrontTemp | ||
159 | - data.Temp2 = deviceYouZhaJi.BackTemp | 152 | + data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1) |
153 | + data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1) | ||
160 | } else { | 154 | } else { |
161 | deviceYouZhaJi := &domain.DeviceYouZhaJi2{} | 155 | deviceYouZhaJi := &domain.DeviceYouZhaJi2{} |
162 | err = json.Unmarshal(mBytes, deviceYouZhaJi) | 156 | err = json.Unmarshal(mBytes, deviceYouZhaJi) |
163 | if err != nil { | 157 | if err != nil { |
164 | break | 158 | break |
165 | } | 159 | } |
166 | - data.Temp1 = deviceYouZhaJi.Temp1 | ||
167 | - data.Temp2 = deviceYouZhaJi.Temp2 | 160 | + data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1) |
161 | + data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1) | ||
168 | } | 162 | } |
169 | break | 163 | break |
170 | //串串机 | 164 | //串串机 |
@@ -189,7 +183,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | @@ -189,7 +183,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | ||
189 | if err != nil { | 183 | if err != nil { |
190 | break | 184 | break |
191 | } | 185 | } |
192 | - data.Temp1 = deviceSuDongXian.CurrTemp | 186 | + data.Temp1 = utils.Truncate(deviceSuDongXian.CurrTemp, 1) |
193 | break | 187 | break |
194 | //封口机 | 188 | //封口机 |
195 | case domain.DeviceTypeFengKouJi: | 189 | case domain.DeviceTypeFengKouJi: |
-
请 注册 或 登录 后发表评论