|
|
@ -1,8 +1,12 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"time" |
|
|
|
|
|
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb" |
|
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskgin" |
|
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hsklogger/L" |
|
|
|
"xorm.io/builder" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
@ -10,11 +14,12 @@ import ( |
|
|
|
type Temp3A60 struct { |
|
|
|
Id int |
|
|
|
service string |
|
|
|
QueueStatus string |
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------temp------------------------------------
|
|
|
|
|
|
|
|
//wherePrimaryKey 主键查询
|
|
|
|
// wherePrimaryKey 主键查询
|
|
|
|
func (TempLowHead3A60 *Temp3A60) wherePrimaryKey() (q interface{}, args []interface{}) { |
|
|
|
//todo 根据需求修改
|
|
|
|
return "`id`=?", []interface{}{ |
|
|
@ -22,53 +27,53 @@ func (TempLowHead3A60 *Temp3A60) wherePrimaryKey() (q interface{}, args []interf |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//wherePrimaryKeyWithCond 主键查询
|
|
|
|
// wherePrimaryKeyWithCond 主键查询
|
|
|
|
func (TempLowHead3A60 *Temp3A60) wherePrimaryKeyWithCond() builder.Cond { |
|
|
|
//todo 根据需求修改
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//whereDataWithCond 列表查询
|
|
|
|
// whereDataWithCond 列表查询
|
|
|
|
func (TempLowHead3A60 *Temp3A60) whereDataWithCond() builder.Cond { |
|
|
|
//todo 根据需求修改
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//whereData 列表查询筛选
|
|
|
|
// whereData 列表查询筛选
|
|
|
|
func (TempLowHead3A60 *Temp3A60) whereData() (q interface{}, args []interface{}) { |
|
|
|
//todo
|
|
|
|
return "", nil |
|
|
|
} |
|
|
|
|
|
|
|
//orderData 列表查询排序
|
|
|
|
// orderData 列表查询排序
|
|
|
|
func (TempLowHead3A60 *Temp3A60) orderData() string { |
|
|
|
//todo
|
|
|
|
return "`id` desc" |
|
|
|
} |
|
|
|
|
|
|
|
//init 数据初始化,可附加更多数据
|
|
|
|
// init 数据初始化,可附加更多数据
|
|
|
|
func (TempLowHead3A60 *Temp3A60) init() { |
|
|
|
//todo
|
|
|
|
} |
|
|
|
|
|
|
|
//saveAllCols 保存时是否全量保存
|
|
|
|
// saveAllCols 保存时是否全量保存
|
|
|
|
func (TempLowHead3A60 *Temp3A60) isSaveAllCols() bool { |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
//insertPretreatment 新增前预处理
|
|
|
|
// insertPretreatment 新增前预处理
|
|
|
|
func (TempLowHead3A60 *Temp3A60) insertPretreatment() error { |
|
|
|
//todo
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//updatePretreatment 修改前预处理
|
|
|
|
// updatePretreatment 修改前预处理
|
|
|
|
func (TempLowHead3A60 *Temp3A60) updatePretreatment() error { |
|
|
|
//todo
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//deletePretreatment 删除前预处理
|
|
|
|
// deletePretreatment 删除前预处理
|
|
|
|
func (TempLowHead3A60 *Temp3A60) deletePretreatment() error { |
|
|
|
//todo
|
|
|
|
return nil |
|
|
@ -79,9 +84,29 @@ func (TempLowHead3A60 *Temp3A60) getXorm() *xorm.Engine { |
|
|
|
return hskdb.GetXormAuto() |
|
|
|
} |
|
|
|
|
|
|
|
// 队列状态
|
|
|
|
const ( |
|
|
|
Temp3A60QueueWait = 2 * time.Second |
|
|
|
Temp3A60QueueStatusNone = "None" |
|
|
|
Temp3A60QueueStatusIng = "Ing" |
|
|
|
Temp3A60QueueStatusSuccess = "Success" |
|
|
|
Temp3A60QueueStatusFail = "Fail" |
|
|
|
) |
|
|
|
|
|
|
|
// 不同service对应的不同队列状态
|
|
|
|
var Temp3A60QueueStatusFieldMap = map[string]string{ |
|
|
|
"service": "queue_status", |
|
|
|
} |
|
|
|
|
|
|
|
// 队列事件
|
|
|
|
func (TempLowHead3A60 *Temp3A60) queueEvent() error { |
|
|
|
//todo
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------temp------------------------------------
|
|
|
|
|
|
|
|
//Save 保存或者新增,通过wherePrimaryKey查不到数据时,新增数据,否则修改数据,参数:isAllCols...
|
|
|
|
// Save 保存或者新增,通过wherePrimaryKey查不到数据时,新增数据,否则修改数据,参数:isAllCols...
|
|
|
|
func (TempLowHead3A60 *Temp3A60) Save(isAllCols ...bool) (err error) { |
|
|
|
if TempLowHead3A60.service == "" { |
|
|
|
TempLowHead3A60.service = "none" |
|
|
@ -132,7 +157,7 @@ func (TempLowHead3A60 *Temp3A60) Save(isAllCols ...bool) (err error) { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//Load 为实例载入数据,数据来源取决于wherePrimaryKey查找实例中的数据
|
|
|
|
// Load 为实例载入数据,数据来源取决于wherePrimaryKey查找实例中的数据
|
|
|
|
func (TempLowHead3A60 *Temp3A60) Load() (err error) { |
|
|
|
if TempLowHead3A60.service == "" { |
|
|
|
TempLowHead3A60.service = "none" |
|
|
@ -158,7 +183,7 @@ func (TempLowHead3A60 *Temp3A60) Load() (err error) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//Data 不进行分页的数据列表
|
|
|
|
// Data 不进行分页的数据列表
|
|
|
|
func (TempLowHead3A60 *Temp3A60) Data() (data []Temp3A60) { |
|
|
|
if TempLowHead3A60.service == "" { |
|
|
|
TempLowHead3A60.service = "none" |
|
|
@ -193,7 +218,7 @@ func (TempLowHead3A60 *Temp3A60) Data() (data []Temp3A60) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//PageData 进行分页的数据列表,page从0开始
|
|
|
|
// PageData 进行分页的数据列表,page从0开始
|
|
|
|
func (TempLowHead3A60 *Temp3A60) PageData(page, pageSize int) (data []Temp3A60, count int64) { |
|
|
|
if TempLowHead3A60.service == "" { |
|
|
|
TempLowHead3A60.service = "none" |
|
|
@ -226,7 +251,7 @@ func (TempLowHead3A60 *Temp3A60) PageData(page, pageSize int) (data []Temp3A60, |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//Delete 删除数据
|
|
|
|
// Delete 删除数据
|
|
|
|
func (TempLowHead3A60 *Temp3A60) Delete() (err error) { |
|
|
|
if TempLowHead3A60.service == "" { |
|
|
|
TempLowHead3A60.service = "none" |
|
|
@ -253,6 +278,64 @@ func (TempLowHead3A60 *Temp3A60) Delete() (err error) { |
|
|
|
|
|
|
|
// ----------------------------temp------------------------------------
|
|
|
|
|
|
|
|
func StartQueueTaskPrefixHigHead3A60Temp3A60() { |
|
|
|
serviceName := "Prefix3A60" |
|
|
|
f := Temp3A60QueueStatusFieldMap[serviceName] |
|
|
|
go func() { |
|
|
|
defer func() { |
|
|
|
err := recover() |
|
|
|
if err != nil { |
|
|
|
L.Error("StartQueueTaskPrefixHigHead3A60Temp3A60意外退出:", err) |
|
|
|
} |
|
|
|
time.Sleep(time.Second * 5) |
|
|
|
|
|
|
|
StartQueueTaskPrefixHigHead3A60Temp3A60() |
|
|
|
}() |
|
|
|
|
|
|
|
for { |
|
|
|
onec := &Temp3A60{} |
|
|
|
hskdb.GetXormAuto().Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).OrderBy("rand()").Find(&onec) |
|
|
|
|
|
|
|
session := onec.getXorm().NewSession() |
|
|
|
defer session.Close() |
|
|
|
whereQuery, whereArgs := onec.wherePrimaryKey() |
|
|
|
whereCond := onec.wherePrimaryKeyWithCond() |
|
|
|
if whereQuery != "" { |
|
|
|
session = session.Where(whereQuery, whereArgs...) |
|
|
|
} |
|
|
|
if whereCond != nil { |
|
|
|
session = session.Where(whereCond) |
|
|
|
} |
|
|
|
|
|
|
|
i, err := session.Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).Update(map[string]interface{}{f: Temp3A60QueueStatusIng}) |
|
|
|
if err == nil && i == 1 { |
|
|
|
func() { |
|
|
|
{ |
|
|
|
err := onec.queueEvent() |
|
|
|
session := onec.getXorm().NewSession() |
|
|
|
defer session.Close() |
|
|
|
whereQuery, whereArgs := onec.wherePrimaryKey() |
|
|
|
whereCond := onec.wherePrimaryKeyWithCond() |
|
|
|
if whereQuery != "" { |
|
|
|
session = session.Where(whereQuery, whereArgs...) |
|
|
|
} |
|
|
|
if whereCond != nil { |
|
|
|
session = session.Where(whereCond) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
session.Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).Update(map[string]interface{}{f: Temp3A60QueueStatusFail}) |
|
|
|
} else { |
|
|
|
session.Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).Update(map[string]interface{}{f: Temp3A60QueueStatusSuccess}) |
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
} |
|
|
|
time.Sleep(Temp3A60QueueWait) |
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
} |
|
|
|
|
|
|
|
func InitializationHttpCrudPrefixHigHead3A60Temp3A60(router *hskgin.GinHelper, authoritys ...func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60)) { |
|
|
|
var authority = func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60) { |
|
|
|
} |
|
|
@ -311,5 +394,3 @@ func InitializationHttpCrudPrefixHigHead3A60Temp3A60(router *hskgin.GinHelper, a |
|
|
|
ctx.DisplayBySuccess("删除成功") |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------temp------------------------------------
|