Commit 59ac8eff authored by 陈精华's avatar 陈精华 Committed by kl

优化:添加日志

parent 9cc02676
......@@ -56,24 +56,27 @@ public class FileConverQueueTask {
@Override
public void run() {
while (true) {
String url = null;
try {
String url = cacheService.takeQueueTask();
url = cacheService.takeQueueTask();
if(url != null){
FileAttribute fileAttribute = fileUtils.getFileAttribute(url);
logger.info("正在处理转换任务,文件名称【{}】",fileAttribute.getName());
FileType fileType=fileAttribute.getType();
if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)){
FilePreview filePreview=previewFactory.get(fileAttribute);
FileType fileType = fileAttribute.getType();
logger.info("正在处理预览转换任务,url:{},预览类型:{}", url, fileType);
if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)) {
FilePreview filePreview = previewFactory.get(fileAttribute);
filePreview.filePreviewHandle(url, new ExtendedModelMap(), fileAttribute);
} else {
logger.info("预览类型无需处理,url:{},预览类型:{}", url, fileType);
}
}
} catch (Exception e) {
try {
Thread.sleep(1000*10);
}catch (Exception ex){
} catch (Exception ex){
ex.printStackTrace();
}
e.printStackTrace();
logger.info("处理预览转换任务异常,url:{}", url, e);
}
}
}
......
......@@ -43,7 +43,7 @@ public class CadToPdf {
cadImage.close();
return true;
} catch (FileNotFoundException e) {
logger.error("PDFFileNotFoundException", e);
logger.error("PDFFileNotFoundException,inputFilePath:{}", inputFilePath, e);
return false;
}
}
......
......@@ -33,10 +33,7 @@ public class ConverterUtils {
private final Logger logger = LoggerFactory.getLogger(ConverterUtils.class);
// @Value("${office.home}")
// String officeHome;
// OpenOfficeConnection connection;
OfficeManager officeManager;
private OfficeManager officeManager;
@PostConstruct
public void initOfficeManager() {
......
......@@ -84,7 +84,7 @@ public class DownloadUtils {
}
return response;
} catch (IOException e) {
LOGGER.error("文件下载失败", e);
LOGGER.error("文件下载失败,url:{}", urlAddress, e);
response.setCode(1);
response.setContent(null);
if (e instanceof FileNotFoundException) {
......
......@@ -36,7 +36,7 @@ public class FileUtils {
String fileDir = ConfigConstants.getFileDir();
/**
* 已转换过的文件集合(redis缓存)
* 已转换过的文件集合(缓存)
* @return
*/
public Map<String, String> listConvertedFiles() {
......
......@@ -18,7 +18,7 @@ import java.util.List;
@Component
public class PdfUtils {
private final Logger LOGGER = LoggerFactory.getLogger(PdfUtils.class);
private final Logger logger = LoggerFactory.getLogger(PdfUtils.class);
@Autowired
FileUtils fileUtils;
......@@ -57,7 +57,7 @@ public class PdfUtils {
doc.close();
fileUtils.addConvertedPdfImage(pdfFilePath, pageCount);
} catch (IOException e) {
LOGGER.error("Convert pdf to jpg exception", e);
logger.error("Convert pdf to jpg exception, pdfFilePath:{}", pdfFilePath, e);
}
return imageUrls;
}
......
......@@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
@ConditionalOnExpression("'${cache.clean.enabled:false}'.equals('true')")
public class ShedulerClean {
private static final Logger LOGGER = LoggerFactory.getLogger(ShedulerClean.class);
private final Logger logger = LoggerFactory.getLogger(ShedulerClean.class);
@Autowired
private CacheService cacheService;
......@@ -27,9 +27,9 @@ public class ShedulerClean {
//默认每晚3点执行一次
@Scheduled(cron = "${cache.clean.cron:0 0 3 * * ?}")
public void clean() {
LOGGER.info("Cache clean start");
logger.info("Cache clean start");
cacheService.cleanCache();
DeleteFileUtil.deleteDirectory(fileDir);
LOGGER.info("Cache clean end");
logger.info("Cache clean end");
}
}
......@@ -427,7 +427,6 @@ public class ZipReader {
@Override
public void run() {
System.out.println("解析压缩文件开始《《《《《《《《《《《《《《《《《《《《《《《");
for (Map<String, ZipArchiveEntry> entryMap : entriesToBeExtracted) {
String childName = entryMap.keySet().iterator().next();
ZipArchiveEntry entry = entryMap.values().iterator().next();
......@@ -445,7 +444,6 @@ public class ZipReader {
if (new File(filePath).exists()) {
new File(filePath).delete();
}
System.out.println("解析压缩文件结束《《《《《《《《《《《《《《《《《《《《《《《");
}
......
package cn.keking.web.controller;
import cn.keking.hutool.URLUtil;
import cn.keking.model.FileAttribute;
import cn.keking.service.FilePreview;
import cn.keking.service.FilePreviewFactory;
......@@ -30,7 +31,7 @@ import java.util.List;
@Controller
public class OnlinePreviewController {
private static final Logger LOGGER = LoggerFactory.getLogger(OnlinePreviewController.class);
private final Logger logger = LoggerFactory.getLogger(OnlinePreviewController.class);
@Autowired
private FilePreviewFactory previewFactory;
......@@ -52,22 +53,20 @@ public class OnlinePreviewController {
req.setAttribute("fileKey", req.getParameter("fileKey"));
model.addAttribute("officePreviewType", req.getParameter("officePreviewType"));
FilePreview filePreview = previewFactory.get(fileAttribute);
logger.info("预览文件url:{},previewType:{}", url, fileAttribute.getType());
return filePreview.filePreviewHandle(url, model, fileAttribute);
}
@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 currentUrl = req.getParameter("currentUrl");
// 路径转码
String decodedUrl = URLDecoder.decode(urls, "utf-8");
String decodedCurrentUrl = URLDecoder.decode(currentUrl, "utf-8");
// 抽取文件并返回文件列表
String[] imgs = decodedUrl.split("\\|");
logger.info("预览文件url:{},urls:{}", currentUrl, urls);
String[] imgs = urls.split("\\|");
List imgurls = Arrays.asList(imgs);
model.addAttribute("imgurls", imgurls);
model.addAttribute("currentUrl",decodedCurrentUrl);
model.addAttribute("currentUrl", currentUrl);
return "picture";
}
/**
......@@ -80,9 +79,9 @@ public class OnlinePreviewController {
@RequestMapping(value = "/getCorsFile", method = RequestMethod.GET)
public void getCorsFile(String urlPath, HttpServletResponse resp) {
InputStream inputStream = null;
logger.info("下载跨域pdf文件url:{}", urlPath);
try {
String strUrl = urlPath.trim();
URL url = new URL(new URI(strUrl).toASCIIString());
URL url = new URL(URLUtil.normalize(urlPath, true));
//打开请求连接
URLConnection connection = url.openConnection();
HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
......@@ -93,8 +92,8 @@ public class OnlinePreviewController {
while (-1 != (len = inputStream.read(bs))) {
resp.getOutputStream().write(bs, 0, len);
}
} catch (IOException | URISyntaxException e) {
LOGGER.error("下载pdf文件失败", e);
} catch (IOException e) {
logger.error("下载跨域pdf文件异常,url:{}", urlPath, e);
} finally {
if (inputStream != null) {
IOUtils.closeQuietly(inputStream);
......@@ -109,6 +108,7 @@ public class OnlinePreviewController {
@GetMapping("/addTask")
@ResponseBody
public String addQueueTask(String url) {
logger.info("添加转码队列url:{}", url);
cacheService.addQueueTask(url);
return "success";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment