import cn.afterturn.easypoi.entity.vo.MapExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.view.PoiBaseView;
/**
* 导出excel
*/
@RequestMapping("/exportExcel")
public void exportExcel(ModelMap modelMap, HttpServletRequest request,
HttpServletResponse response, Integer contractId) {
List<DeviceNvrResult> deviceNvrResults = geyeDeviceNumPoolService.getNvrResults(contractId);
List<Map> totalMaps = new ArrayList<>();
for (DeviceNvrResult deviceNvrResult : deviceNvrResults) {
List<DeviceCamera> deviceCameraList = deviceNvrResult.getDeviceCameraList();
List<Map> listMaps = deviceCameraList.stream().map(v -> {
Map map = new HashMap();
map.put("rackNum", deviceNvrResult.getRackNum());
map.put("projectName2", deviceNvrResult.getProjectName2());
map.put("nvrSipAccount", deviceNvrResult.getSipAccount());
map.put("sipPassword", deviceNvrResult.getSipPassword());
map.put("deviceTotal", deviceCameraList.size());
map.put("deviceSipAccount", v.getSipAccount());
map.put("cameraName", v.getCameraName());
map.put("nvrChannelNum", v.getNvrChannelNum());
// nvr get sip service info
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("本地SIP端口号:");
stringBuffer.append(deviceNvrResult.getHttpPort());
stringBuffer.append("\r\n"); // cell 字符串换行
stringBuffer.append("SIP服务器ID:");
stringBuffer.append(deviceNvrResult.getSipServer().getSipServerNum());
stringBuffer.append("\r\n");
stringBuffer.append("SIP服务器域:");
stringBuffer.append(deviceNvrResult.getSipServer().getSipServerDomain());
stringBuffer.append("\r\n");
stringBuffer.append("SIP服务器地址:");
stringBuffer.append(deviceNvrResult.getSipServer().getSipServerIp());
stringBuffer.append("\r\n");
stringBuffer.append("SIP服务器端口:");
stringBuffer.append(deviceNvrResult.getSipServer().getSipServerPort());
map.put("memo", stringBuffer.toString());
return map;
}).collect(Collectors.toList());
totalMaps.addAll(listMaps);
}
//初始化表头
List<ExcelExportEntity> entity = new ArrayList<>();
entity.add(new ExcelExportEntityCustom("NVR名称", "rackNum", 10));
entity.add(new ExcelExportEntityCustom("项目名称", "projectName2", 30));
entity.add(new ExcelExportEntityCustom("SIP认证ID", "nvrSipAccount", 22));
entity.add(new ExcelExportEntityCustom("密码", "sipPassword", 13));
entity.add(new ExcelExportEntity("IP", ""));
entity.add(new ExcelExportEntity("WG网关", ""));
entity.add(new ExcelExportEntity("YM掩码", ""));
entity.add(new ExcelExportEntityCustom("接入摄像头数量", "deviceTotal", 10));
entity.add(new ExcelExportEntity("SIP通道ID摄像头", "deviceSipAccount", 22));
entity.add(new ExcelExportEntity("摄像头名称", "cameraName", 45));
entity.add(new ExcelExportEntity("通道号", "nvrChannelNum"));
entity.add(new ExcelExportEntityCustom("说明", "memo", 50));
ExportParams params = new ExportParams("工地监控摄像头信息表(电信智能眼数据导入模板)", "设备表", ExcelType.XSSF);
short titleHeight = 15;
params.setTitleHeight(titleHeight);
modelMap.put(MapExcelConstants.MAP_LIST, totalMaps);
modelMap.put(MapExcelConstants.ENTITY_LIST, entity);
modelMap.put(MapExcelConstants.PARAMS, params);
modelMap.put(MapExcelConstants.FILE_NAME, "工地监控摄像头信息表(电信智能眼数据导入模板)");
PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW);
}
public class ExcelExportEntityCustom extends ExcelExportEntity {
public ExcelExportEntityCustom(String name, Object key, int width) {
super.name = name;
super.setWidth((double) width);
super.setKey(key);
super.setNeedMerge(true); // 是否合并
super.setMergeVertical(true);// 是否垂直合并 重复数据合并
}
}
java 导出数据到excel
最新推荐文章于 2024-07-03 14:13:18 发布