Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
618a8b98
Commit
618a8b98
authored
Dec 31, 2018
by
Junling Bu
Browse files
chore[litemall-admin-api]: 简化代码
parent
78a062e2
Changes
26
Hide whitespace changes
Inline
Side-by-side
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminRegionController.java
View file @
618a8b98
...
@@ -31,12 +31,7 @@ public class AdminRegionController {
...
@@ -31,12 +31,7 @@ public class AdminRegionController {
@GetMapping
(
"/clist"
)
@GetMapping
(
"/clist"
)
public
Object
clist
(
@LoginAdmin
Integer
adminId
,
@NotNull
Integer
id
)
{
public
Object
clist
(
@LoginAdmin
Integer
adminId
,
@NotNull
Integer
id
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
LitemallRegion
>
regionList
=
regionService
.
queryByPid
(
id
);
List
<
LitemallRegion
>
regionList
=
regionService
.
queryByPid
(
id
);
return
ResponseUtil
.
ok
(
regionList
);
return
ResponseUtil
.
ok
(
regionList
);
}
}
...
@@ -47,10 +42,6 @@ public class AdminRegionController {
...
@@ -47,10 +42,6 @@ public class AdminRegionController {
@RequestParam
(
defaultValue
=
"10"
)
Integer
limit
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
limit
,
@Sort
(
accepts
=
{
"id"
})
@RequestParam
(
defaultValue
=
"id"
)
String
sort
,
@Sort
(
accepts
=
{
"id"
})
@RequestParam
(
defaultValue
=
"id"
)
String
sort
,
@Order
@RequestParam
(
defaultValue
=
"desc"
)
String
order
)
{
@Order
@RequestParam
(
defaultValue
=
"desc"
)
String
order
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
LitemallRegion
>
regionList
=
regionService
.
querySelective
(
name
,
code
,
page
,
limit
,
sort
,
order
);
List
<
LitemallRegion
>
regionList
=
regionService
.
querySelective
(
name
,
code
,
page
,
limit
,
sort
,
order
);
int
total
=
regionService
.
countSelective
(
name
,
code
,
page
,
limit
,
sort
,
order
);
int
total
=
regionService
.
countSelective
(
name
,
code
,
page
,
limit
,
sort
,
order
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
...
...
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStatController.java
View file @
618a8b98
...
@@ -26,25 +26,16 @@ public class AdminStatController {
...
@@ -26,25 +26,16 @@ public class AdminStatController {
@GetMapping
(
"/user"
)
@GetMapping
(
"/user"
)
public
Object
statUser
(
@LoginAdmin
Integer
adminId
)
{
public
Object
statUser
(
@LoginAdmin
Integer
adminId
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
Map
>
rows
=
statService
.
statUser
();
List
<
Map
>
rows
=
statService
.
statUser
();
String
[]
columns
=
new
String
[]{
"day"
,
"users"
};
String
[]
columns
=
new
String
[]{
"day"
,
"users"
};
StatVo
statVo
=
new
StatVo
();
StatVo
statVo
=
new
StatVo
();
statVo
.
setColumns
(
columns
);
statVo
.
setColumns
(
columns
);
statVo
.
setRows
(
rows
);
statVo
.
setRows
(
rows
);
return
ResponseUtil
.
ok
(
statVo
);
return
ResponseUtil
.
ok
(
statVo
);
}
}
@GetMapping
(
"/order"
)
@GetMapping
(
"/order"
)
public
Object
statOrder
(
@LoginAdmin
Integer
adminId
)
{
public
Object
statOrder
(
@LoginAdmin
Integer
adminId
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
Map
>
rows
=
statService
.
statOrder
();
List
<
Map
>
rows
=
statService
.
statOrder
();
String
[]
columns
=
new
String
[]{
"day"
,
"orders"
,
"customers"
,
"amount"
,
"pcr"
};
String
[]
columns
=
new
String
[]{
"day"
,
"orders"
,
"customers"
,
"amount"
,
"pcr"
};
StatVo
statVo
=
new
StatVo
();
StatVo
statVo
=
new
StatVo
();
...
@@ -56,17 +47,11 @@ public class AdminStatController {
...
@@ -56,17 +47,11 @@ public class AdminStatController {
@GetMapping
(
"/goods"
)
@GetMapping
(
"/goods"
)
public
Object
statGoods
(
@LoginAdmin
Integer
adminId
)
{
public
Object
statGoods
(
@LoginAdmin
Integer
adminId
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
Map
>
rows
=
statService
.
statGoods
();
List
<
Map
>
rows
=
statService
.
statGoods
();
String
[]
columns
=
new
String
[]{
"day"
,
"orders"
,
"products"
,
"amount"
};
String
[]
columns
=
new
String
[]{
"day"
,
"orders"
,
"products"
,
"amount"
};
StatVo
statVo
=
new
StatVo
();
StatVo
statVo
=
new
StatVo
();
statVo
.
setColumns
(
columns
);
statVo
.
setColumns
(
columns
);
statVo
.
setRows
(
rows
);
statVo
.
setRows
(
rows
);
return
ResponseUtil
.
ok
(
statVo
);
return
ResponseUtil
.
ok
(
statVo
);
}
}
...
...
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java
View file @
618a8b98
...
@@ -50,9 +50,6 @@ public class AdminStorageController {
...
@@ -50,9 +50,6 @@ public class AdminStorageController {
@PostMapping
(
"/create"
)
@PostMapping
(
"/create"
)
public
Object
create
(
@LoginAdmin
Integer
adminId
,
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
IOException
{
public
Object
create
(
@LoginAdmin
Integer
adminId
,
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
IOException
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
String
originalFilename
=
file
.
getOriginalFilename
();
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
);
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
...
@@ -62,9 +59,6 @@ public class AdminStorageController {
...
@@ -62,9 +59,6 @@ public class AdminStorageController {
@PostMapping
(
"/read"
)
@PostMapping
(
"/read"
)
public
Object
read
(
@LoginAdmin
Integer
adminId
,
@NotNull
Integer
id
)
{
public
Object
read
(
@LoginAdmin
Integer
adminId
,
@NotNull
Integer
id
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
LitemallStorage
storageInfo
=
litemallStorageService
.
findById
(
id
);
LitemallStorage
storageInfo
=
litemallStorageService
.
findById
(
id
);
if
(
storageInfo
==
null
)
{
if
(
storageInfo
==
null
)
{
return
ResponseUtil
.
badArgumentValue
();
return
ResponseUtil
.
badArgumentValue
();
...
@@ -74,9 +68,6 @@ public class AdminStorageController {
...
@@ -74,9 +68,6 @@ public class AdminStorageController {
@PostMapping
(
"/update"
)
@PostMapping
(
"/update"
)
public
Object
update
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallStorage
litemallStorage
)
{
public
Object
update
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallStorage
litemallStorage
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
if
(
litemallStorageService
.
update
(
litemallStorage
)
==
0
)
{
if
(
litemallStorageService
.
update
(
litemallStorage
)
==
0
)
{
return
ResponseUtil
.
updatedDataFailed
();
return
ResponseUtil
.
updatedDataFailed
();
}
}
...
@@ -85,9 +76,6 @@ public class AdminStorageController {
...
@@ -85,9 +76,6 @@ public class AdminStorageController {
@PostMapping
(
"/delete"
)
@PostMapping
(
"/delete"
)
public
Object
delete
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallStorage
litemallStorage
)
{
public
Object
delete
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallStorage
litemallStorage
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
String
key
=
litemallStorage
.
getKey
();
String
key
=
litemallStorage
.
getKey
();
if
(
StringUtils
.
isEmpty
(
key
))
{
if
(
StringUtils
.
isEmpty
(
key
))
{
return
ResponseUtil
.
badArgument
();
return
ResponseUtil
.
badArgument
();
...
...
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminTopicController.java
View file @
618a8b98
...
@@ -35,10 +35,6 @@ public class AdminTopicController {
...
@@ -35,10 +35,6 @@ public class AdminTopicController {
@RequestParam
(
defaultValue
=
"10"
)
Integer
limit
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
limit
,
@Sort
@RequestParam
(
defaultValue
=
"add_time"
)
String
sort
,
@Sort
@RequestParam
(
defaultValue
=
"add_time"
)
String
sort
,
@Order
@RequestParam
(
defaultValue
=
"desc"
)
String
order
)
{
@Order
@RequestParam
(
defaultValue
=
"desc"
)
String
order
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
LitemallTopic
>
topicList
=
topicService
.
querySelective
(
title
,
subtitle
,
page
,
limit
,
sort
,
order
);
List
<
LitemallTopic
>
topicList
=
topicService
.
querySelective
(
title
,
subtitle
,
page
,
limit
,
sort
,
order
);
int
total
=
topicService
.
countSelective
(
title
,
subtitle
,
page
,
limit
,
sort
,
order
);
int
total
=
topicService
.
countSelective
(
title
,
subtitle
,
page
,
limit
,
sort
,
order
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
...
@@ -66,9 +62,6 @@ public class AdminTopicController {
...
@@ -66,9 +62,6 @@ public class AdminTopicController {
@PostMapping
(
"/create"
)
@PostMapping
(
"/create"
)
public
Object
create
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallTopic
topic
)
{
public
Object
create
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallTopic
topic
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
Object
error
=
validate
(
topic
);
Object
error
=
validate
(
topic
);
if
(
error
!=
null
)
{
if
(
error
!=
null
)
{
return
error
;
return
error
;
...
@@ -79,19 +72,12 @@ public class AdminTopicController {
...
@@ -79,19 +72,12 @@ public class AdminTopicController {
@GetMapping
(
"/read"
)
@GetMapping
(
"/read"
)
public
Object
read
(
@LoginAdmin
Integer
adminId
,
@NotNull
Integer
id
)
{
public
Object
read
(
@LoginAdmin
Integer
adminId
,
@NotNull
Integer
id
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
LitemallTopic
topic
=
topicService
.
findById
(
id
);
LitemallTopic
topic
=
topicService
.
findById
(
id
);
return
ResponseUtil
.
ok
(
topic
);
return
ResponseUtil
.
ok
(
topic
);
}
}
@PostMapping
(
"/update"
)
@PostMapping
(
"/update"
)
public
Object
update
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallTopic
topic
)
{
public
Object
update
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallTopic
topic
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
Object
error
=
validate
(
topic
);
Object
error
=
validate
(
topic
);
if
(
error
!=
null
)
{
if
(
error
!=
null
)
{
return
error
;
return
error
;
...
@@ -104,9 +90,6 @@ public class AdminTopicController {
...
@@ -104,9 +90,6 @@ public class AdminTopicController {
@PostMapping
(
"/delete"
)
@PostMapping
(
"/delete"
)
public
Object
delete
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallTopic
topic
)
{
public
Object
delete
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallTopic
topic
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
topicService
.
deleteById
(
topic
.
getId
());
topicService
.
deleteById
(
topic
.
getId
());
return
ResponseUtil
.
ok
();
return
ResponseUtil
.
ok
();
}
}
...
...
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminUserController.java
View file @
618a8b98
...
@@ -38,9 +38,6 @@ public class AdminUserController {
...
@@ -38,9 +38,6 @@ public class AdminUserController {
@RequestParam
(
defaultValue
=
"10"
)
Integer
limit
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
limit
,
@Sort
@RequestParam
(
defaultValue
=
"add_time"
)
String
sort
,
@Sort
@RequestParam
(
defaultValue
=
"add_time"
)
String
sort
,
@Order
@RequestParam
(
defaultValue
=
"desc"
)
String
order
)
{
@Order
@RequestParam
(
defaultValue
=
"desc"
)
String
order
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
LitemallUser
>
userList
=
userService
.
querySelective
(
username
,
mobile
,
page
,
limit
,
sort
,
order
);
List
<
LitemallUser
>
userList
=
userService
.
querySelective
(
username
,
mobile
,
page
,
limit
,
sort
,
order
);
int
total
=
userService
.
countSeletive
(
username
,
mobile
,
page
,
limit
,
sort
,
order
);
int
total
=
userService
.
countSeletive
(
username
,
mobile
,
page
,
limit
,
sort
,
order
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
...
@@ -52,10 +49,6 @@ public class AdminUserController {
...
@@ -52,10 +49,6 @@ public class AdminUserController {
@GetMapping
(
"/username"
)
@GetMapping
(
"/username"
)
public
Object
username
(
@LoginAdmin
Integer
adminId
,
@NotEmpty
String
username
)
{
public
Object
username
(
@LoginAdmin
Integer
adminId
,
@NotEmpty
String
username
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
int
total
=
userService
.
countSeletive
(
username
,
null
,
null
,
null
,
null
,
null
);
int
total
=
userService
.
countSeletive
(
username
,
null
,
null
,
null
,
null
,
null
);
if
(
total
==
0
)
{
if
(
total
==
0
)
{
return
ResponseUtil
.
ok
(
"不存在"
);
return
ResponseUtil
.
ok
(
"不存在"
);
...
@@ -87,9 +80,6 @@ public class AdminUserController {
...
@@ -87,9 +80,6 @@ public class AdminUserController {
@PostMapping
(
"/create"
)
@PostMapping
(
"/create"
)
public
Object
create
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallUser
user
)
{
public
Object
create
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallUser
user
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
Object
error
=
validate
(
user
);
Object
error
=
validate
(
user
);
if
(
error
!=
null
)
{
if
(
error
!=
null
)
{
return
error
;
return
error
;
...
@@ -119,9 +109,6 @@ public class AdminUserController {
...
@@ -119,9 +109,6 @@ public class AdminUserController {
@PostMapping
(
"/update"
)
@PostMapping
(
"/update"
)
public
Object
update
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallUser
user
)
{
public
Object
update
(
@LoginAdmin
Integer
adminId
,
@RequestBody
LitemallUser
user
)
{
if
(
adminId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
Object
error
=
validate
(
user
);
Object
error
=
validate
(
user
);
if
(
error
!=
null
)
{
if
(
error
!=
null
)
{
return
error
;
return
error
;
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java
View file @
618a8b98
package
org.linlinjava.litemall.core.config
;
package
org.linlinjava.litemall.core.config
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authz.AuthorizationException
;
import
org.apache.shiro.authz.AuthorizationException
;
import
org.apache.shiro.authz.UnauthorizedException
;
import
org.apache.shiro.authz.UnauthorizedException
;
import
org.hibernate.validator.internal.engine.path.PathImpl
;
import
org.hibernate.validator.internal.engine.path.PathImpl
;
...
@@ -47,6 +48,13 @@ public class GlobalExceptionHandler {
...
@@ -47,6 +48,13 @@ public class GlobalExceptionHandler {
return
ResponseUtil
.
badArgumentValue
();
return
ResponseUtil
.
badArgumentValue
();
}
}
@ExceptionHandler
(
AuthenticationException
.
class
)
@ResponseBody
public
Object
unauthenticatedHandler
(
AuthenticationException
e
)
{
e
.
printStackTrace
();
return
ResponseUtil
.
unlogin
();
}
@ExceptionHandler
(
AuthorizationException
.
class
)
@ExceptionHandler
(
AuthorizationException
.
class
)
@ResponseBody
@ResponseBody
public
Object
unauthorizedHandler
(
AuthorizationException
e
)
{
public
Object
unauthorizedHandler
(
AuthorizationException
e
)
{
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
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