This commit is contained in:
shoopea 2019-05-15 18:31:03 +08:00
parent 912690e66d
commit cfa747fa74
3 changed files with 21 additions and 10 deletions

8
bot.go
View File

@ -100,7 +100,9 @@ func botMsgRescan(m *tb.Message) (string, error) {
r = regexp.MustCompile("^all$") r = regexp.MustCompile("^all$")
if r.MatchString(m.Payload) { if r.MatchString(m.Payload) {
p := JobPayloadRescanMsg{ p := JobPayloadRescanMsg{
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d;", objTypeMessage, objSubTypeMessageUnknown), Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d;", objTypeMessage, objSubTypeMessageUnknown),
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
} }
b, _ := json.Marshal(p) b, _ := json.Marshal(p)
log.Printf("botMsgRescan : json : %s\n", string(b)) log.Printf("botMsgRescan : json : %s\n", string(b))
@ -122,7 +124,9 @@ func botMsgRescanAll(m *tb.Message) (string, error) {
return ``, nil return ``, nil
} }
p := JobPayloadRescanMsg{ p := JobPayloadRescanMsg{
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d;", objTypeMessage, objSubTypeMessageUnknown), Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d;", objTypeMessage, objSubTypeMessageUnknown),
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
} }
b, _ := json.Marshal(p) b, _ := json.Marshal(p)
log.Printf("botMsgRescan : json : %s\n", string(b)) log.Printf("botMsgRescan : json : %s\n", string(b))

9
def.go
View File

@ -77,6 +77,7 @@ type Job struct {
ID64 int64 ID64 int64
JobTypeID int32 JobTypeID int32
Status int32 Status int32
UserID64 int64
Payload []byte Payload []byte
} }
@ -101,11 +102,15 @@ type JobPayloadGStock struct {
} }
type JobPayloadRescanMsg struct { type JobPayloadRescanMsg struct {
Query string `json:"query"` Query string `json:"query"`
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
} }
type JobPayloadSetDone struct { type JobPayloadSetDone struct {
JobID64 int64 `json:"job_id"` JobID64 int64 `json:"job_id"`
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
} }
const ( const (

14
sql.go
View File

@ -257,6 +257,7 @@ func initDB() {
_, err = db.Exec(`CREATE TABLE obj_job ( _, err = db.Exec(`CREATE TABLE obj_job (
obj_id BIGINT UNSIGNED NOT NULL obj_id BIGINT UNSIGNED NOT NULL
,priority SMALLINT NOT NULL ,priority SMALLINT NOT NULL
,user_id BIGINT UNSIGNED NOT NULL
,status SMALLINT NOT NULL ,status SMALLINT NOT NULL
,schedule DATETIME NOT NULL ,schedule DATETIME NOT NULL
,is_done TINYINT NOT NULL ,is_done TINYINT NOT NULL
@ -267,6 +268,7 @@ func initDB() {
,ended TIMESTAMP ,ended TIMESTAMP
,payload VARCHAR(4000) ,payload VARCHAR(4000)
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE ,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,KEY (user_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`) ) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_job") failOnError(err, "initDB : create table obj_job")
log.Println("initDB : obj_job created ...") log.Println("initDB : obj_job created ...")
@ -1569,7 +1571,7 @@ func insertMsgPillageInc(m *ChatWarsMessagePillageInc) error {
return nil return nil
} }
func createJob(job_type_id int32, priority int32, schedule time.Time, payload []byte) error { func createJob(jobTypeID int32, priority int32, userID64 int64, schedule time.Time, payload []byte) error {
stmt, err := db.Prepare(`INSERT INTO obj (obj_type_id, obj_sub_type_id) stmt, err := db.Prepare(`INSERT INTO obj (obj_type_id, obj_sub_type_id)
VALUES (? , ?);`) VALUES (? , ?);`)
logOnError(err, "createJob : prepare insert obj") logOnError(err, "createJob : prepare insert obj")
@ -1578,8 +1580,8 @@ func createJob(job_type_id int32, priority int32, schedule time.Time, payload []
} }
defer stmt.Close() defer stmt.Close()
res, err := stmt.Exec(objTypeJob, job_type_id) res, err := stmt.Exec(objTypeJob, jobTypeID)
s := fmt.Sprintf("createJob, insert obj(%d, %d)", objTypeJob, job_type_id) s := fmt.Sprintf("createJob, insert obj(%d, %d)", objTypeJob, jobTypeID)
logOnError(err, s) logOnError(err, s)
if err != nil { if err != nil {
return err return err
@ -1591,15 +1593,15 @@ func createJob(job_type_id int32, priority int32, schedule time.Time, payload []
return err return err
} }
stmt, err = db.Prepare(`INSERT INTO obj_job (obj_id, priority, status, schedule, is_done, in_work, inserted, pulled, started, ended, payload) stmt, err = db.Prepare(`INSERT INTO obj_job (obj_id, priority, user_id, status, schedule, is_done, in_work, inserted, pulled, started, ended, payload)
VALUES (?, ?, ?, ?, 0, 0, ?, NULL, NULL, NULL, ?);`) VALUES (?, ?, ?, ?, ?, 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 err return err
} }
defer stmt.Close() defer stmt.Close()
_, err = stmt.Exec(objId, priority, objJobStatusNew, schedule, time.Now(), payload) _, err = stmt.Exec(objId, priority, userID64, objJobStatusNew, schedule, time.Now(), payload)
logOnError(err, "createJob : insert obj_job") logOnError(err, "createJob : insert obj_job")
if err != nil { if err != nil {
return err return err