product_job.go 1.5 KB
package domain

import "time"

// 工位(车间-生产线-工段-工位)
type ProductJob struct {
	// 工位ID
	ProductJobId int `json:"productJobId,omitempty"`
	// 企业id
	CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	OrgId int `json:"orgId,omitempty"`
	// 工位名称
	JobName string `json:"jobName,omitempty"`
	// 工序名称
	ProcessName string `json:"processName,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt,omitempty"`
	// 工作位置
	WorkStation *WorkStation `json:"workStation,omitempty"`
	// 关联设备列表
	RelatedDevices []int `json:"relatedDevices,omitempty"`
}

type ProductJobRepository interface {
	Save(productJob *ProductJob) (*ProductJob, error)
	Remove(productJob *ProductJob) (*ProductJob, error)
	FindOne(queryOptions map[string]interface{}) (*ProductJob, error)
	Find(queryOptions map[string]interface{}) (int64, []*ProductJob, error)
}

func (productJob *ProductJob) Identify() interface{} {
	if productJob.ProductJobId == 0 {
		return nil
	}
	return productJob.ProductJobId
}

func (productJob *ProductJob) Update(data map[string]interface{}) error {
	if jobName, ok := data["jobName"]; ok {
		productJob.JobName = jobName.(string)
	}
	if relatedDevices, ok := data["relatedDevices"]; ok {
		productJob.RelatedDevices = relatedDevices.([]int)
	}
	productJob.UpdatedAt = time.Now()
	return nil
}