package oa_logic import ( "context" "dubbo.apache.org/dubbo-go/v3/common/logger" "encoding/json" "errors" "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/oa_model" "github.com/fonchain_enterprise/fonchain-main/pkg/service" "github.com/fonchain_enterprise/fonchain-main/pkg/service/oa_new/common" "github.com/fonchain_enterprise/fonchain-main/pkg/service/oa_new/model" "io/ioutil" "net/http" "strconv" "strings" "time" ) func CheckActionType(req *model.ClockInReq, workingTime *oa.WorkingTime, currentTime *time.Time, in bool) (res *model.ActionTypeRes, err error) { res = new(model.ActionTypeRes) // 判断 打卡时间是否在工作时间内 workDay, isWorkDayErr := IsWorkDay(common.CheckIsBeforeFour(), workingTime.Week, workingTime.IsWorkDay) if isWorkDayErr != nil { return nil, isWorkDayErr } fmt.Println("====================================================================================================") fmt.Printf("workDay: %v\n", workDay) if workDay { fmt.Println("==================================== workDay enter ================================================================") // 工作日 res.IsWorkDay = model.IsWork // 查询 打卡记录 查询的日期 根据 当前时间是否在 凌晨 四点之前 四点之前 则 属于 前一天 否则 属于 当天 var checkActionTimeWorkDayErr error res.ActionType, res.WorkTime, res.OnOff, checkActionTimeWorkDayErr = checkActionTimeWorkDay(req.StaffUID, common.CheckIsBeforeFour(), workingTime, currentTime) if checkActionTimeWorkDayErr != nil { fmt.Printf("checkActionTimeWorkDay checkActionTimeWorkDayErr: %v\n", checkActionTimeWorkDayErr) return nil, checkActionTimeWorkDayErr } fmt.Printf("checkActionTimeWorkDay before CheckActionType res: %v\n", res) // 查询 外勤申请 outWork, checkApplyTypeWorkDayErr := checkOutWorkApplyTypeWorkDay(req, workingTime, res, currentTime, in) if checkApplyTypeWorkDayErr != nil { fmt.Printf("checkOutWorkApplyTypeWorkDay checkApplyTypeWorkDayErr: %v\n", checkApplyTypeWorkDayErr) return nil, checkApplyTypeWorkDayErr } fmt.Printf("checkOutWorkApplyTypeWorkDay before CheckActionType res: %v\n", res) if in { fmt.Printf("CheckActionType res: %v\n", res) fmt.Println("==================================== workDay out ================================================================") return } else if !in && workingTime.AllowOutWork == e.AllowOutWork { if res.ActionType == model.ActionTypeBefore { res.ActionType = model.ActionTypeOutWorkBefore } else if res.ActionType == model.ActionTypeLate { res.ActionType = model.ActionTypeOutWorkLate } else if res.ActionType == model.ActionTypeCommon { res.ActionType = model.ActionTypeOutWork } fmt.Printf("CheckActionType res: %v\n", res) fmt.Println("==================================== workDay out ================================================================") return } else if !in && outWork { if res.ActionType == model.ActionTypeBefore { res.ActionType = model.ActionTypeOutWorkBefore } else if res.ActionType == model.ActionTypeLate { res.ActionType = model.ActionTypeOutWorkLate } else if res.ActionType == model.ActionTypeCommon { res.ActionType = model.ActionTypeOutWork } fmt.Printf("CheckActionType res: %v\n", res) fmt.Println("==================================== workDay out ================================================================") return } else { if res.ActionType != model.ActionTypeOutWork { res.ActionType = model.ActionTypeNoClock } fmt.Printf("CheckActionType res: %v\n", res) fmt.Println("==================================== workDay out ================================================================") return } } else { fmt.Println("==================================== notWorkDay enter ================================================================") // 非工作 只允许 在 打卡范围内 打卡 res.IsWorkDay = model.IsFree var checkActionTimeNotWorkDayErr error res.ActionType, res.WorkTime, res.OnOff, checkActionTimeNotWorkDayErr = checkActionTimeNotWorkDay(req.StaffUID, common.CheckIsBeforeFour()) if in { fmt.Printf("CheckActionType res: %v\n", res) fmt.Println("==================================== notWorkDay out ================================================================") return res, checkActionTimeNotWorkDayErr } else if !in && workingTime.AllowOutWork == e.AllowOutWork { if res.ActionType == model.ActionTypeBefore { res.ActionType = model.ActionTypeOutWorkBefore } else if res.ActionType == model.ActionTypeLate { res.ActionType = model.ActionTypeOutWorkLate } else if res.ActionType == model.ActionTypeCommon { res.ActionType = model.ActionTypeOutWork } fmt.Printf("CheckActionType res: %v\n", res) fmt.Println("==================================== notWorkDay out ================================================================") return } else { res.ActionType = model.ActionTypeNoClock fmt.Printf("CheckActionType res: %v\n", res) fmt.Println("==================================== notWorkDay out ================================================================") return res, nil } } } func checkOutWorkApplyTypeWorkDay(req *model.ClockInReq, workingTime *oa.WorkingTime, res *model.ActionTypeRes, currentTime *time.Time, in bool) (outWork bool, err error) { fmt.Println("============================================ checkOutWorkApplyTypeWorkDay =====================================") fmt.Printf("actionType: %v\n", res.ActionType) fmt.Printf("workTime: %v\n", res.WorkTime) fmt.Printf("onOff: %v\n", res.OnOff) fmt.Println("============================================ checkOutWorkApplyTypeWorkDay =====================================") // 查询 外勤申请 outWorkApply, outWorkErr := QueryOaApplyDates(req.StaffUID, []string{common.CheckIsBeforeFour()}, []int32{e.ApprovalWorkStatusDoing, e.ApprovalWorkStatusOk}, []string{oa_model.TypeOutWork}) if outWorkErr != nil { return false, outWorkErr } if len(outWorkApply) == 0 { return false, nil } //for i := 0; i < len(outWorkApply); i++ { // // 查询 外出 回归 记录 // outWorkCheck, outWorkCheckErr := QueryOutWorkCheck(req.StaffUID, outWorkApply[i].ApprovalID) // if outWorkCheckErr != nil { // return outWorkCheckErr // } // // // 有了 外出 和 回来 卡 后 就不需要再打了 // if len(outWorkCheck) == 2 { // break // } // // // 情况一: 没有 外出卡 此时 需要判定 是否需要打 外出 // // 情况二: 有 外出卡 此时 需要判定 是否需要打 回来 // var nextOutOrBack string // // // 判断 是 打 外出 还是 回归 卡 // if len(outWorkCheck) == 1 && outWorkCheck[0].ActionType == model.ActionTypeOut { // // 打了 外出卡 下一次 应该 打 回来 卡 // nextOutOrBack = model.ActionTypeBack // } else { // nextOutOrBack = model.ActionTypeOut // } // // // 如果 外勤申请的 开始时间 在 上班卡之前 结束时间 在 下班卡之后 则不需要 打 外出和 回来的卡 // checkOutWorkApplyTimeErr := checkOutWork(outWorkApply[i], nextOutOrBack, workingTime, res, currentTime, in) // if checkOutWorkApplyTimeErr != nil { // return checkOutWorkApplyTimeErr // } // //} return true, nil } // 判断 外勤申请的 时间点 在 打卡时间范围内的 则需要 打 外出 和 回来 卡 否则 不需要 func checkOutWork(outWorkApply *oa.OAApply, nextOutOrBack string, workingTime *oa.WorkingTime, res *model.ActionTypeRes, currentTime *time.Time, in bool) (err error) { applyTimes := outWorkApply.ApplyTimes // 外勤的 开始时间 和 结束时间 applyStartTime := common.ConvertApplyTimeToTime(applyTimes[0].Date, applyTimes[0].Hour) applyEndTime := common.ConvertApplyTimeToTime(applyTimes[1].Date, applyTimes[1].Hour) // 考勤的 开始时间 和 结束时间(无论 几班次 都是 最后一班次的 下班时间) workStartTime := common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), workingTime.Time[0].OnWorkTime) workEndTime := common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), workingTime.Time[len(workingTime.Time)-1].OffWorkTime) // 情况一 : 外勤开始时间 和 结束时间 在 考勤时间之外 则 无需 打 外出 以及 回来的卡 if !applyStartTime.After(workStartTime) && !applyEndTime.Before(workEndTime) && !in { res.OutWorkAddress = outWorkApply.OutWorkAddress res.ActionType = model.ActionTypeOutWork return } // 迟到 需要 先打 迟到卡 且 当前时间 在 外勤申请时间之前 且 是 打 外出 卡 之前 currentWorkTime := common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), res.WorkTime) if res.ActionType == model.ActionTypeLate && currentWorkTime.Before(applyStartTime) { return } // 找到 外勤申请的时间点 在 考勤时间点的哪个时间段 // applyWorkStartTime 有值 代表 有 out 卡 , 无值 代表 没有 out 卡, applyWorkEndTime 有值 代表 有 back 卡 , 无值 代表 没有 back 卡 // var applyWorkStartTime, applyWorkEndTime string for j := 0; j < len(workingTime.Time); j++ { times := workingTime.Time[j] if applyStartTime.After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OnWorkTime)) && applyStartTime.Before(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OffWorkTime)) { if currentTime.After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OnWorkTime)) && currentTime.Before(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OffWorkTime)) { if nextOutOrBack == model.ActionTypeOut { res.ActionType = model.ActionTypeOut res.OutWorkAddress = outWorkApply.OutWorkAddress return } } } if applyEndTime.After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OnWorkTime)) && applyEndTime.Before(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OffWorkTime)) { if currentTime.After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OnWorkTime)) && currentTime.Before(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OffWorkTime)) { if nextOutOrBack == model.ActionTypeOut { res.ActionType = model.ActionTypeOut res.OutWorkAddress = outWorkApply.OutWorkAddress return } else if nextOutOrBack == model.ActionTypeBack { res.ActionType = model.ActionTypeBack res.OutWorkAddress = outWorkApply.OutWorkAddress return } } } } return } // checkActionTimeWorkDay 判断 工作日的 打卡信息 func checkActionTimeWorkDay(staffUID uint64, date string, workingTime *oa.WorkingTime, currentTime *time.Time) (actionType, workTime, onOff string, err error) { // 查询 打卡记录 oaRecordReq := new(oa.OARecordReq) oaRecordReq.StaffUID = staffUID oaRecordReq.Dates = append(oaRecordReq.Dates, date) oaRecord, oaRecordErr := service.GrpcOAImpl.OARecord(context.Background(), oaRecordReq) if oaRecordErr != nil { logger.Errorf("查询考勤记录失败:%s", oaRecordErr.Error()) fmt.Printf("查询考勤记录失败:%s", oaRecordErr.Error()) return "", "", "", errors.New(e.ErrorQueryOaProfile) } if oaRecord == nil || len(oaRecord.Data) == 0 || oaRecord.Data[0].Records == nil || len(oaRecord.Data[0].Records) == 0 { // 无打卡记录 时 返回的是 考勤的第一班卡 actionType, workTime, onOff, err = withoutOaRecordWorkDay(workingTime, currentTime) } else { fmt.Println("========================================= oaRecord =======================================================") fmt.Printf("oaRecord %+v\n", oaRecord.Data) fmt.Println("========================================= oaRecord =======================================================") // 有打卡记录 时 返回的 需要根据 实际 打卡点 以及 考勤时间点 来确认 actionType, workTime, onOff, err = withOaRecordWorkDay(oaRecord.Data[len(oaRecord.Data)-1], workingTime, currentTime) } return } // checkActionTimeNotWorkDay 判断 非工作日的 打卡信息 func checkActionTimeNotWorkDay(staffUID uint64, date string) (actionType, workTime, onOff string, err error) { // 查询 打卡记录 oaRecordReq := new(oa.OARecordReq) oaRecordReq.StaffUID = staffUID oaRecordReq.Dates = append(oaRecordReq.Dates, date) oaRecord, oaRecordErr := service.GrpcOAImpl.OARecord(context.Background(), oaRecordReq) if oaRecordErr != nil { logger.Errorf("查询考勤记录失败:%s", oaRecordErr.Error()) fmt.Printf("查询考勤记录失败:%s", oaRecordErr.Error()) return "", "", "", errors.New(e.ErrorQueryOaProfile) } if oaRecord == nil || len(oaRecord.Data) == 0 || oaRecord.Data[0].Records == nil { // 无打卡记录 时 返回的是 开始班次 为 凌晨 04:00 on return withoutOaRecordNotWorkDay() } else { // 有打卡记录 时 返回的是 结束班次 为 次日凌晨 04:00 off return withOaRecordNotWorkDay(oaRecord.Data[0].WorkDate) } } // withoutOaRecordWorkDay 工作日 无打卡记录 func withoutOaRecordWorkDay(workingTime *oa.WorkingTime, currentTime *time.Time) (actionType, workTime, onOff string, err error) { fmt.Println("==================================== withoutOaRecordWorkDay enter ================================================================") // 判断 当前打卡点 for i := 0; i < len(workingTime.Time); i++ { times := workingTime.Time[i] fmt.Printf("times: %v\n", times) // 判断是否在上班时间 之前 if currentTime.Before(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OnWorkTime)) && (i == 0 && currentTime.After(common.ConvertWorkDateToTimeFour(common.CurrentDateStr()))) { actionType = common.TypeCommon workTime = times.OnWorkTime onOff = model.OnWork return } // 如果是 只有一班次 或者 已循环到 最后一个班次 if (len(workingTime.Time) == 1 || i == len(workingTime.Time)-1) && currentTime.Add(1*time.Minute).After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OffWorkTime)) && currentTime.Before(common.ConvertWorkDateToTimeFour(common.NextDate())) { // 在下班时间 之后 次日四点之前 则为 当前班次的 下班 正常 actionType = common.TypeCommon workTime = times.OffWorkTime onOff = model.OffWork return } // 判断是否在上班时间 下班时间 之间 if currentTime.After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OnWorkTime)) && currentTime.Add(1*time.Minute).Before(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OffWorkTime)) { // 判断是否在上 和 下班时间 之间 actionType = common.TypeLate workTime = times.OnWorkTime onOff = model.OnWork return } // 判断是否在上班时间 之前 多班次情况 if i > 0 && currentTime.Add(1*time.Minute).After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), workingTime.Time[i-1].OffWorkTime)) && currentTime.Before(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OnWorkTime)) { // 在 上一班次 的 下班卡 之后 当前班次的 上班卡之前 则为 上个班次的 下班 正常 actionType = common.TypeCommon workTime = workingTime.Time[i-1].OffWorkTime onOff = model.OffWork return } } if actionType == "" || workTime == "" || onOff == "" { return "", "", "", errors.New(e.ErrorCheckWorkTime) } return } // withOaRecordWorkDay 工作日 有打卡记录 func withOaRecordWorkDay(oaRecord *oa.OARecord, workingTime *oa.WorkingTime, currentTime *time.Time) (actionType, workTime, onOff string, err error) { // 判断 当前打卡点 lastClockInTime := oaRecord.Records[len(oaRecord.Records)-1].WorkTime lastOnOff := oaRecord.Records[len(oaRecord.Records)-1].OnOff lastActionType := oaRecord.Records[len(oaRecord.Records)-1].ActionType fmt.Println("============================================ findNextClockInTime =====================================") fmt.Printf("lastClockInTime: %v\n", lastClockInTime) fmt.Printf("lastOnOff: %v\n", lastOnOff) fmt.Printf("lastActionType: %v\n", lastActionType) fmt.Println("============================================ findNextClockInTime =====================================") // 不是最后一班的 下班卡 且 打卡类型为 早退的 不可进行下一班次的打卡 if lastClockInTime != workingTime.Time[len(workingTime.Time)-1].OffWorkTime && lastActionType == model.ActionTypeBefore && !currentTime.After(common.ConvertWorkDateAndWorkTime(common.CurrentDateStr(), lastClockInTime)) { actionType = lastActionType workTime = lastClockInTime onOff = lastOnOff return } if lastClockInTime == workingTime.Time[len(workingTime.Time)-1].OffWorkTime && lastActionType == model.ActionTypeBefore { actionType = lastActionType workTime = lastClockInTime onOff = lastOnOff return } for i := 0; i < len(workingTime.Time); i++ { times := workingTime.Time[i] // 判断是否在上班时间 之前 第一班卡 if i == 0 && currentTime.Before(common.ConvertWorkDateAndWorkTime(oaRecord.WorkDate, times.OnWorkTime)) && currentTime.Add(1*time.Minute).After(common.ConvertWorkDateToTimeFour(oaRecord.WorkDate)) { if lastClockInTime == times.OnWorkTime { actionType = common.TypeBefore workTime = times.OffWorkTime onOff = model.OffWork return } else { actionType = common.TypeCommon workTime = times.OnWorkTime onOff = model.OnWork return } } // 判断是否在上班时间 下班时间 之间 if currentTime.After(common.ConvertWorkDateAndWorkTime(oaRecord.WorkDate, times.OnWorkTime)) && currentTime.Add(1*time.Minute).Before(common.ConvertWorkDateAndWorkTime(oaRecord.WorkDate, times.OffWorkTime)) { if lastClockInTime == times.OffWorkTime || lastClockInTime == times.OnWorkTime { actionType = common.TypeBefore workTime = times.OffWorkTime onOff = model.OffWork return } else { actionType = common.TypeLate workTime = times.OnWorkTime onOff = model.OnWork return } } // 判断是否在上班时间 之前 多班次情况 if i > 0 && currentTime.Add(1*time.Minute).After(common.ConvertWorkDateAndWorkTime(oaRecord.WorkDate, workingTime.Time[i-1].OffWorkTime)) && currentTime.Before(common.ConvertWorkDateAndWorkTime(oaRecord.WorkDate, times.OnWorkTime)) { if lastClockInTime == times.OnWorkTime { // 最后一次打卡记录 是 当前班次的 上班卡 接下来 应该 打当前班次的 下班 且 类型 早退 actionType = common.TypeBefore workTime = times.OffWorkTime onOff = model.OffWork return } else if lastClockInTime == workingTime.Time[i-1].OffWorkTime { // 最后一次打卡记录 是 上一个班次的 下班卡 接下来 应该 打当前班次的 上班 且 类型 正常 actionType = common.TypeCommon workTime = times.OnWorkTime onOff = model.OnWork return } else { // 最后一次打卡记录 是 上一个班次的 上班卡 接下来 应该 打上一个班次的 下班 且 类型 正常 actionType = common.TypeCommon workTime = workingTime.Time[i-1].OffWorkTime onOff = model.OffWork return } } if (len(workingTime.Time) == 1 || i == len(workingTime.Time)-1) && currentTime.Add(1*time.Minute).After(common.ConvertWorkDateAndWorkTime(common.CheckIsBeforeFour(), times.OffWorkTime)) && currentTime.Before(common.ConvertWorkDateToTimeFour(common.NextDate())) { // 判断是否在下班时间 之后 actionType = common.TypeCommon workTime = times.OffWorkTime onOff = model.OffWork return } } fmt.Println("============================================ withOaRecordWorkDay =====================================") fmt.Printf("actionType: %v\n", actionType) fmt.Printf("workTime: %v\n", workTime) fmt.Printf("onOff: %v\n", onOff) fmt.Println("============================================ withOaRecordWorkDay =====================================") return } // withoutOaRecordNotWorkDay 非工作日 无打卡记录 func withoutOaRecordNotWorkDay() (actionType, workTime, onOff string, err error) { actionType = oa_model.TypeCommon workTime = common.NotWorkDayWorkTimeOn() onOff = model.OnWork return } // withoutOaRecordNotWorkDay 非工作日 有打卡记录 func withOaRecordNotWorkDay(date string) (actionType, workTime, onOff string, err error) { actionType = oa_model.TypeCommon //if common.CurrentDateTime().After(common.ConvertWorkDateAndWorkTime(date, common.NotWorkDayWorkTimeOff())) { // workTime = common.NotWorkDayWorkTimeOff() //} else { // workTime = common.CurrentDateTime().Format(common.HHmm) //} workTime = common.NotWorkDayWorkTimeOff() onOff = model.OffWork return } // 寻找下一个打卡点 func findNextClockInTime(oaRecord *oa.OARecord, workingTime *oa.WorkingTime, currentTime *time.Time) (nextClockInTime, nextOnOff string, err error) { lastClockInTime := oaRecord.Records[len(oaRecord.Records)-1].WorkTime lastOnOff := oaRecord.Records[len(oaRecord.Records)-1].OnOff lastActionType := oaRecord.Records[len(oaRecord.Records)-1].ActionType fmt.Println("============================================ findNextClockInTime =====================================") fmt.Printf("lastClockInTime: %v\n", lastClockInTime) fmt.Printf("lastOnOff: %v\n", lastOnOff) fmt.Println("============================================ findNextClockInTime =====================================") // 不是最后一班的 下班卡 且 打卡类型为 早退的 不可进行下一班次的打卡 if lastClockInTime != workingTime.Time[len(workingTime.Time)-1].OffWorkTime && lastActionType == model.ActionTypeBefore && !currentTime.After(common.ConvertWorkDateAndWorkTime(common.CurrentDateStr(), lastClockInTime)) { return lastClockInTime, lastOnOff, nil } for i := 0; i < len(workingTime.Time); i++ { times := workingTime.Time[i] if i == len(workingTime.Time)-1 && lastClockInTime == times.OffWorkTime { nextClockInTime = times.OffWorkTime nextOnOff = model.OffWork break } if i < len(workingTime.Time)-1 && lastClockInTime == times.OnWorkTime { nextClockInTime = times.OffWorkTime nextOnOff = model.OffWork break } if i < len(workingTime.Time)-1 && lastClockInTime == times.OffWorkTime { nextClockInTime = workingTime.Time[i+1].OnWorkTime nextOnOff = model.OnWork break } } fmt.Println("============================================ findNextClockInTime =====================================") fmt.Printf("nextClockInTime: %v\n", nextClockInTime) fmt.Printf("nextOnOff: %v\n", nextOnOff) fmt.Println("============================================ findNextClockInTime =====================================") if nextClockInTime == "" || nextOnOff == "" { return "", "", errors.New(e.ErrorCheckNextClockInTime) } return } // IsWorkDay 判断 是否是工作日 func IsWorkDay(date string, week string, isWorkDay int32) (isWorkTime bool, err error) { // 查询是否是工作日 holidaysMap, holidaysMapErr := HolidayList([]string{date}) if holidaysMapErr != nil { fmt.Printf("查询是否是工作日:%s", holidaysMapErr.Error()) return false, holidaysMapErr } if holidaysMap[date] == nil { return false, errors.New(e.ErrorQueryHoliday) } dayType := holidaysMap[date].Type if week != "" { fmt.Println("============================ week is not null =======================================") currentDay := int(holidaysMap[date].WeekDay) weeks := strings.Split(week, ",") start, _ := strconv.Atoi(weeks[0]) end, _ := strconv.Atoi(weeks[len(weeks)-1]) fmt.Printf("week: %v\n", week) fmt.Printf("currentDay: %v, start: %v, end: %v\n", currentDay, start, end) if end >= start && currentDay >= start && currentDay <= end { if dayType != model.HolidayDayType { return true, nil } else { return false, nil } } else if start > end && (currentDay >= end || currentDay <= start) { if dayType != model.HolidayDayType { return true, nil } else { return false, nil } } else if currentDay == 7 || currentDay == 6 { if dayType == model.WorkDayType { return true, nil } else { return false, nil } } else { return false, nil } } else if isWorkDay == model.IsWorkDay { if dayType == model.WorkDayType { return true, nil } else { return false, nil } } return false, nil } func ReverseGeo(longitude, latitude string) (address string) { var reverseGeocodingReq service.ReverseGeocodingReq reverseGeocodingReq.Ak = "3bAjKGA0pv7qvszGe98RsVZ04Ob5r4ZZ" reverseGeocodingReq.Coordtype = "gcj02ll" reverseGeocodingReq.Output = "json" reverseGeocodingReq.RetCoordtype = "gcj02ll" reverseGeocodingReq.Location = strings.Join([]string{latitude, longitude}, ",") url := "https://api.map.baidu.com/reverse_geocoding/v3/?ak=" + reverseGeocodingReq.Ak + "&output=" + reverseGeocodingReq.Output + "&coordtype=" + reverseGeocodingReq.Coordtype + "&location=" + reverseGeocodingReq.Location + "&ret_coordtype=" + reverseGeocodingReq.RetCoordtype resp, err := http.Get(url) if err != nil { logger.Errorf("通过API获取地址失败:%s", err.Error()) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { logger.Errorf("读取返回结果失败:%s", err.Error()) return } var results service.ReverseGeocodingRes err = json.Unmarshal(body, &results) if err != nil { logger.Errorf("反序列化失败:%s", err.Error()) return } if results.Status != 0 { logger.Errorf("通过API获取地址失败:%s", err.Error()) return } address = results.Result.FormattedAddress return address }