using MES.Service.Dto.webApi;
|
|
namespace MES.Service.service.QC;
|
|
public class BarcodeService
|
{
|
private static readonly List<string> ValidWorkOrders = new List<string>
|
{
|
"WO123456", "WO987654", "WO111222", "WO333444", "WO555666"
|
};
|
|
private static readonly List<string> GeneratedBarcodes = new List<string>();
|
|
public GenerateBarcodeResponse GenerateBarcodes(GenerateBarcodeRequest request)
|
{
|
if (request.panelQuantity <= 0)
|
{
|
throw new ArgumentException("panelQuantity 必须是大于0的数字");
|
}
|
|
if (string.IsNullOrEmpty(request.@operator))
|
{
|
throw new ArgumentException("缺少必填参数:operator");
|
}
|
|
if (string.IsNullOrEmpty(request.workOrderNumber))
|
{
|
throw new ArgumentException("缺少必填参数:workOrderNumber");
|
}
|
|
var response = new GenerateBarcodeResponse();
|
var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
|
var random = new Random();
|
|
for (int i = 0; i < request.panelQuantity; i++)
|
{
|
var barcode = $"BC{timestamp}{random.Next(1000, 9999)}{i:D2}";
|
response.barcodes.Add(barcode);
|
GeneratedBarcodes.Add(barcode);
|
}
|
|
return response;
|
}
|
|
public void ConfirmBarcodes(ConfirmBarcodeRequest request)
|
{
|
if (request.barcodes == null || request.barcodes.Count == 0)
|
{
|
throw new ArgumentException("请提供有效的条码列表");
|
}
|
|
if (string.IsNullOrEmpty(request.@operator))
|
{
|
throw new ArgumentException("缺少必填参数:operator");
|
}
|
|
if (string.IsNullOrEmpty(request.workOrderNumber))
|
{
|
throw new ArgumentException("缺少必填参数:workOrderNumber");
|
}
|
|
if (!ValidWorkOrders.Contains(request.workOrderNumber))
|
{
|
throw new ArgumentException($"工单 {request.workOrderNumber} 不存在");
|
}
|
|
foreach (var barcode in request.barcodes)
|
{
|
if (string.IsNullOrEmpty(barcode) || !barcode.StartsWith("BC"))
|
{
|
throw new ArgumentException($"条码 {barcode} 无效");
|
}
|
|
if (!GeneratedBarcodes.Contains(barcode))
|
{
|
throw new ArgumentException($"条码 {barcode} 无效");
|
}
|
}
|
}
|
}
|