整合数据
This commit is contained in:
+115
-148
@@ -1,53 +1,24 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// CmsArticle CMS文章表: yz_cms_article
|
||||
type CmsArticle struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Tid uint64 `orm:"column(tid)" json:"tid"`
|
||||
Title string `orm:"column(title);size(255)" json:"title"`
|
||||
Author string `orm:"column(author);size(100);default()" json:"author"`
|
||||
CateID uint64 `orm:"column(cate_id);default(0)" json:"cate_id"`
|
||||
Content string `orm:"column(content);type(text);null" json:"content"`
|
||||
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
|
||||
Image string `orm:"column(image);size(500);default()" json:"image"`
|
||||
IsTrans int8 `orm:"column(is_trans);default(0)" json:"is_trans"`
|
||||
TransURL *string `orm:"column(transurl);size(500);null" json:"transurl"`
|
||||
Status int8 `orm:"column(status);default(1)" json:"status"` // 1草稿 2已发布 3已下架
|
||||
Views int64 `orm:"column(views);default(0)" json:"views"`
|
||||
Likes int64 `orm:"column(likes);default(0)" json:"likes"`
|
||||
Top int8 `orm:"column(top);default(0)" json:"top"`
|
||||
Recommend int8 `orm:"column(recommend);default(0)" json:"recommend"`
|
||||
PublishTime *time.Time `orm:"column(publish_time);type(datetime);null" json:"publish_time"`
|
||||
PublisherID uint64 `orm:"column(publisher_id);default(0)" json:"publisher_id"`
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||||
}
|
||||
|
||||
func (m *CmsArticle) TableName() string {
|
||||
return "yz_cms_article"
|
||||
}
|
||||
|
||||
// CmsArticleCategory CMS文章分类表: yz_cms_article_category
|
||||
// CmsArticleCategory CMS 文章分类 yz_cms_article_category
|
||||
type CmsArticleCategory struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Tid uint64 `orm:"column(tid)" json:"tid"`
|
||||
Cid uint64 `orm:"column(cid);default(0)" json:"cid"` // 父级分类ID
|
||||
Tid uint64 `orm:"column(tid);default(0)" json:"tid"`
|
||||
Cid uint64 `orm:"column(cid);default(0)" json:"cid"`
|
||||
Name string `orm:"column(name);size(100)" json:"name"`
|
||||
Image string `orm:"column(image);size(500);default()" json:"image"`
|
||||
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
|
||||
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
||||
Status int8 `orm:"column(status);default(1)" json:"status"`
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);null" json:"update_time"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||||
}
|
||||
|
||||
@@ -55,137 +26,133 @@ func (m *CmsArticleCategory) TableName() string {
|
||||
return "yz_cms_article_category"
|
||||
}
|
||||
|
||||
// EnsureCmsArticleTables 确保 CMS 文章相关表存在。
|
||||
func EnsureCmsArticleTables() error {
|
||||
sqls := []string{
|
||||
`CREATE TABLE IF NOT EXISTS ` + "`yz_cms_article_category`" + ` (
|
||||
` + "`id`" + ` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
` + "`tid`" + ` bigint unsigned NOT NULL DEFAULT 0,
|
||||
` + "`cid`" + ` bigint unsigned NOT NULL DEFAULT 0,
|
||||
` + "`name`" + ` varchar(100) NOT NULL DEFAULT '',
|
||||
` + "`image`" + ` varchar(500) NOT NULL DEFAULT '',
|
||||
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
|
||||
` + "`sort`" + ` int NOT NULL DEFAULT 0,
|
||||
` + "`status`" + ` tinyint NOT NULL DEFAULT 1,
|
||||
` + "`create_time`" + ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
` + "`update_time`" + ` datetime NULL DEFAULT NULL,
|
||||
` + "`delete_time`" + ` datetime NULL DEFAULT NULL,
|
||||
PRIMARY KEY (` + "`id`" + `),
|
||||
KEY ` + "`idx_tid`" + ` (` + "`tid`" + `),
|
||||
KEY ` + "`idx_tid_cid`" + ` (` + "`tid`" + `,` + "`cid`" + `),
|
||||
KEY ` + "`idx_delete_time`" + ` (` + "`delete_time`" + `)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
|
||||
`CREATE TABLE IF NOT EXISTS ` + "`yz_cms_article`" + ` (
|
||||
` + "`id`" + ` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
` + "`tid`" + ` bigint unsigned NOT NULL DEFAULT 0,
|
||||
` + "`title`" + ` varchar(255) NOT NULL DEFAULT '',
|
||||
` + "`author`" + ` varchar(100) NOT NULL DEFAULT '',
|
||||
` + "`cate_id`" + ` bigint unsigned NOT NULL DEFAULT 0,
|
||||
` + "`content`" + ` longtext NULL,
|
||||
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
|
||||
` + "`image`" + ` varchar(500) NOT NULL DEFAULT '',
|
||||
` + "`is_trans`" + ` tinyint NOT NULL DEFAULT 0,
|
||||
` + "`transurl`" + ` varchar(500) NULL DEFAULT NULL,
|
||||
` + "`status`" + ` tinyint NOT NULL DEFAULT 1,
|
||||
` + "`views`" + ` bigint NOT NULL DEFAULT 0,
|
||||
` + "`likes`" + ` bigint NOT NULL DEFAULT 0,
|
||||
` + "`top`" + ` tinyint NOT NULL DEFAULT 0,
|
||||
` + "`recommend`" + ` tinyint NOT NULL DEFAULT 0,
|
||||
` + "`publish_time`" + ` datetime NULL DEFAULT NULL,
|
||||
` + "`publisher_id`" + ` bigint unsigned NOT NULL DEFAULT 0,
|
||||
` + "`create_time`" + ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
` + "`update_time`" + ` datetime NULL DEFAULT NULL,
|
||||
` + "`delete_time`" + ` datetime NULL DEFAULT NULL,
|
||||
PRIMARY KEY (` + "`id`" + `),
|
||||
KEY ` + "`idx_tid`" + ` (` + "`tid`" + `),
|
||||
KEY ` + "`idx_tid_cate`" + ` (` + "`tid`" + `,` + "`cate_id`" + `),
|
||||
KEY ` + "`idx_tid_status`" + ` (` + "`tid`" + `,` + "`status`" + `),
|
||||
KEY ` + "`idx_delete_time`" + ` (` + "`delete_time`" + `)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
|
||||
}
|
||||
|
||||
for _, sqlStr := range sqls {
|
||||
if _, err := Orm.Raw(sqlStr).Exec(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
// CmsArticle CMS 文章 yz_cms_article
|
||||
type CmsArticle struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Tid uint64 `orm:"column(tid);default(0)" json:"tid"`
|
||||
Title string `orm:"column(title);size(255)" json:"title"`
|
||||
Author string `orm:"column(author);size(100);default()" json:"author"`
|
||||
CateID uint64 `orm:"column(cate_id);default(0)" json:"cate_id"`
|
||||
Content string `orm:"column(content);type(mediumtext);null" json:"content"`
|
||||
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
|
||||
Image string `orm:"column(image);size(500);default()" json:"image"`
|
||||
IsTrans int8 `orm:"column(is_trans);default(0)" json:"is_trans"`
|
||||
TransURL *string `orm:"column(transurl);size(500);null" json:"transurl"`
|
||||
Status int8 `orm:"column(status);default(0)" json:"status"`
|
||||
Top int8 `orm:"column(top);default(0)" json:"top"`
|
||||
Recommend int8 `orm:"column(recommend);default(0)" json:"recommend"`
|
||||
Views int `orm:"column(views);default(0)" json:"views"`
|
||||
Likes int `orm:"column(likes);default(0)" json:"likes"`
|
||||
PublisherID *uint64 `orm:"column(publisher_id);null" json:"publisher_id"`
|
||||
PublishTime *time.Time `orm:"column(publish_time);type(datetime);null" json:"publish_time"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);null" json:"update_time"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||||
}
|
||||
|
||||
func (m *CmsArticle) TableName() string {
|
||||
return "yz_cms_article"
|
||||
}
|
||||
|
||||
var cmsArticleTablesOnce sync.Once
|
||||
|
||||
// EnsureCmsArticleTables 首次使用时自动建表(若不存在)。
|
||||
func EnsureCmsArticleTables() error {
|
||||
var err error
|
||||
cmsArticleTablesOnce.Do(func() {
|
||||
_, err = Orm.Raw(`
|
||||
CREATE TABLE IF NOT EXISTS yz_cms_article_category (
|
||||
id bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
tid bigint unsigned NOT NULL DEFAULT 0,
|
||||
cid bigint unsigned NOT NULL DEFAULT 0,
|
||||
name varchar(100) NOT NULL DEFAULT '',
|
||||
image varchar(500) NOT NULL DEFAULT '',
|
||||
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
|
||||
sort int NOT NULL DEFAULT 0,
|
||||
status tinyint NOT NULL DEFAULT 1,
|
||||
create_time datetime NOT NULL,
|
||||
update_time datetime DEFAULT NULL,
|
||||
delete_time datetime DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_tid_cid (tid, cid)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`).Exec()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = Orm.Raw(`
|
||||
CREATE TABLE IF NOT EXISTS yz_cms_article (
|
||||
id bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
tid bigint unsigned NOT NULL DEFAULT 0,
|
||||
title varchar(255) NOT NULL DEFAULT '',
|
||||
author varchar(100) NOT NULL DEFAULT '',
|
||||
cate_id bigint unsigned NOT NULL DEFAULT 0,
|
||||
content mediumtext,
|
||||
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
|
||||
image varchar(500) NOT NULL DEFAULT '',
|
||||
is_trans tinyint NOT NULL DEFAULT 0,
|
||||
transurl varchar(500) DEFAULT NULL,
|
||||
status tinyint NOT NULL DEFAULT 0,
|
||||
top tinyint NOT NULL DEFAULT 0,
|
||||
recommend tinyint NOT NULL DEFAULT 0,
|
||||
views int NOT NULL DEFAULT 0,
|
||||
likes int NOT NULL DEFAULT 0,
|
||||
publisher_id bigint unsigned DEFAULT NULL,
|
||||
publish_time datetime DEFAULT NULL,
|
||||
create_time datetime NOT NULL,
|
||||
update_time datetime DEFAULT NULL,
|
||||
delete_time datetime DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_tid_status (tid, status),
|
||||
KEY idx_cate_id (cate_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`).Exec()
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func CmsCategoryNameMap(tid uint64, ids []uint64) map[uint64]string {
|
||||
out := make(map[uint64]string)
|
||||
if len(ids) == 0 {
|
||||
return out
|
||||
}
|
||||
var rows []CmsArticleCategory
|
||||
_, _ = Orm.QueryTable(new(CmsArticleCategory)).
|
||||
Filter("tid", tid).
|
||||
Filter("id__in", ids).
|
||||
Filter("delete_time__isnull", true).
|
||||
All(&rows, "ID", "Name")
|
||||
for _, r := range rows {
|
||||
out[r.ID] = r.Name
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// CmsFormatTime 格式化 CMS 可空时间。
|
||||
func CmsFormatTime(t *time.Time) string {
|
||||
if t == nil || t.IsZero() {
|
||||
if t == nil {
|
||||
return ""
|
||||
}
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// CmsCategoryNameMap 批量获取分类ID到分类名称的映射。
|
||||
func CmsCategoryNameMap(tid uint64, cateIDs []uint64) map[uint64]string {
|
||||
result := make(map[uint64]string)
|
||||
if tid == 0 || len(cateIDs) == 0 {
|
||||
return result
|
||||
}
|
||||
|
||||
seen := make(map[uint64]bool)
|
||||
ids := make([]uint64, 0, len(cateIDs))
|
||||
for _, id := range cateIDs {
|
||||
if id == 0 || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return result
|
||||
}
|
||||
|
||||
var rows []CmsArticleCategory
|
||||
_, err := Orm.QueryTable(new(CmsArticleCategory)).
|
||||
Filter("tid", tid).
|
||||
Filter("id__in", ids).
|
||||
Filter("delete_time__isnull", true).
|
||||
All(&rows, "id", "name")
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
return result
|
||||
}
|
||||
for _, row := range rows {
|
||||
result[row.ID] = row.Name
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// CmsSimilarArticles 根据标题查找相似文章,用于创建文章时提示重复内容。
|
||||
func CmsSimilarArticles(tid uint64, title string, limit int) ([]map[string]interface{}, error) {
|
||||
title = strings.TrimSpace(title)
|
||||
if tid == 0 || title == "" {
|
||||
return []map[string]interface{}{}, nil
|
||||
}
|
||||
func CmsSimilarArticles(tid uint64, title string, limit int) ([]orm.Params, error) {
|
||||
if limit <= 0 {
|
||||
limit = 5
|
||||
}
|
||||
|
||||
var rows []CmsArticle
|
||||
_, err := Orm.QueryTable(new(CmsArticle)).
|
||||
Filter("tid", tid).
|
||||
Filter("title__icontains", title).
|
||||
Filter("delete_time__isnull", true).
|
||||
OrderBy("-id").
|
||||
Filter("title__icontains", title).
|
||||
Limit(limit).
|
||||
All(&rows, "id", "title", "cate_id", "status", "create_time")
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
All(&rows, "ID", "Title")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make([]map[string]interface{}, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"title": row.Title,
|
||||
"cate_id": row.CateID,
|
||||
"status": row.Status,
|
||||
"create_time": row.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
"similarity": fmt.Sprintf("标题包含“%s”", title),
|
||||
out := make([]orm.Params, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
out = append(out, orm.Params{
|
||||
"id": r.ID,
|
||||
"title": r.Title,
|
||||
"similarity": 80,
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
|
||||
+4
-2
@@ -56,11 +56,13 @@ func Init(_ string) {
|
||||
new(ComplaintCategory),
|
||||
new(PlatformComplaint),
|
||||
new(SystemSoftwareUpgrade),
|
||||
new(CmsArticle),
|
||||
new(CmsArticleCategory),
|
||||
new(PlatformCursorEquipment),
|
||||
new(PlatformCursorActivationCode),
|
||||
new(PlatformAccountPoolKiro),
|
||||
new(PlatformAccountPoolWindsurf),
|
||||
new(PlatformAccountPoolCursor),
|
||||
new(CmsArticleCategory),
|
||||
new(CmsArticle),
|
||||
)
|
||||
|
||||
// 创建全局 Ormer
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// PlatformCursorActivationCode Cursor 续杯激活码 yz_platform_cursor_activation_code
|
||||
type PlatformCursorActivationCode struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Code string `orm:"column(code);size(128);unique" json:"code"`
|
||||
Type int `orm:"column(type);default(30)" json:"type"`
|
||||
Status int8 `orm:"column(status);default(0)" json:"status"`
|
||||
DurationDays int `orm:"column(duration_days);default(30)" json:"durationDays"`
|
||||
BindAccount *string `orm:"column(bind_account);size(128);null" json:"bindAccount"`
|
||||
BindDeviceID *uint64 `orm:"column(bind_device_id);null" json:"bindDeviceId"`
|
||||
MachineCode *string `orm:"column(machine_code);size(128);null" json:"machineCode"`
|
||||
DeviceInfo *string `orm:"column(device_info);size(1000);null" json:"deviceInfo"`
|
||||
OwnerUserID *uint64 `orm:"column(owner_user_id);null" json:"ownerUserId"`
|
||||
OwnerUserName *string `orm:"column(owner_user_name);size(128);null" json:"ownerUserName"`
|
||||
ActivatedAt *time.Time `orm:"column(activated_at);type(datetime);null" json:"activatedAt"`
|
||||
ExpiredAt *time.Time `orm:"column(expired_at);type(datetime);null" json:"expiredAt"`
|
||||
Remark *string `orm:"column(remark);size(1000);null" json:"remark"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
|
||||
}
|
||||
|
||||
func (m *PlatformCursorActivationCode) TableName() string {
|
||||
return "yz_platform_cursor_activation_code"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// PlatformCursorEquipment Cursor 设备管理 yz_platform_cursor_equipment
|
||||
type PlatformCursorEquipment struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
DeviceInfo *string `orm:"column(device_info);size(1000);null" json:"deviceInfo"`
|
||||
MachineCode string `orm:"column(machine_code);size(128);unique" json:"machineCode"`
|
||||
Status int8 `orm:"column(status);default(0)" json:"status"`
|
||||
System *string `orm:"column(system);size(64);null" json:"system"`
|
||||
Version *string `orm:"column(version);size(64);null" json:"version"`
|
||||
BindAccount *string `orm:"column(bind_account);size(128);null" json:"bindAccount"`
|
||||
OwnerUserID *uint64 `orm:"column(owner_user_id);null" json:"ownerUserId"`
|
||||
OwnerUserName *string `orm:"column(owner_user_name);size(128);null" json:"ownerUserName"`
|
||||
ActivationTime *time.Time `orm:"column(activation_time);type(datetime);null" json:"activationTime"`
|
||||
ExpireTime *time.Time `orm:"column(expire_time);type(datetime);null" json:"expireTime"`
|
||||
Remark *string `orm:"column(remark);size(1000);null" json:"remark"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
|
||||
}
|
||||
|
||||
func (m *PlatformCursorEquipment) TableName() string {
|
||||
return "yz_platform_cursor_equipment"
|
||||
}
|
||||
@@ -16,5 +16,5 @@ type SystemTenantDomain struct {
|
||||
}
|
||||
|
||||
func (m *SystemTenantDomain) TableName() string {
|
||||
return "yz_tenant_domain"
|
||||
return "yz_system_tenant_domain"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user