From 2fc832067f778903dce3ac451661b3d5f0b2678b Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Sat, 23 Nov 2024 15:28:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao/article_cate_dao.go | 10 ++++++ src/dao/article_dao.go | 11 ++++++ src/implement/article_cate_implement.go | 35 +++++++++++++++++++ src/implement/article_implement.go | 46 +++++++++++++++++++++++++ src/model/article.go | 19 ++++++++++ src/model/article_cate.go | 9 +++++ 6 files changed, 130 insertions(+) create mode 100644 src/dao/article_cate_dao.go create mode 100644 src/dao/article_dao.go create mode 100644 src/implement/article_cate_implement.go create mode 100644 src/implement/article_implement.go create mode 100644 src/model/article.go create mode 100644 src/model/article_cate.go diff --git a/src/dao/article_cate_dao.go b/src/dao/article_cate_dao.go new file mode 100644 index 0000000..6f011cd --- /dev/null +++ b/src/dao/article_cate_dao.go @@ -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) +} diff --git a/src/dao/article_dao.go b/src/dao/article_dao.go new file mode 100644 index 0000000..76f94bf --- /dev/null +++ b/src/dao/article_dao.go @@ -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) +} diff --git a/src/implement/article_cate_implement.go b/src/implement/article_cate_implement.go new file mode 100644 index 0000000..0a56257 --- /dev/null +++ b/src/implement/article_cate_implement.go @@ -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 +} diff --git a/src/implement/article_implement.go b/src/implement/article_implement.go new file mode 100644 index 0000000..1f62b77 --- /dev/null +++ b/src/implement/article_implement.go @@ -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 +} diff --git a/src/model/article.go b/src/model/article.go new file mode 100644 index 0000000..b332dee --- /dev/null +++ b/src/model/article.go @@ -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)"` +} diff --git a/src/model/article_cate.go b/src/model/article_cate.go new file mode 100644 index 0000000..535c487 --- /dev/null +++ b/src/model/article_cate.go @@ -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)"` +}