test vault item
This commit is contained in:
parent
3353f99731
commit
f80527d048
2
bot.go
2
bot.go
@ -739,7 +739,7 @@ func botVaultItem(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r := regexp.MustCompile("([a-z][0-9]{2}[a-e]{0,1})")
|
r := regexp.MustCompile("([a-z][0-9]{2}[a-e]{0,1})")
|
||||||
for _, l := range re.FindAllStringSubmatch(m.Payload, -1) {
|
for _, l := range r.FindAllStringSubmatch(m.Payload, -1) {
|
||||||
item := getObjItemID(l[1], ``)
|
item := getObjItemID(l[1], ``)
|
||||||
if item != 0 {
|
if item != 0 {
|
||||||
p.ItemListID64 = append(p.ItemListID64, item)
|
p.ItemListID64 = append(p.ItemListID64, item)
|
||||||
|
118
job.go
118
job.go
@ -895,8 +895,9 @@ func jobGDeposit(j Job) {
|
|||||||
func jobVaultItemStatus(j Job) {
|
func jobVaultItemStatus(j Job) {
|
||||||
var (
|
var (
|
||||||
p JobPayloadVaultItemStatus
|
p JobPayloadVaultItemStatus
|
||||||
//user, deposit, withdraw int64
|
itemID64, currentItemID64 int64
|
||||||
//userList, depositList, withdrawList []int64
|
user, deposit, withdraw int64
|
||||||
|
userList, depositList, withdrawList []int64
|
||||||
)
|
)
|
||||||
|
|
||||||
err := setJobStart(j.ID64)
|
err := setJobStart(j.ID64)
|
||||||
@ -905,6 +906,98 @@ func jobVaultItemStatus(j Job) {
|
|||||||
err = json.Unmarshal(j.Payload, &p)
|
err = json.Unmarshal(j.Payload, &p)
|
||||||
logOnError(err, "jobVaultItemStatus : Unmarshal payload")
|
logOnError(err, "jobVaultItemStatus : Unmarshal payload")
|
||||||
|
|
||||||
|
stmt := `SELECT x.item_id
|
||||||
|
,x.user_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.item_id in (?` + strings.Repeat(",?", len(p.ItemListID64)-1) + `)) x
|
||||||
|
ORDER BY x.user_id ASC;`
|
||||||
|
|
||||||
|
args := make([]interface{}, len(p.ItemListID64)+1)
|
||||||
|
args[0] = p.DepositChatID64
|
||||||
|
for i, id := range p.ItemListID64 {
|
||||||
|
args[i+1] = id
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := db.Query(stmt, args...)
|
||||||
|
logOnError(err, "jobVaultItemStatus : Get rows")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = setJobDone(j.ID64)
|
||||||
|
logOnError(err, "jobVaultItemStatus : setJobDone")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
currentItemID64 = 0
|
||||||
|
for rows.Next() {
|
||||||
|
err = rows.Scan(&itemID64, &userID64, &deposit, &withdraw)
|
||||||
|
logOnError(err, "jobVaultItemStatus : scan next val")
|
||||||
|
if itemID64 != currentItemID64 {
|
||||||
|
if currentUserID64 != 0 {
|
||||||
|
// display info
|
||||||
|
out := fmt.Sprintf("<code>%-32s | Depo. | Recv. | Total\n────────────────────────────┼──────┼──────┼──────\n", `User`)
|
||||||
|
for i, userId := range userList {
|
||||||
|
logOnError(err, "jobVaultItemStatus : getObjItem")
|
||||||
|
out = fmt.Sprintf("%s%-32d |%6d |%6d |%6d\n", out, userID, depositList[i], withdrawList[i], depositList[i]-withdrawList[i])
|
||||||
|
}
|
||||||
|
out = fmt.Sprintf("%s</code>", out)
|
||||||
|
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandSendMsg,
|
||||||
|
Text: out,
|
||||||
|
ToChatID64: p.UserID64,
|
||||||
|
ParseMode: cmdParseModeHTML,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
}
|
||||||
|
currentUserID64 = userID64
|
||||||
|
itemList = nil
|
||||||
|
depositList = nil
|
||||||
|
withdrawList = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
userList = append(userList, userID64)
|
||||||
|
depositList = append(depositList, deposit)
|
||||||
|
withdrawList = append(withdrawList, withdraw)
|
||||||
|
}
|
||||||
|
if currentUserID64 != 0 {
|
||||||
|
// display info
|
||||||
|
out := fmt.Sprintf("<code>%-32s | Depo. | Recv. | Total\n────────────────────────────┼──────┼──────┼──────\n", `User`)
|
||||||
|
for i, userId := range userList {
|
||||||
|
logOnError(err, "jobVaultItemStatus : getObjItem")
|
||||||
|
out = fmt.Sprintf("%s%-32d |%6d |%6d |%6d\n", out, userID, depositList[i], withdrawList[i], depositList[i]-withdrawList[i])
|
||||||
|
}
|
||||||
|
out = fmt.Sprintf("%s</code>", out)
|
||||||
|
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandSendMsg,
|
||||||
|
Text: out,
|
||||||
|
ToChatID64: p.UserID64,
|
||||||
|
ParseMode: cmdParseModeHTML,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
}
|
||||||
|
|
||||||
|
err = rows.Err()
|
||||||
|
logOnError(err, "jobVaultItemStatus : query end")
|
||||||
|
rows.Close()
|
||||||
|
|
||||||
err = setJobDone(j.ID64)
|
err = setJobDone(j.ID64)
|
||||||
logOnError(err, "jobVaultItemStatus : setJobDone")
|
logOnError(err, "jobVaultItemStatus : setJobDone")
|
||||||
|
|
||||||
@ -945,8 +1038,8 @@ func jobVaultUserStatus(j Job) {
|
|||||||
,omv.item_id
|
,omv.item_id
|
||||||
FROM obj_msg_vault_v omv
|
FROM obj_msg_vault_v omv
|
||||||
WHERE omv.chat_id = ?
|
WHERE omv.chat_id = ?
|
||||||
AND omv.user_id in (?` + strings.Repeat(",?", len(p.UserListID64)-1) + `)
|
AND omv.user_id IN (?` + strings.Repeat(",?", len(p.UserListID64)-1) + `)
|
||||||
AND omv.item_type_id in (?` + strings.Repeat(",?", len(p.ItemTypeListID64)-1) + `)) x
|
AND omv.item_type_id IN (?` + strings.Repeat(",?", len(p.ItemTypeListID64)-1) + `)) x
|
||||||
ORDER BY x.user_id ASC;`
|
ORDER BY x.user_id ASC;`
|
||||||
|
|
||||||
args := make([]interface{}, len(p.UserListID64)+len(p.ItemTypeListID64)+1)
|
args := make([]interface{}, len(p.UserListID64)+len(p.ItemTypeListID64)+1)
|
||||||
@ -974,6 +1067,21 @@ func jobVaultUserStatus(j Job) {
|
|||||||
if userID64 != currentUserID64 {
|
if userID64 != currentUserID64 {
|
||||||
if currentUserID64 != 0 {
|
if currentUserID64 != 0 {
|
||||||
// display info
|
// display info
|
||||||
|
out := fmt.Sprintf("<code>%-32s | Depo. | Recv. | Total\n────────────────────────────┼──────┼──────┼──────\n", `Item`)
|
||||||
|
for i, itemId := range itemList {
|
||||||
|
item, err := getObjItem(itemId)
|
||||||
|
logOnError(err, "jobVaultUserStatus : getObjItem")
|
||||||
|
out = fmt.Sprintf("%s%-32s |%6d |%6d |%6d\n", out, item.Name, depositList[i], withdrawList[i], depositList[i]-withdrawList[i])
|
||||||
|
}
|
||||||
|
out = fmt.Sprintf("%s</code>", out)
|
||||||
|
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandSendMsg,
|
||||||
|
Text: out,
|
||||||
|
ToChatID64: p.UserID64,
|
||||||
|
ParseMode: cmdParseModeHTML,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
}
|
}
|
||||||
currentUserID64 = userID64
|
currentUserID64 = userID64
|
||||||
itemList = nil
|
itemList = nil
|
||||||
@ -990,7 +1098,7 @@ func jobVaultUserStatus(j Job) {
|
|||||||
out := fmt.Sprintf("<code>%-32s | Depo. | Recv. | Total\n────────────────────────────┼──────┼──────┼──────\n", `Item`)
|
out := fmt.Sprintf("<code>%-32s | Depo. | Recv. | Total\n────────────────────────────┼──────┼──────┼──────\n", `Item`)
|
||||||
for i, itemId := range itemList {
|
for i, itemId := range itemList {
|
||||||
item, err := getObjItem(itemId)
|
item, err := getObjItem(itemId)
|
||||||
logOnError(err, "jobVaultStatus : getObjItem")
|
logOnError(err, "jobVaultUserStatus : getObjItem")
|
||||||
out = fmt.Sprintf("%s%-32s |%6d |%6d |%6d\n", out, item.Name, depositList[i], withdrawList[i], depositList[i]-withdrawList[i])
|
out = fmt.Sprintf("%s%-32s |%6d |%6d |%6d\n", out, item.Name, depositList[i], withdrawList[i], depositList[i]-withdrawList[i])
|
||||||
}
|
}
|
||||||
out = fmt.Sprintf("%s</code>", out)
|
out = fmt.Sprintf("%s</code>", out)
|
||||||
|
Loading…
Reference in New Issue
Block a user