Browse Source

解决事务接口事务问题

master
bin.jiang 2 years ago
parent
commit
849c52a5e9
  1. 13550
      host/WmsWebApi.HttpApi.Host/Logs/logs20230224.txt
  2. 17
      host/WmsWebApi.HttpApi.Host/Properties/launchSettings.json
  3. 2
      src/WmsWebApi.Application/OtherZll/OtherZllService.cs
  4. 117
      src/WmsWebApi.Application/ZlldcjLogs/ZlldcjLogAppService.cs
  5. 2
      src/WmsWebApi.EntityFrameworkCore/EntityFrameworkCore/WmsWebApiDbContext.cs

13550
host/WmsWebApi.HttpApi.Host/Logs/logs20230224.txt

File diff suppressed because it is too large

17
host/WmsWebApi.HttpApi.Host/Properties/launchSettings.json

@ -1,24 +1,9 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://localhost:5000",
"sslPort": 5000
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WmsWebApi.DemoApp": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5000",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

2
src/WmsWebApi.Application/OtherZll/OtherZllService.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
@ -328,6 +329,7 @@ public class OtherZllService : ApplicationService, IOtherZllService
{
result.TYPE = 'E';
result.MESSAGE = ex.Message;
throw new UserFriendlyException(ex.Message, null, null, ex);
}
return result;

117
src/WmsWebApi.Application/ZlldcjLogs/ZlldcjLogAppService.cs

