Commit 10540165 by pengjinyang

提交

parent 2f8f7716
......@@ -13,6 +13,8 @@ namespace IService.TakeStock
/// <returns></returns>
Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule record, List<TakeStockOrder> orders);
Task<bool> ReTry(int scheduleId);
/// <summary>
/// 发起线下盘点
/// </summary>
......@@ -27,6 +29,13 @@ namespace IService.TakeStock
/// <returns></returns>
Task<bool> Feedback(int id, int afterQuantity, string description);
/// <summary>
/// 取消盘点的订单
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<bool> CancelOrder(int id);
///// <summary>
///// 冻结库存
///// </summary>
......
......@@ -23,6 +23,7 @@ namespace Service.TakeStock
private readonly IRepository<TakeStockOrder> orderRepository;
private readonly IRepository<TakeStockOrderLog> logRepository;
private readonly IHttpClientFactory httpClientFactory;
private readonly int delay = 3;
public TakeStockService(IHttpClientFactory httpClientFactory, RabbitMQClient mqClient, ITakeStockScheduleRepository scheduleRepository, IRepository<TakeStockOrder> orderRepository, IRepository<TakeStockOrderLog> logRepository)
{
......@@ -54,6 +55,25 @@ namespace Service.TakeStock
});
}
public async Task<bool> ReTry(int scheduleId)
{
var orders = orderRepository.GetAllList(o => !o.IsDeleted && o.State == TSOrderState.创建 && o.ScheduleId == scheduleId);
bool isSuccess = false;
try
{
foreach (var order in orders)
{
BackgroundJob.Enqueue(() => FreezeStockAsync(order.Id));
}
isSuccess = true;
}
catch
{
isSuccess = false;
}
return isSuccess;
}
private async Task<bool> AddOrUpdateLog(int orderId, TSOrderState state, string content, string jsonData = null)
{
var log = await logRepository.FirstOrDefaultAsync(l => l.OrderId == orderId && l.State == state);
......@@ -84,7 +104,7 @@ namespace Service.TakeStock
{
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TSOrderState.冻结库存)
if (order.State == TSOrderState.冻结库存 || order.State == TSOrderState.取消)
isSuccess = true;
else
{
......@@ -116,7 +136,7 @@ namespace Service.TakeStock
logTask = AddOrUpdateLog(id, TSOrderState.异常, "冻结库存失败,WMS返回消息:" + JObject.Parse(responseContent)["message"], responseContent);
}
int row = await orderRepository.UpdateAsync(order, "State", "LastModificationTime");
int row = await orderRepository.UpdateAsync(order, "State", "LastModificationTime");
if (!(row > 0 && await logTask))
isSuccess = false;
}
......@@ -125,7 +145,7 @@ namespace Service.TakeStock
if (isSuccess)
BackgroundJob.Enqueue(() => RollbackStockAsync(id));
else
BackgroundJob.Schedule(() => FreezeStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
BackgroundJob.Schedule(() => FreezeStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess;
}
......@@ -140,7 +160,7 @@ namespace Service.TakeStock
{
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TSOrderState.释放库存)
if (order.State == TSOrderState.释放库存 || order.State == TSOrderState.取消)
isSuccess = true;
else
{
......@@ -181,8 +201,8 @@ namespace Service.TakeStock
}
if (!waitCodes.Equals("[]"))
{
order.WaitCodes += "," + waitCodes.Trim('[', ']');
order.WaitCodes = order.WaitCodes.TrimStart(',');
order.State = TSOrderState.冻结库存;
order.WaitCodes = waitCodes.Trim('[', ']');
}
int row = await orderRepository.UpdateAsync(order, "State", "CancelCodes", "WaitCodes", "LastModificationTime");
......@@ -198,7 +218,7 @@ namespace Service.TakeStock
BackgroundJob.Enqueue(() => SyncAndEnabledAsync(id));
}
else
BackgroundJob.Schedule(() => RollbackStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
BackgroundJob.Schedule(() => RollbackStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess;
}
......@@ -213,7 +233,7 @@ namespace Service.TakeStock
{
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TSOrderState.完成)
if (order.State == TSOrderState.完成 || order.State == TSOrderState.取消)
isSuccess = true;
else
{
......@@ -227,7 +247,7 @@ namespace Service.TakeStock
{
var responseContent = await response.Content.ReadAsStringAsync();
isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]);
Task<bool> logTask = null;
Task<bool> logTask = null;
if (isSuccess)
{
order.State = TSOrderState.完成;
......@@ -247,7 +267,7 @@ namespace Service.TakeStock
if (isSuccess)
BackgroundJob.Enqueue(() => CheckComplete(order.ScheduleId));
else
BackgroundJob.Schedule(() => SyncAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
BackgroundJob.Schedule(() => SyncAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess;
}
......@@ -266,7 +286,7 @@ namespace Service.TakeStock
//BackgroundJob.Enqueue(() => GainLoss(schedule.Id));
}
}
/// <summary>
/// 发起线下盘点
/// </summary>
......@@ -274,13 +294,13 @@ namespace Service.TakeStock
/// <returns></returns>
public async Task<bool> StartTakeStock(int id, int beforeQuantity)
{
var order = orderRepository.Get(id);
var order = orderRepository.Get(id);
order.State = TSOrderState.盘点中;
order.BeforeQuantity = beforeQuantity;
order.LastModificationTime = DateTime.Now;
var record =await orderRepository.UpdateAsync(order, "State", "BeforeQuantity", "LastModificationTime");
var logTask = AddOrUpdateLog(id, TSOrderState.盘点中, "发起线下盘点。");
return record > 0;
var record = await orderRepository.UpdateAsync(order, "State", "BeforeQuantity", "LastModificationTime");
var logTask = await AddOrUpdateLog(id, TSOrderState.盘点中, "发起线下盘点。");
return record > 0 || logTask;
}
/// <summary>
......@@ -295,11 +315,11 @@ namespace Service.TakeStock
order.LastModificationTime = DateTime.Now;
order.Description = description;
var record = await orderRepository.UpdateAsync(order, "AfterQuantity", "LastModificationTime", "Description");
var logTask = AddOrUpdateLog(id, TSOrderState.盘点中, "盘点反馈。");
bool isSuccess = record > 0 && await logTask;
var logTask = await AddOrUpdateLog(id, TSOrderState.盘点中, "盘点反馈。");
bool isSuccess = record > 0 && logTask;
if (isSuccess)
BackgroundJob.Enqueue(() => ModifAndEnabledAsync(order.Id));
BackgroundJob.Enqueue(() => ModifAndEnabledAsync(order.Id));
return isSuccess;
}
......@@ -313,7 +333,7 @@ namespace Service.TakeStock
{
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TSOrderState.完成)
if (order.State == TSOrderState.完成 || order.State == TSOrderState.取消)
isSuccess = true;
else
{
......@@ -348,7 +368,7 @@ namespace Service.TakeStock
if (isSuccess)
BackgroundJob.Enqueue(() => Audit(order.ScheduleId));
else
BackgroundJob.Schedule(() => ModifAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
BackgroundJob.Schedule(() => ModifAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess;
}
......@@ -360,28 +380,36 @@ namespace Service.TakeStock
/// <returns></returns>
public async Task<bool> Audit(int scheduleId)
{
var schedule = scheduleRepository.Get(scheduleId);
bool isSuccess = false;
var orders = orderRepository.GetAllList(o => o.ScheduleId == scheduleId);
int count = orders.Count(o => o.State != TSOrderState.完成 && o.State != TSOrderState.取消);
if (count <= 0)
if (schedule.State == TSScheduleState.完成 || schedule.State == TSScheduleState.取消)
isSuccess = true;
else
{
var schedule = scheduleRepository.Get(scheduleId);
bool isAudit = orders.Any(o => o.BeforeQuantity != o.AfterQuantity);
if (isAudit)
var orders = orderRepository.GetAllList(o => o.ScheduleId == scheduleId);
int count = orders.Count(o => o.State != TSOrderState.完成 && o.State != TSOrderState.取消);
if (count <= 0)
{
schedule.State = TSScheduleState.审核;
BackgroundJob.Enqueue(() => GainLoss(schedule.Id));
bool isAudit = orders.Any(o => o.BeforeQuantity != o.AfterQuantity);
if (isAudit)
{
schedule.State = TSScheduleState.审核;
}
else
{
schedule.State = TSScheduleState.完成;
}
schedule.LastModificationTime = DateTime.UtcNow;
int record = await scheduleRepository.UpdateAsync(schedule, "State", "LastModificationTime");
isSuccess = record > 0;
if (isAudit)
BackgroundJob.Enqueue(() => GainLoss(schedule.Id));
}
else
{
schedule.State = TSScheduleState.完成;
}
int record = await scheduleRepository.UpdateAsync(schedule);
isSuccess = record > 0;
isSuccess = true;
}
else
isSuccess = true;
return isSuccess;
}
......@@ -444,9 +472,74 @@ namespace Service.TakeStock
}
if (string.IsNullOrWhiteSpace(code))
BackgroundJob.Schedule(() => AddGainLoss(obj), DateTimeOffset.UtcNow.AddMinutes(1));
BackgroundJob.Schedule(() => AddGainLoss(obj), DateTimeOffset.UtcNow.AddMinutes(delay));
return code;
}
public async Task<bool> CancelOrder(int id)
{
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TSOrderState.完成 || order.State == TSOrderState.取消)
isSuccess = true;
else
{
var client = httpClientFactory.CreateClient("WMS");
client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
string dataStr = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = order.WarehouseCode, Sku = order.Sku } });
HttpContent content = new StringContent(dataStr);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("WMSStockService/EnabledStock", content);
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]);
Task<bool> logTask = null;
if (isSuccess)
{
order.State = TSOrderState.取消;
logTask = AddOrUpdateLog(id, TSOrderState.取消, "取消盘点。");
}
else
{
order.State = TSOrderState.异常;
logTask = AddOrUpdateLog(id, TSOrderState.异常, "取消盘点失败,WMS返回消息:" + JObject.Parse(responseContent)["message"], responseContent);
}
int row = await orderRepository.UpdateAsync(order, "State", "LastModificationTime");
if (!(row > 0 && await logTask))
isSuccess = false;
}
}
if (isSuccess)
BackgroundJob.Enqueue(() => CancelSchedule(order.ScheduleId));
return isSuccess;
}
private async Task CancelSchedule(int scheduleId)
{
var schedule = scheduleRepository.Get(scheduleId);
bool isSuccess = false;
if (schedule.State == TSScheduleState.完成 || schedule.State == TSScheduleState.取消)
isSuccess = true;
var orders = orderRepository.GetAllList(o => o.ScheduleId == scheduleId);
if (orders.All(o => o.State == TSOrderState.完成 || o.State == TSOrderState.取消))
{
if (orders.Any(o => o.State == TSOrderState.完成))
schedule.State = TSScheduleState.完成;
else
schedule.State = TSScheduleState.取消;
schedule.LastModificationTime = DateTime.UtcNow;
int record = await scheduleRepository.UpdateAsync(schedule, "State", "LastModificationTime");
isSuccess = record > 0;
}
if (!isSuccess)
BackgroundJob.Schedule(() => CancelSchedule(scheduleId), DateTimeOffset.UtcNow.AddMinutes(delay));
}
}
}
......@@ -56,12 +56,24 @@ namespace TakeStock.API.Controllers
return await takeStockAppService.StartTakeStock(input);
}
[HttpGet("ReTry")]
public async Task<bool> ReTry(int scheduleId)
{
return await takeStockAppService.ReTry(scheduleId);
}
[HttpPost("Feedback")]
public async Task<bool> Feedback([FromBody] FeedbackInputDto input)
{
return await takeStockAppService.Feedback(input);
}
[HttpGet("CancelOrder")]
public async Task<bool> CancelOrder(int id)
{
return await takeStockAppService.ReTry(id);
}
// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public void Delete(int id)
......
......@@ -32,6 +32,6 @@
<ProjectReference Include="..\TakeStock.SqlSugar\TakeStock.SqlSugar.csproj" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JSONSchema="" /></VisualStudio></ProjectExtensions>
</Project>
......@@ -16,6 +16,7 @@
"Localhost": "server=gz-cdb-hqmznu0w.sql.tencentcdb.com;port=63523;database=bailun_wms;uid=root;password=#7kfnymAM$Y9-Ntf;Convert Zero Datetime=True;Allow User Variables=true;",
//"Redis": "127.0.0.1"
"Redis": "172.31.1.74"
//"Redis": "129.204.97.78"
},
"App": {
"CorsOrigins": "*"
......
......@@ -27,6 +27,11 @@ namespace TakeStock.Application.TakeStock
return await takeStockService.CreateTakeStockOrderAsync(schedule, orders);
}
public async Task<bool> ReTry(int scheduleId)
{
return await takeStockService.ReTry(scheduleId);
}
public async Task<bool> StartTakeStock(StartTakeStockInputDto input)
{
return await takeStockService.StartTakeStock(input.Id, input.BeforeQuantity);
......@@ -36,5 +41,10 @@ namespace TakeStock.Application.TakeStock
{
return await takeStockService.Feedback(input.Id, input.AfterQuantity, input.Description);
}
public async Task<bool> CancelOrder(int id)
{
return await takeStockService.CancelOrder(id);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment