package dao import ( "github.com/druidcaesa/gotool" "ulink-admin/frame" "ulink-admin/modules/car/models/model" "ulink-admin/modules/car/models/req" "ulink-admin/pkg/base" "ulink-admin/pkg/page" ) type ViolationDao struct { base.BaseDao } // Page 查询服务项目分页数据 func (this ViolationDao) Page(query *req.ViolationQuery) (*[]model.Violation, int64) { violation := make([]model.Violation, 0) session := this.GetSession().Table(model.Violation{}.TableName()) if query.Id > 0 { session.And("id = ?", query.Id) } if !gotool.StrUtils.HasEmpty(query.Item) { session.And("item = ?", query.Item) } if !gotool.StrUtils.HasEmpty(query.Label) { session.And("Label = ?", query.Label) } if !gotool.StrUtils.HasEmpty(query.Content) { session.And("content = ?", query.Content) } if query.Score > 0 { session.And("score = ?", query.Score) } if !gotool.StrUtils.HasEmpty(query.CreateBy) { session.And("create_by = ?", query.CreateBy) } if !gotool.StrUtils.HasEmpty(query.UpdateBy) { session.And("update_by = ?", query.UpdateBy) } if !gotool.StrUtils.HasEmpty(query.BeginTime) { session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime) } if !gotool.StrUtils.HasEmpty(query.EndTime) { session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime) } total, err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).FindAndCount(&violation) if err != nil { frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error()) } return &violation, total } // List 查询服务项目分页数据 func (this ViolationDao) List(query *req.ViolationQuery, list interface{}) { session := this.GetSession().Table(model.Violation{}.TableName()) if query.Id > 0 { session.And("id = ?", query.Id) } if !gotool.StrUtils.HasEmpty(query.Item) { session.And("item = ?", query.Item) } if !gotool.StrUtils.HasEmpty(query.Label) { session.And("Label = ?", query.Label) } if !gotool.StrUtils.HasEmpty(query.Content) { session.And("content = ?", query.Content) } if query.Score > 0 { session.And("score = ?", query.Score) } if !gotool.StrUtils.HasEmpty(query.CreateBy) { session.And("create_by = ?", query.CreateBy) } if !gotool.StrUtils.HasEmpty(query.UpdateBy) { session.And("update_by = ?", query.UpdateBy) } if !gotool.StrUtils.HasEmpty(query.BeginTime) { session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime) } if !gotool.StrUtils.HasEmpty(query.EndTime) { session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime) } err := session.Find(list) if err != nil { frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error()) } }