device.go 3.1 KB
package domain

import "time"

// 设备
type Device struct {
	// 设备Id
	DeviceId int `json:"deviceId,omitempty"`
	// 企业id
	CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	OrgId int `json:"orgId,omitempty"`
	// 设备编号
	DeviceCode string `json:"deviceCode,omitempty"`
	// 设备名称
	DeviceName string `json:"deviceName,omitempty"`
	// 设备型号
	DeviceModel string `json:"deviceModel,omitempty"`
	// 设备类型
	DeviceType string `json:"deviceType,omitempty"`
	// 品牌
	Brand string `json:"brand,omitempty"`
	// 设备状态 1:正常 2:封存 3:报废
	DeviceStatus int `json:"deviceStatus,omitempty"`
	// 风险等级 1:高 2:中 3:低
	RiskLevel int `json:"riskLevel,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt,omitempty"`
	// 所属位置
	WorkStation *WorkStation `json:"workStation,omitempty"`
}

type DeviceRepository interface {
	Save(device *Device) (*Device, error)
	Remove(device *Device) (*Device, error)
	FindOne(queryOptions map[string]interface{}) (*Device, error)
	Find(queryOptions map[string]interface{}) (int64, []*Device, error)
}

func (device *Device) Identify() interface{} {
	if device.DeviceId == 0 {
		return nil
	}
	return device.DeviceId
}

func (device *Device) Update(data map[string]interface{}) error {
	if companyId, ok := data["companyId"]; ok {
		device.CompanyId = companyId.(int)
	}
	if orgId, ok := data["orgId"]; ok {
		device.OrgId = orgId.(int)
	}
	if deviceCode, ok := data["deviceCode"]; ok {
		device.DeviceCode = deviceCode.(string)
	}
	if deviceName, ok := data["deviceName"]; ok {
		device.DeviceName = deviceName.(string)
	}
	if deviceModel, ok := data["deviceModel"]; ok {
		device.DeviceModel = deviceModel.(string)
	}
	if deviceType, ok := data["deviceType"]; ok {
		device.DeviceType = deviceType.(string)
	}
	if brand, ok := data["brand"]; ok {
		device.Brand = brand.(string)
	}
	if deviceStatus, ok := data["deviceStatus"]; ok {
		device.DeviceStatus = deviceStatus.(int)
	}
	if riskLevel, ok := data["riskLevel"]; ok {
		device.RiskLevel = riskLevel.(int)
	}
	if createdAt, ok := data["createdAt"]; ok {
		device.CreatedAt = createdAt.(time.Time)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		device.UpdatedAt = updatedAt.(time.Time)
	}
	if deletedAt, ok := data["deletedAt"]; ok {
		device.DeletedAt = deletedAt.(time.Time)
	}
	if workStationId, ok := data["workStationId"]; ok {
		device.WorkStation.WorkStationId = workStationId.(string)
	}
	if workshopId, ok := data["workshopId"]; ok {
		device.WorkStation.WorkshopId = workshopId.(int)
	}
	if workshopName, ok := data["workshopName"]; ok {
		device.WorkStation.WorkshopName = workshopName.(string)
	}
	if lineId, ok := data["lineId"]; ok {
		device.WorkStation.LineId = lineId.(int)
	}
	if lineName, ok := data["lineName"]; ok {
		device.WorkStation.LineName = lineName.(string)
	}
	if sectionId, ok := data["sectionId"]; ok {
		device.WorkStation.SectionId = sectionId.(int)
	}
	if sectionName, ok := data["sectionName"]; ok {
		device.WorkStation.SectionName = sectionName.(string)
	}
	return nil
}