From d80428a19673e819440a34f2565b6dbbbe6ac567 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 18 七月 2024 22:32:08 +0800
Subject: [PATCH] fix
---
controllers/operation.go | 105 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 69 insertions(+), 36 deletions(-)
diff --git a/controllers/operation.go b/controllers/operation.go
index f0afda4..ae06b4b 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -9,7 +9,6 @@
"github.com/shopspring/decimal"
"github.com/xuri/excelize/v2"
"gorm.io/gorm"
- "sort"
"strconv"
"strings"
"time"
@@ -42,6 +41,7 @@
// @Tags 鍏ュ簱/鍑哄簱
// @Summary 娣诲姞鍏ュ簱/鍑哄簱
// @Produce application/json
+// @Param Authorization header string true "token"
// @Param object body request.AddOperation true "鍏ュ簱/鍑哄簱淇℃伅"
// @Success 200 {object} util.Response "鎴愬姛"
// @Router /api-wms/v1/operation/operation [post]
@@ -147,25 +147,26 @@
util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
}
+// CheckInventoryDealerType 妫�鏌ュ熀纭�绫诲瀷锛岄槻姝㈢被鍨嬩负绌烘坊鍔犲叾瀹冪被鍨�
func CheckInventoryDealerType(params *models.Operation) {
var dictType constvar.MiniDictType
- dictName := "鍏跺畠"
+ dictName := "鍏朵粬"
switch params.BaseOperationType {
case constvar.BaseOperationTypeIncoming:
dictType = constvar.StorageType
- //dictName = "鍏跺畠鍏ュ簱"
+ //dictName = dictName + "鍏ュ簱"
case constvar.BaseOperationTypeOutgoing:
dictType = constvar.StockoutType
- //dictName = "鍏跺畠鍑哄簱"
+ //dictName = dictName + "鍑哄簱"
case constvar.BaseOperationTypeInternal:
dictType = constvar.TransferType
- //dictName = "鍏跺畠璋冩嫧"
+ //dictName = dictName + "璋冩嫧"
case constvar.BaseOperationTypeDisuse:
dictType = constvar.DisuseType
- //dictName = "鍏跺畠鎶ュ簾"
+ //dictName = dictName + "鎶ュ簾"
case constvar.BaseOperationTypeAdjust:
dictType = constvar.TakeStockType
- //dictName = "鍏跺畠鐩樼偣"
+ //dictName = dictName + "鐩樼偣"
default:
return
}
@@ -180,19 +181,19 @@
params.DealerType = miniDict.Name
}
+// CheckDetailsRepeat 鍑哄簱銆佸叆搴撱�佺洏鐐规秹鍙婁骇鍝侀噸澶嶆�ф鏌ワ紙浠ヤ骇鍝佺紪鍙枫�佸嚭搴撳簱鎴跨紪鍙枫�佸叆搴撳簱鎴跨紪鍙凤級
+// 瀛樺湪閲嶅鍊� true锛� 涓嶅瓨鍦ㄨ繑鍥� false
func CheckDetailsRepeat(details []*models.OperationDetails) bool {
- var detailIDs []string
- var tempID string
- for _, v := range details {
- detailIDs = append(detailIDs, v.ProductId)
+ if len(details) == 0 {
+ return false
}
- sort.Strings(detailIDs)
- for _, v := range detailIDs {
- if v != tempID {
- tempID = v
- } else {
- return true
- }
+ var detailKeyMap = make(map[string]bool)
+ for _, v := range details {
+ key := fmt.Sprintf("%v%v%v", v.ProductId, v.FromLocationID, v.ToLocationID)
+ detailKeyMap[key] = true
+ }
+ if len(detailKeyMap) != len(details) { // 闀垮害鐩稿悓锛屼笉瀛樺湪閲嶅鍊硷紱闀垮害涓嶅悓瀛樺湪瀛樺湪涓嶅悓
+ return true
}
return false
}
@@ -287,12 +288,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")
@@ -306,6 +306,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)
}
@@ -313,6 +333,7 @@
// @Tags 鍏ュ簱/鍑哄簱
// @Summary 鍏ュ簱/鍑哄簱鍒楄〃
// @Produce application/json
+// @Param Authorization header string true "token"
// @Param object body request.OperationList true "鏌ヨ鍙傛暟"
// @Success 200 {object} util.ResponseList{data=[]models.Operation} "鎴愬姛"
// @Router /api-wms/v1/operation/list [post]
@@ -352,7 +373,7 @@
util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触:"+err.Error())
return
}
- //userList, err := service.GetUserList()
+ //userList, err := user.GetUserList()
//userMap := make(map[string]string)
//if err == nil {
// for _, user := range userList {
@@ -360,12 +381,16 @@
// }
//}
userInfo := middleware.GetUserInfo(c)
+ if userInfo == nil {
+ util.ResponseFormat(c, code.SetStatusError, "鐧诲綍鐢ㄦ埛淇℃伅涓虹┖锛岃鐧诲綍鍚庨噸璇曪紒")
+ return
+ }
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.CreatedBy = userInfo.NickName
v.CheckedBy = userInfo.NickName
}
for _, v1 := range v.Details {
@@ -463,6 +488,7 @@
// @Tags 鍏ュ簱/鍑哄簱
// @Summary 鍒犻櫎鍏ュ簱/鍑哄簱淇℃伅
// @Produce application/json
+// @Param Authorization header string true "token"
// @Param id path int true "id"
// @Success 200 {object} util.Response "鎴愬姛"
// @Router /api-wms/v1/operation/operation/{id} [delete]
@@ -510,9 +536,10 @@
// @Tags 鍏ュ簱/鍑哄簱
// @Summary 鏇存敼璁板綍鐘舵��
// @Produce application/json
-// @Param id path int true "id"
+// @Param Authorization header string true "token"
+// @Param id path int true "id"
// @Success 200 {object} util.Response "鎴愬姛"
-// @Router /api-wms/v1/operation/finish/{id} [put]
+// @Router /api-wms/v1/operation/finish/{id} [put]
func (slf OperationController) Finish(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
@@ -563,25 +590,26 @@
return err
}
- if operation.BaseOperationType == constvar.BaseOperationTypeIncoming {
+ if operation.BaseOperationType == constvar.BaseOperationTypeIncoming { // 鍏ュ簱
if err := service.FinishOperationInput(c, tx, operation, listDetails, mapLocAmount); err != nil {
return err
}
}
- if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing || operation.BaseOperationType == constvar.BaseOperationTypeDisuse {
+ if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing || // 鍑哄簱
+ operation.BaseOperationType == constvar.BaseOperationTypeDisuse { // 鎶ュ簾
if err := service.FinishOperationOutput(tx, listDetails, mapLocAmount, operation); err != nil {
return err
}
}
- if operation.BaseOperationType == constvar.BaseOperationTypeInternal {
+ if operation.BaseOperationType == constvar.BaseOperationTypeInternal { // 鍐呴儴璋冩嫧
if err := service.FinishOperationInternal(tx, listDetails, operation); err != nil {
return err
}
}
- if operation.BaseOperationType == constvar.BaseOperationTypeAdjust {
+ if operation.BaseOperationType == constvar.BaseOperationTypeAdjust { // 搴撳瓨鐩樼偣
if err := service.FinishOperationAdjust(tx, listDetails, mapLocAmount, operation); err != nil {
return err
}
@@ -604,7 +632,6 @@
go UpdateOutStatus(operation.Source, operation.SourceNumber, 4)
}
}
-
util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛")
}
@@ -837,7 +864,7 @@
}
if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 {
- fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryIn, operation)
+ fileUrl, err = JialianOperation1(constvar.FileWarehouseCategory_JialianInput2, operation)
if err != nil {
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
@@ -874,7 +901,7 @@
}
if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 {
- fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation)
+ fileUrl, err = JialianOperation1(constvar.FileWarehouseCategory_JialianOutput2, operation)
if err != nil {
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
@@ -972,11 +999,13 @@
totalAmount := decimal.NewFromInt(0) // 鎬婚噾棰�
totalPrice := decimal.NewFromInt(0) // 鎬讳环
rowIndex := 6
+ str := ""
for i, v := range operation.Details {
//璁剧疆琛ㄥ崟鏈�澶�6鏉℃暟鎹�
if i > 6 {
break
}
+ str += v.Remark
f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Name) // 浜у搧鍚嶇О
f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Specs) //瑙勬牸
f.SetCellValue(sheet, "D"+strconv.Itoa(rowIndex), attributeValueMap[fmt.Sprintf("%d%s", attributeMap["棰滆壊"], v.ProductId)]) //棰滆壊
@@ -1036,7 +1065,8 @@
}
// 澶囨敞 绗�13琛�
- f.SetCellValue(sheet, "B13", "澶囨敞锛�"+operation.Remark)
+ //f.SetCellValue(sheet, "B13", "澶囨敞锛�"+operation.Comment)
+ f.SetCellValue(sheet, "B13", "澶囨敞锛�"+str)
// 绗�14琛�
f.SetCellValue(sheet, "C14", operation.Manager) // 瀹℃牳
f.SetCellValue(sheet, "F14", operation.Accountant) // 淇濈
@@ -1084,11 +1114,13 @@
totalAmount := decimal.NewFromInt(0) // 鎬婚噾棰�
totalPrice := decimal.NewFromInt(0) // 鎬讳环
rowIndex := 5
+ str := ""
for i, v := range operation.Details {
//璁剧疆琛ㄥ崟鏈�澶�9鏉℃暟鎹�
if i > 9 {
break
}
+ str += v.Remark
f.SetCellValue(sheet, "A"+strconv.Itoa(rowIndex), v.Product.Name) // 鍝佸悕
f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Type) // 鍨嬪彿
f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Unit) // 鍗曚綅
@@ -1152,7 +1184,8 @@
}
}
- f.SetCellValue(sheet, "Q5", operation.Remark) // 澶囨敞
+ //f.SetCellValue(sheet, "Q5", operation.Comment) // 澶囨敞
+ f.SetCellValue(sheet, "Q5", str) // 澶囨敞
// 绗�14琛�
f.SetCellValue(sheet, "B15", operation.Manager) // 涓荤
--
Gitblit v1.8.0