| | |
| | | return |
| | | } |
| | | //获取月份天数 |
| | | location, err := time.ParseInLocation("2006-01", "2024-04", time.Local) |
| | | location, err := time.ParseInLocation("2006-01", params.Month, time.Local) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "月份格式错误") |
| | | return |
| | | } |
| | | year, month, _ := location.Date() |
| | | date := timex.GetDate(year, month) |
| | | weeks := timex.GetWeeksOfMonth(year, month) |
| | | |
| | | manages, err := models.NewAttendanceManageSearch().SetMonth(params.Month).SetPreload(true).FindNotTotal() |
| | | manages, err := models.NewAttendanceManageSearch().SetMonth(params.Month).SetKeyword(params.Keyword).SetPreload(true).FindNotTotal() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err) |
| | | return |
| | | } |
| | | weekMap := map[string]string{ |
| | | "Sunday": "周日", |
| | | "Monday": "周一", |
| | | "Tuesday": "周二", |
| | | "Wednesday": "周三", |
| | | "Thursday": "周四", |
| | | "Friday": "周五", |
| | | "Saturday": "周六", |
| | | } |
| | | |
| | | m := make(map[string]response.AttendanceStatistic) |
| | |
| | | as.Month = params.Month |
| | | as.WorkTypeId = manage.WorkTypeId |
| | | var details []response.AttendanceDetail |
| | | for i := 1; i <= date; i++ { |
| | | for _, week := range weeks { |
| | | for _, day := range week { |
| | | var ad response.AttendanceDetail |
| | | ad.Date = i |
| | | ad.Date = day.Day() |
| | | ad.WeekDay = weekMap[day.Weekday().String()] |
| | | ad.Status = constvar.Vacation |
| | | details = append(details, ad) |
| | | } |
| | | } |
| | | as.Details = details |
| | | } |
| | | as.WeekdayOverTime = as.WeekdayOverTime.Add(manage.OverTimeDuration) |
| | |
| | | |
| | | type GetAttendanceStatistic struct { |
| | | Month string `json:"month"` //月份 |
| | | Keyword string `json:"keyword"` |
| | | } |
| | | |
| | | type UpdateAttendance struct { |
| | |
| | | |
| | | type AttendanceDetail struct { |
| | | Date int `json:"date"` //日期 |
| | | WeekDay string `json:"weekDay"` //星期 |
| | | Status constvar.AttendanceStatus `json:"status"` //状态 |
| | | StartWorkTime string `json:"startWorkTime"` //上班打卡时间 |
| | | EndWorkTime string `json:"endWorkTime"` //下班打卡时间 |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | workers, total, err := models.NewWorkerSearch().SetPage(params.Page, params.PageSize).Find() |
| | | workers, total, err := models.NewWorkerSearch().SetPage(params.Page, params.PageSize).SetOrder("updated_at desc").Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | return |
| | |
| | | "request.GetAttendanceStatistic": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | |
| | | "$ref": "#/definitions/constvar.AttendanceStatus" |
| | | } |
| | | ] |
| | | }, |
| | | "weekDay": { |
| | | "description": "星期", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | |
| | | "request.GetAttendanceStatistic": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | |
| | | "$ref": "#/definitions/constvar.AttendanceStatus" |
| | | } |
| | | ] |
| | | }, |
| | | "weekDay": { |
| | | "description": "星期", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | |
| | | type: object |
| | | request.GetAttendanceStatistic: |
| | | properties: |
| | | keyword: |
| | | type: string |
| | | month: |
| | | description: 月份 |
| | | type: string |
| | |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.AttendanceStatus' |
| | | description: 状态 |
| | | weekDay: |
| | | description: 星期 |
| | | type: string |
| | | type: object |
| | | response.AttendanceList: |
| | | properties: |
| | |
| | | Preload bool |
| | | Ids []uint |
| | | Month string |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *AttendanceManageSearch) SetKeyword(keyword string) *AttendanceManageSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *AttendanceManageSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | |
| | | db = db.Where("worker_id = ?", slf.WorkerId) |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("worker_name like ? or worker_id like ?", "%"+slf.Keyword+"%", "%"+slf.Keyword+"%") |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | |
| | | } |
| | | return day |
| | | } |
| | | |
| | | // 获取一个月内的所有星期 |
| | | func GetWeeksOfMonth(year int, month time.Month) [][]time.Time { |
| | | firstDay := time.Date(year, month, 1, 0, 0, 0, 0, time.Local) |
| | | lastDay := firstDay.AddDate(0, 1, -1) // 下一个月的第一天减一,得到本月的最后一天 |
| | | |
| | | weeks := make([][]time.Time, 0) |
| | | currentWeek := make([]time.Time, 0) |
| | | current := firstDay |
| | | |
| | | for !current.After(lastDay) { |
| | | currentWeek = append(currentWeek, current) |
| | | current = current.AddDate(0, 0, 1) // 增加一天 |
| | | |
| | | // 如果当前周已经满了7天,或者已经到了月的最后一天,则保存这一周 |
| | | if len(currentWeek) == 7 || current.After(lastDay) { |
| | | weeks = append(weeks, currentWeek) |
| | | currentWeek = make([]time.Time, 0) // 重置当前周 |
| | | } |
| | | } |
| | | |
| | | return weeks |
| | | } |