liujiandao
2024-04-22 20af882d5a8b59f4c4a5645fd2e4fd4a244609f2
考勤统计
1个文件已添加
8个文件已修改
786 ■■■■■ 已修改文件
controllers/attendance_controller.go 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/request/attendance_request.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/response/attendance_response.go 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/worker_controller.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 258 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 258 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 171 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/attendance_manage.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/attendance_controller.go
@@ -6,12 +6,14 @@
    "github.com/xuri/excelize/v2"
    "silkserver/constvar"
    "silkserver/controllers/request"
    "silkserver/controllers/response"
    "silkserver/extend/code"
    "silkserver/extend/util"
    "silkserver/middleware"
    "silkserver/models"
    "silkserver/pkg/logx"
    "silkserver/pkg/timex"
    "strings"
    "time"
)
@@ -185,6 +187,59 @@
    util.ResponseFormatList(c, code.Success, manages, total)
}
// GetAttendanceStatistic
//
//    @Tags        考勤管理
//    @Summary    获取考勤统计
//    @Produce    application/json
//    @Param        object    body        request.GetAttendanceStatistic    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.Response{data=response.AttendanceList}        "成功"
//    @Router        /api-jl/v1/attendance/getAttendanceStatistic [post]
func (slf AttendanceController) GetAttendanceStatistic(c *gin.Context) {
    var params request.GetAttendanceStatistic
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.Month == "" {
        util.ResponseFormat(c, code.RequestParamError, "参数不能为空")
        return
    }
    manages, err := models.NewAttendanceManageSearch().SetMonth(params.Month).SetPreload(true).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, err)
        return
    }
    m := make(map[string]response.AttendanceStatistic)
    for _, manage := range manages {
        var as response.AttendanceStatistic
        if _, ok := m[manage.WorkerId]; ok {
            as = m[manage.WorkerId]
        } else {
            as.WorkerId = manage.WorkerId
            as.WorkerName = manage.WorkerName
            as.WorkType = manage.WorkType.WorkName
            as.Month = params.Month
        }
        as.WeekdayOverTime = as.WeekdayOverTime.Add(manage.OverTimeDuration)
        as.ActualAttendanceDays = as.ActualAttendanceDays + 1
        var ad response.AttendanceDetail
        ad.Date = strings.ReplaceAll(manage.Date, params.Month+"-", "")
        ad.Status = manage.Status
        as.Details = append(as.Details, ad)
        m[manage.WorkerId] = as
    }
    var list response.AttendanceList
    for _, statistic := range m {
        list.List = append(list.List, statistic)
    }
    util.ResponseFormat(c, code.Success, list)
}
// DeleteAttendanceInfo
//
//    @Tags        考勤管理
controllers/request/attendance_request.go
@@ -8,3 +8,7 @@
type DeleteAttendanceInfo struct {
    Ids []uint `json:"ids"` //记录id
}
type GetAttendanceStatistic struct {
    Month string `json:"month"` //月份
}
controllers/response/attendance_response.go
New file
@@ -0,0 +1,27 @@
package response
import (
    "github.com/shopspring/decimal"
    "silkserver/constvar"
)
type AttendanceList struct {
    List []AttendanceStatistic `json:"list"`
}
type AttendanceStatistic struct {
    WorkerId               string             `json:"workerId"`               //人员id
    WorkerName             string             `json:"workerName"`             //人员姓名
    WorkType               string             `json:"workType"`               //工种
    Month                  string             `json:"month"`                  //月份
    WeekdayOverTime        decimal.Decimal    `json:"weekdayOverTime"`        //工作日加班时长
    RestDayOverTime        decimal.Decimal    `json:"restDayOverTime"`        //休息日加班时长
    RequiredAttendanceDays int                `json:"requiredAttendanceDays"` //应出勤天数
    ActualAttendanceDays   int                `json:"actualAttendanceDays"`   //实际出勤天数
    Details                []AttendanceDetail `json:"details"`                //详情
}
type AttendanceDetail struct {
    Date   string                    `json:"date"`   //日期
    Status constvar.AttendanceStatus `json:"status"` //状态
}
controllers/worker_controller.go
@@ -77,7 +77,7 @@
        util.ResponseFormat(c, code.RequestParamError, "名称为空")
        return
    }
    err = models.NewWorkerSearch().Create(&params)
    err = models.NewWorkerSearch().Save(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "更新失败")
        return
