| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- package com.common.workflow.web.rest;
- import com.common.workflow.service.util.FileUtils;
- import com.common.workflow.web.rest.vm.*;
- 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();
- }
- @PostMapping("/contrast-excel")
- public void ContrastExcelTemplate(@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());
- Map<String, List<?>> classes = new HashMap<>();
- List<ContrastExcelVM> reportList = new ArrayList<>();
- List<ContrastExcelVM> reportList1 = new ArrayList<>();
- List<ContrastExcelVM> reportList2 = new ArrayList<>();
- ArrayList<LinkedHashMap<String,Object>> list = (ArrayList<LinkedHashMap<String,Object>>) wordTemplateVM.getDatas().get("data");
- for(LinkedHashMap<String,Object> entry : list){
- ContrastExcelVM contrastExcelVM = new ContrastExcelVM();
- contrastExcelVM.setSupplierName(entry.get("SupplierName").toString());
- contrastExcelVM.setInFlag(entry.get("InFlag").toString().equals("1") ? "准入" : entry.get("InFlag").toString().equals("2") ? "暂停" : "取消");
- contrastExcelVM.setAccessCardNo(entry.get("AccessCardNo").toString());
- contrastExcelVM.setSupplierTypeCode(entry.get("SupplierTypeCode").toString().equals("01") ? "物资类" : entry.get("SupplierTypeCode").toString().equals("02") ? "基建类" : "服务类");
- contrastExcelVM.setLegalPerson(entry.get("LegalPerson").toString());
- contrastExcelVM.setRegCapital(entry.get("RegCapital").toString());
- contrastExcelVM.setMobile(entry.get("Mobile").toString());
- contrastExcelVM.setSubCnt(entry.get("SubCnt").toString());
- contrastExcelVM.setNoSubCnt(entry.get("NoSubCnt").toString());
- contrastExcelVM.setOneTwoCount(entry.get("OneTwoCount").toString());
- contrastExcelVM.setTwoOneCount(entry.get("TwoOneCount").toString());
- contrastExcelVM.setChecked(entry.get("Checked").toString().equals("1") ? "否" : "是");
- if (entry.get("MinClassId").toString().equals("0")) {
- reportList2.add(contrastExcelVM);
- } else {
- if (entry.get("Checked").toString().equals("1")) {
- reportList.add(contrastExcelVM);
- } else {
- reportList1.add(contrastExcelVM);
- }
- }
- }
- classes.put("class_two", reportList);
- classes.put("class_one", reportList1);
- classes.put("class_three", reportList2);
- 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().exportObject2Excel(fullFileName, 0, classes, data, ContrastExcelVM.class, false, outputStream);
- outputStream.flush();
- outputStream.close();
- }
- }
|