作者 yangfu

refactor: 设备原数据查询修改,数据消费修改

@@ -50,7 +50,7 @@ func AutoFlushDeviceDailyRunningRecord(ctx context.Context) error { @@ -50,7 +50,7 @@ func AutoFlushDeviceDailyRunningRecord(ctx context.Context) error {
50 // 更新设备效率 OEE = tu * pu * qu 50 // 更新设备效率 OEE = tu * pu * qu
51 51
52 if _, err := deviceDailyRunningRecordRepository.Save(v); err != nil { 52 if _, err := deviceDailyRunningRecordRepository.Save(v); err != nil {
53 - log.Logger.Error(err.Error()) 53 + log.Logger.Error(err.Error(), map[string]interface{}{"record": v})
54 continue 54 continue
55 } else { 55 } else {
56 log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录】 刷新记录 %v", v)) 56 log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录】 刷新记录 %v", v))
  1 +package dto
  2 +
  3 +import "time"
  4 +
  5 +type DeviceCollectionDto struct {
  6 + // 数据采集ID
  7 + DeviceCollectionId int64 `json:"deviceCollectionId,string"`
  8 + // 车间名
  9 + WorkShopName string `json:"workShopName"`
  10 + // 采集时间
  11 + CollectionTime time.Time `json:"collectionTime"`
  12 + // 设备名
  13 + DeviceSn string `json:"deviceSn"`
  14 + // 设备类型
  15 + DeviceType string `json:"deviceType"`
  16 + // 启动状态 1-启动 0-停止
  17 + StartupStatus int64 `json:"startupStatus"`
  18 + // 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
  19 + ComStatus int64 `json:"comStatus"`
  20 + // 设备数据值
  21 + Values map[string]interface{} `json:"values"`
  22 +}
@@ -2,8 +2,10 @@ package query @@ -2,8 +2,10 @@ package query
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
5 "reflect" 6 "reflect"
6 "strings" 7 "strings"
  8 + "time"
7 9
8 "github.com/beego/beego/v2/core/validation" 10 "github.com/beego/beego/v2/core/validation"
9 ) 11 )
@@ -17,20 +19,47 @@ type ListDeviceCollectionQuery struct { @@ -17,20 +19,47 @@ type ListDeviceCollectionQuery struct {
17 DeviceType string `json:"deviceType" cname:"设备类型"` 19 DeviceType string `json:"deviceType" cname:"设备类型"`
18 // 车间名 20 // 车间名
19 WorkShopName string `json:"workShopName"` 21 WorkShopName string `json:"workShopName"`
  22 +
  23 + // 开始时间
  24 + BeginTime string `cname:"开始时间" json:"beginTime"`
  25 + // 结束时间
  26 + EndTime string `cname:"结束时间" json:"endTime"`
  27 +
  28 + // 开始时间
  29 + ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"`
  30 + // 结束时间
  31 + ProductEndTime time.Time `cname:"结束时间" json:"productEndTime"`
20 } 32 }
21 33
22 -func (listDeviceCollectionQuery *ListDeviceCollectionQuery) Valid(validation *validation.Validation) {  
23 - //validation.SetError("CustomValid", "未实现的自定义认证") 34 +func (cmd *ListDeviceCollectionQuery) Valid(validation *validation.Validation) {
  35 + var err error
  36 + if len(cmd.BeginTime) > 0 {
  37 + if cmd.ProductBeginTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.BeginTime, time.Local); err != nil {
  38 + log.Logger.Error(err.Error())
  39 + validation.Error("开始时间有误")
  40 + return
  41 + }
  42 + }
  43 + if len(cmd.EndTime) > 0 {
  44 + if cmd.ProductEndTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.EndTime, time.Local); err != nil {
  45 + log.Logger.Error(err.Error())
  46 + validation.Error("结束时间有误")
  47 + return
  48 + }
  49 + if cmd.ProductBeginTime.Equal(cmd.ProductEndTime) {
  50 + cmd.ProductEndTime = cmd.ProductEndTime.Add(time.Hour * 24)
  51 + }
  52 + }
