test
This commit is contained in:
parent
dda6943c50
commit
87249e141c
|
@ -0,0 +1,136 @@
|
|||
package queuelist
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/qit-team/snow-core/db"
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
m *queuelistModel
|
||||
)
|
||||
|
||||
/**
|
||||
* QueueList
|
||||
*/
|
||||
type QueueList struct {
|
||||
Id int64 `xorm:"pk autoincr"` //注:使用getOne 或者ID() 需要设置主键
|
||||
Name string `xorm:"name"`
|
||||
QueueNo int64 `xorm:"queue_no"`
|
||||
Status int64 `xorm:"status"`
|
||||
Remark string `xorm:"remark"`
|
||||
CreatedAt time.Time `xorm:"created"`
|
||||
}
|
||||
|
||||
/**
|
||||
* 表名规则
|
||||
* @wiki http://gobook.io/read/github.com/go-xorm/manual-zh-CN/chapter-02/3.tags.html
|
||||
*/
|
||||
func (m *QueueList) TableName() string {
|
||||
return "queuelist"
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有化,防止被外部new
|
||||
*/
|
||||
type queuelistModel struct {
|
||||
db.Model //组合基础Model,集成基础Model的属性和方法
|
||||
}
|
||||
|
||||
// 单例模式
|
||||
func GetInstance() *queuelistModel {
|
||||
once.Do(func() {
|
||||
m = new(queuelistModel)
|
||||
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询主键ID的记录
|
||||
* @param id 主键ID
|
||||
* @return has 是否有记录
|
||||
* @return err 错误信息
|
||||
* @return queuelist 查询结果
|
||||
*/
|
||||
func (m *queuelistModel) GetById(id int64) (queuelist *QueueList, has bool, err error) {
|
||||
queuelist = &QueueList{}
|
||||
has, err = m.GetDb().ID(id).Get(queuelist)
|
||||
if err != nil || !has {
|
||||
queuelist = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *queuelistModel) Search(id int64, queue_no int64, name string, status int64, startTime string, endTime string, limit int, page int) (queuelist []*QueueList, err error) {
|
||||
queuelist = make([]*QueueList, 0)
|
||||
sql := "1=1"
|
||||
var args []interface{}
|
||||
if id != 0 {
|
||||
sql += " and id = ?"
|
||||
args = append(args, id)
|
||||
}
|
||||
if queue_no != 0 {
|
||||
sql += " and queue_no = ?"
|
||||
args = append(args, queue_no)
|
||||
}
|
||||
if name != "" {
|
||||
sql += " and name = ?"
|
||||
args = append(args, name)
|
||||
}
|
||||
if status != 0 {
|
||||
sql += " and status = ?"
|
||||
args = append(args, status)
|
||||
}
|
||||
if startTime != "" && endTime != "" {
|
||||
sql += " and created_at >= ? and created_at <= ?"
|
||||
args = append(args, startTime, endTime)
|
||||
}
|
||||
err = m.GetDb().Where(sql, args...).OrderBy("created_at desc").Limit(limit, page).Find(&queuelist)
|
||||
return
|
||||
}
|
||||
|
||||
func (m *queuelistModel) CountAll(id int64, queue_no int64, name string, status int64, startTime string, endTime string) (res int64, err error) {
|
||||
sql := "1=1"
|
||||
var args []interface{}
|
||||
if id != 0 {
|
||||
sql += " and id = ?"
|
||||
args = append(args, id)
|
||||
}
|
||||
if queue_no != 0 {
|
||||
sql += " and queue_no = ?"
|
||||
args = append(args, queue_no)
|
||||
}
|
||||
if name != "" {
|
||||
sql += " and name = ?"
|
||||
args = append(args, name)
|
||||
}
|
||||
if status != 0 {
|
||||
sql += " and status = ?"
|
||||
args = append(args, status)
|
||||
}
|
||||
if startTime != "" && endTime != "" {
|
||||
sql += " and created_at >= ? and created_at <= ?"
|
||||
args = append(args, startTime, endTime)
|
||||
}
|
||||
res, err = m.GetDb().Table("queuelist").Where(sql, args...).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (m *queuelistModel) Create(queuelist *QueueList) (affected int64, err error) {
|
||||
queuelist.CreatedAt = time.Now()
|
||||
affected, err = m.GetDb().Insert(queuelist)
|
||||
return
|
||||
}
|
||||
|
||||
func (m *queuelistModel) Update(queuelist *QueueList) (affected int64, err error) {
|
||||
affected, err = m.GetDb().ID(queuelist.Id).Update(queuelist)
|
||||
return
|
||||
}
|
||||
|
||||
func (m *queuelistModel) Delete(id int64) (affected int64, err error) {
|
||||
affected, err = m.GetDb().ID(id).Delete(&QueueList{})
|
||||
return
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package queuelist
|
||||
|
||||
import (
|
||||
models "com.snow.auto_monitor/app/models/queuelist"
|
||||
)
|
||||
|
||||
func GetLimitStart(limit int, page int) (int, int) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
if page > 0 {
|
||||
page = (page - 1) * limit
|
||||
} else {
|
||||
page = 0
|
||||
}
|
||||
return limit, page
|
||||
}
|
||||
|
||||
func GetById(id int64) (res *models.QueueList, err error) {
|
||||
res, _, err = models.GetInstance().GetById(id)
|
||||
return
|
||||
}
|
||||
|
||||
func Search(id int64, queue_no int64, name string, status int64, startTime string, endTime string, limit int, page int) (res []*models.QueueList, err error) {
|
||||
limit, page = GetLimitStart(limit, page)
|
||||
res, err = models.GetInstance().Search(id, queue_no, name, status, startTime, endTime, limit, page)
|
||||
return
|
||||
}
|
||||
|
||||
func CountAll(id int64, queue_no int64, name string, status int64, startTime string, endTime string) (res int64, err error) {
|
||||
res, err = models.GetInstance().CountAll(id, queue_no, name, status, startTime, endTime)
|
||||
return
|
||||
}
|
||||
|
||||
func Create(queuelist *models.QueueList) (affected int64, err error) {
|
||||
affected, err = models.GetInstance().Create(queuelist)
|
||||
return
|
||||
}
|
||||
|
||||
func Update(queuelist *models.QueueList) (affected int64, err error) {
|
||||
affected, err = models.GetInstance().Update(queuelist)
|
||||
return
|
||||
}
|
||||
|
||||
func Delete(id int64) (affected int64, err error) {
|
||||
affected, err = models.GetInstance().Delete(id)
|
||||
return
|
||||
}
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
models "com.snow.auto_monitor/app/models/orders"
|
||||
queueServ "com.snow.auto_monitor/app/services/queuelist"
|
||||
rdbmq "com.snow.auto_monitor/app/utils/rdbmq"
|
||||
)
|
||||
|
||||
|
@ -61,8 +62,21 @@ func WriteOrder() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
queues, err := queueServ.Search(0, 0, "", 0, "", "", 0, 0)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
queue_nos := make([]int64, 0)
|
||||
for _, queue := range queues {
|
||||
if queue.QueueNo == 0 {
|
||||
continue
|
||||
}
|
||||
queue_nos = append(queue_nos, queue.QueueNo)
|
||||
}
|
||||
|
||||
// 创建价格分组
|
||||
var queue_nos = [...]int{-5, -4, -3, -2, -1, 10, 20, 50, 100, 1000, 102, 10210, 10220, 10250, 102100, 1021000}
|
||||
for _, value := range queue_nos {
|
||||
err = rdbmq.CreateStreamAndGroup(fmt.Sprintf("orders_%d", value), fmt.Sprintf("orders_%d", value))
|
||||
if err != nil && err.Error() != "BUSYGROUP Consumer Group name already exists" {
|
||||
|
|
|
@ -67,3 +67,12 @@ create table ding_list (
|
|||
user_id varchar(64),
|
||||
created_at timestamp default current_timestamp
|
||||
);
|
||||
|
||||
create table queuelist (
|
||||
id int primary key auto_increment,
|
||||
queue_no int,
|
||||
name varchar(64),
|
||||
status tinyint,
|
||||
remark varchar(255),
|
||||
created_at timestamp default current_timestamp
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue