From ee98daf76231cb373d20803dfa1a309fefd82644 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期四, 27 十一月 2025 23:33:07 +0800
Subject: [PATCH] 修改了对应代码

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java |  232 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 185 insertions(+), 47 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
index a38294e..beff88c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
@@ -2,8 +2,14 @@
 
 
 
+import java.awt.*;
 import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
@@ -16,22 +22,20 @@
 import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.common.utils.file.FileUtils;
+import com.ruoyi.domain.ArchiveCategory;
+import com.ruoyi.domain.ArchiveRecords;
 import com.ruoyi.domain.DocumentMaterials;
+import com.ruoyi.domain.vo.DocumentMaterialFileSmallVo;
 import com.ruoyi.framework.config.ServerConfig;
+import com.ruoyi.framework.web.domain.server.Sys;
 import com.ruoyi.service.IDocumentMaterialsService;
 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
 import org.apache.commons.imaging.ImageInfo;
 import org.apache.commons.imaging.Imaging;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -45,7 +49,7 @@
 import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;
 
 /**
- * 銆愯濉啓鍔熻兘鍚嶇О銆慍ontroller
+ * 銆愭枃浠舵潗鏂欑患鍚堜俊鎭�慍ontroller
  *
  * @author ruoyi
  * @date 2025-07-28
@@ -60,34 +64,68 @@
     @Autowired
     private IDocumentMaterialsService documentMaterialsService;
 
+
     /**
-     * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛�
+     * 鍒ゆ柇PageNumber鏄惁杩炵画
+     */
+    @PreAuthorize("@ss.hasPermi('system:materials:list')")
+    @GetMapping("/isPageNubLegal/{recordId}")
+    public AjaxResult judgePageLegal(@PathVariable("recordId") Integer recordId)
+    {
+
+        boolean res = documentMaterialsService.isPageNumberIslegal(recordId);
+        int cnt = documentMaterialsService.getFileCount(recordId);
+        HashMap<String, Object> data = new HashMap<>();
+        data.put("res",res);
+        data.put("total",cnt);
+        return AjaxResult.success(data);
+    }
+    /**
+     * 鎷垮埌闄や簡鍏跺畠绫诲瀷鏉愭枡鐨勪釜鏁�
+     */
+    @PreAuthorize("@ss.hasPermi('system:materials:list')")
+    @GetMapping("/getFileCount/{recordId}")
+    public AjaxResult getFileCount(@PathVariable("recordId") Integer recordId)
+    {
+
+        int cnt = documentMaterialsService.getFileCount(recordId);
+        return AjaxResult.success(cnt);
+    }
+    /**
+     * 鏌ヨ銆愭枃浠舵潗鏂欑患鍚堜俊鎭�戝垪琛�
      */
     @PreAuthorize("@ss.hasPermi('system:materials:list')")
     @GetMapping("/list")
     public AjaxResult list(DocumentMaterials documentMaterials)
     {
-
         Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
         Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
         return documentMaterialsService.selectDataList(documentMaterials, pageNum, pageSize);
     }
 
     /**
-     * 瀵煎嚭銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛�
+     * 瀵煎嚭銆愭枃浠舵潗鏂欑患鍚堜俊鎭�戝垪琛�
      */
     @PreAuthorize("@ss.hasPermi('system:materials:export')")
-    @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.EXPORT)
+    @Log(title = "銆愭枃浠舵潗鏂欑患鍚堜俊鎭��", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, DocumentMaterials documentMaterials)
+    public void export(HttpServletResponse response, DocumentMaterials documentMaterials, @RequestParam(value = "ids", required = false) Long[] ids)
     {
-        List<DocumentMaterials> list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials);
+        List<DocumentMaterials> list;
+        System.out.println(ids);
+        // 濡傛灉鎻愪緵浜唅ds鍙傛暟锛屽垯鏍规嵁ids瀵煎嚭鎸囧畾璁板綍
+        if (ids != null && ids.length > 0) {
+            list = documentMaterialsService.selectDocumentMaterialsByIds(ids);
+        } else {
+            list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials);
+
+        }
         ExcelUtil<DocumentMaterials> util = new ExcelUtil<DocumentMaterials>(DocumentMaterials.class);
