Browse Source

市场管理:资质配置导出

baichengfei 4 years ago
parent
commit
c4f6568d0f

+ 41 - 0
src/main/java/com/common/workflow/web/rest/ExcelResource.java

@@ -1,4 +1,7 @@
 package com.common.workflow.web.rest;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.common.workflow.service.util.FileUtils;
 import com.common.workflow.web.rest.vm.*;
 import com.github.crab2died.ExcelUtils;
@@ -12,6 +15,7 @@ import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.File;
 import java.io.OutputStream;
+import java.lang.reflect.Type;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -157,4 +161,41 @@ public class ExcelResource {
         outputStream.flush();
         outputStream.close();
     }
+
+    @PostMapping("/aptitude-excel")
+    public void exportAptitudeConfig(@Valid @RequestBody ExcelTemplateAptitudeConfigVM aptitudeConfigVM, HttpServletResponse response) throws Exception {
+        response.reset();
+        response.setContentType("multipart/form-data;charset=utf-8");
+        response.setHeader("content-disposition", "attachment;filename=" + aptitudeConfigVM.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() + "/" + aptitudeConfigVM.getFileName();
+
+        File file = new File(fullFileName);
+
+        if (file.exists()) {
+            file.delete(); //清除历史文件
+        }
+
+        fullFileName = FileUtils.downLoadFromUrl(aptitudeConfigVM.getTemplateUrl(), aptitudeConfigVM.getFileName(), FileUtils.getExcelTemplatePath());
+
+        if (aptitudeConfigVM.getSupplierType().equals("1")) {
+            // 物资类
+        } else if (aptitudeConfigVM.getSupplierType().equals("2")) {
+            // 服务类
+            String obj = JSONObject.toJSONString(aptitudeConfigVM.getDataList().get("data"));
+            List<TechSrcAptitudeVo> list = JSONArray.parseArray(obj, TechSrcAptitudeVo.class);
+            Map<String, String> data = new HashMap<>();
+            data.put("title", "大港油田公司服务准入项目所需资质、资料明细表");
+            ExcelUtils.getInstance().exportObjects2Excel(fullFileName, 0, list, data, TechSrcAptitudeVo.class, false, outputStream);
+        } else {
+            log.info("其他导出");
+        }
+
+        outputStream.flush();
+        outputStream.close();
+    }
 }

+ 56 - 0
src/main/java/com/common/workflow/web/rest/vm/ExcelTemplateAptitudeConfigVM.java

@@ -0,0 +1,56 @@
+package com.common.workflow.web.rest.vm;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ExcelTemplateAptitudeConfigVM {
+    /**
+     * 资质类型 1物资类 2服务类 3基建类
+     */
+    private String supplierType;
+    /**
+     * 资质配置表数据
+     */
+    private Map<String, Object> dataList = new HashMap<>();
+
+    /**
+     * 模板路径
+     */
+    private String templateUrl;
+    /**
+     * 文件名称
+     */
+    private String fileName;
+
+    public String getSupplierType() {
+        return supplierType;
+    }
+
+    public void setSupplierType(String supplierType) {
+        this.supplierType = supplierType;
+    }
+
+    public String getTemplateUrl() {
+        return templateUrl;
+    }
+
+    public void setTemplateUrl(String templateUrl) {
+        this.templateUrl = templateUrl;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public Map<String, Object> getDataList() {
+        return dataList;
+    }
+
+    public void setDataList(Map<String, Object> dataList) {
+        this.dataList = dataList;
+    }
+}

+ 136 - 0
src/main/java/com/common/workflow/web/rest/vm/TechSrcAptitudeVo.java

@@ -0,0 +1,136 @@
+package com.common.workflow.web.rest.vm;
+
+import com.github.crab2died.annotation.ExcelField;
+
+public class TechSrcAptitudeVo {
+    /**
+     * 一级编码
+     */
+    @ExcelField(title = "一级编码", order = 1)
+    private String code1;
+    /**
+     * 一级编码名称
+     */
+    @ExcelField(title = "一级编码名称", order = 2)
+    private String name1;
+    /**
+     * 二级编码
+     */
+    @ExcelField(title = "二级编码", order = 3)
+    private String code2;
+    /**
+     * 二级编码名称
+     */
+    @ExcelField(title = "二级编码名称", order = 4)
+    private String name2;
+    /**
+     * 三级编码
+     */
+    @ExcelField(title = "三级编码", order = 5)
+    private String code3;
+    /**
+     * 三级编码名称
+     */
+    @ExcelField(title = "三级编码名称", order = 6)
+    private String name3;
+    /**
+     * 四级编码
+     */
+    @ExcelField(title = "四级编码", order = 7)
+    private String code4;
+    /**
+     * 四级编码名称
+     */
+    @ExcelField(title = "四级编码名称", order = 8)
+    private String name4;
+    /**
+     * 责任部门
+     */
+    @ExcelField(title = "责任部门", order = 9)
+    private String orgName;
+    /**
+     * 所需资质
+     */
+    @ExcelField(title = "所需资质", order = 9)
+    private String allNeedApName;
+
+    public String getCode1() {
+        return code1;
+    }
+
+    public void setCode1(String code1) {
+        this.code1 = code1;
+    }
+
+    public String getName1() {
+        return name1;
+    }
+
+    public void setName1(String name1) {
+        this.name1 = name1;
+    }
+
+    public String getCode2() {
+        return code2;
+    }
+
+    public void setCode2(String code2) {
+        this.code2 = code2;
+    }
+
+    public String getName2() {
+        return name2;
+    }
+
+    public void setName2(String name2) {
+        this.name2 = name2;
+    }
+
+    public String getCode3() {
+        return code3;
+    }
+
+    public void setCode3(String code3) {
+        this.code3 = code3;
+    }
+
+    public String getName3() {
+        return name3;
+    }
+
+    public void setName3(String name3) {
+        this.name3 = name3;
+    }
+
+    public String getCode4() {
+        return code4;
+    }
+
+    public void setCode4(String code4) {
+        this.code4 = code4;
+    }
+
+    public String getName4() {
+        return name4;
+    }
+
+    public void setName4(String name4) {
+        this.name4 = name4;
+    }
+
+    public String getOrgName() {
+        return orgName;
+    }
+
+    public void setOrgName(String orgName) {
+        this.orgName = orgName;
+    }
+
+    public String getAllNeedApName() {
+        return allNeedApName;
+    }
+
+    public void setAllNeedApName(String allNeedApName) {
+        this.allNeedApName = allNeedApName;
+    }
+}