| | |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:合同名称"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Client Client `json:"client" gorm:"foreignKey:ClientId"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"` |
| | | ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:联系人id"` |
| | | OrderType int `json:"orderType" gorm:"column:order_type;type:int;comment:工单类型"` |
| | |
| | | SourceSheet int `json:"sourceSheet" gorm:"column:source_sheet;type:int;comment:来源单据"` |
| | | ProblemDescription string `json:"problemDescription" gorm:"column:problem_description;type:text;comment:问题描述"` |
| | | File string `json:"file" gorm:"column:file;type:varchar(255);comment:附件"` |
| | | gorm.Model `json:"-"` |
| | | } |
| | | |
| | | OrderManageSearch struct { |
| | | OrderManage |
| | | Orm *gorm.DB |
| | | |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | } |
| | | ) |
| | | |
| | |
| | | |
| | | func (slf *OrderManageSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&OrderManage{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *OrderManageSearch) FindAll() ([]*OrderManage, error) { |
| | | func (slf *OrderManageSearch) FindAll() ([]*OrderManage, int64, error) { |
| | | var db = slf.build() |
| | | var record = make([]*OrderManage, 0) |
| | | err := db.Find(&record).Error |
| | | return record, err |
| | | var records = make([]*OrderManage, 0) |
| | | var total int64 |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, err |
| | | } |
| | | if slf.PageNum > 0 && slf.PageSize > 0 { |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Preload("Client").Order("id desc").Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *OrderManageSearch) SetId(id int) *OrderManageSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OrderManageSearch) SetKeyword(keyword string) *OrderManageSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OrderManageSearch) SetPage(page, size int) *OrderManageSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OrderManageSearch) SetOrder(order string) *OrderManageSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | func (slf *OrderManageSearch) SetIds(ids []int) *OrderManageSearch { |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids) |
| | | return slf |
| | | } |