diff --git a/ZR.Admin.WebApi/Controllers/mes/wms/WMentryWarehousing_productController.cs b/ZR.Admin.WebApi/Controllers/mes/wms/WMentryWarehousing_productController.cs
index fc8e480e..141a3533 100644
--- a/ZR.Admin.WebApi/Controllers/mes/wms/WMentryWarehousing_productController.cs
+++ b/ZR.Admin.WebApi/Controllers/mes/wms/WMentryWarehousing_productController.cs
@@ -135,6 +135,45 @@ namespace ZR.Admin.WebApi.Controllers.mes.wms
}
+ ///
+ /// 退货到成品库
+ ///
+ ///
+ ///
+ [HttpPost("ReturnProductwarehouse")]
+ [Log(Title = "入库")]
+ public IActionResult ReturnProductwarehouse([FromBody] WmgoodsDto wmgoodsDto)
+ {
+ try
+ {
+ if (wmgoodsDto == null)
+ {
+ return ToResponse(new ApiResult(200, "传入参数为空", false));
+ }
+ string msg = "";
+
+ string createName = HttpContext.GetName();
+ int num = this.wm_entryWarehousing_productService.ReturnProductwarehouse(wmgoodsDto, createName);
+ if (num == 0)
+ {
+ msg = "退货数为0!";
+ }
+ else if (num >= 1)
+ {
+ msg = "成功退货" + num + "箱";
+
+
+ }
+ return ToResponse(new ApiResult(200, msg, num));
+ }
+ catch (Exception e)
+ {
+ return ToResponse(new ApiResult(500, e.Message, e.Message));
+ }
+
+ }
+
+
///
/// 获取库位已经存在箱子
///
diff --git a/ZR.Service/mes/wms/IService/IWMentryWarehousing_productService.cs b/ZR.Service/mes/wms/IService/IWMentryWarehousing_productService.cs
index 85dc309d..7194e734 100644
--- a/ZR.Service/mes/wms/IService/IWMentryWarehousing_productService.cs
+++ b/ZR.Service/mes/wms/IService/IWMentryWarehousing_productService.cs
@@ -28,7 +28,7 @@ namespace ZR.Service.mes.wms.IService
public bool IsExistedWarehouse(string originalCode);
-
-
+ // 货物退库(从成品库退货到产线)
+ public int ReturnProductwarehouse(WmgoodsDto wmgoods, string createName);
}
}
diff --git a/ZR.Service/mes/wms/WMentryWarehousing_productService.cs b/ZR.Service/mes/wms/WMentryWarehousing_productService.cs
index 72d78f7c..cf322a16 100644
--- a/ZR.Service/mes/wms/WMentryWarehousing_productService.cs
+++ b/ZR.Service/mes/wms/WMentryWarehousing_productService.cs
@@ -502,5 +502,141 @@ namespace ZR.Service.mes.wms
return "标签存在异常!" + e.Message;
}
}
+
+ public int ReturnProductwarehouse(WmgoodsDto wmgoods, string createName)
+ {
+ try
+ {
+ // 1. 前置参数校验(事务外执行,不占用连接)
+ if (wmgoods == null || wmgoods.packagelist == null || wmgoods.packagelist.Length == 0)
+ throw new Exception("无传入箱,请检查传入数据!");
+
+ string location = string.IsNullOrEmpty(wmgoods.location) ? "LS" : wmgoods.location;
+ string[] packageArray = wmgoods.packagelist;
+
+ // 去重校验
+ HashSet uniquePackages = new HashSet(packageArray);
+ if (uniquePackages.Count != packageArray.Length)
+ throw new Exception($"传入箱有重复,实际箱数:{uniquePackages.Count}");
+
+ // 2. 解析数据并查询现有库存(事务外执行)
+ List returnGoodsList = new List();
+ HashSet partnumbers = new HashSet();
+ List allPatchCodes = new List();
+ int totalPackage = 0;
+ int totalPartnumber = 0;
+
+ foreach (var pkgCode in packageArray)
+ {
+ var resultionPackage = ResolutionPackage(pkgCode);
+ if (resultionPackage == null)
+ throw new Exception($"箱标签解析失败: {pkgCode}");
+
+ // 缓存常用属性
+ string patchCode = resultionPackage.PatchCode;
+
+ // 查询现有库存记录
+ var existingGoods = Context.Queryable()
+ .Where(it => it.PackageCodeClient == patchCode)
+ .First();
+
+ if (existingGoods == null)
+ throw new Exception($"箱号{patchCode}在成品库中不存在,无法退货!");
+
+ // 收集箱号
+ allPatchCodes.Add(patchCode);
+
+ // 添加到退货列表
+ returnGoodsList.Add(existingGoods);
+ partnumbers.Add(existingGoods.Partnumber);
+ totalPackage++;
+ totalPartnumber += existingGoods.GoodsNumAction.Value;
+ }
+
+ // 3. 数据库操作(最小化事务范围)
+ Context.Ado.BeginTran();
+ try
+ {
+ // 批量删除库存记录
+ var idsToDelete = returnGoodsList.Select(g => g.Id).ToList();
+ int deleteResult = Context.Deleteable()
+ .Where(it => idsToDelete.Contains(it.Id))
+ .ExecuteCommand();
+
+ if (deleteResult == 0)
+ throw new Exception("退货记录删除失败");
+
+ // 插入操作日志
+ var record = new WmGoodsRecord
+ {
+ Id = SnowFlakeSingle.Instance.NextId().ToString(),
+ FkInventoryId = SnowFlakeSingle.Instance.NextId().ToString(),
+ Code = "ReturnProductwarehouse",
+ Partnumber = partnumbers.FirstOrDefault() ?? "无零件号",
+ ChangeType = 4, // 4表示成品库退货操作
+ ChangePackage = totalPackage,
+ ChangeQuantity = -totalPartnumber, // 负数表示减少
+ Remark = $"货物从成品库退货\n仓库号:{location}\n零件号:{string.Join(',', partnumbers)}\n总箱数:{totalPackage}",
+ CreatedBy = createName,
+ CreatedTime = DateTime.Now
+ };
+
+ if (Context.Insertable(record).ExecuteCommand() == 0)
+ throw new Exception("操作记录插入失败");
+
+ Context.Ado.CommitTran(); // 提交事务,释放连接
+ }
+ catch
+ {
+ Context.Ado.RollbackTran(); // 回滚事务,释放连接
+ throw;
+ }
+
+ // 4. 保留原U8发送逻辑(事务已提交,不占用连接)
+ // 注意:根据需求,U8部分暂时不做修改,保持原有逻辑
+ _ = Task.Run(async () =>
+ {
+ string urlBase = "http://gam.com.cn:8053/";
+ ERP_WMS_interactiveService _eRP_WMS_InteractiveService = new ERP_WMS_interactiveService();
+ List u8PackageList = new List();
+
+ foreach (var item in returnGoodsList)
+ {
+ string dateString = DateTime.Now.ToString("yyyyMMdd");
+ Match match = Regex.Match(item.PackageCodeClient, @"(\d{2})(\d{2})(\d{2})");
+
+ if (match.Success)
+ {
+ dateString = $"20{match.Groups[1].Value}{match.Groups[2].Value}{match.Groups[3].Value}";
+ }
+ else
+ {
+ logger.Warn($"未找到匹配的日期模式:{item.PackageCodeClient}");
+ }
+
+ u8PackageList.Add(new ERP_WMS_interactiveModelQuery
+ {
+ materialCode = item.Partnumber,
+ location = item.LocationCode,
+ Qty = (-item.GoodsNumAction.Value).ToString(),
+ LotNo = dateString,
+ createTime = DateTime.Now,
+ userID = createName,
+ guid = Guid.NewGuid().ToString(),
+ lineno = "涂装生产线"
+ });
+ }
+
+ var u8ErpResult = await _eRP_WMS_InteractiveService.InboundedAsync(urlBase, u8PackageList);
+ logger.Warn(u8ErpResult);
+ });
+
+ return returnGoodsList.Count;
+ }
+ catch (Exception e)
+ {
+ throw new Exception(e.Message);
+ }
+ }
}
}