增加拓展,封装每日更新代码和工作日信息

This commit is contained in:
injoyai
2025-02-21 14:27:37 +08:00
parent eb243b4ac7
commit e9f3d0ac62
2 changed files with 13 additions and 31 deletions

View File

@@ -81,7 +81,7 @@ func (this *Workday) Update() error {
return err
}
this.SessionFunc(func(session *xorm.Session) error {
return NewSessionFunc(this.db, func(session *xorm.Session) error {
for _, v := range resp.List {
if unix := v.Time.Unix(); unix > lastWorkday.Unix {
_, err = session.Insert(&WorkdayModel{Unix: unix, Date: v.Time.Format("20060102"), Is: true})
@@ -108,24 +108,6 @@ func (this *Workday) TodayIs() bool {
return this.Is(time.Now())
}
func (this *Workday) SessionFunc(fn func(session *xorm.Session) error) error {
session := this.db.NewSession()
defer session.Close()
if err := session.Begin(); err != nil {
session.Rollback()
return err
}
if err := fn(session); err != nil {
session.Rollback()
return err
}
if err := session.Commit(); err != nil {
session.Rollback()
return err
}
return nil
}
// WorkdayModel 工作日
type WorkdayModel struct {
ID int64 `json:"id"` //主键