作者 yangfu

fix:采集数据修改

@@ -118,3 +118,5 @@ spec: @@ -118,3 +118,5 @@ spec:
118 value: "23" 118 value: "23"
119 - name: MANUFACTURE_DEFAULT_ORGID 119 - name: MANUFACTURE_DEFAULT_ORGID
120 value: "487" 120 value: "487"
  121 + - name: MANUFACTURE_PRODUCT_TYPE
  122 + value: "0502010004ST,0502010004ST"
@@ -81,24 +81,24 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c @@ -81,24 +81,24 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c
81 //处理设备数据 81 //处理设备数据
82 switch deviceCollection.DeviceType { 82 switch deviceCollection.DeviceType {
83 case domain.DeviceTypeBaoXianJi, domain.DeviceTypeChuanChuanJi, domain.DeviceTypeFengKouJi, domain.DeviceTypeFengXiangJi: 83 case domain.DeviceTypeBaoXianJi, domain.DeviceTypeChuanChuanJi, domain.DeviceTypeFengKouJi, domain.DeviceTypeFengXiangJi:
84 - if v, ok := deviceCollection.Values["Count"]; ok { 84 + if v, ok := deviceCollection.Values["count"]; ok {
85 curCount, errCurCount := strconv.Atoi(fmt.Sprintf("%v", v)) 85 curCount, errCurCount := strconv.Atoi(fmt.Sprintf("%v", v))
86 - v, ok = lastDeviceCollectionRecord.Values["Count"] 86 + v, ok = lastDeviceCollectionRecord.Values["count"]
87 if ok { 87 if ok {
88 lastCount, errLastCount := strconv.Atoi(fmt.Sprintf("%v", v)) 88 lastCount, errLastCount := strconv.Atoi(fmt.Sprintf("%v", v))
89 if errLastCount == nil && errCurCount == nil && lastCount <= curCount { 89 if errLastCount == nil && errCurCount == nil && lastCount <= curCount {
90 - deviceCollection.Values["Count"] = curCount - lastCount 90 + deviceCollection.Values["count"] = curCount - lastCount
91 } else { 91 } else {
92 - deviceCollection.Values["Count"] = 0 92 + deviceCollection.Values["count"] = 0
93 /* 93 /*
94 设备统计的数量超过一定范围会重置为0,特殊处理0操作 94 设备统计的数量超过一定范围会重置为0,特殊处理0操作
95 */ 95 */
96 if lastCount > 10000000 && curCount < 1000 { 96 if lastCount > 10000000 && curCount < 1000 {
97 - deviceCollection.Values["Count"] = curCount 97 + deviceCollection.Values["count"] = curCount
98 } 98 }
99 } 99 }
100 } else { 100 } else {
101 - deviceCollection.Values["Count"] = 0 101 + deviceCollection.Values["count"] = 0
102 } 102 }
103 } 103 }
104 break 104 break
1 package dto 1 package dto
2 2
3 -import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  6 +)
4 7
5 type EmployeeProductRecordDto struct { 8 type EmployeeProductRecordDto struct {
6 // 员工产能记录ID 9 // 员工产能记录ID
@@ -47,10 +50,10 @@ func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgI @@ -47,10 +50,10 @@ func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgI
47 d.PlanProductName = m.ProductRecordInfo.PlanProductName 50 d.PlanProductName = m.ProductRecordInfo.PlanProductName
48 d.BatchNumber = m.ProductRecordInfo.BatchNumber 51 d.BatchNumber = m.ProductRecordInfo.BatchNumber
49 d.ParticipateType = m.ParticipateType 52 d.ParticipateType = m.ParticipateType
50 - d.ProductWeigh = m.RealProductWeigh()  
51 - d.SecondLevelWeigh = m.SecondLevelWeigh 53 + d.ProductWeigh = utils.Round(m.RealProductWeigh(), 1)
  54 + d.SecondLevelWeigh = utils.Round(m.SecondLevelWeigh, 1)
52 d.QualificationRate = m.QualificationRate() 55 d.QualificationRate = m.QualificationRate()
53 - d.CreatedAt = m.CreatedAt.Format("2006-01-02") 56 + d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02")
54 d.ParticipateTypeDescription = domain.ParticipateTypeDescription(m.ParticipateType) 57 d.ParticipateTypeDescription = domain.ParticipateTypeDescription(m.ParticipateType)
55 d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType) 58 d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType)
56 d.WorkOnDescription = domain.WorkOnDescriptions(m.WorkOn) 59 d.WorkOnDescription = domain.WorkOnDescriptions(m.WorkOn)
1 package dto 1 package dto
2 2
3 -import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  6 +)
4 7
5 type WorkshopProductRecordDto struct { 8 type WorkshopProductRecordDto struct {
6 // 员工产能记录ID 9 // 员工产能记录ID
@@ -39,9 +42,9 @@ func (d *WorkshopProductRecordDto) LoadDto(m *domain.WorkshopProductRecord, orgI @@ -39,9 +42,9 @@ func (d *WorkshopProductRecordDto) LoadDto(m *domain.WorkshopProductRecord, orgI
39 d.PlanProductName = m.ProductRecordInfo.PlanProductName 42 d.PlanProductName = m.ProductRecordInfo.PlanProductName
40 d.BatchNumber = m.ProductRecordInfo.BatchNumber 43 d.BatchNumber = m.ProductRecordInfo.BatchNumber
41 //d.ParticipateType = m.ParticipateType 44 //d.ParticipateType = m.ParticipateType
42 - d.DevotedProductWeigh = m.DevotedProductWeigh()  
43 - d.ProductWeigh = m.RealProductWeigh()  
44 - d.SecondLevelWeigh = m.SecondLevelWeigh 45 + d.DevotedProductWeigh = utils.Round(m.DevotedProductWeigh(), 1)
  46 + d.ProductWeigh = utils.Round(m.RealProductWeigh(), 1)
  47 + d.SecondLevelWeigh = utils.Round(m.SecondLevelWeigh, 1)
45 d.QualificationRate = m.QualificationRate() 48 d.QualificationRate = m.QualificationRate()
46 d.CreatedAt = m.ProductDate 49 d.CreatedAt = m.ProductDate
47 d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) 50 d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
@@ -3,6 +3,7 @@ package constant @@ -3,6 +3,7 @@ package constant
3 import ( 3 import (
4 "os" 4 "os"
5 "strconv" 5 "strconv"
  6 + "strings"
6 ) 7 )
7 8
8 var ( 9 var (
@@ -10,6 +11,10 @@ var ( @@ -10,6 +11,10 @@ var (
10 MANUFACTURE_DEFAULT_COMPANYID = 1 11 MANUFACTURE_DEFAULT_COMPANYID = 1
11 // 生产制造 - 称重系统 - 默认组织 12 // 生产制造 - 称重系统 - 默认组织
12 MANUFACTURE_DEFAULT_ORGID = 1 13 MANUFACTURE_DEFAULT_ORGID = 1
  14 + // 产品类型列表
  15 + MANUFACTURE_PRODUCT_TYPE = "0502010004ST,0502010004ST"
  16 +
  17 + MapProductType = make(map[int]string)
13 ) 18 )
14 19
15 func init() { 20 func init() {
@@ -19,4 +24,11 @@ func init() { @@ -19,4 +24,11 @@ func init() {
19 if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" { 24 if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" {
20 MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID")) 25 MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID"))
21 } 26 }
  27 + if os.Getenv("MANUFACTURE_PRODUCT_TYPE") != "" {
  28 + MANUFACTURE_PRODUCT_TYPE = os.Getenv("MANUFACTURE_PRODUCT_TYPE")
  29 + }
  30 + productTypes := strings.Split(MANUFACTURE_PRODUCT_TYPE, ",")
  31 + for i, v := range productTypes {
  32 + MapProductType[i+1] = v
  33 + }
22 } 34 }
1 package domain 1 package domain
2 2
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
  4 +
3 // 包馅机 5 // 包馅机
4 type DeviceBaoXianJi struct { 6 type DeviceBaoXianJi struct {
5 InterSpeed int64 `json:"InterSpeed"` // 内包材速度:内包材运行速率 7 InterSpeed int64 `json:"InterSpeed"` // 内包材速度:内包材运行速率
@@ -58,3 +60,10 @@ type DeviceFengXiangJi struct { @@ -58,3 +60,10 @@ type DeviceFengXiangJi struct {
58 ProductType int `json:"ProductType"` 60 ProductType int `json:"ProductType"`
59 ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类 61 ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类
60 } 62 }
  63 +
  64 +func ProductTypeToProductCode(productType int) string {
  65 + if v, ok := constant.MapProductType[productType]; ok {
  66 + return v
  67 + }
  68 + return ""
  69 +}
@@ -3,6 +3,7 @@ package domain @@ -3,6 +3,7 @@ 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"
6 "time" 7 "time"
7 ) 8 )
8 9
@@ -142,7 +143,8 @@ func (d *DeviceRunningRecordInfo) AddTimeLineDeviceStatus(t time.Time, data *Dev @@ -142,7 +143,8 @@ func (d *DeviceRunningRecordInfo) AddTimeLineDeviceStatus(t time.Time, data *Dev
142 if t.IsZero() { 143 if t.IsZero() {
143 return 144 return
144 } 145 }
145 - key := fmt.Sprintf("%v", t.Hour()) 146 + key := fmt.Sprintf("%v", t.Local().Hour())
  147 + log.Logger.Debug(fmt.Sprintf("time:%v hour:%v", t, key))
146 var v *HourDeviceStatus 148 var v *HourDeviceStatus
147 var ok bool 149 var ok bool
148 if v, ok = d.TimeLineDeviceStatus[key]; !ok { 150 if v, ok = d.TimeLineDeviceStatus[key]; !ok {
@@ -251,6 +253,9 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string @@ -251,6 +253,9 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
251 begin = end + 1 253 begin = end + 1
252 end = begin 254 end = begin
253 } 255 }
  256 + if end >= endTime {
  257 + break
  258 + }
254 index = index << 1 259 index = index << 1
255 } 260 }
256 } 261 }
@@ -279,7 +284,7 @@ type HourDeviceStatus struct { @@ -279,7 +284,7 @@ type HourDeviceStatus struct {
279 284
280 // 更新启动状态 285 // 更新启动状态
281 func (d *HourDeviceStatus) UpdateUp(t time.Time, up int) { 286 func (d *HourDeviceStatus) UpdateUp(t time.Time, up int) {
282 - m := t.Minute() 287 + m := t.Local().Minute()
283 bit := 1 << (m / d.Window) 288 bit := 1 << (m / d.Window)
284 if up&1 == 0 { 289 if up&1 == 0 {
285 return 290 return
@@ -303,7 +303,8 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s @@ -303,7 +303,8 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
303 } 303 }
304 } 304 }
305 if r != nil { 305 if r != nil {
306 - m := r.UpdatedAt.Local().Hour()*60 + r.UpdatedAt.Minute() 306 + //log.Logger.Debug(fmt.Sprintf("%v %v",r.UpdatedAt.Local().Hour(),r.UpdatedAt.Local().Minute()))
  307 + m := r.UpdatedAt.Local().Hour()*60 + r.UpdatedAt.Local().Minute()
307 if r.UpdatedAt.Before(utils.GetZeroTime(time.Now())) { 308 if r.UpdatedAt.Before(utils.GetZeroTime(time.Now())) {
308 m = 60 * 24 309 m = 60 * 24
309 } 310 }
@@ -28,7 +28,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d @@ -28,7 +28,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
28 planId int 28 planId int
29 err error 29 err error
30 plan *domain.ProductPlanDispatchRecord 30 plan *domain.ProductPlanDispatchRecord
31 - datetime time.Time 31 + //datetime time.Time
32 ) 32 )
33 var ( 33 var (
34 deviceRepository, _ = repository.NewDeviceRepository(ptr.transactionContext) 34 deviceRepository, _ = repository.NewDeviceRepository(ptr.transactionContext)
@@ -78,9 +78,9 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d @@ -78,9 +78,9 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
78 78
79 // 封箱机、串串机需要定位到批次 79 // 封箱机、串串机需要定位到批次
80 if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi { 80 if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi {
81 - datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date)  
82 - if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.ProductType); err != nil {  
83 - log.Logger.Error(err.Error()) 81 + //datetime, _ = time.Parse("2006-01-02 15:04:05", deviceRunningData.Date)
  82 + if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, utils.GetZeroTimeWithLocal(deviceRunningData.CollectionTime, time.UTC), deviceRunningData.ProductType); err != nil {
  83 + log.Logger.Error(err.Error(), map[string]interface{}{"workstation": workStation, "product_code": deviceRunningData.ProductType})
84 } else { 84 } else {
85 planId = plan.PlanDispatchRecordExt.ProductPlanId 85 planId = plan.PlanDispatchRecordExt.ProductPlanId
86 } 86 }
@@ -171,7 +171,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -171,7 +171,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
171 break 171 break
172 } 172 }
173 data.Count = int(deviceChuanChuanJi.Count) 173 data.Count = int(deviceChuanChuanJi.Count)
174 - data.ProductType = deviceChuanChuanJi.ProductType1 174 + data.ProductType = domain.ProductTypeToProductCode(deviceChuanChuanJi.ProductType)
175 if data.Date, err = formatDate(deviceChuanChuanJi.Year, deviceChuanChuanJi.Month, deviceChuanChuanJi.Day); err != nil { 175 if data.Date, err = formatDate(deviceChuanChuanJi.Year, deviceChuanChuanJi.Month, deviceChuanChuanJi.Day); err != nil {
176 return nil, err 176 return nil, err
177 } 177 }
@@ -194,7 +194,8 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -194,7 +194,8 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
194 break 194 break
195 } 195 }
196 data.Count = int(deviceFengKouJi.Count) 196 data.Count = int(deviceFengKouJi.Count)
197 - data.ProductType = deviceFengKouJi.ProductType1 197 + //data.ProductType = deviceFengKouJi.ProductType1
  198 + data.ProductType = domain.ProductTypeToProductCode(deviceFengKouJi.ProductType)
198 if data.Date, err = formatDate(deviceFengKouJi.Year, deviceFengKouJi.Month, deviceFengKouJi.Day); err != nil { 199 if data.Date, err = formatDate(deviceFengKouJi.Year, deviceFengKouJi.Month, deviceFengKouJi.Day); err != nil {
199 return nil, err 200 return nil, err
200 } 201 }
@@ -207,7 +208,8 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -207,7 +208,8 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
207 break 208 break
208 } 209 }
209 data.Count = int(deviceFengXiangJi.Count) 210 data.Count = int(deviceFengXiangJi.Count)
210 - data.ProductType = deviceFengXiangJi.ProductType1 211 + //data.ProductType = deviceFengXiangJi.ProductType1
  212 + data.ProductType = domain.ProductTypeToProductCode(deviceFengXiangJi.ProductType)
