ソースを参照

2023-06-12 统筹管理

zoie 1 年間 前
コミット
a1a10a20f1
2 ファイル変更10 行追加5 行削除
  1. 8 3
      controllers/Overtime.go
  2. 2 2
      models/Attendance/Attendance.go

+ 8 - 3
controllers/Overtime.go

@@ -282,12 +282,12 @@ func (c *OvertimeController) Overtime_Stat() {
 		T_uuid = c.User.T_uuid
 	}
 
-	attendance, cnt := Attendance.Read_Attendance_List_For_Stat(T_uuid, page, page_z)
+	attendance, cnt := Attendance.Read_Attendance_List_For_Stat(T_uuid, 0, 9999)
 
 	userList, _ := NatsServer.Read_User_List_All()
 	Account.Read_User_All_Map(userList)
 	var duration int
-	for i := 0; i < len(attendance); i++ {
+	for i := len(attendance) - 1; i >= 0; i-- {
 		if attendance[i].T_type == Attendance.AttendanceDaysOff || attendance[i].T_type == Attendance.AttendanceShiftPerf || attendance[i].T_type > 100 {
 			duration -= attendance[i].T_duration
 			attendance[i].T_duration = -attendance[i].T_duration
@@ -308,9 +308,14 @@ func (c *OvertimeController) Overtime_Stat() {
 	}
 
 	var r_jsons R_JSONS
+	offset := (page - 1) * page_z
+	limit := offset + page_z
+	if limit > int(cnt) {
+		limit = int(cnt)
+	}
 	r_jsons.Num = cnt
 	r_jsons.RemainingTime = Attendance.GetRemainingDaysOff(T_uuid)
-	r_jsons.Data = attendance
+	r_jsons.Data = attendance[offset:limit]
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 

+ 2 - 2
models/Attendance/Attendance.go

@@ -341,9 +341,9 @@ func Read_Attendance_List_For_Stat(T_uid string, page, page_z int) (r []Attendan
 
 	var err error
 	if page_z == 9999 {
-		_, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
+		_, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-T_start_time").All(&map_r)
 	} else {
-		_, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
+		_, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-T_start_time").All(&map_r)
 	}
 
 	if err != nil {