You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.6 KiB
C#

using DS.Module.CaiNiaoApi;
using DS.Module.CaiNiaoApi.CaiNiaoReq;
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.HkOpenApi;
using DS.WMS.Core.OpenApiModule.Dtos;
using DS.WMS.Core.OpenApiModule.Entity;
using DS.WMS.Core.OpenApiModule.Interface;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using NLog;
using SqlSugar;
namespace DS.WMS.Core.OpenApiModule.Method;
public class PortOpenService : IPortOpenService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IHttpRequestService _ihkHttpService;
private readonly ISendCaiNiaoMsgService _iSendCaiNiaoMsgService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public PortOpenService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
_ihkHttpService = _serviceProvider.GetRequiredService<IHttpRequestService>();
_iSendCaiNiaoMsgService= _serviceProvider.GetRequiredService<ISendCaiNiaoMsgService>();
}
public async Task<DataResult<TruckInfoViewModel>> GetTruckInfoAsync(string truckNo)
{
// List<TruckInfoViewModel> truckList = new List<TruckInfoViewModel>();
// List<TruckInfoViewModel> stockinTruckList = await db.Ado.SqlQueryAsync<TruckInfoViewModel>(
// @"select DISTINCT b.TRUCKNO , a.WMSPLANID,a.MBLNO, 1 AS Type,a.PLANTIME as PlanTime from OP_WMS_IN_PLAN a left join OP_WMS_IN_PLAN_GOODS b on a.WMSPLANID = b.WMSPLANID where b.TRUCKNO is not null and b.TRUCKNO<>'' and a.AuditStatus =1 and a.ISEND = 0 ");
//
// List<TruckInfoViewModel> stockoutTruckList = await db.Ado.SqlQueryAsync<TruckInfoViewModel>(
// @"select DISTINCT b.TRUCKNO , a.WMSPLANID,a.MBLNO, 2 AS Type,a.PLANTIME as PlanTime from OP_WMS_OUT_PLAN a left join OP_WMS_OUT_PLAN_DETAIL b on a.WMSPLANID = b.WMSPLANID where b.TRUCKNO is not null and b.TRUCKNO<>'' and a.AuditStatus =1 and a.ISEND = 0 ");
//
// List<TruckInfoViewModel> clearanceTruckList = await db.Ado.SqlQueryAsync<TruckInfoViewModel>(
// @"select DISTINCT b.TRUCKNO , a.WMSPLANID,a.MBLNO, 3 AS Type,a.PLANTIME as PlanTime from OP_WMS_CLEARANCE a left join OP_WMS_CLEARANCE_DETAIL b on a.WMSPLANID = b.WMSPLANID where b.TRUCKNO is not null and b.TRUCKNO<>'' and a.AuditStatus =1 and a.ISEND = 0 ");
//
// truckList.AddRange(stockinTruckList);
// truckList.AddRange(stockoutTruckList);
// truckList.AddRange(clearanceTruckList);
// var truckInfo = truckList.Where(x => x.TRUCKNO == truckNo.Trim()).OrderBy(x => x.PlanTime).ToList();
var truckList = db.Queryable<VW_TruckList>().Where(x => x.TRUCKNO == truckNo.Trim()).OrderBy(x => x.PlanTime)
.Select<TruckInfoViewModel>()
.Mapper(it =>
{
it.IsInternalCar = false;
})
.ToList();
if (truckList.Count == 0)
{
return DataResult<TruckInfoViewModel>.Failed("车辆信息不存在!");
}
return DataResult<TruckInfoViewModel>.Success("获取数据成功", truckList.First());
}
/// <summary>
/// 记录车辆相关信息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public async Task<DataResult> RecordTruckInfoAsync(TruckRecordInput model)
{
Logger.Log(LogLevel.Info,
DateTime.Now.ToString() + "地磅回推数据" + JsonConvert.SerializeObject(model));
var truckList = db.Queryable<VW_TruckList>()
.Where(x => x.TRUCKNO == model.TRUCKNO.Trim() && x.WMSPLANID == model.WMSPLANID).OrderBy(x => x.PlanTime)
.ToList();
if (truckList.Count == 0)
{
return DataResult.Failed("车辆信息不存在!");
}
var info = model.Adapt<tb_TruckRecord>();
var boxNo = string.Empty;
var now = DateTime.Now.AddMinutes(-5).ToString("yyyy-MM-dd HH:mm:ss");
var end = DateTime.Now.AddMinutes(5).ToString("yyyy-MM-dd HH:mm:ss");
var parm = new
{
boxNo = "",
plateNo = info.TRUCKNO,
pageNo = 1,
pageSize = 20,
startTime = now,
endTime = end,
};
var req = new HKPostData()
{
Url = "/artemis/api/v1/record/query/gate",
Data = JsonConvert.SerializeObject(parm),
};
var res = _ihkHttpService.HKHttpPost(req);
if (res.Code == "0")
{
Logger.Log(LogLevel.Info,
DateTime.Now.ToString() + JsonConvert.SerializeObject(res.Data));
var record = JsonConvert.DeserializeObject<HkRecords>(res.Data.ToString());
foreach (var item in record.List)
{
boxNo += item.ContainerNumOne + ";" + item.ContainerNumTwo;
}
//info.BoxNo = record.List[0].ContainerNumOne + ";" + record.List[0].ContainerNumTwo;
}
else
{
Logger.Log(LogLevel.Error,
DateTime.Now.ToString() + JsonConvert.SerializeObject(res));
}
info.BoxNo = boxNo;
#region 推送车辆进出记录给菜鸟系统 TODO
if (model.RecordType==0)
{
// var req = new CarInRecordReq
// {
//
// };
}
#endregion
await db.Insertable(info).ExecuteCommandAsync();
return DataResult.Successed("车辆信息纪录成功!");
}
}