-        util.exportExcel(response, list, "銆愯濉啓鍔熻兘鍚嶇О銆戞暟鎹�");
+        util.exportExcel(response, list, "銆愭枃浠舵潗鏂欑患鍚堜俊鎭�戞暟鎹�");
     }
 
     /**
-     * 鑾峰彇銆愯濉啓鍔熻兘鍚嶇О銆戣缁嗕俊鎭�
+     * 鑾峰彇銆愭枃浠舵潗鏂欑患鍚堜俊鎭�戣缁嗕俊鎭�
      */
     @PreAuthorize("@ss.hasPermi('system:materials:query')")
     @GetMapping(value = "/{materialId}")
@@ -97,10 +135,10 @@
     }
 
     /**
-     * 鏂板銆愯濉啓鍔熻兘鍚嶇О銆�
+     * 鏂板銆愭枃浠舵潗鏂欑患鍚堜俊鎭��
      */
     @PreAuthorize("@ss.hasPermi('system:materials:add')")
-    @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.INSERT)
+    @Log(title = "銆愭枃浠舵潗鏂欑患鍚堜俊鎭��", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody DocumentMaterials documentMaterials)
     {
@@ -110,12 +148,12 @@
     }
 
     /**
-     * 淇敼銆愯濉啓鍔熻兘鍚嶇О銆�
+     * 淇敼銆愭枃浠舵潗鏂欑患鍚堜俊鎭��
      *
      * system:materials:edit
      */
     @PreAuthorize("@ss.hasPermi('system:materials:edit')")
-    @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.UPDATE)
+    @Log(title = "銆愭枃浠舵潗鏂欑患鍚堜俊鎭��", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody DocumentMaterials documentMaterials)
     {
@@ -123,10 +161,10 @@
     }
 
     /**
-     * 鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆�
+     * 鍒犻櫎銆愭枃浠舵潗鏂欑患鍚堜俊鎭��
      */
     @PreAuthorize("@ss.hasPermi('system:materials:remove')")
-    @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.DELETE)
+    @Log(title = "銆愭枃浠舵潗鏂欑患鍚堜俊鎭��", businessType = BusinessType.DELETE)
     @DeleteMapping("/{materialIds}")
     public AjaxResult remove(@PathVariable String[] materialIds)
     {
@@ -147,8 +185,8 @@
             return "A0";
     }
 
