package schedule

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

type WorkShiftSrv struct {
	WorkShiftNr		int
	ShiftType		string
	StartTime		time.Time
	EndTime			time.Time
	Wsstab			model.WorkShift
}

func( wss *WorkShiftSrv)Init(wstab model.WorkShift){
	wss.WorkShiftNr	= wstab.WorkShiftNr
	wss.Wsstab		= wstab
}

// 基于指定的人数获取效率，默认取班组设置效率
func( wss *WorkShiftSrv)GetEffByPersonQty(pesqty int)(eff float64){
	var(
		i		int
		found	bool
	)

	found = false
	for i = 0; i < len(wss.Wsstab.WorkShiftEffLst); i++ {
		if pesqty >= wss.Wsstab.WorkShiftEffLst[i].PlanPersonLclQty && pesqty <= wss.Wsstab.WorkShiftEffLst[i].PlanPersonUclQty {
			found 	= true
			eff		= wss.Wsstab.WorkShiftEffLst[i].PlanEfficiency
			break
		}
	}
	if !found {
		eff = wss.Wsstab.PlanEfficiency
	}
	return
}

// 基于人员出勤等级获取效率，默认取班组设置效率
func( wss *WorkShiftSrv)GetEffByLevel(levelid string)(eff float64){
	var(
		i		int
		found	bool
	)

	found = false
	for i = 0; i < len(wss.Wsstab.WorkShiftEffLst); i++ {
		if levelid >= wss.Wsstab.WorkShiftEffLst[i].LevelId {
			found 	= true
			eff		= wss.Wsstab.WorkShiftEffLst[i].PlanEfficiency
			break
		}
	}
	if !found {
		eff = wss.Wsstab.PlanEfficiency
	}
	return
}
