集合,合并必看,超级容易立即集合

9 篇文章 0 订阅
 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();

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值