Bladeren bron

查询优化

zyg 1 jaar geleden
bovenliggende
commit
3d4920e2bf

+ 7 - 13
hz-business/src/main/java/com/hz/business/service/impl/BatteryServiceImpl.java

@@ -24,7 +24,6 @@ import com.hz.business.req.*;
 import com.hz.business.req.BatteryParam;
 import com.hz.business.service.IBatteryService;
 import com.hz.business.util.CustomerTitleHandler;
-import com.hz.business.util.LindormUtil;
 import com.hz.business.util.PhoenixUtils;
 import com.hz.business.util.StrUtils;
 import com.hz.business.vo.*;
@@ -32,9 +31,7 @@ import com.hz.common.config.HzConfig;
 import com.hz.common.constant.Constants;
 import com.hz.common.core.domain.entity.SysDictData;
 import com.hz.common.utils.*;
-import com.hz.common.utils.bean.BeanCopier;
 import com.hz.system.mapper.SysDictDataMapper;
-import kotlin.collections.Grouping;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import com.hz.common.utils.bean.BeanUtils;
@@ -506,6 +503,7 @@ public class BatteryServiceImpl extends ServiceImpl<BatteryMapper, Battery> impl
                 .or().like("vin", param.getSn()));
         wrapper.in(!packList.isEmpty(), "pack_model_code", packList);
         wrapper.in(!cellList.isEmpty(), "cell_model_code", cellList);
+        wrapper.eq("is_delete", 0);
         wrapper.eq(StringUtils.isNotBlank(param.getBatteryCoreType()), "battery_core_type", param.getBatteryCoreType());
         wrapper.in(batteryIdSet.size() > 0, "id", batteryIdSet);
         wrapper.in((param.getFaultStatus() != null && param.getFaultStatus() == 1 && snSet.size() > 0), "sn", snSet);
@@ -2348,7 +2346,7 @@ public class BatteryServiceImpl extends ServiceImpl<BatteryMapper, Battery> impl
 
         // CellMaxVol,CellMinVol,CellMaxTemp,CellMinTemp,BmsCellVoltDiff,VehSpd
         builder.append("select SN,Time,PackVoltage,PackCrnt,PackSoc,CellVoltage,CellTemp,InsulationRss,Info from ")
-                .append(tableName).append(" where ");
+                .append(database+"."+tableName).append(" where ");
 
 
         if (param.getStartTime() == null && param.getEndTime() == null) {
@@ -2380,10 +2378,10 @@ public class BatteryServiceImpl extends ServiceImpl<BatteryMapper, Battery> impl
         PreparedStatement psSelect = null;
         try {
             conn = PhoenixUtils.getConnection();
-            psSelect = conn.prepareStatement(" use " + database + " ");
-            psSelect.setFetchSize(1000);
-            psSelect.execute();
-            psSelect.close();
+            //psSelect = conn.prepareStatement(" use " + database + " ");
+            //psSelect.setFetchSize(1000);
+            //psSelect.execute();
+            //psSelect.close();
             psSelect = conn.prepareStatement(builder.toString());
             ResultSet resultSet = psSelect.executeQuery();
             flinkDataList = convertList(resultSet);
@@ -3791,16 +3789,12 @@ public class BatteryServiceImpl extends ServiceImpl<BatteryMapper, Battery> impl
             String snKeyMin = snKey + "0";
             String snKeyMax = snKey + "a";
 
-            builder.append("select id,remain_odo from ").append(tableName);
+            builder.append("select id,remain_odo from ").append(database+"."+tableName);
             builder.append(" where id > '").append(snKeyMin).append("' and id < '")
                     .append(snKeyMax).append("'");
             builder.append(" order by id limit 1 ");
 
             conn = PhoenixUtils.getConnection();
-            psSelect = conn.prepareStatement(" use " + database + " ");
-            psSelect.setFetchSize(1000);
-            psSelect.execute();
-            psSelect.close();
             psSelect = conn.prepareStatement(builder.toString());
             ResultSet resultSet = psSelect.executeQuery();
             mapList = ResultSetToJson.toListMap(resultSet, false);

+ 7 - 4
hz-business/src/main/java/com/hz/business/util/PhoenixUtils.java

@@ -25,16 +25,19 @@ public class PhoenixUtils {
         return DriverManager.getConnection(PHOENIX_URL);
     }*/
 
-    static Properties properties;
+    static Properties props;
     static DataSource ds;
 
     static {
-        properties = new Properties();
+        props = new Properties();
         String fileName = "druid.yml";
         InputStream inputStream = PhoenixUtils.class.getClassLoader().getResourceAsStream(fileName);
         try {
-            properties.load(inputStream);
-            ds = DruidDataSourceFactory.createDataSource(properties);
+            props.load(inputStream);
+            props.setProperty("phoenix.query.timeoutMs", "1200000");
+            props.setProperty("hbase.rpc.timeout", "1200000");
+            props.setProperty("hbase.client.scanner.timeout.period", "1200000");
+            ds = DruidDataSourceFactory.createDataSource(props);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 1 - 3
hz-business/src/test/java/com/hz/TestLindorm.java

@@ -24,13 +24,11 @@ public class TestLindorm {
         try {
             Connection conn = PhoenixUtils.getConnection();
             Statement sta = conn.createStatement();
-            String sql = "select Time,SN,CellVoltage,Info,PackVoltage from vehicle_analysis.ods_signal_base order by SnKey desc  limit 10 ";
+            String sql = "select SN,Time,PackVoltage,PackCrnt,PackSoc,CellVoltage,CellTemp,InsulationRss,Info from vehicle_analysis.ods_signal_base where  SnKey<='1959277593_09SPE010DM0111C5S0000174_9223370357526775807' and  SnKey>='1959277593_09SPE010DM0111C5S0000174_9223370357094776807' limit 2000";
             ResultSet rs = sta.executeQuery(sql.toUpperCase());
             while (rs.next()) {
                 System.out.println(rs.getString("SN"));
-                System.out.println(rs.getString("CellVoltage"));
                 System.out.println(rs.getString("TIME"));
-                System.out.println(rs.getString("Time"));
             }
             conn.close();
             sta.close();