318 lines
9.3 KiB
C#
318 lines
9.3 KiB
C#
using System;
|
||
using System.Linq;
|
||
using System.Security.Cryptography;
|
||
using HHWMS.Web.Models;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.EntityFrameworkCore;
|
||
using WalkingTec.Mvvm.Core;
|
||
using WalkingTec.Mvvm.Core.Extensions;
|
||
using WalkingTec.Mvvm.Mvc;
|
||
|
||
namespace HHWMS.Web.Controllers
|
||
{
|
||
[Area("taskManage")]
|
||
[ActionDescription("任务主表")]
|
||
public partial class TaskHeaderController : BaseController
|
||
{
|
||
private readonly IUnitWork _unitwork;
|
||
|
||
public TaskHeaderController(IUnitWork unitwork)
|
||
{
|
||
_unitwork = unitwork;
|
||
}
|
||
|
||
#region Search
|
||
|
||
[ActionDescription("Sys.Search")]
|
||
public ActionResult Index()
|
||
{
|
||
var vm = Wtm.CreateVM<TaskHeaderListVM>();
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[ActionDescription("Sys.Search")]
|
||
[HttpPost]
|
||
public string Search(TaskHeaderSearcher searcher)
|
||
{
|
||
var vm = Wtm.CreateVM<TaskHeaderListVM>(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<TaskHeaderVM>();
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.Create")]
|
||
public ActionResult Create(TaskHeaderVM 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<TaskHeaderVM>(id);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[ActionDescription("Sys.Edit")]
|
||
[HttpPost]
|
||
[ValidateFormItemOnly]
|
||
public ActionResult Edit(TaskHeaderVM 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<TaskHeaderVM>(id);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[ActionDescription("Sys.Delete")]
|
||
[HttpPost]
|
||
public ActionResult Delete(string id, IFormCollection nouse)
|
||
{
|
||
var vm = Wtm.CreateVM<TaskHeaderVM>(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<TaskHeaderVM>(id);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
#endregion Details
|
||
|
||
#region BatchEdit
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.BatchEdit")]
|
||
public ActionResult BatchEdit(string[] IDs)
|
||
{
|
||
var vm = Wtm.CreateVM<TaskHeaderBatchVM>(Ids: IDs);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.BatchEdit")]
|
||
public ActionResult DoBatchEdit(TaskHeaderBatchVM vm, IFormCollection nouse)
|
||
{
|
||
if (!ModelState.IsValid || !vm.DoBatchEdit())
|
||
{
|
||
return PartialView("BatchEdit", vm);
|
||
}
|
||
else
|
||
{
|
||
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
|
||
}
|
||
}
|
||
|
||
#endregion BatchEdit
|
||
|
||
#region BatchDelete
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.BatchDelete")]
|
||
public ActionResult BatchDelete(string[] IDs)
|
||
{
|
||
var vm = Wtm.CreateVM<TaskHeaderBatchVM>(Ids: IDs);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.BatchDelete")]
|
||
public ActionResult DoBatchDelete(TaskHeaderBatchVM vm, IFormCollection nouse)
|
||
{
|
||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||
{
|
||
return PartialView("BatchDelete", vm);
|
||
}
|
||
else
|
||
{
|
||
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
|
||
}
|
||
}
|
||
|
||
#endregion BatchDelete
|
||
|
||
#region Import
|
||
|
||
[ActionDescription("Sys.Import")]
|
||
public ActionResult Import()
|
||
{
|
||
var vm = Wtm.CreateVM<TaskHeaderImportVM>();
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.Import")]
|
||
public ActionResult Import(TaskHeaderImportVM vm, IFormCollection nouse)
|
||
{
|
||
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
||
{
|
||
return PartialView(vm);
|
||
}
|
||
else
|
||
{
|
||
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
|
||
}
|
||
}
|
||
|
||
#endregion Import
|
||
|
||
#region Export
|
||
|
||
[ActionDescription("Sys.Export")]
|
||
[HttpPost]
|
||
public IActionResult ExportExcel(TaskHeaderListVM vm)
|
||
{
|
||
return vm.GetExportData();
|
||
}
|
||
|
||
#endregion Export
|
||
|
||
#region 任务下发
|
||
|
||
[ActionDescription("TaskHeader.Assign")]
|
||
public ActionResult Assign(string id)
|
||
{
|
||
var task = _unitwork.Find<TaskHeader>(x => x.ID == int.Parse(id)).Include(x => x.TaskDetails).FirstOrDefault();
|
||
if(task == null)
|
||
return FFResult().RefreshGrid().Alert($"操作失败,此任务不存在!");
|
||
var taskInfo = new TaskInfo();
|
||
var beginlocation = _unitwork.FindSingle<Location>(x => x.Code.Equals(task.FromLocation));
|
||
var endLocation = _unitwork.FindSingle<Location>(x => x.Code.Equals(task.ToLocation));
|
||
var start = new CoordPos();
|
||
var end = new CoordPos();
|
||
if ((int)task.TaskType == 3 || (int)task.TaskType == 4)
|
||
{
|
||
// 盘料起点终点 与普通任务起点终点不一样,编码未在location中保存
|
||
var taskdel = task.TaskDetails.FirstOrDefault(x => x.Status.Equals(TaskStatusEnum.新建));
|
||
start.X = int.Parse(taskdel.Batch.Split("-")[0]);
|
||
start.Y = int.Parse(taskdel.Batch.Split("-")[1]);
|
||
start.Z = int.Parse(taskdel.Batch.Split("-")[2]);
|
||
|
||
end.X = int.Parse(taskdel.Lot.Split("-")[0]);
|
||
end.Y = int.Parse(taskdel.Lot.Split("-")[1]);
|
||
end.Z = int.Parse(taskdel.Lot.Split("-")[2]);
|
||
|
||
taskInfo.TaskId = taskdel.TaskHeader.TaskNo;
|
||
taskInfo.TaskType = (int)task.TaskType;
|
||
taskInfo.ObjId = taskdel.ContainerCode;
|
||
taskInfo.StartType = int.Parse(task.Station);
|
||
taskInfo.StartPos = start;
|
||
taskInfo.EndType = int.Parse(task.Station);
|
||
taskInfo.EndPos = end;
|
||
}
|
||
else
|
||
{
|
||
start.X = beginlocation.Line;
|
||
start.Y = beginlocation.Row;
|
||
start.Z = beginlocation.Layer;
|
||
|
||
end.X = endLocation.Line;
|
||
end.Y = endLocation.Row;
|
||
end.Z = endLocation.Layer;
|
||
|
||
taskInfo.TaskId = task.TaskNo;
|
||
taskInfo.TaskType = (int)task.TaskType;
|
||
taskInfo.ObjId = task.ContainerCode;
|
||
taskInfo.StartType = int.Parse(task.Station);
|
||
taskInfo.StartPos = start;
|
||
taskInfo.EndType = int.Parse(task.Station);
|
||
taskInfo.EndPos = end;
|
||
}
|
||
|
||
var res = Wtm.CallAPI<ApiJsonResult<dynamic>>("WCS", "TaskAssign", HttpMethodEnum.POST, taskInfo).Result.Data;
|
||
try
|
||
{
|
||
if ((bool)res?.Success)
|
||
{
|
||
// 删除已回传MES的任务
|
||
//_unitwork.Delete(item);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return FFResult().Alert($"操作失败,{ex.Message}");
|
||
}
|
||
return FFResult().RefreshGrid();
|
||
}
|
||
|
||
#endregion 任务下发
|
||
}
|
||
}
|