关于自动回复的数据库设计

93 阅读2分钟

关于goland连接数据主要使用 xorm 这个库,有兴趣的可以看看。

基础字段

常用的字段如下:

	Id         string    `xorm:"varchar(64) pk notnull unique 'id' comment('用户id')"`
	Enable     bool      `xorm:"Bool notnull  'enable' default 1 comment('是否可用')"`
	CreateId         string    `xorm:"varchar(64) pk notnull  'create_id' comment('创建操作id')"`
	CreateTime time.Time `xorm:"DateTime notnull created  'create_time' comment('创建时间')"`
	UpdateId         string    `xorm:"varchar(64) pk notnull  'update_id' comment('更新操作id')"`
	UpdateTime time.Time `xorm:"DateTime notnull updated  'update_time' comment('更新时间')"`

由于数据是逻辑删除,因此使用 Enable 即可。

用户表

按照之前设想的逻辑,首先需要微信公众号去创建账号,在基础字段上添加一个字段,存储微信公众号的openid:

	PbOpenId   string    `xorm:"varchar(255)  'pb_openid' comment('公众号用户openid')" json:"pb_openid"`

可以绑定微信小程序,因此在基础字段上再添加一个字段,存储微信小程序的openid,保持账号的唯一性:

ApOpenId   string    `xorm:"varchar(255)  'ap_openid' comment('小程序用户openid')" json:"ap_openid"`

自动回复设置表

回复设置表主要是看页面有些设置的数据,然后使用相关字段标记存储就好了:

AutoReply      bool      `xorm:"Bool   'auto_reply' default 0 comment('是否开启自动回复')" json:"auto_reply"`
	AutoReplyGroup bool      `xorm:"Bool   'auto_reply_group' default 0 comment('是否开启群艾特自动回复')" json:"auto_reply_group"`
	AutoBot        string    `xorm:"varchar(255)   'auto_bot' default('nobot') comment('机器人类型, tuling chatgpt')" json:"auto_bot"`
	AutoDesc       string    `xorm:"varchar(255)   'auto_desc' default('正在忙') comment('自动回复文案')" json:"auto_desc"`
	TulingApiKey   string    `xorm:"varchar(255)   'tuling_api_key' comment('图灵机器人 key')" json:"tuling_api_key"`
	Enable         bool      `xorm:"Bool  'enable' default 0 comment('是否在运行')"`

由于设置表 跟 用户表是 一对一的关系,因此在设置表中再添加一个用户id的字段关联:

UserId         string    `xorm:"varchar(255) notnull  unique 'user_id' comment('用户id')" json:"user_id"`