作者 yangfu

Merge remote-tracking branch 'origin/test'

... ... @@ -91,7 +91,7 @@ func AutoFlushDeviceDailyRunningRecordOEE(ctx context.Context) error {
log.Logger.Error(err.Error())
continue
}
if err := redis.SaveDeviceDailyRunningRecord(v); err != nil {
if err := redis.SaveDeviceDailyRunningRecordByKey(v.RedisKey, v); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新设备每日运行记录"})
continue
}
... ...
... ... @@ -32,7 +32,7 @@ type UpdateDeviceCommand struct {
// 风险等级 1:高 2:中 3:低
RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
// 标准工时
UnitProductionSecTime int `cname:"标准工时" json:"unitProductionSecTime"`
UnitProductionSecTime float64 `cname:"标准工时" json:"unitProductionSecTime"`
}
func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -153,6 +153,8 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
// newDeviceCollection.ComStatus = 1
// newDeviceCollection.CollectionTime = time.Date(2022,4,18,7,0,0,0,time.Local)
//}
// !!!!!!! 注意:保存到库以后 collect_time 变成了 UTC时间,后续处理的时候都要加上collectTime.Local()
if newDeviceCollection, err = deviceCollectionRepository.Save(newDeviceCollection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
package syncdata
import (
"fmt"
"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"
... ... @@ -523,16 +524,25 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
continue
}
// 计划信息
plan, err = productPlanRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "batchNumber": v.BillNo})
plan, err = productPlanRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "erpBillNo": v.BillNo, "productCode": v.MaterialNumber})
if err == nil && plan != nil {
plan.UpdatedAt = time.Now()
//plan.UpdatedAt = time.Now()
continue
}
count, _, errFindPlan := productPlanRepository.Find(map[string]interface{}{"companyId": cid, "orgId": oid, "erpBillNo": v.BillNo, "productCode": v.MaterialNumber})
if errFindPlan != nil {
continue
}
/* ERP系统BillNO + MaterialNumber 唯一 会重复,需要做自增格式化处理*/
batchNumber := fmt.Sprintf("%v-1", v.BillNo)
if count >= 1 {
batchNumber = fmt.Sprintf("%v-%v", v.BillNo, count)
}
if err == domain.ErrorNotFound {
plan = &domain.ProductPlan{
CompanyId: cid,
OrgId: oid,
BatchNumber: v.BillNo,
BatchNumber: batchNumber,
ProductDate: v.PlanStartDate,
Workshop: workshop.CloneSample(),
WorkOn: 0,
... ... @@ -557,6 +567,7 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
ProductCode: product.ProductCode,
ProductName: product.ProductName,
DevotedUnit: "份",
ErpBillNo: v.BillNo,
})
plan.PlanProductName = product.ProductName
plan.Remark = v.Description
... ...
... ... @@ -20,16 +20,16 @@ var MQTT_TOPIC = "/MQTT"
//var MQTT_USER = ""
//var MQTT_PASSWORD = ""
var MQTT_HOST = "175.24.122.87"
var MQTT_PORT = "1883"
var MQTT_USER = "user111"
var MQTT_PASSWORD = "user111"
//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 = "47.97.5.102"
var MQTT_PORT = "6000"
var MQTT_USER = "admin"
var MQTT_PASSWORD = "123456"
func init() {
if os.Getenv("MQTT_HOST") != "" {
... ...
... ... @@ -36,12 +36,12 @@ type DeviceChuanChuanJi struct {
Month int `json:"Month"` // 月
Day int `json:"Day"` // 日
ProductType int `json:"ProductType"`
//ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类
}
// 速冻线
type DeviceSuDongXian struct {
CurrTemp float64 `json:"CurrTemp"` // 当前温度:当前温度
Alarm int `json:"alarm"` // 报警
}
// 封口机
... ... @@ -51,7 +51,6 @@ type DeviceFengKouJi struct {
Month int `json:"Month"` // 月
Day int `json:"Day"` // 日
ProductType int `json:"ProductType"`
//ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类
}
// 封箱机
... ... @@ -61,7 +60,6 @@ type DeviceFengXiangJi struct {
Month int `json:"Month"` // 月
Day int `json:"Day"` // 日
ProductType int `json:"ProductType"`
//ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类
}
func ProductTypeToProductCode(productType int) string {
... ...
... ... @@ -33,6 +33,8 @@ type DeviceDailyRunningRecord struct {
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
RedisKey string `json:"-"`
}
type DeviceDailyRunningRecordRepository interface {
... ... @@ -69,15 +71,19 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(d
}
func (deviceDailyRunningRecord *DeviceDailyRunningRecord) String() string {
return fmt.Sprintf("记录ID:%v 工段:%v 设备:%v",
return fmt.Sprintf("记录ID:%v 工段:%v 设备:%v 数量:%v(%v)",
deviceDailyRunningRecord.DeviceDailyRunningRecordId,
deviceDailyRunningRecord.WorkStation.SectionName,
deviceDailyRunningRecord.DeviceCode,
deviceDailyRunningRecord.DeviceRunningRecordInfo.Count,
deviceDailyRunningRecord.DeviceRunningRecordInfo.ProductDate,
)
}
// 设备运行记录信息
type DeviceRunningRecordInfo struct {
// 日期
ProductDate string `json:"productDate"`
// 设备类型
DeviceType string `json:"deviceType"`
// 当前状态
... ... @@ -133,7 +139,7 @@ func (d *DeviceRunningRecordInfo) AddDeviceRunningData(t time.Time, data *Device
if len(d.DeviceType) == 0 {
d.DeviceType = data.DeviceType
}
d.CurrentStatus = data.StartupStatus | (1 << data.ComStatus)
d.CurrentStatus = data.StartupStatus | (data.ComStatus << 1) | (data.Alarm << 2)
d.ResetUpTime()
d.Count += data.Count
//d.Temp = data.FrontTemp
... ... @@ -163,6 +169,7 @@ func (d *DeviceRunningRecordInfo) AddTimeLineDeviceStatus(t time.Time, data *Dev
}
v.UpdateUp(t, data.StartupStatus)
v.UpdateCom(t, data.ComStatus)
v.UpdateAlarm(t, data.Alarm)
}
// 重置运行时长
... ... @@ -197,9 +204,14 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
err := make([][]int, 0)
var begin, end int = 0, 0
/*
1.故障: 1 0 \ 0 0
2.正常: 1 1
3.停机:0 1
旧: 1.故障: 1 0 \ 0 0
2.正常: 1 1
3.停机:0 1
新: 只要未开机,就是待机中状态
1.故障: 1 0 0 / 1 0 1 / 1 1 1 / 1/5/7
2.正常: 1 1 0 3
3.停机:0 0 0 / 0 1 0 / 0 0 1 / 0 1 1 0/2/4/6
*/
var status = 1
// 添加数据
... ... @@ -225,13 +237,13 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
if com&index > 0 {
val |= 2
}
if val == 1 {
if val == 1 || val == 5 || val == 7 {
return 1 //故障
}
if val == 3 {
return 2 //正常
}
if val == 2 || val == 0 {
if val == 0 || val == 2 || val == 4 || val == 6 {
return 3 //停机
}
return 3 // 停机
... ... @@ -292,6 +304,8 @@ type HourDeviceStatus struct {
Up int `json:"up"`
// 通讯
Com int `json:"com"`
// 报警
Alarm int `json:"alarm"`
}
// 更新启动状态
... ... @@ -322,6 +336,20 @@ func (d *HourDeviceStatus) UpdateCom(t time.Time, c int) {
return
}
// 更新报警状态
func (d *HourDeviceStatus) UpdateAlarm(t time.Time, c int) {
m := t.Minute()
bit := 1 << (m / d.Window)
if c&1 == 0 {
return
}
if d.Alarm&bit > 0 {
return
}
d.Alarm |= bit
return
}
// 计算状态持续的时间
func (d *HourDeviceStatus) CountTime(v int) time.Duration {
l := 60 / d.Window
... ... @@ -344,5 +372,6 @@ func NewHourDeviceStatus() *HourDeviceStatus {
Window: DefaultTimeWindow,
Up: 0,
Com: 0,
Alarm: 0,
}
}
... ...
... ... @@ -25,6 +25,8 @@ type DeviceRunningData struct {
StartupStatus int `json:"startupStatus"`
// 通讯状态:1:通讯正常,0:设备未上电或与采集端通讯故障
ComStatus int `json:"comStatus"`
// 报警状态:1:故障,0:正常
Alarm int `json:"alarm"`
// 附加数据
// 匹配数目
... ...
... ... @@ -12,4 +12,6 @@ type ProductPlanExt struct {
//ProductSpec *UnitQuantity `json:"productSpec,omitempty"`
// 投入量规格 默认份
DevotedUnit string `json:"devotedUnit" `
// ERP系统里面的 bill_no
ErpBillNo string `json:"erpBillNo" `
}
... ...
... ... @@ -164,7 +164,7 @@ from ts_product_list
func (dao *DeviceDailyRunningRecordDao) DeviceRunningInfo(companyId, orgId int, deviceCode string, result interface{}) error {
tx := dao.transactionContext.PgTx
sql := fmt.Sprintf(`
select * from device_running_info(?,?,?);
select * from manufacture.device_running_info(?,?,?);
`)
if _, err := tx.Query(result, sql, deviceCode, companyId, orgId); err != nil {
return err
... ...
... ... @@ -98,7 +98,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 {
log.Logger.Debug(fmt.Sprintf("设备统计 设备:%v(%v) 当前数量:%v 增加数量:%v",
deviceDailyRecord.DeviceCode,
deviceDailyRecord.ProductDate.Local().Format("2006-01-02"),
deviceDailyRecord.DeviceRunningRecordInfo.ProductDate,
deviceRunningRecord.DeviceRunningRecordInfo.TodayTotal,
deviceRunningRecord.DeviceRunningRecordInfo.Count))
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan)
... ... @@ -110,19 +110,20 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
SendProductRecordStaticsJob(productRecord)
}
}
if err = redis.SaveDeviceDailyRunningRecord(deviceDailyRecord); err != nil {
if err = redis.SaveDeviceDailyRunningRecordByKey(deviceDailyRecord.RedisKey, deviceDailyRecord); err != nil {
return nil, err
}
return nil, nil
}
// 设备运行数据
func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) {
var err error
var unitQuantity float64 = DefaultCCJUnitQuantity // 单位数量
var data = &domain.DeviceRunningData{
DeviceCollectionId: record.DeviceCollectionId,
WorkShopName: record.WorkShopName,
CollectionTime: record.CollectionTime,
CollectionTime: record.CollectionTime.Local(),
DeviceCode: record.DeviceSn,
DeviceType: record.DeviceType,
StartupStatus: int(record.StartupStatus),
... ... @@ -160,6 +161,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
}
data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1)
data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1)
data.Alarm = deviceYouZhaJi.Alarm
} else {
deviceYouZhaJi := &domain.DeviceYouZhaJi2{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
... ... @@ -168,6 +170,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
}
data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1)
data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1)
data.Alarm = deviceYouZhaJi.Alarm
}
break
//串串机
... ... @@ -193,6 +196,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
break
}
data.Temp1 = utils.Truncate(deviceSuDongXian.CurrTemp, 1)
data.Alarm = deviceSuDongXian.Alarm
break
//封口机
case domain.DeviceTypeFengKouJi:
... ... @@ -231,6 +235,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
return data, nil
}
// 设备运行记录
func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData) (*domain.DeviceRunningRecord, error) {
return &domain.DeviceRunningRecord{
CompanyId: companyId,
... ... @@ -239,10 +244,11 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId
DeviceId: device.DeviceId,
DeviceCode: device.DeviceCode,
DeviceRunningRecordInfo: data,
CreatedAt: data.CollectionTime,
CreatedAt: data.CollectionTime.Local(),
}, nil
}
// 生产记录
func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, plan *domain.ProductPlanDispatchRecord) (*domain.ProductRecord, error) {
result := &domain.ProductRecord{
CompanyId: companyId,
... ... @@ -250,7 +256,7 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i
WorkStation: workStation,
ProductRecordType: domain.RecordTypeWeigh,
ProductWorker: &domain.User{},
CreatedAt: data.CollectionTime,
CreatedAt: data.CollectionTime.Local(),
UpdatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
... ... @@ -279,31 +285,33 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId,
if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{
"workStationId": workStation.WorkStationId,
"deviceCode": data.DeviceCode,
"productDate": utils.GetZeroTime(data.CollectionTime),
"productDate": utils.GetZeroTime(data.CollectionTime.Local()),
}); err != nil {
if err != domain.ErrorNotFound {
return nil, err
}
}
if record != nil {
record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode)
return record, nil
}
recordInfo := domain.NewDeviceRunningRecordInfo()
recordInfo.ProductPlanId = planId
recordInfo.DeviceName = device.DeviceName
recordInfo.OrgName = device.Ext.OrgName
recordInfo.ProductDate = data.CollectionTime.Local().Format("2006-01-02")
record = &domain.DeviceDailyRunningRecord{
CompanyId: companyId,
OrgId: orgId,
WorkStation: workStation,
DeviceId: device.DeviceId,
DeviceCode: device.DeviceCode,
ProductDate: utils.GetZeroTime(data.CollectionTime),
ProductDate: utils.GetZeroTime(data.CollectionTime.Local()),
DeviceRunningRecordInfo: recordInfo,
CreatedAt: data.CollectionTime,
CreatedAt: data.CollectionTime.Local(),
UpdatedAt: time.Now(),
}
record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode)
if record, err = deviceDailyRunningRecordRepository.Save(record); err != nil {
return nil, err
}
... ...
... ... @@ -14,8 +14,9 @@ import (
func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.DeviceDailyRunningRecord, error) {
client := GetRedis()
key := DeviceDailyRunningRecordKey(t, deviceCode)
log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v", deviceCode, key))
return getDeviceDailyRunningRecord(client, key)
record, err := getDeviceDailyRunningRecord(client, key)
log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v Value:%v", deviceCode, key, record))
return record, err
}
func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.DeviceDailyRunningRecord, error) {
... ... @@ -25,6 +26,7 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi
return nil, domain.ErrorNotFound
}
var record = &domain.DeviceDailyRunningRecord{}
record.RedisKey = key
if err = json.Unmarshal(data, record); err != nil {
return nil, err
}
... ... @@ -32,16 +34,28 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi
}
// 保存每日设备运行数据
func SaveDeviceDailyRunningRecord(record *domain.DeviceDailyRunningRecord) error {
func SaveDeviceDailyRunningRecord(t time.Time, record *domain.DeviceDailyRunningRecord) error {
client := GetRedis()
key := DeviceDailyRunningRecordKey(record.ProductDate, record.DeviceCode)
log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Count:%v", record.DeviceCode, key, record.DeviceRunningRecordInfo.Count))
key := DeviceDailyRunningRecordKey(t, record.DeviceCode)
recordData, err := json.Marshal(record)
result := client.Set(key, recordData, time.Hour*24*5)
_, err = result.Result()
return err
}
// 保存每日设备运行数据 - 按键值
func SaveDeviceDailyRunningRecordByKey(key string, record *domain.DeviceDailyRunningRecord) error {
client := GetRedis()
recordData, err := json.Marshal(record)
if err != nil {
return err
}
log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Value:%v", record.DeviceCode, key, record))
result := client.Set(key, recordData, time.Hour*24*5)
_, err = result.Result()
return err
}
// 保存每日设备运行数据
func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error {
client := GetRedis()
... ... @@ -51,11 +65,25 @@ func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error {
return err
}
// 保存每日设备运行数据
func RemoveDeviceDailyRunningRecordByKey(key string) error {
client := GetRedis()
//key := DeviceDailyRunningRecordKey(t, deviceCode)
result := client.Del(key)
_, err := result.Result()
return err
}
func DeviceDailyRunningRecordKey(t time.Time, deviceCode string) string {
str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, t.Local().Format("2006-01-02"), deviceCode)
return str
}
func DeviceDailyRunningRecordKeyByTimeStr(timeStr string, deviceCode string) string {
str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, timeStr, deviceCode)
return str
}
// 获取设备每日所有数据记录
func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, error) {
client := GetRedis()
... ... @@ -70,6 +98,7 @@ func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, e
if err != nil {
return nil, err
}
record.RedisKey = v
records = append(records, record)
}
return records, nil
... ...
... ... @@ -151,6 +151,12 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("batch_number=?", "batchNumber")
if v, ok := queryOptions["erpBillNo"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`ext#>'{productPlanExt,erpBillNo}' = '"%v"'`, v))
}
if v, ok := queryOptions["productCode"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`ext#>'{productPlanExt,productCode}' = '"%v"'`, v))
}
if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) {
query.AllWithDeleted()
}
... ... @@ -181,6 +187,12 @@ func (repository *ProductPlanRepository) Find(queryOptions map[string]interface{
if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`workshop->>'workshopName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["erpBillNo"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`ext#>'{productPlanExt,erpBillNo}' = '"%v"'`, v))
}
if v, ok := queryOptions["productCode"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`ext#>'{productPlanExt,productCode}' = '"%v"'`, v))
}
query.SetWhereByQueryOption("plan_status=?", "planStatus")
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_plan_id", "DESC")
... ...
package utils
import (
"fmt"
"github.com/linmadan/egglib-go/utils/json"
"testing"
"time"
)
type User struct {
Age time.Time
AgeZero time.Time
AgeZeroFormat string
}
func TestTimeParseInLocal(t *testing.T) {
timeStr := "2022-01-02 1:00:00"
tl, _ := time.ParseInLocation("2006-01-02 15:04:05", timeStr, time.Local)
u1 := User{
Age: tl,
AgeZero: GetZeroTime(tl),
}
u1.AgeZeroFormat = u1.AgeZero.Format("2006-01-02")
fmt.Println(json.MarshalToString(u1), u1.Age.Local())
timeMarsh(&u1)
}
func timeMarsh(u *User) {
var u2 = &User{}
u1Data, _ := json.Marshal(u)
json.Unmarshal(u1Data, u2)
fmt.Println("时间:", u2.Age, u2.Age.Local(), u2.AgeZero)
}
... ...
... ... @@ -55,7 +55,7 @@ func TestComputeTimeDuration(t *testing.T) {
}
}
const TIME_LAYOUT = "2006-01-02 03:04:05"
const TIME_LAYOUT = "2006-01-02 15:04:05"
func TestTimeParse(t *testing.T) {
fmt.Println(int(-1))
... ... @@ -64,11 +64,13 @@ func TestTimeParse(t *testing.T) {
func timeParse() {
fmt.Println("0. now: ", time.Now())
str := "2018-09-10 10:00:00"
str := "2018-09-10 16:00:00"
fmt.Println("1. str: ", str)
t, _ := time.Parse(TIME_LAYOUT, str)
fmt.Println("2. Parse time: ", t)
t, err := time.Parse(TIME_LAYOUT, str)
fmt.Println("2. Parse time: ", t, err)
fmt.Println("2.1. Parse time: ", t.Local(), t.Local().Local())
parseInLocal, _ := time.ParseInLocation(TIME_LAYOUT, str, time.Local)
fmt.Println("2.2 parse in local", parseInLocal, parseInLocal.Local())
tStr := t.Format(TIME_LAYOUT)
fmt.Println("3. Format time str: ", tStr)
name, offset := t.Zone()
... ...
... ... @@ -119,6 +119,31 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context)
}
Response(ctx, response, nil)
break
case "10":
t := ctx.Input.Query("t")
c, _ := strconv.Atoi(ctx.Input.Query("c"))
if len(t) != 0 {
if v, err := time.ParseInLocation("2006-01-02 - 15:04:05", t, time.UTC); err == nil {
domainService.SendWorkshopDeviceData(&domain.DeviceCollection{
DeviceCollectionId: time.Now().Unix(),
WorkShopName: "NG",
CollectionTime: v,
DeviceSn: "CCJ1",
DeviceType: "CCJ",
StartupStatus: 1,
ComStatus: 1,
ProductCount: c,
Values: map[string]interface{}{
"Count": c,
"Year": 2022,
"Month": 3,
"Day": 8,
"ProductType": 2,
},
LatestUpdateTime: time.Now(),
})
}
}
}
Response(ctx, nil, nil)
}
... ...
... ... @@ -22,13 +22,14 @@ func Start(log logimp.Logger) {
func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
payload := make(map[string]interface{})
var collectionTime time.Time
err := json.Unmarshal(message.Payload(), &payload)
if err != nil {
log.Logger.Error("车间数据json解析失败:" + err.Error())
return
}
if workShop, ok := payload["WorkShop"]; ok {
var collectionTime time.Time
if t, ok := payload["UpTime"]; ok {
collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local)
}
... ... @@ -153,7 +154,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
}
//TODO:日志先注释
if err == nil {
log.Logger.Info("MQTT", map[string]interface{}{
log.Logger.Info(fmt.Sprintf("MQTT:%v", collectionTime), map[string]interface{}{
"Topic": message.Topic(),
"MessageId": message.MessageID(),
"Message": payload,
... ...
... ... @@ -19,7 +19,7 @@ func WorkshopDataConsumer(c context.Context, t *asynq.Task) error {
return err
}
log.Logger.Debug(fmt.Sprintf("【车间数据消费】 消费 设备:%v 消息号:%v 时间:%v ", cmd.DeviceCollection.DeviceSn, cmd.DeviceCollectionId, cmd.CollectionTime),
map[string]interface{}{"p-message": cmd.DeviceCollection})
map[string]interface{}{"p-message": string(t.Payload())})
cmd.CompanyId = constant.MANUFACTURE_DEFAULT_COMPANYID
cmd.OrgId = constant.MANUFACTURE_DEFAULT_ORGID
_, err := svr.WorkshopConsume(cmd)
... ...