问题与需求:后台禁用员工后旧会话仍可继续访问;实时队列跨天误读昨日场次;项目暂停后需禁止取号但允许叫号。 修复思路:账号权限变更时撤销会话并同步前端登录态;实时查询统一按项目时区当天场次过滤;拆分取号与叫号的状态校验,并补充前后端及 PostgreSQL 回归测试。
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"calllinesystem/server/internal/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func (s *Server) businessDateFor(project model.Project) (time.Time, error) {
|
|
location, err := time.LoadLocation(project.Timezone)
|
|
if err != nil {
|
|
return time.Time{}, fmt.Errorf("invalid project timezone: %w", err)
|
|
}
|
|
localNow := s.now().In(location)
|
|
return time.Date(localNow.Year(), localNow.Month(), localNow.Day(), 0, 0, 0, 0, location), nil
|
|
}
|
|
|
|
func (s *Server) currentQueueSession(db *gorm.DB, project model.Project) (model.QueueSession, error) {
|
|
businessDate, err := s.businessDateFor(project)
|
|
if err != nil {
|
|
return model.QueueSession{}, err
|
|
}
|
|
var session model.QueueSession
|
|
err = db.Where(
|
|
"project_id = ? AND business_date = ? AND status IN ?",
|
|
project.ID,
|
|
businessDate,
|
|
[]string{"RUNNING", "PAUSED"},
|
|
).First(&session).Error
|
|
return session, err
|
|
}
|
|
|
|
func (s *Server) queueSessionIsCurrent(project model.Project, session model.QueueSession) (bool, error) {
|
|
businessDate, err := s.businessDateFor(project)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return session.BusinessDate.Format("2006-01-02") == businessDate.Format("2006-01-02"), nil
|
|
}
|