bc_zhang 4 سال پیش
والد
کامیت
ba52f31d17

+ 3 - 0
src/main/java/com/zglc/fm/FaultManagemnetApplication.java

@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import com.zglc.fm.utils.DocToPdf;
 import com.zglc.fm.utils.Ppt2ToPdf;
+import com.zglc.fm.utils.ExcelToPdf;
 
 
 @SpringBootApplication
@@ -16,6 +17,8 @@ public class FaultManagemnetApplication {
         SpringApplication.run(FaultManagemnetApplication.class, args);
         DocToPdf.loadLicense();
         Ppt2ToPdf.loadLicense();
+        ExcelToPdf.loadLicense();
+
 
     }
 

+ 41 - 0
src/main/java/com/zglc/fm/controller/BookController.java

@@ -95,6 +95,27 @@ public class BookController {
     }
 
 
+    @ApiOperation("导入教材缩略图")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @PostMapping("importImg")
+    public Result<Object> importImg(HttpServletRequest request, @RequestParam("file") MultipartFile file){
+        Date date = new Date();
+        String sourcePath1;
+
+        sourcePath1 = "d:\\sourcefm";
+        String filePath = FileTool.fileUp(file, sourcePath1, date.getTime() + file.getOriginalFilename());
+//        FileTypeUtil.Type fileType = FileTypeUtil.getFileType(file.getOriginalFilename());
+//        if (fileType == Type.JPEG) {
+//            filePath = filePath.replaceAll( "doc","pdf");
+//        }
+        filePath = filePath.replaceAll( "d:","");
+        return Result.success(filePath);
+    }
+
+
+
     @ApiOperation("列出所有")
     @ApiResponses({
             @ApiResponse(code = 0, message = "成功")
@@ -124,6 +145,16 @@ public class BookController {
         return Result.success(new PageInfo<>( faultService.searchAllFault(bookName)));
     }
 
+    @ApiOperation("筛选关键词相关书籍")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("relevantBook")
+    public Result<PageInfo<BookEntity>> relevantBook(String bookName,Integer page, Integer size) {
+        PageHelper.startPage(page, size, "id desc");
+        return Result.success(new PageInfo<>( bookService.findByName1(bookName)));
+    }
+
     @ApiOperation("ID查找")
     @ApiResponses({
             @ApiResponse(code = 0, message = "成功")
@@ -168,4 +199,14 @@ public class BookController {
         return Result.success(new PageInfo<>(bookService.getAllBook()));
     }
 
+    @ApiOperation("分页按专业名称筛选")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("searchByMajor")
+    public Result<PageInfo<BookEntity>> searchData(String majorType,String name,Integer page, Integer size) {
+        PageHelper.startPage(page, size, "id desc");
+        return Result.success(new PageInfo<>( bookService.searchByMajor(majorType,name)));
+    }
+
 }

+ 11 - 0
src/main/java/com/zglc/fm/controller/CardController.java

@@ -144,4 +144,15 @@ public class CardController {
         return Result.success(new PageInfo<>(cardService.getAllCard()));
     }
 
+    @ApiOperation("分页按专业名称筛选")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("searchByMajor")
+    public Result<PageInfo<CardEntity>> searchData(String majorType,String name,Integer page, Integer size) {
+        PageHelper.startPage(page, size, "id desc");
+        return Result.success(new PageInfo<>( cardService.searchByMajor(majorType,name)));
+    }
+
+
 }

+ 29 - 0
src/main/java/com/zglc/fm/schedule/ScheduleTasks.java

@@ -6,6 +6,7 @@ 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.ExcelToPdf;
 import com.zglc.fm.utils.ExcelUtils;
 import com.zglc.fm.utils.FileTool;
 import org.springframework.beans.factory.annotation.Value;
@@ -221,6 +222,34 @@ public class ScheduleTasks {
                 card.setInput_time(date.format(new Date()));
                 cardService.add(card);
             }
+            else if (f.getName().endsWith(ExcelUtils.XLS) || f.getName().endsWith(ExcelUtils.XLSX)) {
+                MultipartFile mfile = transtTo(f);
+                String filePath = FileTool.fileUp(mfile, sourcePath1, new Date().getTime() + f.getName());
+                //转为pdf
+                ExcelToPdf.convertExcel2Pdf(filePath, sourcePath1);
+                if (f.getName().endsWith(ExcelUtils.XLS))  {
+                    deleteDir1(new File(filePath));
+                    filePath = filePath.replaceAll( "xls","pdf");
+                }
+                if (f.getName().endsWith(ExcelUtils.XLSX))  {
+                    deleteDir1(new File(filePath));
+                    filePath = filePath.replaceAll( "xlsx","pdf");
+                }
+                filePath = filePath.replaceAll( "d:","");
+                String name = null;
+                if (f.getName().endsWith(ExcelUtils.XLS)) {
+                    name = f.getName().replace(ExcelUtils.XLS, "");
+                } else {
+                    name = f.getName().replace(ExcelUtils.XLSX, "");
+                }
+                System.out.println(f.getName());
+                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);

+ 24 - 0
src/main/java/com/zglc/fm/service/BookService.java

@@ -99,6 +99,13 @@ public class BookService {
         return Result.success(list);
     }
 
+    public List<BookEntity> findByName1(String name){
+        if (name == null ||"".equals(name)){
+            return  null;
+        }
+        return bookDao.findByName("%" + name + "%");
+    }
+
     public BookEntity getOutline(Integer id) {
         return bookDao.selectByPrimaryKey(id);
     }
@@ -127,6 +134,23 @@ public class BookService {
             return getAllBook();
     }
 
+    public List<BookEntity> searchByMajor(String majorType, String name) {
+        Example example = new Example(BookEntity.class);
+        Example.Criteria criteria = example.createCriteria();
+        if (majorType != null)
+            criteria.andEqualTo("major_type", majorType);
+        else
+            criteria.andIsNull("major_type");
+        if(name != null && !name.isEmpty())
+        {
+            criteria.andLike("book_name",name);
+        }
+        if (criteria.isValid())
+            return bookDao.selectByExample(example);
+        else
+            return getAllBook();
+    }
+
 
 
 

+ 19 - 0
src/main/java/com/zglc/fm/service/CardService.java

@@ -108,5 +108,24 @@ public class CardService {
         return cardDao.selectByExample(example);
     }
 
+    public List<CardEntity> searchByMajor(String majorType, String name) {
+        Example example = new Example(CardEntity.class);
+        Example.Criteria criteria = example.createCriteria();
+        if (majorType != null)
+            criteria.andEqualTo("major_type", majorType);
+        else
+            criteria.andIsNull("major_type");
+        if(name != null && !name.isEmpty())
+        {
+            criteria.andLike("card_name",name);
+        }
+        if (criteria.isValid())
+            return cardDao.selectByExample(example);
+        else
+            return getAllCard();
+    }
+
+
+
 
 }

+ 89 - 0
src/main/java/com/zglc/fm/utils/ExcelToPdf.java

@@ -0,0 +1,89 @@
+package com.zglc.fm.utils;
+
+import com.aspose.cells.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.List;
+
+public class ExcelToPdf {
+
+    public static void loadLicense() {
+        final InputStream is = DocToPdf.class.getClassLoader().getResourceAsStream("license.xml");
+        final License aposeLic = new License();
+        try {
+            aposeLic.setLicense(is);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static File convertExcel2Pdf(final String docPath, final String pdfLocal) {
+        FileUtils.mkDirIfNotExists(new File(pdfLocal));
+        final String nameWithoutExtension = FileUtils.getNameWithoutExtension(docPath);
+        final File docPdfFile = new File(pdfLocal + File.separator + nameWithoutExtension + ".pdf");
+        if (docPdfFile.exists() && docPdfFile.length() != 0L) {
+            return docPdfFile;
+        }
+        try {
+            InputStream fileInput = new FileInputStream(docPath);// 待处理的文件
+            Workbook wb = new Workbook(fileInput);
+            FileOutputStream fileOS = new FileOutputStream(docPdfFile.getPath());
+
+            wb.save(fileOS, SaveFormat.PDF);
+            return docPdfFile;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+
+//    public String LogExport(List<LogEntity> logs) throws Exception {
+//
+//        Workbook workbook = new Workbook();
+//        WorksheetCollection worksheets = workbook.getWorksheets();
+//        Worksheet worksheet = worksheets.get(0);
+//        Cells cells = worksheet.getCells();
+//
+//        //设置标题样式
+//        Style HeaderStyle = workbook.createStyle();
+//        HeaderStyle.getFont().setBold(true);  //文字加粗
+//        HeaderStyle.setName("宋体");  //文字字体
+//        HeaderStyle.getFont().setSize(13);  //文字大小
+//        HeaderStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
+//        HeaderStyle.setTextWrapped(true);//单元格内容自动换行
+//
+//        //设置内容样式
+//        Style cellsStyle = workbook.createStyle();
+//        cellsStyle.setHorizontalAlignment(TextAlignmentType.CENTER);  //居中
+//        HeaderStyle.setName("宋体");  //文字字体
+//        HeaderStyle.getFont().setSize(12);  //文字大小
+//        cellsStyle.setTextWrapped(true);//单元格内容自动换行
+//
+//        for (int i = 0; i < 10; i++) {
+//            cells.get(0, i).setValue("标题" + (i+1));
+//            cells.get(0, i).setStyle(HeaderStyle);
+//            cells.setRowHeight(0,25);
+//            cells.setColumnWidth(i,25);
+//        }
+//
+//        for (int i = 0; i < 10; i++) {
+//            cells.get(1, i).setValue("哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈");
+//            cells.get(1, i).setStyle(cellsStyle);
+//            cells.setRowHeight(i, 20);
+//            cells.setColumnWidth(i, 38);
+//        }
+//
+//        String filename = "xxxxxx.xlsx";
+//        try {
+//
+//            workbook.save(filename, SaveFormat.XLSX);
+//        } catch (Exception ex) {
+//            ex.printStackTrace();
+//        }
+//        return filename;
+//    }
+}

+ 2 - 2
src/main/resources/application-dev.yml

@@ -1,8 +1,8 @@
 spring:
 
   datasource:
-    #url: jdbc:mysql://180.76.52.24:3306/fault_management?userUnicode=ture&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
-    url: jdbc:mysql://127.0.0.1:3306/fault_management?userUnicode=ture&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
+    url: jdbc:mysql://180.76.52.24:3306/fault_management?userUnicode=ture&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
+#    url: jdbc:mysql://127.0.0.1:3306/fault_management?userUnicode=ture&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
 
     username: root