| | |
| | | package purchase |
| | | |
| | | import ( |
| | | "fmt" |
| | | "context" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/mitchellh/mapstructure" |
| | | "github.com/shopspring/decimal" |
| | | "go.uber.org/zap" |
| | | "gorm.io/gorm" |
| | | "srm/global" |
| | | "srm/model/common/request" |
| | | "srm/model/common/response" |
| | | "srm/model/purchase" |
| | | purchaserequest "srm/model/purchase/request" |
| | | "srm/proto/purchase_wms" |
| | | "strconv" |
| | | "strings" |
| | | "time" |
| | | |
| | | //"srm/model/purchase" |
| | | |
| | | //"srm/model/purchase" |
| | |
| | | } |
| | | |
| | | var purchaseRecord purchase.Purchase |
| | | if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil { |
| | | if err := utils.AssignTo(params.Purchase, &purchaseRecord); err != nil { |
| | | global.GVA_LOG.Error("Add Purchase failed", zap.Error(err)) |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | |
| | | purchaseRecord.Status = purchase.OrderStatusConfirmed |
| | | purchaseRecord.HandledBy = "admin" |
| | | purchaseRecord.Creator = "admin" |
| | | purchaseRecord.Number = fmt.Sprintf("CG%v", time.Now().Unix()) |
| | | purchaseRecord.OrderType = "采购订单" |
| | | |
| | | if !purchaseRecord.WholeDiscountType.IsValid(purchaseRecord.TotalPrice, purchaseRecord.WholeDiscount) { |
| | | response.FailWithMessage("整单折扣数值不正确", c) |
| | |
| | | return |
| | | } |
| | | global.GVA_LOG.Error("创建失败!", zap.Error(err)) |
| | | response.FailWithMessage("创建失败", c) |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | response.OkWithMessage("创建成功", c) |
| | |
| | | } |
| | | |
| | | var purchaseRecord purchase.Purchase |
| | | if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil { |
| | | if err := utils.AssignTo(params.Purchase, &purchaseRecord); err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | |
| | | return |
| | | } |
| | | respProductList := make([]*purchaseRes.PurchaseProducts, len(productList)) |
| | | err = mapstructure.Decode(productList, &respProductList) |
| | | err = utils.AssignTo(productList, &respProductList) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | |
| | | respProductList[k].Amount = item.Amount |
| | | respProductList[k].Price = item.Price |
| | | respProductList[k].Total = item.Total |
| | | err = mapstructure.Decode(item.Product, &respProductList[k]) |
| | | err = utils.AssignTo(item.Product, &respProductList[k]) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data query request.PageInfo true "页码, 每页大小" |
| | | // @Param data query purchaserequest.PurchaseSearch true "参数" |
| | | // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取采购单列表,返回包括列表,总数,页码,每页数量" |
| | | // @Router /purchase/purchaseList [get] |
| | | func (e *PurchaseApi) GetPurchaseList(c *gin.Context) { |
| | | var pageInfo request.PageInfo |
| | | var pageInfo purchaserequest.PurchaseSearch |
| | | err := c.ShouldBindQuery(&pageInfo) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param id path int true "采购单ID" |
| | | // @Param data body purchaserequest.SubmitPurchase true "参数" |
| | | // @Success 200 {object} response.Response{msg=string} "提交采购单" |
| | | // @Router /purchase/submit/{id} [post] |
| | | // @Router /purchase/submit [post] |
| | | func (e *PurchaseApi) Submit(c *gin.Context) { |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | if id == 0 { |
| | | response.FailWithMessage("参数缺失", c) |
| | | var params purchaserequest.SubmitPurchase |
| | | err := c.ShouldBindJSON(¶ms) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("Submit failed", zap.Error(err)) |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | err := service.NewPurchaseService().Submit(uint(id)) |
| | | warehouse := "" |
| | | data, err := service.NewPurchaseService().GetPurchase(uint(params.Id)) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | if params.Status == purchase.OrderStatusReceived { |
| | | productList, err := service.NewPurchaseService().GetPurchaseProductList(uint(params.Id)) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | product := make([]*purchase_wms.PurchaseProduct, 0) |
| | | for _, products := range productList { |
| | | var p purchase_wms.PurchaseProduct |
| | | p.Id = products.Product.Number |
| | | p.Amount = products.Amount.IntPart() |
| | | product = append(product, &p) |
| | | } |
| | | client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | resp, err := client.PurchaseToWms(context.Background(), &purchase_wms.PurchaseToWmsRequest{ |
| | | Number: data.Number, |
| | | SupplierName: data.Supplier.Name, |
| | | Product: product, |
| | | Source: "SRM_PURCHASE", |
| | | OperationSource: purchase_wms.OperationSource_OperationSourcePurchase, |
| | | SalesDetailsNumber: data.SourceOrder, |
| | | }) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("grpc调用失败!", zap.Error(err)) |
| | | response.FailWithMessage("grpc调用失败", c) |
| | | return |
| | | } |
| | | warehouse = resp.Warehouse |
| | | } |
| | | |
| | | err = service.NewPurchaseService().Submit(params.Id, params.Status, warehouse) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("更新失败!", zap.Error(err)) |
| | | response.FailWithMessage("更新失败", c) |
| | |
| | | } |
| | | |
| | | purchaseTypeList := make([]*purchase.PurchaseType, 0, len(params)) |
| | | if err := mapstructure.Decode(params, &purchaseTypeList); err != nil { |
| | | if err := utils.AssignTo(params, &purchaseTypeList); err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | |
| | | } |
| | | response.OkWithDetailed(list, "获取成功", c) |
| | | } |
| | | |
| | | // GetWarehouseInfo |
| | | // @Tags Purchase |
| | | // @Summary 获取仓库列表 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Success 200 {object} response.Response{data=[]purchase_wms.SrmGetWarehouseInfoResponse} "获取采购类型列表" |
| | | // @Router /purchase/getWarehouseInfo [get] |
| | | func (e *PurchaseApi) GetWarehouseInfo(c *gin.Context) { |
| | | client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | info, err := client.SrmGetWarehouseInfo(context.Background(), &purchase_wms.SrmGetWarehouseInfoRequest{}) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("grpc调用失败!", zap.Error(err)) |
| | | response.FailWithMessage("grpc调用失败", c) |
| | | return |
| | | } |
| | | response.OkWithData(info, c) |
| | | } |
| | | |
| | | // GetOperationInfo |
| | | // @Tags Purchase |
| | | // @Summary 获取操作信息 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Success 200 {object} response.Response{data=[]purchaseRes.OperationInfo} "获取操作信息" |
| | | // @Router /purchase/getOperationInfo/{id} [get] |
| | | func (e *PurchaseApi) GetOperationInfo(c *gin.Context) { |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | if id == 0 { |
| | | response.FailWithMessage("参数缺失", c) |
| | | return |
| | | } |
| | | server := service.NewPurchaseService() |
| | | data, err := server.GetPurchase(uint(id)) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | productList, err := server.GetPurchaseProductList(uint(id)) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | confirmInfo, err := server.GetPurchaseProductConfirmInfo(data.Number) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | info, err := client.SrmGetOperationInfo(context.Background(), &purchase_wms.SrmGetOperationInfoRequest{Number: data.Number}) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("grpc调用失败!", zap.Error(err)) |
| | | response.FailWithMessage("grpc调用失败", c) |
| | | return |
| | | } |
| | | |
| | | var operationInfos purchaseRes.OperationInfo |
| | | productInfos := make([]purchaseRes.ProductInfo, 0) |
| | | inWarehouseInfos := make([]purchaseRes.InWarehouseInfo, 0) |
| | | productMap := make(map[string]*purchaseRes.ProductInfo) |
| | | if len(info.Operations) > 0 { |
| | | for _, operation := range info.Operations { |
| | | var pi purchaseRes.ProductInfo |
| | | var iwi purchaseRes.InWarehouseInfo |
| | | if p, ok := productMap[operation.ProductId]; ok { |
| | | pi = *p |
| | | } |
| | | pi.Number = operation.ProductId |
| | | pi.Name = operation.ProductName |
| | | iwi.Number = operation.ProductId |
| | | iwi.Name = operation.ProductName |
| | | iwi.OperationNumber = operation.Number |
| | | iwi.Status = operation.Status |
| | | iwi.Principal = data.Principal |
| | | iwi.WarehouseName = data.Warehouse |
| | | if operation.OverTime != "" && operation.Status == 4 { |
| | | iwi.OverTime = operation.OverTime |
| | | iwi.OverAmount = operation.Amount |
| | | pi.OverAmount = pi.OverAmount + operation.Amount |
| | | } |
| | | for _, products := range productList { |
| | | if products.Product.Number == operation.ProductId { |
| | | pi.Amount = products.Amount |
| | | pi.PurchasePrice = products.Price |
| | | pi.Total = products.Total |
| | | pi.Unit = products.Product.Unit |
| | | pi.Specifications = products.Product.Specifications |
| | | pi.ModelNumber = products.Product.ModelNumber |
| | | break |
| | | } |
| | | } |
| | | for _, confirm := range confirmInfo { |
| | | if operation.ProductId == confirm.ProductId { |
| | | pi.SendAmount = confirm.OverReceiveAmount.IntPart() |
| | | break |
| | | } |
| | | } |
| | | inWarehouseInfos = append(inWarehouseInfos, iwi) |
| | | productMap[operation.ProductId] = &pi |
| | | } |
| | | } else { |
| | | for _, products := range productList { |
| | | var pi purchaseRes.ProductInfo |
| | | pi.Number = products.Product.Number |
| | | pi.Name = products.Product.Name |
| | | pi.Amount = products.Amount |
| | | pi.PurchasePrice = products.Price |
| | | pi.Total = products.Total |
| | | pi.Unit = products.Product.Unit |
| | | pi.Specifications = products.Product.Specifications |
| | | pi.ModelNumber = products.Product.ModelNumber |
| | | for _, confirm := range confirmInfo { |
| | | if products.Product.Number == confirm.ProductId { |
| | | pi.SendAmount = confirm.OverReceiveAmount.IntPart() |
| | | break |
| | | } |
| | | } |
| | | productMap[pi.Number] = &pi |
| | | } |
| | | } |
| | | for _, productInfo := range productMap { |
| | | productInfos = append(productInfos, *productInfo) |
| | | } |
| | | operationInfos.InWarehouseInfos = inWarehouseInfos |
| | | operationInfos.ProductInfos = productInfos |
| | | |
| | | response.OkWithData(operationInfos, c) |
| | | } |
| | | |
| | | // NewSubmit |
| | | // @Tags Purchase |
| | | // @Summary 新版提交 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body purchaserequest.SubmitPurchase true "参数" |
| | | // @Success 200 {object} response.Response{msg=string} "新版提交" |
| | | // @Router /purchase/newSubmit [post] |
| | | func (e *PurchaseApi) NewSubmit(c *gin.Context) { |
| | | var params purchaserequest.SubmitPurchase |
| | | err := c.ShouldBindJSON(¶ms) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("Submit failed", zap.Error(err)) |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | id := uint(params.Id) |
| | | if id == 0 { |
| | | response.FailWithMessage("参数缺失", c) |
| | | return |
| | | } |
| | | if params.Status == purchase.OrderStatusCanceled { |
| | | err = service.NewPurchaseService().Submit(params.Id, params.Status, "") |
| | | if err != nil { |
| | | global.GVA_LOG.Error("提交失败!", zap.Error(err)) |
| | | response.FailWithMessage("提交失败", c) |
| | | return |
| | | } |
| | | response.OkWithMessage("提交成功", c) |
| | | return |
| | | } |
| | | data, err := service.NewPurchaseService().GetPurchase(id) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | productList, err := service.NewPurchaseService().GetPurchaseProductList(id) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | list := make([]*purchase.PurchaseProductConfirm, 0) |
| | | for _, products := range productList { |
| | | var ppc purchase.PurchaseProductConfirm |
| | | ppc.PurchaseNumber = data.Number |
| | | ppc.Principal = data.Principal |
| | | ppc.ProductId = products.Product.Number |
| | | ppc.ProductName = products.Product.Name |
| | | ppc.Unit = products.Product.Unit |
| | | ppc.Specs = products.Product.Specifications |
| | | ppc.Type = products.Product.ModelNumber |
| | | ppc.Amount = products.Amount |
| | | ppc.OverReceiveAmount = decimal.NewFromInt(0) |
| | | ppc.NotReceiveAmount = products.Amount |
| | | ppc.NowReceiveAmount = decimal.NewFromInt(0) |
| | | ppc.SurplusReceiveAmount = products.Amount |
| | | list = append(list, &ppc) |
| | | } |
| | | err = service.NewPurchaseService().SavePurchaseProductConfirm(list, true) |
| | | |
| | | if err != nil { |
| | | global.GVA_LOG.Error("提交失败!", zap.Error(err)) |
| | | response.FailWithMessage("提交失败", c) |
| | | return |
| | | } |
| | | response.OkWithMessage("提交成功", c) |
| | | } |
| | | |
| | | // GetPurchaseProductConfirmInfo |
| | | // @Tags Purchase |
| | | // @Summary 获取确认信息 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param number path string true "采购单编码" |
| | | // @Success 200 {object} response.Response{data=[]purchase.PurchaseProductConfirm} "获取确认信息" |
| | | // @Router /purchase/getPurchaseProductConfirmInfo/{number} [get] |
| | | func (e *PurchaseApi) GetPurchaseProductConfirmInfo(c *gin.Context) { |
| | | number := c.Param("number") |
| | | if number == "" { |
| | | response.FailWithMessage("参数缺失", c) |
| | | return |
| | | } |
| | | info, err := service.NewPurchaseService().GetPurchaseProductConfirmInfo(number) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取确认信息失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取确认信息失败", c) |
| | | return |
| | | } |
| | | response.OkWithData(info, c) |
| | | } |
| | | |
| | | // SavePurchaseProductConfirm |
| | | // @Tags Purchase |
| | | // @Summary 确认收货 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body []purchaserequest.PurchaseProductConfirmInfo true "list" |
| | | // @Success 200 {object} response.Response{msg=string} "确认收货" |
| | | // @Router /purchase/savePurchaseProductConfirm [post] |
| | | func (e *PurchaseApi) SavePurchaseProductConfirm(c *gin.Context) { |
| | | var params []*purchaserequest.PurchaseProductConfirmInfo |
| | | err := c.ShouldBindJSON(¶ms) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | |
| | | list := make([]*purchase.PurchaseProductConfirm, 0, len(params)) |
| | | if err := utils.AssignTo(params, &list); err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | |
| | | server := service.NewPurchaseService() |
| | | err = server.SavePurchaseProductConfirm(list, false) |
| | | |
| | | if err != nil { |
| | | global.GVA_LOG.Error("保存失败!", zap.Error(err)) |
| | | response.FailWithMessage("保存失败", c) |
| | | return |
| | | } |
| | | _, err = server.SavePurchaseQualityInspection(list) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("保存失败!", zap.Error(err)) |
| | | response.FailWithMessage("保存失败", c) |
| | | return |
| | | } |
| | | response.OkWithMessage("保存成功", c) |
| | | } |
| | | |
| | | // GetPurchaseQualityInspectionInfo |
| | | // @Tags Purchase |
| | | // @Summary 获取采购质检信息信息 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body purchaserequest.GetQualityInspectionInfo true "参数" |
| | | // @Success 200 {object} response.Response{data=[]purchase.PurchaseProductConfirm} "获取确认信息" |
| | | // @Router /purchase/getPurchaseQualityInspectionInfo [post] |
| | | func (e *PurchaseApi) GetPurchaseQualityInspectionInfo(c *gin.Context) { |
| | | var params purchaserequest.GetQualityInspectionInfo |
| | | err := c.ShouldBindJSON(¶ms) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | if params.PurchaseNumber == "" { |
| | | response.FailWithMessage("采购单编码不能为空", c) |
| | | return |
| | | } |
| | | infos, err := service.NewPurchaseService().GetPurchaseQualityInspection(params) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取采购质检信息信息!", zap.Error(err)) |
| | | response.FailWithMessage("获取采购质检信息信息", c) |
| | | return |
| | | } |
| | | response.OkWithData(infos, c) |
| | | } |
| | | |
| | | // SavePurchaseQualityInspectionInfo |
| | | // @Tags Purchase |
| | | // @Summary 保存采购质检信息信息 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body purchaserequest.SaveQualityInspectionInfo true "参数" |
| | | // @Success 200 {object} response.Response{data=[]purchase.PurchaseProductConfirm} "获取确认信息" |
| | | // @Router /purchase/savePurchaseQualityInspectionInfo [post] |
| | | func (e *PurchaseApi) SavePurchaseQualityInspectionInfo(c *gin.Context) { |
| | | var params purchaserequest.SaveQualityInspectionInfo |
| | | err := c.ShouldBindJSON(¶ms) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | if params.PurchaseId == 0 || len(params.Ids) == 0 { |
| | | response.FailWithMessage("采购单编码和id不能为空", c) |
| | | return |
| | | } |
| | | server := service.PurchaseService{} |
| | | purchaseData, err := server.GetPurchase(params.PurchaseId) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | if params.Status == purchase.Unqualified { |
| | | err := server.UpdatePurchaseQualityInspection(params.Ids, params.Status) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("质检失败!", zap.Error(err)) |
| | | response.FailWithMessage("质检失败", c) |
| | | return |
| | | } |
| | | } else if params.Status == purchase.InWarehouse { |
| | | inspectionList, err := server.GetPurchaseQualityInspectionList(params.Ids) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | product := make([]*purchase_wms.PurchaseProduct, 0) |
| | | for _, inspection := range inspectionList { |
| | | var p purchase_wms.PurchaseProduct |
| | | p.Id = inspection.ProductId |
| | | p.Amount = inspection.Amount.IntPart() |
| | | product = append(product, &p) |
| | | } |
| | | client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | _, err = client.PurchaseToWms(context.Background(), &purchase_wms.PurchaseToWmsRequest{ |
| | | Number: purchaseData.Number, |
| | | SupplierName: purchaseData.Supplier.Name, |
| | | SupplierId: int64(purchaseData.SupplierId), |
| | | Product: product, |
| | | Source: "SRM_PURCHASE", |
| | | WarehouseName: purchaseData.Warehouse, |
| | | OperationSource: purchase_wms.OperationSource_OperationSourcePurchase, |
| | | SalesDetailsNumber: purchaseData.SourceOrder, |
| | | }) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("grpc调用失败!", zap.Error(err)) |
| | | response.FailWithMessage("grpc调用失败", c) |
| | | return |
| | | } |
| | | err = server.UpdatePurchaseQualityInspection(params.Ids, params.Status) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("质检失败!", zap.Error(err)) |
| | | response.FailWithMessage("质检失败", c) |
| | | return |
| | | } |
| | | } |
| | | err = server.UpdatePurchaseStatus(purchaseData.Number, purchase.WaitInspection) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("状态更新失败!", zap.Error(err)) |
| | | response.FailWithMessage("状态更新失败", c) |
| | | return |
| | | } |
| | | response.OkWithMessage("质检成功", c) |
| | | } |
| | | |
| | | // AllProductInWarehouse |
| | | // @Tags Purchase |
| | | // @Summary 全部合格入库 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body purchaserequest.PurchaseProductConfirmInfo true "参数" |
| | | // @Success 200 {object} response.Response{} "获取确认信息" |
| | | // @Router /purchase/allProductInWarehouse [post] |
| | | func (e *PurchaseApi) AllProductInWarehouse(c *gin.Context) { |
| | | var params []*purchaserequest.PurchaseProductConfirmInfo |
| | | err := c.ShouldBindJSON(¶ms) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | |
| | | list := make([]*purchase.PurchaseProductConfirm, 0, len(params)) |
| | | if err := utils.AssignTo(params, &list); err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | |
| | | server := service.NewPurchaseService() |
| | | err = server.SavePurchaseProductConfirm(list, false) |
| | | |
| | | if err != nil { |
| | | global.GVA_LOG.Error("保存失败!", zap.Error(err)) |
| | | response.FailWithMessage("保存失败", c) |
| | | return |
| | | } |
| | | inspectionList, err := server.SavePurchaseQualityInspection(list) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("保存失败!", zap.Error(err)) |
| | | response.FailWithMessage("保存失败", c) |
| | | return |
| | | } |
| | | purchaseData, err := server.GetPurchaseByNumber(list[0].PurchaseNumber) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | product := make([]*purchase_wms.PurchaseProduct, 0) |
| | | ids := make([]int, 0) |
| | | productMap := make(map[string]int64) |
| | | for _, inspection := range inspectionList { |
| | | productMap[inspection.ProductId] = inspection.Amount.IntPart() |
| | | ids = append(ids, int(inspection.ID)) |
| | | } |
| | | for k, v := range productMap { |
| | | var p purchase_wms.PurchaseProduct |
| | | p.Id = k |
| | | p.Amount = v |
| | | product = append(product, &p) |
| | | } |
| | | client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | _, err = client.PurchaseToWms(context.Background(), &purchase_wms.PurchaseToWmsRequest{ |
| | | Number: purchaseData.Number, |
| | | SupplierName: purchaseData.Supplier.Name, |
| | | SupplierId: int64(purchaseData.SupplierId), |
| | | Product: product, |
| | | Source: "SRM_PURCHASE", |
| | | WarehouseName: purchaseData.Warehouse, |
| | | OperationSource: purchase_wms.OperationSource_OperationSourcePurchase, |
| | | SalesDetailsNumber: purchaseData.SourceOrder, |
| | | }) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("grpc调用失败!", zap.Error(err)) |
| | | response.FailWithMessage("grpc调用失败", c) |
| | | return |
| | | } |
| | | err = server.UpdatePurchaseQualityInspection(ids, purchase.InWarehouse) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("质检失败!", zap.Error(err)) |
| | | response.FailWithMessage("质检失败", c) |
| | | return |
| | | } |
| | | err = server.UpdatePurchaseStatus(purchaseData.Number, purchase.WaitInspection) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("质检失败!", zap.Error(err)) |
| | | response.FailWithMessage("质检失败", c) |
| | | return |
| | | } |
| | | response.OkWithMessage("质检成功", c) |
| | | } |