Files
YunTongJackYunTask/Reportapi/MyCode.Project.Services/Implementation/JackYunStockinService.cs

167 lines
7.1 KiB
C#
Raw Normal View History

2025-07-16 17:26:20 +08:00
using MyCode.Project.Domain.Message.Request.JackYun;
using MyCode.Project.Domain.Repositories;
using MyCode.Project.Infrastructure.Common;
using MyCode.Project.Infrastructure.Enumeration;
2025-07-21 17:25:29 +08:00
using MyCode.Project.Infrastructure.Exceptions;
2025-07-16 17:26:20 +08:00
using MyCode.Project.Infrastructure.JackYun;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2025-07-17 14:27:41 +08:00
using System.Threading;
2025-07-16 17:26:20 +08:00
using System.Threading.Tasks;
namespace MyCode.Project.Services.Implementation
{
public class JackYunStockinService : ServiceBase, IJackYunStockinService
{
private IWMStoJackyunInventoryMovementView1Repository _wMStoJackyunInventoryMovementView1Repository;
public JackYunStockinService(IWMStoJackyunInventoryMovementView1Repository wMStoJackyunInventoryMovementView1Repository)
{
_wMStoJackyunInventoryMovementView1Repository = wMStoJackyunInventoryMovementView1Repository;
}
public JackyunResponse Call(string method, string version, BaseRequestBizData bizData)
{
//接口返回值
JackyunResponse response = null;
//返回值字符串
string strResponse = null;
try
{
//请求吉客云开放接口。
strResponse = JackyunOpenHttpUtils.Post(method, version, bizData);
}
catch (Exception ex)
{
response = new JackyunResponse();
response.onFail(ex.Message, "CLIENT_EXCEPTION");
return response;
}
return JsonHelper.ToObject<JackyunResponse>(strResponse);
}
2025-07-21 17:25:29 +08:00
public void TaskSendInventoryMovement(string sheet)
2025-07-17 14:27:41 +08:00
{
2025-07-21 17:25:29 +08:00
SendInStock(sheet);
2025-07-17 14:27:41 +08:00
2025-07-21 17:25:29 +08:00
SendOutStock(sheet);
2025-07-17 14:27:41 +08:00
}
/// <summary>
/// 上传入库数据
/// </summary>
2025-07-21 17:25:29 +08:00
public void SendInStock(string sheet)
2025-07-16 17:26:20 +08:00
{
var list = _wMStoJackyunInventoryMovementView1Repository.GetInventoryMovement();
//过滤入库数据
2025-07-21 17:25:29 +08:00
var InStockHead = list.Where(t => t.type == "+" && t.relDataId == sheet).Select(p => p.relDataId).Distinct().ToList();
2025-07-16 17:26:20 +08:00
InStockHead.ForEach(relDataId =>
{
CreateAndStockinGetRequestBizData requestBizData = new CreateAndStockinGetRequestBizData();
List<StockInDetailViews> stockInDetailViews = new List<StockInDetailViews>();
var InStockEntry = list.Where(t => t.relDataId == relDataId).ToList();
2025-07-17 14:27:41 +08:00
requestBizData.inType = 104;
2025-07-16 17:26:20 +08:00
requestBizData.inWarehouseCode = InStockEntry.First().inWarehouseCode;
requestBizData.relDataId = relDataId;
requestBizData.applyDate = InStockEntry.First().applyDate;
requestBizData.@operator = "WMS";
requestBizData.source = "OPEN";
2025-07-17 14:27:41 +08:00
InStockEntry.ForEach(row =>
2025-07-16 17:26:20 +08:00
{
StockInDetailViews StockInDetail = new StockInDetailViews();
StockInDetail.relDetailId = (long)Convert.ToDecimal(row.relDetailId);
StockInDetail.skuCount = row.skuCount;
StockInDetail.isCertified = 1;
StockInDetail.rowRemark = row.rowRemark;
2025-07-17 14:27:41 +08:00
//StockInDetail.outSkuCode = row.outSkuCode;
2025-07-16 17:26:20 +08:00
StockInDetail.skuBarcode = row.skuBarcode;
stockInDetailViews.Add(StockInDetail);
});
requestBizData.stockInDetailViews = stockInDetailViews;
string lggl = JsonHelper.ToJson(requestBizData);
2025-07-21 15:28:55 +08:00
LogHelper.Info("上传入库数据报文:"+lggl);
2025-07-17 14:27:41 +08:00
Thread.Sleep(500);
2025-07-16 17:26:20 +08:00
JackyunResponse response = Call(EnumAttribute.GetAttribute(ApiEnum.CREATEANDSTOCKIN).Value, "1.0", requestBizData);
2025-07-21 17:25:29 +08:00
string ll = JsonHelper.ToJson(response);
LogHelper.Info("上传入库数据结果:" + ll);
2025-07-17 14:27:41 +08:00
//判断返回结果是否成功
if (response.code == "200")
{
_wMStoJackyunInventoryMovementView1Repository.UpdateStatus(2, relDataId);
}
else
{
2025-07-21 17:25:29 +08:00
//_wMStoJackyunInventoryMovementView1Repository.UpdateStatus(3, relDataId);
string msg = response.msg;
throw new BaseException(msg);
2025-07-17 14:27:41 +08:00
}
2025-07-21 17:25:29 +08:00
2025-07-16 17:26:20 +08:00
});
2025-07-17 14:27:41 +08:00
}
2025-07-16 17:26:20 +08:00
2025-07-17 14:27:41 +08:00
/// <summary>
/// 上传出库数据
/// </summary>
2025-07-21 17:25:29 +08:00
public void SendOutStock(string sheet)
2025-07-17 14:27:41 +08:00
{
var list = _wMStoJackyunInventoryMovementView1Repository.GetInventoryMovement();
2025-07-16 17:26:20 +08:00
//过滤出库数据
2025-07-21 17:25:29 +08:00
var OutStockHead = list.Where(t => t.type != "+" && t.relDataId==sheet).Select(p => p.relDataId).Distinct().ToList();
2025-07-16 17:26:20 +08:00
OutStockHead.ForEach(relDataId =>
{
2025-07-18 16:40:54 +08:00
2025-07-16 17:26:20 +08:00
CreateAndStockoutGetRequestBizData requestBizData = new CreateAndStockoutGetRequestBizData();
List<stockOutDetailViews> stockOutDetailViews = new List<stockOutDetailViews>();
var OutStockEntry = list.Where(t => t.relDataId == relDataId).ToList();
requestBizData.outType = 204;
requestBizData.outWarehouseCode = OutStockEntry.First().inWarehouseCode;
requestBizData.relDataId = relDataId;
requestBizData.applyDate = OutStockEntry.First().applyDate;
requestBizData.@operator = "WMS";
requestBizData.source = "OPEN";
OutStockEntry.ForEach(row =>
{
stockOutDetailViews stockOutDetail = new stockOutDetailViews();
stockOutDetail.relDetailId = (long)Convert.ToDecimal(row.relDetailId);
stockOutDetail.skuCount = row.skuCount;
stockOutDetail.isCertified = 1;
stockOutDetail.rowRemark = row.rowRemark;
2025-07-17 14:27:41 +08:00
//stockOutDetail.outSkuCode = row.outSkuCode;
2025-07-16 17:26:20 +08:00
stockOutDetail.skuBarcode = row.skuBarcode;
stockOutDetailViews.Add(stockOutDetail);
});
requestBizData.stockOutDetailViews = stockOutDetailViews;
string lggl = JsonHelper.ToJson(requestBizData);
LogHelper.Info(lggl);
2025-07-17 14:27:41 +08:00
Thread.Sleep(500);
2025-07-16 17:26:20 +08:00
JackyunResponse response = Call(EnumAttribute.GetAttribute(ApiEnum.CREATEANDSTOCKOUT).Value, "1.0", requestBizData);
2025-07-21 17:25:29 +08:00
string ll = JsonHelper.ToJson(response);
LogHelper.Info(ll);
2025-07-17 14:27:41 +08:00
//判断返回结果是否成功
if (response.code == "200")
2025-07-18 16:40:54 +08:00
{
2025-07-17 14:27:41 +08:00
_wMStoJackyunInventoryMovementView1Repository.UpdateStatus(2, relDataId);
}
else
{
2025-07-21 17:25:29 +08:00
string msg = response.msg;
throw new BaseException(msg);
//_wMStoJackyunInventoryMovementView1Repository.UpdateStatus(3, relDataId);
2025-07-17 14:27:41 +08:00
}
2025-07-21 17:25:29 +08:00
2025-07-16 17:26:20 +08:00
});
}
2025-07-21 17:25:29 +08:00
2025-07-16 17:26:20 +08:00
}
}