From 260b3fbc34b4e9ae2ee53e4a7917abb72ef848a7 Mon Sep 17 00:00:00 2001 From: dsmzx <dsmzx@123.com> Date: 星期二, 02 七月 2024 15:44:15 +0800 Subject: [PATCH] 出库/入库打印 修改bug --- controllers/operation.go | 87 ++++++++++++++++++++++++------------------- 1 files changed, 49 insertions(+), 38 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index e174c67..4828007 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -63,37 +63,46 @@ return } - if err := slf.FormatLocation(¶ms); err != nil { - util.ResponseFormat(c, code.RequestParamError, err.Error()) - return - } - if CheckDetailsRepeat(params.Details) { util.ResponseFormat(c, code.RequestParamError, "鏄庣粏涓笉鑳藉瓨鍦ㄩ噸澶嶇殑浜у搧") return } - var operationType *models.OperationType - var err error - if params.OperationTypeId == 0 { - operationType, err = models.NewOperationTypeSearch().SetWarehouseId(params.WarehouseId).SetBaseOperationType(params.BaseOperationType).First() - if err != nil || params.WarehouseId != operationType.WarehouseId { - util.ResponseFormat(c, code.RequestParamError, "鍙傛暟缂哄け") - return - } - } else { - operationType, err = models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() - if err != nil { + + if params.BaseOperationType != constvar.BaseOperationTypeAdjust { + if err := slf.FormatLocation(¶ms); err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return } + + var operationType *models.OperationType + var err error + if params.OperationTypeId == 0 { + operationType, err := models.NewOperationTypeSearch(). + SetWarehouseId(params.WarehouseId).SetBaseOperationType(params.BaseOperationType). + First() + if err != nil || params.WarehouseId != operationType.WarehouseId { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟缂哄け") + return + } + } else { + operationType, err = models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + } + params.BaseOperationType = operationType.BaseOperationType + params.WarehouseId = operationType.WarehouseId } userInfo := middleware.GetUserInfo(c) params.CreatedBy = userInfo.Username params.Status = constvar.OperationStatus_Ready //params.Number = strconv.FormatInt(time.Now().Unix(), 10) - params.BaseOperationType = operationType.BaseOperationType - params.WarehouseId = operationType.WarehouseId + + for _, detail := range params.Details { + detail.BaseOperationType = params.BaseOperationType + } var numberNum int64 if err := mysqlx.GetDB().Model(&models.Operation{}).Where("number=?", params.Number).Count(&numberNum).Error; err != nil { @@ -104,7 +113,7 @@ util.ResponseFormat(c, code.RequestParamError, "鍗曞彿宸插瓨鍦�") return } - err = models.WithTransaction(func(db *gorm.DB) error { + err := models.WithTransaction(func(db *gorm.DB) error { if err := models.NewOperationSearch().Create(¶ms); err != nil { return err } @@ -148,6 +157,7 @@ return false } +// FormatLocation 浣嶇疆妫�鏌� func (slf OperationController) FormatLocation(params *models.Operation) error { operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() if err != nil { @@ -215,9 +225,9 @@ return errors.New("璇烽�夋嫨瀹夋帓鏃ユ湡") } - if params.LocationID == 0 { - return errors.New("璇烽�夋嫨婧愪綅缃�") - } + //if params.LocationID == 0 { + // return errors.New("璇烽�夋嫨婧愪綅缃�") + //} if len(params.Details) <= 0 { return errors.New("璇锋坊鍔犳槑缁嗕俊鎭�") @@ -268,7 +278,7 @@ // @Summary 鍏ュ簱/鍑哄簱鍒楄〃 // @Produce application/json // @Param object body request.OperationList true "鏌ヨ鍙傛暟" -// @Success 200 {object} util.Response "鎴愬姛" +// @Success 200 {object} util.ResponseList{data=[]models.Operation} "鎴愬姛" // @Router /api-wms/v1/operation/list [post] func (slf OperationController) List(c *gin.Context) { var params request.OperationList @@ -358,9 +368,12 @@ util.ResponseFormat(c, code.RequestParamError, "鏄庣粏涓笉鑳藉瓨鍦ㄩ噸澶嶇殑浜у搧") return } - if err := slf.FormatLocation(¶ms); err != nil { - util.ResponseFormat(c, code.RequestParamError, err.Error()) - return + + if params.BaseOperationType != constvar.BaseOperationTypeAdjust { + if err := slf.FormatLocation(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } } if err := models.WithTransaction(func(tx *gorm.DB) error { if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(params.Id).Delete(); err != nil { @@ -772,15 +785,15 @@ return } - if warehouse.FileTemplateCategoryIn == constvar.FileTemplateCategory_JialianInput1 { - fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryIn, operation) + if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 { + fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryIn, operation) if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return } - } else if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 { - fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryIn, operation) + } else if warehouse.FileTemplateCategoryIn == constvar.FileTemplateCategory_JialianInput1 { + fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryIn, operation) if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return @@ -812,15 +825,15 @@ return } - if warehouse.FileTemplateCategoryOut == constvar.FileTemplateCategory_JialianOutput1 { - fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryOut, operation) + if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 { + fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation) if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return } - } else if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 { - fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation) + } else if warehouse.FileTemplateCategoryOut == constvar.FileTemplateCategory_JialianOutput1 { + fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryOut, operation) if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return @@ -988,9 +1001,8 @@ } fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes()) - ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) if err != nil { - //ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) + ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) logx.Errorf("file upload err: %v", err) return "", err } @@ -1108,8 +1120,8 @@ } fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes()) - ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) if err != nil { + ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) logx.Errorf("file upload err: %v", err) return "", err } @@ -1192,7 +1204,6 @@ logx.Errorf("file upload err: %v", err) return "", err } - return fileUrl, nil } -- Gitblit v1.8.0