Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
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
Administrator
browser-backend
Commits
54547f8c
Commit
54547f8c
authored
Mar 16, 2020
by
renjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
批量添加
parent
db14ea11
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
15 deletions
+71
-15
ShopServiceImpl.java
.../browserbackend/browser/service/Impl/ShopServiceImpl.java
+55
-7
FileUtil.java
.../java/com/edgec/browserbackend/common/utils/FileUtil.java
+16
-8
batchAdd.xlsx
src/main/resources/batchAdd.xlsx
+0
-0
~$batchAdd.xlsx
src/main/resources/~$batchAdd.xlsx
+0
-0
No files found.
src/main/java/com/edgec/browserbackend/browser/service/Impl/ShopServiceImpl.java
View file @
54547f8c
...
...
@@ -6,10 +6,7 @@ import com.edgec.browserbackend.account.exception.AccountErrorCode;
import
com.edgec.browserbackend.account.repository.AccountRepository
;
import
com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode
;
import
com.edgec.browserbackend.browser.domain.*
;
import
com.edgec.browserbackend.browser.dto.ShopFilterDto
;
import
com.edgec.browserbackend.browser.dto.ShopResultDto
;
import
com.edgec.browserbackend.browser.dto.PageInfo
;
import
com.edgec.browserbackend.browser.dto.ShopPageResultDto
;
import
com.edgec.browserbackend.browser.dto.*
;
import
com.edgec.browserbackend.browser.repository.GroupRepository
;
import
com.edgec.browserbackend.browser.repository.IpResourceRepository
;
import
com.edgec.browserbackend.browser.repository.ShopRepository
;
...
...
@@ -101,9 +98,60 @@ public class ShopServiceImpl implements ShopService {
@Override
public
List
<
String
>
addShops
(
String
username
,
MultipartFile
file
)
throws
IOException
{
List
<
Object
>
list
=
FileUtil
.
readExcel
(
file
.
getInputStream
());
logger
.
error
(
list
.
toString
());
return
null
;
List
<
String
>
ids
=
new
ArrayList
<>();
List
<
List
<
Object
>>
list
=
FileUtil
.
readExcel
(
file
.
getInputStream
());
Account
account
=
accountRepository
.
findByName
(
username
);
if
(
account
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
}
if
(
account
.
getPermission
()
<
4
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
}
if
(
account
.
getShopCount
()
>=
10000
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
SHOPMAX
);
}
for
(
List
<
Object
>
l
:
list
)
{
ShopResultDto
shopResultDto
=
new
ShopResultDto
();
shopResultDto
.
setOwner
(
username
);
shopResultDto
.
setShopName
(
l
.
get
(
0
).
toString
());
shopResultDto
.
setShopPlatform
(
l
.
get
(
1
).
toString
());
shopResultDto
.
setGroup
(
"-1"
);
if
(
StringUtils
.
isNotBlank
(
l
.
get
(
2
).
toString
()))
shopResultDto
.
setShopAccount
(
l
.
get
(
2
).
toString
());
if
(
StringUtils
.
isNotBlank
(
l
.
get
(
3
).
toString
()))
shopResultDto
.
setShopPassword
(
l
.
get
(
3
).
toString
());
String
id
=
null
;
UserShop
us
=
null
;
if
(
shopResultDto
.
getShopId
()
!=
null
)
us
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shopResultDto
.
getShopId
());
if
(
shopResultDto
.
getGroup
()
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
Group
group
=
groupRepository
.
findById
(
shopResultDto
.
getGroup
()).
orElse
(
null
);
if
(
group
==
null
)
{
throw
new
ClientRequestException
(
BrowserErrorCode
.
GROUPNOTEXIST
);
}
try
{
shopResultDto
.
setOwner
(
username
);
Shop
shop
=
new
Shop
();
shop
.
of
(
shopResultDto
);
id
=
shopRepository
.
save
(
shop
).
getShopId
();
UserShop
userShop
=
new
UserShop
();
userShop
.
setUsername
(
username
);
userShop
.
setShopId
(
id
);
if
(
shopResultDto
.
getGroup
()
!=
null
&&
us
==
null
)
{
userShop
.
setGroupId
(
shopResultDto
.
getGroup
());
}
userShopRepository
.
save
(
userShop
);
//可以优化
account
.
setShopCount
(
account
.
getShopCount
()
+
1
);
accountRepository
.
save
(
account
);
ids
.
add
(
id
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to add shops"
,
e
.
getMessage
());
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
}
}
return
ids
;
}
@Override
...
...
src/main/java/com/edgec/browserbackend/common/utils/FileUtil.java
View file @
54547f8c
...
...
@@ -69,8 +69,8 @@ public class FileUtil {
}
//读取excel
public
static
List
<
Object
>
readExcel
(
InputStream
inputStream
){
List
<
Object
>
list
=
new
ArrayList
<>();
public
static
List
<
List
<
Object
>
>
readExcel
(
InputStream
inputStream
){
List
<
List
<
Object
>
>
list
=
new
ArrayList
<>();
Workbook
workbook
=
null
;
try
{
workbook
=
WorkbookFactory
.
create
(
inputStream
);
...
...
@@ -86,19 +86,27 @@ public class FileUtil {
int
colLength
=
row
.
getLastCellNum
();
//得到指定的单元格
Cell
cell
=
row
.
getCell
(
0
);;
int
size
=
1
;
for
(
int
i
=
2
;
i
<
rowLength
;
i
++)
{
row
=
sheet
.
getRow
(
i
);
List
<
Object
>
rowvalue
=
new
ArrayList
<>();
size
=
0
;
for
(
int
j
=
0
;
j
<
colLength
;
j
++)
{
cell
=
row
.
getCell
(
j
);
// System.out.println(cell);
if
(
cell
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
if
(
cell
!=
null
)
{
if
(
cell
!=
null
)
{
Object
cellValue
=
getCellFormatValue
(
cell
);
if
(
StringUtils
.
isNotBlank
(
cellValue
.
toString
()))
log
.
error
(
cellValue
.
toString
());
rowvalue
.
add
(
cellValue
);
if
(
StringUtils
.
isNotBlank
(
cellValue
.
toString
()))
{
size
++;
}
}
}
if
(
size
==
0
)
break
;
if
(
StringUtils
.
isBlank
(
rowvalue
.
get
(
0
).
toString
())
||
StringUtils
.
isBlank
(
rowvalue
.
get
(
1
).
toString
()))
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
list
.
add
(
rowvalue
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"parse excel file error :"
,
e
);
...
...
@@ -113,7 +121,7 @@ public class FileUtil {
//判断cell类型
switch
(
cell
.
getCellType
()){
case
Cell
.
CELL_TYPE_NUMERIC
:{
cellValue
=
String
.
valueOf
(
cell
.
getNumericCellValue
());
cellValue
=
String
.
valueOf
(
(
int
)
cell
.
getNumericCellValue
());
break
;
}
case
Cell
.
CELL_TYPE_FORMULA
:{
...
...
src/main/resources/batchAdd.xlsx
View file @
54547f8c
No preview for this file type
src/main/resources/~$batchAdd.xlsx
0 → 100644
View file @
54547f8c
File added
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