From 98961b50ca71608110e0156e7dfb30c8e1c46a27 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期五, 10 十一月 2023 16:06:18 +0800
Subject: [PATCH] 注释修改

---
 controllers/operation.go |   75 +++++++++++++++++++++++++++++++++++--
 1 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 6ac7bae..a541b4d 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -1,20 +1,27 @@
 package controllers
 
 import (
+	"encoding/json"
 	"errors"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/shopspring/decimal"
+	"google.golang.org/grpc"
+	"google.golang.org/grpc/credentials/insecure"
 	"gorm.io/gorm"
+	"os"
 	"sort"
 	"strconv"
 	"time"
+	"wms/conf"
 	"wms/constvar"
 	"wms/extend/code"
 	"wms/extend/util"
 	"wms/models"
+	"wms/opa"
 	"wms/pkg/logx"
 	"wms/pkg/structx"
+	"wms/proto/product_inventory"
 	"wms/request"
 )
 
@@ -254,7 +261,7 @@
 	util.ResponseFormat(c, code.Success, "淇敼鎴愬姛")
 }
 
-// DeleteDevice
+// Delete
 //
 //	@Tags		鍏ュ簱/鍑哄簱
 //	@Summary	鍒犻櫎鍏ュ簱/鍑哄簱淇℃伅
@@ -296,7 +303,7 @@
 	util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
 }
 
-// DeleteDevice
+// Finish
 //
 //	@Tags		鍏ュ簱/鍑哄簱
 //	@Summary	鏇存敼璁板綍鐘舵��
@@ -489,8 +496,20 @@
 				if !ok {
 					return errors.New("浜у搧绉嶇被寮傚父")
 				}
-				if v.Amount.LessThan(value) {
-					return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
+				//todo 婕旂ず娴嬭瘯鏁版嵁
+				data, err := os.ReadFile("conf/input.json")
+				if err != nil {
+					return errors.New("鏂囦欢璇诲彇澶辫触")
+				}
+				m := make(map[string]interface{})
+				err = json.Unmarshal(data, &m)
+				if err != nil {
+					return errors.New("鏍煎紡杞崲澶辫触")
+				}
+				if opa.OpaCheck(c, m, "operation") {
+					if v.Amount.LessThan(value) {
+						return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
+					}
 				}
 				listProdt[k].Amount = listProdt[k].Amount.Sub(value)
 				if err := tx.Save(listProdt[k]).Error; err != nil {
@@ -664,10 +683,41 @@
 		util.ResponseFormat(c, code.RequestError, err.Error())
 		return
 	}
+	if operation.SourceNumber != "" {
+		go UpdateSalesDetailStatus(c, operation.SourceNumber)
+	}
 	util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛")
 }
 
-// listTransfer
+var ProductInventoryServiceConn *grpc.ClientConn
+
+func InitProductInventoryServiceConn() {
+	var err error
+	ProductInventoryServiceConn, err = grpc.Dial(conf.GrpcServerConf.CrmAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
+	if err != nil {
+		logx.Errorf("grpc dial product service error: %v", err.Error())
+		return
+	}
+}
+
+func CloseProductInventoryServiceConn() {
+	if ProductInventoryServiceConn != nil {
+		ProductInventoryServiceConn.Close()
+	}
+}
+
+func UpdateSalesDetailStatus(ctx *gin.Context, number string) {
+	client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
+	_, err := client.UpdateSalesDetailStatus(ctx, &product_inventory.UpdateSalesDetailStatusRequest{
+		Number:            number,
+		SalesDetailStatus: "宸插嚭搴�",
+	})
+	if err != nil {
+		logx.Errorf("grpc dial UpdateSalesDetailStatus service error: %v", err)
+	}
+}
+
+// ListTransfer
 // @Tags      鍏ュ簱/鍑哄簱
 // @Summary   搴撳瓨璋冩嫧鍒楄〃
 // @Produce   application/json
@@ -697,3 +747,18 @@
 	}
 	util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize)
 }
+
+// GetLogisticCompanyList
+// @Tags      鍏ュ簱/鍑哄簱
+// @Summary   鑾峰彇鐗╂祦鍏徃鍒楄〃
+// @Produce   application/json
+// @Success   200 {object} util.ResponseList{data=[]models.LogisticCompany} "鎴愬姛"
+// @Router    /api-wms/v1/operation/getLogisticCompanyList [get]
+func (slf OperationController) GetLogisticCompanyList(c *gin.Context) {
+	companies, err := models.NewLogisticCompanySearch().FindNotTotal()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触:"+err.Error())
+		return
+	}
+	util.ResponseFormat(c, code.Success, companies)
+}

--
Gitblit v1.8.0