239 lines
9.3 KiB
C#
239 lines
9.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using JNPF;
|
||
using JNPF.Common.Core.Manager;
|
||
using JNPF.Common.Enums;
|
||
using JNPF.Common.Extension;
|
||
using JNPF.Common.Manager;
|
||
using JNPF.Common.Net;
|
||
using JNPF.Common.Security;
|
||
using JNPF.EventBus;
|
||
using JNPF.EventHandler;
|
||
using JNPF.FriendlyException;
|
||
using JNPF.Logging;
|
||
using JNPF.Systems.Entitys.System;
|
||
using JNPF.Systems.Interfaces.System;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Newtonsoft.Json;
|
||
using NPOI.OpenXmlFormats;
|
||
using Senparc.NeuChar.ApiHandlers;
|
||
using SqlSugar;
|
||
using Tnb.EquipMgr.Entities;
|
||
using Tnb.WarehouseMgr.Entities;
|
||
using Tnb.WarehouseMgr.Entities.Dto;
|
||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
||
using Tnb.WarehouseMgr.Entities.Entity;
|
||
using Tnb.WarehouseMgr.Interfaces;
|
||
|
||
namespace Tnb.WarehouseMgr
|
||
{
|
||
/// <summary>
|
||
/// Wms设备接口提供程序服务类
|
||
/// </summary>
|
||
|
||
public class DeviceProviderService : BaseWareHouseService
|
||
{
|
||
private readonly ISqlSugarClient _db;
|
||
private readonly IWareHouseService _wareHouseService;
|
||
private readonly ICacheManager _cacheManager;
|
||
private readonly IEventPublisher _eventPublisher;
|
||
private readonly IUserManager _userManager;
|
||
|
||
|
||
public DeviceProviderService(ISqlSugarRepository<WmsInstockH> repository, IWareHouseService wareHouseService,
|
||
ICacheManager cacheManager,
|
||
IEventPublisher eventPublisher,
|
||
IUserManager userManger
|
||
)
|
||
{
|
||
_db = repository.AsSugarClient();
|
||
_wareHouseService = wareHouseService;
|
||
_cacheManager = cacheManager;
|
||
_eventPublisher = eventPublisher;
|
||
_userManager = userManger;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建任务链
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost, NonUnify]
|
||
public async Task<Result> CreateTaskChain()
|
||
{
|
||
return await Task.FromResult<Result>(null);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取货确认/申请取货
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, NonUnify, AllowAnonymous]
|
||
public async Task<Result> LoadConfirm(ConfirmInput input)
|
||
{
|
||
try
|
||
{
|
||
var eles = await _db.Queryable<WmsElevatorH>().LeftJoin<WmsElevatorD>((a, b) => a.id == b.bill_id)
|
||
.LeftJoin<WmsDistaskH>((a, b, c) => b.location_id == c.startlocation_id)
|
||
.Where((a, b, c) => c.startlocation_code == input.sourceName && c.bill_code == input.taskCode)
|
||
.ToListAsync();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
|
||
throw;
|
||
}
|
||
return await ToApiResult(HttpStatusCode.OK, "未启用");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 放货确认/申请放货
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, NonUnify, AllowAnonymous]
|
||
public async Task<Result> UnloadConfirm(ConfirmInput input)
|
||
{
|
||
try
|
||
{
|
||
var eles = await _db.Queryable<WmsElevatorH>().LeftJoin<WmsElevatorD>((a, b) => a.id == b.bill_id)
|
||
.LeftJoin<WmsDistaskH>((a, b, c) => b.location_id == c.endlocation_id)
|
||
.Where((a, b, c) => c.endlocation_code == input.targetName && c.bill_code == input.taskCode)
|
||
.ToListAsync();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
|
||
throw;
|
||
}
|
||
return await ToApiResult(HttpStatusCode.OK, "未启用");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 任务链状态上报
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost, NonUnify, AllowAnonymous]
|
||
public async Task<Result> TaskChainCallBack(TaskChainCallBackInput input)
|
||
{
|
||
try
|
||
{
|
||
Log.Information($"任务链编号:{input.taskChainCode},状态:{input.status},设备ID:{input.deviceID}");
|
||
switch (input.status)
|
||
{
|
||
case "CREATED": break;
|
||
case "ALLOCATED": break;
|
||
case "PROCESSING":
|
||
if (await _cacheManager.GetAsync($"{input.taskChainCode}") == "任务链状态上报,上报状态PROCESSING") break;
|
||
if (input.taskChainCode.Trim().IsNullOrEmpty()) break;
|
||
var disTasks = await _db.Queryable<WmsDistaskH>().Where(it => it.bill_code.Contains(input.taskChainCode)).ToListAsync();
|
||
var eps = await _db.Queryable<EqpEquipment>().Where(it => it.code.Contains(input.deviceID)).ToListAsync();
|
||
TaskExecuteUpInput taskExecuteUpInput = new()
|
||
{
|
||
disTaskIds = disTasks.Select(x => x.id).ToList(),
|
||
EqpIds = eps.Select(x => x.id).ToList(),
|
||
};
|
||
await _wareHouseService.TaskExecute(taskExecuteUpInput); break;
|
||
case "CANCELLED": break;
|
||
case "SUCCEED": break;
|
||
case "FAILURE": break;
|
||
case "FINISHED": break;
|
||
default: break;
|
||
}
|
||
//写入redis
|
||
await _cacheManager.SetAsync($"{input.taskChainCode}", $"任务链状态上报,上报状态{input.status}");
|
||
var opts = App.GetOptions<ConnectionConfigOptions>();
|
||
UserAgent userAgent = new(App.HttpContext);
|
||
//写系统日志
|
||
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateOpLog", opts, new SysLogEntity
|
||
{
|
||
Id = SnowflakeIdHelper.NextId(),
|
||
Category = 4,
|
||
UserId = _userManager.UserId,
|
||
UserName = _userManager.User.RealName,
|
||
IPAddress = NetHelper.Ip,
|
||
RequestURL = App.HttpContext.Request.Path,
|
||
RequestMethod = App.HttpContext.Request.Method,
|
||
Json = $"任务链状态上报,任务链编号:{input.taskChainCode},上报状态:{input.status},设备编号:{input.deviceID}",
|
||
PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||
CreatorTime = DateTime.Now
|
||
}));
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
|
||
throw;
|
||
}
|
||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 任务状态上报
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, NonUnify, AllowAnonymous]
|
||
public async Task<Result> TaskCallback(TaskCallBackInput input)
|
||
{
|
||
Log.Information($"接收参数:{JsonConvert.SerializeObject(input)}");
|
||
try
|
||
{
|
||
|
||
var disTasks = await _db.Queryable<WmsDistaskH>().Where(it => it.bill_code.Contains(input.taskCode)).ToListAsync();
|
||
if (input.action == "LOAD")
|
||
{
|
||
TaskExecuteAfterUpInput taskExecuteAfterUpInput = new()
|
||
{
|
||
disTaskIds = disTasks.Select(x => x.id).ToList()
|
||
};
|
||
await _wareHouseService.TaskExecuteAfter(taskExecuteAfterUpInput);
|
||
}
|
||
else if (input.action == "UNLOAD")
|
||
{
|
||
TaskCompleUpInput taskCompleUpInput = new()
|
||
{
|
||
disTaskIds = disTasks.Select(x => x.id).ToList()
|
||
};
|
||
await _wareHouseService.TaskComplate(taskCompleUpInput);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
|
||
throw;
|
||
}
|
||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 申请进出电梯
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, NonUnify, AllowAnonymous]
|
||
public async Task<Result> ElevatorConfirm(ConfirmInput input)
|
||
{
|
||
try
|
||
{
|
||
var eles = await _db.Queryable<WmsElevatorH>().LeftJoin<WmsElevatorD>((a, b) => a.id == b.bill_id)
|
||
.LeftJoin<WmsDistaskH>((a, b, c) => b.location_id == c.startlocation_id)
|
||
.Where((a, b, c) => c.startlocation_code == input.sourceName && c.bill_code == input.taskCode)
|
||
.ToListAsync();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
|
||
throw;
|
||
}
|
||
return await ToApiResult(HttpStatusCode.OK, "未启用");
|
||
}
|
||
|
||
|
||
}
|
||
}
|