product_line.go 1.4 KB
package domain

import "fmt"

// 生产线
type ProductLine struct {
	// 生产线ID
	LineId int `json:"lineId,omitempty"`
	// 生产线名称
	LineName string `json:"lineName,omitempty"`
	// 工段列表
	ProductSections []*ProductSection `json:"productSections,omitempty"`
	// 已删除标识 1:正常 2:已删除
	Removed int `json:"removed,omitempty"`
}

//输出简化的模型
type SimpleProductLine struct {
	LineId   int    `json:"lineId"`   // 生产线ID
	LineName string `json:"lineName"` // 生产线名称
}

// 查询生产线
func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) {
	for i := range productLine.ProductSections {
		item := productLine.ProductSections[i]
		if item.SectionId == sectionId {
			return item, nil
		}
	}
	return nil, fmt.Errorf("工段不存在")
}

func (productLine *ProductLine) GetProductSections(removed int) []*ProductSection {
	var result = make([]*ProductSection, 0)
	for i := range productLine.ProductSections {
		if removed > 0 && productLine.ProductSections[i].Removed != removed {
			continue
		}
		item := productLine.ProductSections[i]
		item.Removed = 0
		result = append(result, item)
	}
	return result
}

//SimpleProductLine 输出简化的模型
func (productLine *ProductLine) SimpleProductLine() SimpleProductLine {
	return SimpleProductLine{
		LineId:   productLine.LineId,
		LineName: productLine.LineName,
	}
}