zhangqian
2024-06-21 9c7551a7a752c07db11b0fd23bfba8da1ad062e0
models/operation.go
@@ -4,6 +4,7 @@
   "fmt"
   "github.com/shopspring/decimal"
   "gorm.io/gorm"
   "time"
   "wms/constvar"
   "wms/pkg/mysqlx"
)
@@ -25,7 +26,7 @@
      OperationDate     string                   `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"`
      ContacterID       int                      `json:"contacterID" gorm:"type:int;comment:联系人ID"`
      ContacterName     string                   `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"`
      CompanyID         int                      `json:"companyID" gorm:"type:int;comment:公司ID-客户"`
      CompanyID         string                   `json:"companyID" gorm:"type:varchar(255);comment:公司ID-客户"`
      CompanyName       string                   `json:"companyName" gorm:"type:varchar(127);comment:公司名称-客户"`
      Comment           string                   `json:"comment" gorm:"type:text;comment:备注"`
      LogisticCompanyId string                   `json:"logisticCompanyId"   gorm:"type:varchar(191);comment:物流公司id"`
@@ -50,9 +51,16 @@
      ToLocation         Location `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"` //目标位置
      SalesDetailsNumber string   `gorm:"type:varchar(191);comment:销售明细编码" json:"salesDetailsNumber"`
      Manager    string `json:"manager" gorm:"type:varchar(255);comment:主管"`
      Accountant string `json:"accountant" gorm:"type:varchar(255);comment:会计"`
      Custodian  string `json:"custodian" gorm:"type:varchar(255);comment:保管员"`
      ManagerId    string `json:"managerId" gorm:"type:varchar(255);comment:主管id"`
      Manager      string `json:"manager" gorm:"type:varchar(255);comment:主管名称"`
      AccountantId string `json:"accountantId" gorm:"type:varchar(255);comment:会计id"`
      Accountant   string `json:"accountant" gorm:"type:varchar(255);comment:会计名称"`
      CustodianId  string `json:"custodianId" gorm:"type:varchar(255);comment:保管员id"`
      Custodian    string `json:"custodian" gorm:"type:varchar(255);comment:保管员名称"`
      CreatedBy    string `json:"createBy" gorm:"type:varchar(255);comment:创建者UserId"`
      CheckedBy    string `json:"checkedBy" gorm:"type:varchar(255);comment:验证者UserId"`
      IsInternalOutput bool `json:"isInternalOutput"` //是否调拨产生的出库
   }
   OperationSearch struct {
@@ -67,6 +75,9 @@
      Ids                 []int
      SourceNumbers       []string
      SalesDetailsNumbers []string
      Fields              string
      BeginTime           time.Time
      EndTime             time.Time
   }
)
@@ -100,6 +111,11 @@
func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch {
   slf.Keyword = keyword
   return slf
}
func (slf *OperationSearch) SetFields(fields string) *OperationSearch {
   slf.Fields = fields
   return slf
}
@@ -160,6 +176,12 @@
func (slf *OperationSearch) SetOperationSource(operationSource constvar.OperationSource) *OperationSearch {
   slf.OperationSource = operationSource
   return slf
}
func (slf *OperationSearch) SetTimeBetween(beginTime, endTime time.Time) *OperationSearch {
   slf.BeginTime = beginTime
   slf.EndTime = endTime
   return slf
}
@@ -225,6 +247,13 @@
      db = db.Where("operation_source = ?", slf.OperationSource)
   }
   if slf.Fields != "" {
      db = db.Select(slf.Fields)
   }
   if !slf.BeginTime.IsZero() && !slf.EndTime.IsZero() {
      db = db.Where("created_at between ? and ?", slf.BeginTime, slf.EndTime)
   }
   return db
}
@@ -348,6 +377,18 @@
   return records, nil
}
func (slf *OperationSearch) FindIds() ([]int, error) {
   var (
      records = make([]int, 0)
      db      = slf.build()
   )
   if err := db.Find(&records).Error; err != nil {
      return records, fmt.Errorf("find records err: %v", err)
   }
   return records, nil
}
// FindByQuery 指定条件查询.
func (slf *OperationSearch) FindByQuery(query string, args []interface{}) ([]*Operation, int64, error) {
   var (