211 if data.Date, err = formatDate(deviceFengXiangJi.Year, deviceFengXiangJi.Month, deviceFengXiangJi.Day); err != nil { 213 if data.Date, err = formatDate(deviceFengXiangJi.Year, deviceFengXiangJi.Month, deviceFengXiangJi.Day); err != nil {
212 return nil, err 214 return nil, err
213 } 215 }
@@ -227,7 +229,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId @@ -227,7 +229,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId
227 DeviceId: device.DeviceId, 229 DeviceId: device.DeviceId,
228 DeviceCode: device.DeviceCode, 230 DeviceCode: device.DeviceCode,
229 DeviceRunningRecordInfo: data, 231 DeviceRunningRecordInfo: data,
230 - CreatedAt: time.Now(), 232 + CreatedAt: data.CollectionTime,
231 }, nil 233 }, nil
232 } 234 }
233 235
@@ -243,8 +245,8 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i @@ -243,8 +245,8 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i
243 ProductRecordInfo: &domain.ProductRecordInfo{ 245 ProductRecordInfo: &domain.ProductRecordInfo{
244 ProductDate: data.CollectionTime.Local().Format("2006-01-02"), 246 ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
245 Original: float64(data.Count), 247 Original: float64(data.Count),
246 - Weigh: float64(data.Count) * DefaultCCJUnitQuantity,  
247 - WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity, 248 + Weigh: utils.Round(float64(data.Count)*DefaultCCJUnitQuantity, 1),
  249 + WeighBefore: utils.Round(float64(data.Count)*DefaultCCJUnitQuantity, 1),
248 ApproveStatus: domain.AttendanceNotApprove, 250 ApproveStatus: domain.AttendanceNotApprove,
249 ProductPlanId: plan.PlanDispatchRecordExt.ProductPlanId, 251 ProductPlanId: plan.PlanDispatchRecordExt.ProductPlanId,
250 PlanProductName: plan.PlanDispatchRecordExt.PlanProductName, 252 PlanProductName: plan.PlanDispatchRecordExt.PlanProductName,
@@ -52,6 +52,11 @@ func GetZeroTime(d time.Time) time.Time { @@ -52,6 +52,11 @@ func GetZeroTime(d time.Time) time.Time {
52 return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local) 52 return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local)
53 } 53 }
54 54
  55 +// GetZeroTime 获取某一天的0点时间
  56 +func GetZeroTimeWithLocal(d time.Time, loc *time.Location) time.Time {
  57 + return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, loc)
  58 +}
  59 +
