This commit is contained in:
shoopea 2019-05-09 18:36:45 +08:00
parent beb6d48f79
commit 252cdcb115
4 changed files with 27 additions and 29 deletions

5
def.go
View File

@ -2,12 +2,13 @@ package main
import (
"regexp"
"time"
)
type ChatWarsMessage struct {
UserID64 int64 `json:"user_id"`
SenderUserID64 int64 `json:"sender_user_id"`
Date int32 `json:"date"`
Date time.Time `json:"date"`
ID64 int64 `json:"id"`
ChatID64 int64 `json:"chat_id"`
Text string `json:"text"`
@ -23,7 +24,7 @@ type ChatWarsMessageAuctionAnnounce struct {
Buyer string `json:"buyer"`
Price int32 `json:"price"`
Status string `json:"status"`
End int64 `json:"end"`
End time.Time `json:"end"`
}
type MessageParsingRule struct {

View File

@ -68,7 +68,7 @@ func main() {
// Connecting to DB
switch cfg.SQL.Driver {
case "mysql":
db, err = sql.Open("mysql", cfg.SQL.Username+":"+cfg.SQL.Password+"@"+cfg.SQL.Type+"("+cfg.SQL.Address+")/"+cfg.SQL.Database)
db, err = sql.Open("mysql", cfg.SQL.Username+":"+cfg.SQL.Password+"@"+cfg.SQL.Type+"("+cfg.SQL.Address+")/"+cfg.SQL.Database+"?parseTime=true")
if err != nil {
log.Fatal(err)
}

16
sql.go
View File

@ -95,8 +95,8 @@ func initDB() {
_, err = db.Exec(`CREATE TABLE obj_war (
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
,start_time TIMESTAMP NOT NULL
,end_time TIMESTAMP NOT NULL
,start_time DATETIME NOT NULL
,end_time DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_war")
@ -107,7 +107,7 @@ func initDB() {
,chat_id BIGINT NOT NULL
,user_id BIGINT NOT NULL
,sender_user_id BIGINT NOT NULL
,date TIMESTAMP NOT NULL
,date DATETIME NOT NULL
,text VARCHAR(4096) NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,UNIQUE KEY (msg_id, chat_id, sender_user_id)
@ -149,7 +149,7 @@ func initDB() {
,buyer VARCHAR(32)
,price SMALLINT NOT NULL
,status VARCHAR(32)
,end TIMESTAMP NOT NULL
,end DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,UNIQUE KEY (lot_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
@ -1189,7 +1189,7 @@ func putUnprocessedMsg(m ChatWarsMessage) (int64, error) {
}
stmt, err := db.Prepare(`INSERT INTO obj_msg (obj_id, msg_id, chat_id, user_id, sender_user_id, date, text)
VALUES (?, ?, ?, ?, ?, FROM_UNIXTIME(?), ?);`)
VALUES (?, ?, ?, ?, ?, ?, ?);`)
if err != nil {
return 0, err
}
@ -1206,7 +1206,7 @@ func putUnprocessedMsg(m ChatWarsMessage) (int64, error) {
func getMsg(objId int64) (ChatWarsMessage, error) {
var m ChatWarsMessage
stmt, err := db.Prepare(`SELECT om.msg_id, om.chat_id, om.sender_user_id, UNIX_TIMESTAMP(om.date), om.text FROM obj_msg om WHERE om.obj_id = ?`)
stmt, err := db.Prepare(`SELECT om.msg_id, om.chat_id, om.sender_user_id, om.date, om.text FROM obj_msg om WHERE om.obj_id = ?`)
if err != nil {
return m, err
}
@ -1234,8 +1234,6 @@ func getObjSubTypeId(objId int64) (int64, error) {
return 0, err
}
log.Printf("getObjSubTypeId(%d) : %d\n", objId, objSubTypeId)
return objSubTypeId, nil
}
@ -1283,7 +1281,7 @@ func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
}
stmt, err := db.Prepare(`INSERT INTO obj_msg_auction_announce (obj_id, lot_id, item, cond, quality, seller, buyer, price, status, end)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?));`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
if err != nil {
return err
}

View File

@ -113,8 +113,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
p, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Price}"), 10, 32)
cwm.Price = int32(p)
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
t, _ := fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
cwm.End = t.Unix()
cwm.End, _ := fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
err = insertMsgAuctionAnnounce(&cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : AuctionAnnounce")
case objSubTypeMessageTime: