unit_conversion.go 4.1 KB
package domain

import "time"

// 单位换算
type UnitConversion struct {
	// 单位换算ID
	UnitConversionId int `json:"unitConversionId,omitempty"`
	// 企业id
	CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	OrgId int `json:"orgId,omitempty"`
	// 工作位置
	WorkStation *WorkStation `json:"workStation,omitempty"`
	// material
	Material *Material `json:"material,omitempty"`
	// 转换前单位数量
	FromUnitQuantity *UnitQuantity `json:"fromUnitQuantity,omitempty"`
	// 转换后单位数量
	ToUnitQuantity *UnitQuantity `json:"toUnitQuantity,omitempty"`
	// 智能称重标识
	IntelligentWeighingFlag bool `json:"intelligentWeighingFlag,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt,omitempty"`
}

type UnitConversionRepository interface {
	Save(unitConversion *UnitConversion) (*UnitConversion, error)
	Remove(unitConversion *UnitConversion) (*UnitConversion, error)
	FindOne(queryOptions map[string]interface{}) (*UnitConversion, error)
	Find(queryOptions map[string]interface{}) (int64, []*UnitConversion, error)
}

func (unitConversion *UnitConversion) Identify() interface{} {
	if unitConversion.UnitConversionId == 0 {
		return nil
	}
	return unitConversion.UnitConversionId
}

func (unitConversion *UnitConversion) Update(data map[string]interface{}) error {
	if unitConversionId, ok := data["unitConversionId"]; ok {
		unitConversion.UnitConversionId = unitConversionId.(int)
	}
	if companyId, ok := data["companyId"]; ok {
		unitConversion.CompanyId = companyId.(int)
	}
	if orgId, ok := data["orgId"]; ok {
		unitConversion.OrgId = orgId.(int)
	}
	if workStationId, ok := data["workStationId"]; ok {
		unitConversion.WorkStation.WorkStationId = workStationId.(string)
	}
	if workshopId, ok := data["workshopId"]; ok {
		unitConversion.WorkStation.WorkshopId = workshopId.(int)
	}
	if workshopName, ok := data["workshopName"]; ok {
		unitConversion.WorkStation.WorkshopName = workshopName.(string)
	}
	if lineId, ok := data["lineId"]; ok {
		unitConversion.WorkStation.LineId = lineId.(int)
	}
	if lineName, ok := data["lineName"]; ok {
		unitConversion.WorkStation.LineName = lineName.(string)
	}
	if sectionId, ok := data["sectionId"]; ok {
		unitConversion.WorkStation.SectionId = sectionId.(int)
	}
	if sectionName, ok := data["sectionName"]; ok {
		unitConversion.WorkStation.SectionName = sectionName.(string)
	}
	if materialName, ok := data["materialName"]; ok {
		unitConversion.Material.MaterialName = materialName.(string)
	}
	if materialCategory, ok := data["materialCategory"]; ok {
		unitConversion.Material.MaterialCategory = materialCategory.(string)
	}
	if quantity, ok := data["quantity"]; ok {
		unitConversion.FromUnitQuantity.Quantity = quantity.(float64)
	}
	if unit, ok := data["unit"]; ok {
		unitConversion.FromUnitQuantity.Unit = unit.(string)
	}
	if unitWeight, ok := data["unitWeight"]; ok {
		unitConversion.FromUnitQuantity.UnitWeight = unitWeight.(float64)
	}
	if weight, ok := data["weight"]; ok {
		unitConversion.FromUnitQuantity.Weight = weight.(float64)
	}
	//if quantity, ok := data["quantity"]; ok {
	//	unitConversion.ToUnitQuantity.FromUnitQuantity.Quantity = quantity.(float64)
	//}
	//if unit, ok := data["unit"]; ok {
	//	unitConversion.ToUnitQuantity.FromUnitQuantity.Unit = unit.(string)
	//}
	//if unitWeight, ok := data["unitWeight"]; ok {
	//	unitConversion.ToUnitQuantity.FromUnitQuantity.UnitWeight = unitWeight.(float64)
	//}
	//if weight, ok := data["weight"]; ok {
	//	unitConversion.ToUnitQuantity.FromUnitQuantity.Weight = weight.(float64)
	//}
	//if intelligentWeighingFlag, ok := data["intelligentWeighingFlag"]; ok {
	//	unitConversion.IntelligentWeighingFlag = intelligentWeighingFlag.(boolean)
	//}
	if createdAt, ok := data["createdAt"]; ok {
		unitConversion.CreatedAt = createdAt.(time.Time)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		unitConversion.UpdatedAt = updatedAt.(time.Time)
	}
	if deletedAt, ok := data["deletedAt"]; ok {
		unitConversion.DeletedAt = deletedAt.(time.Time)
	}
	return nil
}