test g withdraw inspect

This commit is contained in:
shoopea 2020-01-21 15:40:32 +08:00
parent 0e4ca45b80
commit 1d2af2ee69

42
job.go
View File

@ -1432,9 +1432,10 @@ func jobVaultUserStatus(j Job) {
func jobGWithdraw(j Job) {
var (
p JobPayloadGWithdraw
reqTab map[int64]int64
doneTab map[int64]int64
p JobPayloadGWithdraw
reqTab map[int64]int64
doneTab map[int64]int64
inspectTab map[string]bool
)
log.Printf("jobGWithdraw[%d] : Starting.\n", j.ID64)
@ -1455,6 +1456,8 @@ func jobGWithdraw(j Job) {
doneTab[cacheObjSubType[`item_part`]] = 1 << 14
doneTab[cacheObjSubType[`item_other`]] = 1 << 15
inspectTab = make(map[string]bool)
err := setJobStart(j.ID64)
logOnError(err, "jobGWithdraw : setJobStart")
@ -1462,12 +1465,13 @@ func jobGWithdraw(j Job) {
logOnError(err, "jobGWithdraw : Unmarshal payload")
if p.Status == 0 {
for _, item := range p.Items {
for k, item := range p.Items {
id := getSilentObjItemID(item.Code, ``)
if id != 0 {
obj, _ := getObjItem(id)
p.Status = p.Status | reqTab[obj.ItemTypeID]
} else if ok, _ := regexp.MatchString(`^u[0-9]+$`, item.Code); ok {
p.Items[k].Inspect = true
p.Status = p.Status | reqTab[cacheObjSubType[`item_other`]]
}
}
@ -1497,6 +1501,7 @@ func jobGWithdraw(j Job) {
logOnError(err, "jobGWithdraw : getObjSubType("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil {
if id == cacheObjSubType[`msg_gstock_any_ack`] {
var isUnique bool
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobGWithdraw : getObjMsg")
rule, err := getMsgParsingRule(m)
@ -1509,8 +1514,12 @@ func jobGWithdraw(j Job) {
if req.Code == disp.Code {
p.Items[k].Available = disp.Quantity
p.Items[k].Name = disp.Name
p.Items[k].Inspect = false
log.Printf("jobGWithdraw[%d] : Found %s - %s : %d.\n", j.ID64, disp.Code, disp.Name, disp.Quantity)
}
if ok, _ := regexp.MatchString(`^u[0-9]+$`, disp.Code); ok {
isUnique = true
}
}
}
@ -1520,6 +1529,31 @@ func jobGWithdraw(j Job) {
}
b2, _ := json.Marshal(p2)
createJob(cacheObjSubType[`job_msg_del`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b2)
for k, req := range p.Items {
if req.Inspect {
p2 = JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_g_inspect_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
}
b2, _ = json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
p.Inspecting = req.Code
b, _ := json.Marshal(p)
id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
logOnError(err, "jobGWithdraw : createJob")
setJobCallback(id, int64(bot.Me.ID), cacheObjSubType[`msg_invalid_action`])
setJobCallback(id, int64(bot.Me.ID), cacheObjSubType[`msg_inspect_ack`])
clientSendCWMsg(j.UserID64, fmt.Sprintf("/g_inspect_%s", p.Inspecting))
err = setJobDone(j.ID64)
logOnError(err, "jobGWithdraw : setJobDone")
return
}
}
}
if id == cacheObjSubType[`msg_msg_job_gwithdraw_ack`] {