docs/docs.go
@@ -124,6 +124,120 @@
                }
            }
        },
        "/api-jl/v1/attendance/getAttendanceRule": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "考勤管理"
                ],
                "summary": "获取加班规则",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-jl/v1/attendance/getAttendanceStatistic": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "考勤管理"
                ],
                "summary": "获取考勤统计",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetAttendanceStatistic"
                        }
                    },
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.AttendanceList"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-jl/v1/attendance/saveAttendanceRule": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "考勤管理"
                ],
                "summary": "保存加班规则",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.AttendanceRule"
                        }
                    },
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-jl/v1/fineness/changeYieldRegister": {
            "post": {
                "produces": [
@@ -2079,6 +2193,27 @@
        }
    },
    "definitions": {
        "constvar.AttendanceStatus": {
            "type": "integer",
            "enum": [
                1,
                2,
                3,
                4
            ],
            "x-enum-comments": {
                "Abnormal": "异常",
                "Normal": "正常",
                "Overtime": "加班",
                "Vacation": "休假"
            },
            "x-enum-varnames": [
                "Normal",
                "Overtime",
                "Vacation",
                "Abnormal"
            ]
        },
        "constvar.CarFlag": {
            "type": "integer",
            "enum": [
@@ -2241,17 +2376,58 @@
                "id": {
                    "type": "integer"
                },
                "overTimeDuration": {
                    "type": "number"
                },
                "startWorkTime": {
                    "type": "string"
                },
                "status": {
                    "$ref": "#/definitions/constvar.AttendanceStatus"
                },
                "updatedAt": {
                    "type": "string"
                },
                "workType": {
                    "$ref": "#/definitions/models.WorkTypeManage"
                },
                "workTypeId": {
                    "type": "integer"
                },
                "workerId": {
                    "type": "string"
                },
                "workerName": {
                    "type": "string"
                }
            }
        },
        "models.AttendanceRule": {
            "type": "object",
            "properties": {
                "createdAt": {
                    "type": "string"
                },
                "deletedAt": {
                    "$ref": "#/definitions/gorm.DeletedAt"
                },
                "id": {
                    "type": "integer"
                },
                "overTimeStart": {
                    "type": "number"
                },
                "restDayRule": {
                    "type": "integer"
                },
                "restDayStart": {
                    "type": "number"
                },
                "updatedAt": {
                    "type": "string"
                },
                "weekdayRule": {
                    "type": "integer"
                }
            }
        },
@@ -3219,6 +3395,7 @@
            "type": "object",
            "properties": {
                "ids": {
                    "description": "记录id",
                    "type": "array",
                    "items": {
                        "type": "integer"
@@ -3277,6 +3454,15 @@
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                }
            }
        },
        "request.GetAttendanceStatistic": {
            "type": "object",
            "properties": {
                "month": {
                    "description": "月份",
                    "type": "string"
                }
            }
        },
@@ -3784,6 +3970,78 @@
                }
            }
        },
        "response.AttendanceDetail": {
            "type": "object",
            "properties": {
                "date": {
                    "description": "日期",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.AttendanceStatus"
                        }
                    ]
                }
            }
        },
        "response.AttendanceList": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/response.AttendanceStatistic"
                    }
                }
            }
        },
        "response.AttendanceStatistic": {
            "type": "object",
            "properties": {
                "actualAttendanceDays": {
                    "description": "实际出勤天数",
                    "type": "integer"
                },
                "details": {
                    "description": "详情",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/response.AttendanceDetail"
                    }
                },
                "month": {
                    "description": "月份",
                    "type": "string"
                },
                "requiredAttendanceDays": {
                    "description": "应出勤天数",
                    "type": "integer"
                },
                "restDayOverTime": {
                    "description": "休息日加班时长",
                    "type": "number"
                },
                "weekdayOverTime": {
                    "description": "工作日加班时长",
                    "type": "number"
                },
                "workType": {
                    "description": "工种",
                    "type": "string"
                },
                "workerId": {
                    "description": "人员id",
                    "type": "string"
                },
                "workerName": {
                    "description": "人员姓名",
                    "type": "string"
                }
            }
        },
        "response.CarAndLevel": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -112,6 +112,120 @@
                }
            }
        },
        "/api-jl/v1/attendance/getAttendanceRule": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "考勤管理"
                ],
                "summary": "获取加班规则",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-jl/v1/attendance/getAttendanceStatistic": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "考勤管理"
                ],
                "summary": "获取考勤统计",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetAttendanceStatistic"
                        }
                    },
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.AttendanceList"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-jl/v1/attendance/saveAttendanceRule": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "考勤管理"
                ],
                "summary": "保存加班规则",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.AttendanceRule"
                        }
                    },
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-jl/v1/fineness/changeYieldRegister": {
            "post": {
                "produces": [
@@ -2067,6 +2181,27 @@
        }
    },
    "definitions": {
        "constvar.AttendanceStatus": {
            "type": "integer",
            "enum": [
                1,
                2,
                3,
                4
            ],
            "x-enum-comments": {
                "Abnormal": "异常",
                "Normal": "正常",
                "Overtime": "加班",
                "Vacation": "休假"
            },
            "x-enum-varnames": [
                "Normal",
                "Overtime",
                "Vacation",
                "Abnormal"
            ]
        },
        "constvar.CarFlag": {
            "type": "integer",
            "enum": [
@@ -2229,17 +2364,58 @@
                "id": {
                    "type": "integer"
                },
                "overTimeDuration": {
                    "type": "number"
                },
                "startWorkTime": {
                    "type": "string"
                },
                "status": {
                    "$ref": "#/definitions/constvar.AttendanceStatus"
                },
                "updatedAt": {
                    "type": "string"
                },
                "workType": {
                    "$ref": "#/definitions/models.WorkTypeManage"
                },
                "workTypeId": {
                    "type": "integer"
                },
                "workerId": {
                    "type": "string"
                },
                "workerName": {
                    "type": "string"
                }
            }
        },
        "models.AttendanceRule": {
            "type": "object",
            "properties": {
                "createdAt": {
                    "type": "string"
                },
                "deletedAt": {
                    "$ref": "#/definitions/gorm.DeletedAt"
                },
                "id": {
                    "type": "integer"
                },
                "overTimeStart": {
                    "type": "number"
                },
                "restDayRule": {
                    "type": "integer"
                },
                "restDayStart": {
                    "type": "number"
                },
                "updatedAt": {
                    "type": "string"
                },
                "weekdayRule": {
                    "type": "integer"
                }
            }
        },
@@ -3207,6 +3383,7 @@
            "type": "object",
            "properties": {
                "ids": {
                    "description": "记录id",
                    "type": "array",
                    "items": {
                        "type": "integer"
@@ -3265,6 +3442,15 @@
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                }
            }
        },
        "request.GetAttendanceStatistic": {
            "type": "object",
            "properties": {
                "month": {
                    "description": "月份",
                    "type": "string"
                }
            }
        },
@@ -3772,6 +3958,78 @@
                }
            }
        },
        "response.AttendanceDetail": {
            "type": "object",
            "properties": {
                "date": {
                    "description": "日期",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.AttendanceStatus"
                        }
                    ]
                }
            }
        },
        "response.AttendanceList": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/response.AttendanceStatistic"
                    }
                }
            }
        },
        "response.AttendanceStatistic": {
            "type": "object",
            "properties": {
                "actualAttendanceDays": {
                    "description": "实际出勤天数",
                    "type": "integer"
                },
                "details": {
                    "description": "详情",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/response.AttendanceDetail"
                    }
                },
                "month": {
                    "description": "月份",
                    "type": "string"
                },
                "requiredAttendanceDays": {
                    "description": "应出勤天数",
                    "type": "integer"
                },
                "restDayOverTime": {
                    "description": "休息日加班时长",
                    "type": "number"
                },
                "weekdayOverTime": {
                    "description": "工作日加班时长",
                    "type": "number"
                },
                "workType": {
                    "description": "工种",
                    "type": "string"
                },
                "workerId": {
                    "description": "人员id",
                    "type": "string"
                },
                "workerName": {
                    "description": "人员姓名",
                    "type": "string"
                }
            }
        },
        "response.CarAndLevel": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -1,4 +1,21 @@
