|
@@ -1,16 +1,26 @@
|
|
|
package com.ruoyi.project.invoice.controller;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
+import com.deepoove.poi.data.Texts;
|
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
|
+import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
+import com.ruoyi.framework.config.RuoYiConfig;
|
|
|
import com.ruoyi.framework.security.LoginUser;
|
|
|
import com.ruoyi.framework.security.service.TokenService;
|
|
|
import com.ruoyi.project.invoice.domain.TInvoiceContractor;
|
|
|
import com.ruoyi.project.invoice.domain.TInvoiceWorkcontent;
|
|
|
import com.ruoyi.project.invoice.service.ITInvoiceContractorService;
|
|
|
import com.ruoyi.project.invoice.service.ITInvoiceWorkcontentService;
|
|
|
+import io.jsonwebtoken.lang.Assert;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -157,4 +167,50 @@ public class TInvoiceBookingworkticketController extends BaseController
|
|
|
{
|
|
|
return toAjax(tInvoiceBookingworkticketService.deleteTInvoiceBookingworkticketByIds(ids));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取word数据
|
|
|
+ */
|
|
|
+ public Map<String, Object> getWordData (TInvoiceBookingworkticket ticket){
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ // 渲染文本
|
|
|
+ params.put("contact", Texts.of(ticket.getContact().toString()).fontSize(12).bold().create());
|
|
|
+
|
|
|
+ return params;
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author lsc
|
|
|
+ * @param templatePath word模板文件路径
|
|
|
+ * @param fileDir 生成的文件存放地址
|
|
|
+ * @param fileName 生成的文件名
|
|
|
+ * @param paramMap 参数集合
|
|
|
+ * @return 返回word生成的路径
|
|
|
+ */
|
|
|
+ public String createWord(String templatePath, String fileDir, String fileName, Map<String, Object> paramMap) throws IOException {
|
|
|
+ Assert.notNull(templatePath, "word模板文件路径不能为空");
|
|
|
+ Assert.notNull(fileDir, "生成的文件存放地址不能为空");
|
|
|
+ Assert.notNull(fileName, "生成的文件名不能为空");
|
|
|
+ File dir = new File(fileDir);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ logger.info("目录不存在,创建文件夹{}!", fileDir);
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ String filePath = fileDir +"/"+ fileName;
|
|
|
+ logger.info("目录{}!", filePath);
|
|
|
+ // 读取模板渲染参数
|
|
|
+ InputStream is = getClass().getClassLoader().getResourceAsStream(templatePath);
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(is).render(paramMap);
|
|
|
+ try {
|
|
|
+ // 将模板参数写入路径
|
|
|
+ template.writeToFile(filePath);
|
|
|
+ template.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("生成word异常{}", e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String pathFileName = FileUploadUtils.getPathFileName(RuoYiConfig.getFilePath("/"+ "ticketWord"), fileName);
|
|
|
+ return pathFileName;
|
|
|
+ }
|
|
|
}
|