huangjiajun 1 giorno fa
parent
commit
2fc832067f
6 ha cambiato i file con 130 aggiunte e 0 eliminazioni
  1. +10
    -0
      src/dao/article_cate_dao.go
  2. +11
    -0
      src/dao/article_dao.go
  3. +35
    -0
      src/implement/article_cate_implement.go
  4. +46
    -0
      src/implement/article_implement.go
  5. +19
    -0
      src/model/article.go
  6. +9
    -0
      src/model/article_cate.go

+ 10
- 0
src/dao/article_cate_dao.go Vedi File

@@ -0,0 +1,10 @@
package dao

import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
)

type ArticleCateDao interface {
GetArticleCate(id string) (m *model.ArticleCate, err error)
ArticleCateByPid(pid string) (*[]model.ArticleCate, error)
}

+ 11
- 0
src/dao/article_dao.go Vedi File

@@ -0,0 +1,11 @@
package dao

import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
)

type ArticleDao interface {
GetArticle(id string) (m *model.Article, err error)
ArticleCateByTypeId(typeId string) (m *model.Article, err error)
ArticleByCid(cid string) (*[]model.Article, error)
}

+ 35
- 0
src/implement/article_cate_implement.go Vedi File

@@ -0,0 +1,35 @@
package implement

import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"xorm.io/xorm"
)

func NewArticleCateDb(engine *xorm.Engine) dao.ArticleCateDao {
return &ArticleCateDb{Db: engine}
}

type ArticleCateDb struct {
Db *xorm.Engine
}

func (a ArticleCateDb) GetArticleCate(id string) (m *model.ArticleCate, err error) {
m = new(model.ArticleCate)
has, err := a.Db.Where("id=?", id).Get(m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}
func (a ArticleCateDb) ArticleCateByPid(pid string) (*[]model.ArticleCate, error) {
var m []model.ArticleCate
if err := a.Db.Where("pid=?", pid).Find(&m); err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}

+ 46
- 0
src/implement/article_implement.go Vedi File

@@ -0,0 +1,46 @@
package implement

import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"xorm.io/xorm"
)

func NewArticleDb(engine *xorm.Engine) dao.ArticleDao {
return &ArticleDb{Db: engine}
}

type ArticleDb struct {
Db *xorm.Engine
}

func (a ArticleDb) GetArticle(id string) (m *model.Article, err error) {
m = new(model.Article)
has, err := a.Db.Where("id=?", id).Get(m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}
func (a ArticleDb) ArticleCateByTypeId(typeId string) (m *model.Article, err error) {
m = new(model.Article)
has, err := a.Db.Where("is_show=1 and type_id=?", typeId).Get(m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}
func (a ArticleDb) ArticleByCid(cid string) (*[]model.Article, error) {
var m []model.Article
if err := a.Db.Where("cate_id=?", cid).Find(&m); err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}

+ 19
- 0
src/model/article.go Vedi File

@@ -0,0 +1,19 @@
package model

type Article struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Pid int `json:"pid" xorm:"not null default 0 comment('一级分类,对应article_cate表parent_id=0的记录') INT(11)"`
CateId int `json:"cate_id" xorm:"not null default 0 comment('分类ID') index INT(11)"`
TypeId int `json:"type_id" xorm:"not null default 0 comment('类型,对应article_cate表pid=0的记录') index INT(11)"`
Title string `json:"title" xorm:"not null default '' comment('标题') VARCHAR(255)"`
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示:0不显示;1显示') TINYINT(1)"`
CreatedAt int `json:"created_at" xorm:"comment('创建时间') INT(11)"`
UpdatedAt int `json:"updated_at" xorm:"comment('更新时间') INT(11)"`
Content string `json:"content" xorm:"comment('内容') LONGTEXT"`
Sort int `json:"sort" xorm:"not null default 0 comment('排序') INT(11)"`
Cover string `json:"cover" xorm:"comment('封面') VARCHAR(255)"`
Tags string `json:"tags" xorm:"comment('标签') VARCHAR(2048)"`
IsSelected int `json:"is_selected" xorm:"not null default 0 comment('是否精选') TINYINT(1)"`
IsRecommend int `json:"is_recommend" xorm:"not null default 0 comment('是否推荐') TINYINT(1)"`
Info string `json:"info" xorm:"default '' comment('文章描述') VARCHAR(255)"`
}

+ 9
- 0
src/model/article_cate.go Vedi File

@@ -0,0 +1,9 @@
package model

type ArticleCate struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Name string `json:"name" xorm:"VARCHAR(255)"`
Sort int `json:"sort" xorm:"default 0 INT(11)"`
Pid int `json:"pid" xorm:"default 0 INT(11)"`
IsShow int `json:"is_show" xorm:"default 0 INT(1)"`
}

Caricamento…
Annulla
Salva