55 // GetNextDayZeroTime 获取某一天的23点59分59秒 60 // GetNextDayZeroTime 获取某一天的23点59分59秒
56 func GetNextDayZeroTime(d time.Time) time.Time { 61 func GetNextDayZeroTime(d time.Time) time.Time {
57 return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1) 62 return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
1 package utils 1 package utils
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/stretchr/testify/assert" 5 "github.com/stretchr/testify/assert"
5 "testing" 6 "testing"
6 "time" 7 "time"
@@ -52,3 +53,51 @@ func TestComputeTimeDuration(t *testing.T) { @@ -52,3 +53,51 @@ func TestComputeTimeDuration(t *testing.T) {
52 assert.Equal(t, input.ts, out) 53 assert.Equal(t, input.ts, out)
53 } 54 }
54 } 55 }
  56 +
  57 +const TIME_LAYOUT = "2006-01-02 03:04:05"
  58 +
  59 +func TestTimeParse(t *testing.T) {
  60 + timeParse()
  61 +}
  62 +
  63 +func timeParse() {
  64 + fmt.Println("0. now: ", time.Now())
  65 + str := "2018-09-10 10:00:00"
  66 + fmt.Println("1. str: ", str)
  67 + t, _ := time.Parse(TIME_LAYOUT, str)
  68 + fmt.Println("2. Parse time: ", t)
  69 + tStr := t.Format(TIME_LAYOUT)
  70 + fmt.Println("3. Format time str: ", tStr)
  71 + name, offset := t.Zone()
  72 + name2, offset2 := t.Local().Zone()
  73 + fmt.Printf("4. Zone name: %v, Zone offset: %v\n", name, offset)
  74 + fmt.Printf("5. Local Zone name: %v, Local Zone offset: %v\n", name2, offset2)
  75 + tLocal := t.Local()
  76 + tUTC := t.UTC()
  77 + fmt.Printf("6. t: %v, Local: %v, UTC: %v\n", t, tLocal, tUTC)
  78 + fmt.Printf("7. t: %v, Local: %v, UTC: %v\n", t.Format(TIME_LAYOUT), tLocal.Format(TIME_LAYOUT), tUTC.Format(TIME_LAYOUT))
  79 + fmt.Printf("8. Local.Unix: %v, UTC.Unix: %v\n", tLocal.Unix(), tUTC.Unix())
  80 + str2 := "1969-12-31 23:59:59"
  81 + t2, _ := time.Parse(TIME_LAYOUT, str2)
  82 + fmt.Printf("9. str2:%v,time: %v, Unix: %v\n", str2, t2, t2.Unix())
  83 + fmt.Printf("10. %v, %v\n", tLocal.Format(time.ANSIC), tUTC.Format(time.ANSIC))
  84 + fmt.Printf("11. %v, %v\n", tLocal.Format(time.RFC822), tUTC.Format(time.RFC822))
  85 + fmt.Printf("12. %v, %v\n", tLocal.Format(time.RFC822Z), tUTC.Format(time.RFC822Z))
  86 +
  87 + //指定时区
  88 + parseWithLocation("America/Cordoba", str)
  89 + parseWithLocation("Asia/Shanghai", str)
  90 + parseWithLocation("Asia/Beijing", str)
  91 +}
  92 +
  93 +func parseWithLocation(name string, timeStr string) (time.Time, error) {
  94 + locationName := name
  95 + if l, err := time.LoadLocation(locationName); err != nil {
  96 + println(err.Error())
  97 + return time.Time{}, err
  98 + } else {
  99 + lt, _ := time.ParseInLocation(TIME_LAYOUT, timeStr, l)
  100 + fmt.Println(locationName, lt)
  101 + return lt, nil
  102 + }
  103 +}
