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
addbbd1b
Commit
addbbd1b
authored
Sep 16, 2019
by
lizefeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增预测销量配置
parent
c166f51f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
476 additions
and
3 deletions
+476
-3
common.cs
AutoTurnOver.DB/common.cs
+5
-1
db_config.cs
AutoTurnOver.DB/db_config.cs
+105
-0
dc_config_forecast_sales.cs
AutoTurnOver.Models/dc_config_forecast_sales.cs
+31
-0
ConfigServices.cs
AutoTurnOver.Services/ConfigServices.cs
+106
-1
AutoTurnOver.Utility.csproj
AutoTurnOver.Utility/AutoTurnOver.Utility.csproj
+1
-0
EPPlusHelper.cs
AutoTurnOver.Utility/EPPlusHelper.cs
+117
-0
RequestResultDto.cs
AutoTurnOver/Common/RequestResultDto.cs
+20
-0
CommonController.cs
AutoTurnOver/Controllers/CommonController.cs
+10
-1
ConfigController.cs
AutoTurnOver/Controllers/ConfigController.cs
+81
-0
No files found.
AutoTurnOver.DB/common.cs
View file @
addbbd1b
...
...
@@ -41,7 +41,11 @@ namespace AutoTurnOver.DB
public
static
dc_base_warehouse
GetWareHouseByCode
(
string
code
)
{
var
sql
=
"select * from dc_base_warehouse where warehouse_code='"
+
code
+
"'"
;
var
sql
=
"select * from dc_base_warehouse where 1=1 "
;
if
(!
string
.
IsNullOrWhiteSpace
(
code
))
{
sql
+=
(
" and warehouse_code='"
+
code
+
"'"
);
}
return
_connection
.
QueryFirstOrDefault
<
dc_base_warehouse
>(
sql
);
}
...
...
AutoTurnOver.DB/db_config.cs
View file @
addbbd1b
...
...
@@ -981,6 +981,7 @@ left join dc_base_warehouse as dbw on dacp.warehouse_code = dbw.warehouse_code w
#
endregion
#
region
动态备货
sku
public
static
List
<
dc_auto_stock_up_range_dto
>
StockUpRangeList
(
Condition_ConfigPromotion
m
,
int
offset
,
int
limit
,
ref
int
total
)
...
...
@@ -1223,5 +1224,109 @@ where 1 = 1 ";
}
#
endregion
#
region
销量预测
人工配置
public
static
List
<
dc_config_forecast_sales
>
ForecastSalesConfigList
(
Condition_ConfigPromotion
m
,
int
offset
,
int
limit
,
ref
int
total
)
{
var
list
=
new
List
<
dc_config_forecast_sales
>();
try
{
var
sql
=
@"select t1.* from dc_config_forecast_sales as t1 where 1 = 1 "
;
if
(!
string
.
IsNullOrWhiteSpace
(
m
.
warehousetype
))
{
sql
+=
" and dbw.hq_type="
+
$"'
{
m
.
warehousetype
}
'"
;
}
if
(
m
.
warehousearea
>
0
)
{
sql
+=
" and dbw.area_id="
+
m
.
warehousearea
;
}
if
(!
string
.
IsNullOrWhiteSpace
(
m
.
bailun_sku
))
{
sql
+=
" and dacp.bailun_sku ="
+
$"'
{
m
.
bailun_sku
}
'"
;
}
if
(!
string
.
IsNullOrWhiteSpace
(
m
.
warehousecode
))
{
sql
+=
" and dacp.warehouse_code='"
+
m
.
warehousecode
+
"'"
;
}
total
=
_connection
.
ExecuteScalar
<
int
>(
"select count(0) from ("
+
sql
+
") tb1"
);
var
obj
=
_connection
.
Query
<
dc_config_forecast_sales
>(
sql
+
" limit "
+
offset
+
","
+
limit
);
return
obj
.
AsList
();
}
catch
(
Exception
)
{
return
list
;
}
}
/// <summary>
/// 保存销量配置
/// </summary>
/// <param name="m">销售设置model</param>
/// <param name="username">当前操作人名称</param>
/// <returns></returns>
public
static
string
SaveForecastSalesConfig
(
Models
.
dc_config_forecast_sales
m
,
string
username
)
{
var
obj
=
_connection
.
QueryFirstOrDefault
<
Models
.
dc_config_forecast_sales
>(
"select * from dc_config_forecast_sales where id="
+
m
.
id
);
if
(
obj
==
null
)
{
obj
=
new
dc_config_forecast_sales
{
};
}
obj
.
id
=
m
.
id
;
obj
.
bailun_sku
=
m
.
bailun_sku
;
obj
.
warehouse_code
=
m
.
warehouse_code
;
obj
.
start_date
=
m
.
start_date
;
obj
.
end_date
=
m
.
end_date
;
obj
.
warehouse_name
=
m
.
warehouse_name
;
obj
.
create_user
=
username
;
// 检查该数据是否有存在
var
oldData
=
_connection
.
QueryFirstOrDefault
(
@" select * from dc_config_forecast_sales
where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code and id!=@id
and start_date<=@end_date and end_date>=@start_date
"
,
new
{
m
.
bailun_sku
,
m
.
warehouse_code
,
m
.
id
,
end_date
=
m
.
end_date
,
start_date
=
m
.
start_date
});
if
(
oldData
!=
null
)
{
return
$" sku:【
{
m
.
bailun_sku
}
】,仓库:【
{
m
.
warehouse_name
}
】 已经配置过了 "
;
}
try
{
if
(
obj
.
id
>
0
)
{
var
result
=
_connection
.
Update
<
Models
.
dc_config_forecast_sales
>(
obj
);
return
result
>
0
?
""
:
"保存异常,请重试!"
;
}
else
{
var
result
=
_connection
.
Insert
<
Models
.
dc_config_forecast_sales
>(
obj
);
return
result
.
HasValue
&&
result
.
Value
>
0
?
""
:
"提交异常,请重试!"
;
}
}
catch
(
Exception
ex
)
{
return
ex
.
Message
;
}
}
public
static
dc_config_forecast_sales
GetForecastSalesConfigById
(
int
id
)
{
return
_connection
.
QueryFirstOrDefault
<
dc_config_forecast_sales
>(
"select * from dc_config_forecast_sales where id="
+
id
);
}
#
endregion
}
}
AutoTurnOver.Models/dc_config_forecast_sales.cs
0 → 100644
View file @
addbbd1b
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
AutoTurnOver.Models
{
/// <summary>
/// 销量预测 ( 人工配置 )
/// </summary>
public
class
dc_config_forecast_sales
{
public
int
id
{
get
;
set
;
}
/// <summary>
/// 销量
/// </summary>
public
decimal
sales
{
get
;
set
;
}
public
DateTime
start_date
{
get
;
set
;
}
public
DateTime
end_date
{
get
;
set
;
}
public
string
create_user
{
get
;
set
;
}
public
string
bailun_sku
{
get
;
set
;
}
public
string
warehouse_code
{
get
;
set
;
}
public
string
warehouse_name
{
get
;
set
;
}
}
}
AutoTurnOver.Services/ConfigServices.cs
View file @
addbbd1b
using
AutoTurnOver.Models
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Data
;
using
System.IO
;
using
AutoTurnOver.Utility
;
using
System.Linq
;
namespace
AutoTurnOver.Services
{
...
...
@@ -601,5 +604,107 @@ namespace AutoTurnOver.Services
}
#
endregion
#
region
预测销量
人工
public
List
<
dc_config_forecast_sales
>
ForecastSalesConfigList
(
Condition_ConfigPromotion
m
,
int
offset
,
int
limit
,
ref
int
total
)
{
return
DB
.
db_config
.
ForecastSalesConfigList
(
m
,
offset
,
limit
,
ref
total
);
}
public
string
SaveForecastSalesConfig
(
Models
.
dc_config_forecast_sales
m
,
string
username
)
{
if
(
string
.
IsNullOrWhiteSpace
(
m
.
warehouse_code
))
{
return
"请选择仓库!"
;
}
var
objWarehouse
=
DB
.
common
.
GetWareHouseByCode
(
m
.
warehouse_code
);
if
(
objWarehouse
==
null
)
{
return
"系统找不到该仓库。"
;
}
m
.
warehouse_name
=
objWarehouse
.
warehouse_name
;
return
DB
.
db_config
.
SaveForecastSalesConfig
(
m
,
username
);
}
public
dc_config_forecast_sales
GetForecastSalesConfigById
(
int
id
)
{
return
DB
.
db_config
.
GetForecastSalesConfigById
(
id
);
}
public
DataTable
ForecastSalesConfigImport
(
Stream
fileInfo
,
UserData
user
)
{
var
data_set
=
EPPlusHelper
.
ReadExcel
(
fileInfo
);
var
table
=
data_set
.
Tables
[
0
];
if
(!
table
.
Columns
.
Contains
(
"导入结果"
))
table
.
Columns
.
Add
(
"导入结果"
);
if
(!
table
.
Columns
.
Contains
(
"导入异常"
))
table
.
Columns
.
Add
(
"导入异常"
);
var
warehouse_list
=
DB
.
common
.
ListWareHouse
(
null
,
null
);
DateTime
now
=
DateTime
.
Now
;
int
index
=
1
;
foreach
(
DataRow
row
in
table
.
Rows
)
{
index
++;
try
{
var
bailun_sku
=
row
[
"SKU"
].
ToString
();
var
warehouse_code
=
row
[
"仓库编码"
].
ToString
();
var
start_date_str
=
row
[
"开始时间"
].
ToString
();
var
end_date_str
=
row
[
"结束时间"
].
ToString
();
var
sales_str
=
row
[
"预测销量"
].
ToString
();
if
(
string
.
IsNullOrWhiteSpace
(
bailun_sku
))
throw
new
Exception
(
"SKU必填"
);
if
(
string
.
IsNullOrWhiteSpace
(
warehouse_code
))
throw
new
Exception
(
"warehouse_code必填"
);
var
warehouse_data
=
warehouse_list
.
SingleOrDefault
(
s
=>
s
.
warehouse_code
.
Equals
(
warehouse_code
,
StringComparison
.
OrdinalIgnoreCase
));
if
(
warehouse_data
==
null
)
{
throw
new
Exception
(
"仓库在系统中找不到"
);
}
var
warehouse_name
=
warehouse_data
.
warehouse_name
;
decimal
sales
=
0
;
if
(!
decimal
.
TryParse
(
sales_str
,
out
sales
))
{
throw
new
Exception
(
"销量格式异常"
);
}
DateTime
start_date
=
DateTime
.
Now
;
if
(!
DateTime
.
TryParse
(
start_date_str
,
out
start_date
))
{
throw
new
Exception
(
"开始时间格式异常"
);
}
DateTime
end_date
=
DateTime
.
Now
;
if
(!
DateTime
.
TryParse
(
end_date_str
,
out
end_date
))
{
throw
new
Exception
(
"结束时间格式异常"
);
}
var
new_data
=
new
dc_config_forecast_sales
{
bailun_sku
=
bailun_sku
,
warehouse_name
=
warehouse_name
,
warehouse_code
=
warehouse_code
,
create_user
=
user
.
UserName
,
sales
=
sales
,
start_date
=
start_date
,
end_date
=
end_date
};
DB
.
db_config
.
SaveForecastSalesConfig
(
new_data
,
user
.
UserName
);
row
[
"导入结果"
]
=
"成功"
;
row
[
"导入异常"
]
=
""
;
}
catch
(
Exception
ex
)
{
row
[
"导入结果"
]
=
"失败"
;
row
[
"导入异常"
]
=
ex
.
Message
;
}
}
return
table
;
}
#
endregion
}
}
AutoTurnOver.Utility/AutoTurnOver.Utility.csproj
View file @
addbbd1b
...
...
@@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="Bailun.ServiceFabric.Redis" Version="1.0.1" />
<PackageReference Include="EPPlus.Core" Version="1.5.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
...
...
AutoTurnOver.Utility/EPPlusHelper.cs
0 → 100644
View file @
addbbd1b
using
OfficeOpenXml
;
using
OfficeOpenXml.Style
;
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Drawing
;
using
System.IO
;
using
System.Text
;
namespace
AutoTurnOver.Utility
{
public
class
EPPlusHelper
{
/// <summary>
/// 导入数据到Excel中
/// </summary>
/// <param name="fileName"></param>
/// <param name="ds"></param>
public
static
bool
ImportExcel
(
Stream
file
,
DataSet
ds
)
{
if
(
ds
==
null
||
ds
.
Tables
.
Count
==
0
)
{
return
false
;
}
//在using语句里面我们可以创建多个worksheet,ExcelPackage后面可以传入路径参数
//命名空间是using OfficeOpenXml
using
(
ExcelPackage
package
=
new
ExcelPackage
(
file
))
{
foreach
(
DataTable
dt
in
ds
.
Tables
)
{
//创建工作表worksheet
ExcelWorksheet
worksheet
=
package
.
Workbook
.
Worksheets
.
Add
(
dt
.
TableName
);
//给单元格赋值有两种方式
//worksheet.Cells[1, 1].Value = "单元格的值";直接指定行列数进行赋值
//worksheet.Cells["A1"].Value = "单元格的值";直接指定单元格进行赋值
worksheet
.
Cells
.
Style
.
Font
.
Name
=
"微软雅黑"
;
worksheet
.
Cells
.
Style
.
Font
.
Size
=
12
;
worksheet
.
Cells
.
Style
.
ShrinkToFit
=
true
;
//单元格自动适应大小
for
(
int
i
=
0
;
i
<
dt
.
Rows
.
Count
;
i
++)
{
for
(
int
j
=
0
;
j
<
dt
.
Columns
.
Count
;
j
++)
{
worksheet
.
Cells
[
i
+
1
,
j
+
1
].
Value
=
dt
.
Rows
[
i
][
j
].
ToString
();
}
}
using
(
var
cell
=
worksheet
.
Cells
[
1
,
1
,
1
,
dt
.
Columns
.
Count
])
{
//设置样式:首行居中加粗背景色
cell
.
Style
.
Font
.
Bold
=
true
;
//加粗
cell
.
Style
.
HorizontalAlignment
=
ExcelHorizontalAlignment
.
Center
;
//水平居中
cell
.
Style
.
VerticalAlignment
=
ExcelVerticalAlignment
.
Center
;
//垂直居中
cell
.
Style
.
Font
.
Size
=
14
;
cell
.
Style
.
Fill
.
PatternType
=
ExcelFillStyle
.
Solid
;
//背景颜色
cell
.
Style
.
Fill
.
BackgroundColor
.
SetColor
(
Color
.
FromArgb
(
128
,
128
,
128
));
//设置单元格背景色
}
}
//保存
package
.
Save
();
}
return
true
;
}
/// <summary>
/// 读取Excel数据
/// </summary>
/// <param name="fileName"></param>
public
static
DataSet
ReadExcel
(
Stream
file
)
{
DataSet
data_set
=
new
DataSet
();
try
{
using
(
ExcelPackage
package
=
new
ExcelPackage
(
file
))
{
var
count
=
package
.
Workbook
.
Worksheets
.
Count
;
for
(
int
k
=
1
;
k
<=
count
;
k
++)
//worksheet是从1开始的
{
DataTable
table
=
new
DataTable
();
var
workSheet
=
package
.
Workbook
.
Worksheets
[
k
];
table
.
TableName
=
workSheet
.
Name
;
if
(
workSheet
.
Dimension
==
null
)
continue
;
int
row
=
workSheet
.
Dimension
.
Rows
;
int
col
=
workSheet
.
Dimension
.
Columns
;
for
(
int
j
=
1
;
j
<=
col
;
j
++)
{
table
.
Columns
.
Add
(
workSheet
.
Cells
[
1
,
j
].
Value
.
ToString
());
}
for
(
int
i
=
2
;
i
<=
row
;
i
++)
{
DataRow
data_row
=
table
.
NewRow
();
for
(
int
j
=
1
;
j
<=
col
;
j
++)
{
try
{
data_row
[
workSheet
.
Cells
[
1
,
j
].
Value
.
ToString
()]
=
workSheet
.
Cells
[
i
,
j
].
Value
==
null
?
""
:
workSheet
.
Cells
[
i
,
j
].
Value
.
ToString
();
}
catch
(
Exception
ex
)
{
throw
;
}
}
table
.
Rows
.
Add
(
data_row
);
}
data_set
.
Tables
.
Add
(
table
);
}
}
}
catch
(
Exception
ex
)
{
throw
;
}
return
data_set
;
}
}
}
AutoTurnOver/Common/RequestResultDto.cs
0 → 100644
View file @
addbbd1b
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
AutoTurnOver.Common
{
public
class
RequestResultDto
{
public
bool
success
{
get
;
set
;
}
public
dynamic
data
{
get
;
set
;
}
public
dynamic
data1
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
err_data
{
get
;
set
;
}
}
}
AutoTurnOver/Controllers/CommonController.cs
View file @
addbbd1b
...
...
@@ -6,9 +6,10 @@ using Microsoft.AspNetCore.Http;
using
Microsoft.AspNetCore.Mvc
;
using
AutoTurnOver.Services
;
using
Microsoft.AspNetCore.Cors
;
using
System.
Net
;
using
System.
IO
;
using
AutoTurnOver.Common
;
using
AutoTurnOver.DB
;
using
AutoTurnOver.Utility
;
namespace
AutoTurnOver.Controllers
{
...
...
@@ -16,6 +17,14 @@ namespace AutoTurnOver.Controllers
[
ApiController
]
public
class
CommonController
:
BaseController
{
[
HttpPost
]
public
async
Task
<
ActionResult
<
RequestResultDto
>>
FlieUpload
(
IFormFile
file
)
{
var
fileName
=
Guid
.
NewGuid
().
ToString
()
+
Path
.
GetExtension
(
file
.
FileName
);
var
fileData
=
await
QiNiuCloudHelper
.
UploadAsync
(
file
.
OpenReadStream
(),
fileName
);
return
new
RequestResultDto
{
success
=
true
,
data
=
fileData
,
data1
=
fileName
};
}
/// <summary>
/// 获取仓库列表
/// </summary>
...
...
AutoTurnOver/Controllers/ConfigController.cs
View file @
addbbd1b
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
AutoTurnOver.Common
;
using
AutoTurnOver.Models
;
using
AutoTurnOver.Utility
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
...
...
@@ -572,5 +574,83 @@ namespace AutoTurnOver.Controllers
}
#
endregion
#
region
预测销量
人工
[
HttpGet
]
public
JsonResult
ForecastSalesConfigList
(
int
limit
,
int
offset
,
string
order
,
string
sort
,
string
bailun_sku
)
{
var
m
=
new
Condition_ConfigPromotion
{
bailun_sku
=
bailun_sku
};
var
total
=
0
;
var
service
=
new
Services
.
ConfigServices
();
var
list
=
service
.
ForecastSalesConfigList
(
m
,
offset
,
limit
,
ref
total
);
return
new
JsonResult
(
new
{
rows
=
list
,
total
=
total
,
});
}
[
HttpPost
]
public
JsonResult
SaveForecastSalesConfig
([
FromBody
]
dc_config_forecast_sales
m
)
{
try
{
var
result
=
new
Services
.
ConfigServices
().
SaveForecastSalesConfig
(
m
,
AutoUtility
.
GetUser
().
UserName
);
return
new
JsonResult
(
result
);
}
catch
(
Exception
ex
)
{
return
new
JsonResult
(
ex
.
Message
);
}
}
[
HttpGet
]
public
JsonResult
GetForecastSalesConfigById
(
int
id
)
{
var
m
=
new
Services
.
ConfigServices
().
GetForecastSalesConfigById
(
id
);
return
new
JsonResult
(
m
);
}
/// <summary>
/// 导入
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
[
HttpPost
]
public
async
Task
<
ActionResult
<
RequestResultDto
>>
ForecastSalesImport
(
IFormFile
file
)
{
try
{
var
user
=
AutoUtility
.
GetUser
();
var
dataTable
=
new
Services
.
ConfigServices
().
ForecastSalesConfigImport
(
file
.
OpenReadStream
(),
user
);
var
fileName
=
AppContext
.
BaseDirectory
+
$@"Result\预测销量(手动)导入结果.csv"
;
CsvFileHelper
.
SaveCSV
(
dataTable
,
fileName
);
var
memory
=
new
MemoryStream
();
using
(
var
stream
=
new
FileStream
(
fileName
,
FileMode
.
Open
))
{
stream
.
CopyTo
(
memory
);
}
memory
.
Position
=
0
;
var
fileData
=
await
QiNiuCloudHelper
.
UploadAsync
(
memory
,
$"
{
user
.
UserName
}
-
{
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmss"
)}
预测销量(手动)导入结果.csv"
);
return
new
RequestResultDto
{
success
=
true
,
data
=
fileData
};
}
catch
(
Exception
ex
)
{
return
new
RequestResultDto
{
success
=
false
,
message
=
ex
.
Message
,
err_data
=
ex
.
StackTrace
};
}
}
#
endregion
}
}
\ No newline at end of file
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