definitions:
  constvar.AttendanceStatus:
    enum:
    - 1
    - 2
    - 3
    - 4
    type: integer
    x-enum-comments:
      Abnormal: 异常
      Normal: 正常
      Overtime: 加班
      Vacation: 休假
    x-enum-varnames:
    - Normal
    - Overtime
    - Vacation
    - Abnormal
  constvar.CarFlag:
    enum:
    - 1
@@ -126,14 +143,41 @@
        type: string
      id:
        type: integer
      overTimeDuration:
        type: number
      startWorkTime:
        type: string
      status:
        $ref: '#/definitions/constvar.AttendanceStatus'
      updatedAt:
        type: string
      workType:
        $ref: '#/definitions/models.WorkTypeManage'
      workTypeId:
        type: integer
      workerId:
        type: string
      workerName:
        type: string
    type: object
  models.AttendanceRule:
    properties:
      createdAt:
        type: string
      deletedAt:
        $ref: '#/definitions/gorm.DeletedAt'
      id:
        type: integer
      overTimeStart:
        type: number
      restDayRule:
        type: integer
      restDayStart:
        type: number
      updatedAt:
        type: string
      weekdayRule:
        type: integer
    type: object
  models.Dict:
    properties:
@@ -794,6 +838,7 @@
  request.DeleteAttendanceInfo:
    properties:
      ids:
        description: 记录id
        items:
          type: integer
        type: array
