调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

@@ -4,10 +4,13 @@ using JNPF.Common.Enums;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Models;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev.Entitys;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ClearScript.Util.Web;
using Newtonsoft.Json;
@@ -163,6 +166,9 @@ namespace Tnb.ProductionMgr
public async Task<dynamic> SaveDataNew(MaterialReceiptNewInput input)
{
var db = _repository.AsSugarClient();
PrdFeedingH prdFeedingH = null;
List<PrdFeedingD> list = new List<PrdFeedingD>();
DbResult<bool> result2 = new DbResult<bool>();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
var moTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == input.mo_task_id);
@@ -176,9 +182,8 @@ namespace Tnb.ProductionMgr
.ToListAsync();
string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.FEEDING_CODE);
PrdFeedingH prdFeedingH = new PrdFeedingH()
prdFeedingH = new PrdFeedingH()
{
code = code,
station_id = input.station_id,
@@ -195,8 +200,7 @@ namespace Tnb.ProductionMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId
};
List<PrdFeedingD> list = new List<PrdFeedingD>();
if (input.details != null && input.details.Count > 0)
{
foreach (var item in input.details)
@@ -253,8 +257,8 @@ namespace Tnb.ProductionMgr
}
await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
// await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
// await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
});
@@ -281,10 +285,69 @@ namespace Tnb.ProductionMgr
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
};
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CARRY_SIGN,JsonConvert.SerializeObject(mesCarrySignInput),header);
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 db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
});
}
}
if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);
return result.IsSuccess ? "签收成功" : result.ErrorMessage;
if(!result2.IsSuccess) throw Oops.Oh(result2.ErrorMessage);
return result2.IsSuccess ? "签收成功" : result2.ErrorMessage;
}
[HttpPost]
public async Task<dynamic> GetFeedingRecordTree()
{
var db = _repository.AsSugarClient();
var result = await db.Queryable<PrdMoTask>()
.Where(a => a.schedule_type == 2 && a.parent_id!=null)
.Select(a => new FeedingRecordTreeOutput()
{
mo_task_code = a.mo_task_code,
children = SqlFunc.Subqueryable<PrdFeedingH>().Where(b=>a.id==b.mo_task_id).ToList(b=>new FeedingRecordChildren()
{
id = b.id,
code = b.code,
// children = SqlFunc.Subqueryable<PrdFeedingD>().LeftJoin<BasMaterial>((c,d)=>c.material_id==d.id)
// .Where((c,d)=>SqlFunc.IIF(b==null,"0",b.id)==c.feeding_id).ToList((c,d)=>new FeedingRecordMaterialChildren()
// {
// // material_code = d.code,
// // material_name = d.name,
// })
// children = new List<FeedingRecordMaterialChildren>(),
// children = b!=null ? SqlFunc.Subqueryable<PrdFeedingD>()
// .Where((c)=>"26897270557717"=="26897270557717").ToList((c)=>new FeedingRecordMaterialChildren()
// {
// // material_code = d.code,
// // material_name = d.name,
// }) : new List<FeedingRecordMaterialChildren>()
})
}).Mapper(x =>
{
foreach (var item in x.children)
{
item.children = db.Queryable<PrdFeedingD>()
.LeftJoin<BasMaterial>((c, d) => c.material_id == d.id)
.Where((c, d) => item.id == c.feeding_id).Select((c,d) => new FeedingRecordMaterialChildren()
{
material_code = d.code,
material_name = d.name,
}).ToList();
}
})
.ToListAsync();
return result;
}
}
}