|
@@ -0,0 +1,90 @@
|
|
|
|
|
+package com.common.workflow.web.rest;
|
|
|
|
|
+import com.common.workflow.service.util.FileUtils;
|
|
|
|
|
+import com.common.workflow.web.rest.vm.ExcelTemplateVM;
|
|
|
|
|
+import com.common.workflow.web.rest.vm.OilContractSumScoreVo;
|
|
|
|
|
+import com.common.workflow.web.rest.vm.OilContractSumScoreVo2;
|
|
|
|
|
+import com.common.workflow.web.rest.vm.WordTemplateVM;
|
|
|
|
|
+import com.github.crab2died.ExcelUtils;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Created by txz on 2020-10-15.
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/api/excel")
|
|
|
|
|
+public class ExcelResource {
|
|
|
|
|
+ private final Logger log = LoggerFactory.getLogger(ExcelResource.class);
|
|
|
|
|
+ public ExcelResource() { }
|
|
|
|
|
+ @PostMapping("/fill-excel")
|
|
|
|
|
+ public void fillExcelTemplate(@Valid @RequestBody ExcelTemplateVM wordTemplateVM, HttpServletResponse response) throws Exception {
|
|
|
|
|
+ response.reset();
|
|
|
|
|
+ response.setContentType("multipart/form-data;charset=utf-8");
|
|
|
|
|
+ response.setHeader("content-disposition", "attachment;filename=" + wordTemplateVM.getFileName());
|
|
|
|
|
+ response.setHeader("Pragma","No-cache");
|
|
|
|
|
+ response.setHeader ( "Cache-Control", "no-store");
|
|
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
+ response.setHeader("Access-Control-Allow-Headers", "*");
|
|
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
|
|
+ String fullFileName = FileUtils.getExcelTemplatePath() + "/" + wordTemplateVM.getFileName();
|
|
|
|
|
+
|
|
|
|
|
+ File file = new File(fullFileName);
|
|
|
|
|
+ if (file.exists()) {
|
|
|
|
|
+ file.delete(); //清除历史文件
|
|
|
|
|
+ }
|
|
|
|
|
+ fullFileName = FileUtils.downLoadFromUrl(wordTemplateVM.getTemplateUrl(), wordTemplateVM.getFileName(), FileUtils.getExcelTemplatePath());
|
|
|
|
|
+
|
|
|
|
|
+ if(wordTemplateVM.getContractClass().equals("03")){
|
|
|
|
|
+ List<OilContractSumScoreVo> reportList = new ArrayList<>();
|
|
|
|
|
+ ArrayList<LinkedHashMap<String,Object>> list = (ArrayList<LinkedHashMap<String,Object>>) wordTemplateVM.getDatas().get("data");
|
|
|
|
|
+ for(LinkedHashMap<String,Object> entry : list){
|
|
|
|
|
+
|
|
|
|
|
+ reportList.add(new OilContractSumScoreVo(entry.get("SupplierName").toString(),
|
|
|
|
|
+ entry.get("SumScore").toString(),entry.get("SumScore1").toString(),entry.get("SumScore2").toString(),
|
|
|
|
|
+ entry.get("SumScore3").toString(), entry.get("SumScore4").toString(),
|
|
|
|
|
+ entry.get("Conclusion").toString().equals("1") ? "是" : "",
|
|
|
|
|
+ entry.get("Conclusion").toString().equals("2") ? "是" : "",
|
|
|
|
|
+ entry.get("Conclusion").toString().equals("3") ? "是" : ""));
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, String> data = new HashMap<>();
|
|
|
|
|
+ data.put("title", "大港油田公司服务商考核评价表");
|
|
|
|
|
+
|
|
|
|
|
+ Date d = new Date();
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
|
|
+
|
|
|
|
|
+ data.put("info", sdf.format(d));
|
|
|
|
|
+ ExcelUtils.getInstance().exportObjects2Excel(fullFileName, 0, reportList, data, OilContractSumScoreVo.class, false, outputStream);
|
|
|
|
|
+
|
|
|
|
|
+ }else{
|
|
|
|
|
+ List<OilContractSumScoreVo2> reportList = new ArrayList<>();
|
|
|
|
|
+ ArrayList<LinkedHashMap<String,Object>> list = (ArrayList<LinkedHashMap<String,Object>>) wordTemplateVM.getDatas().get("data");
|
|
|
|
|
+ for(LinkedHashMap<String,Object> entry : list){
|
|
|
|
|
+ reportList.add(new OilContractSumScoreVo2(entry.get("SupplierName").toString(),
|
|
|
|
|
+ entry.get("SumScore").toString(),entry.get("SumScore1").toString(),entry.get("SumScore2").toString(),
|
|
|
|
|
+ entry.get("SumScore3").toString(), entry.get("SumScore4").toString(), entry.get("SumScore5").toString(),
|
|
|
|
|
+ entry.get("Conclusion").toString().equals("1") ? "是" : "",
|
|
|
|
|
+ entry.get("Conclusion").toString().equals("2") ? "是" : "",
|
|
|
|
|
+ entry.get("Conclusion").toString().equals("3") ? "是" : ""));
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, String> data = new HashMap<>();
|
|
|
|
|
+ data.put("title", "大港油田公司物资供应商考核评价表(全部、一级、二级)");
|
|
|
|
|
+ Date d = new Date();
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
|
|
+ data.put("info", sdf.format(d));
|
|
|
|
|
+ ExcelUtils.getInstance().exportObjects2Excel(fullFileName, 0, reportList, data, OilContractSumScoreVo2.class, false, outputStream);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ outputStream.flush();
|
|
|
|
|
+ outputStream.close();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|