-    @PostMapping("/upload")
-    public AjaxResult uploadFile(MultipartFile file) throws Exception
+    @PostMapping("/upload/{recordId}")
+    public AjaxResult uploadFile(MultipartFile file, @PathVariable Long recordId) throws Exception
     {
         // System.out.println("sdfd9999999999999999999999999999999");
         try
@@ -167,30 +205,112 @@
             //鍒嗗壊鏂囦欢鍚�
             String [] nams = fname.split("\\.");
             Long nam = Long.parseLong(nams[0]);
-            //鏂囦欢鍚嶇О
-            String pname = nams[1];
-            ajax.put("url", url);
-            //鎷垮埌鍥惧儚灞炴��
-            BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
-            int wid = bufferedImage.getWidth();
-            int hei = bufferedImage.getHeight();
-            double sz =  Double.parseDouble(String.format("%.2f", file.getSize()*1.0/1024));
-            System.out.println(wid+":"+hei+":"+sz);
-            //鎷垮埌鍥惧儚鐨刣pi淇℃伅
+            //鏍规嵁椤靛彿鎷垮埌妗堝嵎鐨勮缁嗕俊鎭�
+            System.out.println("0-------------");
+            System.out.println(recordId);
+            DocumentMaterials doc = documentMaterialsService.selectByPageNumber(nam, Math.toIntExact(recordId));
+            if(doc==null)
+                return AjaxResult.error("鏃犲搴旈〉鍙凤紝璇锋鏌ユ竻妤氶檮浠朵互鍙婂搴旂殑杈撳叆锛�");
+            else{
+                if(doc.getSecurityLevel().equals("璇ラ〉鍙﹀瓨"))
+                {
 
-            ImageInfo info = Imaging.getImageInfo(file.getBytes());
+                    //鏇挎崲涓轰簡鍑嗗濂界殑鍥惧儚
+                    //璇诲彇鏈嶅姟鍣ㄤ笂鐨勫浘鍍�
+                 //   new InputStream();
+                    String fp = filePath + "\\glc.jpg";
+                    Path path = Paths.get(fp);
+                    File fil = new File(fp);
+                    //鎷垮埌鍥惧儚灞炴��
+                    BufferedImage bufferedImage =   ImageIO.read(Files.newInputStream(path));
+                    int wid = bufferedImage.getWidth();
+                    int hei = bufferedImage.getHeight();
+                    double sz =  Double.parseDouble(String.format("%.2f", Files.size(path)*1.0/1024));
+                    System.out.println("ddsdsdsd");
+                    System.out.println(wid+":"+hei+":"+sz);
+
+                    //鎷垮埌鍥惧儚鐨刣pi淇℃伅
+
+                    ImageInfo info = Imaging.getImageInfo(Files.readAllBytes(path));
 
 
-            int wdpi = info.getPhysicalWidthDpi() ;
-            int hdpi = info.getPhysicalHeightDpi();
-            System.out.println("DPI: " + info.getPhysicalWidthDpi());
-            //璁$畻fileNumber
-            Long fileNumber = documentMaterialsService.getFiNum(nam);
-            //璁$畻sizeType
-            String sizeType = getPageSize(wid*hei);
-            //鎻掑叆鏁版嵁搴撳搴旂殑url褰撲腑
-            documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber,wid, hei,wdpi, hdpi,  sz, fileName, pname);
-//            System.out.println(url);
+                    int wdpi = info.getPhysicalWidthDpi() ;
+                    int hdpi = info.getPhysicalHeightDpi();
+                    System.out.println("DPI: " + info.getPhysicalWidthDpi());
+                    //璁$畻fileNumber
+                    Long fileNumber = documentMaterialsService.getFiNum(nam,recordId);
+                    //璁$畻sizeType
+                    String sizeType = getPageSize(wid*hei);
+
+
+                    Graphics2D g2d = bufferedImage.createGraphics(); // 鑾峰彇Graphics2D瀵硅薄鐢ㄤ簬缁樺埗
+                    g2d.setFont(new Font("Arial", Font.BOLD, 80)); // 璁剧疆瀛椾綋鏍峰紡鍜屽ぇ灏�
+                    g2d.setColor(Color.black); // 璁剧疆瀛椾綋棰滆壊涓虹櫧鑹诧紝鍙牴鎹渶瑕佽皟鏁撮鑹插拰瀛椾綋鏍峰紡
+                    String pageNumber =      doc.getPageNumber()+""; // 椤电爜瀛楃涓诧紝鍙互鏍规嵁闇�瑕佷慨鏀规垨鍔ㄦ�佺敓鎴�
+                    int fontHeight = g2d.getFontMetrics().getHeight(); // 鑾峰彇瀛椾綋楂樺害锛岀敤浜庡畾浣嶆枃鏈綅缃�
+                    int x = bufferedImage.getWidth() - g2d.getFontMetrics().stringWidth(pageNumber) - 80; // 璁$畻鏂囨湰X鍧愭爣浣嶇疆锛岀‘淇濆湪鍙充笅瑙掗檮杩�
+                    int y = bufferedImage.getHeight() - fontHeight / 2 - 100; // 璁$畻鏂囨湰Y鍧愭爣浣嶇疆锛屽瀭鐩村眳涓樉绀烘枃鏈�
+                    g2d.drawString(pageNumber, x, y); // 鍦ㄥ浘鐗囦笂缁樺埗椤电爜鏂囨湰
+
+
+                    System.out.println(pageNumber+"[[[[[[[[[[[[[[[");
+                    g2d.dispose(); // 閲婃斁Graphics2D璧勬簮
+//                    File outputFile = new File(filePath+"/output_image.jpg"); // 杈撳嚭鏂囦欢璺緞
+//                    ImageIO.write(bufferedImage, "jpg", outputFile); // 淇�
+                    //寰楀埌BufferedImage瀵硅薄
+                    MultipartFile multipartFile = null;
+                    try {
+                        //鍒涘缓涓�涓狟yteArrayOutputStream
+                        ByteArrayOutputStream os = new ByteArrayOutputStream();
+                        //鎶夿ufferedImage鍐欏叆ByteArrayOutputStream
+                        ImageIO.write(bufferedImage, "jpg", os);
+                        //ByteArrayOutputStream杞垚InputStream
+                        InputStream input = new ByteArrayInputStream(os.toByteArray());
+                        //InputStream杞垚MultipartFile
+                        multipartFile = new MockMultipartFile(pageNumber, pageNumber+".jpg", "text/plain", input);
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+
+                    // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О
+                    String fileName1 = FileUploadUtils.upload(filePath, multipartFile);
+                    String url1 = serverConfig.getUrl() + fileName;
+
+
+                    String us = "/profile/upload/0071.jpg";
+                    documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber,wid, hei,wdpi, hdpi,  sz, fileName1, "jpg", recordId);
+
+
+                }
+                else
+                {
+                    //鏂囦欢鍚嶇О
+                    String pname = nams[1];
+                    ajax.put("url", url);
+                    //鎷垮埌鍥惧儚灞炴��
+                    BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
+                    int wid = bufferedImage.getWidth();
+                    int hei = bufferedImage.getHeight();
+                    double sz =  Double.parseDouble(String.format("%.2f", file.getSize()*1.0/1024));
+                    System.out.println(wid+":"+hei+":"+sz);
+                    //鎷垮埌鍥惧儚鐨刣pi淇℃伅
+
+                    ImageInfo info = Imaging.getImageInfo(file.getBytes());
+
+
+                    int wdpi = info.getPhysicalWidthDpi() ;
+                    int hdpi = info.getPhysicalHeightDpi();
+                    System.out.println("DPI: " + info.getPhysicalWidthDpi());
+                    //璁$畻fileNumber
+                    Long fileNumber = documentMaterialsService.getFiNum(nam, recordId);
+                    //璁$畻sizeType
+                    String sizeType = getPageSize(wid*hei);
+                    //鎻掑叆鏁版嵁搴撳搴旂殑url褰撲腑
+                    documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber,wid, hei,wdpi, hdpi,  sz, fileName, pname, recordId);
+//
+                }
+            }
+           System.out.println(url);
 //            System.out.println(fileName);
             ajax.put("fileName", fileName);
 //            System.out.println(FileUtils.getName(fileName));
@@ -204,4 +324,22 @@
             return AjaxResult.error(e.getMessage());
         }
     }
+
+
+    @Log(title = "妗f璇︾粏淇℃伅璁板綍瀵煎叆", businessType = BusinessType.IMPORT)
+    @PostMapping("/importData")
+    public AjaxResult importData(@RequestParam("file") MultipartFile file, @RequestParam("recordId")String recordId) throws Exception
+    {
+        System.out.println(file);
+        return documentMaterialsService.importExcel(file, recordId);
+    }
+
+    @PostMapping("/model")
+    public void getExportModel(HttpServletResponse response){
+        List<DocumentMaterialFileSmallVo> list = Collections.singletonList(new DocumentMaterialFileSmallVo());
+        ExcelUtil<DocumentMaterialFileSmallVo> util = new ExcelUtil<>(DocumentMaterialFileSmallVo.class);
+        util.exportExcel(response,list,"妗f璇︾粏淇℃伅瀵煎叆妯℃澘");
+    }
+
+    //瀵煎嚭material
 }

--
Gitblit v1.9.1