Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
data-center-auto
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bltdc
data-center-auto
Commits
69379a4e
Commit
69379a4e
authored
Jul 28, 2020
by
泽锋 李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
b7832852
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
57 deletions
+133
-57
DbHelper.cs
AutoTurnOver.DB/Base/DbHelper.cs
+119
-1
report_cash_flow_dao.cs
AutoTurnOver.DB/report_cash_flow_dao.cs
+0
-0
dc_report_cash_flow_log.cs
AutoTurnOver.Models/dc_report_cash_flow_log.cs
+1
-1
CaseFlowBackgrounService.cs
ResetOutofstock/CaseFlowBackgrounService.cs
+2
-13
Program.cs
ResetOutofstock/Program.cs
+9
-0
ResetOutofstockBackgrounService.cs
ResetOutofstock/ResetOutofstockBackgrounService.cs
+2
-42
No files found.
AutoTurnOver.DB/Base/DbHelper.cs
View file @
69379a4e
using
AutoTurnOver.Models.Base
;
using
AutoTurnOver.Models.Base
;
using
AutoTurnOver.Utility
;
using
Dapper
;
using
Dapper
;
using
MySql.Data.MySqlClient
;
using
MySql.Data.MySqlClient
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
System.Text
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Text.RegularExpressions
;
...
@@ -142,7 +145,7 @@ namespace AutoTurnOver.DB.Base
...
@@ -142,7 +145,7 @@ namespace AutoTurnOver.DB.Base
/// <typeparam name="T"></typeparam>
/// <typeparam name="T"></typeparam>
/// <param name="entities"></param>
/// <param name="entities"></param>
/// <param name="exclude">排除的字段</param>
/// <param name="exclude">排除的字段</param>
public
static
int
BatchInsert
<
T
>(
this
MySqlConnection
conn
,
List
<
T
>
entities
,
string
[]
exclude
=
null
)
public
static
int
BatchInsert
_bak
<
T
>(
this
MySqlConnection
conn
,
List
<
T
>
entities
,
string
[]
exclude
=
null
)
{
{
if
(
exclude
==
null
||
exclude
.
Length
<=
0
)
if
(
exclude
==
null
||
exclude
.
Length
<=
0
)
exclude
=
new
[]
{
"id"
};
exclude
=
new
[]
{
"id"
};
...
@@ -199,5 +202,120 @@ namespace AutoTurnOver.DB.Base
...
@@ -199,5 +202,120 @@ namespace AutoTurnOver.DB.Base
throw
new
Exception
(
"传入参数先"
);
throw
new
Exception
(
"传入参数先"
);
}
}
/// <summary>
/// Copy数据
/// </summary>
/// <param name="connectionString">目标连接字符</param>
/// <param name="TableName">目标表</param>
/// <param name="dt">源数据</param>
public
static
int
BatchInsert
<
T
>(
this
MySqlConnection
conn
,
IList
<
T
>
list
,
string
tableName
)
{
var
connectionString
=
conn
.
ConnectionString
;
var
sourceTable
=
DataTableExtensions
.
ToDataTable
<
T
>(
list
);
int
insertCount
=
0
;
int
pageIndex
=
1
;
int
pageSize
=
500000
;
while
(
true
)
{
DataTable
table
=
DtSelectTop
((
pageIndex
-
1
)
*
pageSize
,
pageIndex
*
pageSize
,
sourceTable
);
if
(
table
.
Rows
.
Count
<=
0
)
break
;
pageIndex
++;
if
(
table
.
Rows
.
Count
==
0
)
return
0
;
string
tmpPath
=
Path
.
GetTempFileName
();
string
csv
=
DataTableToCsv
(
table
);
File
.
WriteAllText
(
tmpPath
,
csv
);
// MySqlTransaction tran = null;
try
{
conn
.
Open
();
//tran = conn.BeginTransaction();
MySqlBulkLoader
bulk
=
new
MySqlBulkLoader
(
conn
)
{
FieldTerminator
=
","
,
FieldQuotationCharacter
=
'"'
,
EscapeCharacter
=
'"'
,
LineTerminator
=
"\r\n"
,
FileName
=
tmpPath
,
NumberOfLinesToSkip
=
0
,
TableName
=
tableName
,
Timeout
=
1000
*
60
*
60
};
//bulk.Columns.AddRange(table.Columns.Cast<DataColumn>().Select(colum => colum.ColumnName).ToArray());
insertCount
+=
bulk
.
Load
();
// tran.Commit();
}
catch
(
MySqlException
ex
)
{
// if (tran != null) tran.Rollback();
throw
ex
;
}
File
.
Delete
(
tmpPath
);
}
return
insertCount
;
}
/// <summary>
/// 获取DataTable 指定顺序的数据
/// </summary>
/// <param name="beginItem"></param>
/// <param name="endItem"></param>
/// <param name="oDT"></param>
/// <returns></returns>
public
static
DataTable
DtSelectTop
(
long
beginItem
,
long
endItem
,
DataTable
oDT
)
{
try
{
DataTable
NewTable
=
oDT
.
Clone
();
DataRow
[]
rows
=
oDT
.
Select
(
"1=1"
);
for
(
long
i
=
beginItem
;
i
<
endItem
;
i
++)
{
if
(
rows
.
Length
<=
i
)
{
break
;
}
NewTable
.
ImportRow
((
DataRow
)
rows
[
i
]);
}
return
NewTable
;
}
catch
(
Exception
ex
)
{
throw
;
}
}
private
static
string
DataTableToCsv
(
DataTable
table
)
{
//以半角逗号(即,)作分隔符,列为空也要表达其存在。
//列内容如存在半角逗号(即,)则用半角引号(即"")将该字段值包含起来。
//列内容如存在半角引号(即")则应替换成半角双引号("")转义,并用半角引号(即"")将该字段值包含起来。
StringBuilder
sb
=
new
StringBuilder
();
DataColumn
colum
;
foreach
(
DataRow
row
in
table
.
Rows
)
{
for
(
int
i
=
0
;
i
<
table
.
Columns
.
Count
;
i
++)
{
colum
=
table
.
Columns
[
i
];
if
(
i
!=
0
)
sb
.
Append
(
","
);
if
(
colum
.
DataType
==
typeof
(
string
)
&&
row
[
colum
].
ToString
().
Contains
(
","
))
{
sb
.
Append
(
"\""
+
row
[
colum
].
ToString
().
Replace
(
"\""
,
"\"\""
)
+
"\""
);
}
else
sb
.
Append
(
row
[
colum
].
ToString
());
}
sb
.
AppendLine
();
}
return
sb
.
ToString
();
}
}
}
}
}
AutoTurnOver.DB/report_cash_flow_dao.cs
View file @
69379a4e
This diff is collapsed.
Click to expand it.
AutoTurnOver.Models/dc_report_cash_flow_log.cs
View file @
69379a4e
...
@@ -57,7 +57,7 @@ namespace AutoTurnOver.Models
...
@@ -57,7 +57,7 @@ namespace AutoTurnOver.Models
/// 是否作废
/// 是否作废
/// </summary>
/// </summary>
public
int
is_delete
{
get
;
set
;
}
public
int
is_delete
{
get
;
set
;
}
public
DateTime
?
update_time
{
get
;
set
;
}
public
DateTime
update_time
{
get
;
set
;
}
public
string
pay_time_year_month_no
{
get
;
set
;
}
public
string
pay_time_year_month_no
{
get
;
set
;
}
public
string
occur_time_year_month_no
{
get
;
set
;
}
public
string
occur_time_year_month_no
{
get
;
set
;
}
}
}
...
...
ResetOutofstock/CaseFlowBackgrounService.cs
View file @
69379a4e
...
@@ -24,7 +24,7 @@ namespace ResetOutofstock
...
@@ -24,7 +24,7 @@ namespace ResetOutofstock
if
(
now
.
Hour
==
01
&&
now
.
Minute
==
01
)
if
(
now
.
Hour
==
01
&&
now
.
Minute
==
01
)
{
{
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据 (销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据 (销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
report_cash_flow_dao
.
CalculationOrder
Sale
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
report_cash_flow_dao
.
CalculationOrder
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
}
if
(
now
.
Hour
==
01
&&
now
.
Minute
==
02
)
if
(
now
.
Hour
==
01
&&
now
.
Minute
==
02
)
...
@@ -51,18 +51,7 @@ namespace ResetOutofstock
...
@@ -51,18 +51,7 @@ namespace ResetOutofstock
report_cash_flow_dao
.
CalculationOrderCostLogistics
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
report_cash_flow_dao
.
CalculationOrderCostLogistics
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
Console
.
WriteLine
(
$"结束 刷新订单尾程费 退款数据,线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
Console
.
WriteLine
(
$"结束 刷新订单尾程费 退款数据,线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
}
if
(
now
.
Hour
==
01
&&
now
.
Minute
==
06
)
{
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据 (费),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
report_cash_flow_dao
.
CalculationOrderFee
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(费),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
if
(
now
.
Hour
==
01
&&
now
.
Minute
==
07
)
{
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据 (成本),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
report_cash_flow_dao
.
CalculationOrderCost
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(成本),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
}
}
public
override
void
Dispose
()
public
override
void
Dispose
()
...
...
ResetOutofstock/Program.cs
View file @
69379a4e
...
@@ -14,7 +14,16 @@ namespace ResetOutofstock
...
@@ -14,7 +14,16 @@ namespace ResetOutofstock
{
{
Console
.
WriteLine
(
"刷新缺货数据任务启动..."
);
Console
.
WriteLine
(
"刷新缺货数据任务启动..."
);
//report_cash_flow_dao.CalculationOrderCostLogistics(now.AddMonths(-3), DateTime.Parse(now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
//report_cash_flow_dao.CalculationOrderCostLogistics(now.AddMonths(-3), DateTime.Parse(now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
try
{
var
now
=
DateTime
.
Now
;
report_cash_flow_dao
.
CalculationOrder
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
ToString
(
"yyyy-MM-dd 23:59:59"
)));
}
catch
(
Exception
ex
)
{
throw
;
}
var
builder
=
new
HostBuilder
().
ConfigureServices
((
hostContext
,
services
)
=>
var
builder
=
new
HostBuilder
().
ConfigureServices
((
hostContext
,
services
)
=>
{
{
...
...
ResetOutofstock/ResetOutofstockBackgrounService.cs
View file @
69379a4e
...
@@ -14,47 +14,7 @@ namespace ResetOutofstock
...
@@ -14,47 +14,7 @@ namespace ResetOutofstock
protected
override
Task
ExecuteAsync
(
CancellationToken
stoppingToken
)
protected
override
Task
ExecuteAsync
(
CancellationToken
stoppingToken
)
{
{
Task
.
Factory
.
StartNew
(()
=>
{
while
(
true
)
{
try
{
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据(销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
var
now
=
DateTime
.
Now
;
report_cash_flow_dao
.
CalculationOrderFee
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
ex
.
Message
);
}
Thread
.
Sleep
(
240
*
60
*
60
*
1000
);
}
});
Task
.
Factory
.
StartNew
(()
=>
{
while
(
true
)
{
try
{
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据(成本),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
var
now
=
DateTime
.
Now
;
report_cash_flow_dao
.
CalculationOrderCost
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(成本),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
ex
.
Message
);
}
Thread
.
Sleep
(
240
*
60
*
60
*
1000
);
}
});
Task
.
Factory
.
StartNew
(()
=>
{
Task
.
Factory
.
StartNew
(()
=>
{
while
(
true
)
while
(
true
)
...
@@ -64,7 +24,7 @@ namespace ResetOutofstock
...
@@ -64,7 +24,7 @@ namespace ResetOutofstock
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据(销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
Console
.
WriteLine
(
$"开始 刷新现金流 订单数据(销售),线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
var
now
=
DateTime
.
Now
;
var
now
=
DateTime
.
Now
;
report_cash_flow_dao
.
CalculationOrder
Sale
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
report_cash_flow_dao
.
CalculationOrder
(
now
.
AddMonths
(-
3
),
DateTime
.
Parse
(
now
.
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd 23:59:59"
)));
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(销售,线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
Console
.
WriteLine
(
$"结束刷新现金流 订单数据(销售,线程Id:
{
Thread
.
CurrentThread
.
ManagedThreadId
}
,
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment