Przeglądaj źródła

fix: 交接班记录显示操作员姓名——联表sys_users+前端操作员列

lq 1 miesiąc temu
rodzic
commit
2aeadbb07c

+ 1 - 0
frontend/src/view/parking/shiftRecord.vue

@@ -24,6 +24,7 @@
     </el-card>
 
     <el-table :data="list" border style="margin-top:16px">
+      <el-table-column label="操作员" prop="operator_name" width="100" />
       <el-table-column label="接班时间" prop="start_time" width="170" />
       <el-table-column label="交班时间" prop="end_time" width="170" />
       <el-table-column label="接班现金" width="100"><template #default="{row}">¥{{ row.starting_cash.toFixed(2) }}</template></el-table-column>

+ 21 - 7
internal/modules/shift/repository/repo.go

@@ -25,21 +25,35 @@ func (r *ShiftRepository) GetActive(operatorID uint) (*dao.ShiftRecord, error) {
 }
 
 type ShiftListQuery struct {
-	Page     int `form:"page"`
-	PageSize int `form:"page_size"`
+	Page     int  `form:"page"`
+	PageSize int  `form:"page_size"`
+	ShowAll  bool `form:"show_all"`
 }
 
-func (r *ShiftRepository) List(q ShiftListQuery, operatorID uint) ([]dao.ShiftRecord, int64, error) {
-	db := global.GVA_DB.Model(&dao.ShiftRecord{}).Where("operator_id = ?", operatorID)
+type ShiftListItem struct {
+	dao.ShiftRecord
+	OperatorName string `json:"operator_name"`
+}
+
+func (r *ShiftRepository) List(q ShiftListQuery, operatorID uint) ([]ShiftListItem, int64, error) {
+	db := global.GVA_DB.Table("shift_record sr").
+		Select("sr.*, su.nick_name as operator_name").
+		Joins("LEFT JOIN sys_users su ON su.id = sr.operator_id")
+
+	if !q.ShowAll {
+		db = db.Where("sr.operator_id = ?", operatorID)
+	}
+
 	var total int64
 	db.Count(&total)
+
 	if q.Page <= 0 {
 		q.Page = 1
 	}
 	if q.PageSize <= 0 {
-		q.PageSize = 10
+		q.PageSize = 20
 	}
-	var list []dao.ShiftRecord
-	err := db.Order("id DESC").Offset((q.Page - 1) * q.PageSize).Limit(q.PageSize).Find(&list).Error
+	var list []ShiftListItem
+	err := db.Order("sr.id DESC").Offset((q.Page - 1) * q.PageSize).Limit(q.PageSize).Scan(&list).Error
 	return list, total, err
 }

+ 1 - 1
internal/modules/shift/service/service.go

@@ -64,6 +64,6 @@ func (s *ShiftService) GetCurrent(operatorID uint) (*dao.ShiftRecord, error) {
 	return s.repo.GetActive(operatorID)
 }
 
-func (s *ShiftService) List(q repository.ShiftListQuery, operatorID uint) ([]dao.ShiftRecord, int64, error) {
+func (s *ShiftService) List(q repository.ShiftListQuery, operatorID uint) ([]repository.ShiftListItem, int64, error) {
 	return s.repo.List(q, operatorID)
 }