using System;
using System.Linq;
using System.Web.Http;
using HH.WCS.Mobox3.RiDong.apiMethod;
using HH.WCS.Mobox3.RiDong.dispatch;
using HH.WCS.Mobox3.RiDong.dto;
using HH.WCS.Mobox3.RiDong.generalMethod;
using HH.WCS.Mobox3.RiDong.models;
using HH.WCS.Mobox3.RiDong.util;
using HH.WCS.Mobox3.RiDong.wms;
namespace HH.WCS.Mobox3.RiDong.api;
///
/// 综合性接口
///
public class SynthesizeController : ApiController
{
///
/// 创建作业
///
/// 存在中转货位(入库、出库、盘点入、盘点出)
///
[HttpPost]
public ApiModel.SimpleResult AddOperation(OperationDto input)
{
return SynthesizeService.AddOperation(input);
}
///
/// 作业取消
///
///
///
[HttpPost]
public ApiModel.SimpleResult CancelOperation(ApiModel.MoboxTaskBase model)
{
var result = new ApiModel.SimpleResult();
var operation = AdoSqlMethod.QueryFirst(p => p.S_CODE == model.TaskNo && p.N_B_STATE != 7);
if (operation == null)
{
result.resultCode = -1;
result.resultMsg = "当前任务号不存在或任务已取消";
return result;
}
var tasks = AdoSqlMethod.QueryList(p => p.S_OP_CODE == operation.S_CODE);
// 当前任务数量和当前未执行的任务数量一致的情况下,允许取消任务
if (tasks.Count == tasks.Count(p => p.S_OP_CODE == operation.S_CODE && p.N_B_STATE < 3))
{
// 允许取消任务
foreach (var task in tasks)
{
// 判断任务
if (task.N_SCHEDULE_TYPE == 2 && task.N_B_STATE > 0 && task.N_B_STATE < 3)
{
// 通知agv取消任务
NDCHelper.Cancel(task.S_CODE.Trim());
}
task.N_B_STATE = 5;
task.S_B_STATE = "取消";
task.T_MODIFY = DateTime.Now;
task.T_END_TIME = DateTime.Now;
}
AdoSqlMethod.UpdateList(tasks, p => new { p.N_B_STATE, p.S_B_STATE, p.T_MODIFY, p.T_END_TIME });
operation.N_B_STATE = 7;
operation.S_B_STATE = "取消";
operation.T_MODIFY = DateTime.Now;
operation.T_END_TIME = DateTime.Now;
AdoSqlMethod.UpdateFirst(operation,
p => new { p.N_B_STATE, p.S_B_STATE, p.T_MODIFY, p.T_END_TIME });
var container = AdoSqlMethod.QueryFirst(p => p.S_CODE == operation.S_CNTR_CODE);
// 修改容器状态
container.T_MODIFY = DateTime.Now;
container.N_LOCK_STATE = 0;
string loc = "";
// 解锁
if (operation.N_TYPE == 1 || operation.N_TYPE == 3)
{
container.C_ENABLE = 'N';
loc = operation.S_END_LOC;
}
else if (operation.N_TYPE == 2 || operation.N_TYPE == 4 || operation.N_TYPE == 5 || operation.N_TYPE == 6 || operation.N_TYPE == 7)
{
container.C_ENABLE = 'Y';
loc = operation.S_START_LOC;
}
LocationHelper.UnLockLoc(loc);
AdoSqlMethod.UpdateFirst(container, p => new { p.C_ENABLE, p.T_MODIFY, p.N_LOCK_STATE });
result.resultCode = 0;
result.resultMsg = "任务取消成功";
return result;
}
result.resultCode = -1;
result.resultMsg = "作业正在执行中,不可取消";
return result;
}
///
/// 任务优先级
///
///
[HttpPost]
public ApiModel.SimpleResult TaskPriority(ApiModel.MoboxTaskBase model)
{
var result = new ApiModel.SimpleResult();
var operation = AdoSqlMethod.QueryFirst(p => p.S_CODE == model.TaskNo);
if (operation == null)
{
result.resultCode = -1;
result.resultMsg = $"作业不存在!,传递的任务号为{model.TaskNo}";
return result;
}
// 任务存在,判断任务类型
if (operation.N_TYPE is 1 or 3)
{
result.resultCode = -1;
result.resultMsg = "入库类型任务无法提升优先级";
return result;
}
var task = AdoSqlMethod.QueryFirst(p =>
p.S_OP_CODE == operation.S_CODE && p.N_B_STATE < 2 && p.N_SCHEDULE_TYPE == 2);
if (task == null)
{
result.resultCode = -1;
result.resultMsg = "当前任务已完结或出错,无法提升优先级";
return result;
}
// 未推送
if (task.N_B_STATE == 0)
{
task.N_PRIORITY = 99;
AdoSqlMethod.UpdateFirst(task, p => new { p.N_PRIORITY });
}
else
{
// 已推送,修改
// 让agv放货
NDCHelper.ChangePri(task.S_CODE, 99);
}
result.resultCode = 0;
result.resultMsg = "优先级修改成功";
return result;
}
///
/// 测试接口
///
///
///
public Location QueryStereoscopicStorehouseLocation(string type)
{
var location = LocationMethod.QueryStereoscopicStorehouseLocation(type);
// 加锁
LocationHelper.LockLoc(location.S_CODE, 1);
return location;
}
}