正在显示
6 个修改的文件
包含
36 行增加
和
11 行删除
@@ -78,13 +78,14 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | @@ -78,13 +78,14 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | ||
78 | 78 | ||
79 | newDeviceCollection := &domain.DeviceCollection{ | 79 | newDeviceCollection := &domain.DeviceCollection{ |
80 | //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId, | 80 | //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId, |
81 | - WorkShopName: createDeviceCollectionCommand.WorkShopName, | ||
82 | - DeviceType: createDeviceCollectionCommand.DeviceType, | ||
83 | - StartupStatus: createDeviceCollectionCommand.StartupStatus, | ||
84 | - DeviceSn: createDeviceCollectionCommand.DeviceSn, | ||
85 | - ComStatus: createDeviceCollectionCommand.ComStatus, | ||
86 | - CollectionTime: createDeviceCollectionCommand.CollectionTime, | ||
87 | - Values: createDeviceCollectionCommand.Values, | 81 | + WorkShopName: createDeviceCollectionCommand.WorkShopName, |
82 | + DeviceType: createDeviceCollectionCommand.DeviceType, | ||
83 | + StartupStatus: createDeviceCollectionCommand.StartupStatus, | ||
84 | + DeviceSn: createDeviceCollectionCommand.DeviceSn, | ||
85 | + ComStatus: createDeviceCollectionCommand.ComStatus, | ||
86 | + CollectionTime: createDeviceCollectionCommand.CollectionTime, | ||
87 | + Values: createDeviceCollectionCommand.Values, | ||
88 | + LatestUpdateTime: time.Now(), | ||
88 | } | 89 | } |
89 | var lastDeviceCollectionRecord = &domain.DeviceCollection{} | 90 | var lastDeviceCollectionRecord = &domain.DeviceCollection{} |
90 | var err error | 91 | var err error |
@@ -126,16 +127,19 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | @@ -126,16 +127,19 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | ||
126 | newDeviceCollection.Values["Count"] = 0 | 127 | newDeviceCollection.Values["Count"] = 0 |
127 | curCount, errCurCount := strconv.Atoi(utils.AssertString(v)) | 128 | curCount, errCurCount := strconv.Atoi(utils.AssertString(v)) |
128 | lastCount, errLastCount := strconv.Atoi(utils.AssertString(lastDeviceCollectionRecord.Values["Count"])) | 129 | lastCount, errLastCount := strconv.Atoi(utils.AssertString(lastDeviceCollectionRecord.Values["Count"])) |
130 | + var count int | ||
129 | if errLastCount == nil && errCurCount == nil && lastCount <= curCount { | 131 | if errLastCount == nil && errCurCount == nil && lastCount <= curCount { |
130 | if lastCount <= curCount { | 132 | if lastCount <= curCount { |
131 | - newDeviceCollection.Values["Count"] = curCount - lastCount | 133 | + count = curCount - lastCount |
132 | } else { | 134 | } else { |
133 | - newDeviceCollection.Values["Count"] = 0 | 135 | + count = 0 |
134 | /*设备统计的数量超过一定范围会重置为0,特殊处理0操作*/ | 136 | /*设备统计的数量超过一定范围会重置为0,特殊处理0操作*/ |
135 | if lastCount > 10000000 && curCount < 1000 { | 137 | if lastCount > 10000000 && curCount < 1000 { |
136 | - newDeviceCollection.Values["Count"] = curCount | 138 | + count = curCount |
137 | } | 139 | } |
138 | } | 140 | } |
141 | + newDeviceCollection.Values["Count"] = count | ||
142 | + newDeviceCollection.Count = count | ||
139 | } | 143 | } |
140 | } | 144 | } |
141 | // TODO:测试假数据,后期注释掉 | 145 | // TODO:测试假数据,后期注释掉 |
@@ -24,6 +24,10 @@ type DeviceCollection struct { | @@ -24,6 +24,10 @@ type DeviceCollection struct { | ||
24 | ComStatus int64 `json:"comStatus"` | 24 | ComStatus int64 `json:"comStatus"` |
25 | // 设备数据值 | 25 | // 设备数据值 |
26 | Values map[string]interface{} `json:"values"` | 26 | Values map[string]interface{} `json:"values"` |
27 | + // 数量(字库使用) | ||
28 | + Count int `json:"count"` | ||
29 | + // 最后跟新时间(字库使用) | ||
30 | + LatestUpdateTime time.Time `json:"latest_update_time"` | ||
27 | } | 31 | } |
28 | 32 | ||
29 | var ( | 33 | var ( |
@@ -26,4 +26,8 @@ type DeviceCollection struct { | @@ -26,4 +26,8 @@ type DeviceCollection struct { | ||
26 | UpdatedAt time.Time `comment:"更新时间" pg:",default:now()"` | 26 | UpdatedAt time.Time `comment:"更新时间" pg:",default:now()"` |
27 | // 删除时间 | 27 | // 删除时间 |
28 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` | 28 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` |
29 | + // 数量(字库使用) | ||
30 | + Count int `comment:"数量" json:"count"` | ||
31 | + // 最后更新时间(字库使用) | ||
32 | + LatestUpdateTime time.Time `comment:"最后更新时间" json:"latest_update_time"` | ||
29 | } | 33 | } |
@@ -15,5 +15,7 @@ func TransformToDeviceCollectionDomainModelFromPgModels(deviceCollectionModel *m | @@ -15,5 +15,7 @@ func TransformToDeviceCollectionDomainModelFromPgModels(deviceCollectionModel *m | ||
15 | CollectionTime: deviceCollectionModel.CreatedAt, | 15 | CollectionTime: deviceCollectionModel.CreatedAt, |
16 | ComStatus: deviceCollectionModel.ComStatus, | 16 | ComStatus: deviceCollectionModel.ComStatus, |
17 | Values: deviceCollectionModel.Values, | 17 | Values: deviceCollectionModel.Values, |
18 | + Count: deviceCollectionModel.Count, | ||
19 | + LatestUpdateTime: deviceCollectionModel.LatestUpdateTime, | ||
18 | }, nil | 20 | }, nil |
19 | } | 21 | } |
@@ -35,6 +35,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -35,6 +35,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
35 | "startup_status", | 35 | "startup_status", |
36 | "com_status", | 36 | "com_status", |
37 | "values", | 37 | "values", |
38 | + "count", | ||
39 | + "latest_update_time", | ||
38 | } | 40 | } |
39 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | 41 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) |
40 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | 42 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) |
@@ -59,6 +61,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -59,6 +61,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
59 | &deviceCollection.StartupStatus, | 61 | &deviceCollection.StartupStatus, |
60 | &deviceCollection.ComStatus, | 62 | &deviceCollection.ComStatus, |
61 | &deviceCollection.Values, | 63 | &deviceCollection.Values, |
64 | + &deviceCollection.Count, | ||
65 | + &deviceCollection.LatestUpdateTime, | ||
62 | ), | 66 | ), |
63 | fmt.Sprintf("INSERT INTO manufacture.device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 67 | fmt.Sprintf("INSERT INTO manufacture.device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
64 | deviceCollection.DeviceCollectionId, | 68 | deviceCollection.DeviceCollectionId, |
@@ -69,6 +73,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -69,6 +73,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
69 | deviceCollection.StartupStatus, | 73 | deviceCollection.StartupStatus, |
70 | deviceCollection.ComStatus, | 74 | deviceCollection.ComStatus, |
71 | deviceCollection.Values, | 75 | deviceCollection.Values, |
76 | + deviceCollection.Count, | ||
77 | + deviceCollection.LatestUpdateTime, | ||
72 | ); err != nil { | 78 | ); err != nil { |
73 | return deviceCollection, err | 79 | return deviceCollection, err |
74 | } | 80 | } |
@@ -83,6 +89,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -83,6 +89,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
83 | &deviceCollection.StartupStatus, | 89 | &deviceCollection.StartupStatus, |
84 | &deviceCollection.ComStatus, | 90 | &deviceCollection.ComStatus, |
85 | &deviceCollection.Values, | 91 | &deviceCollection.Values, |
92 | + &deviceCollection.Count, | ||
93 | + &deviceCollection.LatestUpdateTime, | ||
86 | ), | 94 | ), |
87 | fmt.Sprintf("UPDATE manufacture.device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 95 | fmt.Sprintf("UPDATE manufacture.device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
88 | //deviceCollection.DeviceCollectionId, | 96 | //deviceCollection.DeviceCollectionId, |
@@ -93,6 +101,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -93,6 +101,8 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
93 | deviceCollection.StartupStatus, | 101 | deviceCollection.StartupStatus, |
94 | deviceCollection.ComStatus, | 102 | deviceCollection.ComStatus, |
95 | deviceCollection.Values, | 103 | deviceCollection.Values, |
104 | + deviceCollection.Count, | ||
105 | + deviceCollection.LatestUpdateTime, | ||
96 | deviceCollection.Identify(), | 106 | deviceCollection.Identify(), |
97 | ); err != nil { | 107 | ); err != nil { |
98 | return deviceCollection, err | 108 | return deviceCollection, err |
-
请 注册 或 登录 后发表评论