修复BUG:图片上传
This commit is contained in:
@@ -50,17 +50,21 @@ public class AdminGrouponController {
|
||||
|
||||
List<Map<String, Object>> records = new ArrayList<>();
|
||||
for (LitemallGroupon groupon : grouponList) {
|
||||
Map<String, Object> RecordData = new HashMap<>();
|
||||
List<LitemallGroupon> subGrouponList = grouponService.queryJoinRecord(groupon.getId());
|
||||
LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId());
|
||||
LitemallGoods goods = goodsService.findById(rules.getGoodsId());
|
||||
try {
|
||||
Map<String, Object> RecordData = new HashMap<>();
|
||||
List<LitemallGroupon> subGrouponList = grouponService.queryJoinRecord(groupon.getId());
|
||||
LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId());
|
||||
LitemallGoods goods = goodsService.findById(rules.getGoodsId());
|
||||
|
||||
RecordData.put("groupon", groupon);
|
||||
RecordData.put("subGroupons", subGrouponList);
|
||||
RecordData.put("rules", rules);
|
||||
RecordData.put("goods", goods);
|
||||
RecordData.put("groupon", groupon);
|
||||
RecordData.put("subGroupons", subGrouponList);
|
||||
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<>();
|
||||
|
||||
@@ -22,16 +22,6 @@ public abstract class QCodeBase {
|
||||
|
||||
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) {
|
||||
//创建该商品的二维码
|
||||
File file = null;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class StorageService {
|
||||
storage.delete(keyName);
|
||||
}
|
||||
|
||||
public String generateUrl(String keyName) {
|
||||
private String generateUrl(String keyName) {
|
||||
return storage.generateUrl(keyName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class LitemallGoodsService {
|
||||
@Resource
|
||||
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};
|
||||
|
||||
/**
|
||||
* 获取热卖商品
|
||||
|
||||
@@ -189,7 +189,7 @@ public class WxGoodsController {
|
||||
if (cur.getPid() == 0) {
|
||||
parent = cur;
|
||||
children = categoryService.queryByPid(cur.getId());
|
||||
cur = children.size()>0?children.get(0):cur;
|
||||
cur = children.size() > 0 ? children.get(0) : cur;
|
||||
} else {
|
||||
parent = categoryService.findById(cur.getPid());
|
||||
children = categoryService.queryByPid(cur.getPid());
|
||||
@@ -258,8 +258,7 @@ public class WxGoodsController {
|
||||
List<LitemallCategory> categoryList = null;
|
||||
if (goodsCatIds.size() != 0) {
|
||||
categoryList = categoryService.queryL2ByIds(goodsCatIds);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
categoryList = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ public class WxHomeController {
|
||||
data.put("topicList", topicList);
|
||||
|
||||
//优惠专区
|
||||
List<LitemallGrouponRules> grouponRules = grouponRulesService.queryByIndex(0, 4);
|
||||
List<LitemallGrouponRules> grouponRules = grouponRulesService.queryByIndex(0, 5);
|
||||
List<LitemallGoods> grouponGoods = new ArrayList<>();
|
||||
List<Map<String, Object>> grouponList = new ArrayList<>();
|
||||
for (LitemallGrouponRules rule : grouponRules) {
|
||||
|
||||
@@ -71,7 +71,6 @@ public class WxOrderController {
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager txManager;
|
||||
|
||||
@Autowired
|
||||
private LitemallUserService userService;
|
||||
@Autowired
|
||||
|
||||
@@ -15,10 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@@ -31,18 +28,18 @@ public class WxStorageController {
|
||||
@Autowired
|
||||
private LitemallStorageService litemallStorageService;
|
||||
|
||||
private String generateKey(String originalFilename){
|
||||
private String generateKey(String originalFilename) {
|
||||
int index = originalFilename.lastIndexOf('.');
|
||||
String suffix = originalFilename.substring(index);
|
||||
|
||||
String key = null;
|
||||
LitemallStorage storageInfo = null;
|
||||
|
||||
do{
|
||||
do {
|
||||
key = CharUtil.getRandomString(20) + suffix;
|
||||
storageInfo = litemallStorageService.findByKey(key);
|
||||
}
|
||||
while(storageInfo != null);
|
||||
while (storageInfo != null);
|
||||
|
||||
return key;
|
||||
}
|
||||
@@ -50,40 +47,24 @@ public class WxStorageController {
|
||||
@PostMapping("/upload")
|
||||
public Object upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
InputStream inputStream = null;
|
||||
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.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
|
||||
|
||||
String url = storageService.generateUrl(key);
|
||||
LitemallStorage storageInfo = new LitemallStorage();
|
||||
storageInfo.setName(originalFilename);
|
||||
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);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("url", url);
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@GetMapping("/fetch/{key:.+}")
|
||||
public ResponseEntity<Resource> fetch(@PathVariable String key) {
|
||||
LitemallStorage litemallStorage = litemallStorageService.findByKey(key);
|
||||
if(key == null){
|
||||
if (key == null) {
|
||||
ResponseEntity.notFound();
|
||||
}
|
||||
String type = litemallStorage.getType();
|
||||
MediaType mediaType = MediaType.parseMediaType(type);
|
||||
|
||||
Resource file = storageService.loadAsResource(key);
|
||||
if(file == null) {
|
||||
if (file == null) {
|
||||
ResponseEntity.notFound();
|
||||
}
|
||||
return ResponseEntity.ok().contentType(mediaType).body(file);
|
||||
@@ -92,14 +73,14 @@ public class WxStorageController {
|
||||
@GetMapping("/download/{key:.+}")
|
||||
public ResponseEntity<Resource> download(@PathVariable String key) {
|
||||
LitemallStorage litemallStorage = litemallStorageService.findByKey(key);
|
||||
if(key == null){
|
||||
if (key == null) {
|
||||
ResponseEntity.notFound();
|
||||
}
|
||||
String type = litemallStorage.getType();
|
||||
MediaType mediaType = MediaType.parseMediaType(type);
|
||||
|
||||
Resource file = storageService.loadAsResource(key);
|
||||
if(file == null) {
|
||||
if (file == null) {
|
||||
ResponseEntity.notFound();
|
||||
}
|
||||
return ResponseEntity.ok().contentType(mediaType).header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
|
||||
Reference in New Issue
Block a user