@GetMapping(value = "/exportData")
public void exportData(Integer policyId, HttpServletResponse response) {
String platFromId = SecurityUtils.getSubject().getSession().getAttribute("platFromId").toString();
PolicyForm policyForm = policyFormMapper.selectByPolicyId(policyId);
try {
//1、创建workbook,对应一个excel
HSSFWorkbook wb = new HSSFWorkbook();
//1.5、生成excel中可能用到的单元格样式
//首先创建字体样式
HSSFFont font = wb.createFont();//创建字体样式
font.setFontName("宋体");//使用宋体
font.setFontHeightInPoints((short) 10);//字体大小
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
HSSFSheet sheet = wb.createSheet();
HSSFRow hssfRow = sheet.createRow(0);
hssfRow.createCell(0).setCellValue("序号");
hssfRow.createCell(1).setCellValue("企业名称");
hssfRow.createCell(2).setCellValue("社会统一信用代码");
hssfRow.createCell(3).setCellValue("申报状态");
hssfRow.createCell(4).setCellValue("办公楼宇");
hssfRow.createCell(5).setCellValue("申报时间");
hssfRow.createCell(6).setCellValue("申报备注");
String entBasic = policyForm.getEntBasic();
String indicator = policyForm.getIndicator();
int cellColumn = 7;
if (StringUtil.isNotEmpty(entBasic)) {
JSONArray entBasicJson = JSON.parseArray(entBasic);
for (int i = 0; i<entBasicJson.size(); i++) {
hssfRow.createCell(cellColumn).setCellValue(entBasicJson.getJSONObject(i).get("title").toString());
cellColumn++;
}
}
if (StringUtil.isNotEmpty(indicator)) {
JSONArray indicatorJson = JSON.parseArray(indicator);
for (int i = 0; i<indicatorJson.size(); i++) {
hssfRow.createCell(cellColumn).setCellValue(indicatorJson.getJSONObject(i).get("title").toString());
cellColumn++;
}
}
List<PolicyDeclare> policyDeclares = policyDeclareMapper.selectByPolicyId(policyId);
for (int j = 1; j <=policyDeclares.size(); j++) {
hssfRow = sheet.createRow(j);
hssfRow.createCell(0).setCellValue(j);
hssfRow.createCell(1).setCellValue(policyDeclares.get(j-1).getEntName());
hssfRow.createCell(2).setCellValue(policyDeclares.get(j-1).getCreditCode());
if (policyDeclares.get(j-1).getStatus() == 1) {
hssfRow.createCell(3).setCellValue("待审核");
} else if (policyDeclares.get(j-1).getStatus() == 2) {
hssfRow.createCell(3).setCellValue("审核通过");
} else if (policyDeclares.get(j-1).getStatus() == 2) {
hssfRow.createCell(3).setCellValue("审核驳回");
}
String eid = policyDeclares.get(j - 1).getLinkValue();
if (StringUtil.isNotEmpty(eid)) {
EntFile entFile = entFileDao.findByEid(eid, platFromId);
if (StringUtil.isNotEmpty(entFile.getOfficeBuildingIds())) {
String[] layoutIds = entFile.getOfficeBuildingIds().split(",");
StringBuilder layoutName = new StringBuilder();
for (String layoutId: layoutIds) {
Layout layout = layoutService.findById(Integer.valueOf(layoutId));
layoutName.append(layout.getName() == null ? null: layout.getName() + ",");
}
layoutName.deleteCharAt(layoutName.lastIndexOf(","));
hssfRow.createCell(4).setCellValue(layoutName.toString());
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
hssfRow.createCell(5).setCellValue(policyDeclares.get(j-1).getCreateTime() == null ? null: sdf.format(policyDeclares.get(j-1).getCreateTime()));
hssfRow.createCell(6).setCellValue(policyDeclares.get(j-1).getRemark());
String entBasicData = policyDeclares.get(j - 1).getEntBasicData();
String indicatorData = policyDeclares.get(j - 1).getIndicatorData();
cellColumn = 7;
if (StringUtil.isNotEmpty(entBasicData)) {
JSONArray entBasicDataJson = JSON.parseArray(entBasicData);
for (int i = 0; i<entBasicDataJson.size(); i++) {
if (entBasicDataJson.getJSONObject(i).containsKey("value")) {
hssfRow.createCell(cellColumn).setCellValue(entBasicDataJson.getJSONObject(i).get("value").toString());
}
cellColumn++;
}
}
if (StringUtil.isNotEmpty(indicatorData)) {
JSONArray indicatorDataJson = JSON.parseArray(indicatorData);
for (int i = 0; i<indicatorDataJson.size(); i++) {
if (indicatorDataJson.getJSONObject(i).containsKey("value")) {
hssfRow.createCell(cellColumn).setCellValue(indicatorDataJson.getJSONObject(i).get("value").toString());
}
cellColumn++;
}
}
}
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
String fileName = new String("企业填报数据.xls".getBytes("gb2312"), "ISO8859-1");
//response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; fileName=" + fileName);
wb.write(response.getOutputStream());
} catch (Exception e) {
logger.error("企业填报数据导出错误", e);
}
}
导出功能接口
最新推荐文章于 2024-10-25 16:42:48 发布