employee_product_record.go 3.8 KB
package domain

import "time"

const (
	ParticipateNormal  = 1
	ParticipateSupport = 2
)

// 员工生产记录
type EmployeeProductRecord struct {
	// 企业id
	CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	OrgId int `json:"orgId,omitempty"`
	// 员工产能记录ID
	EmployeeProductRecordId int `json:"employeeProductRecordId"`
	// 工作位置
	WorkStation *WorkStation `json:"workStation"`
	// 上班班次 1:全天  2:白班 4:中班  8:夜班
	WorkOn int `json:"workOn"`
	// 参与类型 1:正常 2:支援
	ParticipateType int `json:"participateType"`
	// 产能
	ProductWeigh float64 `json:"productWeigh"`
	// 二级品产能
	SecondLevelWeigh float64 `json:"secondLevelWeigh"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt"`
	// 扩展
	Ext *Ext `json:"ext"`
	// 版本号
	Version int `json:"version"`
	// 生产记录信息
	ProductRecordInfo *EmployeeProductRecordInfo `json:"productRecordInfo"`
	// 生产工人
	ProductWorker *User `comment:"生产工人"`
}

type EmployeeProductRecordInfo struct {
	// 生产日期
	ProductDate string `json:"productDate"`
	// 原始上报数据
	//OriginalWeigh float64 `json:"originalWeigh,omitempty"`
	// 换算后的产能
	//Weigh float64 `json:"weigh"`
	// 产能 - 审核前
	//WeighBefore float64 `json:"weighBefore"`
	// 产能-审核后
	//WeighAfter float64 `json:"weighAfter"`
	// 审核状态  1:未审核  2:已审核
	//ApproveStatus int64 `json:"approveStatus"`
	// 审核时间
	//ApproveAt int64 `json:"approveAt"`
	// 审核人
	//ApproveUser *User `json:"approveUser"`
	// 物料信息
	//Material *UnitConversion `json:"material,omitempty"`
	// 生产计划信息(批次)
	//ProductPlan *ProductPlan `json:"productPlan,omitempty"`
	// 单位换算ID
	//UnitConversionId int `json:"unitConversionId,omitempty"`

	// 生产计划ID
	ProductPlanId int `json:"productPlanId,omitempty"`
	// 计划的产品名称
	PlanProductName string `json:"planProductName,omitempty"`
	// 批号
	BatchNumber string `json:"batchNumber,omitempty"`

	// 生产小组ID
	ProductGroupId int `json:"productGroupId,omitempty"`
}

type EmployeeProductRecordRepository interface {
	Save(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
	Remove(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
	FindOne(queryOptions map[string]interface{}) (*EmployeeProductRecord, error)
	Find(queryOptions map[string]interface{}) (int64, []*EmployeeProductRecord, error)
}

func (employeeProductRecord *EmployeeProductRecord) Identify() interface{} {
	if employeeProductRecord.EmployeeProductRecordId == 0 {
		return nil
	}
	return employeeProductRecord.EmployeeProductRecordId
}

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

func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int) {
	if productRecordType == RecordTypeSecondLevelWeigh {
		employeeProductRecord.SecondLevelWeigh += weigh
	}
	if productRecordType == RecordTypeReceiveMaterial {
		employeeProductRecord.ProductWeigh += weigh
	}
	if productRecordType == RecordTypeReturnMaterial {
		employeeProductRecord.ProductWeigh -= weigh
	}
	employeeProductRecord.UpdatedAt = time.Now()
	employeeProductRecord.Version += 1
}

func (employeeProductRecord *EmployeeProductRecord) RealProductWeigh() float64 {
	return employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh
}

func (employeeProductRecord *EmployeeProductRecord) QualificationRate() int {
	if employeeProductRecord.ProductWeigh == employeeProductRecord.SecondLevelWeigh {
		return 0
	}
	result := int((employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh) * 100 / employeeProductRecord.ProductWeigh)
	return result
}