mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
增加拓展,封装每日更新代码和工作日信息
This commit is contained in:
24
codes.go
24
codes.go
@@ -136,7 +136,7 @@ func (this *Codes) Code(byDatabase bool) ([]*CodeModel, error) {
|
||||
}
|
||||
|
||||
//4. 插入或者更新数据库
|
||||
err := this.SessionFunc(func(session *xorm.Session) error {
|
||||
err := NewSessionFunc(this.db, func(session *xorm.Session) error {
|
||||
for _, v := range insert {
|
||||
if _, err := session.Insert(v); err != nil {
|
||||
return err
|
||||
@@ -157,8 +157,17 @@ func (this *Codes) Code(byDatabase bool) ([]*CodeModel, error) {
|
||||
|
||||
}
|
||||
|
||||
func (this *Codes) SessionFunc(fn func(session *xorm.Session) error) error {
|
||||
session := this.db.NewSession()
|
||||
type CodeModel struct {
|
||||
ID int64 `json:"id"` //主键
|
||||
Name string `json:"name"` //名称,有时候名称会变,例STxxx
|
||||
Code string `json:"code" xorm:"index"` //代码
|
||||
Exchange string `json:"exchange" xorm:"index"` //交易所
|
||||
EditDate int64 `json:"editDate" xorm:"updated"` //修改时间
|
||||
InDate int64 `json:"inDate" xorm:"created"` //创建时间
|
||||
}
|
||||
|
||||
func NewSessionFunc(db *xorm.Engine, fn func(session *xorm.Session) error) error {
|
||||
session := db.NewSession()
|
||||
defer session.Close()
|
||||
if err := session.Begin(); err != nil {
|
||||
session.Rollback()
|
||||
@@ -174,12 +183,3 @@ func (this *Codes) SessionFunc(fn func(session *xorm.Session) error) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CodeModel struct {
|
||||
ID int64 `json:"id"` //主键
|
||||
Name string `json:"name"` //名称,有时候名称会变,例STxxx
|
||||
Code string `json:"code" xorm:"index"` //代码
|
||||
Exchange string `json:"exchange" xorm:"index"` //交易所
|
||||
EditDate int64 `json:"editDate" xorm:"updated"` //修改时间
|
||||
InDate int64 `json:"inDate" xorm:"created"` //创建时间
|
||||
}
|
||||
|
||||
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