合并分支 'dev' 到 'test'
Dev 查看合并请求 !1
正在显示
17 个修改的文件
包含
175 行增加
和
66 行删除
@@ -5,6 +5,7 @@ go 1.16 | @@ -5,6 +5,7 @@ go 1.16 | ||
5 | require ( | 5 | require ( |
6 | github.com/ajg/form v1.5.1 // indirect | 6 | github.com/ajg/form v1.5.1 // indirect |
7 | github.com/beego/beego/v2 v2.0.1 | 7 | github.com/beego/beego/v2 v2.0.1 |
8 | + github.com/bwmarrin/snowflake v0.3.0 // indirect | ||
8 | github.com/eclipse/paho.mqtt.golang v1.3.5 | 9 | github.com/eclipse/paho.mqtt.golang v1.3.5 |
9 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | 10 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect |
10 | github.com/fatih/structs v1.1.0 // indirect | 11 | github.com/fatih/structs v1.1.0 // indirect |
@@ -32,6 +32,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r | @@ -32,6 +32,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r | ||
32 | github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= | 32 | github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= |
33 | github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4= | 33 | github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4= |
34 | github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60= | 34 | github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60= |
35 | +github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= | ||
36 | +github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= | ||
35 | github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE= | 37 | github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE= |
36 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= | 38 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= |
37 | github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= | 39 | github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= |
@@ -4,27 +4,32 @@ import ( | @@ -4,27 +4,32 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | "reflect" | 5 | "reflect" |
6 | "strings" | 6 | "strings" |
7 | + "time" | ||
7 | 8 | ||
8 | "github.com/beego/beego/v2/core/validation" | 9 | "github.com/beego/beego/v2/core/validation" |
9 | ) | 10 | ) |
10 | 11 | ||
11 | type CreateDeviceCollectionCommand struct { | 12 | type CreateDeviceCollectionCommand struct { |
12 | // 数据采集ID | 13 | // 数据采集ID |
13 | - DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"` | 14 | + //DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"` |
14 | // 车间名 | 15 | // 车间名 |
15 | WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"` | 16 | WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"` |
16 | // 启动状态 1-启动 0-停止 | 17 | // 启动状态 1-启动 0-停止 |
17 | - StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus,string" valid:"Required"` | 18 | + StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus"` |
19 | + // 采集时间 | ||
20 | + CollectionTime time.Time `cname:"采集时间" json:"collectionTime" valid:"Required"` | ||
18 | // 设备名 | 21 | // 设备名 |
19 | DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"` | 22 | DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"` |
23 | + // 设备类型 | ||
24 | + DeviceType string `comment:"设备类型" json:"deviceType" valid:"Required"` | ||
20 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 | 25 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 |
21 | - ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus,string" valid:"Required"` | 26 | + ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus"` |
22 | // 设备数据值 | 27 | // 设备数据值 |
23 | - Values string `cname:"设备数据值" json:"values" valid:"Required"` | 28 | + Values map[string]interface{} `cname:"设备数据值" json:"values" valid:"Required"` |
24 | } | 29 | } |
25 | 30 | ||
26 | func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) Valid(validation *validation.Validation) { | 31 | func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) Valid(validation *validation.Validation) { |
27 | - validation.SetError("CustomValid", "未实现的自定义认证") | 32 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
28 | } | 33 | } |
29 | 34 | ||
30 | func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) ValidateCommand() error { | 35 | func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) ValidateCommand() error { |
@@ -14,7 +14,7 @@ type RemoveDeviceCollectionCommand struct { | @@ -14,7 +14,7 @@ type RemoveDeviceCollectionCommand struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) Valid(validation *validation.Validation) { | 16 | func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
18 | } | 18 | } |
19 | 19 | ||
20 | func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) ValidateCommand() error { | 20 | func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) ValidateCommand() error { |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | "reflect" | 5 | "reflect" |
6 | "strings" | 6 | "strings" |
7 | + "time" | ||
7 | 8 | ||
8 | "github.com/beego/beego/v2/core/validation" | 9 | "github.com/beego/beego/v2/core/validation" |
9 | ) | 10 | ) |
@@ -14,17 +15,21 @@ type UpdateDeviceCollectionCommand struct { | @@ -14,17 +15,21 @@ type UpdateDeviceCollectionCommand struct { | ||
14 | // 车间名 | 15 | // 车间名 |
15 | WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"` | 16 | WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"` |
16 | // 启动状态 1-启动 0-停止 | 17 | // 启动状态 1-启动 0-停止 |
17 | - StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus,string" valid:"Required"` | 18 | + StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus"` |
19 | + // 采集时间 | ||
20 | + CollectionTime time.Time `cname:"采集时间" json:"collectionTime" valid:"Required"` | ||
18 | // 设备名 | 21 | // 设备名 |
19 | DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"` | 22 | DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"` |
23 | + // 设备类型 | ||
24 | + DeviceType string `comment:"设备类型" json:"deviceType" valid:"Required"` | ||
20 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 | 25 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 |
21 | - ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus,string" valid:"Required"` | 26 | + ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus"` |
22 | // 设备数据值 | 27 | // 设备数据值 |
23 | - Values string `cname:"设备数据值" json:"values" valid:"Required"` | 28 | + Values map[string]interface{} `cname:"设备数据值" json:"values" valid:"Required"` |
24 | } | 29 | } |
25 | 30 | ||
26 | func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) Valid(validation *validation.Validation) { | 31 | func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) Valid(validation *validation.Validation) { |
27 | - validation.SetError("CustomValid", "未实现的自定义认证") | 32 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
28 | } | 33 | } |
29 | 34 | ||
30 | func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) ValidateCommand() error { | 35 | func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) ValidateCommand() error { |
@@ -10,13 +10,17 @@ import ( | @@ -10,13 +10,17 @@ import ( | ||
10 | 10 | ||
11 | type ListDeviceCollectionQuery struct { | 11 | type ListDeviceCollectionQuery struct { |
12 | // 查询偏离量 | 12 | // 查询偏离量 |
13 | - Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | 13 | + PageNumber int64 `cname:"查询偏离量" json:"pageNumber" ` |
14 | // 查询限制 | 14 | // 查询限制 |
15 | - Limit int `cname:"查询限制" json:"limit" valid:"Required"` | 15 | + PageSize int64 `cname:"查询限制" json:"pageSize" valid:"Required"` |
16 | + // 设备类型 | ||
17 | + DeviceType string `json:"deviceType" cname:"设备类型"` | ||
18 | + // 车间名 | ||
19 | + WorkShopName string `json:"workShopName"` | ||
16 | } | 20 | } |
17 | 21 | ||
18 | func (listDeviceCollectionQuery *ListDeviceCollectionQuery) Valid(validation *validation.Validation) { | 22 | func (listDeviceCollectionQuery *ListDeviceCollectionQuery) Valid(validation *validation.Validation) { |
19 | - validation.SetError("CustomValid", "未实现的自定义认证") | 23 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
20 | } | 24 | } |
21 | 25 | ||
22 | func (listDeviceCollectionQuery *ListDeviceCollectionQuery) ValidateQuery() error { | 26 | func (listDeviceCollectionQuery *ListDeviceCollectionQuery) ValidateQuery() error { |
@@ -29,8 +29,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c | @@ -29,8 +29,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c | ||
29 | transactionContext.RollbackTransaction() | 29 | transactionContext.RollbackTransaction() |
30 | }() | 30 | }() |
31 | newDeviceCollection := &domain.DeviceCollection{ | 31 | newDeviceCollection := &domain.DeviceCollection{ |
32 | - DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId, | 32 | + //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId, |
33 | WorkShopName: createDeviceCollectionCommand.WorkShopName, | 33 | WorkShopName: createDeviceCollectionCommand.WorkShopName, |
34 | + DeviceType: createDeviceCollectionCommand.DeviceType, | ||
34 | StartupStatus: createDeviceCollectionCommand.StartupStatus, | 35 | StartupStatus: createDeviceCollectionCommand.StartupStatus, |
35 | DeviceSn: createDeviceCollectionCommand.DeviceSn, | 36 | DeviceSn: createDeviceCollectionCommand.DeviceSn, |
36 | ComStatus: createDeviceCollectionCommand.ComStatus, | 37 | ComStatus: createDeviceCollectionCommand.ComStatus, |
@@ -50,7 +51,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c | @@ -50,7 +51,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c | ||
50 | if err := transactionContext.CommitTransaction(); err != nil { | 51 | if err := transactionContext.CommitTransaction(); err != nil { |
51 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 52 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
52 | } | 53 | } |
53 | - return deviceCollection, nil | 54 | + return map[string]interface{}{ |
55 | + "deviceCollection":deviceCollection, | ||
56 | + }, nil | ||
54 | } | 57 | } |
55 | } | 58 | } |
56 | 59 | ||
@@ -120,10 +123,7 @@ func (deviceCollectionService *DeviceCollectionService) ListDeviceCollection(lis | @@ -120,10 +123,7 @@ func (deviceCollectionService *DeviceCollectionService) ListDeviceCollection(lis | ||
120 | if err := transactionContext.CommitTransaction(); err != nil { | 123 | if err := transactionContext.CommitTransaction(); err != nil { |
121 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 124 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
122 | } | 125 | } |
123 | - return map[string]interface{}{ | ||
124 | - "count": count, | ||
125 | - "deviceCollections": deviceCollections, | ||
126 | - }, nil | 126 | + return tool_funs.SimpleWrapGridMap(count,deviceCollections), nil |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
@@ -163,7 +163,9 @@ func (deviceCollectionService *DeviceCollectionService) RemoveDeviceCollection(r | @@ -163,7 +163,9 @@ func (deviceCollectionService *DeviceCollectionService) RemoveDeviceCollection(r | ||
163 | if err := transactionContext.CommitTransaction(); err != nil { | 163 | if err := transactionContext.CommitTransaction(); err != nil { |
164 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 164 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
165 | } | 165 | } |
166 | - return deviceCollection, nil | 166 | + return map[string]interface{}{ |
167 | + "deviceCollection":deviceCollection, | ||
168 | + }, nil | ||
167 | } | 169 | } |
168 | } | 170 | } |
169 | 171 | ||
@@ -206,7 +208,9 @@ func (deviceCollectionService *DeviceCollectionService) UpdateDeviceCollection(u | @@ -206,7 +208,9 @@ func (deviceCollectionService *DeviceCollectionService) UpdateDeviceCollection(u | ||
206 | if err := transactionContext.CommitTransaction(); err != nil { | 208 | if err := transactionContext.CommitTransaction(); err != nil { |
207 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 209 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
208 | } | 210 | } |
209 | - return deviceCollection, nil | 211 | + return map[string]interface{}{ |
212 | + "deviceCollection":deviceCollection, | ||
213 | + }, nil | ||
210 | } | 214 | } |
211 | } | 215 | } |
212 | 216 |
@@ -5,6 +5,21 @@ import "os" | @@ -5,6 +5,21 @@ import "os" | ||
5 | var MQTT_TOPIC = "/MQTT" | 5 | var MQTT_TOPIC = "/MQTT" |
6 | 6 | ||
7 | //设备商提供的测试地址 | 7 | //设备商提供的测试地址 |
8 | +//var MQTT_HOST = "175.24.122.87" | ||
9 | +//var MQTT_PORT = "1883" | ||
10 | +//var MQTT_USER = "user111" | ||
11 | +//var MQTT_PASSWORD = "user111" | ||
12 | +//内网测试地址 | ||
13 | +//var MQTT_HOST = "192.168.100.222" | ||
14 | +//var MQTT_PORT = "1883" | ||
15 | +//var MQTT_USER = "admin" | ||
16 | +//var MQTT_PASSWORD = "123456" | ||
17 | + | ||
18 | +//var MQTT_HOST = "192.168.31.51" | ||
19 | +//var MQTT_PORT = "1883" | ||
20 | +//var MQTT_USER = "" | ||
21 | +//var MQTT_PASSWORD = "" | ||
22 | + | ||
8 | var MQTT_HOST = "175.24.122.87" | 23 | var MQTT_HOST = "175.24.122.87" |
9 | var MQTT_PORT = "1883" | 24 | var MQTT_PORT = "1883" |
10 | var MQTT_USER = "user111" | 25 | var MQTT_USER = "user111" |
@@ -23,7 +23,7 @@ type DeviceCollection struct { | @@ -23,7 +23,7 @@ type DeviceCollection struct { | ||
23 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 | 23 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 |
24 | ComStatus int64 `json:"comStatus"` | 24 | ComStatus int64 `json:"comStatus"` |
25 | // 设备数据值 | 25 | // 设备数据值 |
26 | - Values interface{} `json:"values"` | 26 | + Values map[string]interface{} `json:"values"` |
27 | } | 27 | } |
28 | 28 | ||
29 | var ( | 29 | var ( |
@@ -67,7 +67,10 @@ func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) er | @@ -67,7 +67,10 @@ func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) er | ||
67 | deviceCollection.DeviceSn = deviceSn.(string) | 67 | deviceCollection.DeviceSn = deviceSn.(string) |
68 | } | 68 | } |
69 | if deviceType, ok := data["deviceType"]; ok { | 69 | if deviceType, ok := data["deviceType"]; ok { |
70 | - deviceCollection.DeviceSn = deviceType.(string) | 70 | + deviceCollection.DeviceType = deviceType.(string) |
71 | + } | ||
72 | + if collectionTime, ok := data["collectionTime"]; ok { | ||
73 | + deviceCollection.CollectionTime = collectionTime.(time.Time) | ||
71 | } | 74 | } |
72 | if startupStatus, ok := data["startupStatus"]; ok { | 75 | if startupStatus, ok := data["startupStatus"]; ok { |
73 | deviceCollection.StartupStatus = startupStatus.(int64) | 76 | deviceCollection.StartupStatus = startupStatus.(int64) |
@@ -76,7 +79,7 @@ func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) er | @@ -76,7 +79,7 @@ func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) er | ||
76 | deviceCollection.ComStatus = comStatus.(int64) | 79 | deviceCollection.ComStatus = comStatus.(int64) |
77 | } | 80 | } |
78 | if values, ok := data["values"]; ok { | 81 | if values, ok := data["values"]; ok { |
79 | - deviceCollection.Values = values | 82 | + deviceCollection.Values = values.(map[string]interface{}) |
80 | } | 83 | } |
81 | return nil | 84 | return nil |
82 | } | 85 | } |
@@ -28,6 +28,7 @@ func init() { | @@ -28,6 +28,7 @@ func init() { | ||
28 | if !constant.DISABLE_CREATE_TABLE { | 28 | if !constant.DISABLE_CREATE_TABLE { |
29 | for _, model := range []interface{}{ | 29 | for _, model := range []interface{}{ |
30 | (*models.Device)(nil), | 30 | (*models.Device)(nil), |
31 | + (*models.DeviceCollection)(nil), | ||
31 | (*models.Product)(nil), | 32 | (*models.Product)(nil), |
32 | (*models.ProductAttendanceRecord)(nil), | 33 | (*models.ProductAttendanceRecord)(nil), |
33 | (*models.ProductCalendar)(nil), | 34 | (*models.ProductCalendar)(nil), |
@@ -17,7 +17,7 @@ type DeviceCollection struct { | @@ -17,7 +17,7 @@ type DeviceCollection struct { | ||
17 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 | 17 | // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障 |
18 | ComStatus int64 `comment:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" pg:",use_zero"` | 18 | ComStatus int64 `comment:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" pg:",use_zero"` |
19 | // 设备数据值 | 19 | // 设备数据值 |
20 | - Values interface{} `comment:"设备数据值"` | 20 | + Values map[string]interface{} `comment:"设备数据值" pg:""` |
21 | // 创建时间 | 21 | // 创建时间 |
22 | CreatedAt time.Time `comment:"创建时间" pg:",default:now()"` | 22 | CreatedAt time.Time `comment:"创建时间" pg:",default:now()"` |
23 | // 更新时间 | 23 | // 更新时间 |
@@ -10,6 +10,7 @@ func TransformToDeviceCollectionDomainModelFromPgModels(deviceCollectionModel *m | @@ -10,6 +10,7 @@ func TransformToDeviceCollectionDomainModelFromPgModels(deviceCollectionModel *m | ||
10 | DeviceCollectionId: deviceCollectionModel.DeviceCollectionId, | 10 | DeviceCollectionId: deviceCollectionModel.DeviceCollectionId, |
11 | WorkShopName: deviceCollectionModel.WorkShopName, | 11 | WorkShopName: deviceCollectionModel.WorkShopName, |
12 | DeviceSn: deviceCollectionModel.DeviceSn, | 12 | DeviceSn: deviceCollectionModel.DeviceSn, |
13 | + DeviceType: deviceCollectionModel.DeviceType, | ||
13 | StartupStatus: deviceCollectionModel.StartupStatus, | 14 | StartupStatus: deviceCollectionModel.StartupStatus, |
14 | ComStatus: deviceCollectionModel.ComStatus, | 15 | ComStatus: deviceCollectionModel.ComStatus, |
15 | Values: deviceCollectionModel.Values, | 16 | Values: deviceCollectionModel.Values, |
@@ -3,10 +3,10 @@ package repository | @@ -3,10 +3,10 @@ package repository | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "github.com/go-pg/pg/v10" | 5 | "github.com/go-pg/pg/v10" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
6 | 7 | ||
7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 8 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 9 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
9 | - "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" |
@@ -17,18 +17,19 @@ type DeviceCollectionRepository struct { | @@ -17,18 +17,19 @@ type DeviceCollectionRepository struct { | ||
17 | } | 17 | } |
18 | 18 | ||
19 | func (repository *DeviceCollectionRepository) nextIdentify() (int64, error) { | 19 | func (repository *DeviceCollectionRepository) nextIdentify() (int64, error) { |
20 | - IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | - if err != nil { | ||
22 | - return 0, err | ||
23 | - } | ||
24 | - id, err := IdWorker.NextId() | ||
25 | - return id, err | 20 | + //IdWorker, err := snowflake.NewIdWorker(1) |
21 | + //if err != nil { | ||
22 | + // return 0, err | ||
23 | + //} | ||
24 | + //id, err := IdWorker.NextId() | ||
25 | + return utils.NewSnowflakeId() | ||
26 | } | 26 | } |
27 | func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.DeviceCollection) (*domain.DeviceCollection, error) { | 27 | func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.DeviceCollection) (*domain.DeviceCollection, error) { |
28 | sqlBuildFields := []string{ | 28 | sqlBuildFields := []string{ |
29 | "device_collection_id", | 29 | "device_collection_id", |
30 | "work_shop_name", | 30 | "work_shop_name", |
31 | "device_sn", | 31 | "device_sn", |
32 | + "device_type", | ||
32 | "startup_status", | 33 | "startup_status", |
33 | "com_status", | 34 | "com_status", |
34 | "values", | 35 | "values", |
@@ -36,7 +37,7 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -36,7 +37,7 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
36 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | 37 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) |
37 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | 38 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) |
38 | returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | 39 | returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) |
39 | - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "deviceCollection_id") | 40 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_collection_id") |
40 | updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | 41 | updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) |
41 | tx := repository.transactionContext.PgTx | 42 | tx := repository.transactionContext.PgTx |
42 | if deviceCollection.Identify() == nil { | 43 | if deviceCollection.Identify() == nil { |
@@ -51,14 +52,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -51,14 +52,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
51 | &deviceCollection.DeviceCollectionId, | 52 | &deviceCollection.DeviceCollectionId, |
52 | &deviceCollection.WorkShopName, | 53 | &deviceCollection.WorkShopName, |
53 | &deviceCollection.DeviceSn, | 54 | &deviceCollection.DeviceSn, |
55 | + &deviceCollection.DeviceType, | ||
54 | &deviceCollection.StartupStatus, | 56 | &deviceCollection.StartupStatus, |
55 | &deviceCollection.ComStatus, | 57 | &deviceCollection.ComStatus, |
56 | &deviceCollection.Values, | 58 | &deviceCollection.Values, |
57 | ), | 59 | ), |
58 | - fmt.Sprintf("INSERT INTO device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 60 | + fmt.Sprintf("INSERT INTO manufacture.device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
59 | deviceCollection.DeviceCollectionId, | 61 | deviceCollection.DeviceCollectionId, |
60 | deviceCollection.WorkShopName, | 62 | deviceCollection.WorkShopName, |
61 | deviceCollection.DeviceSn, | 63 | deviceCollection.DeviceSn, |
64 | + deviceCollection.DeviceType, | ||
62 | deviceCollection.StartupStatus, | 65 | deviceCollection.StartupStatus, |
63 | deviceCollection.ComStatus, | 66 | deviceCollection.ComStatus, |
64 | deviceCollection.Values, | 67 | deviceCollection.Values, |
@@ -71,14 +74,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | @@ -71,14 +74,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi | ||
71 | &deviceCollection.DeviceCollectionId, | 74 | &deviceCollection.DeviceCollectionId, |
72 | &deviceCollection.WorkShopName, | 75 | &deviceCollection.WorkShopName, |
73 | &deviceCollection.DeviceSn, | 76 | &deviceCollection.DeviceSn, |
77 | + &deviceCollection.DeviceType, | ||
74 | &deviceCollection.StartupStatus, | 78 | &deviceCollection.StartupStatus, |
75 | &deviceCollection.ComStatus, | 79 | &deviceCollection.ComStatus, |
76 | &deviceCollection.Values, | 80 | &deviceCollection.Values, |
77 | ), | 81 | ), |
78 | - fmt.Sprintf("UPDATE device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
79 | - deviceCollection.DeviceCollectionId, | 82 | + fmt.Sprintf("UPDATE manufacture.device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
83 | + //deviceCollection.DeviceCollectionId, | ||
80 | deviceCollection.WorkShopName, | 84 | deviceCollection.WorkShopName, |
81 | deviceCollection.DeviceSn, | 85 | deviceCollection.DeviceSn, |
86 | + deviceCollection.DeviceType, | ||
82 | deviceCollection.StartupStatus, | 87 | deviceCollection.StartupStatus, |
83 | deviceCollection.ComStatus, | 88 | deviceCollection.ComStatus, |
84 | deviceCollection.Values, | 89 | deviceCollection.Values, |
@@ -123,6 +128,12 @@ func (repository *DeviceCollectionRepository) Find(queryOptions map[string]inter | @@ -123,6 +128,12 @@ func (repository *DeviceCollectionRepository) Find(queryOptions map[string]inter | ||
123 | query := sqlbuilder.BuildQuery(tx.Model(&deviceCollectionModels), queryOptions) | 128 | query := sqlbuilder.BuildQuery(tx.Model(&deviceCollectionModels), queryOptions) |
124 | query.SetOffsetAndLimit(20) | 129 | query.SetOffsetAndLimit(20) |
125 | query.SetOrderDirect("device_collection_id", "DESC") | 130 | query.SetOrderDirect("device_collection_id", "DESC") |
131 | + if deviceType,ok := queryOptions["deviceType"];ok && deviceType != "" { | ||
132 | + query.SetWhereByQueryOption("device_type = ?", "deviceType") | ||
133 | + } | ||
134 | + if workShopName,ok := queryOptions["workShopName"];ok && workShopName.(string) != "" { | ||
135 | + query.SetWhereByQueryOption("work_shop_name = ?", "workShopName") | ||
136 | + } | ||
126 | if count, err := query.SelectAndCount(); err != nil { | 137 | if count, err := query.SelectAndCount(); err != nil { |
127 | return 0, deviceCollections, err | 138 | return 0, deviceCollections, err |
128 | } else { | 139 | } else { |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | "encoding/json" | 5 | "encoding/json" |
6 | "fmt" | 6 | "fmt" |
7 | "github.com/beego/beego/v2/core/validation" | 7 | "github.com/beego/beego/v2/core/validation" |
8 | + "github.com/bwmarrin/snowflake" | ||
8 | jsonlib "github.com/linmadan/egglib-go/utils/json" | 9 | jsonlib "github.com/linmadan/egglib-go/utils/json" |
9 | "github.com/shopspring/decimal" | 10 | "github.com/shopspring/decimal" |
10 | "io" | 11 | "io" |
@@ -381,9 +382,27 @@ func SubStr(str string, start, length int) string { | @@ -381,9 +382,27 @@ func SubStr(str string, start, length int) string { | ||
381 | return string(rs[start:end]) | 382 | return string(rs[start:end]) |
382 | } | 383 | } |
383 | 384 | ||
385 | + | ||
386 | +//生成新ID | ||
387 | +var snowFlakeNode *snowflake.Node | ||
388 | + | ||
389 | +func NewSnowflakeId() (int64, error) { | ||
390 | + if snowFlakeNode == nil { | ||
391 | + node, err := snowflake.NewNode(1) | ||
392 | + if err != nil { | ||
393 | + return 0, err | ||
394 | + } | ||
395 | + snowFlakeNode = node | ||
396 | + } | ||
397 | + // Generate a snowflake ID. | ||
398 | + id := snowFlakeNode.Generate() | ||
399 | + return id.Int64(), nil | ||
400 | +} | ||
401 | + | ||
384 | func Round(value float64, places int32) float64 { | 402 | func Round(value float64, places int32) float64 { |
385 | quantity := decimal.NewFromFloat(value) | 403 | quantity := decimal.NewFromFloat(value) |
386 | d := quantity.Round(places) | 404 | d := quantity.Round(places) |
387 | rsp, _ := d.Float64() | 405 | rsp, _ := d.Float64() |
388 | return rsp | 406 | return rsp |
389 | } | 407 | } |
408 | + |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/query" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/query" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/service" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/service" |
8 | + "strconv" | ||
8 | ) | 9 | ) |
9 | 10 | ||
10 | type DeviceCollectionController struct { | 11 | type DeviceCollectionController struct { |
@@ -25,6 +26,9 @@ func (controller *DeviceCollectionController) UpdateDeviceCollection() { | @@ -25,6 +26,9 @@ func (controller *DeviceCollectionController) UpdateDeviceCollection() { | ||
25 | controller.Unmarshal(updateDeviceCollectionCommand) | 26 | controller.Unmarshal(updateDeviceCollectionCommand) |
26 | //Id, _ := controller.GetString(":Id") | 27 | //Id, _ := controller.GetString(":Id") |
27 | //updateDeviceCollectionCommand.Id = Id | 28 | //updateDeviceCollectionCommand.Id = Id |
29 | + Id := controller.GetString(":Id") | ||
30 | + deviceCollectionId,_:= strconv.Atoi(Id) | ||
31 | + updateDeviceCollectionCommand.DeviceCollectionId = int64(deviceCollectionId) | ||
28 | data, err := deviceCollectionService.UpdateDeviceCollection(updateDeviceCollectionCommand) | 32 | data, err := deviceCollectionService.UpdateDeviceCollection(updateDeviceCollectionCommand) |
29 | controller.Response(data, err) | 33 | controller.Response(data, err) |
30 | } | 34 | } |
@@ -34,6 +38,9 @@ func (controller *DeviceCollectionController) GetDeviceCollection() { | @@ -34,6 +38,9 @@ func (controller *DeviceCollectionController) GetDeviceCollection() { | ||
34 | getDeviceCollectionQuery := &query.GetDeviceCollectionQuery{} | 38 | getDeviceCollectionQuery := &query.GetDeviceCollectionQuery{} |
35 | //Id, _ := controller.GetString(":Id") | 39 | //Id, _ := controller.GetString(":Id") |
36 | //getDeviceCollectionQuery.Id = Id | 40 | //getDeviceCollectionQuery.Id = Id |
41 | + Id := controller.GetString(":Id") | ||
42 | + deviceCollectionId,_:= strconv.Atoi(Id) | ||
43 | + getDeviceCollectionQuery.DeviceCollectionId = int64(deviceCollectionId) | ||
37 | data, err := deviceCollectionService.GetDeviceCollection(getDeviceCollectionQuery) | 44 | data, err := deviceCollectionService.GetDeviceCollection(getDeviceCollectionQuery) |
38 | controller.Response(data, err) | 45 | controller.Response(data, err) |
39 | } | 46 | } |
@@ -42,8 +49,9 @@ func (controller *DeviceCollectionController) RemoveDeviceCollection() { | @@ -42,8 +49,9 @@ func (controller *DeviceCollectionController) RemoveDeviceCollection() { | ||
42 | deviceCollectionService := service.NewDeviceCollectionService(nil) | 49 | deviceCollectionService := service.NewDeviceCollectionService(nil) |
43 | removeDeviceCollectionCommand := &command.RemoveDeviceCollectionCommand{} | 50 | removeDeviceCollectionCommand := &command.RemoveDeviceCollectionCommand{} |
44 | controller.Unmarshal(removeDeviceCollectionCommand) | 51 | controller.Unmarshal(removeDeviceCollectionCommand) |
45 | - //Id, _ := controller.GetString(":Id") | ||
46 | - //removeDeviceCollectionCommand.Id = Id | 52 | + Id := controller.GetString(":Id") |
53 | + deviceCollectionId,_:= strconv.Atoi(Id) | ||
54 | + removeDeviceCollectionCommand.DeviceCollectionId = int64(deviceCollectionId) | ||
47 | data, err := deviceCollectionService.RemoveDeviceCollection(removeDeviceCollectionCommand) | 55 | data, err := deviceCollectionService.RemoveDeviceCollection(removeDeviceCollectionCommand) |
48 | controller.Response(data, err) | 56 | controller.Response(data, err) |
49 | } | 57 | } |
@@ -51,10 +59,7 @@ func (controller *DeviceCollectionController) RemoveDeviceCollection() { | @@ -51,10 +59,7 @@ func (controller *DeviceCollectionController) RemoveDeviceCollection() { | ||
51 | func (controller *DeviceCollectionController) ListDeviceCollection() { | 59 | func (controller *DeviceCollectionController) ListDeviceCollection() { |
52 | deviceCollectionService := service.NewDeviceCollectionService(nil) | 60 | deviceCollectionService := service.NewDeviceCollectionService(nil) |
53 | listDeviceCollectionQuery := &query.ListDeviceCollectionQuery{} | 61 | listDeviceCollectionQuery := &query.ListDeviceCollectionQuery{} |
54 | - offset, _ := controller.GetInt("offset") | ||
55 | - listDeviceCollectionQuery.Offset = offset | ||
56 | - limit, _ := controller.GetInt("limit") | ||
57 | - listDeviceCollectionQuery.Limit = limit | 62 | + _ = controller.Unmarshal(listDeviceCollectionQuery) |
58 | data, err := deviceCollectionService.ListDeviceCollection(listDeviceCollectionQuery) | 63 | data, err := deviceCollectionService.ListDeviceCollection(listDeviceCollectionQuery) |
59 | controller.Response(data, err) | 64 | controller.Response(data, err) |
60 | } | 65 | } |
@@ -10,5 +10,5 @@ func init() { | @@ -10,5 +10,5 @@ func init() { | ||
10 | web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Put:UpdateDeviceCollection") | 10 | web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Put:UpdateDeviceCollection") |
11 | web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Get:GetDeviceCollection") | 11 | web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Get:GetDeviceCollection") |
12 | web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Delete:RemoveDeviceCollection") | 12 | web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Delete:RemoveDeviceCollection") |
13 | - web.Router("/device-collections/", &controllers.DeviceCollectionController{}, "Get:ListDeviceCollection") | 13 | + web.Router("/device-collections/list", &controllers.DeviceCollectionController{}, "Post:ListDeviceCollection") |
14 | } | 14 | } |
@@ -2,12 +2,16 @@ package mqtt | @@ -2,12 +2,16 @@ package mqtt | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | + "fmt" | ||
5 | pahomqtt "github.com/eclipse/paho.mqtt.golang" | 6 | pahomqtt "github.com/eclipse/paho.mqtt.golang" |
7 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
6 | "github.com/tidwall/gjson" | 8 | "github.com/tidwall/gjson" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/service" | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
9 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/mqtt" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/mqtt" |
14 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 16 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
13 | "time" | 17 | "time" |
@@ -50,7 +54,7 @@ func Start() { | @@ -50,7 +54,7 @@ func Start() { | ||
50 | if err != nil { | 54 | if err != nil { |
51 | continue | 55 | continue |
52 | } | 56 | } |
53 | - deviceCollection.Values = deviceBaoXianJi | 57 | + deviceCollection.Values = tool_funs.SimpleStructToMap(deviceBaoXianJi) |
54 | break | 58 | break |
55 | //油炸机 | 59 | //油炸机 |
56 | case domain.DeviceTypeYouZhaJi: | 60 | case domain.DeviceTypeYouZhaJi: |
@@ -59,7 +63,7 @@ func Start() { | @@ -59,7 +63,7 @@ func Start() { | ||
59 | if err != nil { | 63 | if err != nil { |
60 | continue | 64 | continue |
61 | } | 65 | } |
62 | - deviceCollection.Values = deviceYouZhaJi | 66 | + deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi) |
63 | break | 67 | break |
64 | //串串机 | 68 | //串串机 |
65 | case domain.DeviceTypeChuanChuanJi: | 69 | case domain.DeviceTypeChuanChuanJi: |
@@ -68,7 +72,7 @@ func Start() { | @@ -68,7 +72,7 @@ func Start() { | ||
68 | if err != nil { | 72 | if err != nil { |
69 | continue | 73 | continue |
70 | } | 74 | } |
71 | - deviceCollection.Values = deviceChuanChuanJi | 75 | + deviceCollection.Values = tool_funs.SimpleStructToMap(deviceChuanChuanJi) |
72 | break | 76 | break |
73 | //速冻线 | 77 | //速冻线 |
74 | case domain.DeviceTypeSuDongXian: | 78 | case domain.DeviceTypeSuDongXian: |
@@ -77,7 +81,7 @@ func Start() { | @@ -77,7 +81,7 @@ func Start() { | ||
77 | if err != nil { | 81 | if err != nil { |
78 | continue | 82 | continue |
79 | } | 83 | } |
80 | - deviceCollection.Values = deviceSuDongXian | 84 | + deviceCollection.Values = tool_funs.SimpleStructToMap(deviceSuDongXian) |
81 | break | 85 | break |
82 | //封口机 | 86 | //封口机 |
83 | case domain.DeviceTypeFengKouJi: | 87 | case domain.DeviceTypeFengKouJi: |
@@ -86,7 +90,7 @@ func Start() { | @@ -86,7 +90,7 @@ func Start() { | ||
86 | if err != nil { | 90 | if err != nil { |
87 | continue | 91 | continue |
88 | } | 92 | } |
89 | - deviceCollection.Values = deviceFengKouJi | 93 | + deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengKouJi) |
90 | break | 94 | break |
91 | //封箱机 | 95 | //封箱机 |
92 | case domain.DeviceTypeFengXiangJi: | 96 | case domain.DeviceTypeFengXiangJi: |
@@ -95,31 +99,60 @@ func Start() { | @@ -95,31 +99,60 @@ func Start() { | ||
95 | if err != nil { | 99 | if err != nil { |
96 | continue | 100 | continue |
97 | } | 101 | } |
98 | - deviceCollection.Values = deviceFengXiangJi | 102 | + deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengXiangJi) |
99 | break | 103 | break |
100 | //打浆机 | 104 | //打浆机 |
101 | case domain.DeviceTypeDaJiangJi: | 105 | case domain.DeviceTypeDaJiangJi: |
102 | default: | 106 | default: |
103 | } | 107 | } |
104 | - //workShopBytes, err := json.Marshal(deviceCollection) | ||
105 | - //if err != nil { | ||
106 | - // continue | ||
107 | - //} | ||
108 | - //err = redis.GetRedis().LPush(constant.REDIS_WORKSHOP_KEY, string(workShopBytes)).Err() | ||
109 | - //if err != nil { | ||
110 | - // log.Logger.Error("车间设备数据加入redis失败:" + err.Error()) | ||
111 | - //} | ||
112 | - err = domainService.SendWorkshopDeviceData(deviceCollection) | 108 | + deviceCollectionService := service.NewDeviceCollectionService(nil) |
109 | + resp, err := deviceCollectionService.CreateDeviceCollection(&command.CreateDeviceCollectionCommand{ | ||
110 | + WorkShopName: deviceCollection.WorkShopName, | ||
111 | + StartupStatus: deviceCollection.StartupStatus, | ||
112 | + CollectionTime: deviceCollection.CollectionTime, | ||
113 | + DeviceSn: deviceCollection.DeviceSn, | ||
114 | + DeviceType: deviceCollection.DeviceType, | ||
115 | + ComStatus: deviceCollection.ComStatus, | ||
116 | + Values: deviceCollection.Values, | ||
117 | + }) | ||
113 | if err != nil { | 118 | if err != nil { |
114 | - log.Logger.Error("车间设备数据加入redis失败:" + err.Error()) | 119 | + continue |
120 | + } | ||
121 | + | ||
122 | + result := resp.(map[string]interface{}) | ||
123 | + if deviceCollectionResult, ok := result["deviceCollection"]; ok { | ||
124 | + fmt.Println(deviceCollectionResult) | ||
125 | + deviceCollection.DeviceCollectionId = deviceCollectionResult.(*domain.DeviceCollection).DeviceCollectionId | ||
126 | + workShopBytes, err := json.Marshal(deviceCollection) | ||
127 | + if err != nil { | ||
128 | + continue | ||
129 | + } | ||
130 | + err = redis.GetRedis().LPush(constant.REDIS_WORKSHOP_KEY, string(workShopBytes)).Err() | ||
131 | + if err != nil { | ||
132 | + log.Logger.Error("车间设备数据加入redis失败:" + err.Error()) | ||
133 | + } | ||
134 | + | ||
135 | + //workShopBytes, err := json.Marshal(deviceCollection) | ||
136 | + //if err != nil { | ||
137 | + // continue | ||
138 | + //} | ||
139 | + //err = redis.GetRedis().LPush(constant.REDIS_WORKSHOP_KEY, string(workShopBytes)).Err() | ||
140 | + //if err != nil { | ||
141 | + // log.Logger.Error("车间设备数据加入redis失败:" + err.Error()) | ||
142 | + //} | ||
143 | + //err = domainService.SendWorkshopDeviceData(deviceCollection) | ||
144 | + //if err != nil { | ||
145 | + // log.Logger.Error("车间设备数据加入redis失败:" + err.Error()) | ||
146 | + // | ||
147 | + //} | ||
115 | } | 148 | } |
116 | } | 149 | } |
150 | + log.Logger.Info("MQTT", map[string]interface{}{ | ||
151 | + "Topic": message.Topic(), | ||
152 | + "MessageId": message.MessageID(), | ||
153 | + "Message": payload, | ||
154 | + }) | ||
117 | } | 155 | } |
118 | - log.Logger.Info("MQTT", map[string]interface{}{ | ||
119 | - "Topic": message.Topic(), | ||
120 | - "MessageId": message.MessageID(), | ||
121 | - "Message": payload, | ||
122 | - }) | ||
123 | } | 156 | } |
124 | }) | 157 | }) |
125 | -} | 158 | +} |
-
请 注册 或 登录 后发表评论