package schedule

import (
	model "LAPP_LF_MOM_BACKEND/models/base"
	"LAPP_LF_MOM_BACKEND/utils"
	"time"
)

// 周模型
type WeekModelSrv struct {
	WeekModelNr		int
	ValidFromDate	time.Time
	DayModelNrArray	[]int
	WeekModelTab	model.WeekModel
}

// 初始化
func(wmsrv *WeekModelSrv)Init(wmtab model.WeekModel){
	var (
		i		int
	)

	wmsrv.WeekModelTab		= wmtab
	wmsrv.WeekModelNr 		= wmsrv.WeekModelTab.WeekModelNr
	wmsrv.ValidFromDate		= time.Now()
	wmsrv.DayModelNrArray	= []int{}
	for i = 0; i < wmsrv.WeekModelTab.LoopDays; i++ {
		if i < len(wmsrv.WeekModelTab.WeekModelLstLi) {
			wmsrv.DayModelNrArray = append(wmsrv.DayModelNrArray, wmsrv.WeekModelTab.WeekModelLstLi[i].DayModelNr)
		}else{
			wmsrv.DayModelNrArray = append(wmsrv.DayModelNrArray, 0 )
		}
	}
}

// 基于指定日期获取对应的日模型号
func(wmsrv *WeekModelSrv)GetDayModelNrByDate(spdate time.Time)(DayModelNr int){
	var(
		crossdays, moddays int
	)

	crossdays 	= utils.GetCrossDays(wmsrv.ValidFromDate, spdate)
	moddays		= crossdays % wmsrv.WeekModelTab.LoopDays
	if moddays < len(wmsrv.DayModelNrArray){
		DayModelNr 	= wmsrv.DayModelNrArray[moddays]
	}else{
		DayModelNr	= 0
	}
	return
}
