作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-manufacture into dev
... ... @@ -5,6 +5,7 @@ go 1.16
require (
github.com/ajg/form v1.5.1 // indirect
github.com/beego/beego/v2 v2.0.1
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/eclipse/paho.mqtt.golang v1.3.5
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
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
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
... ...
... ... @@ -4,27 +4,32 @@ import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateDeviceCollectionCommand struct {
// 数据采集ID
DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"`
//DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"`
// 车间名
WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"`
// 启动状态 1-启动 0-停止
StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus,string" valid:"Required"`
StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus"`
// 采集时间
CollectionTime time.Time `cname:"采集时间" json:"collectionTime" valid:"Required"`
// 设备名
DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"`
// 设备类型
DeviceType string `comment:"设备类型" json:"deviceType" valid:"Required"`
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus,string" valid:"Required"`
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus"`
// 设备数据值
Values string `cname:"设备数据值" json:"values" valid:"Required"`
Values map[string]interface{} `cname:"设备数据值" json:"values" valid:"Required"`
}
func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type RemoveDeviceCollectionCommand struct {
}
func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) ValidateCommand() error {
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
... ... @@ -14,17 +15,21 @@ type UpdateDeviceCollectionCommand struct {
// 车间名
WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"`
// 启动状态 1-启动 0-停止
StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus,string" valid:"Required"`
StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus"`
// 采集时间
CollectionTime time.Time `cname:"采集时间" json:"collectionTime" valid:"Required"`
// 设备名
DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"`
// 设备类型
DeviceType string `comment:"设备类型" json:"deviceType" valid:"Required"`
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus,string" valid:"Required"`
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus"`
// 设备数据值
Values string `cname:"设备数据值" json:"values" valid:"Required"`
Values map[string]interface{} `cname:"设备数据值" json:"values" valid:"Required"`
}
func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) ValidateCommand() error {
... ...
... ... @@ -10,13 +10,17 @@ import (
type ListDeviceCollectionQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
PageNumber int64 `cname:"查询偏离量" json:"pageNumber" `
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
PageSize int64 `cname:"查询限制" json:"pageSize" valid:"Required"`
// 设备类型
DeviceType string `json:"deviceType" cname:"设备类型"`
// 车间名
WorkShopName string `json:"workShopName"`
}
func (listDeviceCollectionQuery *ListDeviceCollectionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDeviceCollectionQuery *ListDeviceCollectionQuery) ValidateQuery() error {
... ...
... ... @@ -29,8 +29,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c
transactionContext.RollbackTransaction()
}()
newDeviceCollection := &domain.DeviceCollection{
DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId,
//DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId,
WorkShopName: createDeviceCollectionCommand.WorkShopName,
DeviceType: createDeviceCollectionCommand.DeviceType,
StartupStatus: createDeviceCollectionCommand.StartupStatus,
DeviceSn: createDeviceCollectionCommand.DeviceSn,
ComStatus: createDeviceCollectionCommand.ComStatus,
... ... @@ -50,7 +51,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return deviceCollection, nil
return map[string]interface{}{
"deviceCollection":deviceCollection,
}, nil
}
}
... ... @@ -120,10 +123,7 @@ func (deviceCollectionService *DeviceCollectionService) ListDeviceCollection(lis
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"deviceCollections": deviceCollections,
}, nil
return tool_funs.SimpleWrapGridMap(count,deviceCollections), nil
}
}
... ... @@ -163,7 +163,9 @@ func (deviceCollectionService *DeviceCollectionService) RemoveDeviceCollection(r
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return deviceCollection, nil
return map[string]interface{}{
"deviceCollection":deviceCollection,
}, nil
}
}
... ... @@ -206,7 +208,9 @@ func (deviceCollectionService *DeviceCollectionService) UpdateDeviceCollection(u
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return deviceCollection, nil
return map[string]interface{}{
"deviceCollection":deviceCollection,
}, nil
}
}
... ...
... ... @@ -5,6 +5,21 @@ import "os"
var MQTT_TOPIC = "/MQTT"
//设备商提供的测试地址
//var MQTT_HOST = "175.24.122.87"
//var MQTT_PORT = "1883"
//var MQTT_USER = "user111"
//var MQTT_PASSWORD = "user111"
//内网测试地址
//var MQTT_HOST = "192.168.100.222"
//var MQTT_PORT = "1883"
//var MQTT_USER = "admin"
//var MQTT_PASSWORD = "123456"
//var MQTT_HOST = "192.168.31.51"
//var MQTT_PORT = "1883"
//var MQTT_USER = ""
//var MQTT_PASSWORD = ""
var MQTT_HOST = "175.24.122.87"
var MQTT_PORT = "1883"
var MQTT_USER = "user111"
... ...
... ... @@ -23,7 +23,7 @@ type DeviceCollection struct {
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `json:"comStatus"`
// 设备数据值
Values interface{} `json:"values"`
Values map[string]interface{} `json:"values"`
}
var (
... ... @@ -71,7 +71,10 @@ func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) er
deviceCollection.DeviceSn = deviceSn.(string)
}
if deviceType, ok := data["deviceType"]; ok {
deviceCollection.DeviceSn = deviceType.(string)
deviceCollection.DeviceType = deviceType.(string)
}
if collectionTime, ok := data["collectionTime"]; ok {
deviceCollection.CollectionTime = collectionTime.(time.Time)
}
if startupStatus, ok := data["startupStatus"]; ok {
deviceCollection.StartupStatus = startupStatus.(int64)
... ... @@ -80,7 +83,7 @@ func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) er
deviceCollection.ComStatus = comStatus.(int64)
}
if values, ok := data["values"]; ok {
deviceCollection.Values = values
deviceCollection.Values = values.(map[string]interface{})
}
return nil
}
... ...
... ... @@ -28,6 +28,7 @@ func init() {
if !constant.DISABLE_CREATE_TABLE {
for _, model := range []interface{}{
(*models.Device)(nil),
(*models.DeviceCollection)(nil),
(*models.Product)(nil),
(*models.ProductAttendanceRecord)(nil),
(*models.ProductCalendar)(nil),
... ...
... ... @@ -17,7 +17,7 @@ type DeviceCollection struct {
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `comment:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" pg:",use_zero"`
// 设备数据值
Values interface{} `comment:"设备数据值"`
Values map[string]interface{} `comment:"设备数据值" pg:""`
// 创建时间
CreatedAt time.Time `comment:"创建时间" pg:",default:now()"`
// 更新时间
... ...
... ... @@ -10,6 +10,7 @@ func TransformToDeviceCollectionDomainModelFromPgModels(deviceCollectionModel *m
DeviceCollectionId: deviceCollectionModel.DeviceCollectionId,
WorkShopName: deviceCollectionModel.WorkShopName,
DeviceSn: deviceCollectionModel.DeviceSn,
DeviceType: deviceCollectionModel.DeviceType,
StartupStatus: deviceCollectionModel.StartupStatus,
ComStatus: deviceCollectionModel.ComStatus,
Values: deviceCollectionModel.Values,
... ...
... ... @@ -3,10 +3,10 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
... ... @@ -17,18 +17,19 @@ type DeviceCollectionRepository struct {
}
func (repository *DeviceCollectionRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
//IdWorker, err := snowflake.NewIdWorker(1)
//if err != nil {
// return 0, err
//}
//id, err := IdWorker.NextId()
return utils.NewSnowflakeId()
}
func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.DeviceCollection) (*domain.DeviceCollection, error) {
sqlBuildFields := []string{
"device_collection_id",
"work_shop_name",
"device_sn",
"device_type",
"startup_status",
"com_status",
"values",
... ... @@ -36,7 +37,7 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "deviceCollection_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_collection_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if deviceCollection.Identify() == nil {
... ... @@ -51,14 +52,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi
&deviceCollection.DeviceCollectionId,
&deviceCollection.WorkShopName,
&deviceCollection.DeviceSn,
&deviceCollection.DeviceType,
&deviceCollection.StartupStatus,
&deviceCollection.ComStatus,
&deviceCollection.Values,
),
fmt.Sprintf("INSERT INTO device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
fmt.Sprintf("INSERT INTO manufacture.device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
deviceCollection.DeviceCollectionId,
deviceCollection.WorkShopName,
deviceCollection.DeviceSn,
deviceCollection.DeviceType,
deviceCollection.StartupStatus,
deviceCollection.ComStatus,
deviceCollection.Values,
... ... @@ -71,14 +74,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi
&deviceCollection.DeviceCollectionId,
&deviceCollection.WorkShopName,
&deviceCollection.DeviceSn,
&deviceCollection.DeviceType,
&deviceCollection.StartupStatus,
&deviceCollection.ComStatus,
&deviceCollection.Values,
),
fmt.Sprintf("UPDATE device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
deviceCollection.DeviceCollectionId,
fmt.Sprintf("UPDATE manufacture.device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
//deviceCollection.DeviceCollectionId,
deviceCollection.WorkShopName,
deviceCollection.DeviceSn,
deviceCollection.DeviceType,
deviceCollection.StartupStatus,
deviceCollection.ComStatus,
deviceCollection.Values,
... ... @@ -123,6 +128,12 @@ func (repository *DeviceCollectionRepository) Find(queryOptions map[string]inter
query := sqlbuilder.BuildQuery(tx.Model(&deviceCollectionModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("device_collection_id", "DESC")
if deviceType,ok := queryOptions["deviceType"];ok && deviceType != "" {
query.SetWhereByQueryOption("device_type = ?", "deviceType")
}
if workShopName,ok := queryOptions["workShopName"];ok && workShopName.(string) != "" {
query.SetWhereByQueryOption("work_shop_name = ?", "workShopName")
}
if count, err := query.SelectAndCount(); err != nil {
return 0, deviceCollections, err
} else {
... ...
... ... @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/beego/beego/v2/core/validation"
"github.com/bwmarrin/snowflake"
jsonlib "github.com/linmadan/egglib-go/utils/json"
"github.com/shopspring/decimal"
"io"
... ... @@ -381,9 +382,27 @@ func SubStr(str string, start, length int) string {
return string(rs[start:end])
}
//生成新ID
var snowFlakeNode *snowflake.Node
func NewSnowflakeId() (int64, error) {
if snowFlakeNode == nil {
node, err := snowflake.NewNode(1)
if err != nil {
return 0, err
}
snowFlakeNode = node
}
// Generate a snowflake ID.
id := snowFlakeNode.Generate()
return id.Int64(), nil
}
func Round(value float64, places int32) float64 {
quantity := decimal.NewFromFloat(value)
d := quantity.Round(places)
rsp, _ := d.Float64()
return rsp
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/service"
"strconv"
)
type DeviceCollectionController struct {
... ... @@ -25,6 +26,9 @@ func (controller *DeviceCollectionController) UpdateDeviceCollection() {
controller.Unmarshal(updateDeviceCollectionCommand)
//Id, _ := controller.GetString(":Id")
//updateDeviceCollectionCommand.Id = Id
Id := controller.GetString(":Id")
deviceCollectionId,_:= strconv.Atoi(Id)
updateDeviceCollectionCommand.DeviceCollectionId = int64(deviceCollectionId)
data, err := deviceCollectionService.UpdateDeviceCollection(updateDeviceCollectionCommand)
controller.Response(data, err)
}
... ... @@ -34,6 +38,9 @@ func (controller *DeviceCollectionController) GetDeviceCollection() {
getDeviceCollectionQuery := &query.GetDeviceCollectionQuery{}
//Id, _ := controller.GetString(":Id")
//getDeviceCollectionQuery.Id = Id
Id := controller.GetString(":Id")
deviceCollectionId,_:= strconv.Atoi(Id)
getDeviceCollectionQuery.DeviceCollectionId = int64(deviceCollectionId)
data, err := deviceCollectionService.GetDeviceCollection(getDeviceCollectionQuery)
controller.Response(data, err)
}
... ... @@ -42,8 +49,9 @@ func (controller *DeviceCollectionController) RemoveDeviceCollection() {
deviceCollectionService := service.NewDeviceCollectionService(nil)
removeDeviceCollectionCommand := &command.RemoveDeviceCollectionCommand{}
controller.Unmarshal(removeDeviceCollectionCommand)
//Id, _ := controller.GetString(":Id")
//removeDeviceCollectionCommand.Id = Id
Id := controller.GetString(":Id")
deviceCollectionId,_:= strconv.Atoi(Id)
removeDeviceCollectionCommand.DeviceCollectionId = int64(deviceCollectionId)
data, err := deviceCollectionService.RemoveDeviceCollection(removeDeviceCollectionCommand)
controller.Response(data, err)
}
... ... @@ -51,10 +59,7 @@ func (controller *DeviceCollectionController) RemoveDeviceCollection() {
func (controller *DeviceCollectionController) ListDeviceCollection() {
deviceCollectionService := service.NewDeviceCollectionService(nil)
listDeviceCollectionQuery := &query.ListDeviceCollectionQuery{}
offset, _ := controller.GetInt("offset")
listDeviceCollectionQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listDeviceCollectionQuery.Limit = limit
_ = controller.Unmarshal(listDeviceCollectionQuery)
data, err := deviceCollectionService.ListDeviceCollection(listDeviceCollectionQuery)
controller.Response(data, err)
}
... ...
... ... @@ -10,5 +10,5 @@ func init() {
web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Put:UpdateDeviceCollection")
web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Get:GetDeviceCollection")
web.Router("/device-collections/:Id", &controllers.DeviceCollectionController{}, "Delete:RemoveDeviceCollection")
web.Router("/device-collections/", &controllers.DeviceCollectionController{}, "Get:ListDeviceCollection")
web.Router("/device-collections/list", &controllers.DeviceCollectionController{}, "Post:ListDeviceCollection")
}
... ...
... ... @@ -2,12 +2,16 @@ package mqtt
import (
"encoding/json"
"fmt"
pahomqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/tidwall/gjson"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/mqtt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
... ... @@ -50,7 +54,7 @@ func Start() {
if err != nil {
continue
}
deviceCollection.Values = deviceBaoXianJi
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceBaoXianJi)
break
//油炸机
case domain.DeviceTypeYouZhaJi1:
... ... @@ -59,7 +63,7 @@ func Start() {
if err != nil {
continue
}
deviceCollection.Values = deviceYouZhaJi
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi)
break
//油炸机
case domain.DeviceTypeYouZhaJi2:
... ... @@ -77,7 +81,7 @@ func Start() {
if err != nil {
continue
}
deviceCollection.Values = deviceChuanChuanJi
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceChuanChuanJi)
break
//速冻线
case domain.DeviceTypeSuDongXian:
... ... @@ -86,7 +90,7 @@ func Start() {
if err != nil {
continue
}
deviceCollection.Values = deviceSuDongXian
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceSuDongXian)
break
//封口机
case domain.DeviceTypeFengKouJi:
... ... @@ -95,7 +99,7 @@ func Start() {
if err != nil {
continue
}
deviceCollection.Values = deviceFengKouJi
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengKouJi)
break
//封箱机
case domain.DeviceTypeFengXiangJi:
... ... @@ -104,31 +108,60 @@ func Start() {
if err != nil {
continue
}
deviceCollection.Values = deviceFengXiangJi
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengXiangJi)
break
//打浆机
case domain.DeviceTypeDaJiangJi:
default:
}
//workShopBytes, err := json.Marshal(deviceCollection)
//if err != nil {
// continue
//}
//err = redis.GetRedis().LPush(constant.REDIS_WORKSHOP_KEY, string(workShopBytes)).Err()
//if err != nil {
// log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
//}
err = domainService.SendWorkshopDeviceData(deviceCollection)
deviceCollectionService := service.NewDeviceCollectionService(nil)
resp, err := deviceCollectionService.CreateDeviceCollection(&command.CreateDeviceCollectionCommand{
WorkShopName: deviceCollection.WorkShopName,
StartupStatus: deviceCollection.StartupStatus,
CollectionTime: deviceCollection.CollectionTime,
DeviceSn: deviceCollection.DeviceSn,
DeviceType: deviceCollection.DeviceType,
ComStatus: deviceCollection.ComStatus,
Values: deviceCollection.Values,
})
if err != nil {
log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
continue
}
result := resp.(map[string]interface{})
if deviceCollectionResult, ok := result["deviceCollection"]; ok {
fmt.Println(deviceCollectionResult)
deviceCollection.DeviceCollectionId = deviceCollectionResult.(*domain.DeviceCollection).DeviceCollectionId
workShopBytes, err := json.Marshal(deviceCollection)
if err != nil {
continue
}
err = redis.GetRedis().LPush(constant.REDIS_WORKSHOP_KEY, string(workShopBytes)).Err()
if err != nil {
log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
}
//workShopBytes, err := json.Marshal(deviceCollection)
//if err != nil {
// continue
//}
//err = redis.GetRedis().LPush(constant.REDIS_WORKSHOP_KEY, string(workShopBytes)).Err()
//if err != nil {
// log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
//}
//err = domainService.SendWorkshopDeviceData(deviceCollection)
//if err != nil {
// log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
//
//}
}
}
log.Logger.Info("MQTT", map[string]interface{}{
"Topic": message.Topic(),
"MessageId": message.MessageID(),
"Message": payload,
})
}
log.Logger.Info("MQTT", map[string]interface{}{
"Topic": message.Topic(),
"MessageId": message.MessageID(),
"Message": payload,
})
}
})
}
}
\ No newline at end of file
... ...