feat: 完善材料条码与焊接业务功能
This commit is contained in:
@@ -3,11 +3,14 @@ using Model;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
public static class TwInputdetailBarCodeService
|
||||
{
|
||||
private static readonly object BarCodeLock = new object();
|
||||
|
||||
public static int Count
|
||||
{
|
||||
get;
|
||||
@@ -52,18 +55,23 @@ namespace BLL
|
||||
MaterialDef = mat.MaterialDef,
|
||||
MaterialSpec = mat.MaterialSpec,
|
||||
MaterialUnit = mat.MaterialUnit,
|
||||
BarCode = x.MaterialCode
|
||||
BarCode = x.BarCode,
|
||||
Quantity = x.Quantity
|
||||
};
|
||||
|
||||
return q.ToList();
|
||||
}
|
||||
public static List<Tw_InputDetailBarCodeOutput> GetListData(string materialCode)
|
||||
{
|
||||
var q = from mat in Funs.DB.HJGL_MaterialCodeLib
|
||||
where
|
||||
mat.MaterialCode == materialCode
|
||||
var q = from detailBarCode in Funs.DB.Tw_InputDetailBarCode
|
||||
join mat in Funs.DB.HJGL_MaterialCodeLib on detailBarCode.MaterialCode equals mat.MaterialCode
|
||||
where detailBarCode.MaterialCode == materialCode
|
||||
orderby detailBarCode.BarCode
|
||||
select new Tw_InputDetailBarCodeOutput
|
||||
{
|
||||
Id = detailBarCode.Id,
|
||||
InputDetailId = detailBarCode.InputDetailId,
|
||||
InputMasterId = detailBarCode.InputMasterId,
|
||||
MaterialCode = mat.MaterialCode,
|
||||
Code = mat.Code,
|
||||
HeatNo = mat.HeatNo,
|
||||
@@ -72,7 +80,8 @@ namespace BLL
|
||||
MaterialDef = mat.MaterialDef,
|
||||
MaterialSpec = mat.MaterialSpec,
|
||||
MaterialUnit = mat.MaterialUnit,
|
||||
BarCode = mat.MaterialCode
|
||||
BarCode = detailBarCode.BarCode,
|
||||
Quantity = detailBarCode.Quantity
|
||||
};
|
||||
|
||||
return q.ToList();
|
||||
@@ -88,17 +97,65 @@ namespace BLL
|
||||
return;
|
||||
}
|
||||
|
||||
string id = SQLHelper.GetNewID();
|
||||
Tw_InputDetailBarCode table = new Tw_InputDetailBarCode
|
||||
lock (BarCodeLock)
|
||||
{
|
||||
Id = id,
|
||||
InputDetailId = inputDetail.Id,
|
||||
InputMasterId = inputMaster.Id,
|
||||
MaterialCode = inputDetail.MaterialCode,
|
||||
BarCode = BuildBarCode(inputMaster, inputDetail, id)
|
||||
};
|
||||
Funs.DB.Tw_InputDetailBarCode.InsertOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
if (IsExist(inputDetail.Id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string id = SQLHelper.GetNewID();
|
||||
bool isMeter = IsMeterMaterial(inputDetail.MaterialCode);
|
||||
Tw_InputDetailBarCode table = new Tw_InputDetailBarCode
|
||||
{
|
||||
Id = id,
|
||||
InputDetailId = inputDetail.Id,
|
||||
InputMasterId = inputMaster.Id,
|
||||
MaterialCode = inputDetail.MaterialCode,
|
||||
// 按米计量的管材由扫码后录入实际长度,其他材料每个条码固定代表1件。
|
||||
Quantity = isMeter ? (decimal?)null : 1m,
|
||||
BarCode = isMeter ? BuildNextBarCode(inputDetail.MaterialCode) : inputDetail.MaterialCode
|
||||
};
|
||||
Funs.DB.Tw_InputDetailBarCode.InsertOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为指定管材入库明细生成下一个流水条码。
|
||||
/// </summary>
|
||||
public static string AddNextByInputDetailId(string inputDetailId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(inputDetailId))
|
||||
{
|
||||
throw new ArgumentException("入库明细不能为空。");
|
||||
}
|
||||
|
||||
lock (BarCodeLock)
|
||||
{
|
||||
var inputDetail = Funs.DB.Tw_InputDetail.FirstOrDefault(x => x.Id == inputDetailId);
|
||||
if (inputDetail == null)
|
||||
{
|
||||
throw new InvalidOperationException("未找到入库明细。");
|
||||
}
|
||||
if (!IsMeterMaterial(inputDetail.MaterialCode))
|
||||
{
|
||||
throw new InvalidOperationException("只有单位为米的管材可以生成新条码。");
|
||||
}
|
||||
|
||||
string barCode = BuildNextBarCode(inputDetail.MaterialCode);
|
||||
Funs.DB.Tw_InputDetailBarCode.InsertOnSubmit(new Tw_InputDetailBarCode
|
||||
{
|
||||
Id = SQLHelper.GetNewID(),
|
||||
InputDetailId = inputDetail.Id,
|
||||
InputMasterId = inputDetail.InputMasterId,
|
||||
MaterialCode = inputDetail.MaterialCode,
|
||||
BarCode = barCode,
|
||||
Quantity = null
|
||||
});
|
||||
Funs.DB.SubmitChanges();
|
||||
return barCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteByInputMasterId(string inputMasterId)
|
||||
@@ -140,7 +197,41 @@ namespace BLL
|
||||
/// </summary>
|
||||
public static string BuildBarCode(Tw_InputMaster inputMaster, Tw_InputDetail inputDetail, string barCodeDetailId)
|
||||
{
|
||||
return inputDetail == null ? string.Empty : inputDetail.MaterialCode;
|
||||
if (inputDetail == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return IsMeterMaterial(inputDetail.MaterialCode)
|
||||
? BuildNextBarCode(inputDetail.MaterialCode)
|
||||
: inputDetail.MaterialCode;
|
||||
}
|
||||
|
||||
private static bool IsMeterMaterial(string materialCode)
|
||||
{
|
||||
string materialUnit = Funs.DB.HJGL_MaterialCodeLib
|
||||
.Where(x => x.MaterialCode == materialCode)
|
||||
.Select(x => x.MaterialUnit)
|
||||
.FirstOrDefault();
|
||||
return string.Equals((materialUnit ?? string.Empty).Trim(), "米", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static string BuildNextBarCode(string materialCode)
|
||||
{
|
||||
string prefix = materialCode + "-";
|
||||
int maxSequence = 0;
|
||||
var barCodes = Funs.DB.Tw_InputDetailBarCode
|
||||
.Where(x => x.MaterialCode == materialCode && x.BarCode.StartsWith(prefix))
|
||||
.Select(x => x.BarCode)
|
||||
.ToList();
|
||||
foreach (string barCode in barCodes)
|
||||
{
|
||||
int sequence;
|
||||
if (int.TryParse(barCode.Substring(prefix.Length), out sequence) && sequence > maxSequence)
|
||||
{
|
||||
maxSequence = sequence;
|
||||
}
|
||||
}
|
||||
return prefix + (maxSequence + 1).ToString("D3");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user