80 lines
3.5 KiB
Go
80 lines
3.5 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/fonchain_enterprise/fonchain-main/api/oa"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/login"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/oa_model"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func OutWorkCheckVerify(applyTimes []*oa.ApplyTime, userInfo login.Info, currentActionType string) (retCurrentActionType string, isNeed bool, err error) {
|
|
fmt.Println("=== OutWorkCheckVerify 0 =================================================")
|
|
fmt.Printf("++ applyTime %+v \n", applyTimes)
|
|
fmt.Printf("++ userInfo %+v \n", userInfo)
|
|
fmt.Printf("++ currentActionType %+v \n", currentActionType)
|
|
fmt.Println("=== OutWorkCheckVerify 0 =================================================")
|
|
// 查询 考勤规则
|
|
departmentUUIDs := make([]string, 0)
|
|
queryTimeOptions := make([]oa_model.QueryTimeOption, 0)
|
|
for i := 0; i < len(userInfo.PositionUsers); i++ {
|
|
departmentUUIDs = append(departmentUUIDs, strconv.FormatUint(userInfo.PositionUsers[i].DepartmentId, 10))
|
|
queryTimeOption := oa_model.QueryTimeOption{
|
|
PositionUID: strconv.FormatUint(userInfo.PositionUsers[i].PositionID, 10),
|
|
DepartmentUID: strconv.FormatUint(userInfo.PositionUsers[i].DepartmentId, 10),
|
|
}
|
|
queryTimeOptions = append(queryTimeOptions, queryTimeOption)
|
|
}
|
|
|
|
timesOptionBest, err := WorkingTimeAndWeekBest(0, queryTimeOptions)
|
|
if err != nil {
|
|
return "", false, err
|
|
}
|
|
|
|
for i := 0; i < len(applyTimes); i++ {
|
|
// 非工作日 无需确认
|
|
if !ConfirmIsWork(timesOptionBest.Week, applyTimes[i].Date) {
|
|
continue
|
|
}
|
|
|
|
// 回公司 记录 必须在 外勤结束时间之后 外勤结束当天 12点之前 创建 否则不再处理
|
|
zeroTime, _ := time.ParseInLocation("2006-01-02 15:04:05", applyTimes[len(applyTimes)-1].Date+" 23:59:59", time.Local)
|
|
applyEndTime, _ := time.ParseInLocation("2006-01-02 15:04:05", applyTimes[len(applyTimes)-1].Date+" "+applyTimes[len(applyTimes)-1].Hour+":00", time.Local)
|
|
|
|
fmt.Println("=== OutWorkCheckVerify time =================================================")
|
|
fmt.Println("applyEndTime : ", applyEndTime)
|
|
fmt.Println("zeroTime : ", zeroTime)
|
|
fmt.Println("=== OutWorkCheckVerify time =================================================")
|
|
|
|
applyTime, _ := time.ParseInLocation("2006-01-02 15:04:05", applyTimes[i].Date+" "+applyTimes[i].Hour+":00", time.Local)
|
|
|
|
for j := 0; j < len(timesOptionBest.Times); j++ {
|
|
workStartTime, _ := time.ParseInLocation("2006-01-02 15:04:05", applyTimes[i].Date+" "+timesOptionBest.Times[j].OnWorkTime+":00", time.Local)
|
|
workEndTime, _ := time.ParseInLocation("2006-01-02 15:04:05", applyTimes[i].Date+" "+timesOptionBest.Times[j].OffWorkTime+":00", time.Local)
|
|
fmt.Println("applyTime.After(workStartTime) && applyTime.Before(workEndTime) : ", applyTime.After(workStartTime) && applyTime.Before(workEndTime))
|
|
fmt.Println(" time.Now().After(applyEndTime) && time.Now().Before(zeroTime) : ", time.Now().After(applyEndTime) && time.Now().Before(zeroTime))
|
|
if applyTime.After(workStartTime) && applyTime.Before(workEndTime) {
|
|
if currentActionType == e.OutWorkOut {
|
|
if time.Now().In(time.Local).After(applyEndTime) && time.Now().In(time.Local).Before(zeroTime) {
|
|
return e.OutWorkBack, true, nil
|
|
} else {
|
|
return e.OutWorkOut, false, nil
|
|
}
|
|
}
|
|
|
|
if currentActionType == e.OutWorkBack {
|
|
return e.OutWorkBack, false, nil
|
|
}
|
|
|
|
if currentActionType == "" {
|
|
return e.OutWorkOut, true, nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return "", false, nil
|
|
}
|