jiangshuai
2023-12-15 fda60dd56911c03330eb7330ebabd5d46e9d7622
controllers/location_product_amount.go
@@ -12,8 +12,10 @@
   "wms/extend/code"
   "wms/extend/util"
   "wms/models"
   "wms/pkg/mysqlx"
   "wms/request"
   "wms/response"
   "wms/service"
)
type LocationProductAmountController struct {
@@ -60,13 +62,13 @@
   if params.Page*params.PageSize > 0 {
      search.Orm = search.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize)
   }
   if err := search.Orm.Order("wms_location_product_amount.updated_at desc").Find(&records).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
   if err := search.Orm.Order("wms_location_product_amount.updated_at desc").Find(&records).Error; err != nil {
      util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err))
      return
   }
   var operation models.Operation
   for k, v := range records {
      if res := models.NewOperationSearch().Orm.Preload("Details", "product_id=?", v.ProductId).Where("wms_operation.base_operation_type=? and wms_operation.status=? and wms_operation.to_location_id=?", constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready, v.LocationId).First(&operation); res.Error != nil {
      if res := mysqlx.GetDB().Table("wms_operation").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id").Where("wms_operation.base_operation_type=? and wms_operation.status=? and wms_operation.to_location_id=? and wms_operation_details.product_id=?", constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready, v.LocationId, v.ProductId).First(&operation); res.Error != nil {
         if errors.Is(res.Error, gorm.ErrRecordNotFound) {
            records[k].Status = constvar.OperationStatus_Finish
            records[k].BaseOperationType = constvar.BaseOperationTypeAdjust
@@ -174,6 +176,8 @@
   }); err != nil {
      return err
   }
   service.AddNewLocationReportRecord(locAmount.Id)
   return nil
}