feat[后台管理]:图片的预览和下载功能
This commit is contained in:
+8
-2
@@ -6,6 +6,7 @@ import com.central.common.model.Result;
|
||||
import com.central.file.service.IFileService;
|
||||
import com.central.file.utils.HexToJpeg;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -81,11 +82,16 @@ public class FileController {
|
||||
return fileService.getViewUrl(id);
|
||||
}
|
||||
|
||||
@PostMapping("/files/name")
|
||||
public String getViewUrlByName(@RequestBody String name) {
|
||||
@GetMapping("/files/name")
|
||||
public String getViewUrlByName(@RequestParam String name) {
|
||||
return fileService.getViewUrlByName(name);
|
||||
}
|
||||
|
||||
@GetMapping("/files/name/style")
|
||||
public String getViewUrlByNameStyle(@RequestParam Map<String, Object> params) {
|
||||
return fileService.getZipViewUrlByName(MapUtils.getString(params,"name"),MapUtils.getString(params, "style"));
|
||||
}
|
||||
|
||||
@GetMapping("/type/{id}")
|
||||
public String getFileInfo(@PathVariable String id) {
|
||||
FileInfo fileInfo = fileService.getFileInfo(id);
|
||||
|
||||
@@ -29,6 +29,8 @@ public interface IFileService extends IService<FileInfo> {
|
||||
|
||||
String getViewUrlByName(String name);
|
||||
|
||||
String getZipViewUrlByName(String name, String style);
|
||||
|
||||
FileInfo getFileInfo(String id);
|
||||
|
||||
FileInfo createFile(String path);
|
||||
|
||||
@@ -54,6 +54,11 @@ public class CosService extends AbstractIFileService {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getZipViewUrlByName(String name, String style) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void out(String id, OutputStream os) {
|
||||
FileInfo fileInfo = baseMapper.selectById(id);
|
||||
|
||||
+5
@@ -50,6 +50,11 @@ public class FastdfsService extends AbstractIFileService {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getZipViewUrlByName(String name, String style) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void out(String id, OutputStream os) {
|
||||
}
|
||||
|
||||
@@ -80,6 +80,11 @@ public class OssService extends AbstractIFileService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getZipViewUrlByName(String name, String style) {
|
||||
return ossTemplate.getViewUrl(name,style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo getFileInfo(String id) {
|
||||
return baseMapper.findById(id);
|
||||
|
||||
@@ -55,6 +55,11 @@ public class S3Service extends AbstractIFileService {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getZipViewUrlByName(String name, String style) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void out(String id, OutputStream os) {
|
||||
FileInfo fileInfo = baseMapper.selectById(id);
|
||||
|
||||
+17
-3
@@ -1,6 +1,8 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
@@ -74,12 +76,15 @@ public class OrderController {
|
||||
@Autowired
|
||||
private TencentPayProperties tencentPayProperties;
|
||||
|
||||
@Value("${cdn.oss-url}")
|
||||
@Value("${file.oss-url}")
|
||||
private String cdnOssUrl;
|
||||
|
||||
@Value("${cdn.url}")
|
||||
@Value("${file.cdn-url}")
|
||||
private String cdnUrl;
|
||||
|
||||
@Value("${file.style}")
|
||||
private String fileStyle;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@@ -125,11 +130,13 @@ public class OrderController {
|
||||
params.put("userId", user.getId());
|
||||
|
||||
// 获取当前日期,格式化为 yyyyMMdd
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstant.DATEMINUTE_FORMAT);
|
||||
|
||||
PageResult<Order> result = orderService.findListByUser(params);
|
||||
if (result.getCount() > 0){
|
||||
List<Map> page = new ArrayList<>();
|
||||
Map<String, String> fileMap = new HashMap<>();
|
||||
fileMap.put("style", fileStyle);
|
||||
for(Order order : result.getData()){
|
||||
Map<String,Object> orderFileMap = new HashMap<>();
|
||||
orderFileMap.put("time", sdf.format(order.getCreateTime()));
|
||||
@@ -143,6 +150,9 @@ public class OrderController {
|
||||
String url = fileCenterService.getViewUrlByName(orderFile.getFilePath());
|
||||
imgMap.put("url", url.replace(cdnOssUrl,cdnUrl));
|
||||
imgMap.put("contentType", ContentTypeUtil.getContentTypeFromUrl(url));
|
||||
|
||||
fileMap.put("name",orderFile.getFilePath());
|
||||
imgMap.put("viewUrl", fileCenterService.getViewUrlByNameStyle(fileMap));
|
||||
resultList.add(imgMap);
|
||||
}
|
||||
}
|
||||
@@ -167,9 +177,13 @@ public class OrderController {
|
||||
public Result<Order> createOrder(@RequestBody Order order) {
|
||||
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
|
||||
//@TODO 设置价格逻辑优化
|
||||
order.setOrderAmount("1990");
|
||||
order.setUserId(user.getId());
|
||||
order.setTenantId(TenantContextHolder.getTenant());
|
||||
|
||||
//景区唯一二维码codeId,该二维码中包含价格信息
|
||||
if (order.getCodeId() == null){
|
||||
order.setCodeId("f83be3a9-2888-4000-8cf9-e6acdb3a22cd");
|
||||
}
|
||||
|
||||
+16
-1
@@ -18,9 +18,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -46,6 +48,9 @@ public class OrderFileController {
|
||||
@Autowired
|
||||
private IOrderService orderService;
|
||||
|
||||
@Value("${file.style}")
|
||||
private String fileStyle;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@@ -56,7 +61,17 @@ public class OrderFileController {
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||
return orderFileService.findList(params);
|
||||
PageResult<OrderFile> pageResult = orderFileService.findList(params);
|
||||
Map<String, String> fileMap = new HashMap<>();
|
||||
fileMap.put("style", fileStyle);
|
||||
if (pageResult.getResp_code() == 0){
|
||||
for (OrderFile orderFile: pageResult.getData()){
|
||||
orderFile.setViewUrl(fileCenterService.getViewUrlByName(orderFile.getFilePath()));
|
||||
fileMap.put("name", orderFile.getFilePath());
|
||||
orderFile.setZipViewUrl(fileCenterService.getViewUrlByNameStyle(fileMap));
|
||||
}
|
||||
}
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-6
@@ -5,10 +5,7 @@ import com.central.common.model.FileInfo;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.fallback.FileCenterServiceFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -41,6 +38,9 @@ public interface FileCenterService {
|
||||
@PostMapping("/path")
|
||||
FileInfo creatFileInfo(@RequestBody String path);
|
||||
|
||||
@PostMapping("/files/name")
|
||||
String getViewUrlByName(@RequestBody String name) ;
|
||||
@GetMapping("/files/name")
|
||||
String getViewUrlByName(@RequestParam("name") String name) ;
|
||||
|
||||
@GetMapping("/files/name/style")
|
||||
String getViewUrlByNameStyle(@RequestParam("params") Map<String,String> params) ;
|
||||
}
|
||||
|
||||
+5
@@ -50,6 +50,11 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCen
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrlByNameStyle(Map<String, String> params) {
|
||||
return "";
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ public class OrderFile extends SuperEntity {
|
||||
private Long userId;
|
||||
|
||||
private transient String viewUrl;
|
||||
|
||||
//文件缩略图
|
||||
private transient String zipViewUrl;
|
||||
// 景区ID
|
||||
private Long tourismId;
|
||||
|
||||
|
||||
@@ -42,9 +42,10 @@ tencent:
|
||||
appSecret: ${zlt.security.tencent.app-secret}
|
||||
accessTokenUrl: ${zlt.security.tencent.accessTokenUrl}
|
||||
getwxacodeUrl: https://api.weixin.qq.com/wxa/getwxacode?access_token=
|
||||
cdn:
|
||||
file:
|
||||
oss-url: goflyapp.oss-cn-beijing.aliyuncs.com
|
||||
url: cdn.goflytec.com
|
||||
cdn-url: cdn.goflytec.com
|
||||
style: image/resize,m_fixed,w_100,h_90
|
||||
#审计日志
|
||||
# audit-log:
|
||||
# enabled: true
|
||||
|
||||
Reference in New Issue
Block a user