Switch warehouse matching to use IDs

This commit is contained in:
2026-06-24 23:25:06 +08:00
parent 4670220614
commit bd9b5a6f4d
27 changed files with 776 additions and 419 deletions
+51 -15
View File
@@ -40,12 +40,15 @@ namespace BLL
from warehouseperson in warehousepersons.DefaultIfEmpty()
join unit in Funs.DB.Base_Unit on x.ReqUnitId equals unit.UnitId into units
from unit in units.DefaultIfEmpty()
join warehouse in Funs.DB.Base_Warehouse on x.WarehouseId equals warehouse.WarehouseId into warehouses
from warehouse in warehouses.DefaultIfEmpty()
orderby x.CreateDate descending
where
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
(string.IsNullOrEmpty(table.ProjectId) || x.ProjectId.Contains(table.ProjectId)) &&
(string.IsNullOrEmpty(table.CusBillCode) || x.CusBillCode.Contains(table.CusBillCode)) &&
(string.IsNullOrEmpty(table.WarehouseCode) || x.WarehouseCode.Contains(table.WarehouseCode)) &&
(string.IsNullOrEmpty(table.WarehouseId) || x.WarehouseId == table.WarehouseId) &&
(string.IsNullOrEmpty(table.WarehouseCode) || x.WarehouseCode.Contains(table.WarehouseCode) || x.WarehouseId.Contains(table.WarehouseCode)) &&
(string.IsNullOrEmpty(table.CreateMan) || x.CreateMan.Contains(table.CreateMan)) &&
(string.IsNullOrEmpty(table.OutputMasterId) || x.OutputMasterId.Contains(table.OutputMasterId)) &&
(string.IsNullOrEmpty(table.ReqUnitId) || x.ReqUnitId.Contains(table.ReqUnitId)) &&
@@ -60,7 +63,9 @@ namespace BLL
Id = x.Id,
ProjectId = x.ProjectId,
CusBillCode = x.CusBillCode,
WarehouseCode = x.WarehouseCode,
WarehouseId = x.WarehouseId,
WarehouseCode = warehouse == null ? x.WarehouseCode : warehouse.WarehouseName,
WarehouseName = warehouse == null ? x.WarehouseCode : warehouse.WarehouseName,
Source = x.Source,
InOutType = x.InOutType,
TypeInt = x.TypeInt,
@@ -117,7 +122,9 @@ namespace BLL
Id = x.Id,
ProjectId = x.ProjectId,
CusBillCode = x.CusBillCode,
WarehouseId = x.WarehouseId,
WarehouseCode = x.WarehouseCode,
WarehouseName = x.WarehouseName,
Source = x.Source,
InOutType = x.InOutType,
TypeInt = x.TypeInt,
@@ -167,7 +174,9 @@ namespace BLL
Id = x.Id,
ProjectId = x.ProjectId,
CusBillCode = x.CusBillCode,
WarehouseId = x.WarehouseId,
WarehouseCode = x.WarehouseCode,
WarehouseName = x.WarehouseName,
Source = x.Source,
InOutType = x.InOutType,
TypeInt = x.TypeInt,
@@ -268,11 +277,13 @@ namespace BLL
responeData.message = "导入数据为空!";
return responeData;
}
var warehouseCodeList = temeplateDtoIns.Select(x => x.WarehouseCode).Distinct().ToList(); //获取导入文件的仓库编号
var warehouseList = Base_WarehouseService.GetWarehouseList(projectid);
var warehouseCodeList = temeplateDtoIns.Select(x => CleanImportText(x.WarehouseCode)).Distinct().ToList(); //获取导入文件的仓库
string errorWarehouseCode = "";
foreach (var item in warehouseCodeList)
{
if (!Base_WarehouseService.GetWarehouseList(projectid).Select(x => x.WarehouseName == item).Any())
var warehouse = warehouseList.FirstOrDefault(x => x.WarehouseId == item || x.WarehouseName == item);
if (warehouse == null)
{
errorWarehouseCode += item + ",";
}
@@ -287,6 +298,15 @@ namespace BLL
return responeData;
//}
}
foreach (var item in temeplateDtoIns)
{
var warehouse = warehouseList.FirstOrDefault(x => x.WarehouseId == CleanImportText(item.WarehouseCode) || x.WarehouseName == CleanImportText(item.WarehouseCode));
if (warehouse != null)
{
// 导入模板仍允许填仓库名称,入库申请保存时同时固化仓库主键,后续改名不影响关联。
item.WarehouseCode = warehouse.WarehouseName;
}
}
var typeString = temeplateDtoIns.Select(x => x.TypeString).Distinct().ToList(); //获取导入文件的类型
if (typeString.Where(x => string.IsNullOrEmpty(x)).Count() > 0)
{
@@ -362,8 +382,11 @@ namespace BLL
//通过映射实体赋值
var twInOutPlanMaster = mapper.Map(CusBillCodeDtoIns).FirstOrDefault();
var twInOutPlanDetails = mapperDetail.Map(CusBillCodeDtoIns.Where(x => !string.IsNullOrEmpty(x.MaterialCode) && !string.IsNullOrEmpty(x.PlanNum)).ToList());
var importWarehouse = warehouseList.FirstOrDefault(x => x.WarehouseName == FirstCusBillCodeDtoIns.WarehouseCode);
twInOutPlanMaster.Id = SQLHelper.GetNewID();
twInOutPlanMaster.WarehouseId = importWarehouse?.WarehouseId;
twInOutPlanMaster.WarehouseCode = importWarehouse?.WarehouseName ?? twInOutPlanMaster.WarehouseCode;
twInOutPlanMaster.InOutType = (int)TwConst.InOutType.;
twInOutPlanMaster.State = (int)TwConst.State.;
@@ -457,7 +480,8 @@ namespace BLL
errors.Add("第" + rowIndex + "行,仓库,此项为必填项!");
continue;
}
if (!warehouseList.Any(x => x.WarehouseName == rowWarehouseCode))
var rowWarehouse = warehouseList.FirstOrDefault(x => x.WarehouseId == rowWarehouseCode || x.WarehouseName == rowWarehouseCode);
if (rowWarehouse == null)
{
errors.Add("第" + rowIndex + "行,仓库[" + rowWarehouseCode + "]不存在!");
continue;
@@ -499,16 +523,17 @@ namespace BLL
continue;
}
var stock = allStock.FirstOrDefault(x => x.WarehouseCode == rowWarehouseCode && x.Code == materialCode && x.HeatNo == heatNo && x.BatchNo == batchNo);
var stock = allStock.FirstOrDefault(x => x.WarehouseId == rowWarehouse.WarehouseId && x.Code == materialCode && x.HeatNo == heatNo && x.BatchNo == batchNo);
if (stock == null)
{
errors.Add("第" + rowIndex + "行,仓库[" + rowWarehouseCode + "]库存中不存在此材料编码/炉号/批号-" + materialCode + "/" + heatNo + "/" + batchNo);
errors.Add("第" + rowIndex + "行,仓库[" + rowWarehouse.WarehouseName + "]库存中不存在此材料编码/炉号/批号-" + materialCode + "/" + heatNo + "/" + batchNo);
continue;
}
detailRows.Add(new Tw_OutHistoryImportRow
{
WarehouseCode = stock.WarehouseCode,
WarehouseId = rowWarehouse.WarehouseId,
WarehouseCode = rowWarehouse.WarehouseName,
MaterialCode = stock.PipeLineMatCode,
Code = stock.Code,
HeatNo = stock.HeatNo,
@@ -533,13 +558,14 @@ namespace BLL
return responeData;
}
var stockErrors = detailRows.GroupBy(x => new { x.WarehouseCode, x.MaterialCode })
var stockErrors = detailRows.GroupBy(x => new { x.WarehouseId, x.WarehouseCode, x.MaterialCode })
.Select(x => new
{
x.Key.WarehouseId,
x.Key.WarehouseCode,
x.Key.MaterialCode,
Num = x.Sum(y => y.Num),
Stock = allStock.FirstOrDefault(y => y.WarehouseCode == x.Key.WarehouseCode && y.PipeLineMatCode == x.Key.MaterialCode)
Stock = allStock.FirstOrDefault(y => y.WarehouseId == x.Key.WarehouseId && y.PipeLineMatCode == x.Key.MaterialCode)
})
.Where(x => x.Stock == null || (x.Stock.StockNum ?? 0) < x.Num)
.Select(x => "仓库[" + x.WarehouseCode + "]" + (x.Stock == null ? x.MaterialCode : x.Stock.Code + "/" + x.Stock.HeatNo + "/" + x.Stock.BatchNo)
@@ -555,6 +581,7 @@ namespace BLL
int planCount = 0;
foreach (var group in detailRows.GroupBy(x => new
{
x.WarehouseId,
x.WarehouseCode,
x.ReqUnitId,
OutputDate = x.OutputDate.Date,
@@ -568,6 +595,7 @@ namespace BLL
Id = planId,
ProjectId = projectId,
CusBillCode = cusBillCode,
WarehouseId = group.Key.WarehouseId,
WarehouseCode = group.Key.WarehouseCode,
WeldTaskId = unitWorkId,
Source = 2,
@@ -667,13 +695,15 @@ namespace BLL
}
public static void Add(Model.Tw_InOutPlanMaster newtable)
{
var warehouseName = Base_WarehouseService.GetWarehouseNameById(newtable.WarehouseId);
Model.Tw_InOutPlanMaster table = new Model.Tw_InOutPlanMaster
{
Id = newtable.Id,
ProjectId = newtable.ProjectId,
CusBillCode = newtable.CusBillCode,
WarehouseCode = newtable.WarehouseCode,
WarehouseId = newtable.WarehouseId,
WarehouseCode = warehouseName ?? newtable.WarehouseCode,
Source = newtable.Source,
Category = newtable.Category,
InOutType = newtable.InOutType,
@@ -704,7 +734,8 @@ namespace BLL
table.Id = newtable.Id;
table.ProjectId = newtable.ProjectId;
table.CusBillCode = newtable.CusBillCode;
table.WarehouseCode = newtable.WarehouseCode;
table.WarehouseId = newtable.WarehouseId;
table.WarehouseCode = Base_WarehouseService.GetWarehouseNameById(newtable.WarehouseId) ?? newtable.WarehouseCode;
table.Category = newtable.Category;
table.Source = newtable.Source;
table.InOutType = newtable.InOutType;
@@ -810,6 +841,7 @@ namespace BLL
Id = Guid.NewGuid().ToString(),
OutputMasterId = outMaster.Id,
ProjectId = outMaster.ProjectId,
WarehouseId = outMaster.WarehouseId,
WarehouseCode = outMaster.WarehouseCode,
Source = 2,
Category = outMaster.Category,
@@ -895,7 +927,7 @@ namespace BLL
public static Dictionary<string, string> GetWarehouseCode(string projectId)
{
var q = Base_WarehouseService.GetWarehouseList(projectId).Distinct().ToDictionary(x => x.WarehouseName, x => x.WarehouseName);
var q = Base_WarehouseService.GetWarehouseList(projectId).Distinct().ToDictionary(x => x.WarehouseName, x => x.WarehouseId);
return q;
}
public static string GetDataInCusBillCode(string projectid, string unitcode, string typeString, string unitWorkCode = "", string Category = "")
@@ -1039,6 +1071,8 @@ namespace BLL
var outPlanDetailListPiece = outMateriaList.Where(x => x.MaterialName.Contains("个"));//管件
var outPlanDetailListOthere = outMateriaList.Where(x => x.MaterialName.Contains("米"));//管段
var weldTaskCode = WeldTaskService.GetWeldTaskById(weldTask.WeldTaskId)?.TaskCode;
var taskPipeline = PipelineService.GetPipelineByPipelineId(weldTask.PipelineId);
var taskWarehouse = BLL.Base_WarehouseService.GetWarehouseByWarehouseId(taskPipeline?.WarehouseId);
if (outPlanDetailListPiece.Any())
{
Model.Tw_InOutPlanMaster table = new Model.Tw_InOutPlanMaster
@@ -1047,7 +1081,8 @@ namespace BLL
ProjectId = weldTask.ProjectId,
// CusBillCode = string.Format("{0:yyyyMMdd}", DateTime.Now) + UnitService.GetUnitCodeByUnitId(weldTask.UnitId) + "-" + UnitWorkService.getUnitWorkByUnitWorkId(weldTask.UnitWorkId)?.UnitWorkCode + "AP-PF01",
CusBillCode = TwInOutplanmasterService.GetCusBillCodeByTaskCode(weldTaskCode, TwConst.TypeInt., TwConst.Category.),
WarehouseCode = BLL.Base_WarehouseService.GetWarehouseByWarehouseId(PipelineService.GetPipelineByPipelineId(weldTask.PipelineId).WarehouseId).WarehouseName,
WarehouseId = taskWarehouse?.WarehouseId,
WarehouseCode = taskWarehouse?.WarehouseName,
Source = 1,
InOutType = (int)TwConst.InOutType.,
TypeInt = (int)TwConst.TypeInt.,
@@ -1088,7 +1123,8 @@ namespace BLL
Id = Guid.NewGuid().ToString(),
ProjectId = weldTask.ProjectId,
CusBillCode = TwInOutplanmasterService.GetCusBillCodeByTaskCode(weldTaskCode, TwConst.TypeInt., TwConst.Category.),
WarehouseCode = BLL.Base_WarehouseService.GetWarehouseByWarehouseId(PipelineService.GetPipelineByPipelineId(weldTask.PipelineId).WarehouseId).WarehouseName,
WarehouseId = taskWarehouse?.WarehouseId,
WarehouseCode = taskWarehouse?.WarehouseName,
Source = 1,
InOutType = (int)TwConst.InOutType.,
TypeInt = (int)TwConst.TypeInt.,