notice_dao.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "github.com/druidcaesa/gotool"
  4. "ulink-admin/frame"
  5. "ulink-admin/modules/system/models/model"
  6. "ulink-admin/modules/system/models/req"
  7. "ulink-admin/pkg/base"
  8. "ulink-admin/pkg/page"
  9. )
  10. type NoticeDao struct {
  11. base.BaseDao
  12. }
  13. // Find 查询集合
  14. func (d NoticeDao) Page(query *req.NoticeQuery) (*[]model.SysNotice, int64) {
  15. notices := make([]model.SysNotice, 0)
  16. session := d.GetSession().Table(model.SysNotice{}.TableName())
  17. if gotool.StrUtils.HasNotEmpty(query.NoticeTitle) {
  18. session.And("notice_title like concat('%', ?, '%')", query.NoticeTitle)
  19. }
  20. if gotool.StrUtils.HasNotEmpty(query.NoticeType) {
  21. session.And("notice_type = ?", query.NoticeType)
  22. }
  23. if gotool.StrUtils.HasNotEmpty(query.CreateBy) {
  24. session.And("create_by like concat('%', ?, '%')", query.CreateBy)
  25. }
  26. total, err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).FindAndCount(&notices)
  27. if err != nil {
  28. frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
  29. }
  30. return &notices, total
  31. }
  32. func (d NoticeDao) List(query *req.NoticeQuery, list interface{}) {
  33. session := d.GetSession().Table(model.SysNotice{}.TableName())
  34. if gotool.StrUtils.HasNotEmpty(query.NoticeTitle) {
  35. session.And("notice_title like concat('%', ?, '%')", query.NoticeTitle)
  36. }
  37. if gotool.StrUtils.HasNotEmpty(query.NoticeType) {
  38. session.And("notice_type = ?", query.NoticeType)
  39. }
  40. if gotool.StrUtils.HasNotEmpty(query.CreateBy) {
  41. session.And("create_by like concat('%', ?, '%')", query.CreateBy)
  42. }
  43. err := session.Find(list)
  44. if err != nil {
  45. frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
  46. }
  47. }