liujiandao
2024-04-25 634c7f5063b8977775be2a4a3584ce38ff055caa
考勤统计修改
9个文件已修改
78 ■■■■■ 已修改文件
controllers/attendance_controller.go 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/request/attendance_request.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/response/attendance_response.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/worker_controller.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/attendance_manage.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/timex/timex.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/attendance_controller.go
@@ -285,18 +285,27 @@
        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)
@@ -311,12 +320,15 @@
            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)
controllers/request/attendance_request.go
@@ -20,6 +20,7 @@
type GetAttendanceStatistic struct {
    Month string `json:"month"` //月份
    Keyword string `json:"keyword"`
}
type UpdateAttendance struct {
controllers/response/attendance_response.go
@@ -24,6 +24,7 @@
type AttendanceDetail struct {
    Date             int                       `json:"date"`             //日期
    WeekDay          string                    `json:"weekDay"`          //星期
    Status           constvar.AttendanceStatus `json:"status"`           //状态
    StartWorkTime    string                    `json:"startWorkTime"`    //上班打卡时间
    EndWorkTime      string                    `json:"endWorkTime"`      //下班打卡时间
controllers/worker_controller.go
@@ -101,7 +101,7 @@
        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
docs/docs.go
@@ -3551,6 +3551,9 @@
        "request.GetAttendanceStatistic": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "month": {
                    "description": "月份",
                    "type": "string"
@@ -4161,6 +4164,10 @@
                            "$ref": "#/definitions/constvar.AttendanceStatus"
                        }
                    ]
                },
                "weekDay": {
                    "description": "星期",
                    "type": "string"
                }
            }
        },
docs/swagger.json
@@ -3539,6 +3539,9 @@
        "request.GetAttendanceStatistic": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "month": {
                    "description": "月份",
                    "type": "string"
@@ -4149,6 +4152,10 @@
                            "$ref": "#/definitions/constvar.AttendanceStatus"
                        }
                    ]
                },
                "weekDay": {
                    "description": "星期",
                    "type": "string"
                }
            }
        },
docs/swagger.yaml
@@ -901,6 +901,8 @@
    type: object
  request.GetAttendanceStatistic:
    properties:
      keyword:
        type: string
      month:
        description: 月份
        type: string
@@ -1329,6 +1331,9 @@
        allOf:
        - $ref: '#/definitions/constvar.AttendanceStatus'
        description: 状态
      weekDay:
        description: 星期
        type: string
    type: object
  response.AttendanceList:
    properties:
models/attendance_manage.go
@@ -34,6 +34,7 @@
        Preload  bool
        Ids      []uint
        Month    string
        Keyword  string
        Orm      *gorm.DB
    }
)
@@ -81,6 +82,11 @@
    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())
@@ -104,6 +110,10 @@
        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
}
pkg/timex/timex.go
@@ -75,3 +75,26 @@
    }
    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
}