1 package mqtt 1 package mqtt
2 2
3 import ( 3 import (
4 - "encoding/json"  
5 pahomqtt "github.com/eclipse/paho.mqtt.golang" 4 pahomqtt "github.com/eclipse/paho.mqtt.golang"
  5 + "github.com/linmadan/egglib-go/utils/json"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "github.com/tidwall/gjson" 7 "github.com/tidwall/gjson"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command"
@@ -27,6 +27,13 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -27,6 +27,13 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
27 return 27 return
28 } 28 }
29 if workShop, ok := payload["WorkShop"]; ok { 29 if workShop, ok := payload["WorkShop"]; ok {
  30 + var collectionTime time.Time
  31 + if t, ok := payload["UpTime"]; ok {
  32 + collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local)
  33 + }
  34 + if collectionTime.IsZero() {
  35 + return
  36 + }
30 for key, item := range payload { 37 for key, item := range payload {
31 if key == "WorkShop" { 38 if key == "WorkShop" {
32 continue 39 continue
@@ -38,7 +45,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -38,7 +45,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
38 deviceCollection := &domain.DeviceCollection{ 45 deviceCollection := &domain.DeviceCollection{
39 WorkShopName: workShop.(string), 46 WorkShopName: workShop.(string),
40 DeviceSn: key, 47 DeviceSn: key,
41 - CollectionTime: time.Now(), 48 + CollectionTime: collectionTime,
42 StartupStatus: gjson.Get(string(message.Payload()), key+".StartupState").Int(), 49 StartupStatus: gjson.Get(string(message.Payload()), key+".StartupState").Int(),
43 ComStatus: gjson.Get(string(message.Payload()), key+".ComStatus").Int(), 50 ComStatus: gjson.Get(string(message.Payload()), key+".ComStatus").Int(),
44 } 51 }
@@ -137,6 +144,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -137,6 +144,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
137 } 144 }
138 } 145 }
139 } 146 }
  147 + //TODO:日志先注释
