更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -15,39 +15,24 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// OA 考勤打卡:移动端签到 / 签退(app_oa_attendance.go)+ 后台考勤记录(本文件)。
|
||||
//
|
||||
// 打卡与排班联动的方式:
|
||||
// 1. 打卡时按「员工 + 日期」查排班明细(yz_backend_oa_schedule_entry),
|
||||
// 命中则把班次名称与上下班时间快照进考勤记录,并据此判定正常 / 迟到 / 早退;
|
||||
// 2. 未命中排班(含员工档案缺失)不影响打卡,只把 match_status 记为 2、
|
||||
// 在 clock_in_note 里写入提醒文案,前端据此做「先提醒、仍可签到」的交互;
|
||||
// 3. 后台只读考勤记录 + 缺卡名单,异常说明由管理员在备注里补充。
|
||||
|
||||
const (
|
||||
// oaAttendGraceMinutes 迟到 / 早退容差,避免卡点打卡被判异常。
|
||||
oaAttendGraceMinutes = 5
|
||||
// oaAttendEarlyLimitMinutes 允许提前签到的分钟数:超过则记为「不在班次时段」。
|
||||
oaAttendEarlyLimitMinutes = 60
|
||||
// oaAttendMaxRangeDays 单次查询的日期区间上限。
|
||||
oaAttendMaxRangeDays = 92
|
||||
// oaAttendMaxPageSize 分页大小上限。
|
||||
oaAttendMaxPageSize = 200
|
||||
)
|
||||
|
||||
// 考勤「当日结果」:列表与统计统一按这个口径展示。
|
||||
const (
|
||||
oaDayStatusNormal int8 = 1 // 正常
|
||||
oaDayStatusLate int8 = 2 // 迟到
|
||||
oaDayStatusEarly int8 = 3 // 早退
|
||||
oaDayStatusMissing int8 = 4 // 缺卡(未签到)
|
||||
oaDayStatusNoSchedule int8 = 5 // 无排班打卡
|
||||
oaDayStatusOffTime int8 = 6 // 不在班次时段
|
||||
oaDayStatusNoClockOut int8 = 7 // 未签退
|
||||
oaDayStatusRest int8 = 8 // 未排班且未打卡(休息)
|
||||
oaDayStatusNormal int8 = 1
|
||||
oaDayStatusLate int8 = 2
|
||||
oaDayStatusEarly int8 = 3
|
||||
oaDayStatusMissing int8 = 4
|
||||
oaDayStatusNoSchedule int8 = 5
|
||||
oaDayStatusOffTime int8 = 6
|
||||
oaDayStatusNoClockOut int8 = 7
|
||||
oaDayStatusRest int8 = 8
|
||||
)
|
||||
|
||||
// oaAttendanceView 考勤记录的对外结构:时间统一转成字符串,避免前端解析 RFC3339。
|
||||
type oaAttendanceView struct {
|
||||
ID uint64 `json:"id"`
|
||||
Uid uint64 `json:"uid"`
|
||||
@@ -83,18 +68,20 @@ type oaAttendanceView struct {
|
||||
Source int8 `json:"source"`
|
||||
DayStatus int8 `json:"day_status"`
|
||||
DayStatusText string `json:"day_status_text"`
|
||||
CreateTime string `json:"create_time"`
|
||||
FixStatus int8 `json:"fix_status"`
|
||||
FixStatusText string `json:"fix_status_text"`
|
||||
FixType int8 `json:"fix_type"`
|
||||
FixTypeText string `json:"fix_type_text"`
|
||||
FixInstanceID uint64 `json:"fix_instance_id"`
|
||||
FixTime string `json:"fix_time"`
|
||||
FixReason string `json:"fix_reason"`
|
||||
CreateTime string `json:"create_time"`
|
||||
}
|
||||
|
||||
// BackendOaAttendanceController 后台考勤记录(只读 + 备注)。
|
||||
type BackendOaAttendanceController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 认证与响应
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
func (c *BackendOaAttendanceController) atClaims() (*jwtutil.Claims, bool) {
|
||||
claims, err := identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend)
|
||||
if err != nil || claims.TenantId <= 0 {
|
||||
@@ -125,16 +112,10 @@ func (c *BackendOaAttendanceController) atFail(httpStatus, bizCode int, msg stri
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 通用工具
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// oaAttendQuery 本租户考勤记录查询。
|
||||
func oaAttendQuery(tid uint64) orm.QuerySeter {
|
||||
return models.Orm.QueryTable(new(models.OaAttendance)).Filter("tid", tid)
|
||||
}
|
||||
|
||||
// oaAttendFind 取某人某天的考勤记录:有员工档案按员工,否则按登录身份兜底。
|
||||
func oaAttendFind(tid uint64, date string, employeeID uint, uid uint64) *models.OaAttendance {
|
||||
qs := oaAttendQuery(tid).Filter("attend_date", date)
|
||||
switch {
|
||||
@@ -152,7 +133,6 @@ func oaAttendFind(tid uint64, date string, employeeID uint, uid uint64) *models.
|
||||
return &row
|
||||
}
|
||||
|
||||
// oaAttendEntryOf 取某员工某天的排班明细(一人一天一条有效记录)。
|
||||
func oaAttendEntryOf(tid uint64, employeeID uint, date string) *models.OaScheduleEntry {
|
||||
if employeeID == 0 {
|
||||
return nil
|
||||
@@ -172,7 +152,6 @@ func oaAttendEntryOf(tid uint64, employeeID uint, date string) *models.OaSchedul
|
||||
return &entry
|
||||
}
|
||||
|
||||
// oaAttendOrgName 组织名称快照(失败返回空串,不影响打卡)。
|
||||
func oaAttendOrgName(tid, orgID uint64) string {
|
||||
if orgID == 0 {
|
||||
return ""
|
||||
@@ -185,7 +164,6 @@ func oaAttendOrgName(tid, orgID uint64) string {
|
||||
return org.OrgName
|
||||
}
|
||||
|
||||
// oaAttendOrgIDs 把组织节点展开成「自身 + 下级」的 ID 列表;org_id=0 表示不限。
|
||||
func oaAttendOrgIDs(tid, root uint64, includeChild bool) []uint64 {
|
||||
if root == 0 {
|
||||
return nil
|
||||
@@ -223,7 +201,6 @@ func oaAttendOrgIDs(tid, root uint64, includeChild bool) []uint64 {
|
||||
return out
|
||||
}
|
||||
|
||||
// oaAttendWeekday 返回 1=周一 ... 7=周日。
|
||||
func oaAttendWeekday(date string) int {
|
||||
parsed, ok := scParseDate(date)
|
||||
if !ok {
|
||||
@@ -236,7 +213,6 @@ func oaAttendWeekday(date string) int {
|
||||
return weekday
|
||||
}
|
||||
|
||||
// oaAttendShiftText 班次时间文案。
|
||||
func oaAttendShiftText(workStart, workEnd string) string {
|
||||
if workStart == "" || workEnd == "" {
|
||||
return "未排班"
|
||||
@@ -263,7 +239,6 @@ func oaAttendClockText(status int8, isOut bool) string {
|
||||
return "未打卡"
|
||||
}
|
||||
|
||||
// oaAttendDayResult 汇总「当天」的考勤结果,列表与统计共用同一口径。
|
||||
func oaAttendDayResult(clockIn string, clockInStatus int8, clockOut string, clockOutStatus int8, matchStatus int8) (int8, string) {
|
||||
switch {
|
||||
case clockIn == "":
|
||||
@@ -282,7 +257,6 @@ func oaAttendDayResult(clockIn string, clockInStatus int8, clockOut string, cloc
|
||||
return oaDayStatusNormal, "正常"
|
||||
}
|
||||
|
||||
// oaAttendView 记录 → 视图。
|
||||
func oaAttendView(row *models.OaAttendance) oaAttendanceView {
|
||||
date := normalizeOaDate(row.AttendDate)
|
||||
inTime, inHm := "", ""
|
||||
@@ -331,23 +305,48 @@ func oaAttendView(row *models.OaAttendance) oaAttendanceView {
|
||||
Source: row.Source,
|
||||
DayStatus: dayStatus,
|
||||
DayStatusText: dayText,
|
||||
FixStatus: row.FixStatus,
|
||||
FixStatusText: oaAttendFixStatusText(row.FixStatus),
|
||||
FixType: row.FixType,
|
||||
FixTypeText: oaAttendFixTypeText(row.FixType),
|
||||
FixInstanceID: row.FixInstanceID,
|
||||
FixTime: row.FixTime,
|
||||
FixReason: row.FixReason,
|
||||
CreateTime: row.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 打卡核心(移动端与后续补录共用)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// oaAttendPunchInput 打卡入参。
|
||||
type oaAttendPunchInput struct {
|
||||
Type string // in=签到 out=签退
|
||||
Location string
|
||||
Remark string
|
||||
FallbackName string // 员工档案缺失时用于展示的姓名
|
||||
func oaAttendFixStatusText(status int8) string {
|
||||
switch status {
|
||||
case models.OaAttendFixRunning:
|
||||
return "补卡审批中"
|
||||
case models.OaAttendFixApproved:
|
||||
return "已补卡"
|
||||
case models.OaAttendFixRejected:
|
||||
return "补卡已驳回"
|
||||
case models.OaAttendFixWithdrawn:
|
||||
return "补卡已撤回"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func oaAttendFixTypeText(fixType int8) string {
|
||||
switch fixType {
|
||||
case models.OaAttendFixTypeIn:
|
||||
return "签到补卡"
|
||||
case models.OaAttendFixTypeOut:
|
||||
return "签退补卡"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type oaAttendPunchInput struct {
|
||||
Type string
|
||||
Location string
|
||||
Remark string
|
||||
FallbackName string
|
||||
}
|
||||
|
||||
// oaAttendPunchResult 打卡结果。
|
||||
type oaAttendPunchResult struct {
|
||||
View oaAttendanceView
|
||||
Warning string
|
||||
@@ -355,7 +354,6 @@ type oaAttendPunchResult struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
// oaShiftWindow 把班次上下班换算成当日分钟区间;下班早于上班视为跨天班次。
|
||||
func oaShiftWindow(workStart, workEnd string) (int, int, bool) {
|
||||
start, okStart := scMinutes(workStart)
|
||||
end, okEnd := scMinutes(workEnd)
|
||||
@@ -368,7 +366,6 @@ func oaShiftWindow(workStart, workEnd string) (int, int, bool) {
|
||||
return start, end, true
|
||||
}
|
||||
|
||||
// oaShiftNowMinutes 把当前时刻换算到班次时间轴上(跨天班次凌晨时刻 +24h)。
|
||||
func oaShiftNowMinutes(now time.Time, startMinutes int) int {
|
||||
value := now.Hour()*60 + now.Minute()
|
||||
if startMinutes >= 12*60 && value < startMinutes {
|
||||
@@ -377,7 +374,6 @@ func oaShiftNowMinutes(now time.Time, startMinutes int) int {
|
||||
return value
|
||||
}
|
||||
|
||||
// oaAttendClockInStatus 签到结果判定:无排班 / 时段异常只提醒,不阻断打卡。
|
||||
func oaAttendClockInStatus(row *models.OaAttendance, now time.Time) (int8, string) {
|
||||
start, _, ok := oaShiftWindow(row.WorkStart, row.WorkEnd)
|
||||
if !ok {
|
||||
@@ -398,7 +394,6 @@ func oaAttendClockInStatus(row *models.OaAttendance, now time.Time) (int8, strin
|
||||
return models.OaAttendClockNormal, ""
|
||||
}
|
||||
|
||||
// oaAttendClockOutStatus 签退结果判定:早退只提醒,不阻断打卡。
|
||||
func oaAttendClockOutStatus(row *models.OaAttendance, now time.Time) (int8, string) {
|
||||
start, end, ok := oaShiftWindow(row.WorkStart, row.WorkEnd)
|
||||
if !ok {
|
||||
@@ -415,8 +410,6 @@ func oaAttendClockOutStatus(row *models.OaAttendance, now time.Time) (int8, stri
|
||||
return models.OaAttendClockNormal, ""
|
||||
}
|
||||
|
||||
// oaAttendPrevOpen 跨天班次兜底:昨天签到未签退、且班次为跨天班次时,
|
||||
// 今天的签退落到昨天那条记录上,避免凌晨签退被记成新的一天。
|
||||
func oaAttendPrevOpen(tid uint64, uid uint64, employeeID uint, date string) *models.OaAttendance {
|
||||
prevDate := nextOaDate(date, -1)
|
||||
if prevDate == "" {
|
||||
@@ -433,7 +426,6 @@ func oaAttendPrevOpen(tid uint64, uid uint64, employeeID uint, date string) *mod
|
||||
return row
|
||||
}
|
||||
|
||||
// oaAttendPunch 考勤打卡核心:写库并返回记录、提醒文案与是否重复打卡。
|
||||
func oaAttendPunch(tid, uid uint64, employee *models.BackendEmployee, input oaAttendPunchInput) (*oaAttendPunchResult, int, string) {
|
||||
clockType := strings.ToLower(strings.TrimSpace(input.Type))
|
||||
if clockType != "in" && clockType != "out" {
|
||||
@@ -485,7 +477,6 @@ func oaAttendPunch(tid, uid uint64, employee *models.BackendEmployee, input oaAt
|
||||
Source: models.OaAttendSourceApp,
|
||||
}
|
||||
} else if row.EmployeeID == 0 && employeeID > 0 {
|
||||
// 早前未绑定员工档案时打的卡,补齐员工信息
|
||||
row.EmployeeID = employeeID
|
||||
row.EmployeeName = name
|
||||
row.EmployeeAccount = account
|
||||
@@ -494,7 +485,6 @@ func oaAttendPunch(tid, uid uint64, employee *models.BackendEmployee, input oaAt
|
||||
row.Position = position
|
||||
}
|
||||
|
||||
// 排班快照:以打卡时的排班为准,后续调班不影响历史记录
|
||||
if entry := oaAttendEntryOf(tid, employeeID, normalizeOaDate(row.AttendDate)); entry != nil {
|
||||
row.EntryID = entry.ID
|
||||
row.ShiftID = entry.ShiftID
|
||||
@@ -565,7 +555,6 @@ func oaAttendPunch(tid, uid uint64, employee *models.BackendEmployee, input oaAt
|
||||
}
|
||||
if created {
|
||||
if _, err := models.Orm.Insert(row); err != nil {
|
||||
// 并发下唯一键冲突:按已打卡返回,避免前端误判失败
|
||||
if exist := oaAttendFind(tid, date, employeeID, uid); exist != nil {
|
||||
return &oaAttendPunchResult{
|
||||
View: oaAttendView(exist),
|
||||
@@ -591,12 +580,6 @@ func oaAttendPunch(tid, uid uint64, employee *models.BackendEmployee, input oaAt
|
||||
}, 200, ""
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 统计
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// oaAttendStats 区间考勤统计:应出勤按排班明细统计,实出勤按已签到(含无排班打卡)。
|
||||
// orgIDs 非空时按组织过滤;employeeID>0 时只统计该员工。
|
||||
func oaAttendStats(tid uint64, startDate, endDate string, orgIDs []uint64, employeeID uint) map[string]interface{} {
|
||||
entryQS := models.Orm.QueryTable(new(models.OaScheduleEntry)).
|
||||
Filter("tid", tid).
|
||||
@@ -669,14 +652,6 @@ func oaAttendStats(tid uint64, startDate, endDate string, orgIDs []uint64, emplo
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 后台:考勤记录
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// RecordList 后台考勤记录列表。
|
||||
// GET /backend/oa/attendance/records?page=&pageSize=&start_date=&end_date=
|
||||
//
|
||||
// &keyword=&org_id=&include_child=1&employee_id=&status=&match_status=
|
||||
func (c *BackendOaAttendanceController) RecordList() {
|
||||
tid, _, ok := c.atOperator()
|
||||
if !ok {
|
||||
@@ -726,7 +701,6 @@ func (c *BackendOaAttendanceController) RecordList() {
|
||||
employeeID = uint(parsed)
|
||||
}
|
||||
}
|
||||
// uid:未绑定员工档案的打卡按登录身份归属,汇总行展开明细时用
|
||||
uid := uint64(0)
|
||||
if raw := strings.TrimSpace(c.GetString("uid")); raw != "" {
|
||||
if parsed, err := strconv.ParseUint(raw, 10, 64); err == nil {
|
||||
@@ -799,8 +773,6 @@ func (c *BackendOaAttendanceController) RecordList() {
|
||||
})
|
||||
}
|
||||
|
||||
// MissingList 缺卡名单:指定日期有排班但未签到的人。
|
||||
// GET /backend/oa/attendance/missing?date=&org_id=&include_child=1&keyword=
|
||||
func (c *BackendOaAttendanceController) MissingList() {
|
||||
tid, _, ok := c.atOperator()
|
||||
if !ok {
|
||||
@@ -878,8 +850,6 @@ func (c *BackendOaAttendanceController) MissingList() {
|
||||
})
|
||||
}
|
||||
|
||||
// RecordRemark 管理员备注 / 异常说明。
|
||||
// POST /backend/oa/attendance/remark/:id body: {"remark": "..."}
|
||||
func (c *BackendOaAttendanceController) RecordRemark() {
|
||||
tid, _, ok := c.atOperator()
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user