|
@@ -1,18 +1,31 @@
|
|
package com.fdkankan.sale.controller;
|
|
package com.fdkankan.sale.controller;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import com.fdkankan.sale.common.ResultData;
|
|
import com.fdkankan.sale.common.ResultData;
|
|
import com.fdkankan.sale.service.IPriceListService;
|
|
import com.fdkankan.sale.service.IPriceListService;
|
|
import com.fdkankan.sale.service.ISysUserService;
|
|
import com.fdkankan.sale.service.ISysUserService;
|
|
|
|
+import com.fdkankan.sale.service.impl.RepairInfoService;
|
|
import com.fdkankan.sale.util.MyExcelUtil;
|
|
import com.fdkankan.sale.util.MyExcelUtil;
|
|
|
|
+import com.fdkankan.sale.util.OrderListVo;
|
|
import com.fdkankan.sale.util.pdf.PdfUtil;
|
|
import com.fdkankan.sale.util.pdf.PdfUtil;
|
|
|
|
+import com.fdkankan.sale.util.pdf.PdfUtils;
|
|
|
|
+import com.fdkankan.sale.vo.response.PriceListExcelVo;
|
|
import com.itextpdf.text.DocumentException;
|
|
import com.itextpdf.text.DocumentException;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/test")
|
|
@RequestMapping("/test")
|
|
@@ -24,6 +37,8 @@ public class TestController {
|
|
PdfUtil pdfUtil;
|
|
PdfUtil pdfUtil;
|
|
@Autowired
|
|
@Autowired
|
|
IPriceListService priceListService;
|
|
IPriceListService priceListService;
|
|
|
|
+ @Autowired
|
|
|
|
+ RepairInfoService repairInfoService;
|
|
|
|
|
|
@GetMapping("/test1")
|
|
@GetMapping("/test1")
|
|
public ResultData test1(HttpServletResponse response) throws IOException, DocumentException {
|
|
public ResultData test1(HttpServletResponse response) throws IOException, DocumentException {
|
|
@@ -32,4 +47,70 @@ public class TestController {
|
|
return ResultData.ok();
|
|
return ResultData.ok();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 导出数据 生成pdf
|
|
|
|
+ *
|
|
|
|
+ * @param response
|
|
|
|
+ */
|
|
|
|
+ @GetMapping("/exportPdf")
|
|
|
|
+ public void exportPdf(@RequestParam(required = false) String repairId,HttpServletResponse response) {
|
|
|
|
+ // 模板路径
|
|
|
|
+ String tempPath = "G:\\templates\\pdf\\四维时代售后服务清单-模版.pdf";
|
|
|
|
+ //文字类
|
|
|
|
+ // dataMap中的key要和模板中的域名对应
|
|
|
|
+ OrderListVo orderListVo = repairInfoService.getExportVo(repairId);
|
|
|
|
+ Map<String, Object> dataMap = BeanUtil.beanToMap(orderListVo);
|
|
|
|
+ //图片
|
|
|
|
+ Map<String, Object> imgMap = BeanUtil.beanToMap(orderListVo.getPdfImg());
|
|
|
|
+ // imgMap中的key要和模板中的域名对应
|
|
|
|
+
|
|
|
|
+ //表格 一行数据是一个list
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ list.add("序号");
|
|
|
|
+ list.add("项目");
|
|
|
|
+ list.add("单价(元)");
|
|
|
|
+ list.add("数量");
|
|
|
|
+ list.add("总价(元)");
|
|
|
|
+ list.add("备注");
|
|
|
|
+
|
|
|
|
+ List<List<String>> partTableList = new ArrayList<>();
|
|
|
|
+ partTableList.add(list);
|
|
|
|
+ List<PriceListExcelVo> priceListExcelVos = orderListVo.getPriceListExcelVos();
|
|
|
|
+ for (PriceListExcelVo priceListExcelVo : priceListExcelVos) {
|
|
|
|
+ List<String> listVo = new ArrayList<>();
|
|
|
|
+ Map<String, Object> map = BeanUtil.beanToMap(priceListExcelVo);
|
|
|
|
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
|
+ listVo.add(entry.getValue().toString());
|
|
|
|
+ }
|
|
|
|
+ partTableList.add(listVo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, List<List<String>>> listMap = new HashMap<>();
|
|
|
|
+ // 这里的listMap中key要和模板中的域名对应
|
|
|
|
+ listMap.put("partTable", partTableList);
|
|
|
|
+
|
|
|
|
+ Map<String, Object> o = new HashMap<>();
|
|
|
|
+ o.put("tempPath", tempPath);
|
|
|
|
+ o.put("dataMap", dataMap);
|
|
|
|
+ o.put("imgMap", imgMap);
|
|
|
|
+ o.put("tableList", listMap);
|
|
|
|
+ try {
|
|
|
|
+ OutputStream out = response.getOutputStream();
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
+ response.setHeader("content-type", "application/octet-stream");
|
|
|
|
+
|
|
|
|
+ String fileName = URLEncoder.encode("pdf模板导出" + ".pdf", "UTF-8");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
|
+ try {
|
|
|
|
+ PdfUtils.creatPdf(o, out);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ out.flush();
|
|
|
|
+ out.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|