浏览代码

个贷意见书撰写

wucl 1 年之前
父节点
当前提交
bfe0dcba1c

+ 15 - 0
biz-base/src/main/java/com/dayou/controller/BusinessProductionController.java

@@ -1,9 +1,11 @@
 package com.dayou.controller;
 
 import com.dayou.common.RestResponse;
+import com.dayou.dto.NameUrlDTO;
 import com.dayou.dto.OrderProductionsBag;
 import com.dayou.dto.OrderReportDTO;
 import com.dayou.dto.ReportDTO;
+import com.dayou.service.IBusinessProductionService;
 import com.dayou.service.IMajorProductionService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +28,9 @@ public class BusinessProductionController {
     @Autowired
     private IMajorProductionService majorProductionService;
 
+    @Autowired
+    private IBusinessProductionService businessProductionService;
+
     /**
      * 大中型产品包
      */
@@ -75,4 +80,14 @@ public class BusinessProductionController {
         return RestResponse.data(ret);
     }
 
+    /**
+     * 产品加盖公章
+     * @param nameUrlDTO
+     * @return
+     */
+    @PostMapping("/doStamp")
+    public RestResponse<Boolean> addPublicStamp(@RequestBody NameUrlDTO nameUrlDTO){
+        Boolean ret = businessProductionService.addPublicStamp(nameUrlDTO.getUrl());
+        return RestResponse.data(ret);
+    }
 }

+ 23 - 0
biz-base/src/main/java/com/dayou/controller/PersonalProductionController.java

@@ -1,11 +1,15 @@
 package com.dayou.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.dayou.annotation.IgnoreAuth;
 import com.dayou.common.BaseEntity;
+import com.dayou.common.DownloadModel;
+import com.dayou.dto.NameUrlDTO;
 import com.dayou.entity.BusinessReply;
 import com.dayou.entity.PersonalProduction;
 import com.dayou.exception.ErrorCode;
+import com.dayou.utils.HttpKit;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,7 +19,9 @@ import com.dayou.common.RestResponse;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static com.dayou.exception.ErrorCode.DEFAULTERROR;
 
@@ -82,5 +88,22 @@ public class PersonalProductionController extends BaseController {
         Boolean ret = personalProductionService.removeFile(id);
         return RestResponse.data(ret);
     }
+
+    @GetMapping("/downloadPkg/{targetId}")
+    public void downloadPkg(@PathVariable("targetId") Long targetId) throws IOException {
+        List<PersonalProduction> productions = personalProductionService.list(new LambdaQueryWrapper<PersonalProduction>().
+                select(PersonalProduction::getFilePath).isNotNull(PersonalProduction::getFilePath).
+                eq(PersonalProduction::getTargetId,targetId).eq(BaseEntity::getDeleted,Boolean.FALSE));
+        List<DownloadModel> downloadModels = productions.stream().map(x -> {
+            DownloadModel downloadModel = new DownloadModel();
+            NameUrlDTO nameUrl = JSON.parseObject(x.getFilePath(), NameUrlDTO.class);
+            downloadModel.setDownloadUrl(nameUrl.getUrl());
+            downloadModel.setNewFileName(nameUrl.getName());
+            return downloadModel;
+        }).collect(Collectors.toList());
+        String newFileName = downloadModels.get(0).getNewFileName();
+        String orderId = newFileName.substring(0, 10);
+        packageFile2Zip(orderId+"产品包", HttpKit.getResponse(), downloadModels);
+    }
 }
 

二进制
biz-base/src/main/resources/static/image/stamp.png


+ 102 - 0
biz-base/src/test/java/rich/DocxTest.java