@@ -835,6 +880,12 @@
      pageSize:
        description: 每页大小
        type: integer
    type: object
  request.GetAttendanceStatistic:
    properties:
      month:
        description: 月份
        type: string
    type: object
  request.GetMentorList:
    properties:
@@ -1190,6 +1241,55 @@
        description: 产量登记表id
        type: integer
    type: object
  response.AttendanceDetail:
    properties:
      date:
        description: 日期
        type: string
      status:
        allOf:
        - $ref: '#/definitions/constvar.AttendanceStatus'
        description: 状态
    type: object
  response.AttendanceList:
    properties:
      list:
        items:
          $ref: '#/definitions/response.AttendanceStatistic'
        type: array
    type: object
  response.AttendanceStatistic:
    properties:
      actualAttendanceDays:
        description: 实际出勤天数
        type: integer
      details:
        description: 详情
        items:
          $ref: '#/definitions/response.AttendanceDetail'
        type: array
      month:
        description: 月份
        type: string
      requiredAttendanceDays:
        description: 应出勤天数
        type: integer
      restDayOverTime:
        description: 休息日加班时长
        type: number
      weekdayOverTime:
        description: 工作日加班时长
        type: number
      workType:
        description: 工种
        type: string
      workerId:
        description: 人员id
        type: string
      workerName:
        description: 人员姓名
        type: string
    type: object
  response.CarAndLevel:
    properties:
      car:
@@ -1342,6 +1442,77 @@
      summary: 获取考勤列表
      tags:
      - 考勤管理
  /api-jl/v1/attendance/getAttendanceRule:
    get:
      parameters:
      - description: token
        in: header
        name: Authorization
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 获取加班规则
      tags:
      - 考勤管理
  /api-jl/v1/attendance/getAttendanceStatistic:
    post:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.GetAttendanceStatistic'
      - description: token
        in: header
        name: Authorization
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.AttendanceList'
              type: object
      summary: 获取考勤统计
      tags:
      - 考勤管理
  /api-jl/v1/attendance/saveAttendanceRule:
    post:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/models.AttendanceRule'
      - description: token
        in: header
        name: Authorization
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 保存加班规则
      tags:
      - 考勤管理
  /api-jl/v1/fineness/changeYieldRegister:
    post:
      parameters:
models/attendance_manage.go
@@ -33,6 +33,7 @@
        PageSize int
        Preload  bool
        Ids      []uint
        Month    string
        Orm      *gorm.DB
    }
)
@@ -65,6 +66,11 @@
    return slf
}
func (slf *AttendanceManageSearch) SetMonth(month string) *AttendanceManageSearch {
    slf.Month = month
    return slf
}
func (slf *AttendanceManageSearch) build() *gorm.DB {
    var db = slf.Orm.Table(slf.TableName())
@@ -76,6 +82,10 @@
        db = db.Model(&AttendanceManage{}).Preload("WorkType")
    }
    if slf.Month != "" {
        db = db.Where("date like ?", slf.Month+"%")
    }
    return db
}
router/router.go
@@ -107,6 +107,7 @@
    {
        attendanceApi.POST("attendanceInput", attendanceController.AttendanceInput)             //考勤导入
        attendanceApi.POST("getAttendanceList", attendanceController.GetAttendanceList)         //获取考勤列表
        attendanceApi.POST("getAttendanceStatistic", attendanceController.GetAttendanceStatistic) //获取考勤统计
        attendanceApi.DELETE("deleteAttendanceInfo", attendanceController.DeleteAttendanceInfo) //删除考勤信息
        attendanceApi.GET("getAttendanceRule", attendanceController.GetAttendanceRule)          //获取加班规则
        attendanceApi.POST("saveAttendanceRule", attendanceController.SaveAttendanceRule)       //保存加班规则