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 != "")
{
return;
} //2、修正数据,将交强险、商业险到期日为 "0001-01-01"的数据到期日置为 NULL
gateway.ModifyDueDate(); //3、保险历史数据上传,每500条作为一个Json
DataSet dcsDS = gateway.GetAllInsuranceData(); JsonDCS mainJson = new JsonDCS();
mainJson.ver = ;
mainJson.bl = "S.I.INSURANCEBUY";
mainJson.sbl = new ArrayList(); DCSHeader dcsHeader = new DCSHeader();
dcsHeader.bl = "S.I.INSURANCEBUY";
dcsHeader.ver = ; //一次性将历史数据写入一个Json之中
if (dcsDS.Tables[].Rows.Count > )
{
JsonDCS insuranceBuyJson = new JsonDCS();
insuranceBuyJson.ver = ;
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[].Rows.Count][];
for (int i = ; i < dcsDS.Tables[].Rows.Count; i++)
{
insuranceBuyJson.data[i] = new object[] { dcsDS.Tables[].Rows[i]["FRAMENO"], CanHelper.ToDate(dcsDS.Tables[].Rows[i]["BUYDATE"]), dcsDS.Tables[].Rows[i]["INSURERCODE"],
dcsDS.Tables[].Rows[i]["INSURANCETYPE"], CanHelper.ToDate(dcsDS.Tables[].Rows[i]["INSURANCEBUYDATE"]), CanHelper.ToDate(dcsDS.Tables[].Rows[i]["INSURANCEMATURITYDATE"]),
dcsDS.Tables[].Rows[i]["SALESTYPE"], dcsDS.Tables[].Rows[i]["REMARK"], dcsDS.Tables[].Rows[i]["BIZNO"],
dcsDS.Tables[].Rows[i]["TRAFFICNO"], dcsDS.Tables[].Rows[i]["COMMERCIALNO"], dcsDS.Tables[].Rows[i]["CUSTOMERNO"],
dcsDS.Tables[].Rows[i]["COVERAGETYPE"], dcsDS.Tables[].Rows[i]["SALECHANNEL"], dcsDS.Tables[].Rows[i]["ISCHANGE"],
dcsDS.Tables[].Rows[i]["HANDLEPERSON"], dcsDS.Tables[].Rows[i]["NEXTPERSON"], dcsDS.Tables[].Rows[i]["CUSTORIGIN"],
CanHelper.ToDate(dcsDS.Tables[].Rows[i]["COMMERCIALSTARTDATE"]), CanHelper.ToDate(dcsDS.Tables[].Rows[i]["COMMERCIALENDDATE"]), dcsDS.Tables[].Rows[i]["INSURED"],
dcsDS.Tables[].Rows[i]["TEL"], dcsDS.Tables[].Rows[i]["TRAFFICFEE"], dcsDS.Tables[].Rows[i]["TRAFFICDISCOUNT"],
dcsDS.Tables[].Rows[i]["COMMERCIALFEE"], dcsDS.Tables[].Rows[i]["COMMERCIALDISCOUNT"], dcsDS.Tables[].Rows[i]["TOTALFEE"],
dcsDS.Tables[].Rows[i]["DELETED"], dcsDS.Tables[].Rows[i]["INPUTPERSON"], dcsDS.Tables[].Rows[i]["INPUTTIME"],"U"};
} mainJson.sbl.Add(insuranceBuyJson);
} //分解Json传送数据
if (mainJson.sbl.Count > )
{
int rowCount = ((JsonDCS) mainJson.sbl[]).data.Length;
if (mainJson.sbl != null && mainJson.sbl[] != null && rowCount > ) //大于500行的分包发送
{
//childCount 分解的后需要传送的Json数目
int childCount = rowCount / ;
if (rowCount % != )
{
childCount++;
}
JsonDCS subJson = (JsonDCS) mainJson.sbl[];
for (int i = ; i < childCount + ; i++)
{
JsonDCS childMainJson = new JsonDCS();
childMainJson.bl = "S.I.INSURANCEBUY";
childMainJson.ver = ;
childMainJson.sbl = new ArrayList(); JsonDCS childJson = new JsonDCS();
childJson.bl = "S.I.INSURANCEBUY.INSURANCEBUY_I0";
childJson.ver = ;
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[][];
if (i == childCount)
{
childJson.data = new object[rowCount - ((i - ) * )][];
}
for (int j = ; j < ; j++)
{
if (j + (i - ) * == rowCount)
{
break;
}
else
{
childJson.data[j] = subJson.data[j + (i - ) * ];
}
}
childMainJson.sbl.Add(childJson);
gateway.CacheData(mainJson, dcsHeader);
}
}
else
{
gateway.CacheData(mainJson, dcsHeader);
} //4、设置系统参数UploadFlag = '1'
commonDataGateway.UpdateStringValue("", "Repair", "UploadFlag"); trans.Commit();
}
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
}

