update vault

This commit is contained in:
shoopea 2019-10-12 13:47:40 +08:00
parent 70fb6df28a
commit 34948714cb
5 changed files with 50 additions and 16 deletions

9
bot.go
View File

@ -53,6 +53,7 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/vault_rec", botVaultRec)
b.Handle("/vault_part", botVaultPart)
b.Handle("/vault_other", botVaultOther)
b.Handle("/vault_item", botVaultItem)
b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost)
@ -711,6 +712,10 @@ func botVaultOther(m *tb.Message) {
botVault(m, l)
}
func botVaultItem(m *tb.Message) {
}
func botVault(m *tb.Message, itemTypeList []int64) {
/*
b, _ := json.Marshal(m)
@ -725,7 +730,7 @@ func botVault(m *tb.Message, itemTypeList []int64) {
return
}
p := JobPayloadVaultStatus{
p := JobPayloadVaultUserStatus{
UserID64: int64(m.Sender.ID),
UserListID64: nil,
ItemTypeListID64: nil,
@ -736,7 +741,7 @@ func botVault(m *tb.Message, itemTypeList []int64) {
b, _ := json.Marshal(p)
t := time.Now().UTC()
_, err := createJob(objSubTypeJobVaultStatus, objJobPriority, int64(m.Sender.ID), 0, t, b)
_, err := createJob(objSubTypeJobVaultUserStatus, objJobPriority, int64(m.Sender.ID), 0, t, b)
if err != nil {
c := TGCommand{

11
def.go
View File

@ -346,13 +346,19 @@ type JobPayloadBackupImport struct {
ChatID64 int64 `json:"chat_id"`
}
type JobPayloadVaultStatus struct {
type JobPayloadVaultUserStatus struct {
UserListID64 []int64 `json:"user_list"`
ItemTypeListID64 []int64 `json:"item_type_list"`
DepositChatID64 int64 `json:"deposit_chat_id"`
UserID64 int64 `json:"user_id"`
}
type JobPayloadVaultItemStatus struct {
ItemListID64 []int64 `json:"item_type_list"`
DepositChatID64 int64 `json:"deposit_chat_id"`
UserID64 int64 `json:"user_id"`
}
const (
userID64ChtWrsBot = 408101137
@ -501,7 +507,8 @@ const (
objSubTypeJobGDeposit = 612
objSubTypeJobGDepositForward = 613
objSubTypeJobSaveRes = 614
objSubTypeJobVaultStatus = 615
objSubTypeJobVaultUserStatus = 615
objSubTypeJobVaultItemStatus = 616
objSubTypeItemResource = 701
objSubTypeItemAlch = 702
objSubTypeItemMisc = 703

37
job.go
View File

@ -892,19 +892,38 @@ func jobGDeposit(j Job) {
return
}
func jobVaultStatus(j Job) {
func jobVaultItemStatus(j Job) {
var (
p JobPayloadVaultStatus
p JobPayloadVaultItemStatus
//user, deposit, withdraw int64
//userList, depositList, withdrawList []int64
)
err := setJobStart(j.ID64)
logOnError(err, "jobVaultItemStatus : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobVaultItemStatus : Unmarshal payload")
err = setJobDone(j.ID64)
logOnError(err, "jobVaultItemStatus : setJobDone")
return
}
func jobVaultUserStatus(j Job) {
var (
p JobPayloadVaultUserStatus
userID64, currentUserID64 int64
itemID64, deposit, withdraw int64
itemList, depositList, withdrawList []int64
)
err := setJobStart(j.ID64)
logOnError(err, "jobVaultStatus : setJobStart")
logOnError(err, "jobVaultUserStatus : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobVaultStatus : Unmarshal payload")
logOnError(err, "jobVaultUserStatus : Unmarshal payload")
stmt := `SELECT x.user_id
,x.item_id
@ -940,18 +959,18 @@ func jobVaultStatus(j Job) {
}
rows, err := db.Query(stmt, args...)
logOnError(err, "jobVaultStatus : Get rows")
logOnError(err, "jobVaultUserStatus : Get rows")
if err != nil {
err = setJobDone(j.ID64)
logOnError(err, "jobVaultStatus : setJobDone")
logOnError(err, "jobVaultUserStatus : setJobDone")
return
}
currentUserID64 = 0
for rows.Next() {
err = rows.Scan(&userID64, &itemID64, &deposit, &withdraw)
logOnError(err, "jobVaultStatus : scan next val")
logOnError(err, "jobVaultUserStatus : scan next val")
if userID64 != currentUserID64 {
if currentUserID64 != 0 {
// display info
@ -985,11 +1004,11 @@ func jobVaultStatus(j Job) {
TGCmdQueue <- c
}
err = rows.Err()
logOnError(err, "jobVaultStatus : query end")
logOnError(err, "jobVaultUserStatus : query end")
rows.Close()
err = setJobDone(j.ID64)
logOnError(err, "jobVaultStatus : setJobDone")
logOnError(err, "jobVaultUserStatus : setJobDone")
return
}

3
sql.go
View File

@ -563,7 +563,8 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeJobGDeposit) + `, "job_gdeposit", "GDeposit job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobGDepositForward) + `, "job_gdeposit_fwd", "GDeposit Forward job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobSaveRes) + `, "job_save_res", "Save resources job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobVaultStatus) + `, "job_vault_status", "Vault Status job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobVaultUserStatus) + `, "job_vault_user_status", "Vault User Status job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobVaultItemStatus) + `, "job_vault_item_status", "Vault Item Status job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `)
,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `)
,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `)

View File

@ -553,8 +553,10 @@ func JobWorker(id int, jobs <-chan Job) {
jobGDepositForward(j)
case objSubTypeJobGWithdraw:
jobGWithdraw(j)
case objSubTypeJobVaultStatus:
jobVaultStatus(j)
case objSubTypeJobVaultUserStatus:
jobVaultUserStatus(j)
case objSubTypeJobVaultItemStatus:
jobVaultItemStatus(j)
default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
}