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
f3d9fce5
Commit
f3d9fce5
authored
Aug 18, 2018
by
Menethil
Browse files
修复BUG:图片上传
parent
d7d7e657
Changes
8
Hide whitespace changes
Inline
Side-by-side
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGrouponController.java
View file @
f3d9fce5
...
@@ -50,17 +50,21 @@ public class AdminGrouponController {
...
@@ -50,17 +50,21 @@ public class AdminGrouponController {
List
<
Map
<
String
,
Object
>>
records
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
records
=
new
ArrayList
<>();
for
(
LitemallGroupon
groupon
:
grouponList
)
{
for
(
LitemallGroupon
groupon
:
grouponList
)
{
Map
<
String
,
Object
>
RecordData
=
new
HashMap
<>();
try
{
List
<
LitemallGroupon
>
subGrouponList
=
grouponService
.
queryJoinRecord
(
groupon
.
getId
());
Map
<
String
,
Object
>
RecordData
=
new
HashMap
<>();
LitemallGrouponRules
rules
=
rulesService
.
queryById
(
groupon
.
getRulesId
());
List
<
LitemallGroupon
>
subGrouponList
=
grouponService
.
queryJoinRecord
(
groupon
.
getId
());
LitemallGoods
goods
=
goodsService
.
findById
(
rules
.
getGoodsId
());
LitemallGrouponRules
rules
=
rulesService
.
queryById
(
groupon
.
getRulesId
());
LitemallGoods
goods
=
goodsService
.
findById
(
rules
.
getGoodsId
());
RecordData
.
put
(
"groupon"
,
groupon
);
RecordData
.
put
(
"subGroupons"
,
subGrouponList
);
RecordData
.
put
(
"groupon"
,
groupon
);
RecordData
.
put
(
"rules"
,
rules
);
RecordData
.
put
(
"subGroupons"
,
subGrouponList
);
RecordData
.
put
(
"goods"
,
goods
);
RecordData
.
put
(
"rules"
,
rules
);
RecordData
.
put
(
"goods"
,
goods
);
records
.
add
(
RecordData
);
records
.
add
(
RecordData
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeBase.java
View file @
f3d9fce5
...
@@ -22,16 +22,6 @@ public abstract class QCodeBase {
...
@@ -22,16 +22,6 @@ public abstract class QCodeBase {
protected
abstract
String
getKeyName
(
String
id
);
protected
abstract
String
getKeyName
(
String
id
);
/**
* 获取图片地址
*
* @param id
* @return
*/
public
String
getShareImageUrl
(
String
id
)
{
return
storageService
.
generateUrl
(
getKeyName
(
id
));
}
protected
BufferedImage
getQCode
(
String
scene
,
String
page
)
{
protected
BufferedImage
getQCode
(
String
scene
,
String
page
)
{
//创建该商品的二维码
//创建该商品的二维码
File
file
=
null
;
File
file
=
null
;
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java
View file @
f3d9fce5
...
@@ -95,7 +95,7 @@ public class StorageService {
...
@@ -95,7 +95,7 @@ public class StorageService {
storage
.
delete
(
keyName
);
storage
.
delete
(
keyName
);
}
}
p
ublic
String
generateUrl
(
String
keyName
)
{
p
rivate
String
generateUrl
(
String
keyName
)
{
return
storage
.
generateUrl
(
keyName
);
return
storage
.
generateUrl
(
keyName
);
}
}
}
}
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java
View file @
f3d9fce5
...
@@ -17,7 +17,7 @@ public class LitemallGoodsService {
...
@@ -17,7 +17,7 @@ public class LitemallGoodsService {
@Resource
@Resource
private
LitemallGoodsMapper
goodsMapper
;
private
LitemallGoodsMapper
goodsMapper
;
Column
[]
columns
=
new
Column
[]{
Column
.
id
,
Column
.
name
,
Column
.
brief
,
Column
.
picUrl
,
Column
.
counterPrice
,
Column
.
retailPrice
};
Column
[]
columns
=
new
Column
[]{
Column
.
id
,
Column
.
name
,
Column
.
brief
,
Column
.
picUrl
,
Column
.
isHot
,
Column
.
isNew
,
Column
.
counterPrice
,
Column
.
retailPrice
};
/**
/**
* 获取热卖商品
* 获取热卖商品
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java
View file @
f3d9fce5
...
@@ -189,7 +189,7 @@ public class WxGoodsController {
...
@@ -189,7 +189,7 @@ public class WxGoodsController {
if
(
cur
.
getPid
()
==
0
)
{
if
(
cur
.
getPid
()
==
0
)
{
parent
=
cur
;
parent
=
cur
;
children
=
categoryService
.
queryByPid
(
cur
.
getId
());
children
=
categoryService
.
queryByPid
(
cur
.
getId
());
cur
=
children
.
size
()
>
0
?
children
.
get
(
0
)
:
cur
;
cur
=
children
.
size
()
>
0
?
children
.
get
(
0
)
:
cur
;
}
else
{
}
else
{
parent
=
categoryService
.
findById
(
cur
.
getPid
());
parent
=
categoryService
.
findById
(
cur
.
getPid
());
children
=
categoryService
.
queryByPid
(
cur
.
getPid
());
children
=
categoryService
.
queryByPid
(
cur
.
getPid
());
...
@@ -258,8 +258,7 @@ public class WxGoodsController {
...
@@ -258,8 +258,7 @@ public class WxGoodsController {
List
<
LitemallCategory
>
categoryList
=
null
;
List
<
LitemallCategory
>
categoryList
=
null
;
if
(
goodsCatIds
.
size
()
!=
0
)
{
if
(
goodsCatIds
.
size
()
!=
0
)
{
categoryList
=
categoryService
.
queryL2ByIds
(
goodsCatIds
);
categoryList
=
categoryService
.
queryL2ByIds
(
goodsCatIds
);
}
}
else
{
else
{
categoryList
=
new
ArrayList
<>(
0
);
categoryList
=
new
ArrayList
<>(
0
);
}
}
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java
View file @
f3d9fce5
...
@@ -96,7 +96,7 @@ public class WxHomeController {
...
@@ -96,7 +96,7 @@ public class WxHomeController {
data
.
put
(
"topicList"
,
topicList
);
data
.
put
(
"topicList"
,
topicList
);
//优惠专区
//优惠专区
List
<
LitemallGrouponRules
>
grouponRules
=
grouponRulesService
.
queryByIndex
(
0
,
4
);
List
<
LitemallGrouponRules
>
grouponRules
=
grouponRulesService
.
queryByIndex
(
0
,
5
);
List
<
LitemallGoods
>
grouponGoods
=
new
ArrayList
<>();
List
<
LitemallGoods
>
grouponGoods
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
grouponList
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
grouponList
=
new
ArrayList
<>();
for
(
LitemallGrouponRules
rule
:
grouponRules
)
{
for
(
LitemallGrouponRules
rule
:
grouponRules
)
{
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java
View file @
f3d9fce5
...
@@ -71,7 +71,6 @@ public class WxOrderController {
...
@@ -71,7 +71,6 @@ public class WxOrderController {
@Autowired
@Autowired
private
PlatformTransactionManager
txManager
;
private
PlatformTransactionManager
txManager
;
@Autowired
@Autowired
private
LitemallUserService
userService
;
private
LitemallUserService
userService
;
@Autowired
@Autowired
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java
View file @
f3d9fce5
...
@@ -15,10 +15,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -15,10 +15,7 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
@RestController
@RestController
...
@@ -31,18 +28,18 @@ public class WxStorageController {
...
@@ -31,18 +28,18 @@ public class WxStorageController {
@Autowired
@Autowired
private
LitemallStorageService
litemallStorageService
;
private
LitemallStorageService
litemallStorageService
;
private
String
generateKey
(
String
originalFilename
){
private
String
generateKey
(
String
originalFilename
)
{
int
index
=
originalFilename
.
lastIndexOf
(
'.'
);
int
index
=
originalFilename
.
lastIndexOf
(
'.'
);
String
suffix
=
originalFilename
.
substring
(
index
);
String
suffix
=
originalFilename
.
substring
(
index
);
String
key
=
null
;
String
key
=
null
;
LitemallStorage
storageInfo
=
null
;
LitemallStorage
storageInfo
=
null
;
do
{
do
{
key
=
CharUtil
.
getRandomString
(
20
)
+
suffix
;
key
=
CharUtil
.
getRandomString
(
20
)
+
suffix
;
storageInfo
=
litemallStorageService
.
findByKey
(
key
);
storageInfo
=
litemallStorageService
.
findByKey
(
key
);
}
}
while
(
storageInfo
!=
null
);
while
(
storageInfo
!=
null
);
return
key
;
return
key
;
}
}
...
@@ -50,40 +47,24 @@ public class WxStorageController {
...
@@ -50,40 +47,24 @@ public class WxStorageController {
@PostMapping
(
"/upload"
)
@PostMapping
(
"/upload"
)
public
Object
upload
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
IOException
{
public
Object
upload
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
IOException
{
String
originalFilename
=
file
.
getOriginalFilename
();
String
originalFilename
=
file
.
getOriginalFilename
();
InputStream
inputStream
=
null
;
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
);
try
{
inputStream
=
file
.
getInputStream
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
ResponseUtil
.
badArgumentValue
();
}
String
key
=
generateKey
(
originalFilename
);
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
key
);
String
url
=
storageService
.
generateUrl
(
key
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
LitemallStorage
storageInfo
=
new
LitemallStorage
();
data
.
put
(
"url"
,
url
);
storageInfo
.
setName
(
originalFilename
);
return
ResponseUtil
.
ok
(
data
);
storageInfo
.
setSize
((
int
)
file
.
getSize
());
storageInfo
.
setType
(
file
.
getContentType
());
storageInfo
.
setAddTime
(
LocalDateTime
.
now
());
storageInfo
.
setModified
(
LocalDateTime
.
now
());
storageInfo
.
setKey
(
key
);
storageInfo
.
setUrl
(
url
);
litemallStorageService
.
add
(
storageInfo
);
return
ResponseUtil
.
ok
(
storageInfo
);
}
}
@GetMapping
(
"/fetch/{key:.+}"
)
@GetMapping
(
"/fetch/{key:.+}"
)
public
ResponseEntity
<
Resource
>
fetch
(
@PathVariable
String
key
)
{
public
ResponseEntity
<
Resource
>
fetch
(
@PathVariable
String
key
)
{
LitemallStorage
litemallStorage
=
litemallStorageService
.
findByKey
(
key
);
LitemallStorage
litemallStorage
=
litemallStorageService
.
findByKey
(
key
);
if
(
key
==
null
){
if
(
key
==
null
)
{
ResponseEntity
.
notFound
();
ResponseEntity
.
notFound
();
}
}
String
type
=
litemallStorage
.
getType
();
String
type
=
litemallStorage
.
getType
();
MediaType
mediaType
=
MediaType
.
parseMediaType
(
type
);
MediaType
mediaType
=
MediaType
.
parseMediaType
(
type
);
Resource
file
=
storageService
.
loadAsResource
(
key
);
Resource
file
=
storageService
.
loadAsResource
(
key
);
if
(
file
==
null
)
{
if
(
file
==
null
)
{
ResponseEntity
.
notFound
();
ResponseEntity
.
notFound
();
}
}
return
ResponseEntity
.
ok
().
contentType
(
mediaType
).
body
(
file
);
return
ResponseEntity
.
ok
().
contentType
(
mediaType
).
body
(
file
);
...
@@ -92,14 +73,14 @@ public class WxStorageController {
...
@@ -92,14 +73,14 @@ public class WxStorageController {
@GetMapping
(
"/download/{key:.+}"
)
@GetMapping
(
"/download/{key:.+}"
)
public
ResponseEntity
<
Resource
>
download
(
@PathVariable
String
key
)
{
public
ResponseEntity
<
Resource
>
download
(
@PathVariable
String
key
)
{
LitemallStorage
litemallStorage
=
litemallStorageService
.
findByKey
(
key
);
LitemallStorage
litemallStorage
=
litemallStorageService
.
findByKey
(
key
);
if
(
key
==
null
){
if
(
key
==
null
)
{
ResponseEntity
.
notFound
();
ResponseEntity
.
notFound
();
}
}
String
type
=
litemallStorage
.
getType
();
String
type
=
litemallStorage
.
getType
();
MediaType
mediaType
=
MediaType
.
parseMediaType
(
type
);
MediaType
mediaType
=
MediaType
.
parseMediaType
(
type
);
Resource
file
=
storageService
.
loadAsResource
(
key
);
Resource
file
=
storageService
.
loadAsResource
(
key
);
if
(
file
==
null
)
{
if
(
file
==
null
)
{
ResponseEntity
.
notFound
();
ResponseEntity
.
notFound
();
}
}
return
ResponseEntity
.
ok
().
contentType
(
mediaType
).
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
return
ResponseEntity
.
ok
().
contentType
(
mediaType
).
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
...
...
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