优化:添加日志

pull/13/head
陈精华 2020-05-14 10:11:15 +08:00 committed by kl
parent 9cc0267619
commit 59ac8effc1
9 changed files with 31 additions and 33 deletions

View File

@ -56,24 +56,27 @@ public class FileConverQueueTask {
@Override @Override
public void run() { public void run() {
while (true) { while (true) {
String url = null;
try { try {
String url = cacheService.takeQueueTask(); url = cacheService.takeQueueTask();
if(url != null){ if(url != null){
FileAttribute fileAttribute = fileUtils.getFileAttribute(url); FileAttribute fileAttribute = fileUtils.getFileAttribute(url);
logger.info("正在处理转换任务,文件名称【{}】",fileAttribute.getName()); FileType fileType = fileAttribute.getType();
FileType fileType=fileAttribute.getType(); logger.info("正在处理预览转换任务url{},预览类型:{}", url, fileType);
if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)){ if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)) {
FilePreview filePreview=previewFactory.get(fileAttribute); FilePreview filePreview = previewFactory.get(fileAttribute);
filePreview.filePreviewHandle(url, new ExtendedModelMap(), fileAttribute); filePreview.filePreviewHandle(url, new ExtendedModelMap(), fileAttribute);
} else {
logger.info("预览类型无需处理url{},预览类型:{}", url, fileType);
} }
} }
} catch (Exception e) { } catch (Exception e) {
try { try {
Thread.sleep(1000*10); Thread.sleep(1000*10);
}catch (Exception ex){ } catch (Exception ex){
ex.printStackTrace(); ex.printStackTrace();
} }
e.printStackTrace(); logger.info("处理预览转换任务异常url{}", url, e);
} }
} }
} }

View File

@ -43,7 +43,7 @@ public class CadToPdf {
cadImage.close(); cadImage.close();
return true; return true;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
logger.error("PDFFileNotFoundException", e); logger.error("PDFFileNotFoundExceptioninputFilePath{}", inputFilePath, e);
return false; return false;
} }
} }

View File

