From 98d8fba819eab8683ea9fa54b8978cde4c7e07ff Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 05 七月 2024 18:19:10 +0800
Subject: [PATCH] 两个月度统计下载如果下载的是当前月,取实时数据 & 修复若干bug

---
 controllers/operation.go |  102 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 86 insertions(+), 16 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 83a9b32..41e3932 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -94,7 +94,15 @@
 		params.WarehouseId = operationType.WarehouseId
 	}
 
+	if params.DealerType == "" {
+		CheckInventoryDealerType(&params)
+	}
+
 	userInfo := middleware.GetUserInfo(c)
+	if userInfo == nil {
+		util.ResponseFormat(c, code.SetStatusError, "鐧诲綍鐢ㄦ埛淇℃伅涓虹┖锛岃鐧诲綍鍚庨噸璇曪紒")
+		return
+	}
 	params.CreatedBy = userInfo.Username
 	params.Status = constvar.OperationStatus_Ready
 	//params.Number = strconv.FormatInt(time.Now().Unix(), 10)
@@ -137,6 +145,39 @@
 		return
 	}
 	util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
+}
+
+func CheckInventoryDealerType(params *models.Operation) {
+	var dictType constvar.MiniDictType
+	dictName := "鍏朵粬"
+	switch params.BaseOperationType {
+	case constvar.BaseOperationTypeIncoming:
+		dictType = constvar.StorageType
+		//dictName = dictName + "鍏ュ簱"
+	case constvar.BaseOperationTypeOutgoing:
+		dictType = constvar.StockoutType
+		//dictName = dictName + "鍑哄簱"
+	case constvar.BaseOperationTypeInternal:
+		dictType = constvar.TransferType
+		//dictName = dictName + "璋冩嫧"
+	case constvar.BaseOperationTypeDisuse:
+		dictType = constvar.DisuseType
+		//dictName = dictName + "鎶ュ簾"
+	case constvar.BaseOperationTypeAdjust:
+		dictType = constvar.TakeStockType
+		//dictName = dictName + "鐩樼偣"
+	default:
+		return
+	}
+	miniDict, err := models.NewMiniDictSearch().SetType(dictType).SetName(dictName).First()
+	if err == gorm.ErrRecordNotFound {
+		miniDict = &models.MiniDict{
+			Type: dictType,
+			Name: dictName,
+		}
+		models.NewMiniDictSearch().Create(miniDict)
+	}
+	params.DealerType = miniDict.Name
 }
 
 func CheckDetailsRepeat(details []*models.OperationDetails) bool {
@@ -212,12 +253,8 @@
 
 	if params.OperationTypeId == 0 && int(params.BaseOperationType) == 0 {
 		return errors.New("鏈瘑鍒璁板綍绫诲瀷1")
-	}
-
-	if params.BaseOperationType != 0 {
-		if params.WarehouseId == 0 {
-			return errors.New("鏈瘑鍒璁板綍绫诲瀷2")
-		}
+	} else if params.OperationTypeId == 0 && params.BaseOperationType != 0 && params.WarehouseId == 0 {
+		return errors.New("鏈瘑鍒璁板綍绫诲瀷2")
 	}
 
 	if params.OperationDate == "" {
@@ -250,12 +287,11 @@
 
 // GetOperationInfo
 // @Tags      鍏ュ簱/鍑哄簱
-// @Summary   鍏ュ簱/鍑哄簱鍒楄〃
+// @Summary   鎿嶄綔璇︽儏鎺ュ彛
 // @Produce   application/json
-//
-//	@Param		id	path		string			true	"id"
-//
-// @Success   200 {object} util.Response	"鎴愬姛"
+// @Param	  id path  string true "id"
+// @Param     Authorization	header string true "token"
+// @Success   200 {object} util.Response{data=models.Operation}	"鎴愬姛"
 // @Router    /api-wms/v1/operation/getOperationInfo/{id} [get]
 func (slf OperationController) GetOperationInfo(c *gin.Context) {
 	number := c.Param("id")
@@ -269,6 +305,26 @@
 		util.ResponseFormat(c, code.RequestParamError, err.Error())
 		return
 	}
+
+	if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing || operation.BaseOperationType == constvar.BaseOperationTypeInternal { //鏌ヨ瀹炴椂鍦ㄥ簱搴撳瓨
+		productIds := make([]string, 0)
+		locationIds := make([]int, 0)
+		for _, v := range operation.Details {
+			productIds = append(productIds, v.ProductId)
+			locationIds = append(locationIds, v.FromLocationID)
+		}
+		locationAmountMap, err := service.GetLocationAmounts(productIds, locationIds)
+		if err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浜у搧搴撳瓨閿欒")
+			return
+		}
+		for _, v := range operation.Details {
+			if locationAmountMap[v.ProductId] != nil {
+				v.StockAmount = locationAmountMap[v.ProductId][v.FromLocationID]
+			}
+		}
+	}
+
 	util.ResponseFormat(c, code.Success, operation)
 }
 
@@ -277,7 +333,7 @@
 // @Summary   鍏ュ簱/鍑哄簱鍒楄〃
 // @Produce   application/json
 // @Param		 object  body  request.OperationList true  "鏌ヨ鍙傛暟"
-// @Success   200 {object} util.ResponseList{data=[]models.Operation}	"鎴愬姛"
+// @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
@@ -315,7 +371,22 @@
 		util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触:"+err.Error())
 		return
 	}
+	//userList, err := user.GetUserList()
+	//userMap := make(map[string]string)
+	//if err == nil {
+	//	for _, user := range userList {
+	//		userMap[user.UserName] = user.NickName
+	//	}
+	//}
+	userInfo := middleware.GetUserInfo(c)
 	for _, v := range list {
+		v.CreatedBy = userInfo.NickName
+		//if err == nil {
+		if userInfo != nil {
+			//	v.CreatedBy = userMap[v.CreatedBy]
+			//	v.CheckedBy = userMap[v.CheckedBy]
+			v.CheckedBy = userInfo.NickName
+		}
 		for _, v1 := range v.Details {
 			//v1.SalePrice = decimal.NewFromFloat(1.2345)
 			//v1.Cost = decimal.NewFromFloat(9.678)
@@ -791,7 +862,7 @@
 					return
 				}
 			} else {
-				fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryIn, operation)
+				fileUrl, err = JialianOperation2(constvar.FileTemplateCategory_JialianInput1, operation)
 				if err != nil {
 					util.ResponseFormat(c, code.RequestParamError, err.Error())
 					return
@@ -829,7 +900,7 @@
 				}
 
 			} else {
-				fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryOut, operation)
+				fileUrl, err = JialianOperation2(constvar.FileTemplateCategory_JialianOutput1, operation)
 				if err != nil {
 					util.ResponseFormat(c, code.RequestParamError, err.Error())
 					return
@@ -1370,8 +1441,7 @@
 // @Tags      鍏ュ簱/鍑哄簱
 // @Summary   鑾峰彇浜哄憳鍒楄〃
 // @Produce   application/json
-// @Param     object  body  request.OperationCondition true  "鍙傛暟"
-// @Success   200 {object} util.ResponseList{data=[]inventory_order.WorkerInfo} "鎴愬姛"
+// @Success   200 {object} util.Response "鎴愬姛"
 // @Router    /api-wms/v1/operation/getPersonnelList [get]
 func (slf OperationController) GetPersonnelList(c *gin.Context) {
 	cli := inventory_order.NewInventoryOrderServiceClient(init_client.ApsConn)

--
Gitblit v1.8.0