From 1d15c41503273f7605237a715e5835b9920d0526 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 26 Nov 2024 10:53:29 +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 | 2 ++ src/dao/article_dao.go | 4 ++- src/implement/article_cate_implement.go | 27 +++++++++++++++++++ src/implement/article_implement.go | 36 ++++++++++++++++++++++++- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/dao/article_cate_dao.go b/src/dao/article_cate_dao.go index 6f011cd..1086288 100644 --- a/src/dao/article_cate_dao.go +++ b/src/dao/article_cate_dao.go @@ -7,4 +7,6 @@ import ( type ArticleCateDao interface { GetArticleCate(id string) (m *model.ArticleCate, err error) ArticleCateByPid(pid string) (*[]model.ArticleCate, error) + FindArticleCate(page, limit, pid string) (*[]model.ArticleCate, error) + FindArticleCateAndTotal(page, limit, pid string) (*[]model.ArticleCate, int64, error) } diff --git a/src/dao/article_dao.go b/src/dao/article_dao.go index 76f94bf..06415c5 100644 --- a/src/dao/article_dao.go +++ b/src/dao/article_dao.go @@ -6,6 +6,8 @@ import ( type ArticleDao interface { GetArticle(id string) (m *model.Article, err error) - ArticleCateByTypeId(typeId string) (m *model.Article, err error) + ArticleByTypeId(typeId string) (m *model.Article, err error) ArticleByCid(cid string) (*[]model.Article, error) + FindArticle(page, limit, pid, cateId string) (*[]model.Article, error) + FindArticleAndTotal(page, limit, pid, cateId string) (*[]model.Article, int64, error) } diff --git a/src/implement/article_cate_implement.go b/src/implement/article_cate_implement.go index 0a56257..70c4d90 100644 --- a/src/implement/article_cate_implement.go +++ b/src/implement/article_cate_implement.go @@ -3,6 +3,7 @@ package implement import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils" zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -33,3 +34,29 @@ func (a ArticleCateDb) ArticleCateByPid(pid string) (*[]model.ArticleCate, error } return &m, nil } +func (a ArticleCateDb) FindArticleCate(page, limit, pid string) (*[]model.ArticleCate, error) { + var m []model.ArticleCate + sess := a.Db.Where("1=1") + start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit) + if pid != "" { + sess.And("pid=?", pid) + } + err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").Find(&m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + return &m, nil +} +func (a ArticleCateDb) FindArticleCateAndTotal(page, limit, pid string) (*[]model.ArticleCate, int64, error) { + var m []model.ArticleCate + sess := a.Db.Where("1=1") + start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit) + if pid != "" { + sess.And("pid=?", pid) + } + count, err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").FindAndCount(&m) + if err != nil { + return nil, count, zhios_order_relate_logx.Error(err) + } + return &m, count, nil +} diff --git a/src/implement/article_implement.go b/src/implement/article_implement.go index 1f62b77..3b8232a 100644 --- a/src/implement/article_implement.go +++ b/src/implement/article_implement.go @@ -3,6 +3,7 @@ package implement import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils" zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -26,7 +27,7 @@ func (a ArticleDb) GetArticle(id string) (m *model.Article, err error) { } return m, nil } -func (a ArticleDb) ArticleCateByTypeId(typeId string) (m *model.Article, err error) { +func (a ArticleDb) ArticleByTypeId(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 { @@ -44,3 +45,36 @@ func (a ArticleDb) ArticleByCid(cid string) (*[]model.Article, error) { } return &m, nil } + +func (a ArticleDb) FindArticle(page, limit, pid, cateId string) (*[]model.Article, error) { + var m []model.Article + sess := a.Db.Where("1=1") + start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit) + if pid != "" { + sess.And("pid=?", pid) + } + if cateId != "" { + sess.And("cate_id=?", cateId) + } + err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").Find(&m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + return &m, nil +} +func (a ArticleDb) FindArticleAndTotal(page, limit, pid, cateId string) (*[]model.Article, int64, error) { + var m []model.Article + sess := a.Db.Where("1=1") + start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit) + if pid != "" { + sess.And("pid=?", pid) + } + if cateId != "" { + sess.And("cate_id=?", cateId) + } + count, err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").FindAndCount(&m) + if err != nil { + return nil, count, zhios_order_relate_logx.Error(err) + } + return &m, count, nil +}