product_group.go 3.5 KB
package domain

import "time"

// 生产班组
type ProductGroup struct {
	// 生产小组ID
	ProductGroupId int `json:"productGroupId,omitempty"`
	// 企业id
	CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	OrgId int `json:"orgId,omitempty"`
	// 班组名称
	GroupName string `json:"groupName,omitempty"`
	// 班组长
	GroupLeader *User `json:"groupLeader,omitempty"`
	// 帮组成员列表
	GroupMembers []*User `json:"groupMembers,omitempty"`
	// 上班班次 1:全天  2:白班 4:中班  8:夜班
	WorkOn int `json:"workOn,omitempty"`
	// 工作位置
	WorkStation *WorkStation `json:"workStation,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt,omitempty"`
}

type ProductGroupRepository interface {
	Save(productGroup *ProductGroup) (*ProductGroup, error)
	Remove(productGroup *ProductGroup) (*ProductGroup, error)
	FindOne(queryOptions map[string]interface{}) (*ProductGroup, error)
	Find(queryOptions map[string]interface{}) (int64, []*ProductGroup, error)
}

func (productGroup *ProductGroup) Identify() interface{} {
	if productGroup.ProductGroupId == 0 {
		return nil
	}
	return productGroup.ProductGroupId
}

func (productGroup *ProductGroup) Update(data map[string]interface{}) error {
	if productGroupId, ok := data["productGroupId"]; ok {
		productGroup.ProductGroupId = productGroupId.(int)
	}
	if companyId, ok := data["companyId"]; ok {
		productGroup.CompanyId = companyId.(int)
	}
	if orgId, ok := data["orgId"]; ok {
		productGroup.OrgId = orgId.(int)
	}
	if groupName, ok := data["groupName"]; ok {
		productGroup.GroupName = groupName.(string)
	}
	if userId, ok := data["userId"]; ok {
		productGroup.GroupLeader.UserId = userId.(int)
	}
	if userName, ok := data["userName"]; ok {
		productGroup.GroupLeader.UserName = userName.(string)
	}
	if employeeType, ok := data["employeeType"]; ok {
		productGroup.GroupLeader.EmployeeType = employeeType.(int)
	}
	if icCardNumber, ok := data["icCardNumber"]; ok {
		productGroup.GroupLeader.IcCardNumber = icCardNumber.(string)
	}
	if avatar, ok := data["avatar"]; ok {
		productGroup.GroupLeader.Avatar = avatar.(string)
	}
	if phone, ok := data["phone"]; ok {
		productGroup.GroupLeader.Phone = phone.(string)
	}
	//if groupMembers, ok := data["groupMembers"]; ok {
	//	productGroup.GroupMembers = groupMembers.(array)
	//}
	if workOn, ok := data["workOn"]; ok {
		productGroup.WorkOn = workOn.(int)
	}
	if workStationId, ok := data["workStationId"]; ok {
		productGroup.WorkStation.WorkStationId = workStationId.(string)
	}
	if workshopId, ok := data["workshopId"]; ok {
		productGroup.WorkStation.WorkshopId = workshopId.(int)
	}
	if workshopName, ok := data["workshopName"]; ok {
		productGroup.WorkStation.WorkshopName = workshopName.(string)
	}
	if lineId, ok := data["lineId"]; ok {
		productGroup.WorkStation.LineId = lineId.(int)
	}
	if lineName, ok := data["lineName"]; ok {
		productGroup.WorkStation.LineName = lineName.(string)
	}
	if sectionId, ok := data["sectionId"]; ok {
		productGroup.WorkStation.SectionId = sectionId.(int)
	}
	if sectionName, ok := data["sectionName"]; ok {
		productGroup.WorkStation.SectionName = sectionName.(string)
	}
	if createdAt, ok := data["createdAt"]; ok {
		productGroup.CreatedAt = createdAt.(time.Time)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		productGroup.UpdatedAt = updatedAt.(time.Time)
	}
	if deletedAt, ok := data["deletedAt"]; ok {
		productGroup.DeletedAt = deletedAt.(time.Time)
	}
	return nil
}