package oa_logic import ( "context" "dubbo.apache.org/dubbo-go/v3/common/logger" "errors" "fmt" "github.com/fonchain_enterprise/fonchain-main/api/account" "github.com/fonchain_enterprise/fonchain-main/api/department" "github.com/fonchain_enterprise/fonchain-main/api/employee" "github.com/fonchain_enterprise/fonchain-main/api/oa" "github.com/fonchain_enterprise/fonchain-main/api/rule" "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" "github.com/fonchain_enterprise/fonchain-main/pkg/service" "github.com/fonchain_enterprise/fonchain-main/pkg/service/oa_new/model" "strconv" "strings" ) // QueryWorkingTimeInUse 临时用于查询员工的考勤信息 func QueryWorkingTimeInUse(positions []*rule.PositionUser, staffUID uint64) (workingTime *oa.WorkingTime, err error) { workingTime = new(oa.WorkingTime) if staffUID != 0 { //checkTheCurrentAttendanceShift, checkTheCurrentAttendanceShiftErr := service.GrpcEmployeeProvider.CheckTheCurrentAttendanceShift(context.Background(), &employee.CheckTheCurrentAttendanceShiftRequest{UserId: staffUID}) checkTheCurrentAttendanceShift, _ := service.GrpcEmployeeProvider.CheckTheCurrentAttendanceShift(context.Background(), &employee.CheckTheCurrentAttendanceShiftRequest{UserId: staffUID}) //if checkTheCurrentAttendanceShiftErr != nil { // logger.Errorf("查询员工档案 绑定的 考勤信息失败:%s", checkTheCurrentAttendanceShiftErr.Error()) // return nil, errors.New(e.ErrQueryEmployeeAttendance) //} if checkTheCurrentAttendanceShift != nil { fmt.Println("=========== checkTheCurrentAttendanceShift ===========") fmt.Printf("checkTheCurrentAttendanceShift %+v \n", checkTheCurrentAttendanceShift.AttendanceSectionUuid) fmt.Println("=========== checkTheCurrentAttendanceShift ===========") if checkTheCurrentAttendanceShift.AttendanceSectionUuid != "" { var queryWorkingTimeFormalErr error workingTime, queryWorkingTimeFormalErr = QueryWorkingTimeFormal(checkTheCurrentAttendanceShift.AttendanceSectionUuid) if err != nil { logger.Errorf("查询员工档案 后查询 考勤信息失败:%s", queryWorkingTimeFormalErr.Error()) } } } } if workingTime != nil && workingTime.UUID != "" { //departmentUID, _ := strconv.ParseUint(workingTime.DepartmentUID, 10, 64) //positionUID, _ := strconv.ParseUint(workingTime.PositionUID, 10, 64) //departmentName, positionName := queryDepartmentNameAndPositionName(departmentUID, positionUID) //if departmentName != "" { // workingTime.DepartmentName = departmentName //} //if positionName != "" { // workingTime.PositionName = positionName //} return workingTime, nil } // 查询 考勤信息 workingTimeWithPositionsReq := new(oa.WorkingTimeWithPositionsReq) workingTimeWithPositionsReq.Page = 1 workingTimeWithPositionsReq.PageSize = 99999 for i := 0; i < len(positions); i++ { workingTimeWithPositionsReq.Positions = append(workingTimeWithPositionsReq.Positions, &oa.WorkingTimeWithPositionsReqPosition{ PositionUID: strconv.FormatUint(positions[i].PositionID, 10), DepartmentUID: strconv.FormatUint(positions[i].DepartmentId, 10), }) } workingTimeWithPositionsReq.InUse = oa_model.InUse workingTimeWithPositionsRes, workingTimeWithPositionsResErr := service.GrpcOAImpl.QueryWorkingTimeWithPositions(context.Background(), workingTimeWithPositionsReq) if workingTimeWithPositionsResErr != nil { logger.Errorf("查询考勤信息失败:%s", workingTimeWithPositionsResErr.Error()) return nil, errors.New(e.ErrorQueryWorkingTime) } if workingTimeWithPositionsRes == nil || len(workingTimeWithPositionsRes.Data) == 0 { logger.Errorf("查询考勤信息失败:%s", "workingTimeWithPositionsRes is nil") return nil, errors.New(e.ErrorMissWorkingTime) } return workingTimeWithPositionsRes.Data[0], nil } func QueryWorkingTimeInUseTempAccount(positions []*account.PositionUser) (workingTime *oa.WorkingTime, err error) { // 查询 考勤信息 workingTimeWithPositionsReq := new(oa.WorkingTimeWithPositionsReq) workingTimeWithPositionsReq.Page = 1 workingTimeWithPositionsReq.PageSize = 99999 for i := 0; i < len(positions); i++ { workingTimeWithPositionsReq.Positions = append(workingTimeWithPositionsReq.Positions, &oa.WorkingTimeWithPositionsReqPosition{ PositionUID: strconv.FormatUint(positions[i].PositionID, 10), DepartmentUID: strconv.FormatUint(positions[i].DepartmentId, 10), }) } workingTimeWithPositionsReq.InUse = oa_model.InUse workingTimeWithPositionsRes, workingTimeWithPositionsResErr := service.GrpcOAImpl.QueryWorkingTimeWithPositions(context.Background(), workingTimeWithPositionsReq) if workingTimeWithPositionsResErr != nil { logger.Errorf("查询考勤信息失败:%s", workingTimeWithPositionsResErr.Error()) return nil, errors.New(e.ErrorQueryWorkingTime) } if workingTimeWithPositionsRes == nil || len(workingTimeWithPositionsRes.Data) == 0 { logger.Errorf("查询考勤信息失败:%s", "workingTimeWithPositionsRes is nil") return nil, errors.New(e.ErrorMissWorkingTime) } return workingTimeWithPositionsRes.Data[0], nil } // QueryWorkingTimeFormal 用于查询员工的考勤信息 正式 func QueryWorkingTimeFormal(workingTimeUUID string) (workingTime *oa.WorkingTime, err error) { // 查询 考勤信息 workingTimeListReq := new(oa.WorkingTimeListReq) workingTimeListReq.WorkingTimeUUID = workingTimeUUID workingTimeListReq.InUse = oa_model.InUse workingTimeListRes, workingTimeListResErr := service.GrpcOAImpl.WorkingTimeList(context.Background(), workingTimeListReq) if workingTimeListResErr != nil { logger.Errorf("查询考勤信息失败:%s", workingTimeListResErr.Error()) return nil, workingTimeListResErr } if workingTimeListRes == nil || len(workingTimeListRes.Data) == 0 { logger.Errorf("查询考勤信息失败:%s", "workingTimeWithPositionsRes is nil") return nil, errors.New(e.ErrorQueryWorkingTime) } if workingTimeListRes.Data[0].InUse != oa_model.InUse { return nil, errors.New(strings.Replace(e.ErrWorkingTimeNotInUse, "a", workingTimeListRes.Data[0].EffectiveDate, -1)) } return workingTimeListRes.Data[0], nil } func queryDepartmentNameAndPositionName(departmentUID, positionUID uint64) (departmentName, positionName string) { departmentDetailReq := new(department.DetailsRequest) departmentDetailReq.IDs = make([]uint64, 0) departmentDetailReq.IDs = append(departmentDetailReq.IDs, departmentUID) departmentDetailReq.Domain = "fontree" res, err := service.DepartmentProvider.Details(context.Background(), departmentDetailReq) if err != nil { return } for i := 0; i < len(res.Data); i++ { if res.Data[i].ID == departmentUID { departmentName = res.Data[i].Name for j := 0; j < len(res.Data[i].AllPositions); j++ { if res.Data[i].AllPositions[j].ID == int64(positionUID) { positionName = res.Data[i].AllPositions[j].Name break } } if positionName != "" { break } } } return departmentName, positionName } // 使用考勤组设置的 是否用于加班调休 func QueryCanDayOffUserWithWorkTimeTemplate(userInfo login.Info) (use bool, forMoney bool, err error) { canDayOff := false forMoney = false // 查询 考勤信息 workingTime, workingTimeErr := QueryWorkingTimeInUse(userInfo.PositionUsers, userInfo.ID) if workingTimeErr != nil { canDayOff = true return canDayOff, forMoney, workingTimeErr } logger.Infof("workingTime: %+v", workingTime) fmt.Printf("workingTime: %+v", workingTime) if len(workingTime.OaRules) > 0 { for i := 0; i < len(workingTime.OaRules); i++ { if workingTime.OaRules[i].Keyword == model.OvertimeRule && workingTime.OaRules[i].OvertimeRule != nil { if workingTime.OaRules[i].OvertimeRule.ForDayOff == model.ForDayOffYes { canDayOff = true } if workingTime.OaRules[i].OvertimeRule.ForDayOff == model.ForDayOffYes && (workingTime.OaRules[i].OvertimeRule.ForMoney == model.ForMoneyYes || workingTime.OaRules[i].OvertimeRule.ForMoney == model.ForMoneyYesDefaultZero) { forMoney = true } } } } return canDayOff, forMoney, nil }