@@ -0,0 +1,102 @@
+package rich;
+
+import com.dayou.BaseApplication;
+import com.dayou.controller.BaseController;
+import com.dayou.enums.UnitEnum;
+import com.dayou.utils.FileUploadUtils;
+import com.dayou.utils.PersonalUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.util.Units;
+import org.apache.poi.xwpf.usermodel.*;
+import org.apache.xmlbeans.XmlException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
+import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
+import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.io.*;
+import java.util.List;
+
+import static com.dayou.common.Constants.DOCX;
+
+/**
+ * 类说明:
+ *
+ * @author: wucl
+ * @since: 2024/4/1
+ * created with IntelliJ IDEA.
+ */
+@Slf4j
+@SpringBootTest(classes = BaseApplication.class)
+@RunWith(SpringJUnit4ClassRunner.class)
+public class DocxTest extends BaseController implements ResourceLoaderAware {
+
+    private ResourceLoader resourceLoader;
+
+    @Test
+    public void genStamp(){
+        try {
+            InputStream inputStream = new FileInputStream("G:\\upload\\2024\\03\\29\\2024030016结果报告.docx");
+            Resource resource = resourceLoader.getResource("classpath:static/image/stamp.png");
+            PersonalUtils.addPublicStamp(inputStream,resource,"G:\\upload\\2024\\04\\01\\2024030016结果报告.docx");
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public void setResourceLoader(ResourceLoader resourceLoader) {
+            this.resourceLoader = resourceLoader;
+    }
+
+    /**
+     * @param ctGraphicalObject 图片数据
+     * @param deskFileName      图片描述
+     * @param width             宽
+     * @param height            高
+     * @param leftOffset        水平偏移 left
+     * @param topOffset         垂直偏移 top
+     * @param behind            文字上方,文字下方
+     * @return
+     * @throws Exception
+     */
+    public static CTAnchor getAnchorWithGraphic(CTGraphicalObject ctGraphicalObject,
+                                                String deskFileName, int width, int height,
+                                                int leftOffset, int topOffset, boolean behind) {
+        System.out.println(">>width>>"+width+"; >>height>>>>"+height);
+        String anchorXML =
+                "<wp:anchor xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" "
+                        + "simplePos=\"0\" relativeHeight=\"0\" behindDoc=\"" + ((behind) ? 1 : 0) + "\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
+                        + "<wp:simplePos x=\"0\" y=\"0\"/>"
+                        + "<wp:positionH relativeFrom=\"column\">"
+                        + "<wp:posOffset>" + leftOffset + "</wp:posOffset>"
+                        + "</wp:positionH>"
+                        + "<wp:positionV relativeFrom=\"paragraph\">"
+                        + "<wp:posOffset>" + topOffset + "</wp:posOffset>" +
+                        "</wp:positionV>"
+                        + "<wp:extent cx=\"" + width + "\" cy=\"" + height + "\"/>"
+                        + "<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>"
+                        + "<wp:wrapNone/>"
+                        + "<wp:docPr id=\"1\" name=\"Drawing 0\" descr=\"" + deskFileName + "\"/><wp:cNvGraphicFramePr/>"
+                        + "</wp:anchor>";
+
+        CTDrawing drawing = null;
+        try {
+            drawing = CTDrawing.Factory.parse(anchorXML);
+        } catch (XmlException e) {
+            e.printStackTrace();
+        }
+        CTAnchor anchor = drawing.getAnchorArray(0);
+        anchor.setGraphic(ctGraphicalObject);
+        return anchor;
+    }
+
+}

+ 26 - 0
common/src/main/java/com/dayou/controller/BaseController.java

@@ -86,4 +86,30 @@ public class BaseController {
         util.exportExcel2HttpResponse(datas, filename, outputStream, options);
     }
 
+    protected void packageFile2Zip(String zipName, HttpServletResponse response, List<? extends SimpleDownloadModel> downloadModels)throws IOException {
+        String fileName = URLEncoder.encode(zipName, "UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".zip");
+        File zipTmpFile = FileUtil.file(dfsConfig.getPath() + "\\" + RandomUtil.randomString(32) + ".zip");
+        List<File> fileList = new ArrayList<>();
+        for (SimpleDownloadModel simpleDownloadModel : downloadModels) {
+            try {
+                String url = simpleDownloadModel.getUrl();
+                if (StrUtil.isNotBlank(url)) {
+                    File old = FileUtil.file("/opt"+url);
+//                    File old = FileUtil.file(url);
+                    fileList.add(old);
+                }
+            } catch (Exception e) {
+                log.error("导出zip错误 ", e);
+            }
+        }
+        File[] files = ArrayUtil.toArray(fileList, File.class);
+
+        ZipUtil.zip(zipTmpFile, true, files);
+
+        ServletOutputStream outputStream = response.getOutputStream();
+        IoUtil.copy(FileUtil.getInputStream(zipTmpFile), outputStream);
+
+        zipTmpFile.delete();
+    }
 }

+ 10 - 3
common/src/main/java/com/dayou/utils/DateUtils.java

@@ -476,10 +476,17 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         }
     }
 