@ -33,10 +33,7 @@ public class ConverterUtils {
private final Logger logger = LoggerFactory.getLogger(ConverterUtils.class); private final Logger logger = LoggerFactory.getLogger(ConverterUtils.class);
// @Value("${office.home}") private OfficeManager officeManager;
// String officeHome;
// OpenOfficeConnection connection;
OfficeManager officeManager;
@PostConstruct @PostConstruct
public void initOfficeManager() { public void initOfficeManager() {

View File

@ -84,7 +84,7 @@ public class DownloadUtils {
} }
return response; return response;
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("文件下载失败", e); LOGGER.error("文件下载失败url{}", urlAddress, e);
response.setCode(1); response.setCode(1);
response.setContent(null); response.setContent(null);
if (e instanceof FileNotFoundException) { if (e instanceof FileNotFoundException) {

View File

@ -36,7 +36,7 @@ public class FileUtils {
String fileDir = ConfigConstants.getFileDir(); String fileDir = ConfigConstants.getFileDir();
/** /**
* (redis) * ()
* @return * @return
*/ */
public Map<String, String> listConvertedFiles() { public Map<String, String> listConvertedFiles() {

View File

@ -18,7 +18,7 @@ import java.util.List;
@Component @Component
public class PdfUtils { public class PdfUtils {
private final Logger LOGGER = LoggerFactory.getLogger(PdfUtils.class); private final Logger logger = LoggerFactory.getLogger(PdfUtils.class);
@Autowired @Autowired
FileUtils fileUtils; FileUtils fileUtils;
@ -57,7 +57,7 @@ public class PdfUtils {
doc.close(); doc.close();
fileUtils.addConvertedPdfImage(pdfFilePath, pageCount); fileUtils.addConvertedPdfImage(pdfFilePath, pageCount);
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Convert pdf to jpg exception", e); logger.error("Convert pdf to jpg exception, pdfFilePath{}", pdfFilePath, e);
} }
return imageUrls; return imageUrls;
} }

View File

@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
@ConditionalOnExpression("'${cache.clean.enabled:false}'.equals('true')") @ConditionalOnExpression("'${cache.clean.enabled:false}'.equals('true')")
public class ShedulerClean { public class ShedulerClean {
private static final Logger LOGGER = LoggerFactory.getLogger(ShedulerClean.class); private final Logger logger = LoggerFactory.getLogger(ShedulerClean.class);
@Autowired @Autowired
private CacheService cacheService; private CacheService cacheService;
@ -27,9 +27,9 @@ public class ShedulerClean {
//默认每晚3点执行一次 //默认每晚3点执行一次
@Scheduled(cron = "${cache.clean.cron:0 0 3 * * ?}") @Scheduled(cron = "${cache.clean.cron:0 0 3 * * ?}")
public void clean() { public void clean() {
LOGGER.info("Cache clean start"); logger.info("Cache clean start");
cacheService.cleanCache(); cacheService.cleanCache();
DeleteFileUtil.deleteDirectory(fileDir); DeleteFileUtil.deleteDirectory(fileDir);
LOGGER.info("Cache clean end"); logger.info("Cache clean end");
} }
} }

View File

@ -427,7 +427,6 @@ public class ZipReader {
@Override @Override
public void run() { public void run() {
System.out.println("解析压缩文件开始《《《《《《《《《《《《《《《《《《《《《《《");
for (Map<String, ZipArchiveEntry> entryMap : entriesToBeExtracted) { for (Map<String, ZipArchiveEntry> entryMap : entriesToBeExtracted) {
String childName = entryMap.keySet().iterator().next(); String childName = entryMap.keySet().iterator().next();
ZipArchiveEntry entry = entryMap.values().iterator().next(); ZipArchiveEntry entry = entryMap.values().iterator().next();
@ -445,7 +444,6 @@ public class ZipReader {
if (new File(filePath).exists()) { if (new File(filePath).exists()) {
new File(filePath).delete(); new File(filePath).delete();
} }
System.out.println("解析压缩文件结束《《《《《《《《《《《《《《《《《《《《《《《");
} }

View File

@ -1,5 +1,6 @@
package cn.keking.web.controller; package cn.keking.web.controller;
import cn.keking.hutool.URLUtil;
import cn.keking.model.FileAttribute; import cn.keking.model.FileAttribute;
import cn.keking.service.FilePreview; import cn.keking.service.FilePreview;
import cn.keking.service.FilePreviewFactory; import cn.keking.service.FilePreviewFactory;
@ -30,7 +31,7 @@ import java.util.List;
@Controller @Controller
public class OnlinePreviewController { public class OnlinePreviewController {
private static final Logger LOGGER = LoggerFactory.getLogger(OnlinePreviewController.class); private final Logger logger = LoggerFactory.getLogger(OnlinePreviewController.class);
@Autowired @Autowired
private FilePreviewFactory previewFactory; private FilePreviewFactory previewFactory;
@ -52,22 +53,20 @@ public class OnlinePreviewController {
req.setAttribute("fileKey", req.getParameter("fileKey")); req.setAttribute("fileKey", req.getParameter("fileKey"));
model.addAttribute("officePreviewType", req.getParameter("officePreviewType")); model.addAttribute("officePreviewType", req.getParameter("officePreviewType"));
FilePreview filePreview = previewFactory.get(fileAttribute); FilePreview filePreview = previewFactory.get(fileAttribute);
logger.info("预览文件url{}previewType{}", url, fileAttribute.getType());
return filePreview.filePreviewHandle(url, model, fileAttribute); return filePreview.filePreviewHandle(url, model, fileAttribute);
} }
@RequestMapping(value = "/picturesPreview") @RequestMapping(value = "/picturesPreview")
public String picturesPreview(Model model, HttpServletRequest req) throws UnsupportedEncodingException { public String picturesPreview(Model model, HttpServletRequest req) {
String urls = req.getParameter("urls"); String urls = req.getParameter("urls");
String currentUrl = req.getParameter("currentUrl"); String currentUrl = req.getParameter("currentUrl");
// 路径转码 logger.info("预览文件url{}urls{}", currentUrl, urls);
String decodedUrl = URLDecoder.decode(urls, "utf-8"); String[] imgs = urls.split("\\|");
String decodedCurrentUrl = URLDecoder.decode(currentUrl, "utf-8");
// 抽取文件并返回文件列表
String[] imgs = decodedUrl.split("\\|");
List imgurls = Arrays.asList(imgs); List imgurls = Arrays.asList(imgs);
model.addAttribute("imgurls", imgurls); model.addAttribute("imgurls", imgurls);
model.addAttribute("currentUrl",decodedCurrentUrl); model.addAttribute("currentUrl", currentUrl);
return "picture"; return "picture";
} }
/** /**
@ -80,9 +79,9 @@ public class OnlinePreviewController {
@RequestMapping(value = "/getCorsFile", method = RequestMethod.GET) @RequestMapping(value = "/getCorsFile", method = RequestMethod.GET)
public void getCorsFile(String urlPath, HttpServletResponse resp) { public void getCorsFile(String urlPath, HttpServletResponse resp) {
InputStream inputStream = null; InputStream inputStream = null;
logger.info("下载跨域pdf文件url{}", urlPath);
try { try {
String strUrl = urlPath.trim(); URL url = new URL(URLUtil.normalize(urlPath, true));
URL url = new URL(new URI(strUrl).toASCIIString());
//打开请求连接 //打开请求连接
URLConnection connection = url.openConnection(); URLConnection connection = url.openConnection();
HttpURLConnection httpURLConnection = (HttpURLConnection) connection; HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
@ -93,8 +92,8 @@ public class OnlinePreviewController {
while (-1 != (len = inputStream.read(bs))) { while (-1 != (len = inputStream.read(bs))) {
resp.getOutputStream().write(bs, 0, len); resp.getOutputStream().write(bs, 0, len);
} }
} catch (IOException | URISyntaxException e) { } catch (IOException e) {
LOGGER.error("下载pdf文件失败", e); logger.error("下载跨域pdf文件异常url{}", urlPath, e);
} finally { } finally {
if (inputStream != null) { if (inputStream != null) {
IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(inputStream);
@ -109,6 +108,7 @@ public class OnlinePreviewController {
@GetMapping("/addTask") @GetMapping("/addTask")
@ResponseBody @ResponseBody
public String addQueueTask(String url) { public String addQueueTask(String url) {
logger.info("添加转码队列url{}", url);
cacheService.addQueueTask(url); cacheService.addQueueTask(url);
return "success"; return "success";
} }