workshop.go 2.4 KB
package domain

import "time"

// 车间
type Workshop struct {
	// 企业id
	CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	OrgId int `json:"orgId,omitempty"`
	// 车间ID
	WorkshopId int `json:"workshopId,omitempty"`
	// 车间名称
	WorkshopName string `json:"workshopName,omitempty"`
	// 负责人 (用户对象)
	Principal *User `json:"principal,omitempty"`
	// 生产线
	ProductLines []*ProductLine `json:"productLines,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt,omitempty"`
}

type WorkshopRepository interface {
	Save(workshop *Workshop) (*Workshop, error)
	Remove(workshop *Workshop) (*Workshop, error)
	FindOne(queryOptions map[string]interface{}) (*Workshop, error)
	Find(queryOptions map[string]interface{}) (int64, []*Workshop, error)
}

func (workshop *Workshop) Identify() interface{} {
	if workshop.WorkshopId == 0 {
		return nil
	}
	return workshop.WorkshopId
}

func (workshop *Workshop) Update(data map[string]interface{}) error {
	//if companyId, ok := data["companyId"]; ok {
	//	workshop.CompanyId = companyId.(int)
	//}
	//if orgId, ok := data["orgId"]; ok {
	//	workshop.OrgId = orgId.(int)
	//}
	//if workshopId, ok := data["workshopId"]; ok {
	//	workshop.WorkshopId = workshopId.(int)
	//}
	if workshopName, ok := data["workshopName"]; ok {
		workshop.WorkshopName = workshopName.(string)
	}
	if userId, ok := data["userId"]; ok {
		workshop.Principal.UserId = userId.(int)
	}
	if userName, ok := data["userName"]; ok {
		workshop.Principal.UserName = userName.(string)
	}
	if employeeType, ok := data["employeeType"]; ok {
		workshop.Principal.EmployeeType = employeeType.(int)
	}
	if icCardNumber, ok := data["icCardNumber"]; ok {
		workshop.Principal.IcCardNumber = icCardNumber.(string)
	}
	if avatar, ok := data["avatar"]; ok {
		workshop.Principal.Avatar = avatar.(string)
	}
	if phone, ok := data["phone"]; ok {
		workshop.Principal.Phone = phone.(string)
	}
	//if productLines, ok := data["productLines"]; ok {
	//	workshop.ProductLines = productLines.(array)
	//}
	if createdAt, ok := data["createdAt"]; ok {
		workshop.CreatedAt = createdAt.(time.Time)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		workshop.UpdatedAt = updatedAt.(time.Time)
	}
	if deletedAt, ok := data["deletedAt"]; ok {
		workshop.DeletedAt = deletedAt.(time.Time)
	}
	return nil
}