10915f566f3c6ab902a7e26319d6d8283d9ec0be.svn-base 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package cn.com.goldenwater.dcproj.controller.pblm;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.dcproj.model.AttAdBase;
  4. import cn.com.goldenwater.dcproj.model.BisInspBaseNew;
  5. import cn.com.goldenwater.dcproj.model.BisInspPblm;
  6. import cn.com.goldenwater.dcproj.param.AttAdBaseParam;
  7. import cn.com.goldenwater.dcproj.param.BisInspAllObjParam;
  8. import cn.com.goldenwater.dcproj.param.ReverParam;
  9. import cn.com.goldenwater.dcproj.service.AttAdBaseService;
  10. import cn.com.goldenwater.dcproj.service.BisInspAllObjService;
  11. import cn.com.goldenwater.dcproj.service.BisInspPblmService;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import io.swagger.annotations.ApiParam;
  15. import org.apache.poi.ss.usermodel.Row;
  16. import org.apache.poi.ss.usermodel.Sheet;
  17. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.web.bind.annotation.RequestBody;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestMethod;
  25. import org.springframework.web.bind.annotation.RestController;
  26. import javax.servlet.http.HttpServletResponse;
  27. import java.io.FileInputStream;
  28. import java.net.URLEncoder;
  29. import java.util.List;
  30. import java.util.Set;
  31. import java.util.stream.Collectors;
  32. /**
  33. * @author lune
  34. * @date 2019-2-18
  35. */
  36. @Api(value = "APP 督查问题管理", tags = "APP 督查问题管理")
  37. @RestController
  38. @RequestMapping("/dc/insp/pblm/genrl/statistics")
  39. public class BisInspPblmStatisticsController extends BaseController {
  40. private Logger logger = LoggerFactory.getLogger(getClass());
  41. @Autowired
  42. private AttAdBaseService attAdBaseService;
  43. @Autowired
  44. private BisInspPblmService bisInspPblmService;
  45. @Autowired
  46. private BisInspAllObjService bisInspAllObjService;
  47. @Value("${export.templatePath}")
  48. String excelFilePath;
  49. private final String[] type = new String[]{"小水库",
  50. "大中型水库",
  51. "在建水利工程",
  52. "水闸工程",
  53. "堤防工程",
  54. "小水电站",
  55. "水利工程设施水毁修复",
  56. "山洪灾害监测预警",
  57. "水旱灾害防御",
  58. "在建涉河建设项目和“清四乱”",
  59. "水利风景区",
  60. "山塘汛前检查"
  61. };
  62. @ApiOperation(value = "128导出问题列表-导出excel")
  63. @RequestMapping(value = "/export", method = RequestMethod.POST)
  64. public void genrlStatisticsExport(@ApiParam(name = "reverParam", value = "reverParam", required = true) @RequestBody ReverParam reverParam, HttpServletResponse response) {
  65. AttAdBaseParam attAdBaseParam = new AttAdBaseParam();
  66. attAdBaseParam.setAdCode("35");
  67. List<AttAdBase> attAdBaseList = attAdBaseService.findList(attAdBaseParam);
  68. BisInspAllObjParam bisInspAllObjParam = new BisInspAllObjParam();
  69. bisInspAllObjParam.setPtype("128");
  70. bisInspAllObjParam.setIds(reverParam.getOrgIds());
  71. List<BisInspBaseNew> objList = bisInspAllObjService.listOfGenrlBase(bisInspAllObjParam);
  72. // Set<String> adCodeSet = objList.stream().map(BisInspBaseNew::getAdCode).collect(Collectors.toSet());
  73. // attAdBaseList = attAdBaseList.stream().filter(attAdBase -> adCodeSet.contains(attAdBase.getAdCode())).collect(Collectors.toList());
  74. List<BisInspPblm> pblmList = bisInspPblmService.list(reverParam);
  75. // 读取下面的文档,编辑文档,并保存
  76. String templatePath = excelFilePath + "/dx_total_shi_fj03.xlsx";
  77. try {
  78. // 读取Excel模板文件
  79. FileInputStream fis = new FileInputStream(templatePath);
  80. XSSFWorkbook workbook = new XSSFWorkbook(fis);
  81. Sheet sheet = workbook.getSheetAt(0);
  82. // 编辑文档内容 - 在这里添加具体的业务逻辑
  83. // 示例:在指定行插入数据
  84. int startRow = 3; // 从第二行开始(索引从0开始)
  85. for (int i = 0; i < attAdBaseList.size(); i++) {
  86. AttAdBase attAdBase = attAdBaseList.get(i);
  87. String adCode = attAdBase.getAdCode().replace("00", "");
  88. Row row = sheet.createRow(startRow + i);
  89. row.createCell(0).setCellValue(attAdBase.getAdName());
  90. // 总体情况[工程数、问题数、典型问题数]
  91. row.createCell(1).setCellValue(objList.stream().filter(o -> o.getAdCode().startsWith(adCode)).count());
  92. row.createCell(2).setCellValue(pblmList.stream().filter(o -> o.getAdCode().startsWith(adCode)).count());
  93. row.createCell(3).setCellValue(0);
  94. int cellIndex = 4;
  95. for (int typeIndex = 0; typeIndex < type.length; typeIndex++) {
  96. // type [工程数、问题数、典型问题数]
  97. int finalTypeIndex = typeIndex;
  98. row.createCell(cellIndex++).setCellValue(objList.stream().filter(o -> type[finalTypeIndex].equals(o.getObjType())).filter(o -> o.getAdCode().startsWith(adCode)).count());
  99. row.createCell(cellIndex++).setCellValue(pblmList.stream().filter(o -> type[finalTypeIndex].equals(o.getBaseObjType())).filter(o -> o.getAdCode().startsWith(adCode)).count());
  100. row.createCell(cellIndex++).setCellValue(0);
  101. }
  102. }
  103. // 保存并导出文件
  104. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  105. response.setCharacterEncoding("UTF-8");
  106. String fileName = URLEncoder.encode("问题统计导出.xlsx", "UTF-8");
  107. response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
  108. workbook.write(response.getOutputStream());
  109. workbook.close();
  110. fis.close();
  111. } catch (Exception e) {
  112. logger.error("导出Excel文件失败", e);
  113. throw new RuntimeException("导出Excel文件失败: " + e.getMessage());
  114. }
  115. }
  116. }