package dao import ( "github.com/druidcaesa/gotool" "ulink-admin/frame" "ulink-admin/modules/system/models/model" "ulink-admin/modules/system/models/req" "ulink-admin/pkg/base" "ulink-admin/pkg/page" ) type NoticeDao struct { base.BaseDao } // Find 查询集合 func (d NoticeDao) Page(query *req.NoticeQuery) (*[]model.SysNotice, int64) { notices := make([]model.SysNotice, 0) session := d.GetSession().Table(model.SysNotice{}.TableName()) if gotool.StrUtils.HasNotEmpty(query.NoticeTitle) { session.And("notice_title like concat('%', ?, '%')", query.NoticeTitle) } if gotool.StrUtils.HasNotEmpty(query.NoticeType) { session.And("notice_type = ?", query.NoticeType) } if gotool.StrUtils.HasNotEmpty(query.CreateBy) { session.And("create_by like concat('%', ?, '%')", query.CreateBy) } total, err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).FindAndCount(¬ices) if err != nil { frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error()) } return ¬ices, total } func (d NoticeDao) List(query *req.NoticeQuery, list interface{}) { session := d.GetSession().Table(model.SysNotice{}.TableName()) if gotool.StrUtils.HasNotEmpty(query.NoticeTitle) { session.And("notice_title like concat('%', ?, '%')", query.NoticeTitle) } if gotool.StrUtils.HasNotEmpty(query.NoticeType) { session.And("notice_type = ?", query.NoticeType) } if gotool.StrUtils.HasNotEmpty(query.CreateBy) { session.And("create_by like concat('%', ?, '%')", query.CreateBy) } err := session.Find(list) if err != nil { frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error()) } }