shi'sen'yuan 3 gadi atpakaļ
vecāks
revīzija
67ff95667d

+ 7 - 0
pom.xml

@@ -326,6 +326,13 @@
             <artifactId>jpinyin</artifactId>
             <version>1.1.8</version>
         </dependency>
+
+        <!-- csv -->
+        <dependency>
+            <groupId>com.opencsv</groupId>
+            <artifactId>opencsv</artifactId>
+            <version>3.8</version>
+        </dependency>
     </dependencies>
 
 

+ 1 - 1
src/main/java/io/renren/common/utils/ExcelUtils.java

@@ -106,7 +106,7 @@ public class ExcelUtils {
                     Double celldata = cellValue1.getNumberValue();
                     cellValue = celldata.toString();
                 }catch (Exception e) {
-                    System.out.println(JSON.toJSONString(e));
+                    System.out.println("错误");
                 }
                 break;
             case "BLANK":

+ 97 - 6
src/main/java/io/renren/modules/common/AspenController.java

@@ -1,6 +1,7 @@
 package io.renren.modules.common;
 
 import com.alibaba.fastjson.JSON;
+import com.opencsv.CSVReader;
 import io.renren.common.utils.ExcelUtils;
 import io.renren.modules.aspen.entity.TDashboarddataEntity;
 import io.renren.modules.aspen.service.TDashboarddataService;
@@ -16,6 +17,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.io.FileReader;
+import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 @Component
@@ -23,20 +27,94 @@ import java.util.List;
 @EnableScheduling   // 2.开启定时任务
 public class AspenController extends AbstractController {
 
-    @Autowired
-    private SysMenuService sysMenuService;
     @Autowired
     private TDashboarddataService tDashboarddataService;
 
     @Scheduled(cron = "0/15 * * * * ?")
 //    @Scheduled(cron = "0 */15 * * * ?")
     public void getExcelData(){
-        Workbook workbook = ExcelUtils.getWorkBook("D://ssyFile/bcc.xlsx");
+        String csvFile = "D://ssyFile/物料.csv";
+//        String csvFile = "C://dashboardAspen/wuliao.csv";
+        TDashboarddataEntity dashboarddataEntity = new TDashboarddataEntity();
+        CSVReader reader = null;
+        try {
+            reader = new CSVReader(new FileReader(csvFile));
+            String[] line;
+            //定义行数
+            int i = 0;
+            while ((line = reader.readNext()) != null) {
+                if (i == 4) {
+                    logger.info("第" + i + "行");
+                    for (int j = 0; j < 16; j++) {
+                        logger.info("读数:" + line[j]);
+                        if (line[j].equals("")) {
+                            line[j] = "0.0";
+                        }else {
+                            if (!Character.isDigit(line[j].charAt(0))) {
+                                line[j] = "0.0";
+                            }else {
+                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
+                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                                line[j] = String.valueOf(f);
+                            }
+                        }
+                        logger.info(line[j]);
+                    }
+                    dashboarddataEntity.setEnergyYixi(line[0]);
+                    dashboarddataEntity.setEnergyBingxi(line[1]);
+                    dashboarddataEntity.setEnergyQingqi(line[2]);
+                    dashboarddataEntity.setEnergyJiawan(line[3]);
+                    dashboarddataEntity.setEnergyOffgas(line[4]);
+                    dashboarddataEntity.setEnergyLpg(line[5]);
+                    dashboarddataEntity.setEnergyCsi(line[6]);
+                    dashboarddataEntity.setEnergyBenzene(line[7]);
+                    dashboarddataEntity.setEnergyToluene(line[8]);
+                    dashboarddataEntity.setEnergyXylene(line[9]);
+                    dashboarddataEntity.setEnergyTanliu(line[10]);
+                    dashboarddataEntity.setEnergyWashoil(line[11]);
+                    dashboarddataEntity.setEnergyTanwu(line[12]);
+                    dashboarddataEntity.setEnergyIma(line[13]);
+                    dashboarddataEntity.setEnergyCjiu(line[14]);
+                    dashboarddataEntity.setEnergyRpg(line[15]);
+                }
+                if (i == 11) {
+                    logger.info("第" + i + "行");
+                    for (int j = 0; j < 5; j++) {
+                        logger.info("读数:" + line[j]);
+                        if (line[j].equals("")) {
+                            line[j] = "0.0";
+                        }else {
+                            if (!Character.isDigit(line[j].charAt(0))) {
+                                line[j] = "0.0";
+                            }else {
+                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
+                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                                line[j] = String.valueOf(f);
+                            }
+                        }
+                        logger.info(line[j]);
+                    }
+                    dashboarddataEntity.setEnergyfeedNap(line[0]);
+                    dashboarddataEntity.setEnergyfeedYiwan(line[1]);
+                    dashboarddataEntity.setEnergyfeedTanwu(line[2]);
+                    dashboarddataEntity.setEnergyfeedTanliu(line[3]);
+                    dashboarddataEntity.setEnergyfeedLpg(line[4]);
+                }
+                i++;
+            }
+            dashboarddataEntity.setCreatedate(new Date());
+            logger.info("dashboardData:" + dashboarddataEntity);
+            tDashboarddataService.save(dashboarddataEntity);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        /*Workbook workbook = ExcelUtils.getWorkBook("B://GLOBAL/7430-BYC/NANJING/CB/CBP/CBP_C/15 CBP Cracker Share 乙烯装置共享文件夹/Dashboard data/物料.xlsx");
+//        Workbook workbook = ExcelUtils.getWorkBook("D://ssyFile/ceshi.xlsx");
         Sheet sheet = workbook.getSheetAt(0);
-        int rowNum = sheet.getPhysicalNumberOfRows();
+        int rowNum = sheet.getLastRowNum();
         TDashboarddataEntity dashboarddataEntity = new TDashboarddataEntity();
         logger.info("rowNum:" + rowNum);
-        for (int i = 0; i < rowNum; i++) {
+        for (int i = 0; i <= rowNum; i++) {
             if (i == 0) {
                 logger.info("i:" + i);
                 Row row = sheet.getRow(i);
@@ -92,6 +170,19 @@ public class AspenController extends AbstractController {
                     }
                 }
             }
+            if (i == 6) {
+                logger.info("i:" + i);
+                Row row = sheet.getRow(i);
+                int cellNum = row.getLastCellNum();
+                for (int j = 0; j <= cellNum; j++) {
+                    if (j == 0) {
+                        logger.info("==========");
+                    }
+                    Cell cell = row.getCell(j);
+                    String cellValue = ExcelUtils.getCellValue(cell);
+
+                }
+            }
             if (i == 11) {
                 logger.info("i:" + i);
                 Row row = sheet.getRow(i);
@@ -115,6 +206,6 @@ public class AspenController extends AbstractController {
         }
         dashboarddataEntity.setCreatedate(new Date());
         logger.info("dashboardData:" + dashboarddataEntity);
-        tDashboarddataService.save(dashboarddataEntity);
+        tDashboarddataService.save(dashboarddataEntity);*/
     }
 }