| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package cn.com.goldenwater.dcproj.controller.pblm;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.dcproj.model.AttAdBase;
- import cn.com.goldenwater.dcproj.model.BisInspBaseNew;
- import cn.com.goldenwater.dcproj.model.BisInspPblm;
- import cn.com.goldenwater.dcproj.param.AttAdBaseParam;
- import cn.com.goldenwater.dcproj.param.BisInspAllObjParam;
- import cn.com.goldenwater.dcproj.param.ReverParam;
- import cn.com.goldenwater.dcproj.service.AttAdBaseService;
- import cn.com.goldenwater.dcproj.service.BisInspAllObjService;
- import cn.com.goldenwater.dcproj.service.BisInspPblmService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletResponse;
- import java.io.FileInputStream;
- import java.net.URLEncoder;
- import java.util.List;
- import java.util.Set;
- import java.util.stream.Collectors;
- /**
- * @author lune
- * @date 2019-2-18
- */
- @Api(value = "APP 督查问题管理", tags = "APP 督查问题管理")
- @RestController
- @RequestMapping("/dc/insp/pblm/genrl/statistics")
- public class BisInspPblmStatisticsController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- private AttAdBaseService attAdBaseService;
- @Autowired
- private BisInspPblmService bisInspPblmService;
- @Autowired
- private BisInspAllObjService bisInspAllObjService;
- @Value("${export.templatePath}")
- String excelFilePath;
- private final String[] type = new String[]{"小水库",
- "大中型水库",
- "在建水利工程",
- "水闸工程",
- "堤防工程",
- "小水电站",
- "水利工程设施水毁修复",
- "山洪灾害监测预警",
- "水旱灾害防御",
- "在建涉河建设项目和“清四乱”",
- "水利风景区",
- "山塘汛前检查"
- };
- @ApiOperation(value = "128导出问题列表-导出excel")
- @RequestMapping(value = "/export", method = RequestMethod.POST)
- public void genrlStatisticsExport(@ApiParam(name = "reverParam", value = "reverParam", required = true) @RequestBody ReverParam reverParam, HttpServletResponse response) {
- AttAdBaseParam attAdBaseParam = new AttAdBaseParam();
- attAdBaseParam.setAdCode("35");
- List<AttAdBase> attAdBaseList = attAdBaseService.findList(attAdBaseParam);
- BisInspAllObjParam bisInspAllObjParam = new BisInspAllObjParam();
- bisInspAllObjParam.setPtype("128");
- bisInspAllObjParam.setIds(reverParam.getOrgIds());
- List<BisInspBaseNew> objList = bisInspAllObjService.listOfGenrlBase(bisInspAllObjParam);
- // Set<String> adCodeSet = objList.stream().map(BisInspBaseNew::getAdCode).collect(Collectors.toSet());
- // attAdBaseList = attAdBaseList.stream().filter(attAdBase -> adCodeSet.contains(attAdBase.getAdCode())).collect(Collectors.toList());
- List<BisInspPblm> pblmList = bisInspPblmService.list(reverParam);
- // 读取下面的文档,编辑文档,并保存
- String templatePath = excelFilePath + "/dx_total_shi_fj03.xlsx";
- try {
- // 读取Excel模板文件
- FileInputStream fis = new FileInputStream(templatePath);
- XSSFWorkbook workbook = new XSSFWorkbook(fis);
- Sheet sheet = workbook.getSheetAt(0);
- // 编辑文档内容 - 在这里添加具体的业务逻辑
- // 示例:在指定行插入数据
- int startRow = 3; // 从第二行开始(索引从0开始)
- for (int i = 0; i < attAdBaseList.size(); i++) {
- AttAdBase attAdBase = attAdBaseList.get(i);
- String adCode = attAdBase.getAdCode().replace("00", "");
- Row row = sheet.createRow(startRow + i);
- row.createCell(0).setCellValue(attAdBase.getAdName());
- // 总体情况[工程数、问题数、典型问题数]
- row.createCell(1).setCellValue(objList.stream().filter(o -> o.getAdCode().startsWith(adCode)).count());
- row.createCell(2).setCellValue(pblmList.stream().filter(o -> o.getAdCode().startsWith(adCode)).count());
- row.createCell(3).setCellValue(0);
- int cellIndex = 4;
- for (int typeIndex = 0; typeIndex < type.length; typeIndex++) {
- // type [工程数、问题数、典型问题数]
- int finalTypeIndex = typeIndex;
- row.createCell(cellIndex++).setCellValue(objList.stream().filter(o -> type[finalTypeIndex].equals(o.getObjType())).filter(o -> o.getAdCode().startsWith(adCode)).count());
- row.createCell(cellIndex++).setCellValue(pblmList.stream().filter(o -> type[finalTypeIndex].equals(o.getBaseObjType())).filter(o -> o.getAdCode().startsWith(adCode)).count());
- row.createCell(cellIndex++).setCellValue(0);
- }
- }
- // 保存并导出文件
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
- response.setCharacterEncoding("UTF-8");
- String fileName = URLEncoder.encode("问题统计导出.xlsx", "UTF-8");
- response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
- workbook.write(response.getOutputStream());
- workbook.close();
- fis.close();
- } catch (Exception e) {
- logger.error("导出Excel文件失败", e);
- throw new RuntimeException("导出Excel文件失败: " + e.getMessage());
- }
- }
- }
|