Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
Laisi_AutoMES2
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
jiawei.su
Laisi_AutoMES2
Commits
bb18f836
Commit
bb18f836
authored
Jan 28, 2021
by
xin.yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
8cb629ed
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
373 additions
and
7 deletions
+373
-7
UploadController.cs
Server/Apis/Siger.ApiWMS/Controllers/UploadController.cs
+18
-7
RequestEnum.cs
Server/Common/Siger.Middlelayer.Share/Enum/RequestEnum.cs
+10
-0
EPPlusWmsExcelHelper.cs
...Siger.Middlelayer.Utility/Helpers/EPPlusWmsExcelHelper.cs
+125
-0
ImportStorageLocation.cs
...ddlelayer.Utility/ImportEntities/ImportStorageLocation.cs
+20
-0
Isiger_wms_storage_locationRepository.cs
...tories/Interface/Isiger_wms_storage_locationRepository.cs
+3
-0
siger_wms_storage_locationRepository.cs
...tory/Repositories/siger_wms_storage_locationRepository.cs
+197
-0
No files found.
Server/Apis/Siger.ApiWMS/Controllers/UploadController.cs
View file @
bb18f836
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
Microsoft.AspNetCore.Http
;
...
...
@@ -13,6 +14,7 @@ using Siger.Middlelayer.Log;
using
Siger.Middlelayer.Repository.Repositories.Interface
;
using
Siger.Middlelayer.Utility.Helpers
;
using
Siger.Middlelayer.Utility.ImportEntities
;
using
Siger.Middlelayer.WmsRepository.Entities
;
using
Siger.Middlelayer.WmsRepository.Repositories.Interface
;
namespace
Siger.ApiWMS.Controllers
...
...
@@ -107,17 +109,18 @@ namespace Siger.ApiWMS.Controllers
private
CommonImportResult
ImportStorageLocation
(
string
temporaryFilePath
)
{
E
pPlu
sExcelHelper
<
ImportStorageLocation
>
excelHelper
=
null
;
E
PPlusWm
sExcelHelper
<
ImportStorageLocation
>
excelHelper
=
null
;
try
{
excelHelper
=
new
E
pPlu
sExcelHelper
<
ImportStorageLocation
>(
temporaryFilePath
);
var
messages
=
excelHelper
.
CheckExcel
();
if
(
messag
es
.
Any
())
excelHelper
=
new
E
PPlusWm
sExcelHelper
<
ImportStorageLocation
>(
temporaryFilePath
);
var
locationTypes
=
_location_TypeRepository
.
GetList
(
q
=>
q
.
projectid
==
ProjectId
&&
q
.
status
==
(
int
)
RowState
.
Valid
).
ToList
();
if
(
!
locationTyp
es
.
Any
())
{
return
new
CommonImportResult
(
0
,
string
.
Join
(
';'
,
messages
)
);
throw
new
BadRequestException
(
RequestEnum
.
LocationTypeNotFound
);
}
var
data
=
excelHelper
.
ConvertSheetToList
();
var
result
=
_locationRepository
.
ImportStorageLocation
(
data
,
ProjectId
,
UserId
);
var
sonLocationTypes
=
GetSonTypes
(
0
,
locationTypes
).
Select
(
q
=>
new
Tuple
<
int
,
string
>(
q
.
id
,
q
.
name
)).
ToList
();
var
data
=
excelHelper
.
ConvertSheetToList
(
sonLocationTypes
);
var
result
=
_locationRepository
.
ImportStorageLocations
(
data
,
ProjectId
,
UserId
);
return
result
;
}
catch
(
Exception
e
)
...
...
@@ -131,5 +134,12 @@ namespace Siger.ApiWMS.Controllers
}
}
private
IEnumerable
<
siger_wms_storage_location_type
>
GetSonTypes
(
int
id
,
List
<
siger_wms_storage_location_type
>
types
)
{
var
query
=
from
c
in
types
where
c
.
parentid
==
id
select
c
;
return
query
.
ToList
().
Concat
(
query
.
ToList
().
SelectMany
(
t
=>
GetSonTypes
(
t
.
id
,
types
)));
}
}
}
\ No newline at end of file
Server/Common/Siger.Middlelayer.Share/Enum/RequestEnum.cs
View file @
bb18f836
...
...
@@ -1522,5 +1522,15 @@ namespace Siger.Middlelayer.Common
[
Description
(
"状态填写可用或停用"
)]
StatusInputUsefulOrDisabled
,
[
Description
(
"请填写大于0的整数ID"
)]
PleaseInputNotZeroIntID
,
[
Description
(
"请填写仓库名称"
)]
PleaseInputStorageName
,
[
Description
(
"请填写仓库名称后面的储位层级"
)]
PleaseInputLocation
,
}
}
Server/Common/Siger.Middlelayer.Utility/Helpers/EPPlusWmsExcelHelper.cs
0 → 100644
View file @
bb18f836
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text.RegularExpressions
;
using
OfficeOpenXml
;
using
OfficeOpenXml.Style
;
using
Siger.Middlelayer.Utility.ExcelImport
;
using
Siger.Middlelayer.Utility.ImportEntities
;
using
ExcelColumn
=
Siger
.
Middlelayer
.
Utility
.
ExcelImport
.
ExcelColumn
;
namespace
Siger.Middlelayer.Utility.Helpers
{
public
class
EPPlusWmsExcelHelper
<
T
>
:
IDisposable
where
T
:
ImportBase
,
new
()
{
private
ExcelWorksheet
Sheet
{
get
;
}
private
readonly
int
_language
=
0
;
public
EPPlusWmsExcelHelper
(
int
language
=
0
)
{
_language
=
language
;
}
public
EPPlusWmsExcelHelper
(
string
filePath
,
int
language
=
0
)
{
_language
=
language
;
if
(
File
.
Exists
(
filePath
))
{
var
file
=
new
FileInfo
(
filePath
);
var
excelPackage
=
new
ExcelPackage
(
file
);
if
(
excelPackage
.
Workbook
!=
null
&&
excelPackage
.
Workbook
.
Worksheets
.
Count
>
0
)
{
Sheet
=
excelPackage
.
Workbook
.
Worksheets
.
First
();
}
else
{
throw
new
Exception
(
"read excel failed."
);
}
}
}
/// <summary>
/// convert excel sheet1 to list
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public
IEnumerable
<
ImportStorageLocations
>
ConvertSheetToList
(
List
<
Tuple
<
int
,
string
>>
locationTypes
)
{
if
(
Sheet
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
Sheet
));
}
var
columns
=
new
List
<
string
>
{
"ID"
,
"仓库名称"
};
foreach
(
var
item
in
locationTypes
)
{
columns
.
Add
(
item
.
Item2
);
}
var
endRow
=
2
;
for
(
var
row
=
2
;
row
<=
Sheet
.
Dimension
.
Rows
;
row
++)
{
var
columnValues
=
new
List
<
string
>();
for
(
var
i
=
1
;
i
<=
columns
.
Count
;
i
++)
{
var
val
=
Sheet
.
Cells
[
row
,
i
];
if
(
val
!=
null
)
{
columnValues
.
Add
(
val
.
Text
);
}
}
if
(
columnValues
.
All
(
string
.
IsNullOrWhiteSpace
))
{
endRow
=
row
-
1
;
break
;
}
endRow
=
row
;
}
IList
<
int
>
rows
=
new
List
<
int
>();
for
(
var
i
=
2
;
i
<=
endRow
;
i
++)
{
rows
.
Add
(
i
);
}
var
collection
=
new
List
<
ImportStorageLocations
>();
foreach
(
var
row
in
rows
)
{
var
tnew
=
new
ImportStorageLocations
();
int
i
=
1
;
foreach
(
var
col
in
columns
)
{
var
val
=
Sheet
.
Cells
[
row
,
i
].
Value
.
ToString
();
if
(
i
==
1
)
{
tnew
.
ID
=
val
;
}
if
(
i
==
2
)
{
tnew
.
StorageName
=
val
;
}
if
(
i
>
2
)
{
var
typeId
=
locationTypes
.
FirstOrDefault
(
q
=>
q
.
Item2
==
col
);
tnew
.
Locations
.
Add
(
new
LocationModels
{
LocationType
=
typeId
==
null
?
0
:
typeId
.
Item1
,
Location
=
val
});
}
i
++;
}
collection
.
Add
(
tnew
);
}
return
collection
;
}
public
void
Dispose
()
{
Sheet
?.
Dispose
();
}
}
}
Server/Common/Siger.Middlelayer.Utility/ImportEntities/ImportStorageLocation.cs
View file @
bb18f836
...
...
@@ -16,4 +16,24 @@ namespace Siger.Middlelayer.Utility.ImportEntities
[
ExcelColumn
(
"上级库位"
)]
public
string
ParentLocation
{
get
;
set
;
}
}
public
class
ImportStorageLocations
{
[
ExcelColumn
(
"ID"
)]
public
string
ID
{
get
;
set
;
}
[
ExcelColumn
(
"仓库名称"
)]
public
string
StorageName
{
get
;
set
;
}
public
int
StorageId
{
get
;
set
;
}
public
List
<
LocationModels
>
Locations
{
get
;
set
;
}
=
new
List
<
LocationModels
>();
}
public
class
LocationModels
{
public
int
LocationType
{
get
;
set
;
}
public
string
Location
{
get
;
set
;
}
}
}
Server/Infrastructure/Repositories/Siger.Middlelayer.WmsRepository/Repositories/Interface/Isiger_wms_storage_locationRepository.cs
View file @
bb18f836
...
...
@@ -11,5 +11,8 @@ namespace Siger.Middlelayer.WmsRepository.Repositories.Interface
string
GenNo
(
int
locationid
);
string
GenInventoryLevel
(
int
material_id
,
int
ProjectId
);
CommonImportResult
ImportStorageLocation
(
IEnumerable
<
ImportStorageLocation
>
types
,
int
projectId
,
int
mid
);
CommonImportResult
ImportStorageLocations
(
IEnumerable
<
ImportStorageLocations
>
locations
,
int
projectid
,
int
userid
);
}
}
Server/Infrastructure/Repositories/Siger.Middlelayer.WmsRepository/Repositories/siger_wms_storage_locationRepository.cs
View file @
bb18f836
...
...
@@ -4,12 +4,14 @@ using System.Linq;
using
System.Text
;
using
Microsoft.EntityFrameworkCore
;
using
Siger.Middlelayer.Common
;
using
Siger.Middlelayer.Common.Extensions
;
using
Siger.Middlelayer.Common.Helpers
;
using
Siger.Middlelayer.Common.ModuleEnum
;
using
Siger.Middlelayer.Utility.ExcelImport
;
using
Siger.Middlelayer.Utility.ImportEntities
;
using
Siger.Middlelayer.WmsRepository.Entities
;
using
Siger.Middlelayer.WmsRepository.Repositories.Interface
;
using
Siger.Middlelayer.WmsRepository.Request
;
namespace
Siger.Middlelayer.WmsRepository.Repositories
{
...
...
@@ -75,6 +77,201 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
return
str
;
}
private
bool
InsertData
(
ImportStorageLocations
locationEntity
,
int
projectid
,
int
userid
,
List
<
siger_wms_storage_location_type
>
sonLocationTypes
)
{
var
locationTypeId
=
sonLocationTypes
.
LastOrDefault
()?.
id
??
0
;
var
ids
=
new
List
<
int
>();
var
parentid
=
0
;
foreach
(
var
locationType
in
sonLocationTypes
)
{
var
Location
=
locationEntity
.
Locations
.
FirstOrDefault
(
q
=>
q
.
LocationType
==
locationType
.
id
);
if
(
Location
==
null
)
{
return
false
;
}
var
tmp
=
new
siger_wms_storage_location
{
storageid
=
locationEntity
.
StorageId
,
parentid
=
parentid
,
name
=
""
,
realname
=
Location
.
Location
,
typeid
=
Location
.
LocationType
,
serial_number
=
GenSerialNumber
(),
creator
=
userid
,
create_time
=
DateTime
.
Now
,
updator
=
userid
,
update_time
=
DateTime
.
Now
,
projectid
=
projectid
,
status
=
(
int
)
RowState
.
Valid
,
locationid
=
Location
.
LocationType
==
locationTypeId
?
locationEntity
.
ID
.
ToInt
()
:
0
};
parentid
=
InsertLocation
(
tmp
,
locationEntity
.
StorageName
,
projectid
);
if
(
parentid
>
0
)
{
ids
.
Add
(
parentid
);
continue
;
}
else
{
foreach
(
var
id
in
ids
)
{
var
entity
=
dbContext
.
siger_wms_storage_location
.
FirstOrDefault
(
q
=>
q
.
id
==
id
);
dbContext
.
siger_wms_storage_location
.
Remove
(
entity
);
}
return
false
;
}
}
return
true
;
}
private
int
InsertLocation
(
siger_wms_storage_location
tmp
,
string
waveHouseName
,
int
projectid
)
{
int
id
=
0
;
dbContext
.
siger_wms_storage_location
.
Add
(
tmp
);
if
(
dbContext
.
SaveChanges
()
<=
0
)
{
return
id
;
}
//更新编号、层级名称
var
sn
=
new
StringBuilder
();
sn
.
Append
(
tmp
.
id
);
var
parent
=
dbContext
.
siger_wms_storage_location
.
FirstOrDefault
(
f
=>
f
.
id
==
tmp
.
parentid
&&
tmp
.
parentid
!=
0
&&
f
.
projectid
==
projectid
&&
f
.
status
==
(
int
)
RowState
.
Valid
);
var
parentname
=
""
;
if
(
parent
!=
null
)
{
parentname
=
parent
.
name
;
}
while
(
parent
!=
null
)
{
sn
.
Insert
(
0
,
parent
.
id
+
"_"
);
parent
=
dbContext
.
siger_wms_storage_location
.
FirstOrDefault
(
f
=>
f
.
id
==
parent
.
parentid
&&
parent
.
parentid
!=
0
&&
f
.
projectid
==
projectid
&&
f
.
status
==
(
int
)
RowState
.
Valid
);
}
//仓库
sn
.
Insert
(
0
,
tmp
.
storageid
+
"_"
);
tmp
.
serial_number
=
sn
.
ToString
();
//上级为仓库
if
(
tmp
.
parentid
==
0
)
{
tmp
.
name
=
$"
{
waveHouseName
}
->
{
tmp
.
realname
}
"
;
}
else
{
tmp
.
name
=
$"
{
parentname
}
->
{
tmp
.
realname
}
"
;
}
dbContext
.
siger_wms_storage_location
.
Update
(
tmp
);
if
(
dbContext
.
SaveChanges
()
<=
0
)
{
return
id
;
}
return
tmp
.
id
;
}
private
IEnumerable
<
siger_wms_storage_location_type
>
GetSonTypes
(
int
id
,
List
<
siger_wms_storage_location_type
>
types
)
{
var
query
=
from
c
in
types
where
c
.
parentid
==
id
select
c
;
return
query
.
ToList
().
Concat
(
query
.
ToList
().
SelectMany
(
t
=>
GetSonTypes
(
t
.
id
,
types
)));
}
public
CommonImportResult
ImportStorageLocations
(
IEnumerable
<
ImportStorageLocations
>
locations
,
int
projectid
,
int
userid
)
{
var
locationTypes
=
dbContext
.
siger_wms_storage_location_type
.
Where
(
q
=>
q
.
projectid
==
projectid
&&
q
.
status
==
(
int
)
RowState
.
Valid
).
ToList
();
if
(!
locationTypes
.
Any
())
{
throw
new
BadRequestException
(
RequestEnum
.
LocationTypeNotFound
);
}
var
sonLocationTypes
=
GetSonTypes
(
0
,
locationTypes
).
ToList
();
var
lastLocationTypeId
=
sonLocationTypes
.
LastOrDefault
()?.
id
??
0
;
int
rowIndex
=
2
;
var
errors
=
new
List
<
string
>();
var
list
=
new
List
<
ImportStorageLocations
>();
foreach
(
var
loca
in
locations
)
{
if
(!
int
.
TryParse
(
loca
.
ID
,
out
int
id
))
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
PleaseInputNotZeroIntID
}
"
);
}
if
(
string
.
IsNullOrEmpty
(
loca
.
StorageName
))
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
PleaseInputStorageName
}
"
);
}
if
(
loca
.
Locations
.
Count
!=
sonLocationTypes
.
Count
)
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
LocationLevelError
}
"
);
return
new
CommonImportResult
(
0
,
string
.
Join
(
";"
,
errors
));
}
var
storage
=
dbContext
.
siger_wms_storage
.
FirstOrDefault
(
q
=>
q
.
name
==
loca
.
StorageName
&&
q
.
projectid
==
projectid
&&
q
.
status
==
(
int
)
RowState
.
Valid
);
if
(
storage
==
null
)
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
StorageError
}
"
);
}
else
{
loca
.
StorageId
=
storage
.
id
;
}
foreach
(
var
typeId
in
loca
.
Locations
)
{
if
(
typeId
.
LocationType
==
0
)
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
LocationLevelError
}
"
);
}
if
(
string
.
IsNullOrEmpty
(
typeId
.
Location
))
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
PleaseInputLocation
}
"
);
}
if
(
storage
!=
null
&&
typeId
.
LocationType
>
0
&&
loca
.
ID
.
ToInt
()
>
0
)
{
var
locationIdExist
=
dbContext
.
siger_wms_storage_location
.
FirstOrDefault
(
q
=>
q
.
projectid
==
projectid
&&
q
.
status
==
(
int
)
RowState
.
Valid
&&
q
.
typeid
==
lastLocationTypeId
&&
q
.
locationid
==
loca
.
ID
.
ToInt
()
&&
q
.
storageid
==
storage
.
id
);
if
(
locationIdExist
!=
null
||
locations
.
Count
(
q
=>
q
.
StorageName
==
loca
.
StorageName
&&
q
.
ID
==
loca
.
ID
)
>
1
)
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
IDExist
}
"
);
break
;
}
}
}
if
(
errors
.
Any
())
{
return
new
CommonImportResult
(
0
,
string
.
Join
(
";"
,
errors
));
}
list
.
Add
(
loca
);
rowIndex
++;
}
rowIndex
=
2
;
foreach
(
var
loca
in
list
)
{
try
{
if
(!
InsertData
(
loca
,
projectid
,
userid
,
locationTypes
))
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
ImportFailed
}
"
);
return
new
CommonImportResult
(
0
,
string
.
Join
(
";"
,
errors
));
}
}
catch
(
Exception
)
{
errors
.
Add
(
$"
{
rowIndex
}
,
{(
int
)
RequestEnum
.
ImportFailed
}
"
);
return
new
CommonImportResult
(
0
,
string
.
Join
(
";"
,
errors
));
}
rowIndex
++;
}
return
new
CommonImportResult
(
1
,
"1"
);
}
public
CommonImportResult
ImportStorageLocation
(
IEnumerable
<
ImportStorageLocation
>
locations
,
int
projectid
,
int
userid
)
{
var
errors
=
new
List
<
string
>();
...
...
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