zoukankan      html  css  js  c++  java
  • 文件导入

    public String importKeyPointDevice(MultipartFile file) {
            //生成任务id
            String taskid = assessTaskUtilsService.getTaskid();
            try {
                Workbook workbook;
                List<TaskDevice> taskDevices = new ArrayList<>();
                Map<String, List<String>> map = new HashMap<>(10);
                //获取文件名
                String fileName = file.getOriginalFilename();
                //文件名后缀
                String postfix = fileName.substring(fileName.lastIndexOf("."));
                //获取输入流
                InputStream inputStream = file.getInputStream();
                //验证文件格式
                if (".xls".equalsIgnoreCase(postfix)) {
                    workbook = new HSSFWorkbook(inputStream);
                } else if (".xlsx".equalsIgnoreCase(postfix)) {
                    workbook = new XSSFWorkbook(inputStream);
                } else {
                    return null;
                }
                //获取第一页表格数据
                Sheet sheet = workbook.getSheetAt(0);
                int first = sheet.getFirstRowNum();
                int last = sheet.getLastRowNum();
                Date date = new Date();
                //遍历每一行数据
                for (int i = first + 1; i <= last; i++) {
                    List<String> contentList = new ArrayList<>();
                    //获取行数据
                    Row row = sheet.getRow(i);
                    //去除空行
                    if (null == row) {
                        continue;
                    }
                    int firstCellNum = 0;
                    int lastCellNum = 5;
                    for (int j = firstCellNum; j < lastCellNum; j++) {
                        //验证每行的列数据
                        if (j < 3) {
                            if (null == sheet.getRow(i).getCell(j) || "".equals(sheet.getRow(i).getCell(j).toString())) {
                                //存在未空或者null,清空contentList数据
                                contentList.clear();
                                break;
                            }
                        }
                        //添加数据
                        if (null != sheet.getRow(i).getCell(j)) {
                            contentList.add(sheet.getRow(i).getCell(j).toString());
                        } else {
                            contentList.add("");
                        }
                    }
                    if (CollectionUtils.isNotEmpty(contentList)) {
                        map.put("deviceInfo" + i, contentList);
                    }
                }
                for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                    List<String> list = entry.getValue();
                    TaskDevice taskDevice = new TaskDevice();
                    taskDevice.setDeviceid(list.get(0));
                    taskDevice.setDevicename(list.get(1));
                    taskDevice.setCivilcode(list.get(2));
                    taskDevice.setParentid(list.get(3));
                    taskDevice.setPkeep(list.get(4));
                    taskDevice.setLabel(taskid);
                    taskDevice.setCtime(date);
                    taskDevice.setTaskno("");
                    taskDevice.setIssend(0);
                    taskDevices.add(taskDevice);
                }
                detectionDao.insertTaskDevices(taskDevices);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return taskid;
        }
    

      

  • 相关阅读:
    <c:forTokens/>标签
    小小的心得
    wordcount编写和提交集群运行问题解决方案
    全国主要城市空气质量
    模拟迁途箭头圆圈
    模拟迁途.html
    大规模markpoint特效
    hadoop例子程序:求圆周率和wordcount
    测试
    hadoop集群安装好之后的启动操作
  • 原文地址:https://www.cnblogs.com/zhaoatian/p/13906451.html
Copyright © 2011-2022 走看看