test vault status
This commit is contained in:
parent
63c9371ee4
commit
7c063108ce
106
job.go
106
job.go
@ -329,29 +329,29 @@ func jobPillage(j Job) {
|
|||||||
logOnError(err, "jobPillage : Unmarshal payload")
|
logOnError(err, "jobPillage : Unmarshal payload")
|
||||||
|
|
||||||
// check if we have a acknoledgment of go or a timeout within 3m30 of the PillageInc from the Job
|
// check if we have a acknoledgment of go or a timeout within 3m30 of the PillageInc from the Job
|
||||||
ids := getSQLListID64(` select ox.id
|
ids := getSQLListID64(`SELECT ox.id
|
||||||
from obj ox
|
FROM obj ox
|
||||||
,obj_msg omx
|
,obj_msg omx
|
||||||
,obj op
|
,obj op
|
||||||
,obj_msg omp
|
,obj_msg omp
|
||||||
,obj_job oj
|
,obj_job oj
|
||||||
where oj.obj_id = ` + strconv.FormatInt(j.ID64, 10) + `
|
WHERE oj.obj_id = ` + strconv.FormatInt(j.ID64, 10) + `
|
||||||
and omx.user_id = oj.user_id
|
AND omx.user_id = oj.user_id
|
||||||
and omx.sender_user_id = ` + strconv.Itoa(userID64ChtWrsBot) + `
|
AND omx.sender_user_id = ` + strconv.Itoa(userID64ChtWrsBot) + `
|
||||||
and omx.obj_id = ox.id
|
AND omx.obj_id = ox.id
|
||||||
and ox.obj_sub_type_id in (` + strconv.Itoa(objSubTypeMessagePillageGo) +
|
AND ox.obj_sub_type_id in (` + strconv.Itoa(objSubTypeMessagePillageGo) +
|
||||||
`, ` + strconv.Itoa(objSubTypeMessagePillageTimeout) +
|
`, ` + strconv.Itoa(objSubTypeMessagePillageTimeout) +
|
||||||
`, ` + strconv.Itoa(objSubTypeMessagePillageLoss) +
|
`, ` + strconv.Itoa(objSubTypeMessagePillageLoss) +
|
||||||
`, ` + strconv.Itoa(objSubTypeMessagePillageWin) + `)
|
`, ` + strconv.Itoa(objSubTypeMessagePillageWin) + `)
|
||||||
and op.id = ` + strconv.FormatInt(r.ObjID64, 10) + `
|
AND op.id = ` + strconv.FormatInt(r.ObjID64, 10) + `
|
||||||
and omp.obj_id = op.id
|
AND omp.obj_id = op.id
|
||||||
and omx.date between omp.date and addtime(omp.date, '0 0:3:30.000000')
|
AND omx.date between omp.date AND ADDTIME(omp.date, '0 0:3:30.000000')
|
||||||
order by case ox.obj_sub_type_id when ` + strconv.Itoa(objSubTypeMessagePillageWin) + ` then 0
|
ORDER BY CASE ox.obj_sub_type_id WHEN ` + strconv.Itoa(objSubTypeMessagePillageWin) + ` THEN 0
|
||||||
when ` + strconv.Itoa(objSubTypeMessagePillageLoss) + ` then 1
|
WHEN ` + strconv.Itoa(objSubTypeMessagePillageLoss) + ` THEN 1
|
||||||
when ` + strconv.Itoa(objSubTypeMessagePillageTimeout) + ` then 2
|
WHEN ` + strconv.Itoa(objSubTypeMessagePillageTimeout) + ` THEN 2
|
||||||
when ` + strconv.Itoa(objSubTypeMessagePillageGo) + ` then 3
|
WHEN ` + strconv.Itoa(objSubTypeMessagePillageGo) + ` THEN 3
|
||||||
else 4 end asc
|
ELSE 4 END ASC
|
||||||
limit 1;`)
|
LIMIT 1;`)
|
||||||
|
|
||||||
if len(ids) > 1 { // issue there ?
|
if len(ids) > 1 { // issue there ?
|
||||||
s := TGCommand{
|
s := TGCommand{
|
||||||
@ -893,13 +893,77 @@ func jobGDeposit(j Job) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func jobVaultStatus(j Job) {
|
func jobVaultStatus(j Job) {
|
||||||
var p JobPayloadVaultStatus
|
var (
|
||||||
|
p JobPayloadVaultStatus
|
||||||
|
userID64, currentUserID64 int64
|
||||||
|
itemID64, deposit, withdraw int64
|
||||||
|
itemList, depositList, withdrawList []int64
|
||||||
|
)
|
||||||
|
|
||||||
err := setJobStart(j.ID64)
|
err := setJobStart(j.ID64)
|
||||||
logOnError(err, "jobVaultStatus : setJobStart")
|
logOnError(err, "jobVaultStatus : setJobStart")
|
||||||
|
|
||||||
err = json.Unmarshal(j.Payload, &p)
|
err = json.Unmarshal(j.Payload, &p)
|
||||||
logOnError(err, "jobVaultStatus : Unmarshal payload")
|
logOnError(err, "jobVaultStatus : Unmarshal payload")
|
||||||
|
|
||||||
|
stmt := `SELECT x.user_id
|
||||||
|
,x.item_id
|
||||||
|
,(SELECT COALESCE(SUM(omv.quantity), 0)
|
||||||
|
FROM obj_msg_vault_v omv
|
||||||
|
WHERE omv.user_id = x.user_id
|
||||||
|
AND omv.item_id = x.item_id
|
||||||
|
AND omv.msg_type_id = ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `
|
||||||
|
AND omv.chat_id = x.chat_id) deposit
|
||||||
|
,(SELECT COALESCE(SUM(omv.quantity), 0)
|
||||||
|
FROM obj_msg_vault_v omv
|
||||||
|
WHERE omv.user_id = x.user_id
|
||||||
|
AND omv.item_id = x.item_id
|
||||||
|
AND omv.msg_type_id = ` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `
|
||||||
|
AND omv.chat_id = x.chat_id) withdraw
|
||||||
|
FROM (SELECT DISTINCT
|
||||||
|
omv.user_id
|
||||||
|
,omv.chat_id
|
||||||
|
,omv.item_id
|
||||||
|
FROM obj_msg_vault_v omv
|
||||||
|
WHERE omv.chat_id = ?
|
||||||
|
AND omv.user_id in (?` + strings.Repeat(",?", len(p.UserListID64)-1) + `)
|
||||||
|
AND omv.item_type_id in (?` + strings.Repeat(",?", len(p.ItemTypeListID64)-1) + `)) x
|
||||||
|
ORDER BY x.user_id ASC;`
|
||||||
|
|
||||||
|
rows, err := db.Query(stmt, p.DepositChatID64, p.UserListID64..., p.ItemTypeListID64...)
|
||||||
|
logOnError(err, "jobVaultStatus : Get rows")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = setJobDone(j.ID64)
|
||||||
|
logOnError(err, "jobVaultStatus : setJobDone")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
currentUserID64 = 0
|
||||||
|
for rows.Next() {
|
||||||
|
err = rows.Scan(&userID64, &itemID64, &deposit, &withdraw)
|
||||||
|
logOnError(err, "jobVaultStatus : scan next val")
|
||||||
|
if userID64 != currentUserID64 {
|
||||||
|
if currentUserID64 != 0 {
|
||||||
|
// display info
|
||||||
|
}
|
||||||
|
itemList = nil
|
||||||
|
depositList = nil
|
||||||
|
withdrawList = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
itemList = append(itemList, itemID64)
|
||||||
|
depositList = append(depositList, deposit)
|
||||||
|
withdrawList = append(withdrawList, withdraw)
|
||||||
|
}
|
||||||
|
if currentUserID64 != 0 {
|
||||||
|
//display info
|
||||||
|
}
|
||||||
|
err = rows.Err()
|
||||||
|
logOnError(err, "jobVaultStatus : query end")
|
||||||
|
rows.Close()
|
||||||
|
|
||||||
|
|
||||||
err = setJobDone(j.ID64)
|
err = setJobDone(j.ID64)
|
||||||
logOnError(err, "jobVaultStatus : setJobDone")
|
logOnError(err, "jobVaultStatus : setJobDone")
|
||||||
|
|
||||||
|
15
sql.go
15
sql.go
@ -585,16 +585,17 @@ func initDB() {
|
|||||||
_, err = db.Exec(`CREATE VIEW obj_msg_vault_v AS
|
_, err = db.Exec(`CREATE VIEW obj_msg_vault_v AS
|
||||||
SELECT om.sender_user_id user_id
|
SELECT om.sender_user_id user_id
|
||||||
,om.chat_id
|
,om.chat_id
|
||||||
,o.obj_sub_type_id msg_type_id
|
,om.obj_sub_type_id msg_type_id
|
||||||
,omi.item_id
|
,omi.item_id
|
||||||
|
,oi.obj_sub_type_id item_type_id
|
||||||
,omi.quantity
|
,omi.quantity
|
||||||
FROM obj o
|
FROM obj om
|
||||||
,obj_msg om
|
,obj oi
|
||||||
,obj_msg_item omi
|
,obj_msg_item omi
|
||||||
WHERE o.id = om.obj_id
|
WHERE om.obj_type_id = ` + strconv.Itoa(objTypeMessage) + `
|
||||||
AND o.obj_type_id = ` + strconv.Itoa(objTypeMessage) + `
|
AND om.obj_sub_type_id in (` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `)
|
||||||
AND o.obj_sub_type_id in (` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `)
|
|
||||||
AND omi.obj_id = o.id
|
AND omi.obj_id = o.id
|
||||||
|
AND oi.id = omi.item_id
|
||||||
ORDER BY om.sender_user_id ASC
|
ORDER BY om.sender_user_id ASC
|
||||||
,omi.item_id ASC;`)
|
,omi.item_id ASC;`)
|
||||||
failOnError(err, "initDB : create view obj_msg_vault_v")
|
failOnError(err, "initDB : create view obj_msg_vault_v")
|
||||||
@ -604,8 +605,6 @@ func initDB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func insertMsgItem(objId int64, itemId int64, quantity int64) error {
|
func insertMsgItem(objId int64, itemId int64, quantity int64) error {
|
||||||
log.Printf("insertMsgItem inserting (%d, %d, %d)\n", objId, itemId, quantity)
|
|
||||||
|
|
||||||
stmt, err := db.Prepare(`INSERT INTO obj_msg_item (obj_id, item_id, quantity)
|
stmt, err := db.Prepare(`INSERT INTO obj_msg_item (obj_id, item_id, quantity)
|
||||||
VALUES (?, ?, ?);`)
|
VALUES (?, ?, ?);`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user