Commit 10540165 by pengjinyang

提交

parent 2f8f7716
...@@ -13,6 +13,8 @@ namespace IService.TakeStock ...@@ -13,6 +13,8 @@ namespace IService.TakeStock
/// <returns></returns> /// <returns></returns>
Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule record, List<TakeStockOrder> orders); Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule record, List<TakeStockOrder> orders);
Task<bool> ReTry(int scheduleId);
/// <summary> /// <summary>
/// 发起线下盘点 /// 发起线下盘点
/// </summary> /// </summary>
...@@ -27,6 +29,13 @@ namespace IService.TakeStock ...@@ -27,6 +29,13 @@ namespace IService.TakeStock
/// <returns></returns> /// <returns></returns>
Task<bool> Feedback(int id, int afterQuantity, string description); Task<bool> Feedback(int id, int afterQuantity, string description);
/// <summary>
/// 取消盘点的订单
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<bool> CancelOrder(int id);
///// <summary> ///// <summary>
///// 冻结库存 ///// 冻结库存
///// </summary> ///// </summary>
......
...@@ -23,6 +23,7 @@ namespace Service.TakeStock ...@@ -23,6 +23,7 @@ namespace Service.TakeStock
private readonly IRepository<TakeStockOrder> orderRepository; private readonly IRepository<TakeStockOrder> orderRepository;
private readonly IRepository<TakeStockOrderLog> logRepository; private readonly IRepository<TakeStockOrderLog> logRepository;
private readonly IHttpClientFactory httpClientFactory; private readonly IHttpClientFactory httpClientFactory;
private readonly int delay = 3;
public TakeStockService(IHttpClientFactory httpClientFactory, RabbitMQClient mqClient, ITakeStockScheduleRepository scheduleRepository, IRepository<TakeStockOrder> orderRepository, IRepository<TakeStockOrderLog> logRepository) public TakeStockService(IHttpClientFactory httpClientFactory, RabbitMQClient mqClient, ITakeStockScheduleRepository scheduleRepository, IRepository<TakeStockOrder> orderRepository, IRepository<TakeStockOrderLog> logRepository)
{ {
...@@ -54,6 +55,25 @@ namespace Service.TakeStock ...@@ -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) 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); var log = await logRepository.FirstOrDefaultAsync(l => l.OrderId == orderId && l.State == state);
...@@ -84,7 +104,7 @@ namespace Service.TakeStock ...@@ -84,7 +104,7 @@ namespace Service.TakeStock
{ {
var order = orderRepository.Get(id); var order = orderRepository.Get(id);
bool isSuccess = false; bool isSuccess = false;
if (order.State == TSOrderState.冻结库存) if (order.State == TSOrderState.冻结库存 || order.State == TSOrderState.取消)
isSuccess = true; isSuccess = true;
else else
{ {
...@@ -116,7 +136,7 @@ namespace Service.TakeStock ...@@ -116,7 +136,7 @@ namespace Service.TakeStock
logTask = AddOrUpdateLog(id, TSOrderState.异常, "冻结库存失败,WMS返回消息:" + JObject.Parse(responseContent)["message"], responseContent); 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)) if (!(row > 0 && await logTask))
isSuccess = false; isSuccess = false;
} }
...@@ -125,7 +145,7 @@ namespace Service.TakeStock ...@@ -125,7 +145,7 @@ namespace Service.TakeStock
if (isSuccess) if (isSuccess)
BackgroundJob.Enqueue(() => RollbackStockAsync(id)); BackgroundJob.Enqueue(() => RollbackStockAsync(id));
else else
BackgroundJob.Schedule(() => FreezeStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1)); BackgroundJob.Schedule(() => FreezeStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess; return isSuccess;
} }
...@@ -140,7 +160,7 @@ namespace Service.TakeStock ...@@ -140,7 +160,7 @@ namespace Service.TakeStock
{ {
var order = orderRepository.Get(id); var order = orderRepository.Get(id);
bool isSuccess = false; bool isSuccess = false;
if (order.State == TSOrderState.释放库存) if (order.State == TSOrderState.释放库存 || order.State == TSOrderState.取消)
isSuccess = true; isSuccess = true;
else else
{ {
...@@ -181,8 +201,8 @@ namespace Service.TakeStock ...@@ -181,8 +201,8 @@ namespace Service.TakeStock
} }
if (!waitCodes.Equals("[]")) if (!waitCodes.Equals("[]"))
{ {
order.WaitCodes += "," + waitCodes.Trim('[', ']'); order.State = TSOrderState.冻结库存;
order.WaitCodes = order.WaitCodes.TrimStart(','); order.WaitCodes = waitCodes.Trim('[', ']');
} }
int row = await orderRepository.UpdateAsync(order, "State", "CancelCodes", "WaitCodes", "LastModificationTime"); int row = await orderRepository.UpdateAsync(order, "State", "CancelCodes", "WaitCodes", "LastModificationTime");
...@@ -198,7 +218,7 @@ namespace Service.TakeStock ...@@ -198,7 +218,7 @@ namespace Service.TakeStock
BackgroundJob.Enqueue(() => SyncAndEnabledAsync(id)); BackgroundJob.Enqueue(() => SyncAndEnabledAsync(id));
} }
else else
BackgroundJob.Schedule(() => RollbackStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1)); BackgroundJob.Schedule(() => RollbackStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess; return isSuccess;
} }
...@@ -213,7 +233,7 @@ namespace Service.TakeStock ...@@ -213,7 +233,7 @@ namespace Service.TakeStock
{ {
var order = orderRepository.Get(id); var order = orderRepository.Get(id);
bool isSuccess = false; bool isSuccess = false;
if (order.State == TSOrderState.完成) if (order.State == TSOrderState.完成 || order.State == TSOrderState.取消)
isSuccess = true; isSuccess = true;
else else
{ {
...@@ -227,7 +247,7 @@ namespace Service.TakeStock ...@@ -227,7 +247,7 @@ namespace Service.TakeStock
{ {
var responseContent = await response.Content.ReadAsStringAsync(); var responseContent = await response.Content.ReadAsStringAsync();
isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]); isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]);
Task<bool> logTask = null; Task<bool> logTask = null;
if (isSuccess) if (isSuccess)
{ {
order.State = TSOrderState.完成; order.State = TSOrderState.完成;
...@@ -247,7 +267,7 @@ namespace Service.TakeStock ...@@ -247,7 +267,7 @@ namespace Service.TakeStock
if (isSuccess) if (isSuccess)
BackgroundJob.Enqueue(() => CheckComplete(order.ScheduleId)); BackgroundJob.Enqueue(() => CheckComplete(order.ScheduleId));
else else
BackgroundJob.Schedule(() => SyncAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1)); BackgroundJob.Schedule(() => SyncAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess; return isSuccess;
} }
...@@ -266,7 +286,7 @@ namespace Service.TakeStock ...@@ -266,7 +286,7 @@ namespace Service.TakeStock
//BackgroundJob.Enqueue(() => GainLoss(schedule.Id)); //BackgroundJob.Enqueue(() => GainLoss(schedule.Id));
} }
} }
/// <summary> /// <summary>
/// 发起线下盘点 /// 发起线下盘点
/// </summary> /// </summary>
...@@ -274,13 +294,13 @@ namespace Service.TakeStock ...@@ -274,13 +294,13 @@ namespace Service.TakeStock
/// <returns></returns> /// <returns></returns>
public async Task<bool> StartTakeStock(int id, int beforeQuantity) public async Task<bool> StartTakeStock(int id, int beforeQuantity)
{ {
var order = orderRepository.Get(id); var order = orderRepository.Get(id);
order.State = TSOrderState.盘点中; order.State = TSOrderState.盘点中;
order.BeforeQuantity = beforeQuantity; order.BeforeQuantity = beforeQuantity;
order.LastModificationTime = DateTime.Now; order.LastModificationTime = DateTime.Now;
var record =await orderRepository.UpdateAsync(order, "State", "BeforeQuantity", "LastModificationTime"); var record = await orderRepository.UpdateAsync(order, "State", "BeforeQuantity", "LastModificationTime");
var logTask = AddOrUpdateLog(id, TSOrderState.盘点中, "发起线下盘点。"); var logTask = await AddOrUpdateLog(id, TSOrderState.盘点中, "发起线下盘点。");
return record > 0; return record > 0 || logTask;
} }
/// <summary> /// <summary>
...@@ -295,11 +315,11 @@ namespace Service.TakeStock ...@@ -295,11 +315,11 @@ namespace Service.TakeStock
order.LastModificationTime = DateTime.Now; order.LastModificationTime = DateTime.Now;
order.Description = description; order.Description = description;
var record = await orderRepository.UpdateAsync(order, "AfterQuantity", "LastModificationTime", "Description"); var record = await orderRepository.UpdateAsync(order, "AfterQuantity", "LastModificationTime", "Description");
var logTask = AddOrUpdateLog(id, TSOrderState.盘点中, "盘点反馈。"); var logTask = await AddOrUpdateLog(id, TSOrderState.盘点中, "盘点反馈。");
bool isSuccess = record > 0 && await logTask; bool isSuccess = record > 0 && logTask;
if (isSuccess) if (isSuccess)
BackgroundJob.Enqueue(() => ModifAndEnabledAsync(order.Id)); BackgroundJob.Enqueue(() => ModifAndEnabledAsync(order.Id));
return isSuccess; return isSuccess;
} }
...@@ -313,7 +333,7 @@ namespace Service.TakeStock ...@@ -313,7 +333,7 @@ namespace Service.TakeStock
{ {
var order = orderRepository.Get(id); var order = orderRepository.Get(id);
bool isSuccess = false; bool isSuccess = false;
if (order.State == TSOrderState.完成) if (order.State == TSOrderState.完成 || order.State == TSOrderState.取消)
isSuccess = true; isSuccess = true;
else else
{ {
...@@ -348,7 +368,7 @@ namespace Service.TakeStock ...@@ -348,7 +368,7 @@ namespace Service.TakeStock
if (isSuccess) if (isSuccess)
BackgroundJob.Enqueue(() => Audit(order.ScheduleId)); BackgroundJob.Enqueue(() => Audit(order.ScheduleId));
else else
BackgroundJob.Schedule(() => ModifAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1)); BackgroundJob.Schedule(() => ModifAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(delay));
return isSuccess; return isSuccess;
} }
...@@ -360,28 +380,36 @@ namespace Service.TakeStock ...@@ -360,28 +380,36 @@ namespace Service.TakeStock
/// <returns></returns> /// <returns></returns>
public async Task<bool> Audit(int scheduleId) public async Task<bool> Audit(int scheduleId)
{ {
var schedule = scheduleRepository.Get(scheduleId);
bool isSuccess = false; bool isSuccess = false;
var orders = orderRepository.GetAllList(o => o.ScheduleId == scheduleId); if (schedule.State == TSScheduleState.完成 || schedule.State == TSScheduleState.取消)
int count = orders.Count(o => o.State != TSOrderState.完成 && o.State != TSOrderState.取消); isSuccess = true;
if (count <= 0) else
{ {
var schedule = scheduleRepository.Get(scheduleId); var orders = orderRepository.GetAllList(o => o.ScheduleId == scheduleId);
bool isAudit = orders.Any(o => o.BeforeQuantity != o.AfterQuantity); int count = orders.Count(o => o.State != TSOrderState.完成 && o.State != TSOrderState.取消);
if (isAudit) if (count <= 0)
{ {
schedule.State = TSScheduleState.审核; bool isAudit = orders.Any(o => o.BeforeQuantity != o.AfterQuantity);
BackgroundJob.Enqueue(() => GainLoss(schedule.Id)); 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 else
{ isSuccess = true;
schedule.State = TSScheduleState.完成;
}
int record = await scheduleRepository.UpdateAsync(schedule);
isSuccess = record > 0;
} }
else
isSuccess = true;
return isSuccess; return isSuccess;
} }
...@@ -444,9 +472,74 @@ namespace Service.TakeStock ...@@ -444,9 +472,74 @@ namespace Service.TakeStock
} }
if (string.IsNullOrWhiteSpace(code)) if (string.IsNullOrWhiteSpace(code))
BackgroundJob.Schedule(() => AddGainLoss(obj), DateTimeOffset.UtcNow.AddMinutes(1)); BackgroundJob.Schedule(() => AddGainLoss(obj), DateTimeOffset.UtcNow.AddMinutes(delay));
return code; 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 ...@@ -56,12 +56,24 @@ namespace TakeStock.API.Controllers
return await takeStockAppService.StartTakeStock(input); return await takeStockAppService.StartTakeStock(input);
} }
[HttpGet("ReTry")]
public async Task<bool> ReTry(int scheduleId)
{
return await takeStockAppService.ReTry(scheduleId);
}
[HttpPost("Feedback")] [HttpPost("Feedback")]
public async Task<bool> Feedback([FromBody] FeedbackInputDto input) public async Task<bool> Feedback([FromBody] FeedbackInputDto input)
{ {
return await takeStockAppService.Feedback(input); return await takeStockAppService.Feedback(input);
} }
[HttpGet("CancelOrder")]
public async Task<bool> CancelOrder(int id)
{
return await takeStockAppService.ReTry(id);
}
// DELETE: api/ApiWithActions/5 // DELETE: api/ApiWithActions/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public void Delete(int id) public void Delete(int id)
......
...@@ -32,6 +32,6 @@ ...@@ -32,6 +32,6 @@
<ProjectReference Include="..\TakeStock.SqlSugar\TakeStock.SqlSugar.csproj" /> <ProjectReference Include="..\TakeStock.SqlSugar\TakeStock.SqlSugar.csproj" />
</ItemGroup> </ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions> <ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JSONSchema="" /></VisualStudio></ProjectExtensions>
</Project> </Project>
...@@ -16,6 +16,7 @@ ...@@ -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;", "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": "127.0.0.1"
"Redis": "172.31.1.74" "Redis": "172.31.1.74"
//"Redis": "129.204.97.78"
}, },
"App": { "App": {
"CorsOrigins": "*" "CorsOrigins": "*"
......
...@@ -27,6 +27,11 @@ namespace TakeStock.Application.TakeStock ...@@ -27,6 +27,11 @@ namespace TakeStock.Application.TakeStock
return await takeStockService.CreateTakeStockOrderAsync(schedule, orders); 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) public async Task<bool> StartTakeStock(StartTakeStockInputDto input)
{ {
return await takeStockService.StartTakeStock(input.Id, input.BeforeQuantity); return await takeStockService.StartTakeStock(input.Id, input.BeforeQuantity);
...@@ -36,5 +41,10 @@ namespace TakeStock.Application.TakeStock ...@@ -36,5 +41,10 @@ namespace TakeStock.Application.TakeStock
{ {
return await takeStockService.Feedback(input.Id, input.AfterQuantity, input.Description); 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