package cn.autoform.excel.impl; import cn.autoform.bean.CodeAndValueBean; import cn.autoform.db.entity.FieldPropertyEntity; import cn.autoform.db.entity.FormBaseEntity; import cn.autoform.db.entity.FormFieldEntity; import cn.autoform.db.exten.MasterValue; import cn.autoform.excel.Excel; import cn.autoform.factory.FormFactory; import cn.autoform.factory.product.ProductMethod; import cn.autoform.factory.product.ProductMethod.IOType; import cn.autoform.fw.utility.ConstMap; import cn.autoform.util.thread.ThreadData; import cn.autoform.util.tool.JSONTool; import cn.autoform.web.client.MasterClient; import cn.autoform.web.controller.datamanagement.DataManagementController; import cn.autoform.web.interceptor.spring.InitParamInterceptor; import cn.autoform.web.mapper.datamanagement.DataManagementMapper; import cn.autoform.web.mapper.formset.FormSetMapper; import cn.autoform.web.service.datamanagement.DataManagementService; import cn.autoform.web.service.formbase.FormBaseService; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import jxl.CellView; import jxl.Sheet; import jxl.Workbook; import jxl.write.*; import lombok.Data; import lombok.extern.slf4j.Slf4j; import net.sf.json.JSONObject; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @Slf4j @Service @Scope("prototype") public class ExcelImpl implements Excel { private final String YEAR = "20"; private static final String TAGATTRIBUTE = "tag_Attribute"; private static final String FIELDSET = "fieldset"; @Resource private FormSetMapper formSetMapper; static final ExecutorService pool = Executors.newFixedThreadPool(10); @Autowired private DataManagementController dataManagementController = null; @Autowired private DataManagementService dataManagementService = null; @Autowired private FormFactory formFactory = null; @Resource DataManagementMapper dataManagementMapper; @Autowired private FormBaseService formBaseService = null; private String DATAROWNUM = "DATAROWNUM"; /** * 主数据缓存 */ private Map> masterCatch = new HashMap>(); @Autowired private MasterClient masterClient; /** * 导出模板 * @param formID * @param tenantID * @param request * @param response * @return * @throws Exception */ @Override public String expMod(String formID, String tenantID, HttpServletRequest request, HttpServletResponse response) throws Exception { //导出模版 //取出当前表单名 String formName = formSetMapper.selectBuss(formID,tenantID)+new SimpleDateFormat("yyyyHHddhhmmss").format(new Date()); System.out.println("当前表单:"+formName); OutputStream out = response.getOutputStream();// 取得输出流 response.reset();// 清空输出流 response.setHeader("Access-Control-Allow-Origin", "*"); //跨域 response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(formName+".xls", "UTF-8")); response.setContentType("application/octet-stream");// 指明response的返回对象是文件流,通知浏览器下载文件而不是打开 WritableWorkbook workbook = Workbook.createWorkbook(out); //生成于response输出流 //创建sheet页(工作表) WritableSheet sheet = workbook.createSheet("main", 0); //页名,页码 WritableFont wfont = new WritableFont(WritableFont.createFont("楷书"), 12); //定义样式,在该实例中可以定义字体,背景颜色,位置等 WritableCellFormat format = new WritableCellFormat(wfont); //查询表单字段 List rsList = dataManagementService.queryFormFields(formID, tenantID); DataMain subForm = new DataMain(); rsList.stream().forEach(formField ->{ if(formField.getFieldtype().equals("subform")){ subForm.getSubList().put(Objects.toString(formField.getColumnOrderNum(),"-1") ,new ArrayList<>()); } }); System.out.println(rsList); System.out.println("表单数据:"+ JSONTool.toJson(rsList.get(0))); getModelData(JSONTool.toObj(rsList.get(0).getFieldset(),Map.class) ,subForm); //首先生成main页面(主表单) Label label = null; Integer i = 0; for(String in :subForm.getMain()){ label = new Label(i, 0,in); sheet.addCell(label); i++; }; //生成子表单 System.out.println("这是撒"+JSONTool.toJson(subForm)); subForm.getSubList().keySet().stream() .forEach(o->{ Integer pa = 1; WritableSheet subSheet = workbook.createSheet(o, pa); //页名,页码 WritableFont subWfont = new WritableFont(WritableFont.createFont("楷书"), 12); //定义样式,在该实例中可以定义字体,背景颜色,位置等 WritableCellFormat subFormat = new WritableCellFormat(subWfont); Label subLabel = null; Integer s = 1; try { //单独添加一个行 subSheet.addCell(new Label(0, 0,"num")); for(String in :subForm.getSubList().get(o)){ subLabel = new Label(s, 0,in); subSheet.addCell(subLabel); s++; } } catch (WriteException e) { e.printStackTrace(); }finally { pa++; } }); workbook.write(); workbook.close(); out.flush(); out.close(); return null; } @Override @SuppressWarnings("unchecked") public String expExcel(String formID, String tenantID, IOType flag, HttpServletRequest request, HttpServletResponse response) throws Exception { //新开线程 // ImpExcelThread impExcelThread = new ImpExcelThread(); //导出为true ImpExcelThread impExcelThread = SpringUtil.getBean(ImpExcelThread.class); impExcelThread.setFormId(formID); impExcelThread.setTenantID(tenantID); impExcelThread.setRequest(request); impExcelThread.setResponse(response); impExcelThread.setCookie(copyCookie()); // pool.submit(new Thread(impExcelThread)); impExcelThread.run(); //导出表单 //查询表单信息,获取表单名 FormBaseEntity formBaseEntity = formBaseService.getFormBaseInfo(tenantID, formID,null); String formName = formBaseEntity.getFormName(); OutputStream out = response.getOutputStream();// 取得输出流 response.reset();// 清空输出流 response.setHeader("Access-Control-Allow-Origin", "*"); //跨域 response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(formName + ".xls", "UTF-8")); response.setContentType("application/octet-stream");// 指明response的返回对象是文件流,通知浏览器下载文件而不是打开 //创建一个工作簿 WritableWorkbook workbook = Workbook.createWorkbook(out); //创建sheet页(工作表) WritableSheet sheet = workbook.createSheet("sheet1", 0); //页名,页码 //定义样式,在该实例中可以定义字体,背景颜色,位置等 WritableCellFormat format = new WritableCellFormat(); CellView cellView = new CellView(); cellView.setAutosize(true); //设置自动大小 //查询表单字段 List rsList = dataManagementService.queryFormFields(formID, tenantID); //获得子表单个数 List subForm = new ArrayList<>(); rsList.stream().forEach(formField ->{ if(formField.getFieldtype().equals("subform")){ subForm.add(formField.getColumnOrderNum()); } }); Map subField = new HashMap<>(); if(subForm.size()> 0){ subForm.stream().forEach(columnOrderNum ->{ rsList.stream().filter(formField -> formField.getParentsubFormNum().equals(columnOrderNum) && !formField.getFieldKey().equals(getDATAROWNUM())) .forEach(formField -> { int i = 1; subField.put(columnOrderNum,i); i++; } ); }); } //字段名(主+子) List filedName = new ArrayList<>(); StringBuilder subname = new StringBuilder(); //装子表单序号 int mainfiled = 0; //主表单字段数 List subfiled = new ArrayList<>(); //子表单字段统计 //统计主表单字段数 for (int i = 0; i < rsList.size(); i++) { if (!"subform".equals(rsList.get(i).getFieldtype()) && rsList.get(i).getParentsubFormNum() ==0) { mainfiled++; } } //字段写入题头(第二行) Label label = null; int j = 0; int subc = 0; int begin = 0; String wToS = "main";//以子表单开头还是主表单开头 List> why = new ArrayList<>(); for (int i = 0; i < rsList.size(); i++) { if ("subform".equals(rsList.get(i).getFieldtype())) { if(i ==0){ wToS = "subForm"; begin = j; } Map where = new HashMap<>(); where.put(rsList.get(i).getColumnOrderNum(),j); why.add(where); label = new Label(j, 0, rsList.get(i).getFieldKey(), format); sheet.setColumnView(j, cellView);//根据内容自动设置列宽 subname.append(rsList.get(i).getColumnOrderNum()); subname.append(","); subfiled.add(subc); subc = 0; } else { if(rsList.get(i).getParentsubFormNum() == 0){ sheet.mergeCells(j,0,j,1); label = new Label(j, 0, rsList.get(i).getFieldKey(), format); //1.列 2.行 3.数据 }else{ label = new Label(j, 1, rsList.get(i).getFieldKey(), format); if(!(getDATAROWNUM()).equals(rsList.get(i).getFieldKey())) subc++ ; } j++; filedName.add(rsList.get(i).getFieldKey()); } sheet.addCell(label); } if(wToS.equals("main")){ sheet.mergeCells(begin, 0, j-1, 0);// }else{ if(why.size()>0){ why.stream().forEach(wh ->{ Iterator it = wh.keySet().iterator(); while(it.hasNext()){ int i = it.next(); try { sheet.mergeCells(wh.get(i), 0,wh.get(i) + subField.get(i), 0); } catch (WriteException e) { e.printStackTrace(); } } }); } } subfiled.add(subc); subfiled.remove(0); //去掉第一位 String[] subNameArr = subname.toString().split(","); //子表单序号数组 //查询主表单数据,统计数据条数 ProductMethod productMethod = this.formFactory.createFormMethod(); List> rsMap =null; //查询当前表单所有数据 rsMap = productMethod.queryFormDataList(formID, tenantID, null); //取得数据行号datarowNum List datarowNum = new ArrayList<>(); for (int i = 0; i < rsMap.size(); i++) { Map map = rsMap.get(i); datarowNum.add(Integer.parseInt(map.get("DATAROWNUM").toString())); } //逐条查询表单数据 int count = rsMap.size(); //表单数据条数 int line = 2; //数据在表格中所在的行 //循环查询单条数据,datarowNum:数据行号,formdataNum:子表单序号 for (int i = 0; i < count; i++) { boolean subWhere = true;//判断子表单是不是第一个控件,默认为第一个 Map single = productMethod.queryFormDataList(formID, tenantID, datarowNum.get(i), subname.toString()); //主表单 Iterator whForm= single.keySet().iterator(); String toMerge = null;//判断是否合并 默认为合并 int filedNameNum = 0; int maxL = 0;//最大长度 while(whForm.hasNext()){ String formW = whForm.next().toString(); if ("main".equals(formW)) { String todo = null; int realine = line; if(toMerge != null){ realine = line-maxL; todo = "do"; } toMerge = "NO"; subWhere = false; if(wToS.equals("main")){ // mainfiled = filedNameNum + mainfiled; filedNameNum = 0; } Map mainData = (Map)single.get("main"); for (int x = filedNameNum; x < mainfiled; x ++) { String value = mainData.get(filedName.get(x)).toString(); if (value.indexOf("★☆") != -1) { //复选数据替换为,间隔 label = new Label(x, realine, value.replaceAll("★☆", ","), format); } else { label = new Label(x, realine, value, format); //1.列 2.行 3.数据 } sheet.addCell(label); if("do".equals(todo)){ sheet.mergeCells(x, realine, x, realine + maxL -1); } } } //子表单 if ("subs".equals(formW)) { //全部子表单 Map>> subs = (Map>>)single.get("subs"); int maxC = 0; for (int k = 0; k < subNameArr.length; k++) { //统计数据最多条数 List> subList = (List>)subs.get(subNameArr[k]); if (subList!=null &&subList.size() > maxC) { maxC = subList.size(); } } maxL = maxC; if(!subWhere){ //合并主表单元格 for(int cul=0; cul> subList = (List>)subs.get(subNameArr[k]); if(maxC>1){ toMerge = "YES"; } for (int m = 0; m < subfiled.get(k); m++) { if (subList.size() > c) { Map subData = subList.get(c); String value = subData.get(filedName.get(n+m)).toString(); if (value.indexOf("★☆") != -1) { //复选数据替换为,间隔 label = new Label(n+m, line, value.replaceAll("★☆", ","), format); } else { label = new Label(n+m, line, value, format); //1.列 2.行 3.数据 } sheet.addCell(label); } } n = n + subfiled.get(k); } line++; } } } // line++; } workbook.write(); workbook.close(); out.flush(); out.close(); return null; } @Override public String impExcel(MultipartFile file, String formID, String tenantID, String userName, IOType flag, HttpServletRequest request , HttpServletResponse response) throws Exception { //新开线程 ImpExcelThread impExcelThread = SpringUtil.getBean(ImpExcelThread.class); impExcelThread.setFile(file); //导入为true impExcelThread.setFlag(true); impExcelThread.setFormId(formID); impExcelThread.setTenantID(tenantID); impExcelThread.setUserName(userName); impExcelThread.setRequest(request); impExcelThread.setResponse(response); impExcelThread.setCookie(copyCookie()); impExcelThread.run(); // pool.submit(impExcelThread); return null; } // 验证数字格式 public boolean isNumeric(String str){ Pattern pattern = null; if(str.indexOf(".")>0){ pattern = Pattern.compile("^-?([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|0?\\.0+|0)$"); }else{ pattern = Pattern.compile("^[0-9]*$"); } // +表示1个或多个,*表示0个或多个,?表示0个或1个 // "[0-9]*" 正数 // "^-?[0-9]+" 负数 //"-?[0-9]+.?[0-9]+" 全部数字 Matcher isNum = pattern.matcher(str); if( !isNum.matches() ){ System.out.println("数字格式错误:++++++++++++++"+str); return false; } return true; } //验证日期格式 public boolean isValidDate(String str) { boolean convertSuccess = true; // 指定日期格式为四位年/两位月份/两位日期,注意yyyy/MM/dd区分大小写; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { // 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期,比如2007/02/29会被接受,并转换成2007/03/01 format.setLenient(false); format.parse(str); } catch (ParseException e) { // 如果throw java.text.ParseException或者NullPointerException,就说明格式不对 System.out.println("日期格式错误:++++++++++++"+str); convertSuccess = false; } return convertSuccess; } /** * 导入子表单 */ @Override public List> imgSonExcel(Integer rowNum,String formID, String tenantID, String userName, MultipartFile file, IOType flag, HttpServletRequest request, HttpServletResponse response) throws Exception { Workbook workbook = Workbook.getWorkbook(file.getInputStream()); //取得工作页 Sheet sheet = workbook.getSheet(0); //查询表单字段 List formList = dataManagementService.queryFormFields(formID, tenantID); //获得当前子表单 Map types1 = new HashMap<>(); for(FormFieldEntity form: formList){ if(Objects.equals(form.getParentsubFormNum(), rowNum) && !form.getFieldKey().equals("DATAROWNUM")){ types1.put(Integer.parseInt(Objects.toString(form.getColumnOrderNum(),"0")),form.getFieldtype()); } } Set types2 = types1.keySet(); List types = new ArrayList<>(); types2.forEach(o -> types.add(o)); List> lists = new ArrayList<>(); for(int c=0; c< sheet.getColumns(); c++){ String title = sheet.getCell(c, 0).getContents(); if("".equals(title)|| title == null){ continue; } Integer itemId = this.getItemId(JSONTool.toObj(JSONTool.toJson(formList.get(0)),Map.class).get(FIELDSET),title); List list = new ArrayList<>(); row: { for (int r = 1; r < sheet.getRows(); r++) { if (c > types.size() - 1) { continue; } //验证是否必填 if (this.isMustCheck(formID, tenantID, itemId)) { String v = sheet.getCell(c, r).getContents(); if ("".equals(v) || v == null) { break row; } } if (types1.get(itemId).equals("number")) { if (!this.isNumeric(sheet.getCell(c, r).getContents())) { break row; } list.add(sheet.getCell(c, r).getContents()); } else if (types1.get(itemId).equals("calendar")) { if (!this.isValidDate(sheet.getCell(c, r).getContents())) { break row; } list.add(YEAR + sheet.getCell(c, r).getContents()); //获取excel的下拉列表和树型的值 } else if (types1.get(itemId).equals("dropdownlist") || types1.get(itemId).equals("tree")) { String value = sheet.getCell(c, r).getContents(); //调用获取Code 的方法 list.add(getCode(formList, value, itemId, types1.get(itemId), tenantID)); } else { list.add(sheet.getCell(c, r).getContents()); } } } lists.add(list); } this.masterCatch.clear(); return lists; } //验证控件属性是否必填 返回是否必填 public boolean isMustCheck(String formID, String tenantID, Integer columnOrderNum){ List fieldPropertys= dataManagementMapper.queryFormFieldProperty(formID, tenantID, columnOrderNum) .stream(). filter(formField ->"mustcheck".equals(formField.getProperty())) .collect(Collectors.toList()); if(Objects.isNull(fieldPropertys)){ return true; }else{ return "true".equals(fieldPropertys.get(0).getValue()) ? true : false; } } private String getDATAROWNUM() { return DATAROWNUM; } /** * 主数据value转code */ @SuppressWarnings("unchecked") public String getCode(List formList,String value,Integer number,String fieldType,String tenantId) throws Exception{ List master = this.masterCatch.get(number); if(master!= null){ return getValue(value,master); } //取出表单控件中的主数据 String d = formList.get(0).getFieldset(); Map map = JSONTool.toObj(d,Map.class); Map map1 = JSONTool.toObj(JSONTool.toJson(map.get("itemId"+"_"+number)),Map.class); Map map2 = JSONTool.toObj(JSONTool.toJson(map1.get(TAGATTRIBUTE)),Map.class); String code = Objects.toString(map2.get("masterData"),null); //查询费用云主数据 String datasourceType = Objects.toString(map2.get("datasourcetype")); if(Objects.equals(datasourceType,"masterdata")){ System.out.println("进入主数据转换"); JSONObject jsonObj = JSONObject.fromObject(code); String defindCode = null; String eleCode = null; if (jsonObj.has("defindCode")) { defindCode = jsonObj.getString("defindCode"); } if (jsonObj.has("eleCode")) { eleCode = jsonObj.getString("eleCode"); } if (defindCode != null && eleCode != null) { String eleName = null; if (jsonObj.has(ConstMap.ELENAME)) { eleName = jsonObj.getString(ConstMap.ELENAME); } String parentCode = null; if (jsonObj.has("parentCode")) { parentCode = jsonObj.getString("parentCode"); } //筛选主数据 MasterValue MasterValue = new MasterValue(); MasterValue.setTenantID(tenantId); MasterValue.setDefineCode(defindCode); MasterValue.setELE_CODE(eleCode); MasterValue.setParentCode(parentCode); MasterValue.setEleName(eleName); System.out.println("主数据参数:" + JSONTool.toJson(MasterValue)); List result1 = this.masterClient.queryClientMasterValues(MasterValue); masterCatch.put(number, result1); System.out.println("Value值" + ":" + value); return getValue(value, result1); } }else if(Objects.equals(datasourceType,"custom")){ System.out.println("进入自定义转换"); List customMap = JSONTool.toList(JSONTool.toJson(map2.get("custom")),Map.class); List res = new ArrayList<>(); customMap.stream().forEach(o->res.add(new CodeAndValueBean(Objects.toString(o.get("code")),Objects.toString(o.get("itemtext"))))); masterCatch.put(number, res); return getValue(value, res); } return null; } public String getValue(String name,List result){ for(CodeAndValueBean con : result){ if(name.equals(con.getValue())){ System.out.println("转换后code:"+con.getCode()); return con.getCode(); } } return ""; } /** * 导入子表单模板 * @return * @throws IOException * @throws WriteException */ public String expSonExcel(String data,String formID, String tenantID,String number, HttpServletRequest request, HttpServletResponse response) throws IOException, WriteException{ //最终表头字段 Map map = new HashMap<>(); OutputStream out = response.getOutputStream();// 取得输出流 response.reset();// 清空输出流 response.setHeader("Access-Control-Allow-Origin", "*"); //跨域 response.setHeader("content-disposition", "attachment;filename=" + new SimpleDateFormat("yyyyHHddhhmmss").format(new Date()) + ".xls"); response.setContentType("application/octet-stream");// 指明response的返回对象是文件流,通知浏览器下载文件而不是打开 WritableWorkbook workbook = Workbook.createWorkbook(out); //生成于response输出流 //创建sheet页(工作表) WritableSheet sheet = workbook.createSheet("sheet1", 0); //页名,页码 WritableFont wfont = new WritableFont(WritableFont.createFont("楷书"), 12); //定义样式,在该实例中可以定义字体,背景颜色,位置等 WritableCellFormat format = new WritableCellFormat(wfont); //查询表单字段 List list = JSONTool.toList(data, String.class); //单元格 Label label = null; Integer i = 0; for(String in :list){ label = new Label(i, 0,in); sheet.addCell(label); i++; }; workbook.write(); workbook.close(); out.flush(); out.close(); return null; } @Override public String newImpExcel(MultipartFile file, String formID, String tenantID, String userName, IOType flag, HttpServletRequest request, HttpServletResponse response) throws Exception { return null; } /** * 通过title获取相应得 item_id * */ @SuppressWarnings("unchecked") public Integer getItemId(Object fieldSet,String title){ Map map = JSONTool.toObj(fieldSet.toString(),Map.class); for(String o :map.keySet()){ Map m = JSONTool.toObj(JSONTool.toJson(map.get(o)),Map.class); Map m1 = JSONTool.toObj(JSONTool.toJson(m.get(TAGATTRIBUTE)),Map.class); if(title.equals(m1.get("title"))){ return Integer.parseInt(Objects.toString(m.get("columnOrderNum"),"0")); } }; return 0; } /** * 自定义属性code转value */ public String getCoustCode(List formList,String value,Integer number,String fieldType,String tenantId) throws Exception{ List master = this.masterCatch.get(number); if(master!= null){ return getValue(value,master); } //取出表单控件中的主数据 String d = formList.get(0).getFieldset(); Map map = JSONTool.toObj(d,Map.class); Map map1 = JSONTool.toObj(JSONTool.toJson(map.get("itemId"+"_"+number)),Map.class); Map map2 = JSONTool.toObj(JSONTool.toJson(map1.get(TAGATTRIBUTE)),Map.class); return null; } Map> subList = new HashMap<>(); /** * 取出需要导出模板得字段 * @return */ public void getModelData(Map map ,DataMain dataMain){ System.out.println("参数:"+ JSONTool.toJson(dataMain)); List mainList = new ArrayList<>(); Map subName = new HashMap<>(); map.keySet().stream().forEach(o->{ Map item = JSONTool.toObj(JSONTool.toJson(map.get(o)),Map.class); String tagType = Objects.toString(item.get("tag_Type")); Map attr = JSONTool.toObj(JSONTool.toJson(item.get(TAGATTRIBUTE)),Map.class); String title = Objects.toString(attr.get("title")); String parentsubFormNum = Objects.toString(item.get("parentsubFormNum"),"-1"); if(!Objects.equals(tagType,"mytext")) { if (Objects.equals("0", parentsubFormNum) && !Objects.equals(tagType, "subform")) { System.out.println("-------->主表控件:" + title); mainList.add(title); } else if (!Objects.equals("0", parentsubFormNum)) { System.out.println("-------->子表控件:" + title); List li = dataMain.getSubList().get(parentsubFormNum); li.add(title); dataMain.getSubList().put(parentsubFormNum, li); } else if (Objects.equals(tagType,"subform")) { System.out.println("-------->子表单:" + title); String column = Objects.toString(item.get("columnOrderNum"), "-1"); subName.put(column, title); } } }); dataMain.setMain(mainList); //转换子表单别名 System.out.println("最后数据:"+ JSONTool.toJson(dataMain)); Map> subL = dataMain.getSubList(); Map> newSub = new HashMap<>(); System.out.println("所有子表单:"+ JSONTool.toJson(subName)); subL.keySet().stream() .forEach(o-> newSub.put(subName.get(o),dataMain.getSubList().get(o)) ); dataMain.setSubList(newSub); } //获取cookie public Map copyCookie(){ Map cookie = new HashMap<>(); InitParamInterceptor.COOKIE_KEY.entrySet().stream() .filter(cookieKey->{ return StringUtils.isNoneBlank(Objects.toString(ThreadData.get(cookieKey.getValue()), "")); }) .forEach(cookieKey->{ log.debug("当前添加:{},{}", cookieKey.getKey(),ThreadData.get(cookieKey.getValue())); cookie.put(cookieKey.getKey(), ThreadData.get(cookieKey.getValue())); }); return cookie; } //导出模板字段 @Data class DataMain{ //主表字段 private List main = new ArrayList<>(); //字表字段 private Map> subList = new HashMap<>(); } }