2018-01-17 17:51:53 +08:00
|
|
|
package cn.keking.service.impl;
|
|
|
|
|
|
2019-06-17 14:21:16 +08:00
|
|
|
import cn.keking.model.FileAttribute;
|
2018-01-17 17:51:53 +08:00
|
|
|
import cn.keking.service.FilePreview;
|
|
|
|
|
import cn.keking.utils.FileUtils;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by kl on 2018/1/17.
|
|
|
|
|
* Content :图片文件处理
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class PictureFilePreviewImpl implements FilePreview {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
FileUtils fileUtils;
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-06-17 14:21:16 +08:00
|
|
|
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
2020-04-14 11:17:07 +08:00
|
|
|
String fileKey = (String) RequestContextHolder.currentRequestAttributes().getAttribute("fileKey",0);
|
2018-01-17 17:51:53 +08:00
|
|
|
List imgUrls = Lists.newArrayList(url);
|
|
|
|
|
try{
|
|
|
|
|
imgUrls.clear();
|
2020-05-12 11:00:20 +08:00
|
|
|
imgUrls.addAll(fileUtils.getImgCache(fileKey));
|
2018-01-17 17:51:53 +08:00
|
|
|
}catch (Exception e){
|
|
|
|
|
imgUrls = Lists.newArrayList(url);
|
|
|
|
|
}
|
|
|
|
|
model.addAttribute("imgurls", imgUrls);
|
|
|
|
|
model.addAttribute("currentUrl",url);
|
|
|
|
|
return "picture";
|
|
|
|
|
}
|
|
|
|
|
}
|