|
@@ -1,5 +1,7 @@
|
|
|
package com.idea.invoice.service;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
@@ -21,21 +23,28 @@ import com.idea.paymentManagement.service.PayLogService;
|
|
|
import com.idea.util.DateUtils;
|
|
|
import com.idea.util.MoneyUtils;
|
|
|
import com.idea.util.ReplaceWord;
|
|
|
+import com.idea.util.WordToPdfUtil;
|
|
|
import com.rockstar.common.base.BaseService;
|
|
|
import com.rockstar.frame.model.extend.Tablepar;
|
|
|
import com.rockstar.shiro.util.ShiroUtils;
|
|
|
import com.rockstar.system.service.SysDictService;
|
|
|
import com.rockstar.util.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class ReceiptManageService implements BaseService<ReceiptManage, ReceiptManageExample> {
|
|
|
|
|
@@ -129,13 +138,13 @@ public class ReceiptManageService implements BaseService<ReceiptManage, ReceiptM
|
|
|
* @param model
|
|
|
* @return
|
|
|
*/
|
|
|
- public int add(ReceiptManage model,String userId) {
|
|
|
+ public int add(ReceiptManage model, String userId) {
|
|
|
|
|
|
if (model.getReceiptStatus() == null) {
|
|
|
// 默认 已开
|
|
|
model.setReceiptStatus(1);
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(userId)){
|
|
|
+ if (StringUtils.isEmpty(userId)) {
|
|
|
userId = ShiroUtils.getUserId();
|
|
|
}
|
|
|
model.setCreatedAt(new Date());
|
|
@@ -248,14 +257,14 @@ public class ReceiptManageService implements BaseService<ReceiptManage, ReceiptM
|
|
|
settingInfoData = new HashMap<>();
|
|
|
settingInfoData.put("leftOffset", "50");
|
|
|
settingInfoData.put("topOffset", "0");
|
|
|
- settingData.put("${seal}",settingInfoData);
|
|
|
+ settingData.put("${seal}", settingInfoData);
|
|
|
|
|
|
|
|
|
// 已换票 已红冲
|
|
|
if (receiptManage.getReceiptStatus() == 2 || receiptManage.getReceiptStatus() == 3) {
|
|
|
filePath = "/home/project/settleDown/tem/receipt_huanpiao.docx";
|
|
|
// 意向金收据 已换票的 用另一个模板
|
|
|
- if(receiptManage.getReceiptType().equals("1")){
|
|
|
+ if (receiptManage.getReceiptType().equals("1")) {
|
|
|
filePath = "/home/project/settleDown/tem/receipt_huanpiao_yxj.docx";
|
|
|
}
|
|
|
sealData.put("${huanpiao}", sealPath2);
|
|
@@ -263,11 +272,24 @@ public class ReceiptManageService implements BaseService<ReceiptManage, ReceiptM
|
|
|
settingInfoData = new HashMap<>();
|
|
|
settingInfoData.put("leftOffset", "300");
|
|
|
settingInfoData.put("topOffset", "0");
|
|
|
- settingData.put("${huanpiao}",settingInfoData);
|
|
|
+ settingData.put("${huanpiao}", settingInfoData);
|
|
|
|
|
|
}
|
|
|
|
|
|
- ReplaceWord.operateWord(response, filePath, fileName, data, picData, sealData, settingData);
|
|
|
+ try {
|
|
|
+ File tempWord = ReplaceWord.operateWord(response, filePath, filePath, data, picData, sealData, settingData);
|
|
|
+ File tempPDF = WordToPdfUtil.word2Pdf(tempWord);
|
|
|
+ response.setContentType("text/html;charset=UTF-8");
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName, "utf-8"));
|
|
|
+ OutputStream out = response.getOutputStream();
|
|
|
+ IoUtil.copy(FileUtil.getInputStream(tempPDF), out);
|
|
|
+ out.close();
|
|
|
+ tempWord.deleteOnExit();
|
|
|
+ tempPDF.deleteOnExit();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("文档生成报错:", e);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|