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. 4
      src/WmsWebApi.Application/OtherZll/OtherZllService.cs
  4. 161
      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"
}

4
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;
@ -324,10 +325,11 @@ public class OtherZllService : ApplicationService, IOtherZllService
await _otherZllManager.AddAsync(dto);
}
}
catch(Exception ex)
catch (Exception ex)
{
result.TYPE = 'E';
result.MESSAGE = ex.Message;
throw new UserFriendlyException(ex.Message, null, null, ex);
}
return result;

161
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,23 +86,23 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
return result;
}
var dtoList = dtos.Where(p => p.WERKS == "1000").ToList();
if (dtoList == null || dtoList.Count == 0)
{
bErr = true;
result.MESSAGE = "err:没有1000工厂数据";
}
else
try
{
foreach (var dtoItem in dtos)
var dtoList = dtos.Where(p => p.WERKS == "1000").ToList();
if (dtoList == null || dtoList.Count == 0)
{
var entity = ObjectMapper.Map<ZlldcjLogDto, ZlldcjLog>(dtoItem);
entity.SetId(GuidGenerator);
_ZlldcjLogs.Add(entity);
bErr = true;
result.MESSAGE = "err:没有1000工厂数据";
}
try
else
{
foreach (var dtoItem in dtos)
{
var entity = ObjectMapper.Map<ZlldcjLogDto, ZlldcjLog>(dtoItem);
entity.SetId(GuidGenerator);
_ZlldcjLogs.Add(entity);
}
var djList = _ZlldcjLogs.Select(p => p.ZLLDJ).Distinct();
foreach (var dj in djList)
{
@ -106,7 +111,7 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
//检查是否为存在
var tbBill = await _tbBillRepository.FirstOrDefaultAsync(p => p.BillNum == dj);
//tbBill.CheckIsNotExist();
if(tbBill != null)
if (tbBill != null)
{
result.TYPE = 'E';
bErr = true;
@ -127,8 +132,8 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
};
//确定SubBillType
var sapMoveType = await _tbSapMoveTypeRepository.FirstOrDefaultAsync(p => p.SAPBillType == _zlldcjList[0].ZDJLX
&& p.GetOrBack == _zlldcjList[0].ZLTLX
&& p.MoveType == _zlldcjList[0].BWART);
&& p.GetOrBack == _zlldcjList[0].ZLTLX
&& p.MoveType == _zlldcjList[0].BWART);
var sapBillDesc = "";
if (sapMoveType != null)
{
@ -140,7 +145,7 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
foreach (var item in _zlldcjList)
{
var hasdetail = await _tbOtherInOutAskRepository.FirstOrDefaultAsync(p => p.BillNum == item.ZLLDJ && p.BillLineID == item.ZLLITEM.ToString());
if(hasdetail != null)
if (hasdetail != null)
{
throw new UserFriendlyException($"单号 {item.ZLLDJ},行号 {item.ZLLITEM} 已存在!");
}
@ -173,9 +178,8 @@ public class ZlldcjLogAppService : ApplicationService, IZlldcjLogAppService
item.IType = "新增";
}
//新增本地单据
await _tbBillRepository.InsertAsync(tbBill,true);
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;
}
}
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