From 73a3e853df1fe0605687fab00ba6e3009e975d62 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Fri, 1 Nov 2024 16:31:49 +0800 Subject: [PATCH] leavedate --- worker/staff.go | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/worker/staff.go b/worker/staff.go index a1b1524..7bfc31c 100644 --- a/worker/staff.go +++ b/worker/staff.go @@ -11,6 +11,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/smbrave/goutil" "github.com/spf13/cast" + "math" "strings" "time" ) @@ -217,22 +218,23 @@ func (s *Staff) SyncStaffSalary(month string) { holiday := float64(0) surplusHoliday := float64(0) for _, vac := range approveVacations { - startTime, _ := time.ParseInLocation(vac.VacationStartTime, "2006-01-02 15:04:05", time.Local) - endTime, _ := time.ParseInLocation(vac.VacationEndTime, "2006-01-02 15:04:05", time.Local) + startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationStartTime, time.Local) + endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationEndTime, time.Local) //同一天请假时长大于8小时算一天 if startTime.Format("2006-01-02") == endTime.Format("2006-01-02") && vac.VacationDuration > 1 { holiday += 1 } else { holiday += vac.VacationDuration + //不是整天数,把剩余的算上 + span := vac.VacationDuration - math.Floor(vac.VacationDuration) + surplusHoliday += goutil.If(math.Abs(span) < 0.000001, 0, 1-span) } - - surplusHoliday += goutil.If(vac.VacationDuration < 1, 1-vac.VacationDuration, 0) } // 打卡正常天数+补卡天数 为正常出勤天数 totalDays := s.getTotalWorkDay(staff.Username, month) - realWorkDays := s.getRealWorkDay(staff.EntryDate, staff.Username, month) + realWorkDays := s.getRealWorkDay(staff.EntryDate, staff.LeaveDate, staff.Username, month) approvalCheckinDay := s.getApprovalCheckinDay(staff.Username, month) extra := make(map[string]interface{}) salary.BaseSalary = cast.ToFloat64(staff.Salary) @@ -310,7 +312,7 @@ func (s *Staff) getApprovalCheckinDay(username, month string) int { return approvalDay } -func (s *Staff) getRealWorkDay(entryDate, username, month string) float64 { +func (s *Staff) getRealWorkDay(entryDate, leaveDate, username, month string) float64 { realWorkdays := float64(0) userCheckins, err := dao.NewCheckinDao().Query(username, month, false) if err != nil { @@ -318,12 +320,30 @@ func (s *Staff) getRealWorkDay(entryDate, username, month string) float64 { return realWorkdays } approvalCheckinDay := 0 + + //入职当天算工作日 + entryTime, _ := time.ParseInLocation("2006-01-02", entryDate, time.Local) + if entryTime.Format("200601") == month { + realWorkdays += 1 + } + + //离职当天算工作日 + leaveTime, _ := time.ParseInLocation("2006-01-02", leaveDate, time.Local) + if leaveTime.Format("200601") == month { + realWorkdays += 1 + } + for _, checkin := range userCheckins { if checkin.Exception == "" { realWorkdays += 1 continue } + //入职离职当天已经算过了 + if entryTime.Format("2006-01-02") == checkin.Day || leaveTime.Format("2006-01-02") == checkin.Day { + continue + } + //有补卡申请就直接算出勤 approvalCheckin, _ := dao.NewApprovalCheckinDao().GetByUsernameDay(username, checkin.Day) if approvalCheckin != nil { @@ -338,12 +358,6 @@ func (s *Staff) getRealWorkDay(entryDate, username, month string) float64 { continue } - //入职当天考勤异常忽略 - if checkin.Day == entryDate { - realWorkdays += 1 - continue - } - // 迟到的按时间折算 if strings.Contains(checkin.Exception, "上班打卡:时间异常") { stTime := time.Unix(checkin.StartTime, 0)