修复bug
This commit is contained in:
@@ -114,7 +114,7 @@ namespace WMS.Web.Api.Controllers
|
||||
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
||||
if (loginInfo == null || loginInfo.UserInfo == null)
|
||||
return Result.ReFailure(ResultCodes.Token_Invalid_Error);
|
||||
_logger.LogInformation($"盘点重传:{JsonConvert.SerializeObject(dto)}");
|
||||
|
||||
return await _takeStockService.Sync(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,9 +118,9 @@ namespace WMS.Web.Domain.Entitys
|
||||
if (task.Type == OutStockType.Sal)
|
||||
{
|
||||
//只有销售出库才需要同步金蝶
|
||||
this.SuccessSync = SyncStatus.Fail;
|
||||
this.SuccessSync = SyncStatus.SyncIng;
|
||||
var erpd = this.Details.SelectMany(s => s.ErpDetails).ToList();
|
||||
erpd.ForEach(f => f.SuccessSync = SyncStatus.Fail);
|
||||
erpd.ForEach(f => f.SuccessSync = SyncStatus.SyncIng);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
@@ -45,13 +46,14 @@ namespace WMS.Web.Domain.Services
|
||||
private readonly ILogger<OutStockService> _logger;
|
||||
private readonly IBoxRepositories _boxRepositories;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
public OutStockService(IMapper mapper, ILoginService loginService,
|
||||
IBasicsRepositories transactionRepositories,
|
||||
IOutStockRepositories outStockRepositories, IOutStockTaskRepositories outStockTaskRepositories,
|
||||
IOutStockTaskService outStockTaskService, IErpService erpService, ISerialNumberService serialNumberService,
|
||||
IBoxInventoryService boxInventoryService, IInventoryInOutDetailsService inventoryInOutDetailsService,
|
||||
IBoxInventoryRepositories boxInventoryRepositories, ILogger<OutStockService> logger, IBoxRepositories boxRepositories,
|
||||
ISingleDataService singleDataService)
|
||||
ISingleDataService singleDataService, IServiceScopeFactory serviceScopeFactory)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_loginService = loginService;
|
||||
@@ -67,6 +69,7 @@ namespace WMS.Web.Domain.Services
|
||||
_logger = logger;
|
||||
_boxRepositories = boxRepositories;
|
||||
_singleDataService = singleDataService;
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
}
|
||||
/// <summary>
|
||||
/// 出库单
|
||||
@@ -213,10 +216,12 @@ namespace WMS.Web.Domain.Services
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var list = _outStockRepositories.GetEntityList(dto.Ids).GetAwaiter().GetResult();
|
||||
var scope = _serviceScopeFactory.CreateScope();
|
||||
var sc_outStockRepositories = scope.ServiceProvider.GetRequiredService<IOutStockRepositories>();
|
||||
var list =await sc_outStockRepositories.GetEntityList(dto.Ids);
|
||||
foreach (var entity in list)
|
||||
{
|
||||
var res = await SalOutStock(entity, loginInfo);
|
||||
var res = await SalOutStock(entity, loginInfo, scope);
|
||||
if (!res.IsSuccess)
|
||||
_logger.LogError($"出库单同步失败:{res.Message}");
|
||||
}
|
||||
@@ -228,8 +233,10 @@ namespace WMS.Web.Domain.Services
|
||||
/// 同步金蝶销售出库
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<Result> SalOutStock(OutStock entity, LoginInDto loginInfo)
|
||||
private async Task<Result> SalOutStock(OutStock entity, LoginInDto loginInfo, IServiceScope scope)
|
||||
{
|
||||
var sc_outStockRepositories = scope.ServiceProvider.GetRequiredService<IOutStockRepositories>();
|
||||
|
||||
if (entity.Type != OutStockType.Sal) return Result.ReSuccess();
|
||||
if (entity.SuccessSync == SyncStatus.Success) return Result.ReSuccess();
|
||||
//List<string> failList = entity.Details.SelectMany(s => s.ErpDetails)
|
||||
@@ -253,7 +260,7 @@ namespace WMS.Web.Domain.Services
|
||||
//DetailsId = string.Join(",", erp_details)
|
||||
};
|
||||
//下推金蝶
|
||||
var res = await this.Push(erpDto, s, entity.BillNo);
|
||||
var res = await this.Push(erpDto, s, entity.BillNo, scope);
|
||||
if (res.result.IsSuccess)
|
||||
entity.SyncSuccess(s.Erp_DetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.erpBillNo);
|
||||
else
|
||||
@@ -261,7 +268,7 @@ namespace WMS.Web.Domain.Services
|
||||
}
|
||||
//entity.SuccessSync = entity.SuccessSyncFail.Count() > 0 ? false : true;
|
||||
//最好一条一条执行,否则执行失败 但是金蝶那边又同步成功 就会造成数据比价乱
|
||||
var isSuccess = await _outStockRepositories.Edit(entity, true);
|
||||
var isSuccess = await sc_outStockRepositories.Edit(entity, true);
|
||||
if (entity == null) return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
@@ -271,23 +278,25 @@ namespace WMS.Web.Domain.Services
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<(Result result, SyncStatus syncStatus, string erpBillNo)> Push(ErpPushDto dto, OutStockErpDetails erpDetail, string billNo)
|
||||
private async Task<(Result result, SyncStatus syncStatus, string erpBillNo)> Push(ErpPushDto dto, OutStockErpDetails erpDetail, string billNo, IServiceScope scope)
|
||||
{
|
||||
var res = await _erpService.Push(dto);
|
||||
var sc_erpService = scope.ServiceProvider.GetRequiredService<IErpService>();
|
||||
|
||||
var res = await sc_erpService.Push(dto);
|
||||
if (!res.IsSuccess)
|
||||
{
|
||||
_logger.LogInformation($"出库单->下推失败 单号:{billNo} erp明细Id:{erpDetail.Erp_DetailId} 错误:{res.Message}");
|
||||
return (Result.ReFailure(res.Message, res.Status), SyncStatus.Fail, "");
|
||||
}
|
||||
string id = res.Data;
|
||||
var resSalOutStock = await _erpService.BillQueryForSalOutStock(id);
|
||||
var resSalOutStock = await sc_erpService.BillQueryForSalOutStock(id);
|
||||
var salOutStock = resSalOutStock.Data;
|
||||
salOutStock.Details[0].Qty = erpDetail.Qty;
|
||||
//{"Id":12709885,"Number":"XSCKD10629570","DIndex":0}
|
||||
|
||||
string formId = dto.TargetFormId.ToString();
|
||||
_logger.LogInformation($"出库单->开始同步金蝶 单号:{billNo} erp明细Id:{erpDetail.Erp_DetailId} 数据: {JsonConvert.SerializeObject(dto)}");
|
||||
var res_s = await _erpService.Save<ErpSalOutStockSaveDto>(salOutStock, formId);
|
||||
var res_s = await sc_erpService.Save<ErpSalOutStockSaveDto>(salOutStock, formId);
|
||||
if (!res_s.IsSuccess)
|
||||
{
|
||||
_logger.LogInformation($"出库单->修改数量失败 单号:{billNo} erp明细Id:{erpDetail.Erp_DetailId} 错误:{res_s.Message}");
|
||||
@@ -296,7 +305,7 @@ namespace WMS.Web.Domain.Services
|
||||
//提交
|
||||
_logger.LogInformation($"出库单->保存成功 开始提交 单号:{billNo} erp明细Id:{erpDetail.Erp_DetailId}");
|
||||
ErpOperateDto o_dto = new ErpOperateDto(formId, res_s.Data);//res_s.Data
|
||||
var resSubmit = await _erpService.Submit(o_dto, formId);
|
||||
var resSubmit = await sc_erpService.Submit(o_dto, formId);
|
||||
if (!resSubmit.IsSuccess)
|
||||
{
|
||||
_logger.LogInformation($"出库单->提交失败 单号:{billNo} erp明细Id:{erpDetail.Erp_DetailId} 错误:{resSubmit.Message}");
|
||||
@@ -304,7 +313,7 @@ namespace WMS.Web.Domain.Services
|
||||
}
|
||||
//审核
|
||||
_logger.LogInformation($"出库单->提交成功 开始审核 单号:{billNo} erp明细Id:{erpDetail.Erp_DetailId}");
|
||||
resSubmit = await _erpService.Audit(o_dto, formId);
|
||||
resSubmit = await sc_erpService.Audit(o_dto, formId);
|
||||
if (!resSubmit.IsSuccess)
|
||||
{
|
||||
_logger.LogInformation($"出库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.Erp_DetailId} 错误:{resSubmit.Message}");
|
||||
|
||||
@@ -153,24 +153,19 @@ namespace WMS.Web.Domain.Services
|
||||
/// <returns></returns>
|
||||
public Task<Result> Sync(OperateRequest dto)
|
||||
{
|
||||
_logger.LogInformation($"盘点同步1:{JsonConvert.SerializeObject(dto)}");
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var scope = _serviceScopeFactory.CreateScope();
|
||||
var sc_takeStockRepositories = scope.ServiceProvider.GetRequiredService<ITakeStockRepositories>();
|
||||
_logger.LogInformation($"盘点同步2");
|
||||
var list = await sc_takeStockRepositories.GetEntityList(dto.Ids);
|
||||
list = list.Where(w => w.SuccessSync == SyncStatus.Fail || w.SuccessSync == SyncStatus.SyncIng).ToList();
|
||||
foreach (var entity in list)
|
||||
{
|
||||
_logger.LogInformation($"盘点同步3");
|
||||
var res = await Loss_Profit(entity, scope);
|
||||
_logger.LogInformation($"盘点同步4:{JsonConvert.SerializeObject(res)}");
|
||||
if (!res.IsSuccess)
|
||||
_logger.LogError($"盘点同步失败:{res.Message}");
|
||||
}
|
||||
});
|
||||
{
|
||||
var scope = _serviceScopeFactory.CreateScope();
|
||||
var sc_takeStockRepositories = scope.ServiceProvider.GetRequiredService<ITakeStockRepositories>();
|
||||
var list = await sc_takeStockRepositories.GetEntityList(dto.Ids);
|
||||
list = list.Where(w => w.SuccessSync == SyncStatus.Fail || w.SuccessSync == SyncStatus.SyncIng).ToList();
|
||||
foreach (var entity in list)
|
||||
{
|
||||
var res = await Loss_Profit(entity, scope);
|
||||
if (!res.IsSuccess)
|
||||
_logger.LogError($"盘点同步失败:{res.Message}");
|
||||
}
|
||||
});
|
||||
|
||||
return Task.FromResult(Result.ReSuccess());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user