@ -11,6 +11,8 @@ using Volo.Abp.Uow;
using WmsWebApi.EntityFrameworkCore;
using WmsWebApi.Wms;
using Abp.Web.Models;
using Microsoft.EntityFrameworkCore;
using Abp.Domain.Uow;
namespace WmsWebApi.ZlldcjLogs;
@ -22,21 +24,24 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
private readonly ITmSapMoveTypeRepository _tbSapMoveTypeRepository;
private readonly ITmOtherAskRepository _tbOtherInOutAskRepository;
private readonly TmOtherAskRepositoryUpdate _tmOtherAskRepositoryUpdate;
private readonly Volo.Abp.Uow.IUnitOfWorkManager _unitOfWorkManager;
public ZlldcjLogAppService(ZlldcjLogManager zlldcjLogManager
, ITbBillRepository tbBillRepository
, ITmSapMoveTypeRepository tbSapMoveTypeRepository
, ITmOtherAskRepository tbOtherInOutAskRepository
, TmOtherAskRepositoryUpdate tmOtherAskRepositoryUpdate)
, TmOtherAskRepositoryUpdate tmOtherAskRepositoryUpdate
, Volo.Abp.Uow.IUnitOfWorkManager unitOfWorkManager)
{
_zlldcjLogManager = zlldcjLogManager;
_tbBillRepository = tbBillRepository;
_tbSapMoveTypeRepository = tbSapMoveTypeRepository;
_tbOtherInOutAskRepository = tbOtherInOutAskRepository;
_tmOtherAskRepositoryUpdate = tmOtherAskRepositoryUpdate;
_unitOfWorkManager = unitOfWorkManager;
}
[HttpPost("add")]
[HttpPost("add")]
public async Task<ReturnResult> AddAsync(List<ZlldcjLogDto> dto)
{
var result = new ReturnResult();
@ -81,6 +86,8 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
return result;
}
try
{
var dtoList = dtos.Where(p => p.WERKS == "1000").ToList();
if (dtoList == null || dtoList.Count == 0)
{
@ -96,8 +103,6 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
_ZlldcjLogs.Add(entity);
}
try
{
var djList = _ZlldcjLogs.Select(p => p.ZLLDJ).Distinct();
foreach (var dj in djList)
{
@ -175,7 +180,6 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
//新增本地单据
await _tbBillRepository.InsertAsync(tbBill, true);
await _tbOtherInOutAskRepository.InsertManyAsync(askList);
}
else
{
@ -188,13 +192,19 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
await _zlldcjLogManager.AddZlldcjAsync(_zlldcjList);
}
}
}
catch (Exception ex)
{
bErr = true;
result.TYPE = 'E';
result.MESSAGE = ex.Message;
throw new UserFriendlyException(ex.Message, null, null, ex);
}
finally
{
}
try
{
WmsWebApiZLLDCJDTO zlldcjdto = new WmsWebApiZLLDCJDTO()
@ -221,6 +231,28 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
return result;
}
private async Task AddDtoAsync(WmsWebApiZLLDCJDTO dto)
{
if (dto == null) { return; }
using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false))
{
await _zlldcjLogManager.AddDtoAsync(dto);
await uow.SaveChangesAsync();
}
}
private async Task AddZlldcjAsync(List<ZlldcjLog> dtos)
{
if (dtos == null || dtos.Count <= 0) { return; }
using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false))
{
await _zlldcjLogManager.AddZlldcjAsync(dtos);
await uow.SaveChangesAsync();
}
}
[HttpPost("close")]
//[UnitOfWork(false)]
public async Task<ReturnResult> CloseAsync([FromBody] object content)//ZlldcjLogDto dto
@ -321,4 +353,79 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
}
return result;
}
[HttpPost("test/shiwu")]
public async Task<ReturnResult> TestShiWu()
{
var result = new ReturnResult();
var dateTime = DateTime.Now;
var tbBill = new TB_BILL()
{
BillNum = dateTime.ToString("yyyyMMddHHmmss"),
State = 0,
BillType = 0,
SubBillType = 0,
BillTime = dateTime,
OperName = dateTime.ToString("yyyyMMddHHmmss"),
DetailQty = 0,
Guid = GuidGenerator.Create()
};
List<TM_PG_OTHER_INOUT_ASK> askList = new List<TM_PG_OTHER_INOUT_ASK>();
for (int i = 0; i < 2; i++)
{
askList.Add(new TM_PG_OTHER_INOUT_ASK()
{
BillNum = dateTime.ToString("yyyyMMddHHmmss"),
BillLineID = i.ToString(),
});
}
var dbContext = await _tbBillRepository.GetDbContextAsync();
dbContext.Database.SetCommandTimeout(120);
try
{
await _tbBillRepository.InsertAsync(tbBill);
throw new Exception("异常了");
await _tbOtherInOutAskRepository.InsertManyAsync(askList);
}
catch (Exception ex)
{
result.TYPE = 'E';
result.MESSAGE = ex.GetBaseException().Message;
throw new UserFriendlyException("经过进一步包装的异常", null, null, ex);
//throw new Exception("经过进一步包装的异常", ex);
}
finally
{
result.TYPE = 'E';
await SaveLogsAsync();
}
return result;
}
private async Task SaveLogsAsync()
{
var dateTime = DateTime.Now;
var tbBill = new TB_BILL()
{
BillNum = dateTime.ToString("yyyyMMddHHmmss") + "log",
State = 0,
BillType = 0,
SubBillType = 0,
BillTime = dateTime,
OperName = dateTime.ToString("yyyyMMddHHmmss"),
DetailQty = 0,
Guid = GuidGenerator.Create()
};
using (var uow = _unitOfWorkManager.Begin(
requiresNew: true, isTransactional: false
))
{
await _tbBillRepository.InsertAsync(tbBill, true);
//await uow.SaveChangesAsync();
}
}
}

2
src/WmsWebApi.EntityFrameworkCore/EntityFrameworkCore/WmsWebApiDbContext.cs

@ -46,7 +46,7 @@ namespace WmsWebApi.EntityFrameworkCore
public WmsWebApiDbContext(DbContextOptions<WmsWebApiDbContext> options)
: base(options)
{
//this.Database.SetCommandTimeout(120);
}
protected override void OnModelCreating(ModelBuilder builder)

Loading…
Cancel
Save