fix:永丰售后修复BUG,
1,物料库存获取不到ERP:重新调整触发查询逻辑 2,工序变更导致物料无法出库:配置旧工序 3,测试出库订单ERP推送,任务下发
This commit is contained in:
1 parent
b2a9a38f38
commit
c76e7bb681
69 files changed
+5510
-157
No files matched your search
@@ -0,0 +1,358 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
using HHWMS.Web.Services.Agv;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 平库任务手动下发页(方案 9.1 页面路径)
|
||||
/// 页面参数与 Receive 接单接口保持一致,共用 AgvTaskService.CreateTaskAsync 同一套创建逻辑
|
||||
/// </summary>
|
||||
[Area("agv")]
|
||||
[ActionDescription("AGV任务")]
|
||||
public partial class AgvTaskController : BaseController
|
||||
{
|
||||
private readonly IUnitWork _unitWork;
|
||||
private readonly AgvTaskService _taskService;
|
||||
|
||||
public AgvTaskController(IUnitWork unitWork, AgvTaskService taskService)
|
||||
{
|
||||
_unitWork = unitWork;
|
||||
_taskService = taskService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务号请求参数(下发/取消/重试完成共用)
|
||||
/// 普通 Controller 的简单类型参数不会从 JSON body 绑定,必须用 [FromBody] 对象接收
|
||||
/// </summary>
|
||||
public class TaskNoRequest
|
||||
{
|
||||
public string TaskNo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务列表 + 手动下发页(WTM 标准 searchpanel + grid,风格与场景配置页统一)
|
||||
/// </summary>
|
||||
[ActionDescription("Sys.Search")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskListVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WTM grid 数据源(多条件查询,由 AgvTaskListVM 统一处理)
|
||||
/// </summary>
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost]
|
||||
public string Search(AgvTaskSearcher searcher)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskListVM>(passInit: true);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
vm.Searcher = searcher;
|
||||
return vm.GetJson(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return vm.GetError();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动下发表单页(Dialog 内 Vue 渲染,提交走下方 POST Create)
|
||||
/// 必须传入 AgvTaskListVM 类型 model,与 Create.cshtml 的 @model 保持一致,
|
||||
/// 否则 WTM 无参 PartialView() 会注入 BaseVM 导致视图类型不匹配异常
|
||||
/// 场景选项由服务端直接查库(AgvTaskSceneConfig)注入页面,前端不再依赖异步接口加载
|
||||
/// </summary>
|
||||
[ActionDescription("Sys.Create")]
|
||||
public ActionResult Create()
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskListVM>();
|
||||
// 与 GetScenes 同一套查库逻辑:直接读取场景配置表全量数据
|
||||
var scenes = DC.Set<AgvTaskSceneConfig>()
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.AgvTaskType)
|
||||
.Select(x => new { value = x.SourceTaskType, label = string.IsNullOrWhiteSpace(x.SceneName) ? x.SourceTaskType : x.SceneName })
|
||||
.ToList();
|
||||
ViewBag.ScenesJson = JsonSerializer.Serialize(scenes);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 场景配置下拉(公开访问,绕过模块权限校验)
|
||||
/// 展示 AgvTaskSceneConfig.SceneName,内部传 SourceTaskType
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Public]
|
||||
public IActionResult GetScenes()
|
||||
{
|
||||
// 走原生 SQL 直捞,绕过 UnitWork 可能的数据权限过滤
|
||||
var sql = @"SELECT * FROM AgvTaskSceneConfig ORDER BY AgvTaskType";
|
||||
var scenes = DC.Set<AgvTaskSceneConfig>()
|
||||
.FromSqlRaw(sql)
|
||||
.AsNoTracking()
|
||||
.ToList()
|
||||
.Select(x => new
|
||||
{
|
||||
value = x.SourceTaskType,
|
||||
label = string.IsNullOrWhiteSpace(x.SceneName) ? x.SourceTaskType : x.SceneName
|
||||
})
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = scenes });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 点位下拉(起点/终点强制校验,Type=P 且未停用)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public IActionResult GetPoints()
|
||||
{
|
||||
var points = _unitWork.Find<Location>(x => x.Type == LocationTypeEnum.P && !x.IsStop).ToList();
|
||||
var zoneIds = points.Where(p => p.ZoneId != 0).Select(p => p.ZoneId).Distinct().ToList();
|
||||
var zoneFloors = zoneIds.Count > 0
|
||||
? _unitWork.Find<LocationZone>(z => zoneIds.Contains(z.ID))
|
||||
.ToDictionary(z => z.ID, z => z.Floor)
|
||||
: new Dictionary<int, int?>();
|
||||
var data = points.OrderBy(p => p.Code)
|
||||
.Select(p => new
|
||||
{
|
||||
value = p.Code,
|
||||
label = p.Code,
|
||||
floor = zoneFloors.TryGetValue(p.ZoneId, out var f) ? f : (int?)null
|
||||
})
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = data });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 物料搜索(SKU 非强制,带明细则需本地存在/ERP补建)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public IActionResult GetMaterials(string keyword)
|
||||
{
|
||||
var query = _unitWork.Find<Material>(m => string.IsNullOrWhiteSpace(keyword)
|
||||
|| m.MaterialCode.Contains(keyword)
|
||||
|| m.MaterialName.Contains(keyword));
|
||||
var materials = query.OrderBy(m => m.MaterialCode)
|
||||
.Take(15)
|
||||
.Select(m => new
|
||||
{
|
||||
MaterialCode = m.MaterialCode,
|
||||
MaterialName = m.MaterialName,
|
||||
MaterialSpec = m.MaterialSpec,
|
||||
MaterialUnit = m.MaterialUnit
|
||||
})
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = materials });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动下发创建:参数与 Receive 接单接口一致(起点/终点/任务场景必填,容器/明细可选)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] AgvReceiveRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
return Json(new { Code = 400, Msg = "请求体为空" });
|
||||
}
|
||||
var task = await _taskService.CreateTaskAsync(request);
|
||||
return Json(new { Code = 200, Msg = $"任务[{task.TaskNo}]创建成功" });
|
||||
}
|
||||
catch (AgvBizException ex)
|
||||
{
|
||||
return Json(new { Code = 400, Msg = ex.Message });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"创建失败: {ex.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务列表查询参数(多条件:任务号/起终点/容器/来源模糊,状态精确)
|
||||
/// </summary>
|
||||
public class GetTasksRequest
|
||||
{
|
||||
public string TaskNo { get; set; }
|
||||
public string FromLocation { get; set; }
|
||||
public string ToLocation { get; set; }
|
||||
public string ContainerCode { get; set; }
|
||||
public string SourceSystem { get; set; }
|
||||
public int? AgvStatus { get; set; }
|
||||
/// <summary>页码(从 1 开始,默认 1)</summary>
|
||||
public int Page { get; set; }
|
||||
/// <summary>每页条数(默认 10)</summary>
|
||||
public int Size { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务列表(多条件模糊查询 + 分页,供原生表格页面直调)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public IActionResult GetTasks([FromBody] GetTasksRequest request)
|
||||
{
|
||||
var page = request != null && request.Page > 0 ? request.Page : 1;
|
||||
var size = request != null && request.Size > 0 ? request.Size : 10;
|
||||
var query = _unitWork.Find<AgvTask>(x => x.CreateTime != null);
|
||||
if (request != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(request.TaskNo))
|
||||
{
|
||||
query = query.Where(x => x.TaskNo.Contains(request.TaskNo.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(request.FromLocation))
|
||||
{
|
||||
query = query.Where(x => x.FromLocation.Contains(request.FromLocation.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(request.ToLocation))
|
||||
{
|
||||
query = query.Where(x => x.ToLocation.Contains(request.ToLocation.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(request.ContainerCode))
|
||||
{
|
||||
query = query.Where(x => x.ContainerCode.Contains(request.ContainerCode.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(request.SourceSystem))
|
||||
{
|
||||
query = query.Where(x => x.SourceSystem == request.SourceSystem.Trim());
|
||||
}
|
||||
if (request.AgvStatus.HasValue)
|
||||
{
|
||||
query = query.Where(x => (int)x.AgvStatus == request.AgvStatus.Value);
|
||||
}
|
||||
}
|
||||
var total = query.Count();
|
||||
var tasks = query
|
||||
.OrderByDescending(x => x.CreateTime)
|
||||
.Skip((page - 1) * size)
|
||||
.Take(size)
|
||||
.Select(x => new
|
||||
{
|
||||
TaskNo = x.TaskNo,
|
||||
// 输出数字状态(0/5/10/90/95/99/100),前端按数字映射中文并判断按钮可用性
|
||||
AgvStatus = x.AgvStatus == null ? 0 : (int)x.AgvStatus,
|
||||
// 状态中文名(枚举成员名即中文:新建/已下发/...),前端直接展示,零解析成本
|
||||
AgvStatusName = x.AgvStatus.ToString(),
|
||||
// 任务场景名:按 AgvTaskType 关联场景配置表(未配置则留空)
|
||||
SceneName = x.AgvTaskType == null ? "" :
|
||||
DC.Set<AgvTaskSceneConfig>()
|
||||
.Where(c => c.AgvTaskType == x.AgvTaskType)
|
||||
.Select(c => c.SceneName)
|
||||
.FirstOrDefault() ?? "",
|
||||
FromLocation = x.FromLocation,
|
||||
ToLocation = x.ToLocation,
|
||||
ContainerCode = x.ContainerCode,
|
||||
SourceSystem = x.SourceSystem,
|
||||
ErrorMsg = x.ErrorMsg,
|
||||
CreateTime = x.CreateTime
|
||||
})
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = new { List = tasks, Total = total, Page = page, Size = size } });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 来源系统下拉(已有任务的 SourceSystem 去重列表)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public IActionResult GetSourceSystems()
|
||||
{
|
||||
var list = _unitWork.Find<AgvTask>(x => x.SourceSystem != null && x.SourceSystem != "")
|
||||
.Select(x => x.SourceSystem)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
return Json(new { Code = 200, Data = list });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下发任务(仅新建/异常可下发)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Dispatch([FromBody] TaskNoRequest request)
|
||||
{
|
||||
var taskNo = request?.TaskNo;
|
||||
if (string.IsNullOrWhiteSpace(taskNo))
|
||||
{
|
||||
return Json(new { Code = 400, Msg = "任务号不能为空" });
|
||||
}
|
||||
try
|
||||
{
|
||||
await _taskService.DispatchTaskAsync(taskNo);
|
||||
return Json(new { Code = 200, Msg = $"任务[{taskNo}]已下发" });
|
||||
}
|
||||
catch (AgvBizException ex)
|
||||
{
|
||||
return Json(new { Code = 400, Msg = ex.Message });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"下发失败: {ex.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消任务(仅新建/已下发/执行中可取消)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Cancel([FromBody] TaskNoRequest request)
|
||||
{
|
||||
var taskNo = request?.TaskNo;
|
||||
if (string.IsNullOrWhiteSpace(taskNo))
|
||||
{
|
||||
return Json(new { Code = 400, Msg = "任务号不能为空" });
|
||||
}
|
||||
try
|
||||
{
|
||||
await _taskService.CancelTaskAsync(taskNo);
|
||||
return Json(new { Code = 200, Msg = $"任务[{taskNo}]已取消" });
|
||||
}
|
||||
catch (AgvBizException ex)
|
||||
{
|
||||
return Json(new { Code = 400, Msg = ex.Message });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"取消失败: {ex.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重试完成联动(仅完成联动失败(99)可重试)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> RetryFinish([FromBody] TaskNoRequest request)
|
||||
{
|
||||
var taskNo = request?.TaskNo;
|
||||
if (string.IsNullOrWhiteSpace(taskNo))
|
||||
{
|
||||
return Json(new { Code = 400, Msg = "任务号不能为空" });
|
||||
}
|
||||
try
|
||||
{
|
||||
await _taskService.RetryFinishLinkAsync(taskNo);
|
||||
return Json(new { Code = 200, Msg = $"任务[{taskNo}]联动重试成功" });
|
||||
}
|
||||
catch (AgvBizException ex)
|
||||
{
|
||||
return Json(new { Code = 400, Msg = ex.Message });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"联动重试失败: {ex.Message}" });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务日志页(只读:状态变更 + 报文留痕,来源 AgvTaskLog 表)
|
||||
/// </summary>
|
||||
[Area("agv")]
|
||||
[ActionDescription("AGV日志")]
|
||||
public partial class AgvTaskLogController : BaseController
|
||||
{
|
||||
#region Search
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskLogListVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost]
|
||||
public string Search(AgvTaskLogSearcher searcher)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskLogListVM>(passInit: true);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
vm.Searcher = searcher;
|
||||
return vm.GetJson(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return vm.GetError();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Search
|
||||
|
||||
#region Details
|
||||
|
||||
[ActionDescription("Sys.Details")]
|
||||
public ActionResult Details(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskLogVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
#endregion Details
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using HHWMS.Web.Models.Agv;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务场景配置管理页(映射上游任务类型 → AGV 场景,方案 5.6)
|
||||
/// </summary>
|
||||
[Area("agv")]
|
||||
[ActionDescription("AGV场景配置")]
|
||||
public partial class AgvTaskSceneConfigController : BaseController
|
||||
{
|
||||
#region Search
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskSceneConfigListVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost]
|
||||
public string Search(AgvTaskSceneConfigSearcher searcher)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskSceneConfigListVM>(passInit: true);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
vm.Searcher = searcher;
|
||||
return vm.GetJson(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return vm.GetError();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Search
|
||||
|
||||
#region Create
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
public ActionResult Create()
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskSceneConfigVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("Sys.Create")]
|
||||
public ActionResult Create(AgvTaskSceneConfigVM vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoAdd();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
vm.DoReInit();
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGrid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Create
|
||||
|
||||
#region Edit
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
public ActionResult Edit(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskSceneConfigVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPost]
|
||||
[ValidateFormItemOnly]
|
||||
public ActionResult Edit(AgvTaskSceneConfigVM vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoEdit();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
vm.DoReInit();
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Edit
|
||||
|
||||
#region Delete
|
||||
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public ActionResult Delete(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskSceneConfigVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Delete")]
|
||||
[HttpPost]
|
||||
public ActionResult Delete(string id, IFormCollection nouse)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskSceneConfigVM>(id);
|
||||
vm.DoDelete();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGrid();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Delete
|
||||
|
||||
#region Details
|
||||
|
||||
[ActionDescription("Sys.Details")]
|
||||
public ActionResult Details(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<AgvTaskSceneConfigVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
#endregion Details
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务日志列表(只读:状态变更 + 报文留痕,来源 AgvTaskLog 表)
|
||||
/// </summary>
|
||||
public partial class AgvTaskLogListVM : BasePagedListVM<AgvTaskLog_View, AgvTaskLogSearcher>
|
||||
{
|
||||
protected override List<GridAction> InitGridAction()
|
||||
{
|
||||
return new List<GridAction>
|
||||
{
|
||||
this.MakeStandardAction("AgvTaskLog", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "agv", dialogWidth: 900),
|
||||
};
|
||||
}
|
||||
|
||||
protected override IEnumerable<IGridColumn<AgvTaskLog_View>> InitGridHeader()
|
||||
{
|
||||
return new List<GridColumn<AgvTaskLog_View>>
|
||||
{
|
||||
this.MakeGridHeader(x => x.TaskNo).SetWidth(170),
|
||||
this.MakeGridHeader(x => x.OrderId).SetWidth(170),
|
||||
this.MakeGridHeader(x => x.FromStatus).SetWidth(90),
|
||||
this.MakeGridHeader(x => x.ToStatus).SetWidth(90),
|
||||
this.MakeGridHeader(x => x.Event).SetWidth(110),
|
||||
this.MakeGridHeader(x => x.Direction).SetWidth(80),
|
||||
this.MakeGridHeader(x => x.EventTime).SetWidth(150),
|
||||
this.MakeGridHeader(x => x.DurationMs).SetWidth(90),
|
||||
this.MakeGridHeader(x => x.Operator).SetWidth(90),
|
||||
this.MakeGridHeader(x => x.RequestJson).SetWidth(180),
|
||||
this.MakeGridHeader(x => x.ResponseJson).SetWidth(180),
|
||||
this.MakeGridHeader(x => x.Remark),
|
||||
this.MakeGridHeader(x => x.CreateTime).SetWidth(150),
|
||||
this.MakeGridHeaderAction(width: 100)
|
||||
};
|
||||
}
|
||||
|
||||
public override IOrderedQueryable<AgvTaskLog_View> GetSearchQuery()
|
||||
{
|
||||
var query = DC.Set<AgvTaskLog>()
|
||||
.CheckContain(Searcher.TaskNo, x => x.TaskNo)
|
||||
.CheckEqual(Searcher.Direction, x => x.Direction)
|
||||
.CheckContain(Searcher.Event, x => x.Event)
|
||||
.CheckContain(Searcher.RequestJson, x => x.RequestJson)
|
||||
.CheckContain(Searcher.ResponseJson, x => x.ResponseJson)
|
||||
.Select(x => new AgvTaskLog_View
|
||||
{
|
||||
ID = x.ID,
|
||||
TaskNo = x.TaskNo,
|
||||
OrderId = x.OrderId,
|
||||
FromStatus = x.FromStatus,
|
||||
ToStatus = x.ToStatus,
|
||||
Event = x.Event,
|
||||
Direction = x.Direction,
|
||||
EventTime = x.EventTime,
|
||||
DurationMs = x.DurationMs,
|
||||
Operator = x.Operator,
|
||||
RequestJson = x.RequestJson,
|
||||
ResponseJson = x.ResponseJson,
|
||||
Remark = x.Remark,
|
||||
CreateTime = x.CreateTime
|
||||
})
|
||||
.OrderByDescending(x => x.CreateTime);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务日志列表行视图
|
||||
/// </summary>
|
||||
public class AgvTaskLog_View : AgvTaskLog
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务日志搜索条件(只读日志页)
|
||||
/// </summary>
|
||||
public partial class AgvTaskLogSearcher : BaseSearcher
|
||||
{
|
||||
[Display(Name = "AGV.TaskNo")]
|
||||
public string TaskNo { get; set; }
|
||||
|
||||
[Display(Name = "AGV.Direction")]
|
||||
public string Direction { get; set; }
|
||||
|
||||
[Display(Name = "AGV.Event")]
|
||||
public string Event { get; set; }
|
||||
|
||||
/// <summary>请求体(模糊查询)</summary>
|
||||
[Display(Name = "AGV.RequestJson")]
|
||||
public string RequestJson { get; set; }
|
||||
|
||||
/// <summary>响应体(模糊查询)</summary>
|
||||
[Display(Name = "AGV.ResponseJson")]
|
||||
public string ResponseJson { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务日志详情(查看请求/响应报文)
|
||||
/// </summary>
|
||||
public partial class AgvTaskLogVM : BaseCRUDVM<AgvTaskLog>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务场景配置列表(方案 5.6:映射上游任务类型 → AGV 场景)
|
||||
/// </summary>
|
||||
public partial class AgvTaskSceneConfigListVM : BasePagedListVM<AgvTaskSceneConfig_View, AgvTaskSceneConfigSearcher>
|
||||
{
|
||||
protected override List<GridAction> InitGridAction()
|
||||
{
|
||||
return new List<GridAction>
|
||||
{
|
||||
this.MakeStandardAction("AgvTaskSceneConfig", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"], "agv", dialogWidth: 800),
|
||||
this.MakeStandardAction("AgvTaskSceneConfig", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "agv", dialogWidth: 800),
|
||||
this.MakeStandardAction("AgvTaskSceneConfig", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "agv", dialogWidth: 800),
|
||||
this.MakeStandardAction("AgvTaskSceneConfig", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "agv", dialogWidth: 800),
|
||||
};
|
||||
}
|
||||
|
||||
protected override IEnumerable<IGridColumn<AgvTaskSceneConfig_View>> InitGridHeader()
|
||||
{
|
||||
return new List<GridColumn<AgvTaskSceneConfig_View>>
|
||||
{
|
||||
this.MakeGridHeader(x => x.SourceTaskType).SetWidth(150),
|
||||
this.MakeGridHeader(x => x.AgvTaskType).SetWidth(130),
|
||||
this.MakeGridHeader(x => x.SceneId).SetWidth(150),
|
||||
this.MakeGridHeader(x => x.SceneName).SetWidth(180),
|
||||
this.MakeGridHeader(x => x.BinTaskLoad).SetWidth(100),
|
||||
this.MakeGridHeader(x => x.BinTaskUnload).SetWidth(100),
|
||||
this.MakeGridHeader(x => x.Remark),
|
||||
this.MakeGridHeaderAction(width: 200)
|
||||
};
|
||||
}
|
||||
|
||||
public override IOrderedQueryable<AgvTaskSceneConfig_View> GetSearchQuery()
|
||||
{
|
||||
var query = DC.Set<AgvTaskSceneConfig>()
|
||||
.CheckContain(Searcher.SourceTaskType, x => x.SourceTaskType)
|
||||
.CheckEqual(Searcher.AgvTaskType, x => x.AgvTaskType)
|
||||
.CheckContain(Searcher.SceneId, x => x.SceneId)
|
||||
.Select(x => new AgvTaskSceneConfig_View
|
||||
{
|
||||
ID = x.ID,
|
||||
SourceTaskType = x.SourceTaskType,
|
||||
AgvTaskType = x.AgvTaskType,
|
||||
SceneId = x.SceneId,
|
||||
SceneName = x.SceneName,
|
||||
BinTaskLoad = x.BinTaskLoad,
|
||||
BinTaskUnload = x.BinTaskUnload,
|
||||
Remark = x.Remark
|
||||
})
|
||||
.OrderByDescending(x => x.ID);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 场景配置列表行视图
|
||||
/// </summary>
|
||||
public class AgvTaskSceneConfig_View : AgvTaskSceneConfig
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务场景配置搜索条件
|
||||
/// </summary>
|
||||
public partial class AgvTaskSceneConfigSearcher : BaseSearcher
|
||||
{
|
||||
[Display(Name = "AGV.SourceTaskType")]
|
||||
public string SourceTaskType { get; set; }
|
||||
|
||||
[Display(Name = "AGV.AgvTaskType")]
|
||||
public AgvTaskTypeEnum? AgvTaskType { get; set; }
|
||||
|
||||
[Display(Name = "AGV.SceneId")]
|
||||
public string SceneId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务场景配置表单
|
||||
/// </summary>
|
||||
public partial class AgvTaskSceneConfigVM : BaseCRUDVM<AgvTaskSceneConfig>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 平库任务列表(WTM 标准 ListVM,供 wt:searchpanel + wt:grid 渲染,风格与场景配置/日志页统一)
|
||||
/// 操作列按任务状态渲染 下发/取消/重试完成 行内按钮,点击调用 Index 页全局 JS(axios 调后端接口后刷新 grid)
|
||||
/// </summary>
|
||||
public partial class AgvTaskListVM : BasePagedListVM<AgvTask_View, AgvTaskSearcher>
|
||||
{
|
||||
protected override List<GridAction> InitGridAction()
|
||||
{
|
||||
return new List<GridAction>
|
||||
{
|
||||
// 工具栏「下发任务」按钮:Dialog 打开 Create 表单页(功能与原页面弹窗一致,仅行内显示关闭)
|
||||
this.MakeStandardAction("AgvTask", GridActionStandardTypesEnum.Create, "下发任务", "agv", dialogWidth: 800).SetShowInRow(false)
|
||||
};
|
||||
}
|
||||
|
||||
protected override IEnumerable<IGridColumn<AgvTask_View>> InitGridHeader()
|
||||
{
|
||||
return new List<GridColumn<AgvTask_View>>
|
||||
{
|
||||
this.MakeGridHeader(x => x.TaskNo).SetWidth(170),
|
||||
// 任务场景列:关联 AgvTaskSceneConfig 取场景名称,便于人工识别业务类型
|
||||
this.MakeGridHeader(x => x.SceneName).SetWidth(110),
|
||||
this.MakeGridHeader(x => x.AgvStatusName).SetWidth(100),
|
||||
this.MakeGridHeader(x => x.FromLocation).SetWidth(110),
|
||||
this.MakeGridHeader(x => x.ToLocation).SetWidth(110),
|
||||
this.MakeGridHeader(x => x.ContainerCode).SetWidth(160),
|
||||
this.MakeGridHeader(x => x.SourceSystem).SetWidth(100),
|
||||
this.MakeGridHeader(x => x.ErrorMsg).SetWidth(200),
|
||||
this.MakeGridHeader(x => x.CreateTime).SetWidth(160),
|
||||
// 操作列:按状态渲染文字链接(新建/异常→下发;新建/已下发/执行中→取消;完成联动失败→重试完成)
|
||||
// 还原为最初始的纯 <a> 文字链接(仅 href + onclick 两个属性),链接间隔 5px 由页面 CSS 控制
|
||||
this.MakeGridHeader(x => x.Operation).SetWidth(120).SetFormat((a, b) =>
|
||||
{
|
||||
var st = (int)(a.AgvStatus ?? 0);
|
||||
var btns = new List<string>();
|
||||
if (st == 0 || st == 90)
|
||||
{
|
||||
btns.Add($"<a href=\"javascript:void(0)\" onclick=\"agvDispatch('{a.TaskNo}')\">下发</a>");
|
||||
}
|
||||
if (st == 0 || st == 5 || st == 10)
|
||||
{
|
||||
btns.Add($"<a href=\"javascript:void(0)\" onclick=\"agvCancel('{a.TaskNo}')\">取消</a>");
|
||||
}
|
||||
if (st == 99)
|
||||
{
|
||||
btns.Add($"<a href=\"javascript:void(0)\" onclick=\"agvRetryFinish('{a.TaskNo}')\">重试完成</a>");
|
||||
}
|
||||
if (btns.Count == 0)
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
return string.Join("", btns);
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
public override IOrderedQueryable<AgvTask_View> GetSearchQuery()
|
||||
{
|
||||
var query = DC.Set<AgvTask>()
|
||||
.CheckContain(Searcher.TaskNo, x => x.TaskNo)
|
||||
.CheckContain(Searcher.FromLocation, x => x.FromLocation)
|
||||
.CheckContain(Searcher.ToLocation, x => x.ToLocation)
|
||||
.CheckContain(Searcher.ContainerCode, x => x.ContainerCode)
|
||||
.CheckEqual(Searcher.SourceSystem, x => x.SourceSystem)
|
||||
.CheckEqual(Searcher.AgvStatus, x => x.AgvStatus)
|
||||
.Select(x => new AgvTask_View
|
||||
{
|
||||
ID = x.ID,
|
||||
TaskNo = x.TaskNo,
|
||||
AgvStatus = x.AgvStatus,
|
||||
// 状态中文名(枚举成员名即中文:新建/已下发/执行中/异常/取消/完成联动失败/完成)
|
||||
AgvStatusName = x.AgvStatus == null ? "" : x.AgvStatus.ToString(),
|
||||
// 任务场景名:按 AgvTaskType 关联场景配置表(AgvTask 仅存枚举,未配置则留空)
|
||||
SceneName = x.AgvTaskType == null ? "" :
|
||||
DC.Set<AgvTaskSceneConfig>()
|
||||
.Where(c => c.AgvTaskType == x.AgvTaskType)
|
||||
.Select(c => c.SceneName)
|
||||
.FirstOrDefault() ?? "",
|
||||
FromLocation = x.FromLocation,
|
||||
ToLocation = x.ToLocation,
|
||||
ContainerCode = x.ContainerCode,
|
||||
SourceSystem = x.SourceSystem,
|
||||
ErrorMsg = x.ErrorMsg,
|
||||
CreateTime = x.CreateTime
|
||||
})
|
||||
.OrderByDescending(x => x.CreateTime);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 任务列表行视图(SceneName 任务场景名 + AgvStatusName 中文状态 + Operation 虚拟操作列)
|
||||
/// </summary>
|
||||
public class AgvTask_View : AgvTask
|
||||
{
|
||||
/// <summary>任务场景名(由 AgvTaskSceneConfig 按 AgvTaskType 映射)</summary>
|
||||
[Display(Name = "任务场景")]
|
||||
public string SceneName { get; set; }
|
||||
|
||||
/// <summary>状态中文名(新建/已下发/执行中/异常/取消/完成联动失败/完成)</summary>
|
||||
[Display(Name = "AGV.AgvStatus")]
|
||||
public string AgvStatusName { get; set; }
|
||||
|
||||
/// <summary>操作列(SetFormat 服务端渲染行内按钮)</summary>
|
||||
[Display(Name = "操作")]
|
||||
public string Operation { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using HHWMS.Web.Models;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 平库任务搜索条件(任务列表页:任务号/起终点/容器模糊,来源/状态精确)
|
||||
/// </summary>
|
||||
public partial class AgvTaskSearcher : BaseSearcher
|
||||
{
|
||||
/// <summary>来源系统下拉选项(WMS / THIRD_PARTY)</summary>
|
||||
public List<ComboSelectListItem> AllSourceSystems { get; set; }
|
||||
|
||||
[Display(Name = "AGV.TaskNo")]
|
||||
public string TaskNo { get; set; }
|
||||
|
||||
[Display(Name = "AGV.FromLocation")]
|
||||
public string FromLocation { get; set; }
|
||||
|
||||
[Display(Name = "AGV.ToLocation")]
|
||||
public string ToLocation { get; set; }
|
||||
|
||||
[Display(Name = "AGV.ContainerCode")]
|
||||
public string ContainerCode { get; set; }
|
||||
|
||||
[Display(Name = "AGV.SourceSystem")]
|
||||
public string SourceSystem { get; set; }
|
||||
|
||||
[Display(Name = "AGV.AgvStatus")]
|
||||
public AgvTaskStatusEnum? AgvStatus { get; set; }
|
||||
|
||||
protected override void InitVM()
|
||||
{
|
||||
// 来源系统固定枚举下拉
|
||||
AllSourceSystems = new List<ComboSelectListItem>
|
||||
{
|
||||
new ComboSelectListItem { Value = "WMS", Text = "WMS" },
|
||||
new ComboSelectListItem { Value = "THIRD_PARTY", Text = "THIRD_PARTY" }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
@model HHWMS.Web.AgvTaskListVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
@* 手动下发 AGV 任务表单(由列表页 grid 工具栏「下发任务」按钮以 Dialog 打开) *@
|
||||
<style>
|
||||
/* 任务场景下拉:原生 select + Vue 渲染选项,规避 ArcoVue 组件渲染链路问题 */
|
||||
.agv-scene-select {
|
||||
width: 100%;
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #e5e6eb;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
color: #4e5969;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.agv-scene-select:focus {
|
||||
border-color: rgb(22, 93, 255);
|
||||
}
|
||||
</style>
|
||||
<div id="plapp">
|
||||
<div style="padding: 16px 20px;">
|
||||
<a-form :model="form" auto-label-width>
|
||||
<a-form-item label="任务场景" field="taskType" required>
|
||||
<select v-model="form.taskType" class="agv-scene-select">
|
||||
<option value="" disabled>请选择任务场景(必填)</option>
|
||||
<option v-for="item in sceneOptions" :key="item.value" :value="item.value">{{ item.label }}</option>
|
||||
</select>
|
||||
</a-form-item>
|
||||
<a-form-item label="起点库位" field="fromLocation" required>
|
||||
<a-input v-model="form.fromLocation" placeholder="手动输入起点库位编码(必填)" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item label="终点库位" field="toLocation" required>
|
||||
<a-input v-model="form.toLocation" placeholder="手动输入终点库位编码(必填)" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item label="容器号" field="containerCode">
|
||||
<a-input v-model="form.containerCode" placeholder="可不填,自动生成 LS 临时容器" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item label="优先级" field="priority">
|
||||
<a-input-number v-model="form.priority" :min="0" placeholder="默认 0" style="width:100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="物料明细" field="details">
|
||||
<div v-if="form.details.length === 0" style="color:#86909c; margin-bottom:8px;">
|
||||
未添加物料,按空容器业务处理
|
||||
</div>
|
||||
<div v-else style="width:100%; margin-bottom:8px;">
|
||||
<!-- 表头 -->
|
||||
<div style="display:flex; background:#f7f8fa; border:1px solid #e5e6eb; border-radius:4px 4px 0 0; padding:6px 8px; font-weight:500; font-size:13px; color:#4e5969;">
|
||||
<span style="flex:2.2;">物料编码</span>
|
||||
<span style="flex:1; text-align:center;">数量</span>
|
||||
<span style="flex:1.4; text-align:center;">批次</span>
|
||||
<span style="width:56px; text-align:center;">操作</span>
|
||||
</div>
|
||||
<!-- 物料行:多个物料竖向排列 -->
|
||||
<div v-for="d in form.details" :key="d._key"
|
||||
style="display:flex; align-items:center; border:1px solid #e5e6eb; border-top:none; padding:4px 8px; background:#fff;">
|
||||
<div style="flex:2.2; padding-right:8px;">
|
||||
<a-auto-complete v-model="d.materialCode" :data="d.options" placeholder="编码/名称搜索"
|
||||
@@search="(kw) => handleMaterialSearch(kw, d)" style="width:100%" />
|
||||
</div>
|
||||
<div style="flex:1; padding-right:8px;">
|
||||
<a-input-number v-model="d.qty" :min="0" placeholder="数量" style="width:100%" />
|
||||
</div>
|
||||
<div style="flex:1.4; padding-right:8px;">
|
||||
<a-input v-model="d.batch" placeholder="批次" allow-clear />
|
||||
</div>
|
||||
<div style="width:56px; text-align:center;">
|
||||
<a-button type="text" status="danger" size="mini" @@click="removeDetail(d._key)">删除</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a-button type="outline" size="small" @@click="addMaterial">+ 添加物料</a-button>
|
||||
</a-form-item>
|
||||
<a-form-item>
|
||||
<a-space>
|
||||
<a-button type="primary" @@click="createTask" :loading="loading">创建任务</a-button>
|
||||
<a-button type="outline" @@click="resetForm">重置</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// IIFE 包裹:弹窗 HTML 每次打开都会重新注入执行脚本,
|
||||
// 避免顶层 const 在当前文档重复声明报错导致第二次打开表单失效
|
||||
(function () {
|
||||
const { createApp, reactive, ref, onMounted } = Vue;
|
||||
const { Message } = ArcoVue;
|
||||
|
||||
const app = createApp({
|
||||
setup() {
|
||||
const loading = ref(false);
|
||||
// 场景选项由服务端 Create 时直接查库注入,前端无需异步加载,保证下拉必有选项
|
||||
const sceneOptions = ref(@Html.Raw(ViewBag.ScenesJson ?? "[]"));
|
||||
|
||||
const form = reactive({
|
||||
taskType: undefined,
|
||||
fromLocation: "",
|
||||
toLocation: "",
|
||||
containerCode: "",
|
||||
priority: 0,
|
||||
details: []
|
||||
});
|
||||
|
||||
// 关闭当前弹窗并刷新列表:同文档弹窗(layer type:1)用父页记录的层号关闭;兼容旧 iframe 模式兜底
|
||||
const closeAndRefresh = () => {
|
||||
try {
|
||||
if (window.agvCreateLayerIndex) {
|
||||
layer.close(window.agvCreateLayerIndex);
|
||||
window.agvCreateLayerIndex = 0;
|
||||
} else {
|
||||
var idx = parent.layer.getFrameIndex(window.name);
|
||||
if (idx) parent.layer.close(idx);
|
||||
}
|
||||
} catch (e) { /* 非 Dialog 环境忽略 */ }
|
||||
try {
|
||||
if (window.reloadAgvTask) { window.reloadAgvTask(); }
|
||||
else if (parent.reloadAgvTask) { parent.reloadAgvTask(); }
|
||||
} catch (e) { /* 父页不可达时忽略 */ }
|
||||
};
|
||||
|
||||
const loadScenes = async () => {
|
||||
// 场景已由服务端注入 sceneOptions,此处保留用于手动刷新兜底
|
||||
const { data } = await axios.post("/agv/AgvTask/GetScenes");
|
||||
if (data && data.Data && data.Data.length > 0)
|
||||
{
|
||||
sceneOptions.value = data.Data;
|
||||
}
|
||||
};
|
||||
|
||||
// 物料搜索(按行缓存选项,支持多行独立搜索)
|
||||
const handleMaterialSearch = async (keyword, row) => {
|
||||
if (!row) return;
|
||||
const { data } = await axios.post(`/agv/AgvTask/GetMaterials?keyword=${encodeURIComponent(keyword || "")}`);
|
||||
row.options = (data.Data || []).map(m => `${m.materialCode}(${m.materialName || ""})`);
|
||||
};
|
||||
|
||||
// 添加物料行(多个物料竖向表格,直接内嵌,无弹窗)
|
||||
const addMaterial = () => {
|
||||
form.details.push({
|
||||
_key: Date.now() + Math.random(),
|
||||
materialCode: "",
|
||||
qty: null,
|
||||
batch: "",
|
||||
options: [],
|
||||
erpDetailId: ""
|
||||
});
|
||||
};
|
||||
|
||||
const removeDetail = (key) => {
|
||||
const idx = form.details.findIndex(d => d._key === key);
|
||||
if (idx >= 0) form.details.splice(idx, 1);
|
||||
};
|
||||
|
||||
const createTask = async () => {
|
||||
if (!form.taskType) {
|
||||
Message.warning("任务场景为必填项");
|
||||
return;
|
||||
}
|
||||
if (!form.fromLocation || !form.fromLocation.trim()) {
|
||||
Message.warning("起点库位为必填项");
|
||||
return;
|
||||
}
|
||||
if (!form.toLocation || !form.toLocation.trim()) {
|
||||
Message.warning("终点库位为必填项");
|
||||
return;
|
||||
}
|
||||
if (form.fromLocation.trim() === form.toLocation.trim()) {
|
||||
Message.warning("起点与终点不能相同");
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
// 过滤未填物料编码的空行,全空则按空容器业务处理
|
||||
const validDetails = form.details
|
||||
.filter(d => d.materialCode && d.materialCode.trim())
|
||||
.map(d => ({ MaterialCode: d.materialCode.trim(), Qty: d.qty || 0, Batch: d.batch || "", ErpDetailId: d.erpDetailId || "" }));
|
||||
const { data } = await axios.post("/agv/AgvTask/Create", {
|
||||
TaskType: form.taskType,
|
||||
FromLocation: form.fromLocation.trim(),
|
||||
ToLocation: form.toLocation.trim(),
|
||||
ContainerCode: form.containerCode || undefined,
|
||||
Priority: form.priority || 0,
|
||||
Details: validDetails.length > 0 ? validDetails : undefined
|
||||
});
|
||||
if (data.Code == 200) {
|
||||
// 提示显示在弹窗上层(父窗口 layer),iframe 内 ArcoVue Message 会被弹窗遮挡
|
||||
parent.layer.msg(data.Msg || "任务创建成功", { icon: 1, time: 1500 });
|
||||
closeAndRefresh();
|
||||
} else {
|
||||
parent.layer.msg(data.Msg || "操作失败", { icon: 2, time: 3000 });
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
form.taskType = undefined;
|
||||
form.fromLocation = "";
|
||||
form.toLocation = "";
|
||||
form.containerCode = "";
|
||||
form.priority = 0;
|
||||
form.details = [];
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
try { await loadScenes(); }
|
||||
catch (e) { console.warn("loadScenes 失败", e); }
|
||||
});
|
||||
|
||||
return {
|
||||
form, loading, sceneOptions,
|
||||
createTask, resetForm,
|
||||
addMaterial, removeDetail, handleMaterialSearch
|
||||
};
|
||||
}
|
||||
});
|
||||
app.use(ArcoVue);
|
||||
app.mount("#plapp");
|
||||
})(); /* IIFE 结束 */
|
||||
</script>
|
||||
@@ -0,0 +1,225 @@
|
||||
@model HHWMS.Web.AgvTaskListVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
@* AGV 平库任务列表:原生 HTML 表格渲染,完全避开 WTM grid / layui table 渲染链路的异常问题
|
||||
查询、分页、行内 下发/取消/重试完成 均由本页 JS 直调后端接口实现 *@
|
||||
<div style="padding:10px;">
|
||||
<!-- 查询区 -->
|
||||
<div style="background:#fff; border-radius:4px; padding:12px 12px 2px; margin-bottom:10px; box-shadow:0 1px 2px rgba(0,0,0,.06);">
|
||||
<div style="display:flex; flex-wrap:wrap; gap:8px 18px; align-items:center;">
|
||||
<div><label style="margin-right:4px;">任务号</label><input id="q_taskNo" placeholder="模糊查询" class="agv-q-input" /></div>
|
||||
<div><label style="margin-right:4px;">起点</label><input id="q_from" placeholder="模糊查询" class="agv-q-input" /></div>
|
||||
<div><label style="margin-right:4px;">终点</label><input id="q_to" placeholder="模糊查询" class="agv-q-input" /></div>
|
||||
<div><label style="margin-right:4px;">容器号</label><input id="q_container" placeholder="模糊查询" class="agv-q-input" /></div>
|
||||
<div><label style="margin-right:4px;">来源系统</label><select id="q_source" class="agv-q-input"><option value="">全部</option></select></div>
|
||||
<div><label style="margin-right:4px;">状态</label><select id="q_status" class="agv-q-input"><option value="">全部</option></select></div>
|
||||
<div style="margin-bottom:10px;">
|
||||
<button type="button" class="layui-btn layui-btn-sm" onclick="agvSearch(1)"><i class="layui-icon"></i> 查询</button>
|
||||
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="agvReset()">重置</button>
|
||||
<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" style="margin-left:10px;" onclick="agvOpenCreate()"><i class="layui-icon"></i> 下发任务</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格(原生 table,行内操作由 JS 直接生成,显示稳定可控) -->
|
||||
<table class="layui-table" style="margin:0;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:170px;">任务号</th>
|
||||
<th style="width:110px;">任务场景</th>
|
||||
<th style="width:90px;">状态</th>
|
||||
<th style="width:110px;">起点</th>
|
||||
<th style="width:110px;">终点</th>
|
||||
<th style="width:150px;">容器号</th>
|
||||
<th style="width:90px;">来源系统</th>
|
||||
<th style="width:180px;">错误信息</th>
|
||||
<th style="width:150px;">创建时间</th>
|
||||
<th style="width:120px;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="agvTbody"><tr><td colspan="10" style="text-align:center; color:#999;">加载中...</td></tr></tbody>
|
||||
</table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div style="display:flex; justify-content:flex-end; align-items:center; gap:10px; padding:10px 2px; color:#666;">
|
||||
<span id="agvTotal">共 0 条</span>
|
||||
<span>每页</span>
|
||||
<select id="q_size" style="height:26px; padding:0 4px; border:1px solid #e5e6eb; border-radius:4px; outline:none;" onchange="agvSizeChange()">
|
||||
<option value="10" selected>10 条</option>
|
||||
<option value="20">20 条</option>
|
||||
<option value="50">50 条</option>
|
||||
<option value="100">100 条</option>
|
||||
</select>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-primary" onclick="agvPageTurn(-1)">上一页</button>
|
||||
<span id="agvPageNo">第 1 页</span>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-primary" onclick="agvPageTurn(1)">下一页</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.agv-q-input {
|
||||
height: 30px;
|
||||
padding: 0 8px;
|
||||
border: 1px solid #e5e6eb;
|
||||
border-radius: 4px;
|
||||
outline: none;
|
||||
font-size: 13px;
|
||||
width: 130px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.agv-q-input:focus { border-color: #16b777; }
|
||||
/* 操作列文字链接:纯文字可点击,间隔 5px */
|
||||
#agvTbody a { color: #01AAED; margin-right: 5px; }
|
||||
#agvTbody td { font-size: 13px; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// 状态映射(与 AgvTaskStatusEnum 一致:成员名即中文)
|
||||
var agvStatusMap = { 0: "新建", 5: "已下发", 10: "执行中", 90: "异常", 95: "取消", 99: "完成联动失败", 100: "完成" };
|
||||
var agvPage = 1, agvSize = 10, agvTotal = 0;
|
||||
|
||||
// HTML 转义,防止数据中的特殊字符破坏表格结构
|
||||
function agvEsc(v) {
|
||||
return v == null ? "" : String(v).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
}
|
||||
|
||||
// 加载任务列表(多条件 + 分页)
|
||||
function loadTasks() {
|
||||
var body = {
|
||||
TaskNo: $("#q_taskNo").val(), FromLocation: $("#q_from").val(), ToLocation: $("#q_to").val(),
|
||||
ContainerCode: $("#q_container").val(), SourceSystem: $("#q_source").val(),
|
||||
AgvStatus: $("#q_status").val() === "" ? null : parseInt($("#q_status").val()),
|
||||
Page: agvPage, Size: agvSize
|
||||
};
|
||||
$.ajax({
|
||||
type: "post", url: "/agv/AgvTask/GetTasks", dataType: "json",
|
||||
contentType: "application/json", data: JSON.stringify(body),
|
||||
success: function (json) {
|
||||
var data = json.Data || {};
|
||||
agvTotal = data.Total || 0;
|
||||
var list = data.List || [];
|
||||
if (list.length === 0) {
|
||||
$("#agvTbody").html('<tr><td colspan="10" style="text-align:center; color:#999;">暂无数据</td></tr>');
|
||||
} else {
|
||||
var rows = "";
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var t = list[i];
|
||||
rows += "<tr>"
|
||||
+ "<td>" + agvEsc(t.TaskNo) + "</td>"
|
||||
+ "<td>" + agvEsc(t.SceneName) + "</td>"
|
||||
+ "<td>" + agvEsc(t.AgvStatusName || agvStatusMap[t.AgvStatus] || "-") + "</td>"
|
||||
+ "<td>" + agvEsc(t.FromLocation) + "</td>"
|
||||
+ "<td>" + agvEsc(t.ToLocation) + "</td>"
|
||||
+ "<td>" + agvEsc(t.ContainerCode) + "</td>"
|
||||
+ "<td>" + agvEsc(t.SourceSystem) + "</td>"
|
||||
+ "<td>" + agvEsc(t.ErrorMsg) + "</td>"
|
||||
+ "<td>" + agvEsc((t.CreateTime || "").replace("T", " ").substring(0, 19)) + "</td>"
|
||||
+ "<td>" + agvOps(t.AgvStatus, t.TaskNo) + "</td>"
|
||||
+ "</tr>";
|
||||
}
|
||||
$("#agvTbody").html(rows);
|
||||
}
|
||||
$("#agvTotal").text("共 " + agvTotal + " 条");
|
||||
var maxPage = Math.max(1, Math.ceil(agvTotal / agvSize));
|
||||
$("#agvPageNo").text("第 " + agvPage + " / " + maxPage + " 页");
|
||||
},
|
||||
error: function () {
|
||||
$("#agvTbody").html('<tr><td colspan="10" style="text-align:center; color:#999;">请求失败,请检查服务是否正常</td></tr>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 行内操作链接:新建/异常→下发;新建/已下发/执行中→取消;完成联动失败→重试完成
|
||||
function agvOps(st, taskNo) {
|
||||
var html = "";
|
||||
if (st == 0 || st == 90) {
|
||||
html += "<a href='javascript:void(0)' onclick=\"agvDispatch('" + agvEsc(taskNo) + "')\">下发</a>";
|
||||
}
|
||||
if (st == 0 || st == 5 || st == 10) {
|
||||
html += "<a href='javascript:void(0)' onclick=\"agvCancel('" + agvEsc(taskNo) + "')\">取消</a>";
|
||||
}
|
||||
if (st == 99) {
|
||||
html += "<a href='javascript:void(0)' onclick=\"agvRetryFinish('" + agvEsc(taskNo) + "')\">重试完成</a>";
|
||||
}
|
||||
return html == "" ? "-" : html;
|
||||
}
|
||||
|
||||
// 通用行操作:确认后 POST 指定接口,成功后刷新列表
|
||||
function agvPost(url, taskNo, confirmText, successMsg) {
|
||||
layer.confirm(confirmText + " [" + taskNo + "]?", { icon: 3, title: "提示" }, function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "post", dataType: "json", contentType: "application/json",
|
||||
data: JSON.stringify({ TaskNo: taskNo }), url: url,
|
||||
success: function (json) {
|
||||
if (json.Code == 200) {
|
||||
layer.msg(json.Msg || successMsg);
|
||||
loadTasks();
|
||||
} else {
|
||||
layer.alert(json.Msg || "操作失败");
|
||||
}
|
||||
},
|
||||
error: function () { layer.alert("请求失败,请检查服务是否正常"); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 下发(仅新建/异常行显示,后端仍做状态校验兜底)
|
||||
function agvDispatch(taskNo) { agvPost("/agv/AgvTask/Dispatch", taskNo, "确定下发任务", "下发成功"); }
|
||||
// 取消(仅新建/已下发/执行中行显示)
|
||||
function agvCancel(taskNo) { agvPost("/agv/AgvTask/Cancel", taskNo, "确定取消任务", "取消成功"); }
|
||||
// 重试完成联动(仅完成联动失败行显示)
|
||||
function agvRetryFinish(taskNo) { agvPost("/agv/AgvTask/RetryFinish", taskNo, "确定重试完成联动", "重试成功"); }
|
||||
|
||||
// 查询(重置回第 1 页)
|
||||
function agvSearch(page) { agvPage = page || 1; loadTasks(); }
|
||||
// 切换每页条数:回到第 1 页重新加载
|
||||
function agvSizeChange() {
|
||||
agvSize = parseInt($("#q_size").val()) || 10;
|
||||
agvSearch(1);
|
||||
}
|
||||
// 翻页
|
||||
function agvPageTurn(step) {
|
||||
var maxPage = Math.max(1, Math.ceil(agvTotal / agvSize));
|
||||
var target = agvPage + step;
|
||||
if (target < 1 || target > maxPage) return;
|
||||
agvPage = target; loadTasks();
|
||||
}
|
||||
// 重置查询条件
|
||||
function agvReset() {
|
||||
$("#q_taskNo,#q_from,#q_to,#q_container").val("");
|
||||
$("#q_source,#q_status").val("");
|
||||
agvSearch(1);
|
||||
}
|
||||
|
||||
// 打开「下发任务」弹窗:与 WTM 弹窗机制一致(ajax 取 HTML 注入当前文档 type:1),
|
||||
// 当前文档已加载 Vue/ArcoVue/CSS,避免 iframe 内无脚本导致表单模板原样显示
|
||||
var agvCreateLayerIndex = 0;
|
||||
function agvOpenCreate() {
|
||||
$.ajax({
|
||||
type: "get", url: "/agv/AgvTask/Create", dataType: "html",
|
||||
success: function (html) {
|
||||
agvCreateLayerIndex = layer.open({
|
||||
type: 1, title: "下发任务", area: ["800px", "90%"], content: html
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 供 Create 弹窗关闭后刷新列表
|
||||
function reloadAgvTask() { loadTasks(); }
|
||||
|
||||
// 初始化:填充状态下拉 + 来源系统下拉 + 首次加载
|
||||
$(function () {
|
||||
var statusSel = $("#q_status");
|
||||
for (var k in agvStatusMap) { statusSel.append('<option value="' + k + '">' + agvStatusMap[k] + "</option>"); }
|
||||
$.ajax({
|
||||
type: "post", url: "/agv/AgvTask/GetSourceSystems", dataType: "json", contentType: "application/json", data: "{}",
|
||||
success: function (json) {
|
||||
var list = json.Data || [];
|
||||
for (var i = 0; i < list.length; i++) { $("#q_source").append('<option value="' + agvEsc(list[i]) + '">' + agvEsc(list[i]) + "</option>"); }
|
||||
}
|
||||
});
|
||||
loadTasks();
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,22 @@
|
||||
@model HHWMS.Web.AgvTaskLogVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:display field="Entity.TaskNo"/>
|
||||
<wt:display field="Entity.OrderId"/>
|
||||
<wt:display field="Entity.FromStatus"/>
|
||||
<wt:display field="Entity.ToStatus"/>
|
||||
<wt:display field="Entity.Event"/>
|
||||
<wt:display field="Entity.Direction"/>
|
||||
<wt:display field="Entity.EventTime"/>
|
||||
<wt:display field="Entity.DurationMs"/>
|
||||
<wt:display field="Entity.Operator"/>
|
||||
</wt:row>
|
||||
<wt:display field="Entity.Remark"/>
|
||||
<wt:display field="Entity.RequestJson"/>
|
||||
<wt:display field="Entity.ResponseJson"/>
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:closebutton />
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
@@ -0,0 +1,13 @@
|
||||
@model HHWMS.Web.AgvTaskLogListVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:searchpanel vm="@Model" reset-btn="true" grid-id="AgvTaskLog">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Three">
|
||||
<wt:textbox field="Searcher.TaskNo" />
|
||||
<wt:textbox field="Searcher.Direction" />
|
||||
<wt:textbox field="Searcher.Event" />
|
||||
<wt:textbox field="Searcher.RequestJson" />
|
||||
<wt:textbox field="Searcher.ResponseJson" />
|
||||
</wt:row>
|
||||
</wt:searchpanel>
|
||||
<wt:grid vm="@Model" id="AgvTaskLog" url="/agv/AgvTaskLog/Search" />
|
||||
@@ -0,0 +1,18 @@
|
||||
@model HHWMS.Web.AgvTaskSceneConfigVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:textbox field="Entity.SourceTaskType" />
|
||||
<wt:combobox field="Entity.AgvTaskType" />
|
||||
<wt:textbox field="Entity.SceneId" />
|
||||
<wt:textbox field="Entity.SceneName" />
|
||||
<wt:textbox field="Entity.BinTaskLoad" />
|
||||
<wt:textbox field="Entity.BinTaskUnload" />
|
||||
</wt:row>
|
||||
<wt:textbox field="Entity.Remark" />
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:submitbutton />
|
||||
<wt:closebutton />
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
@@ -0,0 +1,20 @@
|
||||
@model HHWMS.Web.AgvTaskSceneConfigVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:quote>@Localizer["Sys.DeleteConfirm"]</wt:quote>
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:display field="Entity.SourceTaskType"/>
|
||||
<wt:display field="Entity.AgvTaskType"/>
|
||||
<wt:display field="Entity.SceneId"/>
|
||||
<wt:display field="Entity.SceneName"/>
|
||||
<wt:display field="Entity.BinTaskLoad"/>
|
||||
<wt:display field="Entity.BinTaskUnload"/>
|
||||
</wt:row>
|
||||
<wt:display field="Entity.Remark"/>
|
||||
<wt:hidden field="Entity.ID" />
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:submitbutton theme=" ButtonThemeEnum.Warm" text="@Localizer["Sys.Delete"]"/>
|
||||
<wt:closebutton />
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
@@ -0,0 +1,17 @@
|
||||
@model HHWMS.Web.AgvTaskSceneConfigVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:display field="Entity.SourceTaskType"/>
|
||||
<wt:display field="Entity.AgvTaskType"/>
|
||||
<wt:display field="Entity.SceneId"/>
|
||||
<wt:display field="Entity.SceneName"/>
|
||||
<wt:display field="Entity.BinTaskLoad"/>
|
||||
<wt:display field="Entity.BinTaskUnload"/>
|
||||
</wt:row>
|
||||
<wt:display field="Entity.Remark"/>
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:closebutton />
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
@@ -0,0 +1,19 @@
|
||||
@model HHWMS.Web.AgvTaskSceneConfigVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:textbox field="Entity.SourceTaskType" />
|
||||
<wt:combobox field="Entity.AgvTaskType" />
|
||||
<wt:textbox field="Entity.SceneId" />
|
||||
<wt:textbox field="Entity.SceneName" />
|
||||
<wt:textbox field="Entity.BinTaskLoad" />
|
||||
<wt:textbox field="Entity.BinTaskUnload" />
|
||||
</wt:row>
|
||||
<wt:textbox field="Entity.Remark" />
|
||||
<wt:hidden field="Entity.ID" />
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:submitbutton />
|
||||
<wt:closebutton />
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
@@ -0,0 +1,11 @@
|
||||
@model HHWMS.Web.AgvTaskSceneConfigListVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:searchpanel vm="@Model" reset-btn="true" grid-id="AgvTaskSceneConfig">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Three">
|
||||
<wt:textbox field="Searcher.SourceTaskType" />
|
||||
<wt:combobox field="Searcher.AgvTaskType" empty-text="@Localizer["Sys.All"]" />
|
||||
<wt:textbox field="Searcher.SceneId" />
|
||||
</wt:row>
|
||||
</wt:searchpanel>
|
||||
<wt:grid vm="@Model" id="AgvTaskSceneConfig" url="/agv/AgvTaskSceneConfig/Search" />
|
||||
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
using HHWMS.Web.Services.Agv;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 平库任务对外接口(方案 4.2)
|
||||
/// 调用方向:AGV 调度系统 / 上游系统 → WMS
|
||||
/// 接口:Receive(接单)、Callback(状态回调)
|
||||
/// 鉴权:本期暂不实施,保持 Public 公开访问(AppKey/AppSecret 预留待后续启用)
|
||||
/// </summary>
|
||||
[Public]
|
||||
[ActionDescription("AGV接口")]
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]"), ApiExplorerSettings(GroupName = "User")]
|
||||
public class AgvController : ApiController
|
||||
{
|
||||
private readonly AgvTaskService _taskService;
|
||||
private readonly AgvOption _option;
|
||||
|
||||
public AgvController(AgvTaskService taskService, IOptions<AgvOption> option)
|
||||
{
|
||||
_taskService = taskService;
|
||||
_option = option.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接单:创建 AGV 任务(幂等 + 8 项校验 + LS 临时容器 + SKU 可选补建 + 接单落库即锁)
|
||||
/// 参数与手动下任务页面保持一致
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Receive(AgvReceiveRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_option.Enabled)
|
||||
{
|
||||
return ApiResultError("AGV 模块已停用");
|
||||
}
|
||||
// API 入口:来源系统未传则默认 THIRD_PARTY(页面手动下发走 Service 默认 WMS)
|
||||
if (string.IsNullOrWhiteSpace(request.SourceSystem))
|
||||
{
|
||||
request.SourceSystem = "THIRD_PARTY";
|
||||
}
|
||||
var task = await _taskService.CreateTaskAsync(request);
|
||||
return ApiResult(new
|
||||
{
|
||||
TaskNo = task.TaskNo,
|
||||
ContainerCode = task.ContainerCode,
|
||||
AgvStatus = task.AgvStatus?.ToString()
|
||||
});
|
||||
}
|
||||
catch (AgvBizException ex)
|
||||
{
|
||||
return ApiResultError($"接单失败: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ApiResultError($"接单异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 状态回调:AGV 事件 → 状态机单调推进(Accepted/ArrivedLoad/Loaded/ArrivedUnload/Unloaded/Error/Cancel)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Callback(AgvCallbackRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_option.Enabled)
|
||||
{
|
||||
return ApiResultError("AGV 模块已停用");
|
||||
}
|
||||
await _taskService.HandleCallbackAsync(request);
|
||||
return ApiResult(null);
|
||||
}
|
||||
catch (AgvBizException ex)
|
||||
{
|
||||
return ApiResultError($"回调处理失败: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ApiResultError($"回调处理异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,10 +172,10 @@ namespace HHWMS.Web
|
||||
var data = new List<ChartData>();
|
||||
var locations = Wtm.DC.Set<Location>()
|
||||
.AsEnumerable()
|
||||
.GroupBy(x => x.ContainerStatus).ToList()
|
||||
.GroupBy(x => x.ContainerStatus ?? LocationStatus.空仓位).ToList()
|
||||
.Select(x => new { status = statusMap.TryGetValue(x.Key, out var chineseName)
|
||||
? chineseName
|
||||
: x.Key.ToString(), count = x.Count() });
|
||||
: x.Key, count = x.Count() });
|
||||
foreach (var item in locations)
|
||||
{
|
||||
data.Add(new ChartData
|
||||
@@ -227,12 +227,13 @@ namespace HHWMS.Web
|
||||
|
||||
foreach (var loc in group)
|
||||
{
|
||||
statusMap.TryGetValue(loc.ContainerStatus, out var statusInfo);
|
||||
var statusKey = loc.ContainerStatus ?? LocationStatus.空仓位;
|
||||
statusMap.TryGetValue(statusKey, out var statusInfo);
|
||||
heatmap.Points.Add(new HeatmapPointDto
|
||||
{
|
||||
Line = loc.Line,
|
||||
Layer = loc.Layer,
|
||||
Status = statusInfo.name ?? loc.ContainerStatus ?? "未知",
|
||||
Status = statusInfo.name ?? statusKey,
|
||||
Color = statusInfo.color ?? "#909399",
|
||||
ContainerCode = loc.ContainerCode,
|
||||
LocationCode = loc.Code
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
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 HHWMS.Web.Services.Erp;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
@@ -15,10 +17,12 @@ namespace HHWMS.Web.Controllers
|
||||
public partial class MaterialController : BaseController
|
||||
{
|
||||
private readonly IUnitWork _unitWork;
|
||||
private readonly ErpMaterialService _erpMaterialService;
|
||||
|
||||
public MaterialController(IUnitWork unitWork)
|
||||
public MaterialController(IUnitWork unitWork, ErpMaterialService erpMaterialService)
|
||||
{
|
||||
_unitWork = unitWork;
|
||||
_erpMaterialService = erpMaterialService;
|
||||
}
|
||||
|
||||
#region Search
|
||||
@@ -31,18 +35,20 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost]
|
||||
public string Search(MaterialSearcher searcher)
|
||||
public async Task<string> Search(MaterialSearcher searcher)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Wtm.CreateVM<MaterialListVM>(passInit: true).GetError();
|
||||
}
|
||||
|
||||
// 先查本地物料表,查不到再调 ERP 回写:物料编码→InvCode,图号→InvDefine1
|
||||
await _erpMaterialService.EnsureByCodeAsync(searcher.MaterialCode);
|
||||
await _erpMaterialService.EnsureByTypeAsync(searcher.MaterialType);
|
||||
|
||||
var vm = Wtm.CreateVM<MaterialListVM>(passInit: true);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
vm.Searcher = searcher;
|
||||
return vm.GetJson(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return vm.GetError();
|
||||
}
|
||||
vm.Searcher = searcher;
|
||||
return vm.GetJson(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -51,6 +51,10 @@ namespace HHWMS.Web
|
||||
public override void DoAdd()
|
||||
{
|
||||
base.DoAdd();
|
||||
// 单个新增库位时,库位状态默认空仓位(ContainerStatus = "empty")
|
||||
Entity.ContainerStatus = LocationStatus.空仓位;
|
||||
Entity.Status = LocationStatusEnum.未锁;
|
||||
Entity.IsStop = false;
|
||||
}
|
||||
|
||||
public override void DoEdit(bool updateAllFields = false)
|
||||
|
||||
@@ -35,4 +35,4 @@
|
||||
printData = [];
|
||||
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
@@ -88,7 +88,8 @@ namespace HHWMS.Web
|
||||
var success = await CallAddOtherOut(
|
||||
inventory.MaterialCode,
|
||||
inventory.Qty ?? 0,
|
||||
inventory.CreateBy);
|
||||
inventory.CreateBy,
|
||||
inventory.ZoneId);
|
||||
inventory.UploadErpFlag = success ? 1 : 0;
|
||||
return success;
|
||||
}
|
||||
@@ -106,8 +107,9 @@ namespace HHWMS.Web
|
||||
WorkerCode = inventory.CreateBy, // 工人编码(创建人)
|
||||
Maker = unitWork.FindSingle<FrameworkUser>(x =>
|
||||
x.ITCode == inventory.CreateBy).Name, // 制单人(校验员)
|
||||
Type = inventory.ZoneId == 1027 ? 1: 2,
|
||||
WhCode = inventory.ZoneId == 1027 ? "xb": "cp",
|
||||
// 上报库区取值统一走 AgvErpWhTypeEnum 枚举(5.4.1),后期改枚举即可
|
||||
Type = AgvErpWhTypeEnumExtensions.FromZoneId(inventory.ZoneId).GetErpType(),
|
||||
WhCode = AgvErpWhTypeEnumExtensions.FromZoneId(inventory.ZoneId).GetWhCode(),
|
||||
},
|
||||
Details = new List<FinishInDetail>()
|
||||
};
|
||||
@@ -172,7 +174,8 @@ namespace HHWMS.Web
|
||||
var success = await CallAddOtherOut(
|
||||
transaction.MaterialCode,
|
||||
transaction.Qty ?? 0,
|
||||
transaction.CreateBy);
|
||||
transaction.CreateBy,
|
||||
zoneCode: transaction.ZoneCode);
|
||||
transaction.UploadErpFlag = success ? 1 : 0;
|
||||
return success;
|
||||
}
|
||||
@@ -189,18 +192,28 @@ namespace HHWMS.Web
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> CallAddOtherOut(string materialCode, decimal qty, string createBy)
|
||||
/// <summary>
|
||||
/// 补传 ERP 其他出库(AddOtherOut)。
|
||||
/// zoneId:库存场景按库区ID解析(ProcessErpFinishIn 出库分支);
|
||||
/// zoneCode:流水场景按库区编码解析(ProcessErpOtherOut / AddOtherOutJob 补传)。
|
||||
/// </summary>
|
||||
private async Task<bool> CallAddOtherOut(string materialCode, decimal qty, string createBy,
|
||||
int? zoneId = null, string zoneCode = null)
|
||||
{
|
||||
var maker = unitWork.FindSingle<FrameworkUser>(x => x.ITCode == createBy)?.Name
|
||||
?? createBy
|
||||
?? "WMS";
|
||||
// 上报库区取值统一走 AgvErpWhTypeEnum 枚举(5.4.1),后期改枚举即可
|
||||
var whType = zoneId.HasValue
|
||||
? AgvErpWhTypeEnumExtensions.FromZoneId(zoneId.Value)
|
||||
: AgvErpWhTypeEnumExtensions.FromZoneCode(zoneCode);
|
||||
var request = new AddOtherOutRequest
|
||||
{
|
||||
Main = new AddOtherOutMain
|
||||
{
|
||||
ErpCode = "003",
|
||||
OutCode = unitWork.GetSerialNumber("CK"),
|
||||
WhCode = "xb",
|
||||
WhCode = whType.GetWhCode(),
|
||||
Maker = maker
|
||||
},
|
||||
Details = new List<AddOtherOutDetail>
|
||||
|
||||
@@ -55,21 +55,48 @@ namespace HHWMS.Web.Controllers
|
||||
return Json(new { Code = 200, Data = new object[] { } });
|
||||
}
|
||||
|
||||
// 尝试调用接口获取物料
|
||||
keyword = keyword.Trim();
|
||||
|
||||
// 先查本地物料表:物料编码或图号模糊匹配(名称也一起匹配),和标准入库页面一致
|
||||
var dbMaterials = _unitWork.Find<Material>(m => m.MaterialCode.Contains(keyword)
|
||||
|| m.MaterialType.Contains(keyword)
|
||||
|| m.MaterialName.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();
|
||||
// 本地查到就返回,不再因为图号为空丢弃记录
|
||||
if (dbMaterials.Count > 0)
|
||||
{
|
||||
return Json(new { Code = 200, Data = dbMaterials });
|
||||
}
|
||||
|
||||
// 本地没有则调 ERP LoadInventory(按物料编码 InvCode 查询)并自动建档
|
||||
try
|
||||
{
|
||||
var request = new LoadInventoryRequest
|
||||
{
|
||||
ErpCode = "003",
|
||||
InvDefine1 = keyword,
|
||||
InvCode = keyword,
|
||||
Size = 15,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
Wtm.DoLog($"ERP物料查询: 入库页面搜索触发", ActionLogTypesEnum.Normal,
|
||||
"物料", $"keyword={keyword}, ErpCode=003");
|
||||
var apiResult =
|
||||
await Wtm.CallAPI<LoadInventoryResponse>("ERP", "LoadInventory", HttpMethodEnum.POST, request,3);
|
||||
|
||||
if (apiResult?.Data != null && apiResult.Data.Code == 0)
|
||||
// ERP 有数据才用 ERP 结果;返回成功但 0 条时继续往下走本地兜底,避免页面变成空列表
|
||||
if (apiResult?.Data != null && apiResult.Data.Code == 0
|
||||
&& apiResult.Data.Data != null && apiResult.Data.Data.Count > 0)
|
||||
{
|
||||
var materialsList = new List<object>();
|
||||
var oldMaterials = new List<object>();
|
||||
@@ -81,6 +108,9 @@ namespace HHWMS.Web.Controllers
|
||||
.Select(x => x.InvCode)
|
||||
.ToList();
|
||||
|
||||
Wtm.DoLog($"ERP物料查询: ERP返回{apiResult.Data.Data.Count}条", ActionLogTypesEnum.Normal,
|
||||
"物料", $"keyword={keyword}, codes=[{string.Join(",", invCodes)}]");
|
||||
|
||||
// 一次性查询本地数据库中已存在的物料(优化性能,避免循环中多次查询)
|
||||
var existingMaterials = _unitWork.Find<Material>(m => invCodes.Contains(m.MaterialCode))
|
||||
.ToList();
|
||||
@@ -155,36 +185,28 @@ namespace HHWMS.Web.Controllers
|
||||
_unitWork.BatchAdd(newMaterials);
|
||||
_unitWork.BatchUpdate(oldMaterials);
|
||||
|
||||
Wtm.DoLog($"ERP物料查询: 本地同步完成", ActionLogTypesEnum.Normal,
|
||||
"物料", $"keyword={keyword}, 新增={newMaterials.Count}, 更新={oldMaterials.Count}");
|
||||
|
||||
// 返回物料列表到前端
|
||||
return Json(new { Code = 200, Data = materialsList });
|
||||
}
|
||||
else
|
||||
{
|
||||
Wtm.DoLog($"ERP物料查询: ERP返回异常", ActionLogTypesEnum.Normal,
|
||||
"物料", $"keyword={keyword}, Code={apiResult?.Data?.Code}, Msg={apiResult?.Data?.Msg}");
|
||||
}
|
||||
}
|
||||
catch (System.Exception apiEx)
|
||||
{
|
||||
// 接口调用失败,记录日志
|
||||
Wtm.DoLog("获取ERP物料数据", ActionLogTypesEnum.Normal, "SearchMaterials",
|
||||
request: $"接口调用失败,改用本地数据库查询:{apiEx.Message}",
|
||||
result: "接口调用失败,改用本地数据库查询");
|
||||
Wtm.DoLog($"ERP物料查询: 接口调用失败", ActionLogTypesEnum.Normal, "物料",
|
||||
request: $"keyword={keyword}, 改用本地数据库查询",
|
||||
result: apiEx.Message);
|
||||
}
|
||||
|
||||
// 接口连接失败或返回错误,从本地数据库查询
|
||||
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 });
|
||||
// ERP 返回成功但没有数据,或调用失败:直接返回本地已查到的记录(本地有数据时不能给页面返回空)
|
||||
return Json(new { Code = 200, Data = dbMaterials });
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
@@ -211,51 +233,43 @@ namespace HHWMS.Web.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取物料的工序列表
|
||||
/// 获取工序列表:默认展示全部工序配置
|
||||
/// 具体使用哪道工序由生产订单决定,物料工序表在查到订单后再按订单内容更新
|
||||
/// </summary>
|
||||
/// <param name="materialCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetProcessesByMaterial(string materialCode)
|
||||
public IActionResult GetProcessesByMaterial()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(materialCode))
|
||||
var configs = LoadAllProcessConfigs();
|
||||
return Json(new
|
||||
{
|
||||
return Json(new { Code = 200, Data = new object[] { } });
|
||||
}
|
||||
|
||||
var processes = _unitWork.Find<MaterialProcess>(x => x.MaterialCode == materialCode && x.IsActive)
|
||||
.OrderBy(x => x.ProcessOrder)
|
||||
.Select(x => new
|
||||
Code = 200,
|
||||
Data = configs.Select(x => new
|
||||
{
|
||||
value = x.ID.ToString(),
|
||||
label = x.ProcessName,
|
||||
processCode = x.ProcessCode,
|
||||
processName = x.ProcessName
|
||||
})
|
||||
.ToList();
|
||||
if (processes.Count == 0)
|
||||
{
|
||||
processes = _unitWork.Find<ProcessConfig>(x => x.ID > 0)
|
||||
.OrderBy(x => x.Code)
|
||||
.Select(x => new
|
||||
{
|
||||
value = x.ID.ToString(),
|
||||
label = x.Name,
|
||||
processCode = x.Code,
|
||||
processName = x.Name
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
return Json(new { Code = 200, Data = processes });
|
||||
label = x.Name,
|
||||
processCode = x.Code,
|
||||
processName = x.Name
|
||||
}).ToList()
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = $"获取物料工序失败:{ex.Message}" });
|
||||
return Json(new { Code = 500, Msg = $"获取工序列表失败:{ex.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询全部工序配置
|
||||
/// </summary>
|
||||
private List<ProcessConfig> LoadAllProcessConfigs()
|
||||
{
|
||||
return _unitWork.Find<ProcessConfig>(x => x.ID > 0)
|
||||
.OrderBy(x => x.Code)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取物料的单据信息
|
||||
/// </summary>
|
||||
@@ -329,6 +343,12 @@ namespace HHWMS.Web.Controllers
|
||||
return Json(new { Code = 500, Msg = "物料不存在" });
|
||||
}
|
||||
|
||||
// 生产单号必填:入库时必须选择由订单列表带出的生产单号
|
||||
if (string.IsNullOrWhiteSpace(model.SourceCode))
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "请选择生产单号" });
|
||||
}
|
||||
|
||||
if (material.Qty == null || material.Qty <= 0)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "物料毛重没有设置,请设置后再执行入库" });
|
||||
@@ -348,33 +368,39 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
var materialProcessList = _unitWork.Find<MaterialProcess>(m => m.MaterialCode == material.MaterialCode);
|
||||
|
||||
var materialProcess = _unitWork.FindSingle<MaterialProcess>(m => m.ID == model.ProcessId);
|
||||
if (materialProcess == null)
|
||||
// 页面工序下拉来自工序配置表(ProcessConfig),优先按工序编码取,编码为空时退回按 ID 取
|
||||
ProcessConfig currentProcessConfig = null;
|
||||
if (!string.IsNullOrWhiteSpace(model.ProcessCode))
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "未找到此物料工序配置" });
|
||||
currentProcessConfig = _unitWork.FindSingle<ProcessConfig>(x => x.Code == model.ProcessCode);
|
||||
}
|
||||
if (currentProcessConfig == null)
|
||||
{
|
||||
currentProcessConfig = _unitWork.FindSingle<ProcessConfig>(x => x.ID == model.ProcessId);
|
||||
}
|
||||
if (currentProcessConfig == null)
|
||||
{
|
||||
return Json(new { Code = 500, Msg = "未找到所选工序配置,请重新选择工序" });
|
||||
}
|
||||
|
||||
// 下一道工序
|
||||
var nextProcess = materialProcessList
|
||||
// 筛选同一物料
|
||||
.Where(p => p.MaterialCode == material.MaterialCode)
|
||||
// 筛选顺序大于当前工序的工序
|
||||
.Where(p => p.ProcessOrder > materialProcess.ProcessOrder)
|
||||
// 按工序顺序升序排列(取最小的一个,即下一道)
|
||||
.OrderBy(p => p.ProcessOrder)
|
||||
// 取第一个(下一道工序)
|
||||
.FirstOrDefault();
|
||||
if (nextProcess == null)
|
||||
{
|
||||
// 没有下一道工序的话,默认下一道工序为99
|
||||
nextProcess = new MaterialProcess()
|
||||
{
|
||||
ProcessCode = "99"
|
||||
};
|
||||
}
|
||||
// 从字典查询工序对应的区域
|
||||
// 当前工序在物料工序表中的记录(用于定位下一道工序),没有则视为最后一道
|
||||
var currentMaterialProcess = materialProcessList
|
||||
.FirstOrDefault(p => p.ProcessCode == currentProcessConfig.Code);
|
||||
|
||||
// 下一道工序:物料工序表中顺序大于当前工序的最小一条;不存在则默认 99(工序结束)
|
||||
var nextProcess = currentMaterialProcess == null
|
||||
? null
|
||||
: materialProcessList
|
||||
// 筛选顺序大于当前工序的工序
|
||||
.Where(p => p.ProcessOrder > currentMaterialProcess.ProcessOrder)
|
||||
// 按工序顺序升序排列(取最小的一个,即下一道)
|
||||
.OrderBy(p => p.ProcessOrder)
|
||||
// 取第一个(下一道工序)
|
||||
.FirstOrDefault();
|
||||
|
||||
// 从字典查询下一道工序对应的区域
|
||||
var nextProcessConfig = _unitWork.FindSingle<ProcessConfig>(x =>
|
||||
x.Code == nextProcess.ProcessCode);
|
||||
x.Code == (nextProcess == null ? "99" : nextProcess.ProcessCode));
|
||||
var zoneName = nextProcessConfig?.Zone;
|
||||
|
||||
if (string.IsNullOrEmpty(zoneName))
|
||||
@@ -431,8 +457,8 @@ namespace HHWMS.Web.Controllers
|
||||
SourceCode = model.BillCode,//客户订单号
|
||||
ProduceCode = model.OrderId, // 单号
|
||||
ReceiptDetailId = model.SourceCode, // erpdetailid 回传使用
|
||||
BatchCode = materialProcess.ProcessCode, //erp回传使用 批次编码
|
||||
Batch = materialProcess.ProcessName,
|
||||
BatchCode = currentProcessConfig.Code, //erp回传使用 批次编码
|
||||
Batch = currentProcessConfig.Name,
|
||||
Lot = nextProcessConfig?.Name,
|
||||
Status = model.IsQualified ? "合格" : "不合格",
|
||||
TaskStatus = InventoryTaskStatusEnum.Locked,
|
||||
@@ -693,6 +719,8 @@ namespace HHWMS.Web.Controllers
|
||||
public string OrderId { get; set; }
|
||||
public string OperatorId { get; set; }
|
||||
public int ProcessId { get; set; }
|
||||
/// <summary>工序编码(页面工序下拉来自工序配置表 ProcessConfig)</summary>
|
||||
public string ProcessCode { get; set; }
|
||||
public string ProcessName { get; set; }
|
||||
public int Type { get; set; }
|
||||
public int Qty { get; set; }
|
||||
|
||||
@@ -95,18 +95,24 @@ namespace HHWMS.Web
|
||||
}
|
||||
else
|
||||
{
|
||||
// 框架调用ERP失败时备注只记 send,这里补一条带请求参数和错误原因的日志,便于排查
|
||||
var errMsg = apiResult?.Data?.Msg ?? apiResult?.ErrorMsg ?? "未获取到订单数据";
|
||||
Wtm.DoLog($"ERP接口返回失败:{errMsg}", ActionLogTypesEnum.Exception, "ERP", "MOWorkAPI",
|
||||
request: $"ErpCode=003, MoCode={receiptCode ?? "(空)"}, InvCode={vm.Entity?.MaterialCode ?? "(空)"}, InvDefine1={vm.Entity?.MaterialType ?? "(空)"}, StepCode={vm.Entity?.Batch ?? "(空)"}, Size=100, Page=1",
|
||||
result: errMsg);
|
||||
|
||||
return new ApiJsonResult<List<MoDetailItem>>()
|
||||
{
|
||||
Success = false,
|
||||
Msg = apiResult?.Data?.Msg ?? apiResult?.ErrorMsg ?? "未获取到订单数据"
|
||||
Msg = errMsg
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Wtm.DoLog("获取ERP订单数据", ActionLogTypesEnum.Normal, "GetReceiptDetails",
|
||||
request: $"入库单号:{receiptCode}",
|
||||
result: $"错误:{ex.Message}");
|
||||
Wtm.DoLog($"获取ERP订单数据异常:{ex.Message}", ActionLogTypesEnum.Normal, "GetReceiptDetails",
|
||||
request: $"入库单号:{receiptCode ?? "(空)"},物料:{vm?.Entity?.MaterialCode ?? "(空)"},图号:{vm?.Entity?.MaterialType ?? "(空)"},批次:{vm?.Entity?.Batch ?? "(空)"}",
|
||||
result: ex.ToString());
|
||||
return new ApiJsonResult<List<MoDetailItem>>()
|
||||
{
|
||||
Success = false,
|
||||
@@ -115,6 +121,59 @@ namespace HHWMS.Web
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 ERP 生产订单中获取工序路线并保存到物料工序表(只写工序,不创建入库单/明细)
|
||||
/// </summary>
|
||||
/// <param name="materialCode">物料编码(存货编码)</param>
|
||||
public async Task SyncMaterialProcessFromErp(string materialCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new LoadMoDetailListRequest
|
||||
{
|
||||
ErpCode = "003",
|
||||
InvCode = materialCode,
|
||||
StepCode = "32",
|
||||
Size = 100,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
var apiResult = await Wtm.CallAPI<LoadMoDetailListResponse>("ERP", "MOWorkAPI", HttpMethodEnum.POST, request, 5);
|
||||
|
||||
if (apiResult?.Data == null || apiResult.Data.Code != 0 || apiResult.Data.Data == null)
|
||||
{
|
||||
Wtm.DoLog($"同步物料工序失败:{apiResult?.Data?.Msg ?? apiResult?.ErrorMsg ?? "ERP未返回订单数据"}",
|
||||
ActionLogTypesEnum.Exception, "ERP", "MOWorkAPI",
|
||||
request: $"物料:{materialCode}, ErpCode=003, InvCode={materialCode}, StepCode=32, Size=100, Page=1",
|
||||
result: apiResult?.Data?.Msg ?? apiResult?.ErrorMsg ?? "ERP未返回订单数据");
|
||||
return;
|
||||
}
|
||||
|
||||
// 同一物料只按订单中的工序路线保存一次
|
||||
var items = apiResult.Data.Data
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.InvCode)
|
||||
&& x.ProcessRoute != null && x.ProcessRoute.Count > 0)
|
||||
.GroupBy(x => x.InvCode)
|
||||
.Select(g => g.First())
|
||||
.ToList();
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
await SaveProcessRoute(_unitwork, item.InvCode, item.ProcessRoute);
|
||||
}
|
||||
|
||||
Wtm.DoLog("同步物料工序", ActionLogTypesEnum.Normal, "SyncMaterialProcess",
|
||||
request: $"物料:{materialCode}",
|
||||
result: $"从ERP订单同步工序,涉及物料 {items.Count} 个");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Wtm.DoLog($"同步物料工序异常:{ex.Message}", ActionLogTypesEnum.Exception, "ERP", "MOWorkAPI",
|
||||
request: $"物料:{materialCode}, ErpCode=003, InvCode={materialCode}, StepCode=32, Size=100, Page=1",
|
||||
result: ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理订单数据并保存到本地数据库(照搬 LoadErpOrderJob)
|
||||
/// </summary>
|
||||
@@ -340,6 +399,12 @@ namespace HHWMS.Web
|
||||
/// </summary>
|
||||
private async Task SaveProcessRoute(IUnitWork unitWork, string materialCode, List<ProcessRouteItem> processRoute)
|
||||
{
|
||||
// 防御:物料编码为空会插入违规数据,工序路线为空会误删该物料已有工序
|
||||
if (string.IsNullOrWhiteSpace(materialCode) || processRoute == null || processRoute.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询已存在的工序路线
|
||||
var existingProcesses = unitWork.Find<MaterialProcess>(p => p.MaterialCode == materialCode).ToList();
|
||||
|
||||
|
||||
@@ -168,9 +168,9 @@
|
||||
type: [
|
||||
{ required: true, message: '请选择托盘类型', trigger: ['change', 'blur'] }
|
||||
],
|
||||
//sourceCode: [
|
||||
//{ required: true, message: '请选择生产单据', trigger: ['change', 'blur'] }
|
||||
//],
|
||||
sourceCode: [
|
||||
{ required: true, message: '请选择生产单号', trigger: ['change', 'blur'] }
|
||||
],
|
||||
//billCode: [
|
||||
//{ required: true, message: '请输入客户单据', trigger: ['change', 'blur'] }
|
||||
//],
|
||||
@@ -246,37 +246,27 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 根据物料加载工序列表
|
||||
const loadProcessesByMaterial = (materialCode) => {
|
||||
if (!materialCode) {
|
||||
form.processId = '';
|
||||
processOptions.value = [];
|
||||
return;
|
||||
}
|
||||
// 加载工序列表:默认展示全部工序,选完工序再由生产订单决定用哪道
|
||||
const loadProcesses = () => {
|
||||
processOptions.value = [];
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: { materialCode: materialCode },
|
||||
url: "/receipt/ReceiptIn/GetProcessesByMaterial",
|
||||
success: (json) => {
|
||||
if (json.Code == 200) {
|
||||
|
||||
const newOptions = json.Data.map(item => ({
|
||||
processOptions.value = (json.Data || []).map(item => ({
|
||||
...item,
|
||||
value: item.value,
|
||||
label: `${item.processCode} - ${item.processName}`
|
||||
}));
|
||||
// 使用新数组赋值,强制组件重新渲染
|
||||
processOptions.value = [...newOptions];
|
||||
|
||||
} else {
|
||||
Message.error(json.Msg || '加载物料工序失败');
|
||||
Message.error(json.Msg || '加载工序列表失败');
|
||||
processOptions.value = [];
|
||||
}
|
||||
},
|
||||
error: (xhr, status, error) => {
|
||||
Message.error('加载物料工序失败:' + error);
|
||||
Message.error('加载工序列表失败:' + error);
|
||||
processOptions.value = [];
|
||||
}
|
||||
});
|
||||
@@ -300,15 +290,24 @@
|
||||
|
||||
const searchMaterials = (keyword) => {
|
||||
axios.get(`/receipt/ReceiptIn/SearchMaterials?keyword=${encodeURIComponent(keyword)}`)
|
||||
.then(function (json) {
|
||||
if (json.data.Code == 200) {
|
||||
materialOptions.value = json.data.Data.map(item => ({
|
||||
.then(function (response) {
|
||||
// axios 返回的是响应对象,接口数据在 response.data 里
|
||||
const json = response.data;
|
||||
if (json.Code == 200) {
|
||||
materialOptions.value = (json.Data || []).map(item => ({
|
||||
...item,
|
||||
value: item.MaterialCode,
|
||||
label: `${item.MaterialCode} - ${item.MaterialType} - ${item.MaterialName}`
|
||||
}));
|
||||
|
||||
// 扫描/输入完整物料编码时,自动带出图号并加载工序
|
||||
const exactCode = (form.materialCode || '').trim();
|
||||
const exactItem = materialOptions.value.find(item => item.MaterialCode === exactCode);
|
||||
if (exactItem) {
|
||||
handleMaterialSelect(exactItem.value, null);
|
||||
}
|
||||
} else {
|
||||
Message.error(json.data.Msg);
|
||||
Message.error(json.Msg || '获取物料列表失败');
|
||||
materialOptions.value = [];
|
||||
}
|
||||
})
|
||||
@@ -324,7 +323,7 @@
|
||||
if (selectedMaterial) {
|
||||
form.materialCode = selectedMaterial.MaterialCode;
|
||||
form.name = selectedMaterial.MaterialType;
|
||||
// 选择物料后加载相关工序
|
||||
// 选择物料后重新加载全部工序(工序由后续的生产订单决定)
|
||||
// 先清空当前工序选择,避免显示旧数据
|
||||
form.processId = '';
|
||||
form.processName = '';
|
||||
@@ -335,9 +334,9 @@
|
||||
processOptions.value = [];
|
||||
orderOptions.value = [];
|
||||
|
||||
// 延迟加载新工序,确保先清空再加载
|
||||
// 延迟加载工序,确保先清空再加载
|
||||
nextTick(() => {
|
||||
loadProcessesByMaterial(selectedMaterial.MaterialCode);
|
||||
loadProcesses();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -345,7 +344,7 @@
|
||||
// 扫描物料码
|
||||
const scanMaterial = () => {
|
||||
if (!form.materialCode) return;
|
||||
loadProcessesByMaterial(form.materialCode);
|
||||
loadProcesses();
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
@@ -498,6 +497,8 @@
|
||||
|
||||
loadTrayTypes();
|
||||
loadOperators();
|
||||
// 页面加载即展示全部工序,不依赖物料工序配置
|
||||
loadProcesses();
|
||||
});
|
||||
|
||||
const operatorOptions = ref([]);
|
||||
@@ -543,7 +544,7 @@
|
||||
operatorIdRef,
|
||||
operatorInfoRef,
|
||||
focusNext,
|
||||
loadProcessesByMaterial,
|
||||
loadProcesses,
|
||||
processSelect,
|
||||
orderSelect,
|
||||
trayTypeOptions,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using HHWMS.Web.Models;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
@@ -10,6 +11,31 @@ namespace HHWMS.Web
|
||||
ListVM = new ShipmentHeaderListVM();
|
||||
LinkedVM = new ShipmentHeader_BatchEdit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除:先删除所选出库单的明细,再删除表头,避免残留明细导致后续单据下发报错
|
||||
/// </summary>
|
||||
public override bool DoBatchDelete()
|
||||
{
|
||||
var headerIds = (Ids ?? new string[0])
|
||||
.Select(x => int.TryParse(x, out var id) ? id : -1)
|
||||
.Where(x => x > 0)
|
||||
.ToList();
|
||||
|
||||
if (headerIds.Count > 0)
|
||||
{
|
||||
var details = DC.Set<ShipmentDetail>()
|
||||
.Where(x => headerIds.Contains(x.HeaderId))
|
||||
.ToList();
|
||||
if (details.Count > 0)
|
||||
{
|
||||
DC.Set<ShipmentDetail>().RemoveRange(details);
|
||||
}
|
||||
}
|
||||
|
||||
// base.DoBatchDelete 内部会统一 SaveChanges,明细与表头一并删除
|
||||
return base.DoBatchDelete();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -18,9 +18,10 @@ namespace HHWMS.Web
|
||||
{
|
||||
return new List<GridAction>
|
||||
{
|
||||
this.MakeAction("ShipmentHeader", "GetShipmentDetails", "获取ERP发货通知单", "",
|
||||
GridActionParameterTypesEnum.NoId, "shipment")
|
||||
.SetSize(500, 260),
|
||||
// 暂时不需要“获取ERP发货通知单”,按钮先注释掉
|
||||
//this.MakeAction("ShipmentHeader", "GetShipmentDetails", "获取ERP发货通知单", "",
|
||||
// GridActionParameterTypesEnum.NoId, "shipment")
|
||||
// .SetSize(500, 260),
|
||||
this.MakeAction("ShipmentHeader", "Allocate", "分配/下发", "",
|
||||
GridActionParameterTypesEnum.SingleId, "shipment")
|
||||
.SetSize(1250, 820)
|
||||
@@ -75,6 +76,7 @@ namespace HHWMS.Web
|
||||
.CheckContain(Searcher.Code, x => x.Code)
|
||||
.CheckContain(Searcher.BillType, x => x.BillType)
|
||||
.CheckEqual(Searcher.FirstStatus, x => x.FirstStatus)
|
||||
.CheckContain(Searcher.Remark, x => x.Remark)
|
||||
.Select(x => new ShipmentHeader_View
|
||||
{
|
||||
ID = x.ID,
|
||||
|
||||
@@ -22,6 +22,10 @@ namespace HHWMS.Web
|
||||
[Display(Name = "Receipt.LastStatus")]
|
||||
public ShipStatusEnum? LastStatus { get; set; }
|
||||
|
||||
/// <summary>备注(模糊查询)</summary>
|
||||
[Display(Name = "_Admin.Remark")]
|
||||
public String Remark { get; set; }
|
||||
|
||||
protected override void InitVM()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -47,6 +47,13 @@ namespace HHWMS.Web
|
||||
|
||||
public override void DoDelete()
|
||||
{
|
||||
// 先删除该出库单下的明细,避免表头删除后残留明细导致后续单据下发报错
|
||||
var details = DC.Set<ShipmentDetail>().Where(x => x.HeaderId == Entity.ID).ToList();
|
||||
if (details.Count > 0)
|
||||
{
|
||||
DC.Set<ShipmentDetail>().RemoveRange(details);
|
||||
}
|
||||
// base.DoDelete 内部会统一 SaveChanges,明细与表头一并删除
|
||||
base.DoDelete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
|
||||
<wt:searchpanel vm="@Model" reset-btn="true">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Three">
|
||||
@* <wt:textbox field="Searcher.SourceCode" /> *@
|
||||
<wt:textbox field="Searcher.Code" />
|
||||
<wt:textbox field="Searcher.SourceCode" />
|
||||
<wt:combobox field="Searcher.BillType" items="ShipTypes" />
|
||||
<wt:combobox field="Searcher.FirstStatus" empty-text="@Localizer["Sys.All"]" />
|
||||
<wt:textbox field="Searcher.Remark" />
|
||||
@* <wt:combobox field="Searcher.LastStatus" empty-text="@Localizer["Sys.All"]" /> *@
|
||||
</wt:row>
|
||||
</wt:searchpanel>
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
using Quartz;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Core.Support.Quartz;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 任务归档 Job(方案 5.5 / 9.6,每日执行):
|
||||
/// 1) AgvTask 超 1 个月终态任务(99/95/100)先镜像备份到 AgvTaskHistory,再从主表物理清除;
|
||||
/// 2) AgvTaskLog 超 6 个月日志镜像备份到 AgvTaskLogHistory 后清除。
|
||||
/// 事务包裹防重复归档;每批限量处理,失败回滚下次重跑天然重试。
|
||||
/// </summary>
|
||||
[PersistJobDataAfterExecution]
|
||||
[DisallowConcurrentExecution]
|
||||
public class AgvTaskArchiveJob : WtmJob
|
||||
{
|
||||
public override async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var unitWork = new UnitWork(Wtm);
|
||||
var now = DateTime.Now;
|
||||
const int batchSize = 200;
|
||||
|
||||
await ArchiveTasksAsync(unitWork, now, batchSize);
|
||||
await ArchiveLogsAsync(unitWork, now, batchSize);
|
||||
|
||||
// 更新 SysJob 触发时间
|
||||
var job = unitWork.FindSingle<SysJob>(x => x.JobName == context.JobDetail.Key.Name);
|
||||
if (job != null)
|
||||
{
|
||||
job.LastFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
context.FireTimeUtc.DateTime,
|
||||
TimeZoneInfo.Local);
|
||||
if (context.NextFireTimeUtc != null)
|
||||
{
|
||||
job.NextFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
context.NextFireTimeUtc.Value.DateTime,
|
||||
TimeZoneInfo.Local);
|
||||
}
|
||||
unitWork.Update(job);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Wtm.DoLog("AGV任务归档失败", ActionLogTypesEnum.Job,
|
||||
"AgvTaskArchiveJob", request: "error", result: ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务归档:超 1 个月终态任务镜像到 AgvTaskHistory 后物理删除主表记录
|
||||
/// </summary>
|
||||
private async Task ArchiveTasksAsync(UnitWork unitWork, DateTime now, int batchSize)
|
||||
{
|
||||
var tasks = unitWork.Find<AgvTask>(x =>
|
||||
x.CreateTime != null
|
||||
&& x.CreateTime < now.AddMonths(-1)
|
||||
&& (x.AgvStatus == AgvTaskStatusEnum.完成
|
||||
|| x.AgvStatus == AgvTaskStatusEnum.取消
|
||||
|| x.AgvStatus == AgvTaskStatusEnum.完成联动失败))
|
||||
.OrderBy(x => x.CreateTime)
|
||||
.Take(batchSize)
|
||||
.ToList();
|
||||
if (tasks.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var transaction = Wtm.DC.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
var histories = tasks.Select(t => new AgvTaskHistory
|
||||
{
|
||||
TaskNo = t.TaskNo,
|
||||
SourceCode = t.SourceCode,
|
||||
SourceSystem = t.SourceSystem,
|
||||
AgvTaskType = t.AgvTaskType,
|
||||
FromLocation = t.FromLocation,
|
||||
ToLocation = t.ToLocation,
|
||||
FromFloor = t.FromFloor,
|
||||
ToFloor = t.ToFloor,
|
||||
ContainerCode = t.ContainerCode,
|
||||
Priority = t.Priority,
|
||||
AgvStatus = t.AgvStatus,
|
||||
AgvCarNo = t.AgvCarNo,
|
||||
ErrorMsg = t.ErrorMsg,
|
||||
BillType = t.BillType,
|
||||
Details = t.Details,
|
||||
ArchivedAt = now,
|
||||
CreateTime = t.CreateTime,
|
||||
CreateBy = t.CreateBy,
|
||||
UpdateTime = t.UpdateTime,
|
||||
UpdateBy = t.UpdateBy
|
||||
}).ToList();
|
||||
unitWork.BatchAdd(histories);
|
||||
unitWork.BatchDelete(tasks);
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日志归档:超 6 个月日志镜像到 AgvTaskLogHistory 后物理删除
|
||||
/// </summary>
|
||||
private async Task ArchiveLogsAsync(UnitWork unitWork, DateTime now, int batchSize)
|
||||
{
|
||||
var logs = unitWork.Find<AgvTaskLog>(x =>
|
||||
x.CreateTime != null
|
||||
&& x.CreateTime < now.AddMonths(-6))
|
||||
.OrderBy(x => x.CreateTime)
|
||||
.Take(batchSize)
|
||||
.ToList();
|
||||
if (logs.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var transaction = Wtm.DC.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
var histories = logs.Select(l => new AgvTaskLogHistory
|
||||
{
|
||||
TaskNo = l.TaskNo,
|
||||
OrderId = l.OrderId,
|
||||
FromStatus = l.FromStatus,
|
||||
ToStatus = l.ToStatus,
|
||||
Event = l.Event,
|
||||
Direction = l.Direction,
|
||||
EventTime = l.EventTime,
|
||||
SourceIp = l.SourceIp,
|
||||
DurationMs = l.DurationMs,
|
||||
RequestJson = l.RequestJson,
|
||||
ResponseJson = l.ResponseJson,
|
||||
Operator = l.Operator,
|
||||
Remark = l.Remark,
|
||||
ArchivedAt = now,
|
||||
CreateTime = l.CreateTime,
|
||||
CreateBy = l.CreateBy,
|
||||
UpdateTime = l.UpdateTime,
|
||||
UpdateBy = l.UpdateBy
|
||||
}).ToList();
|
||||
unitWork.BatchAdd(histories);
|
||||
unitWork.BatchDelete(logs);
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
using HHWMS.Web.Services.Agv;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Quartz;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Core.Support.Quartz;
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 定时下发 Job:周期扫描 新建(0)/异常(90) 任务自动下发。
|
||||
/// 启停方式:在【系统管理→定时任务】页面新增本条记录,Cron 建议 0 */2 * * * ?(每 2 分钟)。
|
||||
/// 依赖 DispatchTaskAsync 内部的 FOR UPDATE 行锁 + 状态校验,天然防并发/防重复下发。
|
||||
/// 日志双通道:Console 直写控制台(现场直跑 exe 可直接观察是否触发),Wtm.DoLog 写 ActionLogs 表。
|
||||
/// </summary>
|
||||
[PersistJobDataAfterExecution]
|
||||
[DisallowConcurrentExecution]
|
||||
public class AgvTaskDispatchJob : WtmJob
|
||||
{
|
||||
// 无参构造 —— WtmJob 反射创建 Job 实例必须有无参构造
|
||||
public AgvTaskDispatchJob() { }
|
||||
|
||||
public override async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
// 每次触发必输出心跳行:用于区分「调度没触发」和「触发了但没任务」
|
||||
WriteLog($"Job触发,计划时间 {Fmt(context.ScheduledFireTimeUtc)},下次触发 {Fmt(context.NextFireTimeUtc)}");
|
||||
try
|
||||
{
|
||||
var sp = context.JobDetail.JobDataMap.Get("Sp") as IServiceProvider;
|
||||
if (sp == null)
|
||||
{
|
||||
WriteLog("错误:未能从 JobDataMap 获取 IServiceProvider");
|
||||
DoJobLog("AGV定时下发Job异常", "error", "未能从 JobDataMap 获取 IServiceProvider");
|
||||
return;
|
||||
}
|
||||
// AgvTaskService 为 Scoped 服务,root provider 直接解析会抛
|
||||
// Cannot resolve scoped service(ValidateScopes),必须创建独立作用域
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var service = scope.ServiceProvider.GetService(typeof(AgvTaskService)) as AgvTaskService;
|
||||
if (service == null)
|
||||
{
|
||||
WriteLog("错误:DI 容器中未注册 AgvTaskService");
|
||||
DoJobLog("AGV定时下发Job异常", "error", "DI 容器中未注册 AgvTaskService");
|
||||
return;
|
||||
}
|
||||
WriteLog("依赖解析成功:IServiceScope / AgvTaskService 均可用");
|
||||
await DispatchBatch(context, service);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 输出完整异常堆栈到控制台,避免只有 Message 无法定位
|
||||
WriteLog($"Job执行异常:{ex}");
|
||||
DoJobLog("AGV定时下发Job异常", "error", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫描待下发任务并逐条下发,输出每条结果与汇总
|
||||
/// </summary>
|
||||
private async Task DispatchBatch(IJobExecutionContext context, AgvTaskService service)
|
||||
{
|
||||
var unitWork = new UnitWork(Wtm);
|
||||
const int batchSize = 20;
|
||||
|
||||
var tasks = unitWork.Find<AgvTask>(x =>
|
||||
x.AgvStatus == AgvTaskStatusEnum.新建
|
||||
|| x.AgvStatus == AgvTaskStatusEnum.异常)
|
||||
.OrderByDescending(x => x.Priority)
|
||||
.ThenBy(x => x.CreateTime)
|
||||
.Take(batchSize)
|
||||
.ToList();
|
||||
|
||||
WriteLog($"扫描完成:待下发任务 {tasks.Count} 条(状态=新建/异常,批量上限 {batchSize})"
|
||||
+ (tasks.Count > 0 ? ",任务号:" + string.Join(",", tasks.Select(t => t.TaskNo)) : ""));
|
||||
|
||||
if (tasks.Count == 0)
|
||||
{
|
||||
UpdateJobFireTime(unitWork, context);
|
||||
return;
|
||||
}
|
||||
|
||||
int success = 0, fail = 0;
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
try
|
||||
{
|
||||
await service.DispatchTaskAsync(task.TaskNo);
|
||||
success++;
|
||||
WriteLog($"下发成功:{task.TaskNo}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
fail++;
|
||||
WriteLog($"下发失败:{task.TaskNo},原因:{ex.Message}");
|
||||
DoJobLog($"AGV定时下发失败:{task.TaskNo}", task.TaskNo, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
WriteLog($"本轮执行结束:共 {tasks.Count} 条,成功 {success},失败 {fail}");
|
||||
if (success > 0 || fail > 0)
|
||||
{
|
||||
DoJobLog("AGV定时下发", $"batch={tasks.Count}", $"ok={success},fail={fail}");
|
||||
}
|
||||
|
||||
UpdateJobFireTime(unitWork, context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 SysJob 上 LastFireTime / NextFireTime;内部异常仅记日志,不影响下发主流程
|
||||
/// </summary>
|
||||
private static void UpdateJobFireTime(UnitWork unitWork, IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var job = unitWork.FindSingle<SysJob>(x => x.JobName == context.JobDetail.Key.Name);
|
||||
if (job == null)
|
||||
{
|
||||
WriteLog($"提示:SysJob 表中未找到 JobName={context.JobDetail.Key.Name} 的记录,LastFireTime 未更新");
|
||||
return;
|
||||
}
|
||||
job.LastFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
context.FireTimeUtc.DateTime, TimeZoneInfo.Local);
|
||||
if (context.NextFireTimeUtc != null)
|
||||
{
|
||||
job.NextFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local);
|
||||
}
|
||||
unitWork.Update(job);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLog($"更新 LastFireTime 失败(不影响下发):{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写 ActionLogs 日志;Wtm 不可用时静默跳过(控制台日志已兜底)
|
||||
/// </summary>
|
||||
private void DoJobLog(string title, string request, string result)
|
||||
{
|
||||
try
|
||||
{
|
||||
Wtm.DoLog(title, ActionLogTypesEnum.Job, "AgvTaskDispatchJob", request: request, result: result);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Wtm 为 null 等场景忽略,控制台日志已兜底
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控制台直出日志(带时间戳),用于确认 Job 是否真实触发
|
||||
/// </summary>
|
||||
private static void WriteLog(string message)
|
||||
{
|
||||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [AgvTaskDispatchJob] {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可空时间格式化(本地时间),空值显示 -
|
||||
/// </summary>
|
||||
private static string Fmt(DateTimeOffset? time)
|
||||
{
|
||||
return time.HasValue ? time.Value.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss") : "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Models.Agv;
|
||||
using HHWMS.Web.Services.Agv;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Quartz;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Core.Support.Quartz;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// AGV 完成联动失败自动重试 Job:周期扫描 99(完成联动失败)任务自动重试完成联动。
|
||||
/// 启停方式:在【系统管理→定时任务】页面新增本条记录,Cron 建议 0 */5 * * * ?(每 5 分钟)。
|
||||
/// 注意:完成联动失败时库存/流水/容器/库位已回滚,ERP 报工可能已成功,重试时 ERP 侧需保证幂等性。
|
||||
/// 日志双通道:Console 直写控制台,Wtm.DoLog 写 ActionLogs 表。
|
||||
/// </summary>
|
||||
[PersistJobDataAfterExecution]
|
||||
[DisallowConcurrentExecution]
|
||||
public class AgvTaskRetryFinishJob : WtmJob
|
||||
{
|
||||
// 无参构造 —— WtmJob 反射创建 Job 实例必须有无参构造
|
||||
public AgvTaskRetryFinishJob() { }
|
||||
|
||||
public override async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
WriteLog($"Job触发,计划时间 {Fmt(context.ScheduledFireTimeUtc)},下次触发 {Fmt(context.NextFireTimeUtc)}");
|
||||
try
|
||||
{
|
||||
var sp = context.JobDetail.JobDataMap.Get("Sp") as IServiceProvider;
|
||||
if (sp == null)
|
||||
{
|
||||
WriteLog("错误:未能从 JobDataMap 获取 IServiceProvider");
|
||||
DoJobLog("AGV完成联动重试Job异常", "error", "未能从 JobDataMap 获取 IServiceProvider");
|
||||
return;
|
||||
}
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var service = scope.ServiceProvider.GetService(typeof(AgvTaskService)) as AgvTaskService;
|
||||
if (service == null)
|
||||
{
|
||||
WriteLog("错误:DI 容器中未注册 AgvTaskService");
|
||||
DoJobLog("AGV完成联动重试Job异常", "error", "DI 容器中未注册 AgvTaskService");
|
||||
return;
|
||||
}
|
||||
WriteLog("依赖解析成功:IServiceScope / AgvTaskService 均可用");
|
||||
await RetryBatch(context, service);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLog($"Job执行异常:{ex}");
|
||||
DoJobLog("AGV完成联动重试Job异常", "error", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫描完成联动失败任务并逐条重试完成联动,输出每条结果与汇总
|
||||
/// </summary>
|
||||
private async Task RetryBatch(IJobExecutionContext context, AgvTaskService service)
|
||||
{
|
||||
var unitWork = new UnitWork(Wtm);
|
||||
const int batchSize = 20;
|
||||
|
||||
var tasks = unitWork.Find<AgvTask>(x => x.AgvStatus == AgvTaskStatusEnum.完成联动失败)
|
||||
.OrderByDescending(x => x.Priority)
|
||||
.ThenBy(x => x.CreateTime)
|
||||
.Take(batchSize)
|
||||
.ToList();
|
||||
|
||||
WriteLog($"扫描完成:待重试完成联动任务 {tasks.Count} 条(状态=完成联动失败99,批量上限 {batchSize})"
|
||||
+ (tasks.Count > 0 ? ",任务号:" + string.Join(",", tasks.Select(t => t.TaskNo)) : ""));
|
||||
|
||||
if (tasks.Count == 0)
|
||||
{
|
||||
UpdateJobFireTime(unitWork, context);
|
||||
return;
|
||||
}
|
||||
|
||||
int success = 0, fail = 0;
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
try
|
||||
{
|
||||
await service.RetryFinishLinkAsync(task.TaskNo);
|
||||
success++;
|
||||
WriteLog($"重试完成联动成功:{task.TaskNo}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
fail++;
|
||||
WriteLog($"重试完成联动失败:{task.TaskNo},原因:{ex.Message}");
|
||||
DoJobLog($"AGV重试完成联动失败:{task.TaskNo}", task.TaskNo, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
WriteLog($"本轮执行结束:共 {tasks.Count} 条,成功 {success},失败 {fail}");
|
||||
if (success > 0 || fail > 0)
|
||||
{
|
||||
DoJobLog("AGV完成联动重试", $"batch={tasks.Count}", $"ok={success},fail={fail}");
|
||||
}
|
||||
|
||||
UpdateJobFireTime(unitWork, context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 SysJob 上 LastFireTime / NextFireTime;内部异常仅记日志,不影响主流程
|
||||
/// </summary>
|
||||
private static void UpdateJobFireTime(UnitWork unitWork, IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var job = unitWork.FindSingle<SysJob>(x => x.JobName == context.JobDetail.Key.Name);
|
||||
if (job == null)
|
||||
{
|
||||
WriteLog($"提示:SysJob 表中未找到 JobName={context.JobDetail.Key.Name} 的记录,LastFireTime 未更新");
|
||||
return;
|
||||
}
|
||||
job.LastFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
context.FireTimeUtc.DateTime, TimeZoneInfo.Local);
|
||||
if (context.NextFireTimeUtc != null)
|
||||
{
|
||||
job.NextFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local);
|
||||
}
|
||||
unitWork.Update(job);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLog($"更新 LastFireTime 失败(不影响重试):{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写 ActionLogs 日志;Wtm 不可用时静默跳过
|
||||
/// </summary>
|
||||
private void DoJobLog(string title, string request, string result)
|
||||
{
|
||||
try
|
||||
{
|
||||
Wtm.DoLog(title, ActionLogTypesEnum.Job, "AgvTaskRetryFinishJob", request: request, result: result);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Wtm 为 null 等场景忽略,控制台日志已兜底
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控制台直出日志(带时间戳)
|
||||
/// </summary>
|
||||
private static void WriteLog(string message)
|
||||
{
|
||||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [AgvTaskRetryFinishJob] {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可空时间格式化(本地时间),空值显示 -
|
||||
/// </summary>
|
||||
private static string Fmt(DateTimeOffset? time)
|
||||
{
|
||||
return time.HasValue ? time.Value.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss") : "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,9 @@ namespace HHWMS.Web
|
||||
this.MakeGridHeader(x => x.JobName)
|
||||
.SetFormat((entity,v) =>
|
||||
{
|
||||
return AllJob.FirstOrDefault(x => x.Value.ToString() == entity.JobName).Text;
|
||||
// null 保护:数据库里的 JobName 在 AllJob 里找不到匹配时返回原名,不抛空指针
|
||||
var match = AllJob.FirstOrDefault(x => x.Value.ToString() == entity.JobName);
|
||||
return match?.Text ?? entity.JobName ?? "-";
|
||||
}),
|
||||
this.MakeGridHeader(x => x.JobGroup).SetHide(),
|
||||
this.MakeGridHeader(x => x.MethodName),
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs
|
||||
{
|
||||
var query = DC.Set<ActionLog>()
|
||||
.CheckContain(Searcher.ITCode, x=>x.ITCode)
|
||||
.CheckContain(Searcher.ModuleName, x=>x.ModuleName)
|
||||
.CheckContain(Searcher.ActionUrl, x=>x.ActionUrl)
|
||||
.CheckContain(Searcher.LogType, x=>x.LogType)
|
||||
.CheckContain(Searcher.IP, x=>x.IP)
|
||||
|
||||
@@ -12,6 +12,10 @@ namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs
|
||||
[Display(Name = "_Admin.Account")]
|
||||
public string ITCode { get; set; }
|
||||
|
||||
/// <summary>模块名称(模糊匹配,用于按业务模块筛选日志,如「物料」、「AGV」、「mes」)</summary>
|
||||
[Display(Name = "模块")]
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
[Display(Name = "Url")]
|
||||
public string ActionUrl { get; set; }
|
||||
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
<wt:searchpanel vm="@Model" reset-btn="true">
|
||||
<wt:row items-per-row=" ItemsPerRowEnum.Three">
|
||||
<wt:combobox field="Searcher.LogType" empty-text="@Localizer["Sys.All"]" />
|
||||
<wt:textbox field="Searcher.ModuleName" />
|
||||
<wt:textbox field="Searcher.ITCode" />
|
||||
</wt:row>
|
||||
<wt:row items-per-row=" ItemsPerRowEnum.Three">
|
||||
<wt:textbox field="Searcher.ActionUrl" />
|
||||
<wt:textbox field="Searcher.IP" />
|
||||
<wt:textbox field="Searcher.Duration" />
|
||||
</wt:row>
|
||||
<wt:row items-per-row=" ItemsPerRowEnum.Three">
|
||||
<wt:datetime field="Searcher.ActionTime" type="DateTime" range="true" />
|
||||
<wt:textbox field="Searcher.IP" />
|
||||
<wt:textbox field="Searcher.Duration" />
|
||||
</wt:row>
|
||||
</wt:searchpanel>
|
||||
|
||||
|
||||
Reference in new issue
Block a user