调wms接口返回成功后再操作数据库

This commit is contained in:
2023-07-20 14:06:35 +08:00
parent 716c1f5d14
commit 818e259205
8 changed files with 177 additions and 29 deletions

View File

@@ -3,8 +3,10 @@ using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Models;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.RemoteRequest;
using JNPF.Systems.Interfaces.System;
using Mapster;
@@ -48,6 +50,8 @@ namespace Tnb.ProductionMgr
var db = _repository.AsSugarClient();
var location = await db.Queryable<BasLocation>().FirstAsync(x => x.location_code == input.location_code);
PrdInstockH prdInstockH = null;
List<PrdInstockD> prdInstockDs = new List<PrdInstockD>() { };
DbResult<bool> result2 = new DbResult<bool>();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
prdInstockH = new PrdInstockH()
@@ -63,7 +67,6 @@ namespace Tnb.ProductionMgr
status = 0,
};
List<PrdInstockD> prdInstockDs = new List<PrdInstockD>() { };
foreach (var item in input.details)
{
prdInstockDs.Add(new PrdInstockD()
@@ -79,12 +82,12 @@ namespace Tnb.ProductionMgr
});
}
await _repository.InsertAsync(prdInstockH);
if (prdInstockDs.Count > 0)
{
await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
}
// await _repository.InsertAsync(prdInstockH);
//
// if (prdInstockDs.Count > 0)
// {
// await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
// }
});
@@ -132,11 +135,29 @@ namespace Tnb.ProductionMgr
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
};
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_INSTOCK,JsonConvert.SerializeObject(mesCreateInstockInput),header);
Console.WriteLine(sendResult);
Log.Information(sendResult);
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
if (authResponse.code != 200)
{
throw Oops.Bah(authResponse.msg);
}
else
{
result2 = await db.Ado.UseTranAsync(async () =>
{
await _repository.InsertAsync(prdInstockH);
if (prdInstockDs.Count > 0)
{
await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
}
});
}
}
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
if(!result2.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result2.IsSuccess ? "保存成功" : result2.ErrorMessage;
}
/// <summary>
@@ -147,15 +168,26 @@ namespace Tnb.ProductionMgr
public async Task<dynamic> SyncInstock(Dictionary<string, string> dic)
{
string sourceId = dic.ContainsKey("source_id") ? dic["source_id"] : "";
if (!string.IsNullOrEmpty(sourceId))
var db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
return await _repository.UpdateAsync(x => new PrdInstockH()
if (!string.IsNullOrEmpty(sourceId))
{
status = 1
}, x => x.id == sourceId);
}
await _repository.UpdateAsync(x => new PrdInstockH()
{
status = 1
}, x => x.id == sourceId);
var details = await db.Queryable<PrdInstockD>().Where(x => x.instock_id == sourceId).ToListAsync();
return false;
foreach (var item in details)
{
await db.Updateable<PrdReport>().SetColumns(x => x.status == 1)
.Where(x => x.id == item.report_id).ExecuteCommandAsync();
}
}
});
return result.IsSuccess;
}
}
}