Skip to content

Commit

Permalink
fix: normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
SchwarzSail committed Oct 1, 2024
1 parent be4588c commit c6e743c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/classroom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

此模块基于jwch库(教务处的信息爬取库):https://github.com/west2-online/jwch

飞书文档:
飞书文档:https://west2-online.feishu.cn/wiki/YMtTwhwAOimxkIkeZfAcfAzgnle?from=from_copylink


2 changes: 1 addition & 1 deletion cmd/classroom/dal/cache/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ScheduledGetClassrooms() error {
logger.LoggerObj.Debugf("ScheduledGetClassrooms: add task %v", args)
}
}
logger.LoggerObj.Infof("classroom.cache.CGetClassrooms add all tasks of campus %v in the day %v", campus, date)
logger.LoggerObj.Infof("classroom.cache.GetClassrooms add all tasks of campus %v in the day %v", campus, date)
}
}
return nil
Expand Down
16 changes: 16 additions & 0 deletions cmd/classroom/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/west2-online/fzuhelper-server/cmd/classroom/service"
classroom "github.com/west2-online/fzuhelper-server/kitex_gen/classroom"
"github.com/west2-online/fzuhelper-server/pkg/logger"
"time"
)

// ClassroomServiceImpl implements the last service interface defined in the IDL.
Expand All @@ -14,6 +15,21 @@ type ClassroomServiceImpl struct{}
// GetEmptyRoom implements the ClassroomServiceImpl interface.
func (s *ClassroomServiceImpl) GetEmptyRoom(ctx context.Context, req *classroom.EmptyRoomRequest) (resp *classroom.EmptyRoomResponse, err error) {
resp = classroom.NewEmptyRoomResponse()
//实际上前端会给定一个月内的选择,后端为了完整性,还是要判断一下
//判断req.date只能从今天开始的一个月内
//首先判断date的格式是否符合要求
requestDate, err := time.Parse("2006-01-02", req.Date)
if err != nil {
logger.LoggerObj.Errorf("Classroom.GetEmptyRoom: date format error, err: %v", err)
resp.Base = pack.BuildBaseResp(err)
return resp, nil
}
dateDiff := requestDate.Sub(time.Now()).Hours() / 24
if dateDiff < 0 || dateDiff > 30 {
logger.LoggerObj.Errorf("Classroom.GetEmptyRoom: date out of range, err: %v", err)
resp.Base = pack.BuildBaseResp(err)
return resp, nil
}
l := service.NewClassroomService(ctx)
res, err := l.GetEmptyRoom(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/classroom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func Init() {
config.Init(*path, serviceName)

dal.Init()
InitWorkerQueue()
}

func main() {
Init()
InitWorkerQueue()
r, err := etcd.NewEtcdRegistry([]string{config.Etcd.Addr})
if err != nil {
//如果无法解析etcd的地址,则无法连接到其他的微服务,说明整个服务无法运行,直接panic
Expand Down

0 comments on commit c6e743c

Please sign in to comment.