violation_dao.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package dao
  2. import (
  3. "github.com/druidcaesa/gotool"
  4. "ulink-admin/frame"
  5. "ulink-admin/modules/car/models/model"
  6. "ulink-admin/modules/car/models/req"
  7. "ulink-admin/pkg/base"
  8. "ulink-admin/pkg/page"
  9. )
  10. type ViolationDao struct {
  11. base.BaseDao
  12. }
  13. // Page 查询服务项目分页数据
  14. func (this ViolationDao) Page(query *req.ViolationQuery) (*[]model.Violation, int64) {
  15. violation := make([]model.Violation, 0)
  16. session := this.GetSession().Table(model.Violation{}.TableName())
  17. if query.Id > 0 {
  18. session.And("id = ?", query.Id)
  19. }
  20. if !gotool.StrUtils.HasEmpty(query.Item) {
  21. session.And("item = ?", query.Item)
  22. }
  23. if !gotool.StrUtils.HasEmpty(query.Label) {
  24. session.And("Label = ?", query.Label)
  25. }
  26. if !gotool.StrUtils.HasEmpty(query.Content) {
  27. session.And("content = ?", query.Content)
  28. }
  29. if query.Score > 0 {
  30. session.And("score = ?", query.Score)
  31. }
  32. if !gotool.StrUtils.HasEmpty(query.CreateBy) {
  33. session.And("create_by = ?", query.CreateBy)
  34. }
  35. if !gotool.StrUtils.HasEmpty(query.UpdateBy) {
  36. session.And("update_by = ?", query.UpdateBy)
  37. }
  38. if !gotool.StrUtils.HasEmpty(query.BeginTime) {
  39. session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime)
  40. }
  41. if !gotool.StrUtils.HasEmpty(query.EndTime) {
  42. session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime)
  43. }
  44. total, err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).FindAndCount(&violation)
  45. if err != nil {
  46. frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
  47. }
  48. return &violation, total
  49. }
  50. // List 查询服务项目分页数据
  51. func (this ViolationDao) List(query *req.ViolationQuery, list interface{}) {
  52. session := this.GetSession().Table(model.Violation{}.TableName())
  53. if query.Id > 0 {
  54. session.And("id = ?", query.Id)
  55. }
  56. if !gotool.StrUtils.HasEmpty(query.Item) {
  57. session.And("item = ?", query.Item)
  58. }
  59. if !gotool.StrUtils.HasEmpty(query.Label) {
  60. session.And("Label = ?", query.Label)
  61. }
  62. if !gotool.StrUtils.HasEmpty(query.Content) {
  63. session.And("content = ?", query.Content)
  64. }
  65. if query.Score > 0 {
  66. session.And("score = ?", query.Score)
  67. }
  68. if !gotool.StrUtils.HasEmpty(query.CreateBy) {
  69. session.And("create_by = ?", query.CreateBy)
  70. }
  71. if !gotool.StrUtils.HasEmpty(query.UpdateBy) {
  72. session.And("update_by = ?", query.UpdateBy)
  73. }
  74. if !gotool.StrUtils.HasEmpty(query.BeginTime) {
  75. session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime)
  76. }
  77. if !gotool.StrUtils.HasEmpty(query.EndTime) {
  78. session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime)
  79. }
  80. err := session.Find(list)
  81. if err != nil {
  82. frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
  83. }
  84. }