优化代码
This commit is contained in:
1 parent
8ba15d87b3
commit
7b1c94b5ff
5 files changed
+261
-2
No files matched your search
@@ -778,6 +778,67 @@ func (c *BackendOaSchedulingController) ClearEntries() {
|
||||
c.scOK(map[string]interface{}{"cleared": len(entries)})
|
||||
}
|
||||
|
||||
// MyBoard 当前登录用户的排班:按登录账号匹配员工档案,返回区间内每天的排班,
|
||||
// 供日程日历渲染上班/休息背景。
|
||||
// GET /backend/oa/scheduling/my?start_date=&end_date=
|
||||
func (c *BackendOaSchedulingController) MyBoard() {
|
||||
tid, _, username, ok := c.scOperator()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
startDate := strings.TrimSpace(c.GetString("start_date"))
|
||||
endDate := strings.TrimSpace(c.GetString("end_date"))
|
||||
if startDate == "" || endDate == "" {
|
||||
now := time.Now()
|
||||
startDate = now.Format("2006-01-02")
|
||||
endDate = startDate
|
||||
}
|
||||
dates, msg := scDateSpan(startDate, endDate)
|
||||
if msg != "" {
|
||||
c.scFail(400, 400, msg)
|
||||
return
|
||||
}
|
||||
if len(dates) > scBoardMaxDays {
|
||||
c.scFail(400, 400, fmt.Sprintf("一次最多查询 %d 天", scBoardMaxDays))
|
||||
return
|
||||
}
|
||||
|
||||
// 账号未关联员工档案时返回空列表,前端静默不渲染排班背景
|
||||
var employee models.BackendEmployee
|
||||
if err := c.scBaseEmployeeQuery(tid).Filter("account", username).One(&employee); err != nil {
|
||||
c.scOK(map[string]interface{}{"employee": nil, "list": []map[string]interface{}{}})
|
||||
return
|
||||
}
|
||||
|
||||
var entries []models.OaScheduleEntry
|
||||
_, _ = c.scEntryQuery(tid).
|
||||
Filter("employee_id", employee.ID).
|
||||
Filter("schedule_date__gte", startDate).
|
||||
Filter("schedule_date__lte", endDate).
|
||||
OrderBy("schedule_date").
|
||||
All(&entries)
|
||||
|
||||
list := make([]map[string]interface{}, 0, len(entries))
|
||||
for i := range entries {
|
||||
e := entries[i]
|
||||
list = append(list, map[string]interface{}{
|
||||
"date": e.ScheduleDate,
|
||||
"shift_id": e.ShiftID,
|
||||
"shift_name": e.ShiftName,
|
||||
"short_name": e.ShortName,
|
||||
"color": e.Color,
|
||||
"work_start": e.WorkStart,
|
||||
"work_end": e.WorkEnd,
|
||||
"note": e.Note,
|
||||
})
|
||||
}
|
||||
c.scOK(map[string]interface{}{
|
||||
"employee": map[string]interface{}{"id": employee.ID, "name": employee.Name},
|
||||
"list": list,
|
||||
})
|
||||
}
|
||||
|
||||
// ChangeList 排班变更记录(最近 100 条),用于追溯临时调配。
|
||||
// GET /backend/oa/scheduling/changes?start_date=&end_date=&employee_id=
|
||||
func (c *BackendOaSchedulingController) ChangeList() {
|
||||
|
||||
@@ -347,6 +347,7 @@ func RegisterAuthRoutes() {
|
||||
beego.Router("/backend/oa/scheduling/shifts/:id", &controllers.BackendOaSchedulingController{}, "post:UpdateShift;delete:DeleteShift")
|
||||
beego.Router("/backend/oa/scheduling/employees", &controllers.BackendOaSchedulingController{}, "get:ScheduleEmployeeOptions")
|
||||
beego.Router("/backend/oa/scheduling/board", &controllers.BackendOaSchedulingController{}, "get:Board")
|
||||
beego.Router("/backend/oa/scheduling/my", &controllers.BackendOaSchedulingController{}, "get:MyBoard")
|
||||
beego.Router("/backend/oa/scheduling/plans", &controllers.BackendOaSchedulingController{}, "get:PlanList")
|
||||
beego.Router("/backend/oa/scheduling/templates", &controllers.BackendOaSchedulingController{}, "get:TemplateList")
|
||||
beego.Router("/backend/oa/scheduling/templates/apply", &controllers.BackendOaSchedulingController{}, "post:TemplateApply")
|
||||
|
||||
Reference in new issue
Block a user