response.setContentType("application/vnd.ms-excel;charset=utf-8");
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
//创建sheet页
SXSSFSheet sheet = sxssfWorkbook.createSheet("分析");
List<LinkedHashMap> list = new LinkedList<>();
//查询回来的结果
List<EquipmentData> listEquipDate = equipmentDataMapper.selectAllByAllAndType(peopleCounting.getStartTime(), peopleCounting.getEndTime(), peopleCounting.getSensorType(), peopleCounting.getIdBaseMesure(), null, null, null);
for (int i = 0; i < listEquipDate.size(); i++) {
EquipmentData equipmentData = listEquipDate.get(i);
List<HashMap> dataValueList = equipmentData.getDataValueList();
LinkedHashMap linkedHashMap = new LinkedHashMap();
linkedHashMap.put("id", equipmentData.getId());
linkedHashMap.put("measureStationName", equipmentData.getMeasureStationName());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date collectionTime = equipmentData.getCollectionTime();
String format = sdf.format(collectionTime);
linkedHashMap.put("观影", format);
for (int i1 = 0; i1 < dataValueList.size(); i1++) {
if (dataValueList.size() == 1) {
HashMap hashMap = dataValueList.get(i1);
linkedHashMap.put(hashMap.get("measure_name"), hashMap.get("measure_name"));
linkedHashMap.put("measure_value1", dataValueList.get(0).get("measure_value"));
} else {
HashMap hashMap = dataValueList.get(i1);
linkedHashMap.put(hashMap.get("measure_name"), hashMap.get("measure_name"));
linkedHashMap.put("measure_value1", dataValueList.get(0).get("measure_value"));
linkedHashMap.put("measure_value2", dataValueList.get(1).get("measure_value"));
}
// linkedHashMap.put("measure_value2", dataValueList.get(1).get("measure_value"));
}
list.add(linkedHashMap);
}
List<HashMap> mapList1 = contrastManMapper.selectVarianceFactor(peopleCounting.getUuid());
List<HashMap> varianceHash = new LinkedList<>();
for (int i = 0; i < mapList1.size(); i++) {
HashMap oldVaricanMap = mapList1.get(i);
varianceHash.add(oldVaricanMap);
}
System.out.println(varianceHash + "是否方差存储中");
for (HashMap hash : varianceHash) {
hash.put("type", Double.parseDouble( hash.get("type").toString()));
hash.put("artificial", Double.parseDouble(hash.get("artificial").toString()));
}
//计算结果值
List<HashMap> hashMaps = this.selectAllByFangCha(varianceHash);
ArrayList arrayList = new ArrayList();
System.out.println(list+"-------");
System.out.println(hashMaps+"----");
List<HashMap> list2 = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
LinkedHashMap listHashMap = list.get(i);
for (int i1 = 0; i1 < hashMaps.size(); i1++) {
HashMap hashMap1 = hashMaps.get(i1);
if (listHashMap.get("id").equals(hashMap1.get("id"))){
arrayList.add(i1);
listHashMap.put("八零", hashMap1.get("八零").toString());
listHashMap.put("2a", hashMap1.get("2a").toString());
listHashMap.put("超级王", hashMap1.get("artificial").toString());
listHashMap.put("称呼", hashMap1.get("type").toString());
}
}
list2.add(listHashMap);
}
//后端
//移除list多余元素
for (HashMap map1 : list2) {
map1.remove("");
map1.remove("id");
map1.remove("id_base_mesure");
map1.remove("artificial");
}
//创建表头
//创建sheet页
//创建表头行
Row rowHead = sheet.createRow(0);
//创建表头单元格
Cell cellHead1 = rowHead.createCell(0);//序号
cellHead1.setCellValue("序号");
rowHead.createCell(1).setCellValue("时间");//测点1
rowHead.createCell(2).setCellValue("观影");//采集时间
// equipmentDataMapper.selectResultNameBySensorType
for (int i = 0; i < listEquipDate.size(); i++) {
List<HashMap> dataValueList = listEquipDate.get(i).getDataValueList();
if (dataValueList.size() == 2) {
rowHead.createCell(3).setCellValue(dataValueList.get(0).get("measure_name").toString());
rowHead.createCell(4).setCellValue(dataValueList.get(1).get("measure_name").toString());
break;
}
}
Cell cellHead10 = rowHead.createCell(5);//白龙
cellHead10.setCellValue("称呼");
Cell cellHead7 = rowHead.createCell(6);//白龙
cellHead7.setCellValue("白龙");
Cell cellHead8 = rowHead.createCell(7);//胡龙
cellHead8.setCellValue("胡龙");
Cell cellHead9 = rowHead.createCell(8);//超级王
cellHead9.setCellValue("超级王");
//填充表信息
for (int i = 0; i < list2.size(); i++) {
Row rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(i + 1);
rowBody.createCell(1).setCellValue(list2.get(i).get("measureStationName").toString());
rowBody.createCell(2).setCellValue(list2.get(i).get("观影").toString());
HashMap linkedHashMap = list2.get(i);
if (linkedHashMap.containsKey("measure_value1")) {
rowBody.createCell(3).setCellValue(list2.get(i).get("measure_value1").toString());
}
if (linkedHashMap.containsKey("measure_value2")) {
rowBody.createCell(4).setCellValue(list2.get(i).get("measure_value2").toString());
}
if ((linkedHashMap.containsKey("称呼"))) {
rowBody.createCell(5).setCellValue(list2.get(i).get("称呼").toString());
}
if ((linkedHashMap.containsKey("八零"))) {
rowBody.createCell(6).setCellValue(list2.get(i).get("八零").toString());
}
if ((linkedHashMap.containsKey("2a"))) {
rowBody.createCell(7).setCellValue(list2.get(i).get("2a").toString());
}
if ((linkedHashMap.containsKey("超级王"))) {
double 八零 = Double.parseDouble(list2.get(i).get("八零").toString());
double a2 = Double.parseDouble(list2.get(i).get("2a").toString());
if (八零 > a2) {
rowBody.createCell(8).setCellValue("✘");
} else {
rowBody.createCell(8).setCellValue("✔");
}
}
}
// 下载导出
String filename = "人工对比分析";
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
//一定要设置成xlsx格式
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8"));
//创建一个输出流
ServletOutputStream outputStream = response.getOutputStream();
//写入数据
sxssfWorkbook.write(outputStream);
// 关闭
outputStream.close();
sxssfWorkbook.close();
}
集合,合并必看,超级容易立即集合
最新推荐文章于 2022-10-02 21:26:37 发布