123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 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())
- }
- }
|