work_station.go 1.5 KB
package domain

import "fmt"

// 工作位置(车间、生产线、工段组成),唯一标识工作位置
type WorkStation struct {
	// 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID)
	WorkStationId string `json:"workStationId,omitempty"`
	// 车间ID
	WorkshopId int `json:"workshopId,omitempty"`
	// 车间名称
	WorkshopName string `json:"workshopName,omitempty"`
	// 生产线ID
	LineId int `json:"lineId,omitempty"`
	// 生产线名称
	LineName string `json:"lineName,omitempty"`
	// 工段ID
	SectionId int `json:"sectionId,omitempty"`
	// 工段名称
	SectionName string `json:"sectionName,omitempty"`
	// 负责人 (用户对象)
	Principal *User `json:"principal,omitempty"`
}

func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation {
	item := &WorkStation{
		//WorkshopId:    w.WorkshopId,
		//WorkshopName:  w.WorkshopName,
		//LineId:        l.LineId,
		//LineName:      l.LineName,
		//SectionId:     s.SectionId,
		//SectionName:   s.SectionName,
		//Principal:     w.Principal,
	}
	if w != nil && l != nil && s != nil {
		item.WorkStationId = WorkstationKey(w.WorkshopId, l.LineId, s.SectionId)
	}
	if w != nil {
		item.WorkshopId = w.WorkshopId
		item.WorkshopName = w.WorkshopName
	}
	if l != nil {
		item.LineId = l.LineId
		item.LineName = l.LineName
	}
	if s != nil {
		item.SectionId = s.SectionId
		item.SectionName = s.SectionName
	}
	return item
}

func WorkstationKey(workshopId, lineId, sectionId int) string {
	return fmt.Sprintf("%v.%v.%v", workshopId, lineId, sectionId)
}