入库不发U8
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
/// <returns></returns>
|
||||
public bool ExitwarehouseCommmon(string original);
|
||||
/// <summary>
|
||||
/// 判断箱子是否存在陈平库中
|
||||
/// 判断箱子是否存在成品库中
|
||||
/// </summary>
|
||||
/// <param name="originalCode"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
@@ -30,5 +30,7 @@ namespace ZR.Service.mes.wms.IService
|
||||
|
||||
// 货物退库(从成品库退货到产线)
|
||||
public int ReturnProductwarehouse(WmgoodsDto wmgoods, string createName);
|
||||
|
||||
public int IntoProductwarehouseNoU8(WmgoodsDto wmgoods, string createName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace ZR.Service.mes.wms
|
||||
public class WMExitwarehouseService : BaseService<WmInfo>, IWMExitwarehouseService
|
||||
{
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
//普通入库
|
||||
// 直接退库
|
||||
public bool ExitwarehouseCommmon(string original)
|
||||
{
|
||||
ResultionPackageCodeDto packageCode = ResolutionPackagecode(original);
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace ZR.Service.mes.wms
|
||||
{
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
// 统一入库操作
|
||||
public int IntoProductwarehouse(WmgoodsDto wmgoods, string createName)
|
||||
{
|
||||
try
|
||||
@@ -659,5 +660,153 @@ namespace ZR.Service.mes.wms
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public int IntoProductwarehouseNoU8(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<string> uniquePackages = new HashSet<string>(packageArray);
|
||||
if (uniquePackages.Count != packageArray.Length)
|
||||
throw new Exception($"入库箱有重复,实际箱数:{uniquePackages.Count}");
|
||||
|
||||
// 2. 解析数据并准备入库列表(事务外执行)
|
||||
List<WmGoodsNowProduction> preparegoodsList = new List<WmGoodsNowProduction>();
|
||||
HashSet<string> partnumbers = new HashSet<string>();
|
||||
List<string> allPatchCodes = new List<string>();
|
||||
List<string> packageCodeRemark = new List<string>();
|
||||
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;
|
||||
int? quantity = resultionPackage.Quantity ?? 0;
|
||||
|
||||
// 收集用于批量校验的箱号
|
||||
allPatchCodes.Add(patchCode);
|
||||
packageCodeRemark.Add(patchCode);
|
||||
|
||||
// 构建入库对象
|
||||
var wmGood = new WmGoodsNowProduction
|
||||
{
|
||||
Id = SnowFlakeSingle.Instance.NextId().ToString(),
|
||||
PackageCodeClient = patchCode,
|
||||
Partnumber = resultionPackage.PartNumner,
|
||||
PackageCodeOriginal = resultionPackage.originalCode,
|
||||
LocationCode = location,
|
||||
GoodsNumLogic = quantity.Value,
|
||||
GoodsNumAction = quantity.Value,
|
||||
EntryWarehouseTime = DateTime.Now,
|
||||
CreatedBy = createName,
|
||||
CreatedTime = DateTime.Now
|
||||
};
|
||||
|
||||
// 处理流水号(增加容错)
|
||||
string[] patchParts = patchCode.Split('_');
|
||||
int flowNum = -1;
|
||||
if (patchParts.Length >= 2)
|
||||
int.TryParse(patchParts[1], out flowNum);
|
||||
|
||||
wmGood.PackageCode = Getpack_no(resultionPackage.WorkoderID, flowNum.ToString("000")) ?? "Iminate";
|
||||
|
||||
// 统计数据
|
||||
preparegoodsList.Add(wmGood);
|
||||
partnumbers.Add(wmGood.Partnumber);
|
||||
totalPackage++;
|
||||
totalPartnumber += quantity.Value;
|
||||
}
|
||||
|
||||
// 3. 批量校验已入库状态(单次查询,减少连接占用)
|
||||
if (allPatchCodes.Any())
|
||||
{
|
||||
var existingCodes = Context.Queryable<WmGoodsNowProduction>()
|
||||
.Where(it => allPatchCodes.Contains(it.PackageCodeClient))
|
||||
.Select(it => it.PackageCodeClient)
|
||||
.ToList();
|
||||
|
||||
if (existingCodes.Any())
|
||||
throw new Exception($"箱号已入库: {string.Join(",", existingCodes)}");
|
||||
}
|
||||
|
||||
// 4. 数据库操作(最小化事务范围)
|
||||
Context.Ado.BeginTran();
|
||||
try
|
||||
{
|
||||
// 批量更新校验状态
|
||||
var packageCodes = preparegoodsList
|
||||
.Where(p => !string.IsNullOrEmpty(p.PackageCode))
|
||||
.Select(p => p.PackageCode)
|
||||
.ToList();
|
||||
|
||||
if (packageCodes.Any())
|
||||
{
|
||||
Context.Updateable<WmFgentryInspect>()
|
||||
.SetColumns(it => it.Bitwm == 1)
|
||||
.Where(it => packageCodes.Contains(it.Packcode))
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
// 批量插入入库记录
|
||||
int insertResult = Context.Insertable(preparegoodsList).ExecuteCommand();
|
||||
if (insertResult == 0)
|
||||
throw new Exception("入库记录插入失败");
|
||||
|
||||
// 插入操作日志
|
||||
var record = new WmGoodsRecord
|
||||
{
|
||||
Id = SnowFlakeSingle.Instance.NextId().ToString(),
|
||||
FkInventoryId = SnowFlakeSingle.Instance.NextId().ToString(),
|
||||
Code = "IntoProductwarehouse",
|
||||
Partnumber = partnumbers.FirstOrDefault() ?? "无零件号",
|
||||
ChangeType = 1,
|
||||
ChangePackage = totalPackage,
|
||||
ChangeQuantity = totalPartnumber,
|
||||
ActionTime = DateTime.Now,
|
||||
Status = 1,
|
||||
Remark =
|
||||
"货物入库(不传U8)"
|
||||
+ "\n零件号:"
|
||||
+ string.Join(',', partnumbers)
|
||||
+ "\n总箱数:"
|
||||
+ totalPackage
|
||||
+ "\n总零件数:"
|
||||
+ totalPartnumber
|
||||
+ "\n涉及批次号:\n"
|
||||
+ string.Join(',', allPatchCodes),
|
||||
CreatedBy = createName,
|
||||
CreatedTime = DateTime.Now
|
||||
};
|
||||
|
||||
if (Context.Insertable(record).ExecuteCommand() == 0)
|
||||
throw new Exception("操作记录插入失败");
|
||||
|
||||
Context.Ado.CommitTran(); // 提交事务,释放连接
|
||||
}
|
||||
catch
|
||||
{
|
||||
Context.Ado.RollbackTran(); // 回滚事务,释放连接
|
||||
throw;
|
||||
}
|
||||
|
||||
return preparegoodsList.Count;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,6 +505,12 @@ namespace ZR.Service.mes.wms
|
||||
}
|
||||
foreach (var item in qcBackEndQualityStatistics2)
|
||||
{
|
||||
int _changeQuantity =
|
||||
item.PolishNumber.Value + item.DamoNumber.Value + item.BaofeiNumber.Value;
|
||||
if (_changeQuantity == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// TODO 零件号二次处理
|
||||
string partNumber = item.PartNumber;
|
||||
// 使用正则表达式匹配并移除特殊后缀
|
||||
@@ -522,11 +528,10 @@ namespace ZR.Service.mes.wms
|
||||
Code = "自动",
|
||||
Partnumber = processedPartnumber,
|
||||
ChangeType = 2,
|
||||
ChangeQuantity =
|
||||
item.PolishNumber + item.DamoNumber + item.BaofeiNumber,
|
||||
ChangeQuantity = _changeQuantity,
|
||||
ActionTime = item.StartTime,
|
||||
Status = 1,
|
||||
Remark = "后道触摸屏-非直接出库-报表内损耗自动出库,来源:" + item.WorkOrder
|
||||
Remark = "后道触摸屏-W04非直接出库-报表内损耗自动出库,来源:" + item.WorkOrder
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user