线边操作添加ERP关联
This commit is contained in:
1 parent
713c3528ad
commit
0e5d0247bf
19 files changed
+1467
-139
No files matched your search
@@ -1,13 +1,15 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using HHWMS.Web;
|
||||
using HHWMS.Web.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
@@ -67,7 +69,7 @@ namespace HHWMS.Web.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_unitwork.IsExit<ReceiptHeader>(x => x.Code == vm.Entity.Code))
|
||||
if (_unitwork.IsExit<ReceiptHeader>(x => x.Code == vm.Entity.Code))
|
||||
{
|
||||
return FFResult().Alert($"入库单号 {vm.Entity.Code} 重复!");
|
||||
}
|
||||
@@ -234,5 +236,393 @@ namespace HHWMS.Web.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
[ActionDescription("GetReceiptDetails")]
|
||||
public ActionResult GetReceiptDetails()
|
||||
{
|
||||
var vm = Wtm.CreateVM<ReceiptHeaderVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据入库单单号获取ERP生产订单数据并更新
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[ActionDescription("GetReceiptDetails")]
|
||||
public async Task<IActionResult> GetReceiptDetails(ReceiptHeaderVM vm)
|
||||
{
|
||||
string receiptCode = vm.Entity.SourceCode;
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(receiptCode))
|
||||
{
|
||||
return FFResult().Alert($"入库单单号不能为空");
|
||||
}
|
||||
|
||||
// 根据入库单单号查找对应的 SourceCode(生产订单号)
|
||||
var header = _unitwork.FindSingle<ReceiptHeader>(h => h.SourceCode == receiptCode);
|
||||
if (header != null)
|
||||
{
|
||||
return FFResult().Alert($"已存在此入库单,单号:{receiptCode}");
|
||||
}
|
||||
|
||||
// 调用 ERP 接口获取该订单的最新数据
|
||||
var request = new LoadMoDetailListRequest
|
||||
{
|
||||
ErpCode = "001",
|
||||
MoCode = receiptCode, // 使用生产订单号查询
|
||||
Size = 100,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
var apiResult = await Wtm.CallAPI<LoadMoDetailListResponse>("ERP", "LoadMoDetailList", HttpMethodEnum.POST, request);
|
||||
|
||||
if (apiResult?.Data != null && apiResult.Data.Code == 0 && apiResult.Data.Data?.Count > 0)
|
||||
{
|
||||
Wtm.DoLog("获取ERP订单数据", ActionLogTypesEnum.Normal, "GetReceiptDetails",
|
||||
request: $"订单号:{receiptCode},获取到 {apiResult.Data.Data.Count} 条明细",
|
||||
result: "开始处理订单数据");
|
||||
|
||||
// 使用相同的逻辑处理订单数据
|
||||
await ProcessOrderData(_unitwork, apiResult.Data.Data);
|
||||
|
||||
Wtm.DoLog("获取ERP订单数据", ActionLogTypesEnum.Normal, "GetReceiptDetails",
|
||||
request: $"订单号:{receiptCode}",
|
||||
result: "订单数据处理完成");
|
||||
|
||||
return FFResult().CloseDialog().RefreshGrid().Message("订单数据获取成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().Alert(apiResult?.Data?.Msg ?? apiResult?.ErrorMsg ?? "未获取到订单数据");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Wtm.DoLog("获取ERP订单数据", ActionLogTypesEnum.Normal, "GetReceiptDetails",
|
||||
request: $"入库单号:{receiptCode}",
|
||||
result: $"错误:{ex.Message}");
|
||||
return FFResult().Alert($"获取订单数据失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理订单数据并保存到本地数据库(照搬 LoadErpOrderJob)
|
||||
/// </summary>
|
||||
private async Task ProcessOrderData(IUnitWork unitWork, List<MoDetailItem> orderList)
|
||||
{
|
||||
// 按订单号分组
|
||||
var orderGroups = orderList.GroupBy(x => x.MoCode);
|
||||
|
||||
foreach (var group in orderGroups)
|
||||
{
|
||||
var moCode = group.Key;
|
||||
var orderDetails = group.ToList();
|
||||
|
||||
// 检查订单是否已存在
|
||||
var existingHeader = unitWork.FindSingle<ReceiptHeader>(h => h.SourceCode == moCode);
|
||||
|
||||
if (existingHeader == null)
|
||||
{
|
||||
// 创建新的入库单头
|
||||
var header = new ReceiptHeader
|
||||
{
|
||||
SourceCode = moCode, // 生产订单号
|
||||
Code = unitWork.GetSerialNumber("REC", 8), // 生成入库单号
|
||||
BillType = "生产订单",
|
||||
TotalQty = orderDetails.Sum(x => x.Qty),
|
||||
TotalLines = orderDetails.Count,
|
||||
FirstStatus = ReceiptStatusEnum.新建,
|
||||
LastStatus = ReceiptStatusEnum.新建,
|
||||
Remark = orderDetails.First().Memo,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo?.ITCode ?? "系统",
|
||||
UpdateVersion = 1
|
||||
};
|
||||
|
||||
unitWork.Add(header); // 保存以获取 HeaderId
|
||||
|
||||
// 获取订单明细中的所有物料编码
|
||||
var invCodes = orderDetails
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.InvCode))
|
||||
.Select(x => x.InvCode)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// 一次性查询本地数据库中已存在的物料(优化性能)
|
||||
var existingMaterials = unitWork.Find<Material>(m => invCodes.Contains(m.MaterialCode))
|
||||
.ToList();
|
||||
|
||||
// 待新增的物料列表
|
||||
var newMaterials = new List<Material>();
|
||||
|
||||
// 创建入库单明细
|
||||
var details = new List<ReceiptDetail>();
|
||||
foreach (var item in orderDetails)
|
||||
{
|
||||
// 判断物料是否存在,不存在则创建
|
||||
if (!string.IsNullOrWhiteSpace(item.InvCode))
|
||||
{
|
||||
var existingMaterial = existingMaterials.FirstOrDefault(m => m.MaterialCode == item.InvCode);
|
||||
if (existingMaterial == null)
|
||||
{
|
||||
// 检查是否已在待新增列表中
|
||||
if (!newMaterials.Any(m => m.MaterialCode == item.InvCode))
|
||||
{
|
||||
// 物料不存在,创建新物料
|
||||
var newMaterial = new Material
|
||||
{
|
||||
MaterialCode = item.InvCode,
|
||||
MaterialName = item.InvName,
|
||||
MaterialSpec = item.InvStd,
|
||||
MaterialType = item.InvDefine1, // 图号
|
||||
Qty = 0,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo?.ITCode ?? "系统"
|
||||
};
|
||||
newMaterials.Add(newMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var detail = new ReceiptDetail
|
||||
{
|
||||
HeaderId = header.ID,
|
||||
SourceCode = header.SourceCode,
|
||||
MaterialCode = item.InvCode,
|
||||
MaterialType = item.InvDefine1, // 图号
|
||||
MaterialName = item.InvName,
|
||||
Lot = item.MoDetailId, // 明细id
|
||||
MaterialSpec = item.InvStd,
|
||||
Qty = item.Qty,
|
||||
CompletedQty = 0,
|
||||
Status = ReceiptStatusEnum.新建,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo?.ITCode ?? "系统",
|
||||
UpdateVersion = 1
|
||||
};
|
||||
|
||||
details.Add(detail);
|
||||
|
||||
// 保存工序路线到 MaterialProcess 表
|
||||
if (item.ProcessRoute != null && item.ProcessRoute.Count > 0)
|
||||
{
|
||||
await SaveProcessRoute(unitWork, item.InvCode, item.ProcessRoute);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量新增物料
|
||||
if (newMaterials.Count > 0)
|
||||
{
|
||||
unitWork.BatchAdd(newMaterials);
|
||||
}
|
||||
|
||||
unitWork.BatchAdd(details);
|
||||
|
||||
Wtm.DoLog("保存订单数据", ActionLogTypesEnum.Normal, "ProcessOrderData",
|
||||
request: $"订单号:{moCode}",
|
||||
result: $"成功创建入库单 {header.Code},明细 {details.Count} 条");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 订单已存在,更新数据
|
||||
existingHeader.TotalQty = orderDetails.Sum(x => x.Qty);
|
||||
existingHeader.TotalLines = orderDetails.Count;
|
||||
existingHeader.Remark = orderDetails.First().Memo;
|
||||
existingHeader.UpdateVersion++;
|
||||
existingHeader.UpdateTime = DateTime.Now;
|
||||
existingHeader.UpdateBy = Wtm.LoginUserInfo?.ITCode ?? "系统";
|
||||
unitWork.Update(existingHeader);
|
||||
|
||||
// 更新明细
|
||||
var oldDetails = unitWork.Find<ReceiptDetail>(d => d.HeaderId == existingHeader.ID).ToList();
|
||||
|
||||
// 获取订单明细中的所有物料编码
|
||||
var invCodes = orderDetails
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.InvCode))
|
||||
.Select(x => x.InvCode)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// 一次性查询本地数据库中已存在的物料(优化性能)
|
||||
var existingMaterials = unitWork.Find<Material>(m => invCodes.Contains(m.MaterialCode))
|
||||
.ToList();
|
||||
|
||||
// 待新增的物料列表
|
||||
var newMaterials = new List<Material>();
|
||||
|
||||
var newDetails = new List<ReceiptDetail>();
|
||||
foreach (var item in orderDetails)
|
||||
{
|
||||
// 判断明细是否存在 用MoDetailId 判断
|
||||
if (!oldDetails.Any(x => x.Lot == item.MoDetailId))
|
||||
{
|
||||
// 判断物料是否存在,不存在则创建
|
||||
if (!string.IsNullOrWhiteSpace(item.InvCode))
|
||||
{
|
||||
var existingMaterial = existingMaterials.FirstOrDefault(m => m.MaterialCode == item.InvCode);
|
||||
if (existingMaterial == null)
|
||||
{
|
||||
// 检查是否已在待新增列表中
|
||||
if (!newMaterials.Any(m => m.MaterialCode == item.InvCode))
|
||||
{
|
||||
// 物料不存在,创建新物料
|
||||
var newMaterial = new Material
|
||||
{
|
||||
MaterialCode = item.InvCode,
|
||||
MaterialName = item.InvName,
|
||||
MaterialSpec = item.InvStd,
|
||||
MaterialType = item.InvDefine1, // 图号
|
||||
Qty = 0,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo?.ITCode ?? "系统"
|
||||
};
|
||||
newMaterials.Add(newMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var detail = new ReceiptDetail
|
||||
{
|
||||
HeaderId = existingHeader.ID,
|
||||
SourceCode = existingHeader.SourceCode,
|
||||
MaterialCode = item.InvCode,
|
||||
MaterialType = item.InvDefine1, // 图号
|
||||
MaterialName = item.InvName,
|
||||
Lot = item.MoDetailId, // 明细id
|
||||
MaterialSpec = item.InvStd,
|
||||
Qty = item.Qty,
|
||||
CompletedQty = 0,
|
||||
Status = ReceiptStatusEnum.新建,
|
||||
Batch = item.Version,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo?.ITCode ?? "系统",
|
||||
UpdateVersion = 1
|
||||
};
|
||||
|
||||
newDetails.Add(detail);
|
||||
|
||||
// 更新工序路线
|
||||
if (item.ProcessRoute != null && item.ProcessRoute.Count > 0)
|
||||
{
|
||||
await SaveProcessRoute(unitWork, item.InvCode, item.ProcessRoute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量新增物料
|
||||
if (newMaterials.Count > 0)
|
||||
{
|
||||
unitWork.BatchAdd(newMaterials);
|
||||
}
|
||||
|
||||
unitWork.BatchAdd(newDetails);
|
||||
|
||||
Wtm.DoLog("更新订单数据", ActionLogTypesEnum.Normal, "ProcessOrderData",
|
||||
request: $"订单号:{moCode}",
|
||||
result: $"成功更新入库单 {existingHeader.Code},新增明细 {newDetails.Count} 条");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存工序路线到 MaterialProcess 表
|
||||
/// </summary>
|
||||
private async Task SaveProcessRoute(IUnitWork unitWork, string materialCode, List<ProcessRouteItem> processRoute)
|
||||
{
|
||||
// 查询已存在的工序路线
|
||||
var existingProcesses = unitWork.Find<MaterialProcess>(p => p.MaterialCode == materialCode).ToList();
|
||||
|
||||
// 待新增的工序
|
||||
var processesToAdd = new List<MaterialProcess>();
|
||||
// 待更新的工序
|
||||
var processesToUpdate = new List<MaterialProcess>();
|
||||
|
||||
var processConfigs = unitWork.Find<ProcessConfig>(x => x.Code != "").ToList();
|
||||
// 遍历新的工序路线
|
||||
foreach (var route in processRoute)
|
||||
{
|
||||
// 检查工艺是否存在于ProcessConfig中,不存在则添加
|
||||
var processConfig = processConfigs.Any(p => p.Code == route.ProcessCode);
|
||||
if (!processConfig)
|
||||
{
|
||||
unitWork.Add(new ProcessConfig
|
||||
{
|
||||
Code = route.ProcessCode,
|
||||
Name = route.ProcessName,
|
||||
Zone = "Zone2",
|
||||
Port = "EnterExit_P2005"
|
||||
});
|
||||
}
|
||||
|
||||
// 查找是否存在相同工序名称的记录
|
||||
var existing = existingProcesses.FirstOrDefault(p =>
|
||||
p.ProcessName == route.ProcessName);
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
// 已存在,检查是否需要更新
|
||||
bool needUpdate = false;
|
||||
|
||||
if (existing.ProcessCode != route.ProcessCode || existing.ProcessOrder != route.Sort)
|
||||
{
|
||||
existing.ProcessCode = route.ProcessCode;
|
||||
existing.ProcessOrder = route.Sort;
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
if (!existing.IsActive)
|
||||
{
|
||||
existing.IsActive = true;
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
if (needUpdate)
|
||||
{
|
||||
existing.UpdateTime = DateTime.Now;
|
||||
existing.UpdateBy = Wtm.LoginUserInfo?.ITCode ?? "系统";
|
||||
processesToUpdate.Add(existing);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 不存在,新增
|
||||
var newProcess = new MaterialProcess
|
||||
{
|
||||
MaterialCode = materialCode,
|
||||
ProcessCode = route.ProcessCode,
|
||||
ProcessName = route.ProcessName,
|
||||
ProcessOrder = route.Sort,
|
||||
Weight = 0,
|
||||
IsActive = true,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo?.ITCode ?? "系统"
|
||||
};
|
||||
processesToAdd.Add(newProcess);
|
||||
}
|
||||
}
|
||||
|
||||
// 查找需要删除的工序(旧的多余的)
|
||||
var processesToDelete = existingProcesses.Where(existing =>
|
||||
!processRoute.Any(route =>
|
||||
route.ProcessName == existing.ProcessName)
|
||||
).ToList();
|
||||
|
||||
// 执行数据库操作
|
||||
if (processesToAdd.Count > 0)
|
||||
{
|
||||
unitWork.BatchAdd(processesToAdd);
|
||||
}
|
||||
|
||||
if (processesToUpdate.Count > 0)
|
||||
{
|
||||
unitWork.BatchUpdate(processesToUpdate);
|
||||
}
|
||||
|
||||
if (processesToDelete.Count > 0)
|
||||
{
|
||||
unitWork.BatchDelete(processesToDelete);
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,37 +42,164 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
#region API Methods
|
||||
|
||||
/// <summary>
|
||||
/// 搜索物料
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> SearchMaterials(string keyword)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
{
|
||||
return Json(new { Code = 200, Data = new object[] { } });
|
||||
}
|
||||
|
||||
// 尝试调用接口获取物料
|
||||
try
|
||||
{
|
||||
var request = new LoadInventoryRequest
|
||||
{
|
||||
ErpCode = "001",
|
||||
InvDefine1 = keyword,
|
||||
Size = 15,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
var apiResult =
|
||||
await Wtm.CallAPI<LoadInventoryResponse>("ERP", "LoadInventory", HttpMethodEnum.POST, request);
|
||||
|
||||
if (apiResult?.Data != null && apiResult.Data.Code == 0)
|
||||
{
|
||||
var materialsList = new List<object>();
|
||||
var newMaterials = new List<Material>();
|
||||
|
||||
// 获取接口返回的所有物料编码
|
||||
var invCodes = apiResult.Data.Data
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.InvCode))
|
||||
.Select(x => x.InvCode)
|
||||
.ToList();
|
||||
|
||||
// 一次性查询本地数据库中已存在的物料(优化性能,避免循环中多次查询)
|
||||
var existingMaterials = _unitWork.Find<Material>(m => invCodes.Contains(m.MaterialCode))
|
||||
.ToList();
|
||||
|
||||
// 遍历接口返回的物料数据
|
||||
foreach (var item in apiResult.Data.Data)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(item.InvCode))
|
||||
continue;
|
||||
|
||||
// 在已查询的列表中查找物料是否存在
|
||||
var existingMaterial =
|
||||
existingMaterials.FirstOrDefault(m => m.MaterialCode == item.InvCode);
|
||||
|
||||
if (existingMaterial == null)
|
||||
{
|
||||
// 物料不存在,新增到数据库
|
||||
var newMaterial = new Material
|
||||
{
|
||||
MaterialCode = item.InvCode,
|
||||
MaterialName = item.InvName,
|
||||
MaterialSpec = item.InvStd,
|
||||
MaterialUnit = item.UnitName,
|
||||
MaterialType = item.InvDefine1, // 永丰图号
|
||||
SupplierCode = item.InvDefine4, // 客户图号
|
||||
Qty = 0, // 默认数量为0
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo?.ITCode ?? "System"
|
||||
};
|
||||
|
||||
newMaterials.Add(newMaterial);
|
||||
|
||||
// 添加到返回列表
|
||||
materialsList.Add(new
|
||||
{
|
||||
MaterialCode = newMaterial.MaterialCode,
|
||||
MaterialName = newMaterial.MaterialName,
|
||||
MaterialSpec = newMaterial.MaterialSpec,
|
||||
MaterialUnit = newMaterial.MaterialUnit,
|
||||
MaterialType = newMaterial.MaterialType,
|
||||
SupplierCode = newMaterial.SupplierCode
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// 物料已存在,添加到返回列表
|
||||
materialsList.Add(new
|
||||
{
|
||||
MaterialCode = existingMaterial.MaterialCode,
|
||||
MaterialName = existingMaterial.MaterialName,
|
||||
MaterialSpec = existingMaterial.MaterialSpec,
|
||||
MaterialUnit = existingMaterial.MaterialUnit,
|
||||
MaterialType = existingMaterial.MaterialType,
|
||||
SupplierCode = existingMaterial.SupplierCode
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 保存新增的物料
|
||||
_unitWork.BatchAdd(newMaterials);
|
||||
|
||||
// 返回物料列表到前端
|
||||
return Json(new { Code = 200, Data = materialsList });
|
||||
}
|
||||
}
|
||||
catch (System.Exception apiEx)
|
||||
{
|
||||
// 接口调用失败,记录日志
|
||||
Wtm.DoLog("获取ERP物料数据", ActionLogTypesEnum.Normal, "SearchMaterials",
|
||||
request: $"接口调用失败,改用本地数据库查询:{apiEx.Message}",
|
||||
result: "接口调用失败,改用本地数据库查询");
|
||||
}
|
||||
|
||||
// 接口连接失败或返回错误,从本地数据库查询
|
||||
var localMaterials = _unitWork.Find<Material>
|
||||
(m => m.MaterialCode.Contains(keyword)
|
||||
|| m.MaterialName.Contains(keyword)
|
||||
|| m.MaterialType.Contains(keyword))
|
||||
.Select(m => new
|
||||
{
|
||||
MaterialCode = m.MaterialCode,
|
||||
MaterialName = m.MaterialName,
|
||||
MaterialSpec = m.MaterialSpec,
|
||||
MaterialUnit = m.MaterialUnit,
|
||||
MaterialType = m.MaterialType,
|
||||
SupplierCode = m.SupplierCode
|
||||
})
|
||||
.Take(15)
|
||||
.ToList();
|
||||
|
||||
return Json(new { Code = 200, Data = localMaterials });
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"搜索物料失败:{ex.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetOperators()
|
||||
{
|
||||
var users = _unitWork.Find<FrameworkUser>(x => x.ITCode != "Admin")
|
||||
.Select(x => new {x.ITCode,x.Name})
|
||||
.Select(x => new
|
||||
{
|
||||
value = x.ITCode,
|
||||
label = x.Name
|
||||
})
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = users});
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult GetProcesses()
|
||||
{
|
||||
try
|
||||
{
|
||||
var processes = _unitWork.Find<MaterialProcess>(x => x.IsActive)
|
||||
.OrderBy(x => x.ProcessOrder)
|
||||
.Select(x => new {
|
||||
value = x.ID.ToString(),
|
||||
label = x.ProcessName,
|
||||
processCode = x.ProcessCode,
|
||||
processName = x.ProcessName
|
||||
})
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = processes });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"获取工序列表失败:{ex.Message}" });
|
||||
}
|
||||
return Json(new { Code = 200, Data = users });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取物料的工序列表
|
||||
/// </summary>
|
||||
/// <param name="materialCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetProcessesByMaterial(string materialCode)
|
||||
{
|
||||
@@ -85,8 +212,9 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
var processes = _unitWork.Find<MaterialProcess>(x => x.MaterialCode == materialCode && x.IsActive)
|
||||
.OrderBy(x => x.ProcessOrder)
|
||||
.Select(x => new {
|
||||
value = x.ID.ToString(),
|
||||
.Select(x => new
|
||||
{
|
||||
value = x.ID.ToString(),
|
||||
label = x.ProcessName,
|
||||
processCode = x.ProcessCode,
|
||||
processName = x.ProcessName
|
||||
@@ -100,33 +228,37 @@ namespace HHWMS.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult GetOperatorInfo()
|
||||
{
|
||||
var users = _unitWork.Find<FrameworkUser>(x => x.ITCode != "Admin")
|
||||
.Select(x => new {x.ITCode,x.Name})
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = users});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取物料的单据信息
|
||||
/// </summary>
|
||||
/// <param name="materialCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetOrdersByMaterial(string materialCode)
|
||||
{
|
||||
// TODO: 根据物料码查询相关生产订单
|
||||
var orders = new List<object>
|
||||
{
|
||||
new { value = "1", label = "生产订单1" },
|
||||
new { value = "2", label = "生产订单2" }
|
||||
};
|
||||
// 查询包含这个物料的入库单单号
|
||||
|
||||
var orders = _unitWork.Find<ReceiptDetail>(x => x.MaterialCode == materialCode)
|
||||
.Select(x => new
|
||||
{
|
||||
value = x.Lot,
|
||||
label = x.SourceCode,
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Json(new { Code = 200, Data = orders });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取托盘类型信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Public]
|
||||
[HttpGet]
|
||||
public IActionResult GetTrayTypes()
|
||||
{
|
||||
var containerconfig = _unitWork.Find<SysDictData>(x => x.DictType == "ContainerConfig"
|
||||
&& x.DictLabelUs.ToLower() != "container")
|
||||
&& x.DictLabelUs.ToLower() != "container")
|
||||
.Select(x => new
|
||||
{
|
||||
value = x.ID,
|
||||
@@ -136,32 +268,43 @@ namespace HHWMS.Web.Controllers
|
||||
return Json(new { Code = 200, Data = containerconfig });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上架入库
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult SubmitReceipt([FromBody] ReceiptInModel model)
|
||||
{
|
||||
if (_unitWork.IsExit<TaskHeader>(x => x.ContainerCode == model.PalletCode))
|
||||
{
|
||||
return JsonMore(null, 500, $"库内已存在托盘编码为 {model.PalletCode} 的任务!");
|
||||
}
|
||||
|
||||
// 获取物料信息
|
||||
var material = _unitWork.FindSingle<Material>(m => m.MaterialCode == model.MaterialCode);
|
||||
if (material == null)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "物料不存在" });
|
||||
}
|
||||
|
||||
if (material.Qty == null || material.Qty <= 0)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "物料毛重没有设置,请设置后再执行入库" });
|
||||
}
|
||||
|
||||
|
||||
// 获取容器信息
|
||||
var container = _unitWork.FindSingle<Container>(c => c.Code == model.PalletCode);
|
||||
if (container == null)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "容器不存在" });
|
||||
}
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(container.LocationCode))
|
||||
{
|
||||
return Json(new { Code = 400, Msg = $"{container.Code} 容器状态不正确!已存在任务或者已在库内" });
|
||||
}
|
||||
|
||||
|
||||
var materialProcessList = _unitWork.Find<MaterialProcess>(m => m.MaterialCode == material.MaterialCode);
|
||||
|
||||
var materialProcess = _unitWork.FindSingle<MaterialProcess>(m => m.ID == model.ProcessId);
|
||||
@@ -169,7 +312,7 @@ namespace HHWMS.Web.Controllers
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "未找到此物料工序配置" });
|
||||
}
|
||||
|
||||
|
||||
// 下一道工序
|
||||
var nextProcess = materialProcessList
|
||||
// 筛选同一物料
|
||||
@@ -180,25 +323,26 @@ namespace HHWMS.Web.Controllers
|
||||
.OrderBy(p => p.ProcessOrder)
|
||||
// 取第一个(下一道工序)
|
||||
.FirstOrDefault();
|
||||
|
||||
|
||||
// 从字典查询工序对应的区域
|
||||
var zoneName = _unitWork.FindSingle<ProcessConfig>(x =>
|
||||
var zoneName = _unitWork.FindSingle<ProcessConfig>(x =>
|
||||
x.Code == nextProcess.ProcessCode)?.Zone;
|
||||
|
||||
if (string.IsNullOrEmpty(zoneName))
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "未找到此工序对应区域配置" });
|
||||
}
|
||||
|
||||
|
||||
// 1. 查找可用库位信息
|
||||
var locationVm = Wtm.CreateVM<LocationVM>();
|
||||
var locationCode = locationVm.GetEmptyLocationFromXb(_materialZones[zoneName].BeginLine, _materialZones[zoneName].EndLine);
|
||||
|
||||
var locationCode =
|
||||
locationVm.GetEmptyLocationFromXb(_materialZones[zoneName].BeginLine, _materialZones[zoneName].EndLine);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(locationCode))
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "未找到可用的空仓位" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 使用事务
|
||||
using (var tran = DC.BeginTransaction())
|
||||
{
|
||||
@@ -235,13 +379,15 @@ namespace HHWMS.Web.Controllers
|
||||
MaterialSpec = material.MaterialSpec,
|
||||
MaterialUnit = material.MaterialUnit,
|
||||
SupplierCode = material.SupplierCode,
|
||||
SourceCode = model.SourceCode,
|
||||
SourceCode = model.OrderId, // 单号
|
||||
ReceiptDetailId = model.SourceCode, // erpdetailid 回传使用
|
||||
BatchCode = materialProcess.ProcessCode, //erp回传使用 批次编码
|
||||
Batch = materialProcess.ProcessName,
|
||||
Lot = nextProcess?.ProcessName,
|
||||
Status = model.IsQualified ? "合格" : "不合格",
|
||||
TaskStatus = InventoryTaskStatusEnum.Locked,
|
||||
TaskQty = model.Qty,//小托盘数量
|
||||
Flag = model.Type,//小托盘类型
|
||||
TaskQty = model.Qty, //小托盘数量
|
||||
Flag = model.Type, //小托盘类型
|
||||
CreateBy = model.OperatorId,
|
||||
ReceiptCode = model.OperatorInfo, //校验员
|
||||
CreateTime = DateTime.Now
|
||||
@@ -257,8 +403,9 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
// 从数据库中重新获取库位实体,避免实体跟踪冲突
|
||||
var locationToUpdate = _unitWork.FindSingle<Location>(l => l.Code == locationCode);
|
||||
|
||||
var resultNum = _unitWork.BatchUpdate<Location>(x => x.Code == locationCode && x.Version == locationToUpdate.Version,
|
||||
|
||||
var resultNum = _unitWork.BatchUpdate<Location>(
|
||||
x => x.Code == locationCode && x.Version == locationToUpdate.Version,
|
||||
x => new Location()
|
||||
{
|
||||
Status = LocationStatusEnum.锁定,
|
||||
@@ -268,12 +415,12 @@ namespace HHWMS.Web.Controllers
|
||||
UpdateBy = "WMS",
|
||||
Version = Guid.NewGuid()
|
||||
});
|
||||
|
||||
|
||||
if (resultNum == 0)
|
||||
{
|
||||
//失败 回滚
|
||||
tran.Rollback();
|
||||
return Json(new { Code = 500, Msg = "更新仓位失败!请重新提交!"});
|
||||
return Json(new { Code = 500, Msg = "更新仓位失败!请重新提交!" });
|
||||
}
|
||||
|
||||
// 6. 调用WCS接口下发任务
|
||||
@@ -288,14 +435,15 @@ namespace HHWMS.Web.Controllers
|
||||
// 调用WCS任务下发接口
|
||||
// tran.Commit();
|
||||
// return Json(new { Code = 200, Msg = "入库成功", Data = new { TaskNo = taskNo } });
|
||||
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
||||
var wcsResult = Wtm
|
||||
.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
||||
|
||||
if (wcsResult != null && wcsResult.Success)
|
||||
{
|
||||
// WCS任务下发成功,提交事务
|
||||
taskHeader.Status = TaskStatusEnum.已下发;
|
||||
_unitWork.Update(taskHeader);
|
||||
|
||||
|
||||
tran.Commit();
|
||||
return Json(new { Code = 200, Msg = "入库成功", Data = new { TaskNo = taskNo } });
|
||||
}
|
||||
@@ -329,16 +477,17 @@ namespace HHWMS.Web.Controllers
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "容器不存在" });
|
||||
}
|
||||
|
||||
|
||||
// 1. 查找可用库位信息
|
||||
var locationVm = Wtm.CreateVM<LocationVM>();
|
||||
var locationCode = locationVm.GetEmptyLocationFromXb(_materialZones["Zone1"].BeginLine, _materialZones["Zone1"].EndLine);
|
||||
|
||||
var locationCode =
|
||||
locationVm.GetEmptyLocationFromXb(_materialZones["Zone1"].BeginLine, _materialZones["Zone1"].EndLine);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(locationCode))
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "未找到可用的空仓位" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 使用事务
|
||||
using (var tran = DC.BeginTransaction())
|
||||
{
|
||||
@@ -363,7 +512,7 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
_unitWork.Add(taskHeader);
|
||||
|
||||
|
||||
|
||||
// 5. 锁定容器和库位
|
||||
container.IsLock = ContainerLockEnum.任务锁;
|
||||
container.LocationCode = locationCode;
|
||||
@@ -372,8 +521,9 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
// 从数据库中重新获取库位实体,避免实体跟踪冲突
|
||||
var locationToUpdate = _unitWork.FindSingle<Location>(l => l.Code == locationCode);
|
||||
|
||||
var resultNum = _unitWork.BatchUpdate<Location>(x => x.Code == locationCode && x.Version == locationToUpdate.Version,
|
||||
|
||||
var resultNum = _unitWork.BatchUpdate<Location>(
|
||||
x => x.Code == locationCode && x.Version == locationToUpdate.Version,
|
||||
x => new Location()
|
||||
{
|
||||
Status = LocationStatusEnum.锁定,
|
||||
@@ -383,12 +533,12 @@ namespace HHWMS.Web.Controllers
|
||||
UpdateBy = "WMS",
|
||||
Version = Guid.NewGuid()
|
||||
});
|
||||
|
||||
|
||||
if (resultNum == 0)
|
||||
{
|
||||
//失败 回滚
|
||||
tran.Rollback();
|
||||
return Json(new { Code = 500, Msg = "更新仓位失败!请重新提交!"});
|
||||
return Json(new { Code = 500, Msg = "更新仓位失败!请重新提交!" });
|
||||
}
|
||||
|
||||
// 6. 调用WCS接口下发任务
|
||||
@@ -401,7 +551,8 @@ namespace HHWMS.Web.Controllers
|
||||
};
|
||||
|
||||
// 调用WCS任务下发接口
|
||||
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
||||
var wcsResult = Wtm
|
||||
.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
||||
|
||||
if (wcsResult != null && wcsResult.Success)
|
||||
{
|
||||
@@ -422,7 +573,8 @@ namespace HHWMS.Web.Controllers
|
||||
tran.Rollback();
|
||||
return Json(new { Code = 500, Msg = ex.Message });
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 空托盘出库
|
||||
@@ -436,18 +588,18 @@ namespace HHWMS.Web.Controllers
|
||||
&& !string.IsNullOrEmpty(x.LocationCode));
|
||||
if (container == null)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "库内不存在可用空容器!"} );
|
||||
return Json(new { Code = 500, Msg = "库内不存在可用空容器!" });
|
||||
}
|
||||
|
||||
|
||||
//创建出库任务
|
||||
var location = _unitWork.FindSingle<Location>(x => x.Code == container.LocationCode);
|
||||
|
||||
var outPort = _unitWork.FindSingle<ProcessConfig>(x => x.Code == "00")?.Port;
|
||||
if (string.IsNullOrEmpty(outPort))
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "未配置空托盘出库口,请配置后重新呼叫出库任务!"} );
|
||||
return Json(new { Code = 500, Msg = "未配置空托盘出库口,请配置后重新呼叫出库任务!" });
|
||||
}
|
||||
|
||||
|
||||
var task = new TaskHeader()
|
||||
{
|
||||
ZoneId = location.ZoneId,
|
||||
@@ -458,12 +610,12 @@ namespace HHWMS.Web.Controllers
|
||||
ToLocation = outPort,
|
||||
Status = TaskStatusEnum.新建
|
||||
};
|
||||
|
||||
|
||||
var vm = Wtm.CreateVM<LocationVM>();
|
||||
var result = vm.SendWcsTask(task);
|
||||
if (!result.Status)
|
||||
{
|
||||
return Json(new { Code = 500, Msg =result.Message});
|
||||
return Json(new { Code = 500, Msg = result.Message });
|
||||
}
|
||||
|
||||
location.Status = LocationStatusEnum.锁定;
|
||||
@@ -475,38 +627,6 @@ namespace HHWMS.Web.Controllers
|
||||
_unitWork.Update(container);
|
||||
return Json(new { Code = 200, Msg = "提交成功" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索物料
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public IActionResult SearchMaterials(string keyword)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
{
|
||||
return Json(new { Code = 200, Data = new object[] { } });
|
||||
}
|
||||
|
||||
var materials = _unitWork.Find<Material>
|
||||
(m => m.MaterialCode.Contains(keyword) || m.MaterialName.Contains(keyword))
|
||||
.Select(m => new
|
||||
{
|
||||
MaterialCode = m.MaterialCode,
|
||||
m.MaterialType,
|
||||
MaterialName = m.MaterialName
|
||||
})
|
||||
.Take(10)
|
||||
.ToList();
|
||||
|
||||
return Json(new { Code = 200, Data = materials });
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"搜索物料失败:{ex.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion API Methods
|
||||
}
|
||||
@@ -525,7 +645,7 @@ namespace HHWMS.Web.Controllers
|
||||
public bool IsQualified { get; set; }
|
||||
public string OperatorInfo { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class LineRange
|
||||
{
|
||||
public int BeginLine { get; set; }
|
||||
|
||||
@@ -215,6 +215,10 @@ namespace HHWMS.Web.Controllers
|
||||
return JsonMore(null, 500, "容器编码为空!");
|
||||
}
|
||||
|
||||
if (_unitWork.IsExit<TaskHeader>(x => x.ContainerCode == containerCode))
|
||||
{
|
||||
return JsonMore(null, 500, $"库内已存在托盘编码为 {containerCode} 的任务!");
|
||||
}
|
||||
// 查询容器
|
||||
var container = _unitWork.FindSingle<Container>(u => u.Code == containerCode);
|
||||
if (container == null)
|
||||
|
||||
Reference in new issue
Block a user