MQ 分拆Json数据包然后上传的更多相关文章

  1. Burp Post、Get数据包转为上传multipart/form-data格式数据包

    方法一: 新建一个网页进行上传,代码代码如下: <html> <head></head> <body> <form method="po ...

  2. SpringMVC(三)-- 视图和视图解析器、数据格式化标签、数据类型转换、SpringMVC处理JSON数据、文件上传

    1.视图和视图解析器 请求处理方法执行完成后,最终返回一个 ModelAndView 对象 对于那些返回 String,View 或 ModeMap 等类型的处理方法,SpringMVC 也会在内部将 ...

  3. 01- ajax, 登录验证,json数据,文件上传

    1.ajax简介 1.向服务器发送请求的途径 # 向服务器发送请求的途径 1. 浏览器地址栏,默认get请求 2. form表单: get请求 post请求 3. a标签,默认get请求 4. Aja ...

  4. c# 生成json数据包

    json数据类型,归根到底就是一个字符串,管他里面什么格式,它就是一个字符串来的! 看一个json数据包: { "touser":"OPENID", " ...

  5. 使用Ajax方式POST JSON数据包(转)

    add by zhj: 用ajax发送json数据时注意两点, 第一,使用JSON.stringify()函数将data转为json格式的字符串,如下 data: JSON.stringify({   ...

  6. 前端学习——使用Ajax方式POST JSON数据包

    0.前言     本文解释怎样使用Jquery中的ajax方法传递JSON数据包,传递的方法使用POST(当然PUT又有时也是一个不错的选择).POST JSON数据包相比标准的POST格式可读性更好 ...

  7. Django使用cropbox包来上传裁剪图片

    1.使用cropbox包来上传裁剪图片,可见介绍:https://www.jianshu.com/p/6c269f0b48c0I ImgCrop包包括:css--style.css,js--cropb ...

  8. 从零开始写一个npm包及上传

    最近刚好自己需要写公有npm包及上传,虽然百度上资料都能找到,但是都是比较零零碎碎的,个人就来整理下,如何从零开始写一个npm包及上传. 该篇文件只记录一个大概的流程,一些细节没有记录. tips:  ...

  9. 使用FormData数据做图片上传: new FormData() canvas实现图片压缩

    使用FormData数据做图片上传: new FormData()       canvas实现图片压缩 ps: 千万要使用append不要用set   苹果ios有兼容问题导致数据获取不到,需要后台 ...

随机推荐

  1. Volatile小结

    1)Java 中能创建 Volatile 数组吗? 能,Java 中可以创建 volatile 类型数组,不过只是一个指向数组的引用,而不是整个数组.我的意思是,如果改变引用指向的数组,将会受到 vo ...

  2. The 2016 ACM-ICPC Asia Shenyang Regional Contest

    A. Thickest Burger 大数 × 2 + 小数 #include <cstdio> #include <algorithm> using namespace st ...

  3. python之返回状态commands模块

    需要得到命令执行的状态则需要判断$?的值, 在Python中有一个模块commands很容易做到以上的效果. commands.getstatusoutput(cmd)  返回一个元组(status, ...

  4. laravel5.2总结--门面(facades)

    Facades 为应用程序的服务容器中可用的类提供了一个「静态」接口.   Laravel 本身附带许多的 facades,甚至你可能在不知情的状况下已经在使用他们!   xpower的静态接口(门面 ...

  5. 设计模式之第13章-职责链模式(Java实现)

    设计模式之第13章-职责链模式(Java实现) “请假都那么麻烦,至于么.”“咋的了?”“这不快过年了么,所以我想早两天回去,准备一下,买买东西什么的,然后去给项目经理请假,但是他说快过年了,所以这个 ...

  6. postgresql connection failure:SQLSTATE[08006] [7] could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

    PHP 程序无法连接到 CentOS 上的PostgreSQL,但是在 CentOS 服务器上却能正常运行 psql, 操作如下:多次重启 PG 数据库后发现 CGI 脚本无法连接数据库,但是可以使用 ...

  7. 为 rails 本地项目搭建 elasticsearch 服务

    首先安装 elasticsearch 服务 OSX 系统 brew install elasticsearch brew services start elasticsearch 测试服务是否启动浏览 ...

  8. Android App程序结构

    先看结构图: ====================================== 1.   /src   源码目录,不解释. 2.  /gen   gen目录是ADT 自动生成的代码所在位置 ...

  9. Qt数据库查询之事务操作

    在做借书系统的时候,用到了事务操作,不会使用qt中事务操作怎么写,查了一些博客帖子,并不起作用,后来发现,在进行事务成功判断时,出现问题,正确代码如下 if(QSqlDatabase::databas ...

  10. java实现图的深度优先遍历和广度优先遍

    首先需要知道的是,图的深度优先遍历是一种类似于树的前序遍历方式,即选择一个入口节点,沿着这个节点一直遍历下去,直至所有节点都被访问完毕:如果说,图的深度优先遍历类似于树的前序遍历的话,那么图的广度优先 ...