|
@@ -1,205 +1,358 @@
|
|
|
-//package com.zglc.fm.schedule;
|
|
|
-//
|
|
|
-//
|
|
|
-//import com.zglc.fm.dao.AircraftTypeDao;
|
|
|
-//import com.zglc.fm.dao.DeviceDao;
|
|
|
-//import com.zglc.fm.dao.RepairManualDao;
|
|
|
-//import com.zglc.fm.entity.AircraftEntity;
|
|
|
-//import com.zglc.fm.entity.DeviceEntity;
|
|
|
-//import com.zglc.fm.entity.EquipmentEntity;
|
|
|
-//import com.zglc.fm.entity.RepairManualEntity;
|
|
|
-//import com.zglc.fm.exceptions.BusinessException;
|
|
|
-//import com.zglc.fm.utils.DocToPdf;
|
|
|
-//import com.zglc.fm.utils.ExcelUtils;
|
|
|
-//import com.zglc.fm.utils.FileTool;
|
|
|
-//import com.zglc.fm.utils.FileTypeUtil;
|
|
|
-//import org.apache.poi.ss.usermodel.Row;
|
|
|
-//import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-//import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-//import org.springframework.beans.factory.annotation.Value;
|
|
|
-//import org.springframework.context.annotation.Configuration;
|
|
|
-//import org.springframework.mock.web.MockMultipartFile;
|
|
|
-//import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-//import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-//import org.springframework.web.multipart.MultipartFile;
|
|
|
-//
|
|
|
-//import java.io.File;
|
|
|
-//import java.io.FileInputStream;
|
|
|
-//import java.io.IOException;
|
|
|
-//import java.text.SimpleDateFormat;
|
|
|
-//import java.util.*;
|
|
|
-//
|
|
|
-//@Configuration
|
|
|
-//@EnableScheduling
|
|
|
-//public class ScheduleTasks {
|
|
|
-//
|
|
|
-// private static final String sheetName = "sheet1";
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private AircraftDao aircraftDao;
|
|
|
-// @Autowired
|
|
|
-// private DeviceDao deviceDao;
|
|
|
-// @Autowired
|
|
|
-// private RepairManualDao repairManualDao;
|
|
|
-//
|
|
|
-// @Value("${spring.fault.sourcePath}")
|
|
|
-// private String sourcePath; //targetPath
|
|
|
-//
|
|
|
-// @Value("${spring.fault.uploadPath}")
|
|
|
-// private String uploadPath;
|
|
|
-//
|
|
|
-// @Scheduled(cron = "0/10 * * * * ?")
|
|
|
-// public void faultImport() {
|
|
|
-// readDirTargetContext();
|
|
|
-// deleteDir(new File(uploadPath));
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// private void readDirTargetContext() {
|
|
|
-// File file = new File(uploadPath);
|
|
|
-// if (file == null) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// File[] files = file.listFiles();
|
|
|
-// if (files == null || files.length == 0) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// for (File f : files) {
|
|
|
-// AircraftEntity aircraft = new AircraftEntity();
|
|
|
-// aircraft.setAircraft_type(f.getName());
|
|
|
-// SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
-// aircraft.setInput_time(date.format(new Date()));
|
|
|
-// aircraftDao.addNotExist(aircraft);
|
|
|
-// getAllDirName(f, f.getName());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// private void getAllDirName(File file, String type) {
|
|
|
-// String sourcePath1;
|
|
|
-// sourcePath1 = "d:\\source";
|
|
|
-// File[] files = file.listFiles();
|
|
|
-// boolean falg = false;
|
|
|
-// for (File f : files) {
|
|
|
-// DeviceEntity device = new DeviceEntity();
|
|
|
-// if (f.isDirectory()) {
|
|
|
-// falg = true;
|
|
|
-// device.setDevice_type(f.getName());
|
|
|
-// if (type != null) {
|
|
|
-// device.setAircraft_type(file.getName());
|
|
|
-// } else {
|
|
|
-// device.setParent(file.getName());
|
|
|
-// }
|
|
|
-// deviceDao.insertNotExists(device);
|
|
|
-// getAllDirName(f, null);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (!falg) {
|
|
|
-// Map<String, String> fileparams = new HashMap<>();
|
|
|
-// for (File f : files) {
|
|
|
-// if (f.getName().endsWith(ExcelUtils.DOC) || f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
-// MultipartFile mfile = transtTo(f);
|
|
|
-// String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
-// //转为pdf
|
|
|
-// DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
|
|
|
-// if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
-// filePath = filePath.replaceAll( "doc","pdf");
|
|
|
-// filePath = filePath.replaceAll( "d:","");
|
|
|
-// }
|
|
|
-// if (f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
-// filePath = filePath.replaceAll( "docx","pdf");
|
|
|
-// filePath = filePath.replaceAll( "d:","");
|
|
|
-// }
|
|
|
-//
|
|
|
-// String name = null;
|
|
|
-// if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
-// name = f.getName().replace(ExcelUtils.DOC, "");
|
|
|
-// } else {
|
|
|
-// name = f.getName().replace(ExcelUtils.DOCX, "");
|
|
|
-// }
|
|
|
-// System.out.println(f.getName());
|
|
|
-// fileparams.put(name, filePath);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// for (File f : files) {
|
|
|
-// if (f.getName().endsWith(ExcelUtils.XLS) || f.getName().endsWith(ExcelUtils.XLSX)) {
|
|
|
-// int id = deviceDao.getIdByType(file.getName());
|
|
|
-// String name = null;
|
|
|
-// if (f.getName().endsWith(ExcelUtils.XLS)) {
|
|
|
-// name = f.getName().replace(ExcelUtils.XLS, "");
|
|
|
-// } else {
|
|
|
-// name = f.getName().replace(ExcelUtils.XLSX, "");
|
|
|
-// }
|
|
|
-//
|
|
|
-// List<RepairManualEntity> list = getAllByFile(f, id, file.getName(), fileparams.get(name), name);
|
|
|
-// if (list != null && list.size() > 0) {
|
|
|
-// repairManualDao.addBatch(list);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// private List<RepairManualEntity> getAllByFile(File file, int id, String deviceType, String filePath, String name) {
|
|
|
-// Workbook wb = ExcelUtils.readExcel(file);
|
|
|
-// Sheet sheet = ExcelUtils.getSheet(wb, sheetName);
|
|
|
-// if (sheet == null || sheet.getLastRowNum() < 1) {
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// List<RepairManualEntity> list = new ArrayList<>();
|
|
|
-//// int rowNums = sheet.getLastRowNum();
|
|
|
-//// for (int i = 1; i<=1; i++) {
|
|
|
-//// RepairManualEntity repairManual = new RepairManualEntity();
|
|
|
-//// repairManual.setType(ExcelUtils.getCeilValue(sheet, i, 0));
|
|
|
-//// repairManual.setFault_describe(ExcelUtils.getCeilValue(sheet, i, 1));
|
|
|
-//// repairManual.setRepair_plan(ExcelUtils.getCeilValue(sheet, i, 2));
|
|
|
-//// repairManual.setDevice_id(id);
|
|
|
-//// repairManual.setDevice_type(deviceType);
|
|
|
-//// repairManual.setFile_path(filePath);
|
|
|
-//// list.add(repairManual);
|
|
|
-// RepairManualEntity repairManual = new RepairManualEntity();
|
|
|
-// repairManual.setDevice_id(id);
|
|
|
-// repairManual.setDevice_type(deviceType);
|
|
|
-// repairManual.setFile_path(filePath);
|
|
|
-// repairManual.setAircraft(ExcelUtils.getCeilValue(sheet, 0, 1));
|
|
|
-// repairManual.setManual_system(ExcelUtils.getCeilValue(sheet, 1, 1));
|
|
|
-// repairManual.setManual_number(Integer.parseInt(ExcelUtils.getCeilValue(sheet, 3, 1)));
|
|
|
-// repairManual.setType(name);
|
|
|
-// repairManual.setFault_describe(ExcelUtils.getCeilValue(sheet, 4, 1));
|
|
|
-// repairManual.setRepair_plan(ExcelUtils.getCeilValue(sheet, 5, 2));
|
|
|
-// list.add(repairManual);
|
|
|
-//
|
|
|
-//// }
|
|
|
-// try {
|
|
|
-// wb.close();
|
|
|
-// } catch (IOException e) {
|
|
|
-// throw new BusinessException("关闭文件错误!", e);
|
|
|
-// }
|
|
|
-// return list;
|
|
|
-// }
|
|
|
-//
|
|
|
-// private void deleteDir(File file) {
|
|
|
-// File[] files = file.listFiles();
|
|
|
-// if (files == null) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// for (File f : files) {
|
|
|
-// if (f.isDirectory()) {
|
|
|
-// deleteDir(f);
|
|
|
-// f.delete();
|
|
|
-// }
|
|
|
-// f.delete();
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// private MultipartFile transtTo(File file) {
|
|
|
-// MultipartFile mfile = null;
|
|
|
-// try {
|
|
|
-// FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
-// mfile = new MockMultipartFile(file.getName(), file.getName(), "text/plain", fileInputStream);
|
|
|
-// } catch (IOException e) {
|
|
|
-// throw new BusinessException("文件转换错误!", e);
|
|
|
-// }
|
|
|
-// return mfile;
|
|
|
-// }
|
|
|
-//}
|
|
|
+package com.zglc.fm.schedule;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import com.zglc.fm.entity.*;
|
|
|
+import com.zglc.fm.exceptions.BusinessException;
|
|
|
+import com.zglc.fm.service.*;
|
|
|
+import com.zglc.fm.utils.DocToPdf;
|
|
|
+import com.zglc.fm.utils.ExcelUtils;
|
|
|
+import com.zglc.fm.utils.FileTool;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Configuration
|
|
|
+@EnableScheduling
|
|
|
+public class ScheduleTasks {
|
|
|
+
|
|
|
+ @Value("${spring.fault.sourcePath}")
|
|
|
+ private String sourcePath; //targetPath
|
|
|
+
|
|
|
+ @Value("${spring.fault.uploadPath}")
|
|
|
+ private String uploadPath;
|
|
|
+
|
|
|
+ public ScheduleTasks(FaultService faultService, BookService bookService, CardService cardService, ManuelService manuelService, OutlineService outlineService) {
|
|
|
+ this.faultService = faultService;
|
|
|
+ this.bookService = bookService;
|
|
|
+ this.cardService = cardService;
|
|
|
+ this.manuelService = manuelService;
|
|
|
+ this.outlineService = outlineService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0/10 * * * * ?")
|
|
|
+ public void faultImport() {
|
|
|
+ readDirTargetContext();
|
|
|
+
|
|
|
+ }
|
|
|
+ @Resource
|
|
|
+ private final FaultService faultService;
|
|
|
+ private final BookService bookService;
|
|
|
+ private final CardService cardService;
|
|
|
+ private final ManuelService manuelService;
|
|
|
+ private final OutlineService outlineService;
|
|
|
+
|
|
|
+ private void readDirTargetContext() {
|
|
|
+ File file = new File(uploadPath);
|
|
|
+ if (file == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ if (files == null || files.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (File f : files) {
|
|
|
+ String na = f.getName();
|
|
|
+ if (na.equals("fault")){
|
|
|
+ getFault(f);
|
|
|
+ deleteDir(new File(uploadPath+"/fault"));
|
|
|
+ }
|
|
|
+ if (na.equals("book")){
|
|
|
+ getBook(f);
|
|
|
+ deleteDir(new File(uploadPath+"/book"));
|
|
|
+ }
|
|
|
+ if (na.equals("card")){
|
|
|
+ getCard(f);
|
|
|
+ deleteDir(new File(uploadPath+"/card"));
|
|
|
+ }
|
|
|
+ if (na.equals("manuel")){
|
|
|
+ getManuel(f);
|
|
|
+ deleteDir(new File(uploadPath+"/manuel"));
|
|
|
+ }
|
|
|
+ if (na.equals("outline")){
|
|
|
+ getOutline(f);
|
|
|
+ deleteDir(new File(uploadPath+"/outline"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getFault(File file) {
|
|
|
+ String sourcePath1;
|
|
|
+ sourcePath1 = "d:\\sourcefm";
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ Map<String, String> fileparams = new HashMap<>();
|
|
|
+ for (File f : files) {
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC) || f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ //转为pdf
|
|
|
+ DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ filePath = filePath.replaceAll( "doc","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ filePath = filePath.replaceAll( "docx","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ String name = null;
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOC, "");
|
|
|
+ } else {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOCX, "");
|
|
|
+ }
|
|
|
+ System.out.println(f.getName());
|
|
|
+// fileparams.put(name, filePath);
|
|
|
+ FaultEntity fault = new FaultEntity();
|
|
|
+ fault.setFault_name(name);
|
|
|
+ fault.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ fault.setInput_time(date.format(new Date()));
|
|
|
+ faultService.add(fault);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ FaultEntity fault = new FaultEntity();
|
|
|
+ fault.setFault_name(f.getName().replace( ".pdf",""));
|
|
|
+ fault.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ fault.setInput_time(date.format(new Date()));
|
|
|
+ faultService.add(fault);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getBook(File file) {
|
|
|
+ String sourcePath1;
|
|
|
+ sourcePath1 = "d:\\sourcefm";
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ Map<String, String> fileparams = new HashMap<>();
|
|
|
+ for (File f : files) {
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC) || f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ //转为pdf
|
|
|
+ DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ filePath = filePath.replaceAll( "doc","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ filePath = filePath.replaceAll( "docx","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ String name = null;
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOC, "");
|
|
|
+ } else {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOCX, "");
|
|
|
+ }
|
|
|
+ System.out.println(f.getName());
|
|
|
+// fileparams.put(name, filePath);
|
|
|
+ BookEntity book = new BookEntity();
|
|
|
+ book.setBook_name(name);
|
|
|
+ book.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ book.setInput_time(date.format(new Date()));
|
|
|
+ bookService.add(book);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ BookEntity book = new BookEntity();
|
|
|
+ book.setBook_name(f.getName().replace( ".pdf",""));
|
|
|
+ book.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ book.setInput_time(date.format(new Date()));
|
|
|
+ bookService.add(book);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getCard(File file) {
|
|
|
+ String sourcePath1;
|
|
|
+ sourcePath1 = "d:\\sourcefm";
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ Map<String, String> fileparams = new HashMap<>();
|
|
|
+ for (File f : files) {
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC) || f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ //转为pdf
|
|
|
+ DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ filePath = filePath.replaceAll( "doc","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ filePath = filePath.replaceAll( "docx","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ String name = null;
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOC, "");
|
|
|
+ } else {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOCX, "");
|
|
|
+ }
|
|
|
+ System.out.println(f.getName());
|
|
|
+// fileparams.put(name, filePath);
|
|
|
+ CardEntity card = new CardEntity();
|
|
|
+ card.setCard_name(name);
|
|
|
+ card.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ card.setInput_time(date.format(new Date()));
|
|
|
+ cardService.add(card);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ CardEntity card = new CardEntity();
|
|
|
+ card.setCard_name(f.getName().replace( ".pdf",""));
|
|
|
+ card.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ card.setInput_time(date.format(new Date()));
|
|
|
+ cardService.add(card);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getManuel(File file) {
|
|
|
+ String sourcePath1;
|
|
|
+ sourcePath1 = "d:\\sourcefm";
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ Map<String, String> fileparams = new HashMap<>();
|
|
|
+ for (File f : files) {
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC) || f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ //转为pdf
|
|
|
+ DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ filePath = filePath.replaceAll( "doc","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ filePath = filePath.replaceAll( "docx","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ String name = null;
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOC, "");
|
|
|
+ } else {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOCX, "");
|
|
|
+ }
|
|
|
+ System.out.println(f.getName());
|
|
|
+// fileparams.put(name, filePath);
|
|
|
+ ManuelEntity manuel = new ManuelEntity();
|
|
|
+ manuel.setManuel_name(name);
|
|
|
+ manuel.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ manuel.setInput_time(date.format(new Date()));
|
|
|
+ manuelService.add(manuel);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ ManuelEntity manuel = new ManuelEntity();
|
|
|
+ manuel.setManuel_name(f.getName().replace( ".pdf",""));
|
|
|
+ manuel.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ manuel.setInput_time(date.format(new Date()));
|
|
|
+ manuelService.add(manuel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getOutline(File file) {
|
|
|
+ String sourcePath1;
|
|
|
+ sourcePath1 = "d:\\sourcefm";
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ Map<String, String> fileparams = new HashMap<>();
|
|
|
+ for (File f : files) {
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC) || f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ //转为pdf
|
|
|
+ DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ filePath = filePath.replaceAll( "doc","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOCX)) {
|
|
|
+ filePath = filePath.replaceAll( "docx","pdf");
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ }
|
|
|
+ String name = null;
|
|
|
+ if (f.getName().endsWith(ExcelUtils.DOC)) {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOC, "");
|
|
|
+ } else {
|
|
|
+ name = f.getName().replace(ExcelUtils.DOCX, "");
|
|
|
+ }
|
|
|
+ System.out.println(f.getName());
|
|
|
+// fileparams.put(name, filePath);
|
|
|
+ OutlineEntity outline = new OutlineEntity();
|
|
|
+ outline.setOutline_name(name);
|
|
|
+ outline.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ outline.setInput_time(date.format(new Date()));
|
|
|
+ outlineService.add(outline);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MultipartFile mfile = transtTo(f);
|
|
|
+ String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
|
|
|
+ filePath = filePath.replaceAll( "d:","");
|
|
|
+ OutlineEntity outline = new OutlineEntity();
|
|
|
+ outline.setOutline_name(f.getName().replace( ".pdf",""));
|
|
|
+ outline.setFile_path(filePath);
|
|
|
+ SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
|
|
+ outline.setInput_time(date.format(new Date()));
|
|
|
+ outlineService.add(outline);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteDir(File file) {
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ if (files == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (File f : files) {
|
|
|
+ if (f.isDirectory()) {
|
|
|
+ deleteDir(f);
|
|
|
+ f.delete();
|
|
|
+ }
|
|
|
+ f.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private MultipartFile transtTo(File file) {
|
|
|
+ MultipartFile mfile = null;
|
|
|
+ try {
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
+ mfile = new MockMultipartFile(file.getName(), file.getName(), "text/plain", fileInputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new BusinessException("文件转换错误!", e);
|
|
|
+ }
|
|
|
+ return mfile;
|
|
|
+ }
|
|
|
+}
|