using System.Diagnostics; using JNPF.Common.Core.Manager; using JNPF.Common.Extension; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.Extras.CollectiveOAuth.Utils; using JNPF.FriendlyException; using JNPF.Logging; using JNPF.Systems.Interfaces.Permission; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NPOI.Util; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; using Tnb.BasicData.Entities.Dto; using Tnb.ProductionMgr.Entities; using Tnb.BasicData.Interfaces; using Tnb.WarehouseMgr.Entities.Entity; using JNPF.Common.Security; namespace Tnb.BasicData { /// /// 第三方接口发送记录 /// [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] public class ThirdApiRecordService : IThirdApiRecordService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; public ThirdApiRecordService( ISqlSugarRepository repository, IUserManager userManager ) { _repository = repository; _userManager = userManager; } [HttpGet] [AllowAnonymous] public async Task Send(string id) { ThirdWebapiRecord record = await _repository.GetSingleAsync(x=>x.id==id); if (record.name == "产成品入库") { Dictionary requestData = JsonConvert.DeserializeObject>>(record.request_data)[0]; string reportId = requestData["report_id"].ToString(); PrdReport report = await _repository.AsSugarClient().Queryable().Where(x=>x.id==reportId).SingleAsync(); // if (report != null && !string.IsNullOrEmpty(report.erp_pk_wr) && !string.IsNullOrEmpty(report.erp_pk_wr_product) && !string.IsNullOrEmpty(report.vsourcebillcode) && !string.IsNullOrEmpty(report.vsourcerowno)) if (report != null && !string.IsNullOrEmpty(report.erp_pk_wr) && !string.IsNullOrEmpty(report.erp_pk_wr_product)) { requestData["csourcebillhid"] = report.erp_pk_wr; JArray dtls = (JArray)requestData["dtls"]; foreach (var item in dtls) { item["csourcebillhid"] = report.erp_pk_wr; item["csourcebillbid"] = report.erp_pk_wr_product; item["vsourcebillcode"] = report.vsourcebillcode; item["vsourcerowno"] = report.vsourcerowno; } record.request_data = JsonConvert.SerializeObject(requestData); await _repository.AsSugarClient().Updateable() .SetColumns(x => x.request_data == record.request_data) .Where(x => x.id == record.id) .ExecuteCommandAsync(); } } ThirdResult thirdResult = await Send(Arrays.AsList(record), "手动",null,false); return thirdResult.msgResult; } [HttpGet] [AllowAnonymous] public async Task test() { var db = _repository.AsSugarClient(); string response = "{\"Code\":200,\"msg\":{\"children\":[[{\"valueIndex\":{\"cfirstbid\":\"1001A1100000000KLLLV\",\"pk_group\":\"0001H11000000000257J\",\"pk_reqstoorg\":\"0001A11000000007GGN9\",\"dproducedate\":{\"utcTime\":1722355200000},\"bfixedrate\":{\"value\":true},\"ccurrencyid\":\"1002Z0100000000001K1\",\"nplanastnum\":{\"power\":0,\"si\":1,\"v\":[0,10,0,0,0],\"trimZero\":false},\"nprice\":{\"power\":-3,\"si\":1,\"v\":[5690000000000000,7,0,0,0],\"trimZero\":false},\"pk_org\":\"0001A11000000007GGN9\",\"norigtaxprice\":{\"power\":-1,\"si\":1,\"v\":[7000000000000000,8,0,0,0],\"trimZero\":false},\"pk_material\":\"1001A11000000000WHK1\",\"csourcetypecode\":\"21\",\"ctaxcountryid\":\"0001Z010000000079UJJ\",\"pk_arriveorder\":\"1001B1100000000KM4ZE\",\"pk_order\":\"1001A1100000000KLLLV\",\"pk_psfinanceorg_v\":\"0001A11000000007GGN8\",\"bbackreforder\":{\"value\":false},\"castunitid\":\"0001Z0100000000000XI\",\"pk_apfinanceorg_v\":\"0001A11000000007GGN8\",\"cunitid\":\"0001Z0100000000000XI\",\"fproductclass\":1,\"cfirsttypecode\":\"21\",\"pk_reqstoorg_v\":\"0001A11000000007GGN8\",\"pk_srcmaterial\":\"1001A11000000000WHK1\",\"ntaxmny\":{\"power\":-8,\"si\":1,\"v\":[5000000000000000,43,0,0,0],\"trimZero\":false},\"pk_order_b\":\"1001A1100000000KLLLX\",\"ntaxrate\":{\"power\":0,\"si\":1,\"v\":[0,13,0,0,0],\"trimZero\":false},\"fbuysellflag\":1,\"pk_org_v\":\"0001A11000000007GGN8\",\"ntaxprice\":{\"power\":-1,\"si\":1,\"v\":[7000000000000000,8,0,0,0],\"trimZero\":false},\"pk_psfinanceorg\":\"0001A11000000007GGN8\",\"crececountryid\":\"0001Z010000000079UJJ\",\"norigtaxmny\":{\"power\":-8,\"si\":1,\"v\":[5000000000000000,43,0,0,0],\"trimZero\":false},\"naccumchecknum\":{\"power\":-8,\"si\":1,\"v\":[0,0,0,0,0],\"trimZero\":false},\"nastnum\":{\"power\":-1,\"si\":1,\"v\":[0,5,0,0,0],\"trimZero\":false},\"pk_arriveorder_b\":\"1001B1100000000KM4ZF\",\"ntax\":{\"power\":-8,\"si\":1,\"v\":[6550000000000000,5,0,0,0],\"trimZero\":false},\"pk_receivestore\":\"1001A1100000000JXT9L\",\"dplanreceivedate\":{\"utcTime\":1722355200000},\"dbilldate\":{\"utcTime\":1722355200000},\"csourcebid\":\"1001A1100000000KLLLX\",\"csourceid\":\"1001A1100000000KLLLV\",\"corigcurrencyid\":\"1002Z0100000000001K1\",\"nplannum\":{\"power\":0,\"si\":1,\"v\":[0,10,0,0,0],\"trimZero\":false},\"nexchangerate\":{\"power\":-8,\"si\":1,\"v\":[0,1,0,0,0],\"trimZero\":false},\"vchangerate\":\"1/1\",\"nelignum\":{\"power\":-8,\"si\":1,\"v\":[0,0,0,0,0],\"trimZero\":false},\"nnum\":{\"power\":-1,\"si\":1,\"v\":[0,5,0,0,0],\"trimZero\":false},\"norigprice\":{\"power\":-3,\"si\":1,\"v\":[5690000000000000,7,0,0,0],\"trimZero\":false},\"csendcountryid\":\"0001Z010000000079UJJ\",\"cfirstid\":\"1001A1100000000KLLLX\",\"crowno\":\"10\",\"vbatchcode\":\"123456789\",\"nmny\":{\"power\":-8,\"si\":1,\"v\":[8450000000000000,37,0,0,0],\"trimZero\":false},\"norigmny\":{\"power\":-8,\"si\":1,\"v\":[8450000000000000,37,0,0,0],\"trimZero\":false},\"ts\":{\"utcTime\":1722415114000}},\"status\":0,\"m_isDirty\":false},{\"valueIndex\":{\"cfirstbid\":\"1001A1100000000KLLLV\",\"pk_group\":\"0001H11000000000257J\",\"pk_reqstoorg\":\"0001A11000000007GGN9\",\"dproducedate\":{\"utcTime\":1722355200000},\"bfixedrate\":{\"value\":true},\"ccurrencyid\":\"1002Z0100000000001K1\",\"nplanastnum\":{\"power\":0,\"si\":1,\"v\":[0,10,0,0,0],\"trimZero\":false},\"nprice\":{\"power\":-3,\"si\":1,\"v\":[5690000000000000,7,0,0,0],\"trimZero\":false},\"pk_org\":\"0001A11000000007GGN9\",\"norigtaxprice\":{\"power\":-1,\"si\":1,\"v\":[7000000000000000,8,0,0,0],\"trimZero\":false},\"pk_material\":\"1001A11000000000WHK1\",\"csourcetypecode\":\"21\",\"ctaxcountryid\":\"0001Z010000000079UJJ\",\"pk_arriveorder\":\"1001B1100000000KM4ZE\",\"pk_order\":\"1001A1100000000KLLLV\",\"pk_psfinanceorg_v\":\"0001A11000000007GGN8\",\"bbackreforder\":{\"value\":false},\"castunitid\":\"0001Z0100000000000XI\",\"pk_apfinanceorg_v\":\"0001A11000000007GGN8\",\"cunitid\":\"0001Z0100000000000XI\",\"fproductclass\":1,\"cfirsttypecode\":\"21\",\"pk_reqstoorg_v\":\"0001A11000000007GGN8\",\"pk_srcmaterial\":\"1001A11000000000WHK1\",\"ntaxmny\":{\"power\":-8,\"si\":1,\"v\":[5000000000000000,43,0,0,0],\"trimZero\":false},\"pk_order_b\":\"1001A1100000000KLLLX\",\"ntaxrate\":{\"power\":0,\"si\":1,\"v\":[0,13,0,0,0],\"trimZero\":false},\"fbuysellflag\":1,\"pk_org_v\":\"0001A11000000007GGN8\",\"ntaxprice\":{\"power\":-1,\"si\":1,\"v\":[7000000000000000,8,0,0,0],\"trimZero\":false},\"pk_psfinanceorg\":\"0001A11000000007GGN8\",\"crececountryid\":\"0001Z010000000079UJJ\",\"norigtaxmny\":{\"power\":-8,\"si\":1,\"v\":[5000000000000000,43,0,0,0],\"trimZero\":false},\"naccumchecknum\":{\"power\":-8,\"si\":1,\"v\":[0,0,0,0,0],\"trimZero\":false},\"nastnum\":{\"power\":-1,\"si\":1,\"v\":[0,5,0,0,0],\"trimZero\":false},\"pk_arriveorder_b\":\"测试1111\",\"ntax\":{\"power\":-8,\"si\":1,\"v\":[6550000000000000,5,0,0,0],\"trimZero\":false},\"pk_receivestore\":\"1001A1100000000JXT9L\",\"dplanreceivedate\":{\"utcTime\":1722355200000},\"dbilldate\":{\"utcTime\":1722355200000},\"csourcebid\":\"1001A1100000000KLLLX\",\"csourceid\":\"1001A1100000000KLLLV\",\"corigcurrencyid\":\"1002Z0100000000001K1\",\"nplannum\":{\"power\":0,\"si\":1,\"v\":[0,10,0,0,0],\"trimZero\":false},\"nexchangerate\":{\"power\":-8,\"si\":1,\"v\":[0,1,0,0,0],\"trimZero\":false},\"vchangerate\":\"1/1\",\"nelignum\":{\"power\":-8,\"si\":1,\"v\":[0,0,0,0,0],\"trimZero\":false},\"nnum\":{\"power\":-1,\"si\":1,\"v\":[0,5,0,0,0],\"trimZero\":false},\"norigprice\":{\"power\":-3,\"si\":1,\"v\":[5690000000000000,7,0,0,0],\"trimZero\":false},\"csendcountryid\":\"0001Z010000000079UJJ\",\"cfirstid\":\"1001A1100000000KLLLX\",\"crowno\":\"10\",\"vbatchcode\":\"123456789\",\"nmny\":{\"power\":-8,\"si\":1,\"v\":[8450000000000000,37,0,0,0],\"trimZero\":false},\"norigmny\":{\"power\":-8,\"si\":1,\"v\":[8450000000000000,37,0,0,0],\"trimZero\":false},\"ts\":{\"utcTime\":1722415114000}},\"status\":0,\"m_isDirty\":false}]],\"parent\":{\"valueIndex\":{\"ntotaltaxmny\":{\"power\":-1,\"si\":1,\"v\":[5000000000000000,43,0,0,0],\"trimZero\":false},\"pk_purchaseorg\":\"0001A11000000007GGN9\",\"ntotalastnum\":{\"power\":0,\"si\":1,\"v\":[0,5,0,0,0],\"trimZero\":false},\"pk_org\":\"0001A11000000007GGN9\",\"dbilldate\":{\"utcTime\":1722355200000},\"pk_supplier\":\"1001A110000000007U02\",\"approver\":\"1001H11000000000000X\",\"pk_arriveorder\":\"1001B1100000000KM4ZE\",\"bisback\":{\"value\":false},\"creator\":\"1001H11000000000000X\",\"ctrantypeid\":\"0001H11000000000D2ZU\",\"fbillstatus\":3,\"pk_dept_v\":\"0001A11000000000S786\",\"vtrantypecode\":\"23-01\",\"taudittime\":{\"utcTime\":1722415114000},\"pk_busitype\":\"1001A110000000009NUO\",\"dmakedate\":{\"utcTime\":1722355200000},\"pk_supplier_v\":\"1001A110000000007U02\",\"vbillcode\":\"DH2024070012\",\"pk_dept\":\"1001A110000000003CC3\",\"billmaker\":\"1001A110000000026S7L\",\"pk_purchaseorg_v\":\"0001A11000000007GGN8\",\"creationtime\":{\"utcTime\":1722415114000},\"pk_org_v\":\"0001A11000000007GGN8\",\"ts\":{\"utcTime\":1722415114000}},\"status\":0,\"m_isDirty\":false}},\"msgResult\":\"执行成功\"}"; string requestDataJson = "{\"approver\":\"1001A110000000026S7L\",\"billmaker\":\"1001A110000000026S7L\",\"creationtime\":\"2024-07-31 16:18:30\",\"creator\":\"1001A110000000026S7L\",\"dbilldate\":\"2024-07-31 16:18:30\",\"dmakedate\":\"2024-07-31 16:18:30\",\"ntotalastnum\":0.0,\"pk_arriveorder\":null,\"Pk_receivepsndoc\":\"1001A110000000026S7L\",\"pk_org\":\"0001A11000000007GGN9\",\"pk_org_v\":\"0001A11000000007GGN8\",\"pk_group\":\"0001H11000000000257J\",\"pk_pupsndoc\":\"\",\"pk_purchaseorg\":\"0001A11000000007GGN9\",\"pk_purchaseorg_v\":\"0001A11000000007GGN8\",\"pk_supplier\":\"1001A110000000007U02\",\"pk_supplier_v\":\"1001A110000000007U02\",\"vbillcode\":\"WP202407310004\",\"vmemo\":null,\"vtrantypecode\":\"\",\"csourceid\":\"1001A1100000000KLLLV\",\"dtls\":[{\"castunitid\":\"0001Z0100000000000XI\",\"cfirstbid\":\"1001A1100000000KLLLV\",\"cfirstid\":\"1001A1100000000KLLLX\",\"cfirsttypecode\":\"\",\"crececountryid\":\"0001Z010000000079UJJ\",\"crowno\":10,\"csendcountryid\":\"0001Z010000000079UJJ\",\"csourcetypecode\":\"\",\"ctaxcountryid\":\"0001Z010000000079UJJ\",\"cunitid\":\"0001Z0100000000000XI\",\"dbilldate\":\"2024-07-31 16:18:30\",\"dplanreceivedate\":\"2024-07-31 16:18:30\",\"dproducedate\":\"2024-07-31 16:18:30\",\"fbuysellflag\":1,\"fproductclass\":1,\"naccumchecknum\":0,\"nnum\":5.0,\"nplannum\":10.0,\"apfinanceorg\":\"0001A11000000007GGN9\",\"pk_apfinanceorg_v\":\"0001A11000000007GGN8\",\"pk_arriveorder\":null,\"pk_arriveorder_b\":null,\"pk_group\":\"\",\"csourcebid\":\"1001A1100000000KLLLX\",\"csourceid\":\"1001A1100000000KLLLV\",\"pk_material\":\"1001A11000000000WHK1\",\"pk_order\":\"1001A1100000000KLLLV\",\"pk_order_b\":\"1001A1100000000KLLLX\",\"pk_org\":\"0001A11000000007GGN9\",\"pk_org_v\":\"0001A11000000007GGN8\",\"pk_psfinanceorg\":\"0001A11000000007GGN8\",\"pk_psfinanceorg_v\":\"0001A11000000007GGN8\",\"pk_receivestore\":\"1001A1100000000JXT9L\",\"pk_reqstoorg\":\"0001A11000000007GGN9\",\"pk_reqstoorg_v\":\"0001A11000000007GGN8\",\"pk_srcmaterial\":\"1001A11000000000WHK1\",\"vbatchcode\":\"123456789\",\"Vfree1\":\"123456789\"}]}"; Dictionary requestData = JsonConvert.DeserializeObject>(requestDataJson); var aaa = ((JArray)requestData["dtls"]).Select(x => new ErpPurchaseDto() { csourcebid = x["csourcebid"]?.ToString(), mes_detail_id = x["mes_detail_id"]?.ToString(), }).ToList(); try { ThirdResult thirdResult = JsonConvert.DeserializeObject(response); Console.WriteLine(thirdResult); JObject data = (JObject)thirdResult.msg; JToken children = data.SelectToken("children")[0]; JToken parent = data.SelectToken("parent"); var bbb = 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(); } catch (Exception e) { Log.Error(e.Message,e); } return "失败"; } public async Task Send(List records, string send_type,ISqlSugarClient db=null,bool threadFlag=true) { ThirdResult thirdResult = new ThirdResult(); if (threadFlag) { Task.Run(() => { Send(records, send_type, db); }); } else { thirdResult = await Send(records, send_type, db); } return thirdResult; } private async Task Send(List records, string send_type, ISqlSugarClient db = null) { ThirdResult thirdResult = null; bool tranFlag = true; try { if (records == null || records.IsEmpty()) return new ThirdResult(); if (db == null) { db = _repository.AsSugarClient(); } else { tranFlag = false; } DateTime now = DateTime.Now; Stopwatch stopwatch = null; string response = ""; var elapsedMilliseconds = 0l; foreach (var record in records) { now = DateTime.Now; stopwatch = Stopwatch.StartNew(); switch (record.method.ToUpper()) { case "GET": response = HttpUtils.RequestGet(record.url); break; case "POST": response = HttpUtils.RequestPost(record.url, record.request_data); break; } stopwatch.Stop(); elapsedMilliseconds = stopwatch.ElapsedMilliseconds; thirdResult = new ThirdResult(); try { if (response != null && !response.IsEmpty()) { thirdResult = JsonConvert.DeserializeObject(response); } else { thirdResult.Code = 500; } } catch (Exception e) { thirdResult.Code = 500; thirdResult.msgResult = response; } if(db==null) await db.Ado.BeginTranAsync(); if (thirdResult.Code == 200) { await db.Updateable() .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 == send_type) .SetColumns(x => x.status == "1") .Where(x=>x.id==record.id) .ExecuteCommandAsync(); } else { await db.Updateable() .SetColumns(x => x.response_data == response) .SetColumns(x => x.response_code == thirdResult.Code) .SetColumns(x => x.last_send_time == now) .SetColumns(x => x.error_count == x.error_count + 1) .SetColumns(x => x.response_time == elapsedMilliseconds) .Where(x=>x.id==record.id) .ExecuteCommandAsync(); } if (thirdResult.Code == 200 && record.third_name == "BIP" && record.name == "采购到货") { Dictionary requestData = JsonConvert.DeserializeObject>(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() .SetColumns(x => x.erp_arriveorder_b_pk == pk_arriveorder_b) .Where(x => x.id == item.mes_detail_id) .ExecuteCommandAsync(); } int updateRow = await db.Updateable() .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)}"); } } if (thirdResult.Code == 200 && record.third_name == "BIP" && record.name == "委外到货") { Dictionary requestData = JsonConvert.DeserializeObject>(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() .SetColumns(x => x.erp_arriveorder_b_pk == pk_arriveorder_b) .Where(x => x.id == item.mes_detail_id) .ExecuteCommandAsync(); } int updateRow = await db.Updateable() .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)}"); } } if (thirdResult.Code == 200 && record.third_name == "BIP" && record.name == "生产报告") { Dictionary requestData = JsonConvert.DeserializeObject>(record.request_data); string reportId = requestData.ContainsKey("report_id") ? requestData["report_id"].ToString() : ""; if (string.IsNullOrEmpty(reportId)) { Log.Error($"请求记录id{record.id}生产报告提报id为空"); } JObject data = (JObject)thirdResult.msg; JToken children = data.SelectToken("children")[0]; JToken parent = data.SelectToken("parent"); string vbillcode = parent["valueIndex"]["vbillcode"].ToString(); var responsetDtos = children.Select(x => new ErpReportDto() { // pk_wr_product = x["valueIndex"]["pk_wr_product"].ToString(), // pk_wr_product = x["qualityvos"][0]["pk_wr_product_q"].ToString(), pk_wr_product = x["qualityvos"][0]["valueIndex"]["pk_wr_quality"].ToString(), pk_wr = x["valueIndex"]["pk_wr"].ToString(), vsourcerowno = x["valueIndex"]["vbrowno"].ToString(), vsourcebillcode = vbillcode, report_id = reportId }).ToList(); int updateRow = 0; foreach (var item in responsetDtos) { if (!string.IsNullOrEmpty(item.pk_wr) && !string.IsNullOrEmpty(item.pk_wr_product)) { updateRow += await db.Updateable() .SetColumns(x => x.erp_pk_wr == item.pk_wr) .SetColumns(x => x.erp_pk_wr_product == item.pk_wr_product) .SetColumns(x=>x.vsourcebillcode==item.vsourcebillcode) .SetColumns(x=>x.vsourcerowno==item.vsourcerowno) .Where(x => x.id == item.report_id) .ExecuteCommandAsync(); } } if (updateRow <= 0) { Log.Error($"请求记录{record.id}更新失败"); } } //产成品入库的BIP调用完成之后,自动新增生产入库记录 if(thirdResult.Code==200 && record.third_name=="BIP" && record.name == "产成品入库") { //根据生产提报记录的report_id,与生产入库子表中的prd_report_id字段对应,找到生产入库子表记录,然后根据子表记录找到对应的主表记录 var requestDatas = JsonConvert.DeserializeObject>>(record.request_data); if (requestDatas == null || requestDatas.Count <= 0) Log.Error($"产成品入库同步BIP后,更新生产入库记录失败,请求数据为空:{record.request_data}"); foreach (var reqData in requestDatas) { var prd_instock_h_id = reqData["prd_instock_h_id"].ToString(); #region 修改生成入库记录主表数据为已同步bip await db.Updateable().SetColumns(r => r.is_sync_bip == 1).Where(r => r.id == prd_instock_h_id).ExecuteCommandAsync(); #endregion } } } if(tranFlag) await db.Ado.CommitTranAsync(); } catch (Exception e) { Log.Error(e.Message,e); if(tranFlag) await db.Ado.RollbackTranAsync(); } return thirdResult; } } }