device_collection.go 2.8 KB
package domain

import (
	"fmt"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
	"time"
)

// 设备采集数据
type DeviceCollection struct {
	// 数据采集ID
	DeviceCollectionId int64 `json:"deviceCollectionId,string"`
	// 车间名
	WorkShopName string `json:"workShopName"`
	// 采集时间
	CollectionTime time.Time `json:"collectionTime"`
	// 设备名
	DeviceSn string `json:"deviceSn"`
	// 设备类型
	DeviceType string `json:"deviceType"`
	// 启动状态 1-启动 0-停止
	StartupStatus int64 `json:"startupStatus"`
	// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
	ComStatus int64 `json:"comStatus"`
	// 设备数据值
	Values map[string]interface{} `json:"values"`
	// 数量(字库使用)
	ProductCount int `json:"productCount"`
	// 最后跟新时间(字库使用)
	LatestUpdateTime time.Time `json:"latest_update_time"`
}

var (
	// 包馅机
	DeviceTypeBaoXianJi = "BXJ"
	// 打浆机
	DeviceTypeDaJiangJi = "DJJ"
	// 面包屑机
	DeviceTypeMianBaoXie = "MBX"
	// 面包屑机
	DeviceTypeMianBaoXieJi = "MBXJ"
	// 油炸机
	DeviceTypeYouZhaJi = "YZJ"
	// 油炸机
	DeviceTypeYouZhaJi1 = "YZJ1"
	// 油炸机
	DeviceTypeYouZhaJi2 = "YZJ2"
	// 串串机
	DeviceTypeChuanChuanJi = "CCJ"
	// 速冻线
	DeviceTypeSuDongXian = "SDX"
	// 封口机
	DeviceTypeFengKouJi = "FKJ"
	// 封箱机
	DeviceTypeFengXiangJi = "FXJ"
)

type DeviceCollectionRepository interface {
	Save(deviceCollection *DeviceCollection) (*DeviceCollection, error)
	Remove(deviceCollection *DeviceCollection) (*DeviceCollection, error)
	FindOne(queryOptions map[string]interface{}) (*DeviceCollection, error)
	Find(queryOptions map[string]interface{}) (int64, []*DeviceCollection, error)
}

func (deviceCollection *DeviceCollection) Identify() interface{} {
	if deviceCollection.DeviceCollectionId == 0 {
		return nil
	}
	return deviceCollection.DeviceCollectionId
}

func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) error {
	if workShopName, ok := data["workShopName"]; ok {
		deviceCollection.WorkShopName = workShopName.(string)
	}
	if deviceSn, ok := data["deviceSn"]; ok {
		deviceCollection.DeviceSn = deviceSn.(string)
	}
	if deviceType, ok := data["deviceType"]; ok {
		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)
	}
	if comStatus, ok := data["comStatus"]; ok {
		deviceCollection.ComStatus = comStatus.(int64)
	}
	if values, ok := data["values"]; ok {
		deviceCollection.Values = values.(map[string]interface{})
	}
	return nil
}

func TaskDeviceCollection() string {
	return fmt.Sprintf("%v:task:device-collection:report", constant.CACHE_PREFIX)
}