using ServiceCenter;
using ServiceCenter.Extensions;
using ServiceCenter.Logs;
using ServiceCenter.Redis;
using ServiceCenter.WebApi;
using WCS.WorkEngineering.Extensions;
using WCS.WorkEngineering.WebApi.Models.WCS.Response;
using WCS.WorkEngineering.WebApi.Models.WMS.Request;
using WCS.WorkEngineering.WebApi.Models.WMS.Response;
using wms.dto;
using wms.dto.request;
using wms.dto.request.fj;
using wms.dto.response.fj;
using FJBuildEmptyPalletsStockRequest = WCS.WorkEngineering.WebApi.Models.WMS.Request.FJBuildEmptyPalletsStockRequest;
using FJEnteMainLineRequest = WCS.WorkEngineering.WebApi.Models.WMS.Request.FJEnteMainLineRequest;
using GetTunnelPriorityListRequest = WCS.WorkEngineering.WebApi.Models.WMS.Request.GetTunnelPriorityListRequest;
using ResponseStatusCodeEnum = WCS.WorkEngineering.WebApi.Models.WMS.Response.ResponseStatusCodeEnum;
using TaskBusType = WCS.WorkEngineering.WebApi.Models.WMS.Request.TaskBusType;
namespace WCS.WorkEngineering.WebApi.Controllers
{
///
/// AWMS相关接口控制器
///
public static class WmsApi
{
private static string _wmsUrl = null!;
private static string _wareHouseId = null!;
///
/// WMS URL
///
public static string WmsUrl
{
get
{
_wmsUrl ??= RedisHub.Default.Check("WMSUrl")!;
if (string.IsNullOrEmpty(_wmsUrl))
{
throw new KnownException($"请在Redis配置WMSUrl", LogLevelEnum.High);
}
return _wmsUrl;
}
}
///
/// 仓库编号
///
public static string wareHouseId = ServiceHub.WarehouseName;
///
/// 上传重量等信息
///
/// 任务号
/// rfid
///
public static SRes WcsUploadInfo(int taskCode, decimal weight) => WcsUploadInfo(taskCode, weight, "");
///
/// 上传重量等信息
///
/// 任务号
/// 重量
///
public static SRes WcsUploadInfo(int taskCode, string RFID) => WcsUploadInfo(taskCode, 0, RFID);
///
/// 上传重量等信息
///
/// 任务号
/// 重量
/// rfid
///
///
public static SRes WcsUploadInfo(int taskCode, decimal weight, string RFID)
{
var res = APICaller.CallApi2(WmsUrl + "/api/Hj/WcsUploadInfo", new WcsUploadInfoRequest
{
TaskCode = taskCode,
Weight = weight,
RFID = RFID
});
return res;
}
///
/// 变更流向
///
///
///
public static SRes EditorialFlow(FjEditorialFlowRequest req)
{
var res = APICaller.CallApi2(WmsUrl + "/api/FJ/EditorialFlow", new FjEditorialFlowRequest
{
LocCode = req.LocCode,
TaskId = req.TaskId,
WareCode = req.WareCode
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// 分配货位
///
/// WMS任务ID
/// 货位
/// 设备号
///
///
///
public static SRes GetLocalIn(int wcsTaskNum, string tunnel, string device, int size)
{
var res = APICaller.CallApi2>(WmsUrl + "/api/FJ/ApplyStockInLoc", new ApplyStockInLocRequest
{
TaskNum = wcsTaskNum,
TunnelNum = tunnel.GetLastDigit(),
PickUpEquipmentNo = device.ToString(),
Height = size
});
return res;
}
///
/// 分配货位
///
/// WMS任务ID
/// 货位
/// 设备号
///
///
///
public static SRes RingApplyStockInLoc(int wcsTaskNum, string tunnel, string device, int size)
{
var res = APICaller.CallApi2>(WmsUrl + "/api/FJ/RingApplyStockInLoc", new FJApplyStockInLocRequest
{
TaskNum = wcsTaskNum,
PickUpEquipmentNo = device,
Height = size
});
return res;
}
///
/// 堆垛机出库任务执行完成
///
///
///
///
public static SRes SrmPickOutCompleted(int taskNum)
{
var res = APICaller.CallApi2>(WmsUrl + "/api/FJ/SrmPickOutCompleted", new SrmPickOutCompletedRequest
{
TaskNum = taskNum,
});
return res;
}
///
/// 申请出库任务
///
///
///
public static SRes ApplyEmptyPalletGroupOutStorage(string addto, int tunnel, PalletType type)
{
var request = new ApplyStockOutTaskRequest
{
Tunnel = tunnel,
FJPalletType = type,
AddTo = addto
};
var res = APICaller.CallApi2(WmsUrl + "/api/fj/ApplyEmptyPalletGroupOutStorage", request);
return res;
}
///
/// 完成任务
///
///
///
///
public static SRes CompleteTask(int taskNo)
{
var res = APICaller.CallApi2>(WmsUrl + "/api/fj/CompleteTask", new CompleteTaskRequest
{
TaskNum = taskNo,
OperationType = Models.WMS.Request.CompleteTask.自动完成,
WCSUpdateName = "WCS"
});
return res;
}
public static SRes CancelTask(int taskNo)
{
var res = APICaller.CallApi2>(WmsUrl + "/api/fj/CancelTask", new CompleteTaskRequest
{
TaskNum = taskNo,
OperationType = Models.WMS.Request.CompleteTask.自动完成,
WCSUpdateName = "WCS"
});
return res;
}
///
/// 处理任务验证接口
///
/// 需要处理的任务进行验证
/// 目标状态
///
///
public static SRes HandleTaskVerify(List taskNo, int state)
{
var res = APICaller.CallApi2(WmsUrl + "/api/fj/CancelTaskVerify", new CancelTaskVerifyRequest
{
TaskNo = taskNo,
State = state
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// 处理任务接口
///
/// 处理
/// 目标状态
///
///
public static SRes CarryTaskInfo(List taskNo, int state)
{
var res = APICaller.CallApi2(WmsUrl + "/api/fj/CarryTaskInfo", new CancelTaskVerifyRequest
{
TaskNo = taskNo,
State = state
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// WMS完成或取消任务验证
///
///
///
/// 99完成,106取消
///
public static SRes? HandleTaskVerify(SRes sRes, int id, int type)
{
try
{
var res = WmsApi.HandleTaskVerify(new List() { id }, type);
return res;
}
catch (Exception ex)
{
sRes.ResDataList.Add(new HandleTaskResponse()
{
IsSuccess = false,
TaskNo = id,
Message = $"WMS错误:{ex.Message}",
});
return null;
}
}
///
/// WMS完成或取消任务执行
///
///
///
/// 99完成,106取消
///
public static SRes? CarryTaskInfo(SRes sRes, int id, int type)
{
try
{
var res = WmsApi.CarryTaskInfo(new List() { id }, type);
return res;
}
catch (Exception ex)
{
sRes.ResDataList.Add(new HandleTaskResponse()
{
IsSuccess = false,
TaskNo = id,
Message = $"WMS错误:{ex.Message}",
});
return null;
}
}
///
/// 一楼扫码入库
///
/// 工字轮条码组
///
///
public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
{
var res = APICaller.CallApi2(WmsUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
{
PalletCode = reqDto.PalletCode,
PalletType = reqDto.PalletType,
StartLoc = reqDto.StartLoc,
WareCode = reqDto.StartLoc.GetWareCode(),
PalletNum = "1"
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// 工字轮/芯股进入主线扫码
///
///
///
///
///
public static SRes EnteMainLine(List reqDto, string equNo)
{
var res = APICaller.CallApi(WmsUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest
{
IShapedWheelCodes = reqDto,
equNo = equNo
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// 生成空托盘组盘任务
///
///
///
///
///
public static SRes GroupTask(string palletCode, string loc)
{
var res = APICaller.CallApi(WmsUrl + "/api/FJ/GroupTask", new FJBuildEmptyPalletsStockRequest
{
PalletCode = palletCode,
PalletType = FJPalletType.Pallet09,
PalletNum = "1",
StartLoc = loc,
WareCode = loc.GetWareCode(),
BusType = TaskBusType.组盘_托盘
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// 正常结盘
///
///
///
///
///
///
///
public static SRes FinishBingPallet(string palletCode, List taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", true, false);
///
/// 需要二次绑盘的结盘
///
///
///
///
///
///
///
public static SRes SecondaryBingPallet(string palletCode, List taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "二次绑盘", true, true);
///
/// 异常结盘
///
///
///
///
///
///
///
public static SRes ForceFinishBingPallet(string palletCode, List taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, true, "强制码垛结束", true, false);
///
/// 绑盘
///
///
///
///
///
///
///
public static SRes BingPallet(string palletCode, List taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", false, false);
///
/// 绑盘
///
///
///
///
///
///
///
///
///
public static SRes BingPallet(string palletCode, List taskCodes, string warehouseCode, string loc, bool isFail, string failReason, bool isFinish, bool isItHalf)
{
var res = APICaller.CallApi2(WmsUrl + "/api/FJ/BingPallet", new FJBingPalletRequest
{
PalletCode = palletCode,
TaskCode = taskCodes,
WarehouseCode = warehouseCode,
loc = loc,
IsFail = isFail,
FailReason = failReason,
IsFinish = isFinish,
IsItHalf = isItHalf
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// 绑盘
///
///
///
///
public static SRes GetTwoPallet(string warehouseCode, int taskId)
{
var res = APICaller.CallApi>(WmsUrl + "/api/FJ/GetTwoPallet", new FJGetTwoPalletDto
{
WarehouseCode = warehouseCode,
TaskId = taskId
});
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
///
/// 环形库申请码垛任务
///
///
///
///
///
public static SRes ApplyPalletizingStockOut(string loc, string robotCode)
{
var res = APICaller.CallApi2(WmsUrl + "/api/FJ/ApplyPalletizingStockOut", new wms.dto.request.fj.RingApplyPalletizingStockOutRequest(loc.GetWareCode(), loc, robotCode));
return res;
}
///
/// 码垛工资轮创建异常任务信息
///
/// 位置
/// 类型
/// 异常类型
///
///
public static SRes PalletizingCreateseErrorTasks(string loc, string type, int errType = 0)
{
var res = APICaller.CallApi2(WmsUrl + "/api/FJ/PalletizingCreateseErrorTasks", new Models.WMS.Request.PalletizingCreateseErrorTasksRequest(loc, type, loc.GetWareCode(), errType));
if (res.ResCode != ResponseStatusCodeEnum.Sucess)
{
throw new KnownException(res.ResMsg, LogLevelEnum.High);
}
return res;
}
}
public class FJGetTwoPalletDto : BaseRequest
{
///
/// 仓库号
///
public string WarehouseCode { get; set; }
///
/// 仓库号
///
public int TaskId { get; set; }
}
///
/// 变更流向
///
public class FjEditorialFlowRequest : BaseRequest
{
///
/// 任务号
///
public int TaskId { get; set; }
///
/// 目标仓库
///
public string WareCode { get; set; }
///
/// 位置
///
public string LocCode { get; set; }
}
}