This commit is contained in:
2024-08-03 00:04:17 +08:00
parent abd8e36e4c
commit 07d656a9d6
3 changed files with 123 additions and 53 deletions

View File

@@ -0,0 +1,10 @@
namespace Tnb.BasicData.Entities.Dto
{
public class ErpPurchaseDto
{
public string pk_arriveorder { get; set; }
public string pk_arriveorder_b { get; set; }
public string csourcebid { get; set; }
public string mes_detail_id { get; set; }
}
}

View File

@@ -14,6 +14,7 @@ using Newtonsoft.Json.Linq;
using SqlSugar; using SqlSugar;
using Tnb.BasicData.Entities; using Tnb.BasicData.Entities;
using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities;
using Tnb.BasicData.Entities.Dto;
namespace Tnb.BasicData namespace Tnb.BasicData
{ {
@@ -207,11 +208,4 @@ namespace Tnb.BasicData
} }
} }
public class ErpPurchaseDto
{
public string pk_arriveorder { get; set; }
public string pk_arriveorder_b { get; set; }
public string csourcebid { get; set; }
public string mes_detail_id { get; set; }
}
} }

View File

@@ -20,6 +20,7 @@ using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SQLitePCL; using SQLitePCL;
using SqlSugar; using SqlSugar;
using SqlSugar.Extensions; using SqlSugar.Extensions;
@@ -39,6 +40,7 @@ using Tnb.ProductionMgr.Interfaces;
using Tnb.ProductionMgr.Entities.Dto.PrdManage; using Tnb.ProductionMgr.Entities.Dto.PrdManage;
using Tnb.ProductionMgr.Entities.Entity; using Tnb.ProductionMgr.Entities.Entity;
using Tnb.ProductionMgr.Entities.Entity.ErpEntity; using Tnb.ProductionMgr.Entities.Entity.ErpEntity;
using Tnb.BasicData.Entities.Dto;
namespace Tnb.ProductionMgr namespace Tnb.ProductionMgr
{ {
@@ -716,56 +718,120 @@ namespace Tnb.ProductionMgr
string response = ""; string response = "";
var elapsedMilliseconds = 0l; var elapsedMilliseconds = 0l;
ThirdResult thirdResult = new ThirdResult(); ThirdResult thirdResult = new ThirdResult();
foreach (var record in records) try
{ {
now = DateTime.Now; await _db.Ado.BeginTranAsync();
stopwatch = Stopwatch.StartNew(); foreach (var record in records)
switch (record.method.ToUpper())
{ {
case "GET": now = DateTime.Now;
response = HttpUtils.RequestGet(record.url); stopwatch = Stopwatch.StartNew();
break; switch (record.method.ToUpper())
case "POST": {
response = HttpUtils.RequestPost(record.url, record.request_data); case "GET":
break; response = HttpUtils.RequestGet(record.url);
break;
case "POST":
response = HttpUtils.RequestPost(record.url, record.request_data);
break;
}
stopwatch.Stop();
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
try
{
thirdResult = JsonConvert.DeserializeObject<ThirdResult>(response);
}
catch (Exception e)
{
thirdResult.Code = 500;
thirdResult.msgResult = response;
}
if (thirdResult.Code == 200)
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.SetColumns(x => x.send_type == "自动")
.SetColumns(x => x.status == 1)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
else
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
if (thirdResult.Code == 200 && record.third_name == "BIP" && record.name == "采购到货")
{
Dictionary<string,object> requestData = JsonConvert.DeserializeObject<Dictionary<string,object>>(record.request_data);
//((JObject)requestData[0]["dtls"]).SelectTokens("csourcebid")
string billCode = requestData.ContainsKey("vbillcode") ? requestData["vbillcode"].ToString() : "";
if (string.IsNullOrEmpty(billCode))
{
Log.Error($"请求记录id{record.id}采购到货单号为空");
}
var requestDtos = ((JArray)requestData["dtls"]).Select(x => new ErpPurchaseDto()
{
csourcebid = x["csourcebid"]?.ToString(),
mes_detail_id = x["mes_detail_id"]?.ToString(),
}).ToList();
JObject data = (JObject)thirdResult.msg;
JToken children = data.SelectToken("children")[0];
var responsetDtos = children.Select(x => new ErpPurchaseDto()
{
pk_arriveorder = x["valueIndex"]["pk_arriveorder"].ToString(),
pk_arriveorder_b = x["valueIndex"]["pk_arriveorder_b"].ToString(),
csourcebid = x["valueIndex"]["csourcebid"].ToString()
}).ToList();
string pk_arriveorder = responsetDtos[0]?.pk_arriveorder ?? "";
int updateDRow = 0;
bool flag = !string.IsNullOrEmpty(pk_arriveorder);
foreach (var item in requestDtos)
{
string pk_arriveorder_b = responsetDtos.Find(x => x.csourcebid == item.csourcebid)?.pk_arriveorder_b;
if (string.IsNullOrEmpty(pk_arriveorder_b))
{
flag = true;
break;
}
updateDRow += await _db.Updateable<WmsPurchaseD>()
.SetColumns(x => x.erp_arriveorder_b_pk == pk_arriveorder_b)
.Where(x => x.id == item.mes_detail_id)
.ExecuteCommandAsync();
}
int updateRow = await _db.Updateable<WmsPurchaseH>()
.SetColumns(x => x.erp_arriveorder_pk == pk_arriveorder)
.Where(x => x.bill_code == billCode)
.ExecuteCommandAsync();
if (flag || updateRow <= 0 || updateDRow <= 0)
{
Log.Error($"更新失败,requestDtos:{JsonConvert.SerializeObject(requestDtos)},responsetDtos:{JsonConvert.SerializeObject(responsetDtos)}");
}
}
} }
await _db.Ado.CommitTranAsync();
stopwatch.Stop();
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
try
{
thirdResult = JsonConvert.DeserializeObject<ThirdResult>(response);
}
catch (Exception e)
{
thirdResult.Code = 500;
thirdResult.msgResult = response;
}
if (thirdResult.Code == 200)
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.SetColumns(x => x.send_type == "自动")
.SetColumns(x => x.status == 1)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
else
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
} }
catch (Exception e)
{
Log.Error(e.Message,e);
await _db.Ado.RollbackTranAsync();
}
return "true"; return "true";
} }