Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DataCenter_Core2.1_20190520
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
DataCenter_Core2.1_20190520
Commits
a4bbae70
Commit
a4bbae70
authored
Jul 16, 2021
by
GhostUI
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://code.bailuntec.com/bltdc/DataCenter_Core2.1_20190520
parents
471e671e
feb0b63e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
455 additions
and
17 deletions
+455
-17
flowing_sales.cs
Bailun.DC.Models/DataWareHouse/flowing_sales.cs
+1
-0
PlatformOrderServices.cs
Bailun.DC.Services/DataWareHouse/PlatformOrderServices.cs
+78
-1
PlatformOrderController.cs
...reas/DataWareHouse/Controllers/PlatformOrderController.cs
+157
-0
OrderBillings.cshtml
...as/DataWareHouse/Views/PlatformOrder/OrderBillings.cshtml
+157
-16
BaseController.cs
Bailun.DC.Web/Base/BaseController.cs
+60
-0
NpolHelper.cs
Bailun.DC.Web/Base/NpolHelper.cs
+2
-0
No files found.
Bailun.DC.Models/DataWareHouse/flowing_sales.cs
View file @
a4bbae70
...
...
@@ -27,5 +27,6 @@ namespace Bailun.DC.Models.DataWareHouse
public
DateTime
?
datatime
{
get
;
set
;
}
public
string
platformsku
{
get
;
set
;
}
}
}
Bailun.DC.Services/DataWareHouse/PlatformOrderServices.cs
View file @
a4bbae70
...
...
@@ -26,7 +26,7 @@ namespace Bailun.DC.Services.DataWareHouse
var
sql
=
$"select t1.website from flowing_sales t1 where t1.platform='
{
platform
}
' group by t1.website"
;
return
cn
.
Query
<
string
>(
sql
).
ToList
();
return
cn
.
Query
<
string
>(
sql
).
Where
(
a
=>!
string
.
IsNullOrEmpty
(
a
)).
ToList
();
}
}
...
...
@@ -107,5 +107,82 @@ namespace Bailun.DC.Services.DataWareHouse
}
/// <summary>
/// 获取销售平台流水的模版数据
/// </summary>
/// <param name="platform"></param>
/// <param name="website"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <returns></returns>
public
Models
.
DataWareHouse
.
flowing_sales
Get
(
string
platform
,
string
website
,
DateTime
?
start
,
DateTime
?
end
)
{
var
sql
=
"select * from flowing_sales where 1=1"
;
var
sqlParam
=
new
DynamicParameters
();
if
(!
string
.
IsNullOrEmpty
(
platform
))
{
sql
+=
" and platform=@platform"
;
sqlParam
.
Add
(
"platform"
,
platform
);
}
if
(!
string
.
IsNullOrEmpty
(
website
))
{
sql
+=
" and website=@website"
;
sqlParam
.
Add
(
"website"
,
website
);
}
if
(
start
.
HasValue
)
{
sql
+=
$" and datatime>='
{
start
.
Value
.
ToString
(
"yyyy-MM-dd"
)}
'"
;
}
if
(
end
.
HasValue
)
{
sql
+=
$" and datatime<'
{
end
.
Value
.
AddDays
(
1
).
ToString
(
"yyyy-MM-dd"
)}
'"
;
}
using
(
var
cn
=
new
MySqlConnection
(
Common
.
GlobalConfig
.
ConnectionString_DW
))
{
if
(
cn
.
State
==
System
.
Data
.
ConnectionState
.
Closed
)
{
cn
.
Open
();
}
var
obj
=
cn
.
QueryFirstOrDefault
<
Models
.
DataWareHouse
.
flowing_sales
>(
sql
,
sqlParam
);
return
obj
;
}
}
/// <summary>
/// 保存流水信息
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public
string
InsertOrderBilling
(
List
<
Models
.
DataWareHouse
.
flowing_sales
>
list
)
{
try
{
using
(
var
cn
=
new
MySqlConnection
(
Common
.
GlobalConfig
.
ConnectionString_DW
))
{
if
(
cn
.
State
==
System
.
Data
.
ConnectionState
.
Closed
)
{
cn
.
Open
();
}
foreach
(
var
item
in
list
)
{
cn
.
Insert
(
item
);
}
}
return
""
;
}
catch
(
Exception
ex
)
{
return
ex
.
Message
;
}
}
}
}
Bailun.DC.Web/Areas/DataWareHouse/Controllers/PlatformOrderController.cs
View file @
a4bbae70
...
...
@@ -6,6 +6,7 @@ using System.Linq;
using
Microsoft.AspNetCore.Hosting
;
using
System.Threading.Tasks
;
namespace
Bailun.DC.Web.Areas.DataWareHouse.Controllers
{
[
Area
(
"DataWareHouse"
)]
...
...
@@ -189,5 +190,161 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
ms
.
Position
=
0
;
return
File
(
ms
,
"text/csv"
,
filename
+
".csv"
);
}
/// <summary>
/// 下载销售平台流水上传模版
/// </summary>
/// <param name="platform"></param>
/// <param name="website"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <returns></returns>
public
ActionResult
DownLoadOrderBillingTemplate
(
string
platform
,
string
website
,
DateTime
?
start
,
DateTime
?
end
)
{
if
(
string
.
IsNullOrEmpty
(
platform
))
{
return
Content
(
"请选择完平台再导出"
);
}
var
obj
=
new
Services
.
DataWareHouse
.
PlatformOrderServices
().
Get
(
platform
,
website
,
start
,
end
);
if
(
obj
==
null
)
{
return
Content
(
"系统没有该平台的模版可导出,你可自定义一个模版,后面的导入都以本次导入的格式作为新模板。"
);
}
DataTable
dataTable
=
new
DataTable
();
//实例化
var
jsonData
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
Dictionary
<
string
,
string
>>(
obj
.
jsondata
);
var
colnames
=
new
List
<
string
>();
foreach
(
var
item
in
jsonData
)
{
dataTable
.
Columns
.
Add
(
item
.
Key
,
typeof
(
string
));
colnames
.
Add
(
item
.
Key
);
}
jsonData
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
Dictionary
<
string
,
string
>>(
obj
.
jsondata
);
DataRow
dataRow
=
dataTable
.
NewRow
();
foreach
(
var
c
in
jsonData
)
{
dataRow
[
c
.
Key
]
=
c
.
Value
;
}
dataTable
.
Rows
.
Add
(
dataRow
);
//for (var i = 0; i < dataTable.Columns.Count; i++)
//{
// colnames.Add(dataTable.Columns[i].ColumnName);
//}
var
listVal
=
new
List
<
string
>();
for
(
int
j
=
0
;
j
<
dataTable
.
Rows
.
Count
;
j
++)
{
var
s
=
""
;
for
(
int
k
=
0
;
k
<
dataTable
.
Columns
.
Count
;
k
++)
{
string
tmpRowValue
=
dataTable
.
Rows
[
j
][
k
].
ToString
();
s
+=
tmpRowValue
+
"|"
;
}
//s = s.Substring(0, s.Length - 1);
listVal
.
Add
(
s
);
}
var
guid
=
Guid
.
NewGuid
().
ToString
();
var
filename
=
platform
+
" "
+
((
start
.
HasValue
?
start
.
Value
.
ToString
(
"yyyy-MM-dd"
)
:
""
+
(
end
.
HasValue
?
"至"
+
end
.
Value
.
ToString
(
"yyyy-MM-dd"
)
:
""
)))
+
"的上传模版"
;
var
filepath
=
_hostingEnvironment
.
WebRootPath
+
"\\Files\\Report\\"
+
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd"
)
+
"\\"
;
//ToCSV(listVal, colnames, guid, filepath);
ToExcel
(
dataTable
,
guid
,
filepath
);
var
ms
=
new
System
.
IO
.
MemoryStream
();
using
(
var
f
=
new
System
.
IO
.
FileStream
(
filepath
+
guid
+
".xls"
,
System
.
IO
.
FileMode
.
Open
))
{
f
.
CopyTo
(
ms
);
}
ms
.
Position
=
0
;
return
File
(
ms
,
"text/xls"
,
filename
+
".xls"
);
}
/// <summary>
/// 上传销售平台流水
/// </summary>
/// <param name="platform">平台类型</param>
/// <param name="website">站点</param>
/// <returns></returns>
public
JsonResult
UploadOrderBilling
(
string
platform
,
string
website
)
{
if
(
Request
.
Form
.
Files
.
Count
==
0
)
{
return
Json
(
new
{
success
=
false
,
msg
=
"请上传文件!"
});
}
var
file
=
Request
.
Form
.
Files
[
0
];
Dictionary
<
string
,
DataTable
>
dic
=
Base
.
NpolHelper
.
ExcelToDataTable
(
file
.
OpenReadStream
(),
file
.
FileName
,
true
);
if
(
dic
.
Count
>
0
)
{
var
tb
=
dic
.
FirstOrDefault
();
var
list
=
Dtb2Json
(
tb
.
Value
);
var
listOrders
=
new
List
<
Models
.
DataWareHouse
.
flowing_sales
>();
foreach
(
var
item
in
list
)
{
//保存数据
var
m
=
new
Models
.
DataWareHouse
.
flowing_sales
{
accountname
=
""
,
createtime
=
DateTime
.
Now
,
jsondata
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
item
),
month
=
""
,
platform
=
platform
,
website
=
website
??
""
,
orderno
=
""
,
platformsku
=
""
,
};
listOrders
.
Add
(
m
);
}
var
result
=
new
Services
.
DataWareHouse
.
PlatformOrderServices
().
InsertOrderBilling
(
listOrders
);
return
Json
(
new
{
success
=
string
.
IsNullOrEmpty
(
result
),
msg
=
result
});
}
return
Json
(
new
{
success
=
false
,
msg
=
"无法识别表格的数据,请下载模版重新导入,或者检查下表格数据是否正确。"
,
});
}
private
System
.
Collections
.
ArrayList
Dtb2Json
(
DataTable
dtb
)
{
System
.
Collections
.
ArrayList
dic
=
new
System
.
Collections
.
ArrayList
();
foreach
(
DataRow
dr
in
dtb
.
Rows
)
{
System
.
Collections
.
Generic
.
Dictionary
<
string
,
object
>
drow
=
new
System
.
Collections
.
Generic
.
Dictionary
<
string
,
object
>();
foreach
(
DataColumn
dc
in
dtb
.
Columns
)
{
drow
.
Add
(
dc
.
ColumnName
,
dr
[
dc
.
ColumnName
]);
}
dic
.
Add
(
drow
);
}
return
dic
;
}
}
}
Bailun.DC.Web/Areas/DataWareHouse/Views/PlatformOrder/OrderBillings.cshtml
View file @
a4bbae70
This diff is collapsed.
Click to expand it.
Bailun.DC.Web/Base/BaseController.cs
View file @
a4bbae70
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
NPOI.HSSF.UserModel
;
using
NPOI.SS.UserModel
;
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.IO
;
using
System.Linq
;
using
System.Threading.Tasks
;
...
...
@@ -96,6 +99,63 @@ namespace Bailun.DC.Web.Base
writer
.
Dispose
();
}
public
void
ToExcel
(
DataTable
dt
,
string
filename
,
string
filePath
)
{
#
region
3
s
//创建全新的Workbook
var
workbook
=
new
HSSFWorkbook
();
//一個sheet最多65536行
var
count
=
0
;
for
(
double
i
=
0
;
i
<
Convert
.
ToDouble
(
dt
.
Rows
.
Count
)
/
Convert
.
ToDouble
(
65534
);
i
++)
//每个Excel文件的一个页签只能存放65536行数据
{
var
row_index
=
0
;
//创建Sheet
workbook
.
CreateSheet
(
"Sheet"
+
(
i
+
1
));
//根据Sheet名字获得Sheet对象
var
sheet
=
workbook
.
GetSheet
(
"Sheet"
+
(
i
+
1
));
IRow
row
;
row
=
sheet
.
CreateRow
(
row_index
);
//写入标题
for
(
int
j
=
0
;
j
<
dt
.
Columns
.
Count
;
j
++)
{
row
.
CreateCell
(
j
).
SetCellValue
(
dt
.
Columns
[
j
].
Caption
.
ToString
());
}
row
=
sheet
.
CreateRow
(++
row_index
);
//写入数据
for
(
int
j
=
0
;
j
<
(
dt
.
Rows
.
Count
-
count
>
65534
?
65534
:
dt
.
Rows
.
Count
-
count
);
j
++)
{
var
r
=
dt
.
Rows
[
j
+
count
];
for
(
int
k
=
0
;
k
<
dt
.
Columns
.
Count
;
k
++)
{
row
.
CreateCell
(
k
).
SetCellValue
(
r
[
k
].
ToString
());
//如果是数字,判断是否需要转换为数字
//if (IsNumeric(r[k].ToString()))
//{
// row.CreateCell(k).SetCellValue(Convert.ToDouble(r[k].ToString()));
//}
//else
//{
// row.CreateCell(k).SetCellValue(r[k].ToString());
//}
}
row
=
sheet
.
CreateRow
(++
row_index
);
}
count
+=
row_index
-
2
;
}
//保存Workbook方式一: 以文件形式保存到服务器中(每次导出都会生成一个文件,慎重使用)
//var FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
var
sw
=
System
.
IO
.
File
.
Create
(
filePath
+
filename
+
".xls"
);
workbook
.
Write
(
sw
);
sw
.
Close
();
#
endregion
}
#
endregion
}
...
...
Bailun.DC.Web/Base/NpolHelper.cs
View file @
a4bbae70
...
...
@@ -133,6 +133,8 @@ namespace Bailun.DC.Web.Base
row
=
sheet
.
GetRow
(
i
);
if
(
row
==
null
)
continue
;
if
(
row
.
FirstCellNum
==
-
1
)
continue
;
try
{
dataRow
=
dataTable
.
NewRow
();
...
...
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