c44ad1090a88798d0b273d9f13e0340850e99e4d.svn-base 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package cn.com.goldenwater.dcproj.utils.export;
  2. import cn.com.goldenwater.dcproj.dao.AttAdBaseDao;
  3. import cn.com.goldenwater.dcproj.dto.AdUpDto;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Component;
  6. import java.io.OutputStream;
  7. import java.util.*;
  8. import static cn.com.goldenwater.dcproj.utils.export.FieldFormat.formatCheckNull;
  9. /**
  10. * @ClassName CreateExcelHelper
  11. * @Author liyz
  12. * @Date 2019/3/15 16:27
  13. * @Version 1.0
  14. **/
  15. @Component
  16. public class CreateExcelHelper {
  17. /**
  18. * 用于获取行政村名称
  19. */
  20. @Autowired
  21. private AttAdBaseDao attAdBaseDao;
  22. /**
  23. * 创建Excel公共方法
  24. *
  25. * @param tab
  26. * @param fileName
  27. * @param os
  28. * @param dataList
  29. * @return
  30. * @throws Exception
  31. */
  32. public ExportAbstract export(String tab, String fileName, OutputStream os, List<Map<String, Object>> dataList) throws Exception {
  33. ExportAbstract exportZ = new ExcelExport();
  34. // 容器1
  35. Hashtable index_h = new Hashtable();
  36. // 容器2
  37. ArrayList rSearchfields = new ArrayList();
  38. // 参数设置,根据tab
  39. setDataInfo(index_h, rSearchfields, tab);
  40. exportZ.fileName = fileName;
  41. exportZ.bdata = true;
  42. exportZ.index_h = index_h;
  43. exportZ.rSearchfields = rSearchfields;
  44. // 生成Excel数据
  45. exportZ.ExportHead(os, dataList);
  46. exportZ.ContinueExport(dataList);
  47. // XLSTransformer former = new XLSTransformer();
  48. return exportZ;
  49. }
  50. /**
  51. * 根据tab设置数据
  52. *
  53. * @param index_h
  54. * @param rSearchfields
  55. * @param tab
  56. */
  57. public static void setDataInfo(Hashtable index_h, ArrayList rSearchfields, String tab) {
  58. String[] index_h_s = TableFieldUtil.map.get(tab);
  59. if (index_h_s != null) {
  60. for (String str : index_h_s) {
  61. Column col = new Column();
  62. int i = 0;
  63. col.setCode(str.split(",")[i++]);
  64. col.setName(str.split(",")[i++]);
  65. String width = str.split(",")[i++];
  66. col.setGridwidth(Integer.parseInt("".equals(width) ? "80" : width));
  67. col.setType(str.split(",")[i++]);
  68. index_h.put(col.getCode(), col);
  69. rSearchfields.add(col.getCode());
  70. }
  71. }
  72. }
  73. //------------------------------- 其他业务方法 -------------------------------------------
  74. /**
  75. * 通过行政编码获取行政村名称
  76. *
  77. * @param adCode 行政区划(全称)
  78. * @return 行政村名称
  79. */
  80. public String getAdName(String adCode) {
  81. try {
  82. AdUpDto adUpDto = attAdBaseDao.fingAdUp(adCode);
  83. if (adUpDto != null) {
  84. return adUpDto.getAdFullName();
  85. }
  86. } catch (Exception e) {
  87. }
  88. return "";
  89. }
  90. /**
  91. * 通过行政编码获取 省 市 县
  92. *
  93. * @param adCode 行政区划(全称)
  94. * @return 行政村名称
  95. */
  96. public HashMap<String, String> getAdNames(String adCode) {
  97. HashMap<String, String> map = new HashMap<>(3);
  98. String province = "";
  99. String city = "";
  100. String county = "";
  101. try {
  102. if (adCode != null) {
  103. AdUpDto obj = attAdBaseDao.fingAdUp(adCode.substring(0, 2) + "0000000000");
  104. if (obj != null) {
  105. province = obj.getAdName();
  106. }
  107. obj = attAdBaseDao.fingAdUp(adCode.substring(0, 4) + "00000000");
  108. if (obj != null) {
  109. city = obj.getAdName();
  110. }
  111. obj = attAdBaseDao.fingAdUp(adCode.substring(0, 6) + "000000");
  112. if (obj != null) {
  113. county = obj.getAdName();
  114. }
  115. }
  116. } catch (Exception e) {
  117. e.printStackTrace();
  118. }
  119. map.put("province", formatCheckNull(province).toString());
  120. map.put("city", formatCheckNull(city).toString());
  121. map.put("county", formatCheckNull(county).toString());
  122. return map;
  123. }
  124. }