260 lines
11 KiB
Go
260 lines
11 KiB
Go
package table
|
||
|
||
import (
|
||
"database/sql/driver"
|
||
"fmt"
|
||
"time"
|
||
)
|
||
|
||
const (
|
||
//发送文本消息
|
||
MYSQL_BUSINESS_TYPE_SENDTEXTMSG = "SendTextMessage"
|
||
//发送图片信息
|
||
MYSQL_BUSINESS_TYPE_SENDIMGMSG = "SendImageMessage"
|
||
)
|
||
|
||
type LocalTime struct {
|
||
time.Time
|
||
}
|
||
|
||
// MarshalJSON on LocalTime format Time field with %Y-%m-%d %H:%M:%S
|
||
func (t LocalTime) MarshalJSON() ([]byte, error) {
|
||
formatted := fmt.Sprintf("\"%s\"", t.Format("2006-01-02 15:04:05"))
|
||
return []byte(formatted), nil
|
||
}
|
||
|
||
// Value insert timestamp into mysql need this function.
|
||
func (t LocalTime) Value() (driver.Value, error) {
|
||
var zeroTime time.Time
|
||
if t.Time.UnixNano() == zeroTime.UnixNano() {
|
||
return nil, nil
|
||
}
|
||
return t.Time, nil
|
||
}
|
||
|
||
// Scan valueof time.Time
|
||
func (t *LocalTime) Scan(v interface{}) error {
|
||
switch v.(type) {
|
||
case []byte:
|
||
timeBytes, ok := v.([]byte)
|
||
if ok {
|
||
todayZero, _ := time.ParseInLocation("2006-01-02 15:04:05", string(timeBytes), time.Local)
|
||
*t = LocalTime{Time: todayZero}
|
||
return nil
|
||
}
|
||
case time.Time:
|
||
value, ok := v.(time.Time)
|
||
if ok {
|
||
*t = LocalTime{Time: value}
|
||
return nil
|
||
}
|
||
|
||
}
|
||
|
||
return fmt.Errorf("can not convert %v to timestamp", v)
|
||
}
|
||
|
||
func NewLocalTime() *LocalTime {
|
||
return &LocalTime{time.Now()}
|
||
}
|
||
|
||
type CdnSnsImageInfo struct {
|
||
Ver uint32
|
||
Seq uint32
|
||
RetCode uint32
|
||
FileKey string
|
||
RecvLen uint32
|
||
FileURL string
|
||
ThumbURL string
|
||
EnableQuic uint32
|
||
RetrySec uint32
|
||
IsRetry uint32
|
||
IsOverLoad uint32
|
||
IsGetCDN uint32
|
||
XClientIP string
|
||
ImageMD5 string `gorm:"primary_key"`
|
||
ImageWidth uint32
|
||
ImageHeight uint32
|
||
}
|
||
|
||
type MysqlBase struct {
|
||
TargetIp string `gorm:"column:targetIp"`
|
||
}
|
||
|
||
// USerBusinessLog 用户行为日志
|
||
type UserBusinessLog struct {
|
||
Id uint `gorm:"primary_key,AUTO_INCREMENT"` //自增Id
|
||
UUID string `gorm:"column:uuid" json:"uuid"` //用户链接Id
|
||
UserName string `gorm:"column:user_name" json:"userName"` //登录的WXID
|
||
BusinessType string `gorm:"column:business_type" json:"businessType"` //业务类型 所调用的接口
|
||
ExecuteResult string `gorm:"column:ex_result" json:"executeResult"` //执行结果
|
||
}
|
||
|
||
// UserMessageLog 用户消息日志,用于去重
|
||
type UserMessageLog struct {
|
||
UserName string `gorm:"primary_key;column:user_name;unique" json:"userName"` // 唯一的用户名
|
||
MsgIds string `gorm:"column:msg_ids;type:text" json:"msgIds"` // 消息ID,以逗号分隔
|
||
}
|
||
|
||
// 用户登录日志
|
||
type UserLoginLog struct {
|
||
MysqlBase
|
||
Id uint `gorm:"primary_key,AUTO_INCREMENT" json:"id"`
|
||
UUId string
|
||
UserName string
|
||
NickName string
|
||
LoginType string
|
||
UpdatedAt LocalTime `json:"loginTime"`
|
||
RetCode int32 `gorm:"column:ret_code"`
|
||
ErrMsg string `gorm:"column:err_msg;type:text"`
|
||
}
|
||
|
||
// UserInfoEntity 用户信息
|
||
type UserInfoEntity struct {
|
||
MysqlBase
|
||
UUID string `gorm:"column:uuid" json:"uuid"`
|
||
Uin uint32 `gorm:"column:uin" json:"uin"`
|
||
WxId string `gorm:"column:wxId;primary_key" json:"wxId"`
|
||
NickName string `gorm:"column:nickname" json:"nickname"`
|
||
BindMobile string `gorm:"column:bindmobile" json:"bindmobile"`
|
||
Alias string `gorm:"column:alias" json:"alias"`
|
||
UserName string `gorm:"column:userName" json:"user_name"`
|
||
Password string `gorm:"column:password" json:"password"`
|
||
HeadURL string `gorm:"column:headurl" json:"headurl"`
|
||
Session []byte `gorm:"column:cookie" json:"cookie"`
|
||
SessionKey []byte `gorm:"column:sessionKey" json:"sessionKey"`
|
||
Proxy string `gorm:"column:proxy" json:"proxy"`
|
||
ClientVersion uint32 `gorm:"column:clientVersion" json:"clientVersion"`
|
||
ShortHost string `gorm:"column:shorthost" json:"shorthost"`
|
||
LongHost string `gorm:"column:longhost" json:"longhost"`
|
||
EcPublicKey []byte `gorm:"column:ecpukey" json:"ecpukey"`
|
||
EcPrivateKey []byte `gorm:"column:ecprkey" json:"ecprkey"`
|
||
CheckSumKey []byte `gorm:"column:checksumkey" json:"checksumkey"`
|
||
AutoAuthKey string `gorm:"column:autoauthkey;type:varchar(2048)" json:"autoauthkey"`
|
||
State int32 `gorm:"column:state" json:"state"`
|
||
InitContact int32 `gorm:"column:initcontact;default:0" json:"initcontact"`
|
||
SyncKey string `gorm:"column:synckey;type:varchar(1024)" json:"synckey"`
|
||
FavSyncKey string `gorm:"column:favsynckey;type:varchar(100)" json:"favsynckey"`
|
||
// 登录的Rsa 密钥版本
|
||
LoginRsaVer uint32
|
||
ErrMsg string `gorm:"type:text"`
|
||
|
||
// `gorm:"type:timestamp;default:CURRENT_TIMESTAMP"`
|
||
// `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"`
|
||
|
||
// 新设备创建时间
|
||
DeviceCreateTime LocalTime `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"deviceCreateTime"`
|
||
// 上次手动登录时间
|
||
LastLoginTime LocalTime `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"lastLoginTime"`
|
||
// 上次手动登录时间
|
||
LastAuthTime LocalTime `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"lastAuthTime"`
|
||
// 短连接启用状态
|
||
ShortLinkEnabled bool `gorm:"column:short_link_enabled;default:true" json:"shortLinkEnabled"`
|
||
}
|
||
|
||
// DeviceInfoEntity 设备信息
|
||
type DeviceInfoEntity struct {
|
||
WxId string `gorm:"column:wxid;primary_key" json:"wxid"`
|
||
UUIDOne string `gorm:"column:uuidone" json:"uuidone"`
|
||
UUIDTwo string `gorm:"column:uuidtwo" json:"uuidtwo"`
|
||
Imei string `gorm:"column:imei" json:"imei"`
|
||
DeviceID []byte `gorm:"column:deviceid" json:"deviceid"`
|
||
DeviceName string `gorm:"column:devicename" json:"devicename"`
|
||
TimeZone string `gorm:"column:timezone" json:"timezone"`
|
||
Language string `gorm:"column:language" json:"language"`
|
||
DeviceBrand string `gorm:"column:devicebrand" json:"devicebrand"`
|
||
RealCountry string `gorm:"column:realcountry" json:"realcountry"`
|
||
IphoneVer string `gorm:"column:iphonever" json:"iphonever"`
|
||
BundleID string `gorm:"column:boudleid" json:"boudleid"`
|
||
OsType string `gorm:"column:ostype" json:"ostype"`
|
||
AdSource string `gorm:"column:adsource" json:"adsource"`
|
||
OsTypeNumber string `gorm:"column:ostypenumber" json:"ostypenumber"`
|
||
CoreCount uint32 `gorm:"column:corecount" json:"corecount"`
|
||
CarrierName string `gorm:"column:carriername" json:"carriername"`
|
||
SoftTypeXML string `gorm:"column:softtypexml;type:varchar(2048)" json:"softtypexml"`
|
||
ClientCheckDataXML string `gorm:"column:clientcheckdataxml;type:varchar(4096)" json:"clientcheckdataxml"`
|
||
// extInfo
|
||
GUID2 string `json:"GUID2"`
|
||
}
|
||
|
||
// 授权key
|
||
type LicenseKey struct {
|
||
ID int `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||
DeviceToken string `gorm:"column:device_token;type:varchar(255)" json:"device_token"`
|
||
Status int `gorm:"column:status" json:"status"`
|
||
License string `gorm:"column:license;type:varchar(255);unique;not null" json:"license"`
|
||
ExpiryDate string `gorm:"column:expiry_date;type:varchar(255)" json:"expiry_date"`
|
||
StartDate string `gorm:"column:start_date;type:varchar(255)" json:"start_date"`
|
||
WxId string `gorm:"column:wx_id;type:varchar(255)" json:"wx_id"`
|
||
NickName string `gorm:"column:nick_name;type:varchar(255)" json:"nick_name"`
|
||
BindMobile string `gorm:"column:bindmobile" json:"bindmobile"`
|
||
Alias string `gorm:"column:alias" json:"alias"`
|
||
// 类型 1日 7 周 30月 90季 180 半年 365年 30000永久(数字为标识,非准确天数)
|
||
Type int `gorm:"column:type;type:int;default:0" json:"type"`
|
||
IsBanned int `gorm:"column:is_banned;type:int;default:0" json:"is_banned"`
|
||
}
|
||
|
||
type BlackList struct {
|
||
ID int `gorm:"primaryKey"`
|
||
Owner string `gorm:"column:owner;type:varchar(255)"`
|
||
Blacker string `gorm:"column:blacker;type:json"`
|
||
}
|
||
|
||
func (BlackList) TableName() string {
|
||
return "black_list"
|
||
}
|
||
|
||
// 指令:Command key str_value int_value
|
||
type Command struct {
|
||
UUID string `gorm:"column:uuid;primary_key" json:"uuid"`
|
||
A101 int `gorm:"column:a101;type:int;default:0" json:"a101"`
|
||
A111 int `gorm:"column:a111;type:int;default:0" json:"a111"`
|
||
A102 int `gorm:"column:a102;type:int;default:0" json:"a102"`
|
||
A103 int `gorm:"column:a103;type:int;default:0" json:"a103"`
|
||
A104 int `gorm:"column:a104;type:int;default:0" json:"a104"`
|
||
A104Str string `gorm:"column:a104_str;type:varchar(255)" json:"a104_str"`
|
||
A105 int `gorm:"column:a105;type:int;default:0" json:"a105"`
|
||
A106 int `gorm:"column:a106;type:int;default:0" json:"a106"`
|
||
A107 int `gorm:"column:a107;type:int;default:0" json:"a107"`
|
||
A109 int `gorm:"column:a109;type:int;default:0" json:"a109"`
|
||
A116 int `gorm:"column:a116;type:int;default:0" json:"a116"`
|
||
A116Str string `gorm:"column:a116_str;type:varchar(255)" json:"a116_str"`
|
||
A118 int `gorm:"column:a118;type:int;default:0" json:"a118"`
|
||
A118Str string `gorm:"column:a118_str;type:varchar(255)" json:"a118_str"`
|
||
A301 int `gorm:"column:a301;type:int;default:0" json:"a301"`
|
||
A301Str string `gorm:"column:a301_str;type:varchar(255)" json:"a301_str"`
|
||
A401 int `gorm:"column:a401;type:int;default:0" json:"a401"`
|
||
A402 int `gorm:"column:a402;type:int;default:0" json:"a402"`
|
||
A403 int `gorm:"column:a403;type:int;default:0" json:"a403"`
|
||
A601 int `gorm:"column:a601;type:int;default:0" json:"a601"`
|
||
A801 int `gorm:"column:a801;type:int;default:0" json:"a801"`
|
||
A811 int `gorm:"column:a811;type:int;default:0" json:"a811"`
|
||
B001 int `gorm:"column:b001;type:int;default:0" json:"b001"`
|
||
B001Str string `gorm:"column:b001_str;type:varchar(255)" json:"b001_str"`
|
||
B002 int `gorm:"column:b002;type:int;default:0" json:"b002"`
|
||
B002Str string `gorm:"column:b002_str;type:text" json:"b002_str"` // JSON string storing keyword-reply pairs
|
||
B003 int `gorm:"column:b003;type:int;default:0" json:"b003"` // Enable welcome message (0: disabled, 1: enabled)
|
||
B003Str string `gorm:"column:b003_str;type:text" json:"b003_str"` // JSON string storing welcome message config
|
||
B004 int `gorm:"column:b004;type:int;default:0" json:"b004"` // Enable admin keyword (0: disabled, 1: enabled)
|
||
B004Str string `gorm:"column:b004_str;type:text" json:"b004_str"` // JSON string storing admin keyword config
|
||
B005 int `gorm:"column:b005;type:int;default:0" json:"b005"` // Enable invite keyword (0: disabled, 1: enabled)
|
||
B005Str string `gorm:"column:b005_str;type:text" json:"b005_str"` // JSON string storing invite keyword config
|
||
B006 int `gorm:"column:b006;type:int;default:0" json:"b006"` // Enable kick keyword (0: disabled, 1: enabled)
|
||
B006Str string `gorm:"column:b006_str;type:text" json:"b006_str"` // JSON string storing kick keyword config
|
||
}
|
||
|
||
type ModContactDB struct {
|
||
UUID string `gorm:"type:varchar(36)" json:"uuid"` // 新增 UUID 字段
|
||
UserName string `gorm:"type:varchar(255)" json:"userName"`
|
||
UserUUIDCombined string `gorm:"primary_key;type:varchar(291);index" json:"user_uuid_combined"` // 新的组合字段,设置为主键
|
||
Data string `gorm:"type:json" json:"data"`
|
||
}
|
||
|
||
type AddMsgDB struct {
|
||
UUID string `gorm:"type:varchar(36)" json:"uuid"`
|
||
NewMsgId int64 `gorm:"type:bigint" json:"new_msg_id"`
|
||
MsgUUIDCombined string `gorm:"primary_key;type:varchar(291);index" json:"msg_uuid_combined"` // 新的组合字段,设置为主键
|
||
Data string `gorm:"type:json" json:"data"`
|
||
CreateTime uint32 `gorm:"type:int" json:"create_time"`
|
||
}
|