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 | 553 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 468 insertions(+), 85 deletions(-)
diff --git a/controllers/operation.go b/controllers/operation.go
index 0d409a3..ae06b4b 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -3,12 +3,12 @@
import (
"context"
"errors"
+ "fmt"
"github.com/gin-gonic/gin"
uuid "github.com/satori/go.uuid"
"github.com/shopspring/decimal"
"github.com/xuri/excelize/v2"
"gorm.io/gorm"
- "sort"
"strconv"
"strings"
"time"
@@ -41,12 +41,14 @@
// @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]
func (slf OperationController) Add(c *gin.Context) {
var reqParams request.AddOperation
var params models.Operation
+
if err := c.BindJSON(&reqParams); err != nil {
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
return
@@ -60,26 +62,54 @@
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
}
- operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First()
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, err.Error())
+ 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
+ }
+
+ if params.DealerType == "" {
+ CheckInventoryDealerType(¶ms)
+ }
+
+ userInfo := middleware.GetUserInfo(c)
+ if userInfo == nil {
+ util.ResponseFormat(c, code.SetStatusError, "鐧诲綍鐢ㄦ埛淇℃伅涓虹┖锛岃鐧诲綍鍚庨噸璇曪紒")
return
}
- 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
+
+ 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 {
@@ -90,8 +120,26 @@
util.ResponseFormat(c, code.RequestParamError, "鍗曞彿宸插瓨鍦�")
return
}
+ err := models.WithTransaction(func(db *gorm.DB) error {
+ if err := models.NewOperationSearch().Create(¶ms); err != nil {
+ return err
+ }
+ /*od := params.Details
+ for _, v := range od {
+ //material, err := models.NewMaterialSearch().SetID(v.ProductId).First()
+ //if err != nil {return err}
+ material := new(models.Material)
+ material.ID = v.ProductId
+ material.Cost = v.Cost
+ material.SalePrice = v.SalePrice
+ if err := models.NewMaterialSearch().SetOrm(db).Update(material); err != nil {
+ return err
+ }
+ }*/
+ return nil
+ })
- if err := models.NewOperationSearch().Create(¶ms); err != nil {
+ if err != nil {
logx.Errorf("Operation create err: %v", err)
util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error())
return
@@ -99,23 +147,58 @@
util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
}
-func CheckDetailsRepeat(details []*models.OperationDetails) bool {
- var detailIDs []string
- var tempID string
- for _, v := range details {
- detailIDs = append(detailIDs, v.ProductId)
+// CheckInventoryDealerType 妫�鏌ュ熀纭�绫诲瀷锛岄槻姝㈢被鍨嬩负绌烘坊鍔犲叾瀹冪被鍨�
+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
}
- sort.Strings(detailIDs)
- for _, v := range detailIDs {
- if v != tempID {
- tempID = v
- } else {
- return true
+ 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
+}
+
+// CheckDetailsRepeat 鍑哄簱銆佸叆搴撱�佺洏鐐规秹鍙婁骇鍝侀噸澶嶆�ф鏌ワ紙浠ヤ骇鍝佺紪鍙枫�佸嚭搴撳簱鎴跨紪鍙枫�佸叆搴撳簱鎴跨紪鍙凤級
+// 瀛樺湪閲嶅鍊� true锛� 涓嶅瓨鍦ㄨ繑鍥� false
+func CheckDetailsRepeat(details []*models.OperationDetails) bool {
+ if len(details) == 0 {
+ return false
+ }
+ 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
}
+// FormatLocation 浣嶇疆妫�鏌�
func (slf OperationController) FormatLocation(params *models.Operation) error {
operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First()
if err != nil {
@@ -161,25 +244,27 @@
}
func (slf OperationController) CheckParams(params models.Operation) error {
- if params.SourceNumber == "" {
+ /*if params.SourceNumber == "" {
return errors.New("璇峰~鍏ユ簮鍗曞彿")
- }
+ }*/
if params.Number == "" {
return errors.New("璇峰~鍏ュ崟鍙�")
}
if params.OperationTypeId == 0 && int(params.BaseOperationType) == 0 {
- return errors.New("鏈瘑鍒璁板綍绫诲瀷")
+ return errors.New("鏈瘑鍒璁板綍绫诲瀷1")
+ } else if params.OperationTypeId == 0 && params.BaseOperationType != 0 && params.WarehouseId == 0 {
+ return errors.New("鏈瘑鍒璁板綍绫诲瀷2")
}
if params.OperationDate == "" {
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("璇锋坊鍔犳槑缁嗕俊鎭�")
@@ -203,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")
@@ -222,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)
}
@@ -229,8 +333,9 @@
// @Tags 鍏ュ簱/鍑哄簱
// @Summary 鍏ュ簱/鍑哄簱鍒楄〃
// @Produce application/json
+// @Param Authorization header string true "token"
// @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
@@ -250,10 +355,50 @@
if int(params.Status) != 0 {
search.SetStatus(params.Status)
}
- list, total, err := search.SetOperationTypeId(params.OperationTypeId).SetPreload(true).SetOrder("created_at desc").Find()
+ materials, err := models.NewMaterialSearch().FindNotTotal()
if err != nil {
util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触:"+err.Error())
return
+ }
+ costMap := make(map[string]decimal.Decimal)
+ salePriceMap := make(map[string]decimal.Decimal)
+ for _, material := range materials {
+ costMap[material.ID] = material.Cost
+ salePriceMap[material.ID] = material.SalePrice
+ }
+ list, total, err := search.SetOperationTypeId(params.OperationTypeId).
+ SetBaseOperationType(params.BaseOperationType).
+ SetPreload(true).SetOrder("created_at desc").Find()
+ if err != nil {
+ 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)
+ 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.CheckedBy = userInfo.NickName
+ }
+ for _, v1 := range v.Details {
+ //v1.SalePrice = decimal.NewFromFloat(1.2345)
+ //v1.Cost = decimal.NewFromFloat(9.678)
+ v1.SalePrice = v1.Cost
+ v1.Cost = v1.SalePrice
+ }
}
util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize)
@@ -263,8 +408,8 @@
if !params.PageInfo.Check() {
return errors.New("鏁版嵁鍒嗛〉淇℃伅閿欒")
}
- if params.OperationTypeId == 0 {
- return errors.New("operationTypeId涓�0")
+ if params.OperationTypeId == 0 && params.BaseOperationType == 0 {
+ return errors.New("operationTypeId鍜宐aseOperationType涓嶈兘鍚屾椂涓�0")
}
return nil
}
@@ -299,9 +444,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 {
@@ -314,6 +462,18 @@
if err := models.NewOperationSearch().SetOrm(tx).SetID(params.Id).Save(¶ms); err != nil {
return err
}
+ /*od := params.Details
+ for _, v := range od {
+ //material, err := models.NewMaterialSearch().SetID(v.ProductId).First()
+ //if err != nil {return err}
+ material := new(models.Material)
+ material.ID = v.ProductId
+ material.Cost = v.Cost
+ material.SalePrice = v.SalePrice
+ if err := models.NewMaterialSearch().SetOrm(tx).Update(material); err != nil {
+ return err
+ }
+ }*/
return nil
}); err != nil {
util.ResponseFormat(c, code.RequestParamError, "淇敼澶辫触锛�"+err.Error())
@@ -328,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]
@@ -375,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 {
@@ -428,26 +590,27 @@
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 err := service.FinishOperationOutput(tx, listDetails, mapLocAmount); err != nil {
+ 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 err := service.FinishOperationInternal(tx, listDetails, mapLocAmount); err != nil {
+ if operation.BaseOperationType == constvar.BaseOperationTypeInternal { // 鍐呴儴璋冩嫧
+ if err := service.FinishOperationInternal(tx, listDetails, operation); err != nil {
return err
}
}
- if operation.BaseOperationType == constvar.BaseOperationTypeAdjust {
- if err := service.FinishOperationAdjust(tx, listDetails, mapLocAmount); err != nil {
+ if operation.BaseOperationType == constvar.BaseOperationTypeAdjust { // 搴撳瓨鐩樼偣
+ if err := service.FinishOperationAdjust(tx, listDetails, mapLocAmount, operation); err != nil {
return err
}
}
@@ -469,7 +632,6 @@
go UpdateOutStatus(operation.Source, operation.SourceNumber, 4)
}
}
-
util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛")
}
@@ -646,7 +808,7 @@
util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛")
}
-// outputOperation
+// OutputOperation
//
// @Tags 鍏ュ簱/鍑哄簱
// @Summary 鎵撳嵃
@@ -664,6 +826,7 @@
util.ResponseFormat(c, code.RequestParamError, "id涓�0")
return
}
+ // 鑾峰彇鎿嶄綔娑堟伅
operation, err := models.NewOperationSearch().SetPreload(true).SetID(id).First()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "鏈壘鍒扮浉鍏冲嚭鍏ュ簱淇℃伅:"+err.Error())
@@ -675,17 +838,43 @@
}
var fileUrl string
+ // 鑾峰彇鍏徃鍚嶇О
companyName := conf.WebConf.CompanyName
if companyName == "" {
util.ResponseFormat(c, code.RequestParamError, "缂哄皯宸ュ巶鍚嶇О閰嶇疆")
return
}
+ // BaseOperationTypeIncoming 鏀惰揣
if operation.BaseOperationType == constvar.BaseOperationTypeIncoming {
if companyName == "jialian" {
- fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianInput, operation)
+ // 鍏ュ簱
+ oT, err := models.NewOperationTypeSearch().SetID(uint(operation.OperationTypeId)).First()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
+ }
+ warehouse, err := models.NewWarehouseSearch().SetID(oT.WarehouseId).First()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
+ if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 {
+ fileUrl, err = JialianOperation1(constvar.FileWarehouseCategory_JialianInput2, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ } else {
+ fileUrl, err = JialianOperation2(constvar.FileTemplateCategory_JialianInput1, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
}
} else if companyName == "geruimi" {
fileUrl, err = ExportInputSelfmade(constvar.FileTemplateCategory_Selfmade, operation)
@@ -694,12 +883,37 @@
return
}
}
- } else if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing {
+ } else if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing { // 浜よ揣
if companyName == "jialian" {
- fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianOutput, operation)
+ oT, err := models.NewOperationTypeSearch().SetID(uint(operation.OperationTypeId)).First()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
+ }
+ warehouse, err := models.NewWarehouseSearch().SetID(oT.WarehouseId).First()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
+ if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 {
+ fileUrl, err = JialianOperation1(constvar.FileWarehouseCategory_JialianOutput2, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
+ } else {
+ fileUrl, err = JialianOperation2(constvar.FileTemplateCategory_JialianOutput1, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
}
} else if companyName == "geruimi" {
fileUrl, err = ExportInputSelfmade(constvar.FileTemplateCategory_Output, operation)
@@ -719,39 +933,88 @@
util.ResponseFormat(c, code.Success, m)
}
-func JialianOperation(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
+func JialianOperation1(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
+ // 鑾峰彇妯℃澘璁板綍
template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First()
if err != nil {
return "", errors.New("鑾峰彇妯$増璁板綍澶辫触:" + err.Error())
}
+ fmt.Println(template)
+ // 鏍规嵁妯℃澘璺緞鑾峰彇妯℃澘娑堟伅
readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl)
if err != nil {
return "", errors.New("鑾峰彇妯$増澶辫触:" + err.Error())
}
+ // 璇诲彇妯℃澘鍐呭
f, err := excelize.OpenReader(readerCloser)
if err != nil {
return "", errors.New("璇诲彇excel妯$増澶辫触锛�" + err.Error())
}
readerCloser.Close()
+
defer f.Close()
- f.SetCellValue("Sheet1", "H2", operation.OperationDate)
- f.SetCellValue("Sheet1", "O2", operation.Number)
+ sheet := "Sheet1"
+ if category == constvar.FileWarehouseCategory_JialianInput2 {
+ sheet = "鍏ュ簱鍗�"
+ } else if category == constvar.FileWarehouseCategory_JialianOutput2 {
+ sheet = "鍑哄簱鍗�"
+ }
- rowIndex := 5
- totalAmount := decimal.NewFromInt(0)
- totalPrice := decimal.NewFromInt(0)
+ // 绗簩琛�
+ f.SetCellValue(sheet, "K2", operation.Number) // 鍗曞彿
+ // 绗笁琛�
+ f.SetCellValue(sheet, "D3", operation.CompanyName) // 鍏徃
+ f.SetCellValue(sheet, "G3", "") // 閮ㄩ棬
+
+ // 鏃堕棿
+ date := operation.OperationDate
+ f.SetCellValue(sheet, "I3", date[0:4]) // 骞�
+ f.SetCellValue(sheet, "L3", date[5:7]) // 鏈�
+ f.SetCellValue(sheet, "N3", date[8:10]) // 鏃�
+
+ var entityIDs []string
+ for _, v := range operation.Details {
+ entityIDs = append(entityIDs, v.ProductId)
+ }
+ attributeMap := make(map[string]uint)
+ attributeValueMap := make(map[string]string)
+ attributes, err := models.NewAttributeSearch().SetEntityType(1).FindNotTotal()
+ if err != nil {
+ return "", errors.New("鑾峰彇鍔ㄦ�佸睘鎬уけ璐ワ細" + err.Error())
+ }
+ for _, v := range attributes {
+ attributeMap[v.Name] = v.ID
+ }
+ attributeValues, err := models.NewAttributeValueSearch().SetEntityIDs(entityIDs).FindNotTotal()
+ if err != nil {
+ return "", errors.New("鑾峰彇鍔ㄦ�佸睘鎬у�煎け璐ワ細" + err.Error())
+ }
+ for _, v := range attributeValues {
+ attributeValueMap[fmt.Sprintf("%d%s", v.AttributeID, v.EntityID)] = v.Value
+ }
+
+ // 绗叚琛� 寰幆濉��
+ totalAmount := decimal.NewFromInt(0) // 鎬婚噾棰�
+ totalPrice := decimal.NewFromInt(0) // 鎬讳环
+ rowIndex := 6
+ str := ""
for i, v := range operation.Details {
- //璁剧疆琛ㄥ崟鏈�澶�9鏉℃暟鎹�
- if i > 8 {
+ //璁剧疆琛ㄥ崟鏈�澶�6鏉℃暟鎹�
+ if i > 6 {
break
}
- f.SetCellValue("Sheet1", "A"+strconv.Itoa(rowIndex), v.Product.Name)
- f.SetCellValue("Sheet1", "B"+strconv.Itoa(rowIndex), v.Product.Type)
- f.SetCellValue("Sheet1", "C"+strconv.Itoa(rowIndex), v.Product.Unit)
- f.SetCellValue("Sheet1", "D"+strconv.Itoa(rowIndex), v.Amount.String())
- f.SetCellValue("Sheet1", "E"+strconv.Itoa(rowIndex), v.Product.SalePrice.String())
+ 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)]) //棰滆壊
+ f.SetCellValue(sheet, "E"+strconv.Itoa(rowIndex), attributeValueMap[fmt.Sprintf("%d%s", attributeMap["闈㈡枡"], v.ProductId)]) //闈㈡枡
+ f.SetCellValue(sheet, "F"+strconv.Itoa(rowIndex), v.TotalGrossWeight.String()) //閲嶉噺
+ f.SetCellValue(sheet, "G"+strconv.Itoa(rowIndex), v.Amount.String()) //鏁伴噺
+ f.SetCellValue(sheet, "H"+strconv.Itoa(rowIndex), v.Product.SalePrice.String()) // 鍗曚环
+
+ // 閲戦
if !v.Product.SalePrice.IsZero() {
ap := v.Amount.Mul(v.Product.SalePrice)
totalPrice = totalPrice.Add(ap)
@@ -759,53 +1022,55 @@
split := strings.Split(price, ".")
if len(split) == 2 {
for n, a := range split[1] {
- f.SetCellValue("Sheet1", string('M'+n)+strconv.Itoa(rowIndex), string(a))
+ f.SetCellValue(sheet, string('N'+n)+strconv.Itoa(rowIndex), string(a))
}
}
s := split[0]
n := 0
for j := len(s) - 1; j >= 0; j-- {
if n == 6 {
- f.SetCellValue("Sheet1", string('L'-n)+strconv.Itoa(rowIndex), s[:j])
+ f.SetCellValue(sheet, string('M'-n)+strconv.Itoa(rowIndex), s[:j])
break
}
- f.SetCellValue("Sheet1", string('L'-n)+strconv.Itoa(rowIndex), string(s[j]))
+ f.SetCellValue(sheet, string('M'-n)+strconv.Itoa(rowIndex), string(s[j]))
n++
}
}
-
rowIndex++
totalAmount = totalAmount.Add(v.Amount)
}
+
//鍚堣
if !totalPrice.IsZero() {
price := totalPrice.String()
split := strings.Split(price, ".")
if len(split) == 2 {
for n, a := range split[1] {
- f.SetCellValue("Sheet1", string('M'+n)+"14", string(a))
+ f.SetCellValue(sheet, string('M'+n)+"12", string(a))
}
} else {
- f.SetCellValue("Sheet1", "M14", "0")
- f.SetCellValue("Sheet1", "N14", "0")
+ f.SetCellValue(sheet, "N12", "0")
+ f.SetCellValue(sheet, "O12", "0")
}
s := split[0]
n := 0
for j := len(s) - 1; j >= 0; j-- {
if n == 6 {
- f.SetCellValue("Sheet1", string('L'-n)+"14", s[:j])
+ f.SetCellValue(sheet, string('M'-n)+"12", s[:j])
break
}
- f.SetCellValue("Sheet1", string('L'-n)+"14", string(s[j]))
+ f.SetCellValue(sheet, string('M'-n)+"12", string(s[j]))
n++
}
}
- f.SetCellValue("Sheet1", "D14", totalAmount)
- f.SetCellValue("Sheet1", "B15", operation.Manager)
- f.SetCellValue("Sheet1", "D15", operation.Accountant)
- f.SetCellValue("Sheet1", "F15", operation.Custodian)
-
+ // 澶囨敞 绗�13琛�
+ //f.SetCellValue(sheet, "B13", "澶囨敞锛�"+operation.Comment)
+ f.SetCellValue(sheet, "B13", "澶囨敞锛�"+str)
+ // 绗�14琛�
+ f.SetCellValue(sheet, "C14", operation.Manager) // 瀹℃牳
+ f.SetCellValue(sheet, "F14", operation.Accountant) // 淇濈
+ f.SetCellValue(sheet, "I14", operation.Custodian) //缁忓姙浜�
buf, err := f.WriteToBuffer()
if err != nil {
return "", err
@@ -816,7 +1081,127 @@
logx.Errorf("file upload err: %v", err)
return "", err
}
+ return fileUrl, nil
+}
+func JialianOperation2(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
+ // 鑾峰彇妯℃澘璁板綍
+ template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First()
+ if err != nil {
+ return "", errors.New("鑾峰彇妯$増璁板綍澶辫触:" + err.Error())
+ }
+ fmt.Println(template)
+ // 鏍规嵁妯℃澘璺緞鑾峰彇妯℃澘娑堟伅
+ readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl)
+ if err != nil {
+ return "", errors.New("鑾峰彇妯$増澶辫触:" + err.Error())
+ }
+
+ // 璇诲彇妯℃澘鍐呭
+ f, err := excelize.OpenReader(readerCloser)
+ if err != nil {
+ return "", errors.New("璇诲彇excel妯$増澶辫触锛�" + err.Error())
+ }
+ readerCloser.Close()
+
+ defer f.Close()
+
+ sheet := "Sheet1"
+ f.SetCellValue(sheet, "A2", "鍗曚綅(閮ㄩ棬):"+operation.CompanyName) // 鍗曚綅閮ㄩ棬
+ f.SetCellValue(sheet, "J2", operation.OperationDate) // 鏃堕棿
+ f.SetCellValue(sheet, "Q2", operation.Number) // 缂栧彿
+
+ 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) // 鍗曚綅
+ f.SetCellValue(sheet, "D"+strconv.Itoa(rowIndex), v.Amount.String()) // 鏁伴噺
+ unit := service.CreateMoreUnit(v.Amount, v.Product.MoreUnitList)
+ for _, v1 := range unit {
+ if !v1.Amount.IsZero() {
+ f.SetCellValue(sheet, "E"+strconv.Itoa(rowIndex), v1.Amount) // 杈呮暟閲�
+ f.SetCellValue(sheet, "F"+strconv.Itoa(rowIndex), v1.Unit) // 杈呭崟浣�
+ break
+ }
+ }
+ f.SetCellValue(sheet, "G"+strconv.Itoa(rowIndex), v.Product.SalePrice.String()) // 鍗曚环
+ // 閲戦
+ if !v.Product.SalePrice.IsZero() {
+ ap := v.Amount.Mul(v.Product.SalePrice)
+ totalPrice = totalPrice.Add(ap)
+ price := ap.String()
+ split := strings.Split(price, ".")
+ if len(split) == 2 {
+ for n, a := range split[1] {
+ f.SetCellValue(sheet, string('O'+n)+strconv.Itoa(rowIndex), string(a))
+ }
+ }
+ s := split[0]
+ n := 0
+ for j := len(s) - 1; j >= 0; j-- {
+ if n == 6 {
+ f.SetCellValue(sheet, string('N'-n)+strconv.Itoa(rowIndex), s[:j])
+ break
+ }
+ f.SetCellValue(sheet, string('N'-n)+strconv.Itoa(rowIndex), string(s[j]))
+ n++
+ }
+ }
+ rowIndex++
+ totalAmount = totalAmount.Add(v.Amount)
+ }
+
+ //鍚堣
+ if !totalPrice.IsZero() {
+ price := totalPrice.String()
+ split := strings.Split(price, ".")
+ if len(split) == 2 {
+ for n, a := range split[1] {
+ f.SetCellValue(sheet, string('N'+n)+"14", string(a))
+ }
+ } else {
+ f.SetCellValue(sheet, "O14", "0")
+ f.SetCellValue(sheet, "P14", "0")
+ }
+ s := split[0]
+ n := 0
+ for j := len(s) - 1; j >= 0; j-- {
+ if n == 6 {
+ f.SetCellValue(sheet, string('N'-n)+"14", s[:j])
+ break
+ }
+ f.SetCellValue(sheet, string('N'-n)+"14", string(s[j]))
+ n++
+ }
+ }
+
+ //f.SetCellValue(sheet, "Q5", operation.Comment) // 澶囨敞
+ f.SetCellValue(sheet, "Q5", str) // 澶囨敞
+
+ // 绗�14琛�
+ f.SetCellValue(sheet, "B15", operation.Manager) // 涓荤
+ f.SetCellValue(sheet, "D15", operation.Accountant) // 浼氳
+ f.SetCellValue(sheet, "H15", operation.Custodian) //淇濈鍛�
+ f.SetCellValue(sheet, "Q15", operation.Custodian) //缁忔墜
+ buf, err := f.WriteToBuffer()
+ if err != nil {
+ return "", err
+ }
+
+ fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes())
+ if err != nil {
+ logx.Errorf("file upload err: %v", err)
+ return "", err
+ }
return fileUrl, nil
}
@@ -896,7 +1281,6 @@
logx.Errorf("file upload err: %v", err)
return "", err
}
-
return fileUrl, nil
}
@@ -1071,8 +1455,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