Commit 2beb31d3 by 余根龙

增加fast

parent 10f8b792
...@@ -31,12 +31,12 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> { ...@@ -31,12 +31,12 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
//String path = ".\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties"; //String path = ".\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties";
connection = MySQLUtils.getConnection(); connection = MySQLUtils.getConnection();
String cycleSql="insert into app_cycle_green_ratio" + String cycleSql="insert into app_cycle_green_ratio" +
"(id,cross_code,signal_code,begin_time,end_time,duration,cycle_order,green_ratio,loss_time,update_time) " + "(id,cross_id,signal_code,begin_time,end_time,duration,cycle_order,green_ratio,loss_time,statistic_time,record_date,p_month) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
insertCyclePstmt = connection.prepareStatement(cycleSql); insertCyclePstmt = connection.prepareStatement(cycleSql);
String phaseSql="insert into app_phase_green_ratio(cycle_order,cross_code,phase_value,begin_time,end_time,duration,phase_order,green_ratio,valid_green,loss_time,update_time) values (?,?,?,?,?,?,?,?,?,?,?)"; //String phaseSql="insert into app_phase_green_ratio(cycle_order,cross_code,phase_value,begin_time,end_time,duration,phase_order,green_ratio,valid_green,loss_time,update_time) values (?,?,?,?,?,?,?,?,?,?,?)";
insertPhasePstmt = connection.prepareStatement(phaseSql); //insertPhasePstmt = connection.prepareStatement(phaseSql);
} }
@Override @Override
public void close() throws Exception { public void close() throws Exception {
...@@ -57,24 +57,27 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> { ...@@ -57,24 +57,27 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
insertCyclePstmt.setDouble(8, cycle.getGreenRatio()); insertCyclePstmt.setDouble(8, cycle.getGreenRatio());
insertCyclePstmt.setInt(9, cycle.getLossTime()); insertCyclePstmt.setInt(9, cycle.getLossTime());
insertCyclePstmt.setString(10, DateUtils.getTodayTime()); insertCyclePstmt.setString(10, DateUtils.getTodayTime());
insertCyclePstmt.setString(11, DateUtils.getTodayDate());
insertCyclePstmt.setString(12, DateUtils.getCurrentMonth());
insertCyclePstmt.execute(); insertCyclePstmt.execute();
List<Stage> stageList = cycle.getStageList();
for(int i=0;i<stageList.size();i++){ //List<Stage> stageList = cycle.getStageList();
Stage phase = stageList.get(i); //for(int i=0;i<stageList.size();i++){
insertPhasePstmt.setLong(1,cycle.getCycleOrder()); // Stage phase = stageList.get(i);
insertPhasePstmt.setString(2,cycle.getCrossCode()); // insertPhasePstmt.setLong(1,cycle.getCycleOrder());
insertPhasePstmt.setString(3,phase.getPhaseValue()); // insertPhasePstmt.setString(2,cycle.getCrossCode());
insertPhasePstmt.setString(4, cycle.getBeginDateTime()); // insertPhasePstmt.setString(3,phase.getPhaseValue());
insertPhasePstmt.setString(5, cycle.getEndDateTime()); // insertPhasePstmt.setString(4, cycle.getBeginDateTime());
insertPhasePstmt.setInt(6,cycle.getDuration()); // insertPhasePstmt.setString(5, cycle.getEndDateTime());
insertPhasePstmt.setInt(7,phase.getPhaseOrder()); // insertPhasePstmt.setInt(6,cycle.getDuration());
insertPhasePstmt.setDouble(8,phase.getGreenRatio()); // insertPhasePstmt.setInt(7,phase.getPhaseOrder());
insertPhasePstmt.setInt(9,phase.getValidGreen()); // insertPhasePstmt.setDouble(8,phase.getGreenRatio());
insertPhasePstmt.setInt(10,phase.getLossTime()); // insertPhasePstmt.setInt(9,phase.getValidGreen());
insertPhasePstmt.setString(11, DateUtils.getTodayTime()); // insertPhasePstmt.setInt(10,phase.getLossTime());
insertPhasePstmt.addBatch(); // insertPhasePstmt.setString(11, DateUtils.getTodayTime());
} // insertPhasePstmt.addBatch();
insertPhasePstmt.executeBatch(); //}
insertPhasePstmt.clearBatch(); //insertPhasePstmt.executeBatch();
//insertPhasePstmt.clearBatch();
} }
} }
...@@ -1058,7 +1058,7 @@ public class DateUtils { ...@@ -1058,7 +1058,7 @@ public class DateUtils {
* 例如 202211 * 例如 202211
* @return * @return
*/ */
public static String getCurrentMonthPartition() { public static String getCurrentMonth() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return simpleDateFormat.format(new Date()); return simpleDateFormat.format(new Date());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment