更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -2,6 +2,8 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -9,21 +11,12 @@ import (
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
approvalEngine "server/services/approval"
|
||||
authSvc "server/services/auth"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// 移动端 OA 考勤打卡接口(挂在 AppOaController 上)。
|
||||
//
|
||||
// 与 Web 后台 /backend/oa/attendance/* 共用同一套数据与判定逻辑:
|
||||
// - 打卡:oaAttendPunch(联动排班明细,匹配不上只提醒、仍可签到);
|
||||
// - 记录:本人维度,只能看到自己的考勤。
|
||||
//
|
||||
// 员工档案缺失时仍允许打卡(employee_id=0,按登录身份 uid 归档),
|
||||
// 保证「排班 / 人事档案没配好也能先签到」,由管理员后续核对。
|
||||
|
||||
// oaAttendAppClaims 取 app 令牌并确认已归属租户;失败时返回可直接输出的状态码与文案。
|
||||
func (c *AppOaController) oaAttendAppClaims() (*jwtutil.Claims, int, string) {
|
||||
claims, err := c.oaClaims()
|
||||
if err != nil {
|
||||
@@ -36,7 +29,6 @@ func (c *AppOaController) oaAttendAppClaims() (*jwtutil.Claims, int, string) {
|
||||
return claims, 200, ""
|
||||
}
|
||||
|
||||
// oaAttendSelf 解析当前登录者对应的员工档案;未绑定时返回 nil 与兜底姓名。
|
||||
func (c *AppOaController) oaAttendSelf(claims *jwtutil.Claims) (*models.BackendEmployee, string) {
|
||||
tid := uint64(claims.TenantId)
|
||||
uid := uint64(claims.UserID)
|
||||
@@ -55,7 +47,6 @@ func (c *AppOaController) oaAttendSelf(claims *jwtutil.Claims) (*models.BackendE
|
||||
return nil, name
|
||||
}
|
||||
|
||||
// oaAttendEmployeeMap 当前登录者的员工信息(未绑定时 bound=false)。
|
||||
func oaAttendEmployeeMap(tid uint64, employee *models.BackendEmployee, fallbackName string) map[string]interface{} {
|
||||
if employee == nil {
|
||||
return map[string]interface{}{
|
||||
@@ -79,7 +70,6 @@ func oaAttendEmployeeMap(tid uint64, employee *models.BackendEmployee, fallbackN
|
||||
}
|
||||
}
|
||||
|
||||
// oaAttendEntryMap 当日排班(未排班返回 nil)。
|
||||
func oaAttendEntryMap(entry *models.OaScheduleEntry) map[string]interface{} {
|
||||
if entry == nil {
|
||||
return nil
|
||||
@@ -98,7 +88,6 @@ func oaAttendEntryMap(entry *models.OaScheduleEntry) map[string]interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
// oaAttendTodayWarning 未匹配排班时的提醒文案(页面顶部横幅 + 打卡前二次确认共用)。
|
||||
func oaAttendTodayWarning(entry *models.OaScheduleEntry, employee *models.BackendEmployee) string {
|
||||
if entry != nil {
|
||||
return ""
|
||||
@@ -109,7 +98,6 @@ func oaAttendTodayWarning(entry *models.OaScheduleEntry, employee *models.Backen
|
||||
return "今日未匹配到排班,仍可签到,签到后将标记为「无排班打卡」,请联系管理员核对排班"
|
||||
}
|
||||
|
||||
// oaAttendRecentDays 最近 N 天的排班 + 打卡合并视图(一次性批量查询,避免逐天查库)。
|
||||
func oaAttendRecentDays(tid, uid uint64, employeeID uint, endDate string, days int) []map[string]interface{} {
|
||||
if days < 1 || days > 31 {
|
||||
days = 7
|
||||
@@ -191,14 +179,12 @@ func oaAttendRecentDays(tid, uid uint64, employeeID uint, endDate string, days i
|
||||
list = append(list, item)
|
||||
}
|
||||
|
||||
// 倒序(最近的日期在前)
|
||||
for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
|
||||
list[i], list[j] = list[j], list[i]
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// oaAttendPersonalStats 个人区间考勤统计(员工档案缺失时只统计打卡次数)。
|
||||
func oaAttendPersonalStats(tid, uid uint64, employeeID uint, startDate, endDate string) map[string]interface{} {
|
||||
baseCond := func() *orm.Condition {
|
||||
cond := orm.NewCondition().
|
||||
@@ -261,9 +247,6 @@ func oaAttendPersonalStats(tid, uid uint64, employeeID uint, startDate, endDate
|
||||
}
|
||||
}
|
||||
|
||||
// AttendanceToday GET /api/oa/attendance/today?days=7
|
||||
// 今日打卡状态 + 当日排班 + 最近 N 天记录 + 本月统计。
|
||||
// 未匹配排班时 warning 非空,前端据此提醒,但 can_clock_in/can_clock_out 仍为 true。
|
||||
func (c *AppOaController) AttendanceToday() {
|
||||
claims, code, msg := c.oaAttendAppClaims()
|
||||
if msg != "" {
|
||||
@@ -310,9 +293,6 @@ func (c *AppOaController) AttendanceToday() {
|
||||
})
|
||||
}
|
||||
|
||||
// AttendanceClock POST /api/oa/attendance/clock
|
||||
// body: {"type":"in|out","location":"...","remark":"..."}
|
||||
// 未匹配排班时会返回 warning,但打卡依然成功(match_status=2,clock_*_status=3)。
|
||||
func (c *AppOaController) AttendanceClock() {
|
||||
claims, code, msg := c.oaAttendAppClaims()
|
||||
if msg != "" {
|
||||
@@ -352,8 +332,188 @@ func (c *AppOaController) AttendanceClock() {
|
||||
})
|
||||
}
|
||||
|
||||
// AttendanceRecords GET /api/oa/attendance/records?page=&pageSize=&start_date=&end_date=
|
||||
// 本人考勤记录(默认本月),返回 list/total/stats。
|
||||
func (c *AppOaController) AttendanceFixSubmit() {
|
||||
claims, code, msg := c.oaAttendAppClaims()
|
||||
if msg != "" {
|
||||
c.oaErr(code, code, msg)
|
||||
return
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
RecordID uint64 `json:"record_id"`
|
||||
FixType int8 `json:"fix_type"`
|
||||
FixTime string `json:"fix_time"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
if raw, readErr := io.ReadAll(c.Ctx.Request.Body); readErr == nil && len(raw) > 0 {
|
||||
if json.Unmarshal(raw, &payload) != nil {
|
||||
c.oaErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
}
|
||||
if payload.RecordID == 0 {
|
||||
c.oaErr(400, 400, "缺少考勤记录")
|
||||
return
|
||||
}
|
||||
if payload.FixType != models.OaAttendFixTypeIn && payload.FixType != models.OaAttendFixTypeOut {
|
||||
c.oaErr(400, 400, "请选择补卡类型")
|
||||
return
|
||||
}
|
||||
reason := strings.TrimSpace(payload.Reason)
|
||||
if reason == "" {
|
||||
c.oaErr(400, 400, "请填写补卡原因")
|
||||
return
|
||||
}
|
||||
fixTime := strings.TrimSpace(payload.FixTime)
|
||||
if fixTime != "" {
|
||||
if _, err := time.Parse("15:04", fixTime); err != nil {
|
||||
c.oaErr(400, 400, "补卡时间格式应为 HH:mm")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tid := uint64(claims.TenantId)
|
||||
uid := uint64(claims.UserID)
|
||||
|
||||
var row models.OaAttendance
|
||||
if err := models.Orm.QueryTable(new(models.OaAttendance)).
|
||||
Filter("id", payload.RecordID).Filter("tid", tid).One(&row); err != nil {
|
||||
c.oaErr(404, 404, "考勤记录不存在")
|
||||
return
|
||||
}
|
||||
|
||||
employee, _ := c.oaAttendSelf(claims)
|
||||
isMine := row.Uid == uid || (employee != nil && row.EmployeeID > 0 && row.EmployeeID == employee.ID)
|
||||
if !isMine {
|
||||
c.oaErr(403, 403, "只能申请本人的补卡")
|
||||
return
|
||||
}
|
||||
if row.FixStatus == models.OaAttendFixRunning {
|
||||
c.oaErr(400, 400, "该记录已有补卡申请在审批中")
|
||||
return
|
||||
}
|
||||
if row.FixStatus == models.OaAttendFixApproved {
|
||||
c.oaErr(400, 400, "该记录已补卡成功,无需重复申请")
|
||||
return
|
||||
}
|
||||
attendDate := normalizeOaDate(row.AttendDate)
|
||||
if attendDate > time.Now().Format("2006-01-02") {
|
||||
c.oaErr(400, 400, "未来日期无法补卡")
|
||||
return
|
||||
}
|
||||
|
||||
abnormal := false
|
||||
needFixTime := false
|
||||
if payload.FixType == models.OaAttendFixTypeIn {
|
||||
abnormal = row.ClockInTime == nil || row.ClockInStatus == models.OaAttendClockLate ||
|
||||
row.ClockInStatus == models.OaAttendClockNoShift || row.ClockInStatus == models.OaAttendClockOffTime
|
||||
needFixTime = row.ClockInTime == nil
|
||||
} else {
|
||||
abnormal = row.ClockOutTime == nil || row.ClockOutStatus == models.OaAttendClockLate ||
|
||||
row.ClockOutStatus == models.OaAttendClockNoShift || row.ClockOutStatus == models.OaAttendClockOffTime
|
||||
needFixTime = row.ClockOutTime == nil
|
||||
}
|
||||
if !abnormal {
|
||||
c.oaErr(400, 400, "当前打卡状态正常,无需补卡")
|
||||
return
|
||||
}
|
||||
if needFixTime && fixTime == "" {
|
||||
c.oaErr(400, 400, "缺卡补卡请填写实际打卡时间")
|
||||
return
|
||||
}
|
||||
|
||||
submitUID := oaApprovalSubmitUID(claims)
|
||||
var deptID uint64
|
||||
var tu models.SystemTenantUser
|
||||
if models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
Filter("uid", submitUID).Filter("tid", tid).
|
||||
Filter("delete_time__isnull", true).One(&tu) == nil {
|
||||
deptID = tu.OrgID
|
||||
}
|
||||
|
||||
fixTypeText := "签到补卡"
|
||||
if payload.FixType == models.OaAttendFixTypeOut {
|
||||
fixTypeText = "签退补卡"
|
||||
}
|
||||
title := fmt.Sprintf("考勤补卡 · %s %s", attendDate, fixTypeText)
|
||||
|
||||
instID, err := approvalEngine.Submit(approvalEngine.SubmitInput{
|
||||
Scope: models.ApprovalScopeTenant,
|
||||
Tid: tid,
|
||||
BizType: models.ApprovalBizAttendanceFix,
|
||||
BizID: row.ID,
|
||||
BizTitle: title,
|
||||
SubmitUID: submitUID,
|
||||
SubmitName: oaApprovalUserName(c, claims),
|
||||
DeptID: deptID,
|
||||
FormData: map[string]interface{}{
|
||||
"attend_date": attendDate,
|
||||
"fix_type": payload.FixType,
|
||||
"fix_type_text": fixTypeText,
|
||||
"fix_time": fixTime,
|
||||
"reason": reason,
|
||||
"employee_name": row.EmployeeName,
|
||||
"shift_name": row.ShiftName,
|
||||
"work_start": row.WorkStart,
|
||||
"work_end": row.WorkEnd,
|
||||
"clock_in_hm": oaAttendTimeHm(row.ClockInTime),
|
||||
"clock_out_hm": oaAttendTimeHm(row.ClockOutTime),
|
||||
"apply_user_name": oaApprovalUserName(c, claims),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
var noFlow *approvalEngine.ErrNoFlow
|
||||
if errors.As(err, &noFlow) {
|
||||
c.oaErr(400, 400, "补卡审批流未配置,请联系管理员在「审批流配置」中启用考勤补卡")
|
||||
return
|
||||
}
|
||||
c.oaErr(400, 400, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
instStatus := int8(models.ApprovalInstanceRunning)
|
||||
var inst models.ApprovalInstance
|
||||
if models.Orm.QueryTable(new(models.ApprovalInstance)).
|
||||
Filter("id", instID).One(&inst, "status") == nil {
|
||||
instStatus = inst.Status
|
||||
}
|
||||
fixStatus := models.OaAttendFixRunning
|
||||
message := "补卡申请已提交,等待审批"
|
||||
switch instStatus {
|
||||
case models.ApprovalInstanceApproved:
|
||||
fixStatus = models.OaAttendFixApproved
|
||||
message = "补卡审批已通过,考勤记录已恢复正常"
|
||||
case models.ApprovalInstanceRejected:
|
||||
fixStatus = models.OaAttendFixRejected
|
||||
case models.ApprovalInstanceWithdrawn, models.ApprovalInstanceCanceled:
|
||||
fixStatus = models.OaAttendFixWithdrawn
|
||||
}
|
||||
|
||||
_, _ = models.Orm.QueryTable(new(models.OaAttendance)).
|
||||
Filter("id", row.ID).
|
||||
Update(orm.Params{
|
||||
"fix_status": fixStatus,
|
||||
"fix_type": payload.FixType,
|
||||
"fix_instance_id": instID,
|
||||
"fix_time": fixTime,
|
||||
"fix_reason": reason,
|
||||
"update_time": time.Now(),
|
||||
})
|
||||
|
||||
c.oaOk(map[string]interface{}{
|
||||
"instance_id": instID,
|
||||
"fix_status": fixStatus,
|
||||
"message": message,
|
||||
})
|
||||
}
|
||||
|
||||
func oaAttendTimeHm(t *time.Time) string {
|
||||
if t == nil {
|
||||
return ""
|
||||
}
|
||||
return t.Format("15:04")
|
||||
}
|
||||
|
||||
func (c *AppOaController) AttendanceRecords() {
|
||||
claims, code, msg := c.oaAttendAppClaims()
|
||||
if msg != "" {
|
||||
@@ -429,8 +589,6 @@ func (c *AppOaController) AttendanceRecords() {
|
||||
})
|
||||
}
|
||||
|
||||
// AttendanceStats GET /api/oa/attendance/stats?period=month|quarter|year&date=YYYY-MM-DD
|
||||
// 个人考勤卡:按「月 / 季 / 年」聚合,供移动端统计卡片切换维度。
|
||||
func (c *AppOaController) AttendanceStats() {
|
||||
claims, code, msg := c.oaAttendAppClaims()
|
||||
if msg != "" {
|
||||
|
||||
Reference in new issue
Block a user