Browse Source

一卡通按小时获取数据

master
ndbs 9 months ago
parent
commit
5f0fce131d
1 changed files with 58 additions and 37 deletions
  1. +58
    -37
      DigitalSchoolApi/Controllers/YKTTrabs.cs

+ 58
- 37
DigitalSchoolApi/Controllers/YKTTrabs.cs View File

@@ -1860,7 +1860,7 @@ namespace DigitalSchoolApi.Controllers
List<DepartmentEntity> departments = db.Query<DepartmentEntity>("select * from LR_Base_Department").ToList();
int anumDept = 0;
int unumDept = 0;
foreach (var item in depts)
{
try
@@ -2353,11 +2353,6 @@ namespace DigitalSchoolApi.Controllers
{
try
{
using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
{
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水1','开始执行',getdate())");
}
string Token = "";
#region 登陆获取token
//获取配置文件
@@ -2377,57 +2372,83 @@ namespace DigitalSchoolApi.Controllers
using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
{
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水2','Token秘钥获取成功',getdate())");
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水','Token秘钥获取成功',getdate())");
}
#endregion

#region 插入数据
using (IDbConnection conn = new SqlConnection(_sqlConnection))
{
var tday = DateTime.Now.ToShortDateString();
DateTime StartTime = DateTime.Today.AddHours(0);
DateTime EndTime = DateTime.Today.AddHours(1);

string JylsUrl = ConfigurationManager.AppSettings["JylsUrl"];
var Historylist = Convert.ToInt64(conn.ExecuteScalar("select isnull(Max(centralNo),0) from MealCardRunTab "));
string data = "{ \"pageNo\":\"1\",\"PageSize\":\"1000\",\"Date\":\"" + DateTime.Now.ToShortDateString() + "\",\"StartTime\":\"00:00:00\",\"EndTime\":\"23:59:59\",\"depcode\":\"7D\"}";
string data = "{ \"pageNo\":\"1\",\"PageSize\":\"1000\",\"Date\":\"" + tday + "\",\"StartTime\":\"00:00:00\",\"EndTime\":\"23:59:59\",\"depcode\":\"7D\"}";
var responses = HttpMethods.sendHttpPost(JylsUrl, Token, data);
var RequsetList = JsonConvert.DeserializeObject<JSONList>(responses);
if (RequsetList.pageTotal > 0)


using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
{
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通数据()','本次一共" + RequsetList.total + "条数据',getdate())");
}


for (int k = 0; k <= 23; k++)
{
for (int i = 1; i <= RequsetList.pageTotal; i++)
using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
{
data = "{ \"pageNo\":\"" + i + " \",\"PageSize\":\"1000\",\"Date\":\"" + DateTime.Now.ToShortDateString() + "\",\"StartTime\":\"00:00:00\",\"EndTime\":\"23:59:59\",\"depcode\":\"7D\"}";
var responses1 = HttpMethods.sendHttpPost(JylsUrl, Token, data);
var RequsetList1 = JsonConvert.DeserializeObject<JSONList>(responses1);
var NowCen = RequsetList1.data.flowlist.Max(x => x.centralNo);
if (NowCen > Historylist)
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通数据','第" + k + "次循环',getdate())");
}
if (k != 0)
{
StartTime = StartTime.AddHours(1);
EndTime = EndTime.AddHours(1);
}
data = "{ \"pageNo\":\"1\",\"PageSize\":\"1000\",\"Date\":\"" + tday + "\",\"StartTime\":\"" + StartTime + "\",\"EndTime\":\"" + EndTime + "\",\"depcode\":\"7D\"}";
responses = HttpMethods.sendHttpPost(JylsUrl, Token, data);
RequsetList = JsonConvert.DeserializeObject<JSONList>(responses);

if (RequsetList.pageTotal > 0)
{
int total = (int)Math.Ceiling((decimal)RequsetList.total / 1000);
using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
{
using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
{
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水3','准备开始插入数据',getdate())");
}
for (int j = 0; j < RequsetList1.data.flowlist.Count; j++)
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水1','一共" + RequsetList.total + "条数据',getdate())");
}

for (int i = 1; i <= total; i++)
{
data = "{ \"pageNo\":\"" + i + " \",\"PageSize\":\"1000\",\"Date\":\"" + tday + "\",\"StartTime\":\"" + StartTime + "\",\"EndTime\":\"" + EndTime + "\",\"depcode\":\"7D\"}";
responses = HttpMethods.sendHttpPost(JylsUrl, Token, data);
RequsetList = JsonConvert.DeserializeObject<JSONList>(responses);
if (RequsetList.data.flowlist.Count > 0)
{
var nowCen = Convert.ToInt32(conn.ExecuteScalar("select Count(*) from MealCardRunTab where centralNo='" + RequsetList1.data.flowlist[j].centralNo + "' "));
if (nowCen <= 0)
{
conn.Execute(
"insert into MealCardRunTab(Id,accountNo,accountName,depName,personId,identiName,flowtype,flowamount,balance,cardNo,centralTm,centralNo,occurTime,node,bigGroup,smallGroup,seg,pos) " +
"values(newid(), '" + RequsetList1.data.flowlist[j].accountNo + "', '" + RequsetList1.data.flowlist[j].accountName + "', '" + RequsetList1.data.flowlist[j].depName + "','" + RequsetList1.data.flowlist[j].personId + "','" + RequsetList1.data.flowlist[j].identiName + "','" + RequsetList1.data.flowlist[j].flowType + "','" + RequsetList1.data.flowlist[j].flowAmount +
"','" + RequsetList1.data.flowlist[j].balance + "','" + RequsetList1.data.flowlist[j].cardNo + "','" + RequsetList1.data.flowlist[j].centralTm + "','" + RequsetList1.data.flowlist[j].centralNo + "','" + RequsetList1.data.flowlist[j].occurTime + "','" + RequsetList1.data.flowlist[j].node + "','" + RequsetList1.data.flowlist[j].bigGroup + "','" + RequsetList1.data.flowlist[j].group + "','" + RequsetList1.data.flowlist[j].seg + "','" + RequsetList1.data.flowlist[j].pos + "')");
}
using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
var NowCen = RequsetList.data.flowlist.Max(x => x.centralNo);
if (NowCen > Historylist)
{
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水4','第" + j + "次插入数据完成',getdate())");
for (int j = 0; j < RequsetList.data.flowlist.Count; j++)
{
var nowCen = Convert.ToInt32(conn.ExecuteScalar("select Count(*) from MealCardRunTab where centralNo='" + RequsetList.data.flowlist[j].centralNo + "' "));
if (nowCen <= 0)
{
conn.Execute(
"insert into MealCardRunTab(Id,accountNo,accountName,depName,personId,identiName,flowtype,flowamount,balance,cardNo,centralTm,centralNo,occurTime,node,bigGroup,smallGroup,seg,pos) " +
"values(newid(), '" + RequsetList.data.flowlist[j].accountNo + "', '" + RequsetList.data.flowlist[j].accountName + "', '" + RequsetList.data.flowlist[j].depName + "','" + RequsetList.data.flowlist[j].personId + "','" + RequsetList.data.flowlist[j].identiName + "','" + RequsetList.data.flowlist[j].flowType + "','" + RequsetList.data.flowlist[j].flowAmount +
"','" + RequsetList.data.flowlist[j].balance + "','" + RequsetList.data.flowlist[j].cardNo + "','" + RequsetList.data.flowlist[j].centralTm + "','" + RequsetList.data.flowlist[j].centralNo + "','" + RequsetList.data.flowlist[j].occurTime + "','" + RequsetList.data.flowlist[j].node + "','" + RequsetList.data.flowlist[j].bigGroup + "','" + RequsetList.data.flowlist[j].group + "','" + RequsetList.data.flowlist[j].seg + "','" + RequsetList.data.flowlist[j].pos + "')");
}
}
}
}
}
using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
{
conncore.Execute(
$"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水5','插入数据',getdate())");
}
}
}

}
#endregion
}


Loading…
Cancel
Save