product_calendar.go 3.5 KB
package domain

import "time"

// 工厂日历
type ProductCalendar struct {
	// 工厂日历ID
	ProductCalendarId int `json:"productCalendarId,omitempty"`
	// 企业id
	CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	OrgId int `json:"orgId,omitempty"`
	// 工作位置
	WorkStation *WorkStation `json:"workStation,omitempty"`
	// 上班班次 1:全天  2:白班 4:中班  8:夜班
	WorkOn int `json:"workOn,omitempty"`
	// 日历选择
	CalendarSelected []string `json:"calendarSelected,omitempty"`
	// 上岗时间
	InWorkAt string `json:"inWorkAt,omitempty"`
	// 下岗时间
	OutWorkAt string `json:"outWorkAt,omitempty"`
	// 休息时间 (单位 h)
	BreakTime float64 `json:"breakTime,omitempty"`
	// 工时 (单位 h)
	WorkTime float64 `json:"workTime,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt,omitempty"`
}

type ProductCalendarRepository interface {
	Save(productCalendar *ProductCalendar) (*ProductCalendar, error)
	Remove(productCalendar *ProductCalendar) (*ProductCalendar, error)
	FindOne(queryOptions map[string]interface{}) (*ProductCalendar, error)
	Find(queryOptions map[string]interface{}) (int64, []*ProductCalendar, error)
}

func (productCalendar *ProductCalendar) Identify() interface{} {
	if productCalendar.ProductCalendarId == 0 {
		return nil
	}
	return productCalendar.ProductCalendarId
}

func (productCalendar *ProductCalendar) Update(data map[string]interface{}) error {
	if productCalendarId, ok := data["productCalendarId"]; ok {
		productCalendar.ProductCalendarId = productCalendarId.(int)
	}
	if companyId, ok := data["companyId"]; ok {
		productCalendar.CompanyId = companyId.(int)
	}
	if orgId, ok := data["orgId"]; ok {
		productCalendar.OrgId = orgId.(int)
	}
	if workStationId, ok := data["workStationId"]; ok {
		productCalendar.WorkStation.WorkStationId = workStationId.(string)
	}
	if workshopId, ok := data["workshopId"]; ok {
		productCalendar.WorkStation.WorkshopId = workshopId.(int)
	}
	if workshopName, ok := data["workshopName"]; ok {
		productCalendar.WorkStation.WorkshopName = workshopName.(string)
	}
	if lineId, ok := data["lineId"]; ok {
		productCalendar.WorkStation.LineId = lineId.(int)
	}
	if lineName, ok := data["lineName"]; ok {
		productCalendar.WorkStation.LineName = lineName.(string)
	}
	if sectionId, ok := data["sectionId"]; ok {
		productCalendar.WorkStation.SectionId = sectionId.(int)
	}
	if sectionName, ok := data["sectionName"]; ok {
		productCalendar.WorkStation.SectionName = sectionName.(string)
	}
	if workOn, ok := data["workOn"]; ok {
		productCalendar.WorkOn = workOn.(int)
	}
	//if calendarSelected, ok := data["calendarSelected"]; ok {
	//	productCalendar.CalendarSelected = calendarSelected.(array)
	//}
	if inWorkAt, ok := data["inWorkAt"]; ok {
		productCalendar.InWorkAt = inWorkAt.(string)
	}
	if outWorkAt, ok := data["outWorkAt"]; ok {
		productCalendar.OutWorkAt = outWorkAt.(string)
	}
	if breakTime, ok := data["breakTime"]; ok {
		productCalendar.BreakTime = breakTime.(float64)
	}
	if workTime, ok := data["workTime"]; ok {
		productCalendar.WorkTime = workTime.(float64)
	}
	if createdAt, ok := data["createdAt"]; ok {
		productCalendar.CreatedAt = createdAt.(time.Time)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		productCalendar.UpdatedAt = updatedAt.(time.Time)
	}
	if deletedAt, ok := data["deletedAt"]; ok {
		productCalendar.DeletedAt = deletedAt.(time.Time)
	}
	return nil
}