mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
增加拓展,封装每日更新代码和工作日信息
This commit is contained in:
20
workday.go
20
workday.go
@@ -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"` //主键
|
||||
|
||||
Reference in New Issue
Block a user