lishihai
2024-06-20 504f3e9bc274bcd6c7221e738802e0e5d4aef36f
models/operation.go
@@ -4,6 +4,7 @@
   "fmt"
   "github.com/shopspring/decimal"
   "gorm.io/gorm"
   "time"
   "wms/constvar"
   "wms/pkg/mysqlx"
)
@@ -14,7 +15,7 @@
      WmsModel
      Id                int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
      Number            string                   `json:"number" gorm:"type:varchar(255)"`                           //单号
      SourceNumber      string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                     //源单号
      SourceNumber      string                   `json:"sourceNumber" gorm:"index;type:varchar(255)"`               //源单号
      OperationTypeId   int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"`   //作业类型id
      OperationTypeName string                   `json:"operationTypeName" gorm:"type:varchar(127);comment:作业类型名称"` //作业类型名称
      Status            constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`            //状态
@@ -22,18 +23,19 @@
      //FromLocation      Location                 `json:"fromLocation"     gorm:"foreignKey:FromLocationID;references:Id"` //源位置
      //ToLocationID      int                      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"`         //目标位置id
      //ToLocation        Location                 `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"`    //目标位置
      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-客户"`
      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"`
      LogisticCompany   LogisticCompany `json:"logisticCompany"      gorm:"foreignKey:LogisticCompanyId"`
      WaybillNumber     string          `json:"waybillNumber" gorm:"type:varchar(255);comment:运单号"`    //运单号
      Weight            decimal.Decimal `gorm:"type:decimal(20,2);comment:重量" json:"weight"`           //重量
      LogisticWeight    decimal.Decimal `gorm:"type:decimal(20,2);comment:物流重量" json:"logisticWeight"` //物流重量
      Source            string          `json:"source" gorm:"type:varchar(255);comment:来源系统,用于返回修改状态"`
      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         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"`
      LogisticCompany   LogisticCompany          `json:"logisticCompany"      gorm:"foreignKey:LogisticCompanyId"`
      WaybillNumber     string                   `json:"waybillNumber" gorm:"type:varchar(255);comment:运单号"`    //运单号
      Weight            decimal.Decimal          `gorm:"type:decimal(20,2);comment:重量" json:"weight"`           //重量
      LogisticWeight    decimal.Decimal          `gorm:"type:decimal(20,2);comment:物流重量" json:"logisticWeight"` //物流重量
      Source            string                   `json:"source" gorm:"type:varchar(255);comment:来源系统,用于返回修改状态"`
      OperationSource   constvar.OperationSource `json:"operationSource" gorm:"type:tinyint(3);not null;default:0;comment:操作来源"` //操作来源
      Details           []*OperationDetails        `json:"details" gorm:"foreignKey:OperationID;references:Id"`
      BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:基础作业类型"` //基础作业类型
@@ -48,19 +50,34 @@
      ToLocationID       int      `json:"toLocationId"    gorm:"type:int;not null;comment:仓库位置id"`      //目标位置id
      ToLocation         Location `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"` //目标位置
      SalesDetailsNumber string   `gorm:"type:varchar(191);comment:销售明细编码" json:"salesDetailsNumber"`
      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 {
      Operation
      Order    string
      PageNum  int
      PageSize int
      Keyword  string
      Orm      *gorm.DB
      Preload  bool
      Disuse   bool
      Ids      []int
      Numbers  []string
      Order               string
      PageNum             int
      PageSize            int
      Keyword             string
      Orm                 *gorm.DB
      Preload             bool
      Disuse              bool
      Ids                 []int
      SourceNumbers       []string
      SalesDetailsNumbers []string
      Fields              string
      BeginTime           time.Time
      EndTime             time.Time
   }
)
@@ -97,6 +114,11 @@
   return slf
}
func (slf *OperationSearch) SetFields(fields string) *OperationSearch {
   slf.Fields = fields
   return slf
}
func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch {
   slf.OperationTypeId = operationTypeId
   return slf
@@ -114,6 +136,11 @@
func (slf *OperationSearch) SetSourceNumber(sourceNumber string) *OperationSearch {
   slf.SourceNumber = sourceNumber
   return slf
}
func (slf *OperationSearch) SetSourceNumbers(numbers []string) *OperationSearch {
   slf.SourceNumbers = numbers
   return slf
}
@@ -142,6 +169,22 @@
   return slf
}
func (slf *OperationSearch) SetSalesDetailsNumbers(salesDetailsNumbers []string) *OperationSearch {
   slf.SalesDetailsNumbers = salesDetailsNumbers
   return slf
}
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
}
func (slf *OperationSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&Operation{})
@@ -158,6 +201,10 @@
   if slf.SourceNumber != "" {
      db = db.Where("source_number = ?", slf.SourceNumber)
   }
   if len(slf.SourceNumbers) > 0 {
      db = db.Where("source_number in (?)", slf.SourceNumbers)
   }
   if slf.Number != "" {
@@ -192,6 +239,21 @@
      db = db.Where("sales_details_number = ?", slf.SalesDetailsNumber)
   }
   if len(slf.SalesDetailsNumbers) > 0 {
      db = db.Where("sales_details_number in (?)", slf.SalesDetailsNumbers)
   }
   if slf.OperationSource != 0 {
      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
}
@@ -315,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 (
@@ -364,3 +438,13 @@
   }
   return int(total), nil
}
func (slf *OperationSearch) Count() (int64, error) {
   var (
      total int64
      db    = slf.build()
   )
   err := db.Count(&total).Error
   return total, err
}