package oa_logic import ( "fmt" "github.com/fonchain_enterprise/fonchain-main/api/oa" "github.com/fonchain_enterprise/fonchain-main/pkg/model/oa_model" "github.com/fonchain_enterprise/fonchain-main/pkg/service/oa_new/common" "github.com/fonchain_enterprise/fonchain-main/pkg/service/oa_new/model" "github.com/fonchain_enterprise/fonchain-main/pkg/utils/holiday" "go.uber.org/zap" ) /* 拆分 oa 申请 */ func CheckLeaveIn(dates []string, applyTimes []*oa.ApplyTime) (allIn, startIn, endIn bool) { if dates != nil && len(dates) > 0 { if applyTimes != nil { if len(applyTimes) == 1 { if common.IsInDates(applyTimes[0].Date, dates) { return true, false, false } } else if len(applyTimes) == 2 { if common.IsInDates(applyTimes[0].Date, dates) { startIn = true } if common.IsInDates(applyTimes[1].Date, dates) { endIn = true } if startIn && endIn { allIn = true } } } } return } func CheckLeaveOut(dates []string, applyTimes []*oa.ApplyTime) (within bool) { if dates != nil && len(dates) > 0 { if applyTimes != nil { if len(applyTimes) == 1 { if !common.IsInDates(applyTimes[0].Date, dates) { return true } } else if len(applyTimes) == 2 { var beforeStartOut, afterEndOut bool if common.BeforeStartDate(applyTimes[0].Date, dates) { beforeStartOut = true } if common.AfterEndDate(applyTimes[1].Date, dates) { afterEndOut = true } // 申请时间 开始时间 在时间段之前 且 结束时间 在时间段之后 if beforeStartOut && afterEndOut { within = true return } } } } return } func CalcDurationForDates(month string, dates []string, applyTimes []*oa.ApplyTime, workingTime *oa.WorkingTime, leaveType string) (day, hour float32, allIn bool) { if month != "" { dates = holiday.SplitMonthV1(common.Add25ForMonth(month), common.YYMMDD) } fmt.Println("============================================ CalcDurationForDates ============================================") fmt.Printf("dates: %+v\n", dates) fmt.Println("===========================================================================================================") fmt.Println("============================================ applyTimes ============================================") fmt.Printf("applyTimes: %+v\n", applyTimes) fmt.Println("===========================================================================================================") allIn, startIn, endIn := CheckLeaveIn(dates, applyTimes) fmt.Println("============================================ CheckLeaveIn ============================================") fmt.Printf("allIn: %v, startIn: %v, endIn: %v\n", allIn, startIn, endIn) fmt.Println("===========================================================================================================") if allIn { return 0, 0, allIn } // 开始时间 在 查询的 时间段内 if startIn { newApplyTimes := applyTimes if len(newApplyTimes) == 2 { newApplyTimes[1].Date = dates[len(dates)-1] if newApplyTimes[1].M != "" { newApplyTimes[1].M = "下午" } if newApplyTimes[1].Hour != "" { newApplyTimes[1].Hour = workingTime.Time[len(workingTime.Time)-1].OffWorkTime } } fmt.Println("============================================ newApplyTimes ============================================") fmt.Printf("newApplyTimes: %+v\n", newApplyTimes) fmt.Println("===========================================================================================================") fmt.Println("============================================ workingTime ============================================") fmt.Printf("workingTime: %+v\n", workingTime) fmt.Println("===========================================================================================================") fmt.Println("============================================ leaveType ============================================") fmt.Printf("leaveType: %s\n", leaveType) fmt.Println("===========================================================================================================") day, hour = calcDuration(newApplyTimes, workingTime, leaveType) return day, hour, allIn } // 结束时间 在 查询的 时间段内 if endIn { newApplyTimes := applyTimes newApplyTimes[0].Date = dates[0] if newApplyTimes[0].M != "" { newApplyTimes[0].M = "上午" } if newApplyTimes[0].Hour != "" { newApplyTimes[0].Hour = workingTime.Time[0].OnWorkTime } day, hour = calcDuration(newApplyTimes, workingTime, leaveType) return day, hour, allIn } within := CheckLeaveOut(dates, applyTimes) fmt.Println("============================================ CheckLeaveOut ============================================") fmt.Printf("within: %v\n", within) fmt.Println("===========================================================================================================") if within { newApplyTimes := applyTimes newApplyTimes[0].Date = dates[0] if newApplyTimes[0].M != "" { newApplyTimes[0].M = "上午" } if newApplyTimes[0].Hour != "" { newApplyTimes[0].Hour = workingTime.Time[0].OnWorkTime } if len(newApplyTimes) == 2 { newApplyTimes[1].Date = dates[len(dates)-1] if newApplyTimes[1].M != "" { newApplyTimes[1].M = "下午" } if newApplyTimes[1].Hour != "" { newApplyTimes[1].Hour = workingTime.Time[len(workingTime.Time)-1].OffWorkTime } } day, hour = calcDuration(newApplyTimes, workingTime, leaveType) } return } /* 包含节假日的假期类型 婚假 产假 陪产假 流产假 */ func calcDuration(applyTimes []*oa.ApplyTime, workingTime *oa.WorkingTime, leaveType string) (day, hour float32) { switch leaveType { case oa_model.TypeAnnualLeave: data := copyApplyTimes(applyTimes) res, err := AnnualLeaveDurationHandle(data, workingTime) if err != nil { zap.L().Error("calcDuration AnnualLeaveDurationHandle ", zap.Error(err)) } fmt.Println("============================================ AnnualLeaveDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return res.NotTakeOut.Days, 0 case oa_model.TypeBusinessTrip: data := copyApplyTimes(applyTimes) res, err := CalcAllDayDurationHandle(data) if err != nil { zap.L().Error("calcDuration BusinessTripDurationHandle ", zap.Error(err)) } fmt.Println("============================================ BusinessTripDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return res.NotTakeOut.Days, 0 case oa_model.TypeOutWork: data := copyApplyTimes(applyTimes) res, err := OutWorkDurationHandle(data) if err != nil { zap.L().Error("calcDuration OutWorkDurationHandle ", zap.Error(err)) } fmt.Println("============================================ OutWorkDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return 0, res.NotTakeOut.Hours case oa_model.TypeMaritalLeave: data := copyApplyTimes(applyTimes) res, err := CalcAllDayDurationHandle(data) if err != nil { zap.L().Error("calcDuration BusinessTripDurationHandle ", zap.Error(err)) } fmt.Println("============================================ BusinessTripDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return res.NotTakeOut.Days, 0 case oa_model.TypeMaternityLeave: data := copyApplyTimes(applyTimes) res, err := CalcAllDayDurationHandle(data) if err != nil { zap.L().Error("calcDuration BusinessTripDurationHandle ", zap.Error(err)) } fmt.Println("============================================ BusinessTripDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return res.NotTakeOut.Days, 0 case oa_model.TypeAbortLeave: data := copyApplyTimes(applyTimes) res, err := CalcAllDayDurationHandle(data) if err != nil { zap.L().Error("calcDuration BusinessTripDurationHandle ", zap.Error(err)) } fmt.Println("============================================ BusinessTripDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return res.NotTakeOut.Days, 0 case oa_model.TypePaternityLeave: data := copyApplyTimes(applyTimes) res, err := CalcAllDayDurationHandle(data) if err != nil { zap.L().Error("calcDuration BusinessTripDurationHandle ", zap.Error(err)) } fmt.Println("============================================ BusinessTripDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return res.NotTakeOut.Days, 0 default: data := copyApplyTimes(applyTimes) res, err := LeaveDurationHandle(data, workingTime) if err != nil { zap.L().Error("calcDuration LeaveDurationHandle ", zap.Error(err)) } fmt.Println("============================================ LeaveDurationHandle ============================================") fmt.Printf("res: %+v\n", res) fmt.Println("===========================================================================================================") return res.NotTakeOut.Days, res.NotTakeOut.Hours } } func copyApplyTimes(applyTimes []*oa.ApplyTime) model.Data { var date = model.Data{} date.ApplyTimes = make([]model.ApplyTime, 0) for i := 0; i < len(applyTimes); i++ { date.ApplyTimes = append(date.ApplyTimes, model.ApplyTime{ Date: applyTimes[i].Date, M: applyTimes[i].M, Hour: applyTimes[i].Hour, }) } return date }