Skip to content

Commit

Permalink
fix: 修复工学云 getJobInfo 函数中的击穿问题,增加 PlanId 检测
Browse files Browse the repository at this point in the history
- 修复了在 `getJobInfo` 函数中未正确检测空值或无效工作信息导致的崩溃问题,确保在没有有效工作信息时能正确处理并返回错误。
- 增加了对 `PlanId` 的检测,确保在处理时 `PlanId` 为有效值,避免因空值或无效数据引起后续问题。

feat: 学习通新增个人信息与课程检测功能(后续开发中)

- 新增了个人信息检测功能,确保从学习通获取的个人信息有效。
- 增加了课程检测功能,确保课程数据正常处理。
- 这些功能目前处于开发阶段,后续将进一步完善并测试。
  • Loading branch information
mirai-MIC committed Dec 18, 2024
1 parent f047b12 commit df661ac
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 170 deletions.
143 changes: 19 additions & 124 deletions core/logrus.go
Original file line number Diff line number Diff line change
@@ -1,87 +1,3 @@
//package core
//
//import (
// "BronyaBot/global"
// "bytes"
// "fmt"
// "github.com/sirupsen/logrus"
// "os"
// "path"
//)
//
//const (
// red = 31
// yellow = 33
// blue = 36
// gray = 37
//)
//
//type LogFormatter struct{}
//
//// Format 格式化日志 实现Formatter
//func (t LogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
// //根据不同level展示颜色
// var levelColor int
// switch entry.Level {
// case logrus.DebugLevel, logrus.TraceLevel:
// levelColor = gray
// case logrus.WarnLevel:
// levelColor = yellow
// case logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel:
// levelColor = red
// default:
// levelColor = blue
// }
// var b *bytes.Buffer
//
// if entry.Buffer != nil {
// b = entry.Buffer
// } else {
// b = &bytes.Buffer{}
// }
//
// log := global.Config.Logger
//
// //自定义日期格式
// timesTamp := entry.Time.Format("2006-01-02 15:04:05")
// if entry.HasCaller() {
// //自定义文件路径
// funcVal := entry.Caller.Function
// fileVal := fmt.Sprintf("%s:%d", path.Base(entry.Caller.File), entry.Caller.Line)
// //自定义输出路径
// _, _ = fmt.Fprintf(b, "%s[%s] \x1b[%dm[%s]\x1b[0m %s %s %s\n", log.Prefix, timesTamp, levelColor, entry.Level, funcVal, fileVal, entry.Message)
// } else {
// _, _ = fmt.Fprintf(b, "%s[%s] \x1b[%dm[%s]\x1b[0m %s\n", log.Prefix, timesTamp, levelColor, entry.Level, entry.Message)
// }
// return b.Bytes(), nil
//}
//
//func InitLogger() *logrus.Logger {
// mLog := logrus.New() //创建一个实例
// mLog.SetOutput(os.Stdout) //设置输出类型
// mLog.SetReportCaller(global.Config.Logger.ShowLine) //开启返回函数名 和 行号
// mLog.SetFormatter(&LogFormatter{}) //设置自己定义的LogFormatter
// level, err := logrus.ParseLevel(global.Config.Logger.Level)
// if err != nil {
// level = logrus.InfoLevel
// }
// mLog.SetLevel(level) //设置最低的Level
// InitDefaultLogger() //调用全局log
// return mLog
//}
//
//func InitDefaultLogger() {
// //全局log
// logrus.SetOutput(os.Stdout) //设置输出类型
// logrus.SetReportCaller(global.Config.Logger.ShowLine)
// logrus.SetFormatter(&LogFormatter{})
// level, err := logrus.ParseLevel(global.Config.Logger.Level)
// if err != nil {
// level = logrus.InfoLevel
// }
// logrus.SetLevel(level) //设置最低的Level
//}

package core

