product_material.go 2.5 KB
package domain

import "time"

// 生产物料
type ProductMaterial struct {
	// 物料ID
	ProductMaterialId int `json:"productMaterialId"`
	// 企业id
	CompanyId int `json:"companyId"`
	// 组织ID
	OrgId int `json:"orgId"`
	// 物料分组ID
	ProductMaterialGroupId int `json:"productMaterialGroupId"`
	// 物料编码
	MaterialNumber string `json:"materialNumber"`
	// 物料名称
	MaterialName string `json:"materialName"`
	// 物料属性
	MaterialAttribute *MaterialAttribute `json:"materialAttribute"`
	// 物料类别
	MaterialCategory *MaterialCategory `json:"materialCategory"`
	// 物料扩展
	ProductMaterialExt *MaterialExt `json:"productMaterialExt"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt"`
	// 扩展
	Ext *Ext `json:"ext"`
}

type ProductMaterialRepository interface {
	Save(productMaterial *ProductMaterial) (*ProductMaterial, error)
	Remove(productMaterial *ProductMaterial) (*ProductMaterial, error)
	FindOne(queryOptions map[string]interface{}) (*ProductMaterial, error)
	Find(queryOptions map[string]interface{}) (int64, []*ProductMaterial, error)
}

func (productMaterial *ProductMaterial) Identify() interface{} {
	if productMaterial.ProductMaterialId == 0 {
		return nil
	}
	return productMaterial.ProductMaterialId
}

func (productMaterial *ProductMaterial) Update(data map[string]interface{}) error {
	return nil
}

type ProductMaterials []*ProductMaterial

func (productMaterials ProductMaterials) ToMapById() map[int]*ProductMaterial {
	var mapProductMaterial = make(map[int]*ProductMaterial, 0)
	for _, v := range productMaterials {
		mapProductMaterial[v.ProductMaterialId] = v
	}
	return mapProductMaterial
}

func (productMaterials ProductMaterials) ToMapByNumber() map[string]*ProductMaterial {
	var mapProductMaterial = make(map[string]*ProductMaterial, 0)
	for _, v := range productMaterials {
		mapProductMaterial[v.MaterialNumber] = v
	}
	return mapProductMaterial
}

//  10:资产,9:配置,2:自制,11:费用,12:模型,5:虚拟,7:一次性,13:产品系列 12:模型,3:委外,4:特征,6:服务,1:外购
var mapMaterialCategory = map[int]string{
	1:  "外购",
	2:  "自制",
	3:  "委外",
	4:  "特征",
	5:  "虚拟",
	6:  "服务",
	7:  "一次性",
	8:  "",
	9:  "配置",
	10: "资产",
	11: "费用",
	12: "模型",
	13: "产品系列",
}

func MaterialAttributeDescription(code int) string {
	if v, ok := mapMaterialCategory[code]; ok {
		return v
	}
	return ""
}