MQ 分拆Json数据包然后上传
public void UploadInsurHistory() { using (IDbConnection connection = ConnConfig.DmsConnection) { IDbTransaction trans = connection.BeginTransaction(); try { InsuranceBuyAccess gateway = new InsuranceBuyAccess(trans); CommonDataGateway commonDataGateway = new CommonDataGateway(trans); //1、检测系统参数UploadFlag != ‘0‘,就不上传 string uploadFlag = commonDataGateway.GetSettingValue("Repair", "UploadFlag"); if (uploadFlag != "0") { return; } //2、修正数据,将交强险、商业险到期日为 "0001-01-01"的数据到期日置为 NULL gateway.ModifyDueDate(); //3、保险历史数据上传,每500条作为一个Json DataSet dcsDS = gateway.GetAllInsuranceData(); JsonDCS mainJson = new JsonDCS(); mainJson.ver = 1; mainJson.bl = "S.I.INSURANCEBUY"; mainJson.sbl = new ArrayList(); DCSHeader dcsHeader = new DCSHeader(); dcsHeader.bl = "S.I.INSURANCEBUY"; dcsHeader.ver = 1; //一次性将历史数据写入一个Json之中 if (dcsDS.Tables[0].Rows.Count > 0) { JsonDCS insuranceBuyJson = new JsonDCS(); insuranceBuyJson.ver = 1; insuranceBuyJson.bl = "S.I.INSURANCEBUY.INSURANCEBUY_I0"; insuranceBuyJson.cols = new string[]{"FrameNo","BuyDate","InsurerCode","InsuranceType","InsuranceBuyDate","InsuranceMaturityDate","SalesType","Remark","BizNo","TrafficNo", "CommercialNo","CustomerNo","CoverageType","SaleChannel","IsChange","HandlePerson","NextPerson","CustOrigin","CommercialStartDate","CommercialEndDate", "Insured","Tel","TrafficFee","TrafficDiscount","CommercialFee","CommercialDiscount","TotalFee","Deleted","InputPerson","InputTime","OpFlag"}; insuranceBuyJson.data = new object[dcsDS.Tables[0].Rows.Count][]; for (int i = 0; i < dcsDS.Tables[0].Rows.Count; i++) { insuranceBuyJson.data[i] = new object[] { dcsDS.Tables[0].Rows[i]["FRAMENO"], CanHelper.ToDate(dcsDS.Tables[0].Rows[i]["BUYDATE"]), dcsDS.Tables[0].Rows[i]["INSURERCODE"], dcsDS.Tables[0].Rows[i]["INSURANCETYPE"], CanHelper.ToDate(dcsDS.Tables[0].Rows[i]["INSURANCEBUYDATE"]), CanHelper.ToDate(dcsDS.Tables[0].Rows[i]["INSURANCEMATURITYDATE"]), dcsDS.Tables[0].Rows[i]["SALESTYPE"], dcsDS.Tables[0].Rows[i]["REMARK"], dcsDS.Tables[0].Rows[i]["BIZNO"], dcsDS.Tables[0].Rows[i]["TRAFFICNO"], dcsDS.Tables[0].Rows[i]["COMMERCIALNO"], dcsDS.Tables[0].Rows[i]["CUSTOMERNO"], dcsDS.Tables[0].Rows[i]["COVERAGETYPE"], dcsDS.Tables[0].Rows[i]["SALECHANNEL"], dcsDS.Tables[0].Rows[i]["ISCHANGE"], dcsDS.Tables[0].Rows[i]["HANDLEPERSON"], dcsDS.Tables[0].Rows[i]["NEXTPERSON"], dcsDS.Tables[0].Rows[i]["CUSTORIGIN"], CanHelper.ToDate(dcsDS.Tables[0].Rows[i]["COMMERCIALSTARTDATE"]), CanHelper.ToDate(dcsDS.Tables[0].Rows[i]["COMMERCIALENDDATE"]), dcsDS.Tables[0].Rows[i]["INSURED"], dcsDS.Tables[0].Rows[i]["TEL"], dcsDS.Tables[0].Rows[i]["TRAFFICFEE"], dcsDS.Tables[0].Rows[i]["TRAFFICDISCOUNT"], dcsDS.Tables[0].Rows[i]["COMMERCIALFEE"], dcsDS.Tables[0].Rows[i]["COMMERCIALDISCOUNT"], dcsDS.Tables[0].Rows[i]["TOTALFEE"], dcsDS.Tables[0].Rows[i]["DELETED"], dcsDS.Tables[0].Rows[i]["INPUTPERSON"], dcsDS.Tables[0].Rows[i]["INPUTTIME"],"U"}; } mainJson.sbl.Add(insuranceBuyJson); } //分解Json传送数据 if (mainJson.sbl.Count > 0) { int rowCount = ((JsonDCS) mainJson.sbl[0]).data.Length; if (mainJson.sbl != null && mainJson.sbl[0] != null && rowCount > 500) //大于500行的分包发送 { //childCount 分解的后需要传送的Json数目 int childCount = rowCount / 500; if (rowCount % 500 != 0) { childCount++; } JsonDCS subJson = (JsonDCS) mainJson.sbl[0]; for (int i = 1; i < childCount + 1; i++) { JsonDCS childMainJson = new JsonDCS(); childMainJson.bl = "S.I.INSURANCEBUY"; childMainJson.ver = 1; childMainJson.sbl = new ArrayList(); JsonDCS childJson = new JsonDCS(); childJson.bl = "S.I.INSURANCEBUY.INSURANCEBUY_I0"; childJson.ver = 1; childJson.cols = new string[]{"FrameNo","BuyDate","InsurerCode","InsuranceType","InsuranceBuyDate","InsuranceMaturityDate","SalesType","Remark","BizNo","TrafficNo", "CommercialNo","CustomerNo","CoverageType","SaleChannel","IsChange","HandlePerson","NextPerson","CustOrigin","CommercialStartDate","CommercialEndDate", "Insured","Tel","TrafficFee","TrafficDiscount","CommercialFee","CommercialDiscount","TotalFee","Deleted","InputPerson","InputTime","OpFlag"}; childJson.data = new object[500][]; if (i == childCount) { childJson.data = new object[rowCount - ((i - 1) * 500)][]; } for (int j = 0; j < 500; j++) { if (j + (i - 1) * 500 == rowCount) { break; } else { childJson.data[j] = subJson.data[j + (i - 1) * 500]; } } childMainJson.sbl.Add(childJson); gateway.CacheData(mainJson, dcsHeader); } } else { gateway.CacheData(mainJson, dcsHeader); } //4、设置系统参数UploadFlag = ‘1‘ commonDataGateway.UpdateStringValue("1", "Repair", "UploadFlag"); trans.Commit(); } } catch (Exception ex) { trans.Rollback(); throw ex; } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。