test
This commit is contained in:
parent
beb6d48f79
commit
252cdcb115
33
def.go
33
def.go
@ -2,28 +2,29 @@ package main
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ChatWarsMessage struct {
|
||||
UserID64 int64 `json:"user_id"`
|
||||
SenderUserID64 int64 `json:"sender_user_id"`
|
||||
Date int32 `json:"date"`
|
||||
ID64 int64 `json:"id"`
|
||||
ChatID64 int64 `json:"chat_id"`
|
||||
Text string `json:"text"`
|
||||
UserID64 int64 `json:"user_id"`
|
||||
SenderUserID64 int64 `json:"sender_user_id"`
|
||||
Date time.Time `json:"date"`
|
||||
ID64 int64 `json:"id"`
|
||||
ChatID64 int64 `json:"chat_id"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageAuctionAnnounce struct {
|
||||
MsgID64 int64 `json:"msg_id"`
|
||||
LotID int32 `json:"lot_id"`
|
||||
Item string `json:"item"`
|
||||
Cond string `json:"cond"`
|
||||
Quality string `json:"quality"`
|
||||
Seller string `json:"seller"`
|
||||
Buyer string `json:"buyer"`
|
||||
Price int32 `json:"price"`
|
||||
Status string `json:"status"`
|
||||
End int64 `json:"end"`
|
||||
MsgID64 int64 `json:"msg_id"`
|
||||
LotID int32 `json:"lot_id"`
|
||||
Item string `json:"item"`
|
||||
Cond string `json:"cond"`
|
||||
Quality string `json:"quality"`
|
||||
Seller string `json:"seller"`
|
||||
Buyer string `json:"buyer"`
|
||||
Price int32 `json:"price"`
|
||||
Status string `json:"status"`
|
||||
End time.Time `json:"end"`
|
||||
}
|
||||
|
||||
type MessageParsingRule struct {
|
||||
|
2
main.go
2
main.go
@ -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)
|
||||
}
|
||||
|
18
sql.go
18
sql.go
@ -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;`)
|
||||
@ -1188,8 +1188,8 @@ func putUnprocessedMsg(m ChatWarsMessage) (int64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
stmt, err := db.Prepare(`INSERT INTO obj_msg (obj_id, msg_id, chat_id, user_id, sender_user_id, date , text)
|
||||
VALUES (?, ?, ?, ?, ?, FROM_UNIXTIME(?), ?);`)
|
||||
stmt, err := db.Prepare(`INSERT INTO obj_msg (obj_id, msg_id, chat_id, user_id, sender_user_id, date, text)
|
||||
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
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user