test
This commit is contained in:
parent
beb6d48f79
commit
252cdcb115
5
def.go
5
def.go
@ -2,12 +2,13 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ChatWarsMessage struct {
|
type ChatWarsMessage struct {
|
||||||
UserID64 int64 `json:"user_id"`
|
UserID64 int64 `json:"user_id"`
|
||||||
SenderUserID64 int64 `json:"sender_user_id"`
|
SenderUserID64 int64 `json:"sender_user_id"`
|
||||||
Date int32 `json:"date"`
|
Date time.Time `json:"date"`
|
||||||
ID64 int64 `json:"id"`
|
ID64 int64 `json:"id"`
|
||||||
ChatID64 int64 `json:"chat_id"`
|
ChatID64 int64 `json:"chat_id"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
@ -23,7 +24,7 @@ type ChatWarsMessageAuctionAnnounce struct {
|
|||||||
Buyer string `json:"buyer"`
|
Buyer string `json:"buyer"`
|
||||||
Price int32 `json:"price"`
|
Price int32 `json:"price"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
End int64 `json:"end"`
|
End time.Time `json:"end"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageParsingRule struct {
|
type MessageParsingRule struct {
|
||||||
|
2
main.go
2
main.go
@ -68,7 +68,7 @@ func main() {
|
|||||||
// Connecting to DB
|
// Connecting to DB
|
||||||
switch cfg.SQL.Driver {
|
switch cfg.SQL.Driver {
|
||||||
case "mysql":
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
18
sql.go
18
sql.go
@ -95,8 +95,8 @@ func initDB() {
|
|||||||
|
|
||||||
_, err = db.Exec(`CREATE TABLE obj_war (
|
_, err = db.Exec(`CREATE TABLE obj_war (
|
||||||
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
|
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
|
||||||
,start_time TIMESTAMP NOT NULL
|
,start_time DATETIME NOT NULL
|
||||||
,end_time TIMESTAMP NOT NULL
|
,end_time DATETIME NOT NULL
|
||||||
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
||||||
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
|
||||||
failOnError(err, "initDB : create table obj_war")
|
failOnError(err, "initDB : create table obj_war")
|
||||||
@ -107,7 +107,7 @@ func initDB() {
|
|||||||
,chat_id BIGINT NOT NULL
|
,chat_id BIGINT NOT NULL
|
||||||
,user_id BIGINT NOT NULL
|
,user_id BIGINT NOT NULL
|
||||||
,sender_user_id BIGINT NOT NULL
|
,sender_user_id BIGINT NOT NULL
|
||||||
,date TIMESTAMP NOT NULL
|
,date DATETIME NOT NULL
|
||||||
,text VARCHAR(4096) NOT NULL
|
,text VARCHAR(4096) NOT NULL
|
||||||
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
||||||
,UNIQUE KEY (msg_id, chat_id, sender_user_id)
|
,UNIQUE KEY (msg_id, chat_id, sender_user_id)
|
||||||
@ -149,7 +149,7 @@ func initDB() {
|
|||||||
,buyer VARCHAR(32)
|
,buyer VARCHAR(32)
|
||||||
,price SMALLINT NOT NULL
|
,price SMALLINT NOT NULL
|
||||||
,status VARCHAR(32)
|
,status VARCHAR(32)
|
||||||
,end TIMESTAMP NOT NULL
|
,end DATETIME NOT NULL
|
||||||
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
||||||
,UNIQUE KEY (lot_id)
|
,UNIQUE KEY (lot_id)
|
||||||
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
|
||||||
@ -1188,8 +1188,8 @@ func putUnprocessedMsg(m ChatWarsMessage) (int64, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt, err := db.Prepare(`INSERT INTO obj_msg (obj_id, msg_id, chat_id, user_id, sender_user_id, date , text)
|
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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -1206,7 +1206,7 @@ func putUnprocessedMsg(m ChatWarsMessage) (int64, error) {
|
|||||||
func getMsg(objId int64) (ChatWarsMessage, error) {
|
func getMsg(objId int64) (ChatWarsMessage, error) {
|
||||||
var m ChatWarsMessage
|
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 {
|
if err != nil {
|
||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
@ -1234,8 +1234,6 @@ func getObjSubTypeId(objId int64) (int64, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("getObjSubTypeId(%d) : %d\n", objId, objSubTypeId)
|
|
||||||
|
|
||||||
return objSubTypeId, nil
|
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)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
|||||||
p, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Price}"), 10, 32)
|
p, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Price}"), 10, 32)
|
||||||
cwm.Price = int32(p)
|
cwm.Price = int32(p)
|
||||||
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
|
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
|
||||||
t, _ := fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
|
cwm.End, _ := fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
|
||||||
cwm.End = t.Unix()
|
|
||||||
err = insertMsgAuctionAnnounce(&cwm)
|
err = insertMsgAuctionAnnounce(&cwm)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : AuctionAnnounce")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : AuctionAnnounce")
|
||||||
case objSubTypeMessageTime:
|
case objSubTypeMessageTime:
|
||||||
|
Loading…
Reference in New Issue
Block a user