24 } 53 }
25 54
26 -func (listDeviceCollectionQuery *ListDeviceCollectionQuery) ValidateQuery() error { 55 +func (cmd *ListDeviceCollectionQuery) ValidateQuery() error {
27 valid := validation.Validation{} 56 valid := validation.Validation{}
28 - b, err := valid.Valid(listDeviceCollectionQuery) 57 + b, err := valid.Valid(cmd)
29 if err != nil { 58 if err != nil {
30 return err 59 return err
31 } 60 }
32 if !b { 61 if !b {
33 - elem := reflect.TypeOf(listDeviceCollectionQuery).Elem() 62 + elem := reflect.TypeOf(cmd).Elem()
34 for _, validErr := range valid.Errors { 63 for _, validErr := range valid.Errors {
35 field, isExist := elem.FieldByName(validErr.Field) 64 field, isExist := elem.FieldByName(validErr.Field)
36 if isExist { 65 if isExist {
@@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
  14 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" 15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
15 "strconv" 16 "strconv"
16 "sync" 17 "sync"
@@ -29,6 +30,57 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c @@ -29,6 +30,57 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c
29 if err := createDeviceCollectionCommand.ValidateCommand(); err != nil { 30 if err := createDeviceCollectionCommand.ValidateCommand(); err != nil {
30 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 31 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
31 } 32 }
  33 + transactionContext, err := factory.CreateTransactionContext(nil)
  34 + if err != nil {
  35 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  36 + }
  37 + if err := transactionContext.StartTransaction(); err != nil {
  38 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  39 + }
  40 + defer func() {
  41 + transactionContext.RollbackTransaction()
  42 + }()
  43 + newDeviceCollection := &domain.DeviceCollection{
  44 + //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId,
  45 + WorkShopName: createDeviceCollectionCommand.WorkShopName,
  46 + DeviceType: createDeviceCollectionCommand.DeviceType,
  47 + StartupStatus: createDeviceCollectionCommand.StartupStatus,
  48 + DeviceSn: createDeviceCollectionCommand.DeviceSn,
  49 + ComStatus: createDeviceCollectionCommand.ComStatus,
  50 + CollectionTime: createDeviceCollectionCommand.CollectionTime,
  51 + Values: createDeviceCollectionCommand.Values,
  52 + }
  53 + var deviceCollectionRepository domain.DeviceCollectionRepository
  54 + if value, err := factory.CreateDeviceCollectionRepository(map[string]interface{}{
  55 + "transactionContext": transactionContext,
  56 + }); err != nil {
  57 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  58 + } else {
  59 + deviceCollectionRepository = value
  60 + }
  61 + if deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection); err != nil {
  62 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  63 + } else {
  64 + //err = domainService.SendWorkshopDeviceData(deviceCollection)
  65 + //if err != nil {
  66 + // log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
  67 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  68 + //}
  69 +
  70 + if err := transactionContext.CommitTransaction(); err != nil {
  71 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  72 + }
  73 + return map[string]interface{}{
  74 + "deviceCollection": deviceCollection,
  75 + }, nil
  76 + }
  77 +}
  78 +
  79 +// 创建
  80 +func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createDeviceCollectionCommand *command.CreateDeviceCollectionCommand) (interface{}, error) {
  81 + if err := createDeviceCollectionCommand.ValidateCommand(); err != nil {
  82 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  83 + }
32 84
33 newDeviceCollection := &domain.DeviceCollection{ 85 newDeviceCollection := &domain.DeviceCollection{
34 //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId, 86 //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId,
@@ -73,34 +125,31 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c @@ -73,34 +125,31 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c
73 } else { 125 } else {
74 deviceCollectionRepository = value 126 deviceCollectionRepository = value
75 } 127 }
76 - deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection)  
77 - if err != nil {  
78 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
79 - }  
80 128
81 - //处理设备数据 129 + //计算区间的产能
82 //switch deviceCollection.DeviceType { 130 //switch deviceCollection.DeviceType {
83 //case domain.DeviceTypeBaoXianJi, domain.DeviceTypeChuanChuanJi, domain.DeviceTypeFengKouJi, domain.DeviceTypeFengXiangJi: 131 //case domain.DeviceTypeBaoXianJi, domain.DeviceTypeChuanChuanJi, domain.DeviceTypeFengKouJi, domain.DeviceTypeFengXiangJi:
84 - if v, ok := deviceCollection.Values["count"]; ok {  
85 - curCount, errCurCount := strconv.Atoi(fmt.Sprintf("%v", v))  
86 - v, ok = lastDeviceCollectionRecord.Values["count"]  
87 - if ok {  
88 - lastCount, errLastCount := strconv.Atoi(fmt.Sprintf("%v", v))  
89 - if errLastCount == nil && errCurCount == nil && lastCount <= curCount {  
90 - deviceCollection.Values["count"] = curCount - lastCount 132 + if v, ok := newDeviceCollection.Values["Count"]; ok {
  133 + newDeviceCollection.Values["total"] = v // 记录原始值
  134 + newDeviceCollection.Values["Count"] = 0
  135 + curCount, errCurCount := strconv.Atoi(utils.AssertString(v))
  136 + lastCount, errLastCount := strconv.Atoi(utils.AssertString(lastDeviceCollectionRecord.Values["Count"]))
  137 + if errLastCount == nil && errCurCount == nil && lastCount <= curCount {
  138 + if lastCount <= curCount {
  139 + newDeviceCollection.Values["Count"] = curCount - lastCount
91 } else { 140 } else {
92 - deviceCollection.Values["count"] = 0  
93 - /*  
94 - 设备统计的数量超过一定范围会重置为0,特殊处理0操作  
95 - */ 141 + newDeviceCollection.Values["Count"] = 0
  142 + /*设备统计的数量超过一定范围会重置为0,特殊处理0操作*/
96 if lastCount > 10000000 && curCount < 1000 { 143 if lastCount > 10000000 && curCount < 1000 {
97 - deviceCollection.Values["count"] = curCount 144 + newDeviceCollection.Values["Count"] = curCount
98 } 145 }
99 } 146 }
100 - } else {  
101 - deviceCollection.Values["count"] = 0  
102 } 147 }
103 } 148 }
  149 + deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection)
  150 + if err != nil {
  151 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  152 + }
104 // break 153 // break
105 //} 154 //}
106 err = domainService.SendWorkshopDeviceData(deviceCollection) 155 err = domainService.SendWorkshopDeviceData(deviceCollection)
@@ -28,6 +28,7 @@ type DeviceYouZhaJi2 struct { @@ -28,6 +28,7 @@ type DeviceYouZhaJi2 struct {
28 28
29 // 串串机 29 // 串串机
30 type DeviceChuanChuanJi struct { 30 type DeviceChuanChuanJi struct {
  31 + Total int64 `json:"Total"` // 累计生产计数:生产统计数量
31 Count int64 `json:"Count"` // 生产计数:生产统计数量 32 Count int64 `json:"Count"` // 生产计数:生产统计数量
32 Year int `json:"Year"` // 年 33 Year int `json:"Year"` // 年
33 Month int `json:"Month"` // 月 34 Month int `json:"Month"` // 月
@@ -3,11 +3,11 @@ package domain @@ -3,11 +3,11 @@ package domain
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
6 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"  
7 "time" 6 "time"
8 ) 7 )
9 8
10 const DefaultTimeWindow = 1 9 const DefaultTimeWindow = 1
  10 +const DefaultCollectionTimeSpan = 60 * 20
11 11
12 // 设备每日运行记录(汇总) 12 // 设备每日运行记录(汇总)
13 type DeviceDailyRunningRecord struct { 13 type DeviceDailyRunningRecord struct {
@@ -55,6 +55,11 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) Update(data map[string @@ -55,6 +55,11 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) Update(data map[string
55 55
56 func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(t time.Time, data *DeviceRunningData) { 56 func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(t time.Time, data *DeviceRunningData) {
57 deviceDailyRunningRecord.DeviceRunningRecordInfo.AddDeviceRunningData(t, data) 57 deviceDailyRunningRecord.DeviceRunningRecordInfo.AddDeviceRunningData(t, data)
  58 + now := time.Now().Unix()
  59 + if t.Unix() > (now-DefaultCollectionTimeSpan) && t.Unix() < (now+DefaultCollectionTimeSpan) {
  60 + deviceDailyRunningRecord.UpdatedAt = t
  61 + return
  62 + }
58 deviceDailyRunningRecord.UpdatedAt = time.Now() 63 deviceDailyRunningRecord.UpdatedAt = time.Now()
59 } 64 }
60 65
@@ -144,7 +149,7 @@ func (d *DeviceRunningRecordInfo) AddTimeLineDeviceStatus(t time.Time, data *Dev @@ -144,7 +149,7 @@ func (d *DeviceRunningRecordInfo) AddTimeLineDeviceStatus(t time.Time, data *Dev
144 return 149 return
145 } 150 }
146 key := fmt.Sprintf("%v", t.Local().Hour()) 151 key := fmt.Sprintf("%v", t.Local().Hour())
147 - log.Logger.Debug(fmt.Sprintf("time:%v hour:%v", t, key)) 152 + //log.Logger.Debug(fmt.Sprintf("time:%v hour:%v", t, key))
148 var v *HourDeviceStatus 153 var v *HourDeviceStatus
149 var ok bool 154 var ok bool
150 if v, ok = d.TimeLineDeviceStatus[key]; !ok { 155 if v, ok = d.TimeLineDeviceStatus[key]; !ok {
@@ -24,6 +24,8 @@ type DeviceRunningData struct { @@ -24,6 +24,8 @@ type DeviceRunningData struct {
24 // 附加数据 24 // 附加数据
25 // 匹配数目 25 // 匹配数目
26 Count int `json:"count"` 26 Count int `json:"count"`
  27 + // 合计数目
  28 + Total int `json:"total"`
27 // 炸机前段温度:炸机前段当前温度 YZJ1 油炸机 29 // 炸机前段温度:炸机前段当前温度 YZJ1 油炸机
28 //FrontTemp float64 `json:"frontTemp"` 30 //FrontTemp float64 `json:"frontTemp"`
29 // 炸机前段温度:炸机前段当前温度 YZJ2 油炸机 31 // 炸机前段温度:炸机前段当前温度 YZJ2 油炸机
@@ -29,7 +29,6 @@ func SendWorkshopDeviceData(productRecord *domain.DeviceCollection) error { @@ -29,7 +29,6 @@ func SendWorkshopDeviceData(productRecord *domain.DeviceCollection) error {
29 29
30 func SendAsyncJob(queueName string, job interface{}) error { 30 func SendAsyncJob(queueName string, job interface{}) error {
31 task := asynq.NewTask(queueName, []byte(json.MarshalToString(job))) 31 task := asynq.NewTask(queueName, []byte(json.MarshalToString(job)))
32 -  
33 client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS}) 32 client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
34 _, err := client.Enqueue(task) 33 _, err := client.Enqueue(task)
35 return err 34 return err
@@ -40,7 +40,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d @@ -40,7 +40,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
40 } 40 }
41 41
42 // 0.初始化 从缓存捞数据、没取到查询库 42 // 0.初始化 从缓存捞数据、没取到查询库
43 - deviceDailyRecord, err = redis.GetDeviceDailyRunningRecord(time.Now(), deviceRunningData.DeviceCode) 43 + deviceDailyRecord, err = redis.GetDeviceDailyRunningRecord(deviceRunningData.CollectionTime, deviceRunningData.DeviceCode)
44 if err == domain.ErrorNotFound { 44 if err == domain.ErrorNotFound {
45 err = nil 45 err = nil
46 } 46 }
@@ -173,6 +173,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -173,6 +173,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
173 break 173 break
174 } 174 }
175 data.Count = int(deviceChuanChuanJi.Count) 175 data.Count = int(deviceChuanChuanJi.Count)
  176 + data.Total = int(deviceChuanChuanJi.Total)
176 data.ProductType = domain.ProductTypeToProductCode(deviceChuanChuanJi.ProductType) 177 data.ProductType = domain.ProductTypeToProductCode(deviceChuanChuanJi.ProductType)
177 if data.Date, err = formatDate(deviceChuanChuanJi.Year, deviceChuanChuanJi.Month, deviceChuanChuanJi.Day); err != nil { 178 if data.Date, err = formatDate(deviceChuanChuanJi.Year, deviceChuanChuanJi.Month, deviceChuanChuanJi.Day); err != nil {
178 return nil, err 179 return nil, err
@@ -273,7 +274,7 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, @@ -273,7 +274,7 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId,
273 if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{ 274 if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{
274 "workStationId": workStation.WorkStationId, 275 "workStationId": workStation.WorkStationId,
275 "deviceCode": data.DeviceCode, 276 "deviceCode": data.DeviceCode,
276 - "productDate": utils.GetZeroTime(time.Now()), 277 + "productDate": utils.GetZeroTime(data.CollectionTime),
277 }); err != nil { 278 }); err != nil {
278 if err != domain.ErrorNotFound { 279 if err != domain.ErrorNotFound {
279 return nil, err 280 return nil, err
@@ -293,7 +294,7 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, @@ -293,7 +294,7 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId,
293 WorkStation: workStation, 294 WorkStation: workStation,
294 DeviceId: device.DeviceId, 295 DeviceId: device.DeviceId,
295 DeviceCode: device.DeviceCode, 296 DeviceCode: device.DeviceCode,
296 - ProductDate: utils.GetZeroTime(time.Now()), 297 + ProductDate: utils.GetZeroTime(data.CollectionTime),
297 DeviceRunningRecordInfo: recordInfo, 298 DeviceRunningRecordInfo: recordInfo,
298 CreatedAt: time.Now(), 299 CreatedAt: time.Now(),
299 UpdatedAt: time.Now(), 300 UpdatedAt: time.Now(),
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ 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 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  7 + "time"
7 8
8 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 9 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 10 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -133,12 +134,18 @@ func (repository *DeviceCollectionRepository) Find(queryOptions map[string]inter @@ -133,12 +134,18 @@ func (repository *DeviceCollectionRepository) Find(queryOptions map[string]inter
133 query := sqlbuilder.BuildQuery(tx.Model(&deviceCollectionModels), queryOptions) 134 query := sqlbuilder.BuildQuery(tx.Model(&deviceCollectionModels), queryOptions)
134 query.SetOffsetAndLimit(20) 135 query.SetOffsetAndLimit(20)
135 query.SetOrderDirect("device_collection_id", "DESC") 136 query.SetOrderDirect("device_collection_id", "DESC")
136 - if deviceType,ok := queryOptions["deviceType"];ok && deviceType != "" { 137 + if deviceType, ok := queryOptions["deviceType"]; ok && deviceType != "" {
137 query.SetWhereByQueryOption("device_type = ?", "deviceType") 138 query.SetWhereByQueryOption("device_type = ?", "deviceType")
138 } 139 }
139 - if workShopName,ok := queryOptions["workShopName"];ok && workShopName.(string) != "" { 140 + if workShopName, ok := queryOptions["workShopName"]; ok && workShopName.(string) != "" {
140 query.SetWhereByQueryOption("work_shop_name = ?", "workShopName") 141 query.SetWhereByQueryOption("work_shop_name = ?", "workShopName")
141 } 142 }
  143 + if v, ok := queryOptions["productBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
  144 + query.Where("collection_time>=?", v.(time.Time))
  145 + }
  146 + if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) {
  147 + query.Where("collection_time<?", v.(time.Time))
  148 + }
142 if count, err := query.SelectAndCount(); err != nil { 149 if count, err := query.SelectAndCount(); err != nil {
143 return 0, deviceCollections, err 150 return 0, deviceCollections, err
144 } else { 151 } else {
@@ -51,6 +51,16 @@ func ObjectToMap(o interface{}) map[string]interface{} { @@ -51,6 +51,16 @@ func ObjectToMap(o interface{}) map[string]interface{} {
51 return m 51 return m
52 } 52 }
53 53
  54 +func ToMap(o interface{}) map[string]interface{} {
  55 + if o == nil {
  56 + return nil
  57 + }
  58 + m := make(map[string]interface{})
  59 + data, _ := json.Marshal(o)
  60 + json.Unmarshal(data, &m)
  61 + return m
  62 +}
  63 +
54 func DeleteMapKeys(options map[string]interface{}, keys ...string) map[string]interface{} { 64 func DeleteMapKeys(options map[string]interface{}, keys ...string) map[string]interface{} {
55 for i := range keys { 65 for i := range keys {
56 if _, ok := options[keys[i]]; ok { 66 if _, ok := options[keys[i]]; ok {
@@ -382,7 +392,6 @@ func SubStr(str string, start, length int) string { @@ -382,7 +392,6 @@ func SubStr(str string, start, length int) string {
382 return string(rs[start:end]) 392 return string(rs[start:end])
383 } 393 }
384 394
385 -  
386 //生成新ID 395 //生成新ID
387 var snowFlakeNode *snowflake.Node 396 var snowFlakeNode *snowflake.Node
388 397
@@ -405,4 +414,3 @@ func Round(value float64, places int32) float64 { @@ -405,4 +414,3 @@ func Round(value float64, places int32) float64 {
405 rsp, _ := d.Float64() 414 rsp, _ := d.Float64()
406 return rsp 415 return rsp
407 } 416 }
408 -  
@@ -3,7 +3,6 @@ package mqtt @@ -3,7 +3,6 @@ package mqtt
3 import ( 3 import (
4 pahomqtt "github.com/eclipse/paho.mqtt.golang" 4 pahomqtt "github.com/eclipse/paho.mqtt.golang"
5 "github.com/linmadan/egglib-go/utils/json" 5 "github.com/linmadan/egglib-go/utils/json"
6 - "github.com/linmadan/egglib-go/utils/tool_funs"  
7 "github.com/tidwall/gjson" 6 "github.com/tidwall/gjson"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/service" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/service"
@@ -68,7 +67,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -68,7 +67,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
68 if err != nil { 67 if err != nil {
69 continue 68 continue
70 } 69 }
71 - deviceCollection.Values = tool_funs.SimpleStructToMap(deviceBaoXianJi) 70 + deviceCollection.Values = utils.ToMap(deviceBaoXianJi)
72 break 71 break
73 //油炸机 72 //油炸机
74 case domain.DeviceTypeYouZhaJi1: 73 case domain.DeviceTypeYouZhaJi1:
@@ -77,7 +76,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -77,7 +76,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
77 if err != nil { 76 if err != nil {
78 continue 77 continue
79 } 78 }
80 - deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi) 79 + deviceCollection.Values = utils.ToMap(deviceYouZhaJi)
81 break 80 break
82 //油炸机 81 //油炸机
83 case domain.DeviceTypeYouZhaJi2: 82 case domain.DeviceTypeYouZhaJi2:
@@ -86,7 +85,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -86,7 +85,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
86 if err != nil { 85 if err != nil {
87 continue 86 continue
88 } 87 }
89 - deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi2) 88 + deviceCollection.Values = utils.ToMap(deviceYouZhaJi2)
90 break 89 break
91 //串串机 90 //串串机
92 case domain.DeviceTypeChuanChuanJi: 91 case domain.DeviceTypeChuanChuanJi:
@@ -96,7 +95,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -96,7 +95,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
96 log.Logger.Error(err.Error()) 95 log.Logger.Error(err.Error())
97 continue 96 continue
98 } 97 }
99 - deviceCollection.Values = tool_funs.SimpleStructToMap(deviceChuanChuanJi) 98 + deviceCollection.Values = utils.ToMap(deviceChuanChuanJi)
100 break 99 break
101 //速冻线 100 //速冻线
102 case domain.DeviceTypeSuDongXian: 101 case domain.DeviceTypeSuDongXian:
@@ -105,7 +104,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -105,7 +104,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
105 if err != nil { 104 if err != nil {
106 continue 105 continue
107 } 106 }
108 - deviceCollection.Values = tool_funs.SimpleStructToMap(deviceSuDongXian) 107 + deviceCollection.Values = utils.ToMap(deviceSuDongXian)
109 break 108 break
110 //封口机 109 //封口机
111 case domain.DeviceTypeFengKouJi: 110 case domain.DeviceTypeFengKouJi:
@@ -114,7 +113,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -114,7 +113,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
114 if err != nil { 113 if err != nil {
115 continue 114 continue
116 } 115 }
117 - deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengKouJi) 116 + deviceCollection.Values = utils.ToMap(deviceFengKouJi)
118 break 117 break
119 //封箱机 118 //封箱机
120 case domain.DeviceTypeFengXiangJi: 119 case domain.DeviceTypeFengXiangJi:
@@ -123,7 +122,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -123,7 +122,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
123 if err != nil { 122 if err != nil {
124 continue 123 continue
125 } 124 }
126 - deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengXiangJi) 125 + deviceCollection.Values = utils.ToMap(deviceFengXiangJi)
127 break 126 break
128 //打浆机 //面包屑机 127 //打浆机 //面包屑机
129 case domain.DeviceTypeDaJiangJi: 128 case domain.DeviceTypeDaJiangJi:
@@ -135,7 +134,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -135,7 +134,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
135 //} 134 //}
136 // 发送数据 135 // 发送数据
137 deviceCollectionService := service.NewDeviceCollectionService(nil) 136 deviceCollectionService := service.NewDeviceCollectionService(nil)
138 - _, err = deviceCollectionService.CreateDeviceCollection(&command.CreateDeviceCollectionCommand{ 137 + _, err = deviceCollectionService.DeviceCollection(&command.CreateDeviceCollectionCommand{
139 WorkShopName: deviceCollection.WorkShopName, 138 WorkShopName: deviceCollection.WorkShopName,
140 StartupStatus: deviceCollection.StartupStatus, 139 StartupStatus: deviceCollection.StartupStatus,
141 CollectionTime: deviceCollection.CollectionTime, 140 CollectionTime: deviceCollection.CollectionTime,