import (
Expand All @@ -104,9 +20,8 @@ const (

type LogFormatter struct{}

// Format 格式化日志 实现Formatter
// Format formats the log entry to include colored level indicators and caller information
func (t LogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
// 根据不同level展示颜色
var levelColor int
switch entry.Level {
case logrus.DebugLevel, logrus.TraceLevel:
Expand All @@ -127,60 +42,40 @@ func (t LogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
}

log := global.Config.Logger

// 自定义日期格式
timesTamp := entry.Time.Format("2006-01-02 15:04:05")
timeStamp := entry.Time.Format("2006-01-02 15:04:05")
if entry.HasCaller() {
// 自定义文件路径
funcVal := entry.Caller.Function
fileVal := fmt.Sprintf("%s:%d", path.Base(entry.Caller.File), entry.Caller.Line)
// 自定义输出路径
_, _ = fmt.Fprintf(b, "%s[%s] \x1b[%dm[%s]\x1b[0m %s %s %s\n", log.Prefix, timesTamp, levelColor, entry.Level, funcVal, fileVal, entry.Message)
_, _ = fmt.Fprintf(b, "%s[%s] \x1b[%dm[%s]\x1b[0m %s %s %s\n", log.Prefix, timeStamp, levelColor, entry.Level, funcVal, fileVal, entry.Message)
} else {
_, _ = fmt.Fprintf(b, "%s[%s] \x1b[%dm[%s]\x1b[0m %s\n", log.Prefix, timesTamp, levelColor, entry.Level, entry.Message)
_, _ = fmt.Fprintf(b, "%s[%s] \x1b[%dm[%s]\x1b[0m %s\n", log.Prefix, timeStamp, levelColor, entry.Level, entry.Message)
}
return b.Bytes(), nil
}

func InitLogger() *logrus.Logger {
mLog := logrus.New() // 创建一个实例
mLog.SetOutput(os.Stdout) // 设置输出类型
mLog.SetReportCaller(global.Config.Logger.ShowLine) // 开启返回函数名和行号
mLog.SetFormatter(&LogFormatter{}) // 设置自定义的LogFormatter

mLog := logrus.New()
mLog.SetOutput(os.Stdout)
mLog.SetReportCaller(global.Config.Logger.ShowLine)
mLog.SetFormatter(&LogFormatter{})
level, err := logrus.ParseLevel(global.Config.Logger.Level)
if err != nil {
level = logrus.InfoLevel
}
mLog.SetLevel(level) // 设置最低的Level

// 添加文件日志
fileWriter := createLogFile()
if fileWriter != nil {
mLog.SetOutput(io.MultiWriter(os.Stdout, fileWriter))
}

InitDefaultLogger() // 调用全局log
mLog.SetLevel(level)
scheduleLogRotation(mLog)
return mLog
}

func InitDefaultLogger() {
// 全局log
logrus.SetOutput(os.Stdout) // 设置输出类型
logrus.SetReportCaller(global.Config.Logger.ShowLine)
logrus.SetFormatter(&LogFormatter{})

level, err := logrus.ParseLevel(global.Config.Logger.Level)
if err != nil {
level = logrus.InfoLevel
}
logrus.SetLevel(level) // 设置最低的Level

// 添加文件日志
fileWriter := createLogFile()
if fileWriter != nil {
logrus.SetOutput(io.MultiWriter(os.Stdout, fileWriter))
}
func scheduleLogRotation(logger *logrus.Logger) {
go func() {
for range time.NewTicker(24 * time.Hour).C {
fileWriter := createLogFile()
if fileWriter != nil {
logger.SetOutput(io.MultiWriter(os.Stdout, fileWriter))
}
}
}()
}

func createLogFile() *os.File {
Expand Down
10 changes: 7 additions & 3 deletions internal/service/Init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ func NewAppService() *AppService {
}

func (svc *AppService) Init() {
svc.scheduleTasks()
svc.cron.Start()
//svc.scheduleTasks()

//svc.cron.Start()

//svc.StartTestCX()
svc.StartGongxueYun("sign")
//select {}
}

func (svc *AppService) scheduleTasks() {
Expand All @@ -31,7 +36,6 @@ func (svc *AppService) scheduleTasks() {
svc.addCronTask("0 8 * * *", "每天早上8点签到", "sign")
svc.addCronTask("0 18 * * *", "每天晚上6点签到", "sign")
svc.addCronTask("0 10 * * 5", "每周周五早上10点签到", "week")

svc.cron.AddFunc("0 10 ? * 1L", func() {
if isLastWeek(time.Now()) {
global.Log.Info("Running task: 每月最后一周的周一早上10点签到")
Expand Down
119 changes: 119 additions & 0 deletions internal/service/cx_service/data/ssologin_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package data

type AccinfoData struct {
Msg struct {
Fid int `json:"fid"`
Rosterrights int `json:"rosterrights"`
CodeInfos struct {
HomeConfig struct {
Weburl string `json:"weburl"`
Dwtype int `json:"dwtype"`
Hometype int `json:"hometype"`
} `json:"homeConfig"`
} `json:"codeInfos"`
Boundaccount int `json:"boundaccount"`
LoginId int `json:"loginId"`
CodeInfo struct {
} `json:"codeInfo"`
Pic string `json:"pic"`
Source string `json:"source"`
Type int `json:"type"`
Ranknum string `json:"ranknum"`
IsCertify int `json:"isCertify"`
Uname string `json:"uname"`
CopyRight int `json:"copyRight"`
UnitConfig struct {
} `json:"unitConfig"`
Schoolname string `json:"schoolname"`
UnitConfigInfo struct {
HpConfig struct {
ShowBaseHp int `json:"showBaseHp"`
ShowMicroServiceHp int `json:"showMicroServiceHp"`
} `json:"hpConfig"`
Xb int `json:"xb"`
} `json:"unitConfigInfo"`
UnitConfigInfos []struct {
Fid int `json:"fid"`
HpConfig struct {
ShowBaseHp int `json:"showBaseHp"`
ShowMicroServiceHp int `json:"showMicroServiceHp"`
} `json:"hpConfig"`
Xb int `json:"xb"`
Schoolname string `json:"schoolname"`
} `json:"unitConfigInfos"`
Phone string `json:"phone"`
BindFanya bool `json:"bindFanya"`
UpdateWay string `json:"updateWay"`
Name string `json:"name"`
Fullpinyin string `json:"fullpinyin"`
UserConfig struct {
Recommend struct {
All int `json:"all"`
} `json:"recommend"`
} `json:"userConfig"`
Status int `json:"status"`
SwitchInfo string `json:"switchInfo"`
Roleid string `json:"roleid"`
Controlinfo struct {
InitializedRole string `json:"initializedRole"`
Selected string `json:"selected"`
} `json:"controlinfo"`
Industry int `json:"industry"`
Uid int `json:"uid"`
Acttime2 string `json:"acttime2"`
Dxfid string `json:"dxfid"`
Puid int `json:"puid"`
Rights int `json:"rights"`
NeedIntruction int `json:"needIntruction"`
Openid4 string `json:"openid4"`
BindOpac bool `json:"bindOpac"`
Ppfid string `json:"ppfid"`
AccountInfo struct {
CxOpac struct {
LoginId int `json:"loginId"`
Tiptitle string `json:"tiptitle"`
LoginUrl string `json:"loginUrl"`
BoundUrl string `json:"boundUrl"`
Tippwd string `json:"tippwd"`
Tipuname string `json:"tipuname"`
} `json:"cx_opac"`
ImAccount struct {
Uid int `json:"uid"`
Password string `json:"password"`
Created int64 `json:"created"`
Modified int64 `json:"modified"`
Type string `json:"type"`
Uuid string `json:"uuid"`
Activated int `json:"activated"`
Username string `json:"username"`
} `json:"imAccount"`
CxFanya struct {
LoginId int `json:"loginId"`
CopyRight int `json:"copyRight"`
Roleid string `json:"roleid"`
Countrycode string `json:"countrycode"`
Tippwd string `json:"tippwd"`
Result bool `json:"result"`
Uid int `json:"uid"`
Dxfid string `json:"dxfid"`
Tiptitle string `json:"tiptitle"`
LoginUrl string `json:"loginUrl"`
Schoolid int `json:"schoolid"`
Time int64 `json:"time"`
BoundUrl string `json:"boundUrl"`
Tipuname string `json:"tipuname"`
IsCertify int `json:"isCertify"`
Cxid int `json:"cxid"`
CreateDate string `json:"createDate"`
Status int `json:"status"`
} `json:"cx_fanya"`
} `json:"accountInfo"`
Simplepinyin string `json:"simplepinyin"`
Sex int `json:"sex"`
IsNewUser int `json:"isNewUser"`
Studentcode string `json:"studentcode"`
PrivacyPolicyVersion int `json:"privacyPolicyVersion"`
Inputfid int `json:"inputfid"`
} `json:"msg"`
Result int `json:"result"`
}
Loading

0 comments on commit df661ac

Please sign in to comment.