update g deposit fwd

This commit is contained in:
shoopea 2019-08-29 18:24:21 +08:00
parent 1c6a17178b
commit 9399a84094
2 changed files with 21 additions and 10 deletions

2
def.go
View File

@ -274,7 +274,7 @@ type JobPayloadGDeposit struct {
Status int `json:"status"` Status int `json:"status"`
} }
type JobPayloadGDepositForwardd struct { type JobPayloadGDepositForward struct {
ItemID64 int64 `json:"item_id"` ItemID64 int64 `json:"item_id"`
Quantity int64 `json:"quantity"` Quantity int64 `json:"quantity"`
} }

29
job.go
View File

@ -38,14 +38,14 @@ func createJob(jobTypeID int32, priority int32, userID64 int64, trigger int64, s
} }
stmt, err = db.Prepare(`INSERT INTO obj_job (obj_id, priority, user_id, trigger_id, seq_nr, schedule, is_done, in_work, inserted, timeout, pulled, started, ended, payload) stmt, err = db.Prepare(`INSERT INTO obj_job (obj_id, priority, user_id, trigger_id, seq_nr, schedule, is_done, in_work, inserted, timeout, pulled, started, ended, payload)
VALUES (?, ?, ?, ?, NULL, ?, 0, 0, ?, NULL, NULL, NULL, NULL, ?);`) VALUES (?, ?, ?, ?, NULL, ?, 0, 0, ?, ?, NULL, NULL, NULL, ?);`)
logOnError(err, "createJob : prepare insert obj_job") logOnError(err, "createJob : prepare insert obj_job")
if err != nil { if err != nil {
return 0, err return 0, err
} }
defer stmt.Close() defer stmt.Close()
_, err = stmt.Exec(objId, priority, userID64, trigger, schedule.UTC(), time.Now().UTC(), payload) _, err = stmt.Exec(objId, priority, userID64, trigger, schedule.UTC(), time.Now().UTC(), time.Unix(maxUnixTimestamp, 0).UTC(), payload)
logOnError(err, "createJob : insert obj_job") logOnError(err, "createJob : insert obj_job")
if err != nil { if err != nil {
return 0, err return 0, err
@ -56,11 +56,13 @@ func createJob(jobTypeID int32, priority int32, userID64 int64, trigger int64, s
func createJobCallback(jobTypeID int32, userID64 int64, msgTypeID64 int64, payload []byte, timeout time.Duration) error { func createJobCallback(jobTypeID int32, userID64 int64, msgTypeID64 int64, payload []byte, timeout time.Duration) error {
//t, err := time.Parse(time.RFC3339, "9999-12-31T00:00:00+00:00") //t, err := time.Parse(time.RFC3339, "9999-12-31T00:00:00+00:00")
jobID64, err := createJob(jobTypeID, objJobPriority, userID64, 0, time.Unix(maxUnixTimestamp, 0), payload) jobID64, err := createJob(jobTypeID, objJobPriority, userID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), payload)
if err != nil { if err != nil {
return err return err
} }
setJobCallback(jobID64, userID64, msgTypeID64) setJobCallback(jobID64, userID64, msgTypeID64)
err = setJobTimeout(jobID64, timeout)
logOnError(err, "createJobCallback : setJobTimeout")
return nil return nil
} }
@ -725,7 +727,7 @@ func jobGStock(j Job) {
} }
func jobGDepositForward(j Job) { func jobGDepositForward(j Job) {
var p JobPayloadGDepositForwardd var p JobPayloadGDepositForward
err := setJobStart(j.ID64) err := setJobStart(j.ID64)
logOnError(err, "jobGDepositForward : setJobStart") logOnError(err, "jobGDepositForward : setJobStart")
@ -744,7 +746,10 @@ func jobGDepositForward(j Job) {
err = setJobDone(j.ID64) err = setJobDone(j.ID64)
logOnError(err, "jobGDeposit : setJobDone") logOnError(err, "jobGDeposit : setJobDone")
} else { } else {
err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
logOnError(err, "jobGDepositForward : rescheduleJob")
setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositAck) setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositAck)
} }
return return
} }
@ -839,12 +844,18 @@ func jobGDeposit(j Job) {
rule, err := getMsgParsingRule(msg) rule, err := getMsgParsingRule(msg)
logOnError(err, "jobGDeposit : getMsgParsingRule") logOnError(err, "jobGDeposit : getMsgParsingRule")
cwm, err := parseSubTypeMessageStockAck(msg, rule.re) cwm, err := parseSubTypeMessageStockAck(msg, rule.re)
for i := range cwm.Stock { for stockIdx := range cwm.Stock {
for j := range p.ResObjID64 { for resIdx := range p.ResObjID64 {
if cwm.Stock[i].ItemID64 == p.ResObjID64[j] { if cwm.Stock[stockIdx].ItemID64 == p.ResObjID64[resIdx] {
log.Printf("jobGDeposit : objSubTypeMessageStockAck : Matching ItemID %d (%d).\n", p.ResObjID64[j], cwm.Stock[i].Quantity) log.Printf("jobGDeposit : objSubTypeMessageStockAck : Matching ItemID %d (%d).\n", p.ResObjID64[resIdx], cwm.Stock[stockIdx].Quantity)
item, _ := getObjItem(p.ResObjID64[j]) item, _ := getObjItem(p.ResObjID64[resIdx])
clientSendCWMsg(p.ChatID64, fmt.Sprintf("/g_deposit %s 1", item.Code)) clientSendCWMsg(p.ChatID64, fmt.Sprintf("/g_deposit %s 1", item.Code))
p2 := JobPayloadGDepositForward{
ItemID64: p.ResObjID64[resIdx],
Quantity: cwm.Stock[stockIdx].Quantity,
}
b2, _ := json.Marshal(p2)
err = createJobCallback(objSubTypeJobGDepositForward, j.UserID64, objSubTypeMessageGDepositAck, b2, time.Duration(1*time.Minute))
} }
} }
} }