|
@@ -22,6 +22,8 @@ const ( |
|
@@ -22,6 +22,8 @@ const ( |
|
22
|
WorkshopProductionEfficiencyStatistics = "WorkshopProductionEfficiencyStatistics"
|
22
|
WorkshopProductionEfficiencyStatistics = "WorkshopProductionEfficiencyStatistics"
|
|
23
|
// 设备运行统计
|
23
|
// 设备运行统计
|
|
24
|
DeviceRunningStatistics = "DeviceRunningStatistics"
|
24
|
DeviceRunningStatistics = "DeviceRunningStatistics"
|
|
|
|
25
|
+ // 设备运行信息
|
|
|
|
26
|
+ DeviceRunningInfo = "DeviceRunningInfo"
|
|
25
|
)
|
27
|
)
|
|
26
|
|
28
|
|
|
27
|
const (
|
29
|
const (
|
|
@@ -51,6 +53,9 @@ func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryO |
|
@@ -51,6 +53,9 @@ func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryO |
|
51
|
case DeviceRunningStatistics:
|
53
|
case DeviceRunningStatistics:
|
|
52
|
result, err = ptr.DeviceRunningStatistics(queryOptions)
|
54
|
result, err = ptr.DeviceRunningStatistics(queryOptions)
|
|
53
|
break
|
55
|
break
|
|
|
|
56
|
+ case DeviceRunningInfo:
|
|
|
|
57
|
+ result, err = ptr.DeviceRunningInfo(queryOptions)
|
|
|
|
58
|
+ break
|
|
54
|
}
|
59
|
}
|
|
55
|
return result, err
|
60
|
return result, err
|
|
56
|
}
|
61
|
}
|
|
@@ -331,6 +336,80 @@ type DeviceRunningStatisticRequest struct { |
|
@@ -331,6 +336,80 @@ type DeviceRunningStatisticRequest struct { |
|
331
|
Date string `json:"date"`
|
336
|
Date string `json:"date"`
|
|
332
|
}
|
337
|
}
|
|
333
|
|
338
|
|
|
|
|
339
|
+// 设备运行统计
|
|
|
|
340
|
+func (ptr *PGCommonStatisticsService) DeviceRunningInfo(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
|
341
|
+ var request = &DeviceRunningStatisticRequest{}
|
|
|
|
342
|
+ if err := utils.LoadQueryObject(queryOptions, request); err != nil {
|
|
|
|
343
|
+ return nil, err
|
|
|
|
344
|
+ }
|
|
|
|
345
|
+ deviceDailyRunningRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
|
|
|
|
346
|
+ var response = make([]*DeviceInfo, 0)
|
|
|
|
347
|
+ deviceDailyRunningRecordDao.DeviceRunningInfo(request.CompanyId, request.OrgId, "CCJ1", &response)
|
|
|
|
348
|
+
|
|
|
|
349
|
+ return map[string]interface{}{
|
|
|
|
350
|
+ "devices": response,
|
|
|
|
351
|
+ "device_summary": ptr.DeviceSummary(response),
|
|
|
|
352
|
+ }, nil
|
|
|
|
353
|
+}
|
|
|
|
354
|
+
|
|
|
|
355
|
+func (ptr *PGCommonStatisticsService) DeviceSummary(deviceInfos []*DeviceInfo) interface{} {
|
|
|
|
356
|
+ var result = make(map[string]interface{})
|
|
|
|
357
|
+ total := len(deviceInfos)
|
|
|
|
358
|
+ var (
|
|
|
|
359
|
+ deviceRunning = 0
|
|
|
|
360
|
+ deviceOff = 0
|
|
|
|
361
|
+ deviceErr = 0
|
|
|
|
362
|
+ )
|
|
|
|
363
|
+
|
|
|
|
364
|
+ for _, v := range deviceInfos {
|
|
|
|
365
|
+ if v.TStatus == "待机中" {
|
|
|
|
366
|
+ deviceOff += 1
|
|
|
|
367
|
+ } else if v.TStatus == "故障中" {
|
|
|
|
368
|
+ deviceErr += 1
|
|
|
|
369
|
+ } else if v.TStatus == "运行中" {
|
|
|
|
370
|
+ deviceRunning += 1
|
|
|
|
371
|
+ }
|
|
|
|
372
|
+ }
|
|
|
|
373
|
+
|
|
|
|
374
|
+ deviceSummary := func(t, num int) interface{} {
|
|
|
|
375
|
+ var rate float64
|
|
|
|
376
|
+ if t == 0 || num == 0 {
|
|
|
|
377
|
+ rate = 0
|
|
|
|
378
|
+ } else {
|
|
|
|
379
|
+ rate = utils.Round(float64(num*100.0/t), 0)
|
|
|
|
380
|
+ }
|
|
|
|
381
|
+ return map[string]interface{}{
|
|
|
|
382
|
+ "device_number": num,
|
|
|
|
383
|
+ "rate": rate,
|
|
|
|
384
|
+ }
|
|
|
|
385
|
+ }
|
|
|
|
386
|
+
|
|
|
|
387
|
+ result = map[string]interface{}{
|
|
|
|
388
|
+ "total": total,
|
|
|
|
389
|
+ "off": deviceSummary(total, deviceOff),
|
|
|
|
390
|
+ "on": deviceSummary(total, deviceRunning),
|
|
|
|
391
|
+ "err": deviceSummary(total, deviceRunning),
|
|
|
|
392
|
+ }
|
|
|
|
393
|
+ return result
|
|
|
|
394
|
+}
|
|
|
|
395
|
+
|
|
|
|
396
|
+type DeviceRunningInfoRequest struct {
|
|
|
|
397
|
+ CompanyId int `json:"companyId" valid:"Required"`
|
|
|
|
398
|
+ OrgId int `json:"orgId" valid:"Required"`
|
|
|
|
399
|
+ WorkshopId int `json:"workshopId"`
|
|
|
|
400
|
+}
|
|
|
|
401
|
+
|
|
|
|
402
|
+type DeviceInfo struct {
|
|
|
|
403
|
+ TDeviceName string `json:"t_device_name"`
|
|
|
|
404
|
+ TDeviceCode string `json:"t_device_code"`
|
|
|
|
405
|
+ TStatus string `json:"t_status"`
|
|
|
|
406
|
+ TTemperature float64 `json:"t_temperature"`
|
|
|
|
407
|
+ TTemperature1 float64 `json:"t_temperature1"`
|
|
|
|
408
|
+ TDeviceType string `json:"t_device_type"`
|
|
|
|
409
|
+ TTotal float64 `json:"t_total"`
|
|
|
|
410
|
+ TUptime int `json:"t_uptime"`
|
|
|
|
411
|
+}
|
|
|
|
412
|
+
|
|
334
|
func NewPGCommonStatisticsService(transactionContext *pgTransaction.TransactionContext) (*PGCommonStatisticsService, error) {
|
413
|
func NewPGCommonStatisticsService(transactionContext *pgTransaction.TransactionContext) (*PGCommonStatisticsService, error) {
|
|
335
|
if transactionContext == nil {
|
414
|
if transactionContext == nil {
|
|
336
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
415
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|