作者 yangfu

feat: 统计服务重定向

@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/byte_bank" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/byte_bank"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
11 ) 12 )
12 13
@@ -73,51 +74,51 @@ func (svr *ByteBankService) DeviceOperationEfficiency() (interface{}, error) { @@ -73,51 +74,51 @@ func (svr *ByteBankService) DeviceOperationEfficiency() (interface{}, error) {
73 defer func() { 74 defer func() {
74 transactionContext.RollbackTransaction() 75 transactionContext.RollbackTransaction()
75 }() 76 }()
76 - //deviceRepository, _ := repository.NewDeviceRepository(transactionContext)  
77 - //_, devices, err := deviceRepository.Find(map[string]interface{}{  
78 - // "companyId": constant.MANUFACTURE_DEFAULT_COMPANYID,  
79 - // "orgId": constant.MANUFACTURE_DEFAULT_ORGID,  
80 - // "workshopId": constant.MANUFACTURE_DEFAULT_WORKSHOPID,  
81 - // "orderBy": "device_name asc"})  
82 - //if err != nil {  
83 - // return nil, err  
84 - //}  
85 - //var response = make([]interface{}, 0)  
86 - //for _, d := range devices {  
87 - // var deviceSn string  
88 - // var productCount, runningTime int64  
89 - // for _, item := range queryResult {  
90 - // deviceSn = item.Get("device_sn").String()  
91 - // if deviceSn == d.DeviceCode {  
92 - // productCount = item.Get("product_count").Int()  
93 - // runningTime = item.Get("timing").Int()  
94 - // break  
95 - // }  
96 - // }  
97 - // response = append(response, map[string]interface{}{  
98 - // "deviceName": d.DeviceName,  
99 - // "deviceType": d.DeviceType,  
100 - // "productCount": productCount,  
101 - // "timing": runningTime,  
102 - // })  
103 - //}  
104 - 77 + deviceRepository, _ := repository.NewDeviceRepository(transactionContext)
  78 + _, devices, err := deviceRepository.Find(map[string]interface{}{
  79 + "companyId": constant.MANUFACTURE_DEFAULT_COMPANYID,
  80 + "orgId": constant.MANUFACTURE_DEFAULT_ORGID,
  81 + "workshopId": constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  82 + "orderBy": "device_name asc"})
  83 + if err != nil {
  84 + return nil, err
  85 + }
105 var response = make([]interface{}, 0) 86 var response = make([]interface{}, 0)
  87 + for _, d := range devices {
106 var deviceSn string 88 var deviceSn string
107 var productCount, runningTime int64 89 var productCount, runningTime int64
108 for _, item := range queryResult { 90 for _, item := range queryResult {
109 deviceSn = item.Get("device_sn").String() 91 deviceSn = item.Get("device_sn").String()
110 - if deviceSn != "" { 92 + if deviceSn == d.DeviceCode {
111 productCount = item.Get("product_count").Int() 93 productCount = item.Get("product_count").Int()
112 runningTime = item.Get("timing").Int() 94 runningTime = item.Get("timing").Int()
  95 + break
  96 + }
  97 + }
113 response = append(response, map[string]interface{}{ 98 response = append(response, map[string]interface{}{
114 - "设备名称": deviceSn,  
115 - "设备类型": item.Get("device_type").String(),  
116 - "运行时长": productCount,  
117 - "数量": runningTime, 99 + "device_name": d.DeviceName,
  100 + "device_type": d.DeviceType,
  101 + "product_count": productCount,
  102 + "timing": runningTime,
118 }) 103 })
119 } 104 }
120 - } 105 +
  106 + //var response = make([]interface{}, 0)
  107 + //var deviceSn string
  108 + //var productCount, runningTime int64
  109 + //for _, item := range queryResult {
  110 + // deviceSn = item.Get("device_sn").String()
  111 + // if deviceSn != "" {
  112 + // productCount = item.Get("product_count").Int()
  113 + // runningTime = item.Get("timing").Int()
  114 + // response = append(response, map[string]interface{}{
  115 + // "设备名称": deviceSn,
  116 + // "设备类型": item.Get("device_type").String(),
  117 + // "运行时长": productCount,
  118 + // "数量": runningTime,
  119 + // })
  120 + // }
  121 + //}
121 122
122 if err := transactionContext.CommitTransaction(); err != nil { 123 if err := transactionContext.CommitTransaction(); err != nil {
123 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 124 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())