Browse Source

PDF导出调整

anderx 1 year ago
parent
commit
396052cdeb

+ 77 - 0
src/main/java/com/goafanti/common/utils/pdf/PDFUtils.java

@@ -2,6 +2,7 @@ package com.goafanti.common.utils.pdf;
 
 import com.goafanti.RD.bo.OutWordRdDetails;
 import com.goafanti.common.utils.excel.FileUtils;
+import com.goafanti.expenseAccount.bo.MainExpenseAccount;
 import com.itextpdf.text.*;
 import com.itextpdf.text.pdf.BaseFont;
 import com.itextpdf.text.pdf.PdfWriter;
@@ -87,6 +88,11 @@ public class PDFUtils {
         return font;
     }
 
+    public static Font getFont(int size){
+        Font font =setFont(size,Font.NORMAL);
+        return font;
+    }
+
 
     /**
      *
@@ -107,4 +113,75 @@ public class PDFUtils {
 
         return font;
     }
+
+    public void pushMainExpenseExport(MainExpenseAccount mainExpenseAccount,HttpServletResponse response, String uploadPath) {
+        String title = "报销明细表";
+        String attName = String.format("报销明细表_%s.pdf",new Date().getTime());
+        String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".pdf";
+
+        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+        Document document=new Document();
+        try {
+            FileUtils.setAttachmentResponseHeader(response, title,attName);
+            FileOutputStream outputStream = new FileOutputStream(realFileName);
+            PdfWriter.getInstance(document, outputStream);
+            document.open();
+            Paragraph paragraph = new Paragraph(title, getTitleFont());
+            paragraph.setAlignment(1);
+            document.add(paragraph);
+            //默认算60
+            pushExpenseTitle(document,mainExpenseAccount);
+
+            document.close();
+            outputStream.close();
+//            FileUtils.writeBytes(realFileName, response.getOutputStream());
+//            FileUtils.deleteFile(realFileName);
+        } catch (DocumentException e) {
+            e.printStackTrace();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+     private static String   CHECKNO="报销编号:";
+     private static String   APPLYDEP="申请部门:";
+     private static String   ANAME="报销人:";
+     private static String   CREATETIME="报销日期:";
+     private static String   REMARKS="报销事由:";
+     private static String   BANK_ACCOUNT="收款方式:";
+    private void pushExpenseTitle(Document document, MainExpenseAccount mainExpenseAccount) throws DocumentException {
+
+        int  x= CHECKNO.length() + mainExpenseAccount.getCheckNo().length()/2 +
+                APPLYDEP.length() + mainExpenseAccount.getApplyDepName().length() +
+                ANAME.length() + mainExpenseAccount.getAname().length();
+        StringBuilder builder = new StringBuilder();
+        if (x>55){
+            builder.append(CHECKNO).append(mainExpenseAccount.getCheckNo()).append("  ")
+                    .append(APPLYDEP).append(mainExpenseAccount.getApplyDepName()).append(" ")
+                    .append(ANAME).append(mainExpenseAccount.getAname());
+        }else {
+            int y =(60-x);
+            StringBuilder blank= new StringBuilder();
+            for (int i = 0; i < y; i++) {
+                blank.append(" ");
+            }
+            builder.append(CHECKNO).append(mainExpenseAccount.getCheckNo()).append(blank)
+                    .append(APPLYDEP).append(mainExpenseAccount.getApplyDepName()).append(blank)
+                    .append(ANAME).append(mainExpenseAccount.getAname());
+        }
+        Paragraph tile1=new Paragraph(builder.toString(),getFont(8));
+        document.add(tile1);
+
+
+        String str2=String.format("报销日期:%s   报销事由:%s  收款方式:%s",
+                mainExpenseAccount.getCreateTimeStr(),mainExpenseAccount.getRemarks(),
+                mainExpenseAccount.getBank() + " " + mainExpenseAccount.getAccounts() + " " +
+                        mainExpenseAccount.getName());
+        Paragraph tile2=new Paragraph(str2,getFont(8));
+        tile2.setAlignment(1);
+        document.add(tile2);
+    }
+
 }

+ 19 - 0
src/main/java/com/goafanti/expenseAccount/controller/ExpenseAccountController.java

@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.List;
@@ -346,6 +347,24 @@ public class ExpenseAccountController extends CertifyApiController {
         return res.data(expenseAccountService.mainExpense(id));
     }
 
+
+
+    /**
+     * 主报销详情导出PDF,未完待续
+     */
+    @RequestMapping(value = "/mainExpenseExport",method = RequestMethod.GET)
+    public Result mainExpenseExport(Integer id, HttpServletResponse response){
+        Result res =new Result();
+        if (id==null){
+            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"合并编号"));
+            return  res;
+        }
+        return res.data(expenseAccountService.mainExpenseExport(id,response));
+    }
+
+
+
+
     /**
      * 修改主报销
      */

+ 3 - 0
src/main/java/com/goafanti/expenseAccount/service/ExpenseAccountService.java

@@ -4,6 +4,7 @@ import com.goafanti.common.model.ExpenseAccount;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.expenseAccount.bo.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.List;
 
@@ -74,4 +75,6 @@ public interface ExpenseAccountService {
     Object updateTypeOther(Integer id, String typeOther,String remarks,String orderNo);
 
     Object updateDetailsTypeOther(Integer id, String typeOther);
+
+    Object mainExpenseExport(Integer id, HttpServletResponse response);
 }

+ 10 - 0
src/main/java/com/goafanti/expenseAccount/service/impl/ExpenseAccountServiceImpl.java

@@ -13,6 +13,7 @@ import com.goafanti.common.error.BusinessException;
 import com.goafanti.common.model.*;
 import com.goafanti.common.utils.*;
 import com.goafanti.common.utils.excel.NewExcelUtil;
+import com.goafanti.common.utils.pdf.PDFUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.JDBCIdGenerator;
 import com.goafanti.core.mybatis.page.Pagination;
@@ -30,6 +31,7 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -430,6 +432,14 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
         return expenseAccountDetailsMapper.updateByPrimaryKeySelective(in);
     }
 
+    @Override
+    public Object mainExpenseExport(Integer id, HttpServletResponse response) {
+        MainExpenseAccount mainExpenseAccount = mainExpense(id);
+        PDFUtils pdfUtils = new PDFUtils();
+        pdfUtils.pushMainExpenseExport(mainExpenseAccount,response,uploadPath);
+        return null;
+    }
+
 
     private void pushResettingDebit(InputExpenseAccount in, Integer debitId) {
         ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(debitId);

+ 2 - 2
src/main/resources/props/config_local.properties

@@ -51,8 +51,8 @@ yxjl_max=100
 
 amb.maxLvl=6
 
-static.host=//static.jishutao.com/1.3.09
-#static.host=//172.16.1.187/1.3.09
+#static.host=//static.jishutao.com/1.3.09
+static.host=//172.16.1.187/1.3.10
 #avatar.host=//172.16.0.255:3000
 #static.host=//172.16.0.255:3000/1.2.62
 avatar.host=//static.jishutao.com