+    public static Boolean checkIsDate(String chineseDate){
+        try {
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD_C);
+            simpleDateFormat.parse(chineseDate);
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
 //    public static void main(String[]agrs){
-//        LocalDateTime parse = LocalDateTime.parse("2024-02-29T16:00:00.000Z", DateTimeFormatter.ofPattern(TZ));
-//        String ret = format(parse, YYYY_MM_C);
-//        System.out.println(ret);
+//        Boolean aBoolean = checkIsDate("2024年年032月22日");
 //    }
     /**
      * 月份差

+ 113 - 0
common/src/main/java/com/dayou/utils/PersonalUtils.java

@@ -3,8 +3,23 @@ package com.dayou.utils;
 import com.alibaba.fastjson.JSON;
 import com.dayou.dto.ItemData;
 import com.dayou.entity.PersonalExample;
+import com.dayou.exception.ErrorCode;
 import com.dayou.vo.CompareExampleItemVO;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.util.Units;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
+import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
+import org.springframework.core.io.Resource;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -194,4 +209,102 @@ public class PersonalUtils {
     }
 
 
+    /**
+     * 添加公章
+     * @param inputStream 需要盖章的文件流
+     * @param resource   公章图片资源
+     * @param originFilePath 原文件路经
+     */
+    public static void addPublicStamp(InputStream inputStream,Resource resource,String originFilePath){
+        try {
+            XWPFDocument document = new XWPFDocument(inputStream);
+            XWPFRun targetRun = stampingPoint(document,1);
+            if (targetRun == null){
+                targetRun = stampingPoint(document,13);
+                if(targetRun == null){
+                    return;
+                }
+            }
+            targetRun.addPicture(resource.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, "stamp.png", Units.toEMU(150), Units.toEMU(150));
+            CTDrawing drawing = targetRun.getCTR().getDrawingArray(0);
+            CTGraphicalObject graphic = drawing.getInlineArray(0).getGraphic();
+            //拿到新插入的图片替换添加CTAnchor 设置浮动属性 删除inline属性
+            CTAnchor anchor = getAnchorWithGraphic(graphic, "stamp",
+                    Units.toEMU(150), Units.toEMU(150),//图片大小
+                    Units.toEMU(260), Units.toEMU(-90), true);//相对当前段落位置 需要计算段落已有内容的左偏移
+            drawing.setAnchorArray(new CTAnchor[]{anchor});//添加浮动属性
+            drawing.removeInline(0);//删除行内属性
+
+            File absoluteFile = new File(originFilePath);
+            FileOutputStream out = new FileOutputStream(absoluteFile);
+            document.write(out);
+            out.close();
+            inputStream.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } catch (InvalidFormatException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static XWPFRun stampingPoint( XWPFDocument document,int point) throws IOException {
+        List<XWPFParagraph> paragraphs = document.getParagraphs();
+        XWPFParagraph paragraph = paragraphs.get(paragraphs.size() - point);
+        List<XWPFRun> runs = paragraph.getRuns();
+        XWPFRun targetRun = null;
+        if (runs.size()>0){
+            targetRun = runs.get(runs.size() - 1);
+            if (targetRun.getEmbeddedPictures().size()==0){
+                if (DateUtils.checkIsDate(targetRun.toString())){
+                    return targetRun;
+                }
+            }else {
+                ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"文件已加盖公章.");
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @param ctGraphicalObject 图片数据
+     * @param deskFileName      图片描述
+     * @param width             宽
+     * @param height            高
+     * @param leftOffset        水平偏移 left
+     * @param topOffset         垂直偏移 top
+     * @param behind            文字上方,文字下方
+     * @return
+     * @throws Exception
+     */
+    private static CTAnchor getAnchorWithGraphic(CTGraphicalObject ctGraphicalObject,
+                                                String deskFileName, int width, int height,
+                                                int leftOffset, int topOffset, boolean behind) {
+        System.out.println(">>width>>"+width+"; >>height>>>>"+height);
+        String anchorXML =
+                "<wp:anchor xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" "
+                        + "simplePos=\"0\" relativeHeight=\"0\" behindDoc=\"" + ((behind) ? 1 : 0) + "\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
+                        + "<wp:simplePos x=\"0\" y=\"0\"/>"
+                        + "<wp:positionH relativeFrom=\"column\">"
+                        + "<wp:posOffset>" + leftOffset + "</wp:posOffset>"
+                        + "</wp:positionH>"
+                        + "<wp:positionV relativeFrom=\"paragraph\">"
+                        + "<wp:posOffset>" + topOffset + "</wp:posOffset>" +
+                        "</wp:positionV>"
+                        + "<wp:extent cx=\"" + width + "\" cy=\"" + height + "\"/>"
+                        + "<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>"
+                        + "<wp:wrapNone/>"
+                        + "<wp:docPr id=\"1\" name=\"Drawing 0\" descr=\"" + deskFileName + "\"/><wp:cNvGraphicFramePr/>"
+                        + "</wp:anchor>";
+
+        CTDrawing drawing = null;
+        try {
+            drawing = CTDrawing.Factory.parse(anchorXML);
+        } catch (XmlException e) {
+            e.printStackTrace();
+        }
+        CTAnchor anchor = drawing.getAnchorArray(0);
+        anchor.setGraphic(ctGraphicalObject);
+        return anchor;
+    }
+
 }

+ 13 - 0
service/src/main/java/com/dayou/service/IBusinessProductionService.java

@@ -0,0 +1,13 @@
+package com.dayou.service;
+
+/**
+ * 类说明:
+ *
+ * @author: wucl
+ * @since: 2024/4/1
+ * created with IntelliJ IDEA.
+ */
+public interface IBusinessProductionService{
+
+    Boolean addPublicStamp(String filePath);
+}

+ 50 - 0
service/src/main/java/com/dayou/service/impl/BusinessProductionServiceImpl.java

@@ -0,0 +1,50 @@
+package com.dayou.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.dayou.service.IBusinessProductionService;
+import com.dayou.utils.PersonalUtils;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.stereotype.Service;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * 类说明:
+ *
+ * @author: wucl
+ * @since: 2024/4/1
+ * created with IntelliJ IDEA.
+ */
+@Service
+public class BusinessProductionServiceImpl implements IBusinessProductionService, ResourceLoaderAware {
+
+    private ResourceLoader resourceLoader;
+
+    @Override
+    public void setResourceLoader(ResourceLoader resourceLoader) {
+        this.resourceLoader = resourceLoader;
+    }
+
+    @Override
+    public Boolean addPublicStamp(String filePath) {
+        try {
+            if (StrUtil.isNotBlank(filePath)){
+                InputStream inputStream = new FileInputStream(filePath);
+                Resource resource = resourceLoader.getResource("classpath:static/image/stamp.png");
+                PersonalUtils.addPublicStamp(inputStream,resource,filePath);
+                inputStream.close();
+                return Boolean.TRUE;
+            }
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return Boolean.FALSE;
+    }
+}