b4db109ffb67742788637bbdd86315d339b4e834.svn-base 5.9 KB

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