@@ -0,0 +1,58 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// Album 创作者专辑
|
||||
// 表: official_website_album
|
||||
type Album struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
HeroID primitive.ObjectID `json:"heroID" bson:"heroID"` //创作者ID
|
||||
Title string `json:"title" bson:"title"`
|
||||
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
||||
Description string `json:"description" bson:"description"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
IsHot bool `json:"isHot" bson:"isHot"`
|
||||
Tags []Tag `json:"tags" bson:"tags"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (a *Album) tableName() string { return tableAlbum }
|
||||
|
||||
func (a *Album) FindOne(filter M) error {
|
||||
return findOneByTable(a.tableName(), a, filter)
|
||||
}
|
||||
|
||||
func (a *Album) FindMany(filter M, opts ...*options.FindOptions) ([]Album, error) {
|
||||
out := make([]Album, 0)
|
||||
err := findManyByTable(a.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (a *Album) Count(filter M) (int64, error) {
|
||||
return countByTable(a.tableName(), filter)
|
||||
}
|
||||
|
||||
func (a *Album) Create() error {
|
||||
a.CreatedAt = time.Now().UTC()
|
||||
a.UpdatedAt = a.CreatedAt
|
||||
id, err := createByTable(a.tableName(), a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
a.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Album) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(a.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (a Album) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(a.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"91porn-server/common/stderr"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// BasicData 官方网站公用数据结构,包括基础静态数据和CMS动态数据
|
||||
// 表: official_website_basic_data
|
||||
type BasicData struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
|
||||
// 轮播图和创作者轮博分开
|
||||
Banner []Banner `json:"banner" bson:"banner"`
|
||||
HeroBanner []HeroBanner `json:"heroBanner" bson:"heroBanner"`
|
||||
BannersDescription string `json:"bannersDescription" bson:"bannersDescription"`
|
||||
BannersDuration int `json:"bannersDuration" bson:"bannersDuration"`
|
||||
Masterpiece []Masterpiece `json:"masterpiece" bson:"masterpiece"`
|
||||
Business []Business `json:"business" bson:"business"`
|
||||
AboutUs AboutUs `json:"aboutUs" bson:"aboutUs"`
|
||||
FAQ []FAQ `json:"faq" bson:"faq"`
|
||||
HomePageCMS []CMSData `json:"homePageCMS" bson:"homePageCMS"`
|
||||
HomePageCMSDescription string `json:"homePageCMSDescription" bson:"homePageCMSDescription"`
|
||||
RecruitCMS []CMSData `json:"recruitCMS" bson:"recruitCMS"`
|
||||
Tags []Tag `json:"tags" bson:"tags"` // 标签列表
|
||||
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (b *BasicData) tableName() string {
|
||||
return tableBasicData
|
||||
}
|
||||
|
||||
func (b *BasicData) FindOne() error {
|
||||
if b == nil {
|
||||
return stderr.ErrDataInvalid
|
||||
}
|
||||
return findOneByTable(b.tableName(), b, nil)
|
||||
}
|
||||
|
||||
func (b *BasicData) Create() error {
|
||||
if b == nil {
|
||||
return stderr.ErrDataInvalid
|
||||
}
|
||||
oldOne := &BasicData{}
|
||||
if err := oldOne.FindOne(); err == nil && oldOne.ID != primitive.NilObjectID {
|
||||
return stderr.OfficialWebsiteBasicDataExist
|
||||
}
|
||||
|
||||
b.CreatedAt = time.Now().UTC()
|
||||
b.UpdatedAt = b.CreatedAt
|
||||
id, err := createByTable(b.tableName(), b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *BasicData) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(b.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (b *BasicData) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(b.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type BusinessData struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Type string `json:"type" bson:"type"` // 业务类型,如"adPlacement", "contentProduction", "subRevenue"
|
||||
ServiceOverview string `json:"serviceOverview" bson:"serviceOverview"`
|
||||
CollaborationProcess string `json:"collaborationProcess" bson:"collaborationProcess"`
|
||||
CaseStudies string `json:"caseStudies" bson:"caseStudies"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (b *BusinessData) tableName() string { return tableBusiness }
|
||||
|
||||
func (b *BusinessData) FindOne(filter M) error {
|
||||
return findOneByTable(b.tableName(), &b, filter)
|
||||
}
|
||||
|
||||
func (b *BusinessData) FindMany(filter M, opts ...*options.FindOptions) ([]BusinessData, error) {
|
||||
out := make([]BusinessData, 0)
|
||||
err := findManyByTable(b.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (b *BusinessData) Count(filter M) (int64, error) {
|
||||
return countByTable(b.tableName(), filter)
|
||||
}
|
||||
|
||||
func (b BusinessData) Create() error {
|
||||
b.CreatedAt = time.Now().UTC()
|
||||
b.UpdatedAt = b.CreatedAt
|
||||
id, err := createByTable(b.tableName(), b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *BusinessData) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(b.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (b *BusinessData) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(b.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func notDeletedFilter() M {
|
||||
return M{
|
||||
"$or": bson.A{
|
||||
M{"deletedAt": M{"$exists": false}},
|
||||
M{"deletedAt": nil},
|
||||
M{"deletedAt": time.Time{}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func withNotDeletedFilter(filter M) M {
|
||||
if filter == nil {
|
||||
return notDeletedFilter()
|
||||
} else {
|
||||
copied := M{}
|
||||
for k, v := range filter {
|
||||
copied[k] = v
|
||||
}
|
||||
filter = copied
|
||||
}
|
||||
|
||||
if _, ok := filter["deletedAt"]; ok {
|
||||
return filter
|
||||
}
|
||||
|
||||
return M{
|
||||
"$and": bson.A{
|
||||
filter,
|
||||
notDeletedFilter(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func findOneByTable(table string, out interface{}, filter M) error {
|
||||
filter = withNotDeletedFilter(filter)
|
||||
return coll(nil, table).FindOne(out, filter)
|
||||
}
|
||||
|
||||
func findManyByTable(table string, out interface{}, filter M, opts ...*options.FindOptions) error {
|
||||
filter = withNotDeletedFilter(filter)
|
||||
return coll(nil, table).Find(out, filter, opts...)
|
||||
}
|
||||
|
||||
func countByTable(table string, filter M) (int64, error) {
|
||||
filter = withNotDeletedFilter(filter)
|
||||
return coll(nil, table).Count(filter)
|
||||
}
|
||||
|
||||
func createByTable(table string, doc interface{}) (primitive.ObjectID, error) {
|
||||
res, err := coll(nil, table).InsertOne(doc)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
id, ok := res.InsertedID.(primitive.ObjectID)
|
||||
if !ok {
|
||||
return primitive.NilObjectID, errors.New("inserted id is not ObjectID")
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func createManyByTable(table string, docs []Video) ([]primitive.ObjectID, error) {
|
||||
insertIds, err := coll(nil, table).InsertMany(docs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var ids []primitive.ObjectID
|
||||
for _, v := range insertIds.InsertedIDs {
|
||||
id, ok := v.(primitive.ObjectID)
|
||||
if !ok {
|
||||
return nil, errors.New("inserted id is not ObjectID")
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func updateByTable(table string, filter M, update M) (int64, error) {
|
||||
if len(filter) == 0 {
|
||||
return 0, errors.New("update filter is empty")
|
||||
}
|
||||
if len(update) == 0 {
|
||||
return 0, errors.New("update doc is empty")
|
||||
}
|
||||
res, err := coll(nil, table).UpdateOne(filter, update)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.ModifiedCount, nil
|
||||
}
|
||||
|
||||
func updateManyByTable(table string, filter M, update M) (int64, error) {
|
||||
if len(filter) == 0 {
|
||||
return 0, errors.New("update filter is empty")
|
||||
}
|
||||
if len(update) == 0 {
|
||||
return 0, errors.New("update doc is empty")
|
||||
}
|
||||
res, err := coll(nil, table).UpdateMany(filter, update)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.ModifiedCount, nil
|
||||
}
|
||||
|
||||
func deleteByTable(table string, filter M) (int64, error) {
|
||||
if len(filter) == 0 {
|
||||
return 0, errors.New("delete filter is empty")
|
||||
}
|
||||
res, err := coll(nil, table).DeleteMany(filter)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.DeletedCount, nil
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type Banner struct {
|
||||
Name string `json:"name" bson:"name"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Image string `json:"image" bson:"image"`
|
||||
PhoneImage string `json:"phoneImage" bson:"phoneImage"`
|
||||
Thumbnail string `json:"thumbnail" bson:"thumbnail"`
|
||||
URL string `json:"url" bson:"url"`
|
||||
}
|
||||
|
||||
type HeroBanner struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
HeroID primitive.ObjectID `json:"heroId" bson:"heroId"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Image string `json:"image" bson:"image"`
|
||||
URL string `json:"url" bson:"url"`
|
||||
Duration int `json:"duration" bson:"duration"`
|
||||
}
|
||||
|
||||
type Masterpiece struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Type string `json:"type" bson:"type"` // 作品类型,如"video", "article", "album"
|
||||
}
|
||||
|
||||
type Business struct {
|
||||
Name string `json:"name" bson:"name"`
|
||||
EnglishName string `json:"englishName" bson:"englishName"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Detail []BusinessDetail `json:"detail" bson:"detail"`
|
||||
}
|
||||
|
||||
type BusinessDetail struct {
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
}
|
||||
|
||||
type AboutUs struct {
|
||||
Description string `json:"description" bson:"description"`
|
||||
Companies []CompanyInfo `json:"companies" bson:"companies"`
|
||||
Values string `json:"values" bson:"values"`
|
||||
ValuesImg string `json:"valuesImg" bson:"valuesImg"`
|
||||
}
|
||||
|
||||
type CompanyInfo struct {
|
||||
Name string `json:"name" bson:"name"`
|
||||
Address string `json:"address" bson:"address"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Contact []ContactInfo `json:"contact" bson:"contact"`
|
||||
}
|
||||
|
||||
type Source struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
IsActive bool `json:"isActive" bson:"isActive"`
|
||||
Type string `json:"type" bson:"type"`
|
||||
Domain Domain `json:"domain" bson:"domain"`
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
Weight int `json:"weight" bson:"weight"`
|
||||
Url string `json:"url" bson:"url"`
|
||||
Desc string `json:"desc" bson:"desc"`
|
||||
Status int `json:"status" bson:"status"`
|
||||
}
|
||||
|
||||
type FAQ struct {
|
||||
Question string `json:"question" bson:"question"`
|
||||
Answer string `json:"answer" bson:"answer"`
|
||||
}
|
||||
|
||||
type CMSData struct {
|
||||
Description string `json:"description" bson:"description"`
|
||||
Value string `json:"value" bson:"value"`
|
||||
}
|
||||
|
||||
type ContactInfo struct {
|
||||
Type string `json:"type" bson:"type"`
|
||||
Value string `json:"value" bson:"value"`
|
||||
}
|
||||
|
||||
type SortModel struct {
|
||||
Sort int64 `json:"sort" bson:"sort"`
|
||||
IsActive bool `json:"isActive" bson:"isActive"`
|
||||
}
|
||||
|
||||
type BaseModel struct {
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
|
||||
DeletedAt *time.Time `json:"deletedAt" bson:"deletedAt"`
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// Hero 创作者
|
||||
// 表: official_website_hero
|
||||
type Hero struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
||||
Avatar string `json:"avatar" bson:"avatar"`
|
||||
Height int64 `json:"height" bson:"height"`
|
||||
Bust int64 `json:"bust" bson:"bust"`
|
||||
Waist int64 `json:"waist" bson:"waist"`
|
||||
Hip int64 `json:"hip" bson:"hip"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
FansCount int64 `json:"fansCount" bson:"fansCount"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Partners []primitive.ObjectID `json:"partners" bson:"partners"` //合作伙伴ID列表
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (h *Hero) tableName() string { return tableHero }
|
||||
|
||||
func (h *Hero) FindOne(filter M) error {
|
||||
return findOneByTable(h.tableName(), &h, filter)
|
||||
}
|
||||
|
||||
func (h *Hero) FindMany(filter M, opts ...*options.FindOptions) ([]Hero, error) {
|
||||
out := make([]Hero, 0)
|
||||
err := findManyByTable(h.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (h *Hero) Count(filter M) (int64, error) {
|
||||
return countByTable(h.tableName(), filter)
|
||||
}
|
||||
|
||||
func (h *Hero) Create() error {
|
||||
h.CreatedAt = time.Now().UTC()
|
||||
h.UpdatedAt = h.CreatedAt
|
||||
id, err := createByTable(h.tableName(), h)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Hero) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(h.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (h *Hero) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(h.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"91porn-server/common/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type M = bson.M
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
const (
|
||||
tableBasicData = "official_website_basic_data"
|
||||
tableHero = "official_website_hero"
|
||||
tableAlbum = "official_website_album"
|
||||
tableVideo = "official_website_video"
|
||||
tableTag = "official_website_tag"
|
||||
tableRecruitForm = "official_website_recruit_form"
|
||||
tableJobList = "official_website_job"
|
||||
tableNews = "official_website_news"
|
||||
tableNewsDetail = "official_website_news_detail"
|
||||
tablePartner = "official_website_partner"
|
||||
tableBusiness = "official_website_business"
|
||||
tablePhotograph = "official_website_photograph"
|
||||
)
|
||||
|
||||
func coll(t *db.MongoTool, tableName string) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(tableName)
|
||||
}
|
||||
return t.Coll(tableName)
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(tableBasicData)
|
||||
initIndex()
|
||||
}
|
||||
|
||||
func initIndex() {
|
||||
// 需要 seoSlug 唯一标识的表:稀疏唯一索引(空值不参与唯一约束,配合 bson omitempty)
|
||||
seoSlugTables := []string{tableHero, tableAlbum, tableVideo, tablePhotograph, tableNews}
|
||||
for _, table := range seoSlugTables {
|
||||
if _, err := coll(nil, table).CreateIndex([]mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "seoSlug", Value: 1}},
|
||||
Options: options.Index().SetUnique(true).SetSparse(true),
|
||||
},
|
||||
}); err != nil {
|
||||
panic(fmt.Sprintf("officialWebsite seoSlug index err [%s] ==> [%+v]", table, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// JobList 招聘页岗位列表
|
||||
// 表: official_website_job_list
|
||||
type Job struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Requirements string `json:"requirements" bson:"requirements"`
|
||||
Benefits string `json:"benefits" bson:"benefits"`
|
||||
JDUrl string `json:"jdUrl" bson:"jdUrl"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (j *Job) tableName() string { return tableJobList }
|
||||
|
||||
func (j *Job) FindOne(filter M) error {
|
||||
return findOneByTable(j.tableName(), &j, filter)
|
||||
}
|
||||
|
||||
func (j *Job) FindMany(filter M, opts ...*options.FindOptions) ([]Job, error) {
|
||||
out := make([]Job, 0)
|
||||
err := findManyByTable(j.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (j *Job) Count(filter M) (int64, error) {
|
||||
return countByTable(j.tableName(), filter)
|
||||
}
|
||||
|
||||
func (j *Job) Create() error {
|
||||
j.CreatedAt = time.Now().UTC()
|
||||
j.UpdatedAt = j.CreatedAt
|
||||
id, err := createByTable(j.tableName(), j)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
j.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *Job) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(j.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (j *Job) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(j.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// News 资讯
|
||||
// 表: official_website_news
|
||||
type News struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"`
|
||||
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
||||
Description string `json:"description" bson:"description"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Url string `json:"url" bson:"url"`
|
||||
Tags []Tag `json:"tags" bson:"tags"`
|
||||
Detail string `json:"detail" bson:"detail"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (n *News) tableName() string { return tableNews }
|
||||
|
||||
func (n *News) FindOne(filter M) error {
|
||||
return findOneByTable(n.tableName(), &n, filter)
|
||||
}
|
||||
|
||||
func (n *News) FindMany(filter M, opts ...*options.FindOptions) ([]News, error) {
|
||||
out := make([]News, 0)
|
||||
err := findManyByTable(n.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (n *News) Count(filter M) (int64, error) {
|
||||
return countByTable(n.tableName(), filter)
|
||||
}
|
||||
|
||||
func (n *News) Create() error {
|
||||
n.CreatedAt = time.Now().UTC()
|
||||
n.UpdatedAt = n.CreatedAt
|
||||
id, err := createByTable(n.tableName(), n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *News) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(n.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (n *News) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(n.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type Partner struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Logo string `json:"logo" bson:"logo"`
|
||||
Url string `json:"url" bson:"url"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (p *Partner) tableName() string { return tablePartner }
|
||||
|
||||
func (p *Partner) FindOne(filter M) error {
|
||||
return findOneByTable(p.tableName(), &p, filter)
|
||||
}
|
||||
|
||||
func (p *Partner) FindMany(filter M, opts ...*options.FindOptions) ([]Partner, error) {
|
||||
out := make([]Partner, 0)
|
||||
err := findManyByTable(p.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (p *Partner) Count(filter M) (int64, error) {
|
||||
return countByTable(p.tableName(), filter)
|
||||
}
|
||||
|
||||
func (p *Partner) Create() error {
|
||||
p.CreatedAt = time.Now().UTC()
|
||||
p.UpdatedAt = p.CreatedAt
|
||||
id, err := createByTable(p.tableName(), p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Partner) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(p.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (p *Partner) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(p.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type Photograph struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
HeroID primitive.ObjectID `json:"heroId" bson:"heroId"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
||||
Description string `json:"description" bson:"description"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Photos []string `json:"photos" bson:"photos"`
|
||||
Tags []Tag `json:"tags" bson:"tags"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (p *Photograph) tableName() string {
|
||||
return tablePhotograph
|
||||
}
|
||||
|
||||
func (p *Photograph) FindOne(filter M) error {
|
||||
return findOneByTable(p.tableName(), p, filter)
|
||||
}
|
||||
|
||||
func (p *Photograph) FindMany(filter M, opts ...*options.FindOptions) ([]Photograph, error) {
|
||||
out := make([]Photograph, 0)
|
||||
err := findManyByTable(p.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (p *Photograph) Count(filter M) (int64, error) {
|
||||
return countByTable(p.tableName(), filter)
|
||||
}
|
||||
|
||||
func (p *Photograph) Create() error {
|
||||
p.CreatedAt = time.Now().UTC()
|
||||
p.UpdatedAt = p.CreatedAt
|
||||
id, err := createByTable(p.tableName(), p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Photograph) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(p.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (p *Photograph) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(p.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// RecruitForm 招募页面表单
|
||||
// 表: official_website_recruit_form
|
||||
type RecruitForm struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Sex int `json:"sex" bson:"sex"`
|
||||
Age int `json:"age" bson:"age"`
|
||||
Country string `json:"country" bson:"country"`
|
||||
Address string `json:"address" bson:"address"`
|
||||
Contact []ContactInfo `json:"contact" bson:"contact"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (r *RecruitForm) tableName() string { return tableRecruitForm }
|
||||
|
||||
func (r *RecruitForm) FindOne(filter M) error {
|
||||
return findOneByTable(r.tableName(), &r, filter)
|
||||
}
|
||||
|
||||
func (r *RecruitForm) FindMany(filter M, opts ...*options.FindOptions) ([]RecruitForm, error) {
|
||||
out := make([]RecruitForm, 0)
|
||||
err := findManyByTable(r.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (r *RecruitForm) Count(filter M) (int64, error) {
|
||||
return countByTable(r.tableName(), filter)
|
||||
}
|
||||
|
||||
func (r *RecruitForm) Create() error {
|
||||
r.CreatedAt = time.Now().UTC()
|
||||
r.UpdatedAt = r.CreatedAt
|
||||
id, err := createByTable(r.tableName(), r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RecruitForm) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(r.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (r *RecruitForm) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(r.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const (
|
||||
OfficialWebsiteTagTypeVideo = "video"
|
||||
OfficialWebsiteTagTypeHero = "hero"
|
||||
OfficialWebsiteTagTypeAlbum = "album"
|
||||
)
|
||||
|
||||
// Tag 标签
|
||||
// 表: official_website_tag
|
||||
type Tag struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Type string `json:"type" bson:"type"`
|
||||
IsHot bool `json:"isHot" bson:"isHot"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (t *Tag) tableName() string { return tableTag }
|
||||
|
||||
func (t *Tag) FindOne(filter M) error {
|
||||
return findOneByTable(t.tableName(), &t, filter)
|
||||
}
|
||||
|
||||
func (t *Tag) FindMany(filter M, opts ...*options.FindOptions) ([]Tag, error) {
|
||||
out := make([]Tag, 0)
|
||||
err := findManyByTable(t.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (t *Tag) Count(filter M) (int64, error) {
|
||||
return countByTable(t.tableName(), filter)
|
||||
}
|
||||
|
||||
func (t *Tag) Create() error {
|
||||
t.CreatedAt = time.Now().UTC()
|
||||
t.UpdatedAt = t.CreatedAt
|
||||
id, err := createByTable(t.tableName(), t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Tag) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(t.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (t *Tag) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(t.tableName(), filter)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// Video 创作者视频
|
||||
// 表: official_website_video
|
||||
type Video struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
AlbumID primitive.ObjectID `json:"albumId" bson:"albumId"`
|
||||
HeroID primitive.ObjectID `json:"heroId" bson:"heroId"` //创作者ID
|
||||
Title string `json:"title" bson:"title"`
|
||||
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
||||
Description string `json:"description" bson:"description"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Url string `json:"url" bson:"url"`
|
||||
Tags []Tag `json:"tags" bson:"tags"`
|
||||
IsHot bool `json:"isHot" bson:"isHot"`
|
||||
WatchCount int64 `json:"watchCount" bson:"watchCount"`
|
||||
LikeCount int64 `json:"likeCount" bson:"likeCount"`
|
||||
CommentCount int64 `json:"commentCount" bson:"commentCount"`
|
||||
CollectCount int64 `json:"collectCount" bson:"collectCount"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (v *Video) tableName() string { return tableVideo }
|
||||
|
||||
func (v *Video) FindOne(filter M) error {
|
||||
return findOneByTable(v.tableName(), &v, filter)
|
||||
}
|
||||
|
||||
func (v *Video) FindMany(filter M, opts ...*options.FindOptions) ([]Video, error) {
|
||||
out := make([]Video, 0)
|
||||
err := findManyByTable(v.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (v *Video) Count(filter M) (int64, error) {
|
||||
return countByTable(v.tableName(), filter)
|
||||
}
|
||||
|
||||
func (v *Video) Create() error {
|
||||
v.CreatedAt = time.Now().UTC()
|
||||
v.UpdatedAt = v.CreatedAt
|
||||
id, err := createByTable(v.tableName(), v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Video) InsertMany(videos []Video) (ids []primitive.ObjectID, err error) {
|
||||
//var docs []interface{}
|
||||
//for _, video := range videos {
|
||||
// docs = append(docs, video)
|
||||
//}
|
||||
return createManyByTable(v.tableName(), videos)
|
||||
}
|
||||
|
||||
func (v *Video) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(v.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (v *Video) UpdateMany(filter M, update M) (int64, error) {
|
||||
return updateManyByTable(v.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (v *Video) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(v.tableName(), filter)
|
||||
}
|
||||
Reference in New Issue
Block a user