1
yanjinhui
2025-09-29 18ef8c37e6290ba6f47cbd5bbd26e56a682d767e
´úÂë¹ÜÀí/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs
@@ -9,12 +9,14 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.SquareCabin;
using WIDESEA_ISquareCabinRepository;
using WIDESEA_ISquareCabinServices;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.SquareCabin;
using WIDESEA_SquareCabinRepository;
using static WIDESEA_DTO.SquareCabin.OrderDto;
using static WIDESEA_DTO.SquareCabin.TowcsDto;
namespace WIDESEA_SquareCabinServices
{
@@ -75,6 +77,97 @@
            }
        }
        /// <summary>
        /// wcs回传给我
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ApiResponse<Dt_Inventory> OrderFeedback(EdiOrderCallbackRequest request)
        {
            try
            {
                if (request == null || request.details == null || !request.details.Any())
                {
                    return new ApiResponse<Dt_Inventory> { code ="500",msg = "请求参数无效" };
                }
                foreach (var detail in request.details)
                {
                    // å…ˆæŸ¥åº“存是否存在
                    var entity = Db.Queryable<Dt_Inventory>()
                                   .First(x => x.Goods_no == detail.productCode);
                    //将集合中的数量进行累加
                    decimal orderQty = detail.orderDetails?.Sum(x => Convert.ToDecimal(x.quantity)) ?? 0;
                    decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 0;
                    //decimal orderQty = detail.orderDetails?.Sum(x => Convert.ToDecimal(x.quantity)) ?? 0;
                    //decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 0;
                    if (entity == null)
                    {
                        // å¦‚果不存在,新建一条
                        entity = new Dt_Inventory
                        {
                            Goods_no = detail.productCode ?? detail.productName,
                            Reservoirarea = "默认库区",
                            Batch_num = detail.batchNo,
                            Business_qty = 0,
                            Actual_qty = 0
                        };
                    }
                    switch (request.orderType)
                    {
                        case "1": // å…¥åº“
                            entity.Business_qty += orderQty;
                            entity.Actual_qty += orderQty;
                            break;
                        case "2": // å‡ºåº“
                            entity.Business_qty -= orderQty;
                            entity.Actual_qty -= orderQty;
                            if (entity.Business_qty < 0) entity.Business_qty = 0; // å¯é€‰ï¼šé˜²æ­¢è´Ÿæ•°
                            if (entity.Actual_qty < 0) entity.Actual_qty = 0;
                            break;
                        case "3": // ç›˜ç‚¹
                            if (detail.stocktakingDetails != null && detail.stocktakingDetails.Any())
                            {
                                foreach (var stock in detail.stocktakingDetails)
                                {
                                    decimal diff = Convert.ToDecimal(stock.differenceQuantity);
                                    if (stock.IsProfit == "1") // ç›˜ç›ˆ
                                    {
                                        entity.Actual_qty += diff;
                                    }
                                    else // ç›˜äº
                                    {
                                        entity.Actual_qty -= diff;
                                        if (entity.Actual_qty < 0) entity.Actual_qty = 0;
                                    }
                                }
                            }
                            break;
                    }
                    // ä¿å­˜æ•°æ®
                    if (entity.Id == 0) // æ–°å»º
                        Db.Insertable(entity).ExecuteCommand();
                    else // æ›´æ–°
                        Db.Updateable(entity).ExecuteCommand();
                }
                return new ApiResponse<Dt_Inventory> {code = "0", msg = "成功" };
            }
            catch (Exception ex)
            {
                return new ApiResponse<Dt_Inventory> { code = "500", msg = ex.Message };
            }
        }
        /// <summary>
        /// æŽ¨é€å¼‚常信息给上游系统1.入库单接口;2.入库单报完成接口;3.出库单接口;4.出库报完成接口;5.药品基础信息同步接口;6.供应商信息接口;7.客户信息接口;8.库存
        /// </summary>