140 log.Logger.Info("MQTT", map[string]interface{}{ 148 log.Logger.Info("MQTT", map[string]interface{}{
141 "Topic": message.Topic(), 149 "Topic": message.Topic(),
142 "MessageId": message.MessageID(), 150 "MessageId": message.MessageID(),
@@ -18,7 +18,8 @@ func WorkshopDataConsumer(c context.Context, t *asynq.Task) error { @@ -18,7 +18,8 @@ func WorkshopDataConsumer(c context.Context, t *asynq.Task) error {
18 if err := json.Unmarshal(t.Payload(), cmd); err != nil { 18 if err := json.Unmarshal(t.Payload(), cmd); err != nil {
19 return err 19 return err
20 } 20 }
21 - log.Logger.Debug(fmt.Sprintf("【车间数据消费】 消费 设备:%v 消息号:%v 时间:%v ", cmd.DeviceCollection.DeviceSn, cmd.DeviceCollectionId, cmd.CollectionTime)) 21 + log.Logger.Debug(fmt.Sprintf("【车间数据消费】 消费 设备:%v 消息号:%v 时间:%v ", cmd.DeviceCollection.DeviceSn, cmd.DeviceCollectionId, cmd.CollectionTime),
  22 + map[string]interface{}{"p-message": cmd.DeviceCollection})
22 cmd.CompanyId = constant.MANUFACTURE_DEFAULT_COMPANYID 23 cmd.CompanyId = constant.MANUFACTURE_DEFAULT_COMPANYID
23 cmd.OrgId = constant.MANUFACTURE_DEFAULT_ORGID 24 cmd.OrgId = constant.MANUFACTURE_DEFAULT_ORGID
24 _, err := svr.WorkshopConsume(cmd) 25 _, err := svr.WorkshopConsume(cmd)