Administrator 1 rok pred
rodič
commit
b60ef62fda

+ 2 - 2
ruoyi-admin/src/main/resources/ueditor-config.json

@@ -8,8 +8,8 @@
   "imageCompressEnable": true, /* 是否压缩图片,默认是true */
   "imageCompressBorder": 1600, /* 图片压缩最长边限制 */
   "imageInsertAlign": "none", /* 插入的图片浮动方式 */
-  "imageUrlPrefix": "", /* 图片访问路径前缀 */
-  "imagePathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
+  "imageUrlPrefix": "/", /* 图片访问路径前缀 */
+  "imagePathFormat": "/home/ruoyi/uploadPath/upload/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
   /* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
   /* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
   /* {time} 会替换成时间戳 */

+ 41 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InvestigateDispositionTableServiceImpl.java

@@ -88,7 +88,7 @@ public class InvestigateDispositionTableServiceImpl implements IInvestigateDispo
             ajax.put("fileName", fileName);
             ajax.put("newFileName", FileUtils.getName(fileName));
             ajax.put("originalFilename", file.getOriginalFilename());
-            investigateDispositionTable.setUrl(url);
+            investigateDispositionTable.setUrl(fileName);
             html.delete();
         } catch (IOException e) {
             e.printStackTrace();
@@ -109,6 +109,46 @@ public class InvestigateDispositionTableServiceImpl implements IInvestigateDispo
     public int updateInvestigateDispositionTable(InvestigateDispositionTable investigateDispositionTable)
     {
 
+        String filePathOld = investigateDispositionTable.getUrl();
+        //获取HTML文件
+        String content = investigateDispositionTable.getContent();
+        content = " <meta charset=\"utf-8\">" +content;
+        try {
+            // 上传文件路径
+            String filePath = RuoYiConfig.getUploadPath();
+            String fileNameHtml = UUID.randomUUID().toString();
+            File html = File.createTempFile(fileNameHtml, ".html",new File(filePath));
+            BufferedWriter writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (html,true),StandardCharsets.UTF_8));
+            writer.write(content);
+            writer.close();
+            InputStream inputStream = new FileInputStream(html);
+            MultipartFile file = new org.springframework.mock.web.MockMultipartFile(html.getName(),html.getName(),"text/html",inputStream);
+
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = investigateDispositionTable.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("url", url);
+            ajax.put("fileName", fileName);
+            ajax.put("newFileName", FileUtils.getName(fileName));
+            ajax.put("originalFilename", file.getOriginalFilename());
+            investigateDispositionTable.setUrl(fileName);
+            html.delete();
+            File fileOld = new File(filePathOld);
+
+            if (fileOld.exists()) {
+                if (fileOld.delete()) {
+                    System.out.println("文件删除成功!");
+                } else {
+                    System.out.println("文件删除失败!");
+                }
+            } else {
+                System.out.println("文件不存在!");
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        System.out.println("文件生成成功!");
         return investigateDispositionTableMapper.updateInvestigateDispositionTable(investigateDispositionTable);
     }
 

+ 1 - 1
ruoyi-system/src/main/resources/mapper/system/InvestigateDispositionTableMapper.xml

@@ -72,7 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update investigate_disposition_table
         <trim prefix="SET" suffixOverrides=",">
             <if test="investigateDispositionId != null">investigate_disposition_id = #{investigateDispositionId},</if>
-            <if test="investigate_table_id != null">investigate_table_id = #{investigateTableId},</if>
+            <if test="investigateTableId != null">investigate_table_id = #{investigateTableId},</if>
             <if test="url != null">url = #{url},</if>
             <if test="title != null">title = #{title},</if>
             <if test="content != null">content = #{content},</if>