Commit 632a93a0305c2c8b34e9f423daf59d5c76a5623a

Authored by 廖磊
2 parents 56750772 d2dcc317

Merge branch 'minhang' of

http://222.66.0.204:8090/panzhaov5/bsth_control into minhang
@@ -259,11 +259,11 @@ @@ -259,11 +259,11 @@
259 </dependency> 259 </dependency>
260 260
261 261
262 - <!--<dependency>-->  
263 - <!--<groupId>ojdbc</groupId>-->  
264 - <!--<artifactId>ojdbc</artifactId>-->  
265 - <!--<version>14</version>-->  
266 - <!--</dependency>--> 262 + <dependency>
  263 + <groupId>ojdbc</groupId>
  264 + <artifactId>ojdbc</artifactId>
  265 + <version>14</version>
  266 + </dependency>
267 </dependencies> 267 </dependencies>
268 268
269 <dependencyManagement> 269 <dependencyManagement>
src/main/java/com/bsth/data/gpsdata/arrival/handlers/OfflineSignalHandle.java
@@ -30,7 +30,8 @@ public class OfflineSignalHandle extends SignalHandle{ @@ -30,7 +30,8 @@ public class OfflineSignalHandle extends SignalHandle{
30 30
31 if(isNotEmpty(prevs)){ 31 if(isNotEmpty(prevs)){
32 GpsEntity prev = prevs.getTail(); 32 GpsEntity prev = prevs.getTail();
33 - int space = (int) (gps.getTimestamp() - prev.getTimestamp()); 33 + //间隔太大就丢弃,不管之前还是之后
  34 + int space = Math.abs((int) (gps.getTimestamp() - prev.getTimestamp()));
34 if(space > OFFLINE_TIME) 35 if(space > OFFLINE_TIME)
35 gps.setSignalState("reconnection"); 36 gps.setSignalState("reconnection");
36 37
src/main/java/com/bsth/entity/schedule/SchedulePlan.java
@@ -2,8 +2,11 @@ package com.bsth.entity.schedule; @@ -2,8 +2,11 @@ package com.bsth.entity.schedule;
2 2
3 import com.bsth.entity.Line; 3 import com.bsth.entity.Line;
4 import com.fasterxml.jackson.annotation.JsonIgnore; 4 import com.fasterxml.jackson.annotation.JsonIgnore;
  5 +import org.apache.commons.lang3.BooleanUtils;
5 6
6 import javax.persistence.*; 7 import javax.persistence.*;
  8 +import java.sql.PreparedStatement;
  9 +import java.sql.SQLException;
7 import java.util.ArrayList; 10 import java.util.ArrayList;
8 import java.util.Date; 11 import java.util.Date;
9 import java.util.List; 12 import java.util.List;
@@ -53,6 +56,30 @@ public class SchedulePlan extends BEntity { @@ -53,6 +56,30 @@ public class SchedulePlan extends BEntity {
53 @OneToMany(mappedBy = "schedulePlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY) 56 @OneToMany(mappedBy = "schedulePlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
54 private List<SchedulePlanInfo> schedulePlanInfoList = new ArrayList<>(); 57 private List<SchedulePlanInfo> schedulePlanInfoList = new ArrayList<>();
55 58
  59 +
  60 + public static String generateInsertSql() {
  61 + String sql = "insert into bsth_c_s_sp " +
  62 + " (xl, schedule_from_time, schedule_to_time, " +
  63 + "tt_info_names, tt_info_ids, is_history_plan_first, plan_result, " +
  64 + "create_by, update_by, create_date, update_date) " +
  65 + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  66 + return sql;
  67 + }
  68 +
  69 + public void preparedStatementSet(PreparedStatement ps) throws SQLException {
  70 + ps.setInt(1, this.xl.getId());
  71 + ps.setDate(2, new java.sql.Date(this.scheduleFromTime.getTime()));
  72 + ps.setDate(3, new java.sql.Date(this.scheduleToTime.getTime()));
  73 + ps.setString(4, this.ttInfoNames);
  74 + ps.setString(5, this.ttInfoIds);
  75 + ps.setInt(6, BooleanUtils.isTrue(this.isHistoryPlanFirst) ? 1 : 0);
  76 + ps.setString(7, this.planResult);
  77 + ps.setInt(8, this.getCreateBy().getId());
  78 + ps.setInt(9, this.getUpdateBy().getId());
  79 + ps.setTimestamp(10, new java.sql.Timestamp(this.getCreateDate().getTime()));
  80 + ps.setTimestamp(11, new java.sql.Timestamp(this.getUpdateDate().getTime()));
  81 + }
  82 +
56 public Long getId() { 83 public Long getId() {
57 return id; 84 return id;
58 } 85 }
src/main/java/com/bsth/entity/schedule/SchedulePlanInfo.java
@@ -6,6 +6,9 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; @@ -6,6 +6,9 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
6 import org.apache.commons.lang3.StringUtils; 6 import org.apache.commons.lang3.StringUtils;
7 7
8 import javax.persistence.*; 8 import javax.persistence.*;
  9 +import java.sql.PreparedStatement;
  10 +import java.sql.SQLException;
  11 +import java.sql.Types;
9 import java.util.Date; 12 import java.util.Date;
10 import java.util.List; 13 import java.util.List;
11 14
@@ -148,12 +151,15 @@ public class SchedulePlanInfo { @@ -148,12 +151,15 @@ public class SchedulePlanInfo {
148 private Date updateDate; 151 private Date updateDate;
149 152
150 153
  154 +// @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
  155 +// @JoinTable(
  156 +// name = "bsth_c_s_sp_r_info",
  157 +// joinColumns = @JoinColumn(name = "sp_info_id"),
  158 +// inverseJoinColumns = @JoinColumn(name = "sp_id")
  159 +// )
  160 +// private SchedulePlan schedulePlan;
  161 +
151 @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) 162 @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
152 - @JoinTable(  
153 - name = "bsth_c_s_sp_r_info",  
154 - joinColumns = @JoinColumn(name = "sp_info_id"),  
155 - inverseJoinColumns = @JoinColumn(name = "sp_id")  
156 - )  
157 private SchedulePlan schedulePlan; 163 private SchedulePlan schedulePlan;
158 164
159 public SchedulePlanInfo() {} 165 public SchedulePlanInfo() {}
@@ -302,6 +308,62 @@ public class SchedulePlanInfo { @@ -302,6 +308,62 @@ public class SchedulePlanInfo {
302 308
303 } 309 }
304 310
  311 + public static String generateInsertSql() {
  312 + String sql = "insert into bsth_c_s_sp_info " +
  313 + " (schedule_date, gs_name, gs_bm, fgs_name, fgs_bm, ccno, " +
  314 + "xl, xl_name, xl_bm, lp, lp_name, cl, cl_zbh, bd_time, cc_time, " +
  315 + "j, j_gh, j_name, s, s_gh, s_name, " +
  316 + "xl_dir, qdz_code, qdz_name, zdz_code, zdz_name, " +
  317 + "fcsj, fcno, bcs, jhlc, bcsj, bc_type, " +
  318 + "tt_info, tt_info_name, remark, schedule_plan, " +
  319 + "create_by, update_by, create_date, update_date) " +
  320 + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
  321 + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  322 + return sql;
  323 + }
  324 +
  325 + public void preparedStatementSet(PreparedStatement ps) throws SQLException {
  326 + if (this.scheduleDate != null) ps.setDate(1, new java.sql.Date(this.scheduleDate.getTime())); else ps.setNull(1, Types.DATE);
  327 + if (this.gsName != null) ps.setString(2, this.gsName); else ps.setNull(2, Types.VARCHAR);
  328 + if (this.gsBm != null) ps.setString(3, this.gsBm); else ps.setNull(3, Types.VARCHAR);
  329 + if (this.fgsName != null) ps.setString(4, this.fgsName); else ps.setNull(4, Types.VARCHAR);
  330 + if (this.fgsBm != null) ps.setString(5, this.fgsBm); else ps.setNull(5, Types.VARCHAR);
  331 + if (this.ccno != null) ps.setInt(6, this.ccno); else ps.setNull(6, Types.INTEGER);
  332 + if (this.xl != null) ps.setInt(7, this.xl); else ps.setNull(7, Types.INTEGER);
  333 + if (this.xlName != null) ps.setString(8, this.xlName); else ps.setNull(8, Types.VARCHAR);
  334 + if (this.xlBm != null) ps.setString(9, this.xlBm); else ps.setNull(9, Types.VARCHAR);
  335 + if (this.lp != null) ps.setLong(10, this.lp); else ps.setNull(10, Types.BIGINT);
  336 + if (this.lpName != null) ps.setString(11, this.lpName); else ps.setNull(11, Types.VARCHAR);
  337 + if (this.cl != null) ps.setInt(12, this.cl); else ps.setNull(12, Types.INTEGER);
  338 + if (this.clZbh != null) ps.setString(13, this.clZbh); else ps.setNull(13, Types.VARCHAR);
  339 + if (this.bdTime != null) ps.setString(14, this.bdTime); else ps.setNull(14, Types.VARCHAR);
  340 + if (this.ccTime != null) ps.setString(15, this.ccTime); else ps.setNull(15, Types.VARCHAR);
  341 + if (this.j != null) ps.setInt(16, this.j); else ps.setNull(16, Types.INTEGER);
  342 + if (this.jGh != null) ps.setString(17, this.jGh); else ps.setNull(17, Types.VARCHAR);
  343 + if (this.jName != null) ps.setString(18, this.jName); else ps.setNull(18, Types.VARCHAR);
  344 + if (this.s != null) ps.setInt(19, this.s); else ps.setNull(19, Types.INTEGER);
  345 + if (this.sGh != null) ps.setString(20, this.sGh); else ps.setNull(20, Types.VARCHAR);
  346 + if (this.sName != null) ps.setString(21, this.sName); else ps.setNull(21, Types.VARCHAR);
  347 + if (this.xlDir != null) ps.setString(22, this.xlDir); else ps.setNull(22, Types.VARCHAR);
  348 + if (this.qdzCode != null) ps.setString(23, this.qdzCode); else ps.setNull(23, Types.VARCHAR);
  349 + if (this.qdzName != null) ps.setString(24, this.qdzName); else ps.setNull(24, Types.VARCHAR);
  350 + if (this.zdzCode != null) ps.setString(25, this.zdzCode); else ps.setNull(25, Types.VARCHAR);
  351 + if (this.zdzName != null) ps.setString(26, this.zdzName); else ps.setNull(26, Types.VARCHAR);
  352 + if (this.fcsj != null) ps.setString(27, this.fcsj); else ps.setNull(27, Types.VARCHAR);
  353 + if (this.fcno != null) ps.setInt(28, this.fcno); else ps.setNull(28, Types.INTEGER);
  354 + if (this.bcs != null) ps.setInt(29, this.bcs); else ps.setNull(29, Types.INTEGER);
  355 + if (this.jhlc != null) ps.setDouble(30, this.jhlc); else ps.setNull(30, Types.DOUBLE);
  356 + if (this.bcsj != null) ps.setInt(31, this.bcsj); else ps.setNull(31, Types.INTEGER);
  357 + if (this.bcType != null) ps.setString(32, this.bcType); else ps.setNull(32, Types.VARCHAR);
  358 + if (this.ttInfo != null) ps.setLong(33, this.ttInfo); else ps.setNull(33, Types.BIGINT);
  359 + if (this.ttInfoName != null) ps.setString(34, this.ttInfoName); else ps.setNull(34, Types.VARCHAR);
  360 + if (this.remark != null) ps.setString(35, this.remark); else ps.setNull(35, Types.VARCHAR);
  361 + if (this.schedulePlan != null) ps.setLong(36, this.schedulePlan.getId()); else ps.setNull(36, Types.BIGINT);
  362 + if (this.createBy != null) ps.setInt(37, this.createBy.getId()); else ps.setNull(37, Types.INTEGER);
  363 + if (this.updateBy != null) ps.setInt(38, this.updateBy.getId()); else ps.setNull(38, Types.INTEGER);
  364 + if (this.createDate != null) ps.setTimestamp(39, new java.sql.Timestamp(this.createDate.getTime())); else ps.setNull(39, Types.TIMESTAMP);
  365 + if (this.updateDate != null) ps.setTimestamp(40, new java.sql.Timestamp(this.updateDate.getTime())); else ps.setNull(40, Types.TIMESTAMP);
  366 + }
305 367
306 public Long getId() { 368 public Long getId() {
307 return id; 369 return id;
src/main/java/com/bsth/repository/schedule/SchedulePlanInfoRepository.java
@@ -24,8 +24,6 @@ public interface SchedulePlanInfoRepository extends BaseRepository&lt;SchedulePlanI @@ -24,8 +24,6 @@ public interface SchedulePlanInfoRepository extends BaseRepository&lt;SchedulePlanI
24 @Query(value = "select s from SchedulePlanInfo s where scheduleDate=?1") 24 @Query(value = "select s from SchedulePlanInfo s where scheduleDate=?1")
25 List<SchedulePlanInfo> findByDate(Date date); 25 List<SchedulePlanInfo> findByDate(Date date);
26 26
27 - Long deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual(Integer xlid, Date startDate, Date endDate);  
28 -  
29 @Query(value = " select " + 27 @Query(value = " select " +
30 "info.xl as xlId, " + 28 "info.xl as xlId, " +
31 "info.xl_name as xlName, " + 29 "info.xl_name as xlName, " +
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
@@ -8,6 +8,7 @@ import com.bsth.repository.LineRepository; @@ -8,6 +8,7 @@ import com.bsth.repository.LineRepository;
8 import com.bsth.repository.schedule.*; 8 import com.bsth.repository.schedule.*;
9 import com.bsth.service.schedule.SchedulePlanRuleResultService; 9 import com.bsth.service.schedule.SchedulePlanRuleResultService;
10 import com.bsth.service.schedule.SchedulePlanService; 10 import com.bsth.service.schedule.SchedulePlanService;
  11 +import com.bsth.service.schedule.exception.ScheduleException;
11 import com.bsth.service.schedule.rules.ScheduleRuleService; 12 import com.bsth.service.schedule.rules.ScheduleRuleService;
12 import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input; 13 import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input;
13 import com.bsth.service.schedule.rules.plan.PlanResult; 14 import com.bsth.service.schedule.rules.plan.PlanResult;
@@ -24,9 +25,6 @@ import org.slf4j.Logger; @@ -24,9 +25,6 @@ import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory; 25 import org.slf4j.LoggerFactory;
25 import org.springframework.beans.factory.annotation.Autowired; 26 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Service; 27 import org.springframework.stereotype.Service;
27 -import org.springframework.transaction.annotation.Isolation;  
28 -import org.springframework.transaction.annotation.Propagation;  
29 -import org.springframework.transaction.annotation.Transactional;  
30 28
31 import java.util.*; 29 import java.util.*;
32 30
@@ -216,32 +214,53 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im @@ -216,32 +214,53 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
216 214
217 } 215 }
218 216
219 - @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)  
220 public SchedulePlan save(SchedulePlan schedulePlan) { 217 public SchedulePlan save(SchedulePlan schedulePlan) {
221 // pre、如果排班的数据之前已经有了,删除之前的数据 218 // pre、如果排班的数据之前已经有了,删除之前的数据
222 - schedulePlanInfoRepository.deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual(  
223 - schedulePlan.getXl().getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime()  
224 - ); 219 + Date startpre = new Date();
  220 + scheduleRuleService.deelteSchedulePlanInfo(
  221 + schedulePlan.getXl().getId(),
  222 + schedulePlan.getScheduleFromTime(),
  223 + schedulePlan.getScheduleToTime());
  224 + Date endpre = new Date();
225 225
226 // 1、时刻表数据及每日路牌数据计算 226 // 1、时刻表数据及每日路牌数据计算
  227 + Date start1 = new Date();
227 Object[] ttInfoRets = ttInfoOutput(schedulePlan); 228 Object[] ttInfoRets = ttInfoOutput(schedulePlan);
228 TTInfoResults_output ttInfoResults_output = (TTInfoResults_output) ttInfoRets[0]; 229 TTInfoResults_output ttInfoResults_output = (TTInfoResults_output) ttInfoRets[0];
229 LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1]; 230 LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1];
  231 + Date end1 = new Date();
230 // 2、循环规则计算输出 232 // 2、循环规则计算输出
  233 + Date start2 = new Date();
231 ScheduleResults_output scheduleResults_output = loopRuleOutput(schedulePlan, lpInfoResults_output); 234 ScheduleResults_output scheduleResults_output = loopRuleOutput(schedulePlan, lpInfoResults_output);
  235 + Date end2 = new Date();
232 // 3、计划输出 236 // 3、计划输出
  237 + Date start3 = new Date();
233 PlanResult planResult = planResultOutput(schedulePlan, scheduleResults_output, ttInfoResults_output); 238 PlanResult planResult = planResultOutput(schedulePlan, scheduleResults_output, ttInfoResults_output);
  239 + Date end3 = new Date();
  240 +
  241 + // 4、保存数据(jdbcTemplate 批量插入)
  242 + Date start4 = new Date();
  243 + scheduleRuleService.generateSchedulePlan(schedulePlan, planResult.getSchedulePlanInfos());
  244 + Date end4 = new Date();
  245 +
234 246
235 - // 4、保存数据(TODO:之后改成批量保存)  
236 - schedulePlan.getSchedulePlanInfoList().addAll(planResult.getSchedulePlanInfos());  
237 - super.save(schedulePlan); 247 + logger.info("删除数据 {} ms,drool时刻表每日路牌计算 {} ms,drool循环规则计算 {} ms,drool计划数据 {} ms,插入数据 {} ms",
  248 + endpre.getTime() - startpre.getTime(),
  249 + end1.getTime() - start1.getTime(),
  250 + end2.getTime() - start2.getTime(),
  251 + end3.getTime() - start3.getTime(),
  252 + end4.getTime() - start4.getTime());
238 253
239 - schedulePlanRuleResultService.bulkSave(scheduleResults_output.getSchedulePlanRuleResults());  
240 254
241 return new SchedulePlan(); 255 return new SchedulePlan();
242 } 256 }
243 257
244 @Override 258 @Override
  259 + public void delete(Long aLong) throws ScheduleException {
  260 + scheduleRuleService.deleteSchedulePlanAll(aLong);
  261 + }
  262 +
  263 + @Override
245 public SchedulePlan findSchedulePlanTommorw() { 264 public SchedulePlan findSchedulePlanTommorw() {
246 DateTime today = new DateTime(new Date()); 265 DateTime today = new DateTime(new Date());
247 DateTime tommorw = new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0).plusDays(1); 266 DateTime tommorw = new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0).plusDays(1);
src/main/java/com/bsth/service/schedule/rules/ScheduleRuleService.java
1 package com.bsth.service.schedule.rules; 1 package com.bsth.service.schedule.rules;
2 2
  3 +import com.bsth.entity.schedule.SchedulePlan;
  4 +import com.bsth.entity.schedule.SchedulePlanInfo;
3 import com.bsth.entity.schedule.temp.SchedulePlanRuleResult; 5 import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
4 6
5 import java.util.Date; 7 import java.util.Date;
@@ -19,4 +21,26 @@ public interface ScheduleRuleService { @@ -19,4 +21,26 @@ public interface ScheduleRuleService {
19 * @return 21 * @return
20 */ 22 */
21 List<SchedulePlanRuleResult> findLastByXl(String xlid, Date from); 23 List<SchedulePlanRuleResult> findLastByXl(String xlid, Date from);
  24 +
  25 + /**
  26 + * 生成排班计划。
  27 + * @param schedulePlan 计划主表
  28 + * @param schedulePlanInfos 计划明细表
  29 + */
  30 + void generateSchedulePlan(SchedulePlan schedulePlan, List<SchedulePlanInfo> schedulePlanInfos);
  31 +
  32 + /**
  33 + * 删除排班计划。
  34 + * @param id 排班计划id
  35 + */
  36 + void deleteSchedulePlanAll(Long id);
  37 +
  38 + /**
  39 + * 删除指定时间范围的排班明细。
  40 + * @param xlid 线路id
  41 + * @param datefrom 开始日期
  42 + * @param dateto 结束日期
  43 + */
  44 + void deelteSchedulePlanInfo(Integer xlid, Date datefrom, Date dateto);
22 } 45 }
  46 +
src/main/java/com/bsth/service/schedule/rules/ScheduleRuleServiceImpl.java
1 package com.bsth.service.schedule.rules; 1 package com.bsth.service.schedule.rules;
2 2
  3 +import com.bsth.entity.schedule.SchedulePlan;
  4 +import com.bsth.entity.schedule.SchedulePlanInfo;
3 import com.bsth.entity.schedule.temp.SchedulePlanRuleResult; 5 import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
4 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
5 import org.springframework.jdbc.core.JdbcTemplate; 10 import org.springframework.jdbc.core.JdbcTemplate;
  11 +import org.springframework.jdbc.core.PreparedStatementCreator;
6 import org.springframework.jdbc.core.RowMapper; 12 import org.springframework.jdbc.core.RowMapper;
  13 +import org.springframework.jdbc.support.GeneratedKeyHolder;
  14 +import org.springframework.jdbc.support.KeyHolder;
7 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
  16 +import org.springframework.transaction.annotation.Isolation;
  17 +import org.springframework.transaction.annotation.Propagation;
  18 +import org.springframework.transaction.annotation.Transactional;
8 19
  20 +import java.sql.Connection;
  21 +import java.sql.PreparedStatement;
9 import java.sql.ResultSet; 22 import java.sql.ResultSet;
10 import java.sql.SQLException; 23 import java.sql.SQLException;
  24 +import java.util.ArrayList;
11 import java.util.Date; 25 import java.util.Date;
12 import java.util.List; 26 import java.util.List;
13 27
@@ -16,6 +30,8 @@ import java.util.List; @@ -16,6 +30,8 @@ import java.util.List;
16 */ 30 */
17 @Service 31 @Service
18 public class ScheduleRuleServiceImpl implements ScheduleRuleService { 32 public class ScheduleRuleServiceImpl implements ScheduleRuleService {
  33 + /** 日志记录器 */
  34 + private static final Logger logger = LoggerFactory.getLogger(ScheduleRuleServiceImpl.class);
19 35
20 @Autowired 36 @Autowired
21 private JdbcTemplate jdbcTemplate; 37 private JdbcTemplate jdbcTemplate;
@@ -43,4 +59,70 @@ public class ScheduleRuleServiceImpl implements ScheduleRuleService { @@ -43,4 +59,70 @@ public class ScheduleRuleServiceImpl implements ScheduleRuleService {
43 } 59 }
44 }); 60 });
45 } 61 }
  62 +
  63 + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
  64 + public void deleteSchedulePlanAll(Long id) {
  65 + String sql1 = "delete from bsth_c_s_sp where id = ?";
  66 + String sql2 = "delete from bsth_c_s_sp_info where schedule_plan = ?";
  67 +
  68 + jdbcTemplate.update(sql2, id);
  69 + jdbcTemplate.update(sql1, id);
  70 + }
  71 +
  72 + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
  73 + public void deelteSchedulePlanInfo(Integer xlid, Date datefrom, Date dateto) {
  74 + String sql = "delete from bsth_c_s_sp_info where xl = ? and schedule_date >= ? and schedule_date <= ?";
  75 + jdbcTemplate.update(sql, xlid, datefrom, dateto);
  76 + }
  77 +
  78 + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
  79 + @Override
  80 + public void generateSchedulePlan(final SchedulePlan schedulePlan, final List<SchedulePlanInfo> schedulePlanInfos) {
  81 + // 1、插入排班计划主表,并获取主键id
  82 + KeyHolder keyHolder = new GeneratedKeyHolder();
  83 + jdbcTemplate.update(new PreparedStatementCreator() {
  84 + @Override
  85 + public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
  86 + PreparedStatement ps = connection.prepareStatement(
  87 + SchedulePlan.generateInsertSql(), new String[] {"id"});
  88 + schedulePlan.preparedStatementSet(ps);
  89 +
  90 + return ps;
  91 + }
  92 + }, keyHolder);
  93 +
  94 + SchedulePlan master = new SchedulePlan();
  95 + master.setId(keyHolder.getKey().longValue());
  96 + for (SchedulePlanInfo schedulePlanInfo : schedulePlanInfos) {
  97 + schedulePlanInfo.setSchedulePlan(master);
  98 + }
  99 +
  100 + // 2、批量插入排班计划从表
  101 + List<List<SchedulePlanInfo>> lists = new ArrayList<>();
  102 + int batchSize = 2000;
  103 + int loopCount = schedulePlanInfos.size() / batchSize;
  104 + int otherCount = schedulePlanInfos.size() % batchSize;
  105 + for (int i = 0; i < loopCount; i++) {
  106 + lists.add(schedulePlanInfos.subList(i * batchSize, i * batchSize + batchSize));
  107 + }
  108 + if (otherCount > 0) {
  109 + lists.add(schedulePlanInfos.subList(loopCount * batchSize, loopCount * batchSize + otherCount));
  110 + }
  111 +
  112 + for (final List<SchedulePlanInfo> list : lists) {
  113 + jdbcTemplate.batchUpdate(SchedulePlanInfo.generateInsertSql(), new BatchPreparedStatementSetter() {
  114 + @Override
  115 + public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
  116 + SchedulePlanInfo schedulePlanInfo = list.get(i);
  117 + schedulePlanInfo.preparedStatementSet(preparedStatement);
  118 + }
  119 + @Override
  120 + public int getBatchSize() {
  121 + return list.size();
  122 + }
  123 + });
  124 + }
  125 +
  126 + }
46 } 127 }
  128 +
src/main/java/com/bsth/util/db/DBUtils_oldSystem.java
@@ -50,8 +50,8 @@ public class DBUtils_oldSystem { @@ -50,8 +50,8 @@ public class DBUtils_oldSystem {
50 pool_conf.put("testConnectionOnCheckout", false); 50 pool_conf.put("testConnectionOnCheckout", false);
51 //异步检测连接的有效性 51 //异步检测连接的有效性
52 pool_conf.put("testConnectionOnCheckin", true); 52 pool_conf.put("testConnectionOnCheckin", true);
53 - //10分钟检测一次  
54 - pool_conf.put("idleConnectionTestPeriod", 60 * 10); 53 + //30秒检测一次
  54 + pool_conf.put("idleConnectionTestPeriod", 30);
55 ds_pooled = DataSources.pooledDataSource(ds_unpooled, pool_conf); 55 ds_pooled = DataSources.pooledDataSource(ds_unpooled, pool_conf);
56 } catch (ClassNotFoundException e) { 56 } catch (ClassNotFoundException e) {
57 logger.error(e.toString()); 57 logger.error(e.toString());
src/main/resources/static/real_control_v2/mapmonitor/fragments/playback_v2/main.html
@@ -858,6 +858,7 @@ @@ -858,6 +858,7 @@
858 upDown = roadUpdown; 858 upDown = roadUpdown;
859 859
860 map.clearOverlays(); 860 map.clearOverlays();
  861 + parkPolygons = {};//清除停车场对照
861 //路段 862 //路段
862 drawRoadPolyline(upDown); 863 drawRoadPolyline(upDown);
863 //站点 864 //站点
src/test/resources/testdata/test5.txt 0 → 100644
  1 +update bsth_c_s_sp_info a
  2 +set a.schedule_plan = (
  3 +select sp_id from bsth_c_s_sp_r_info b where a.id = b.sp_info_id
  4 +)
  5 +where a.schedule_plan is null
  6 +
  7 +select count(*) from bsth_c_s_sp_info
  8 +where schedule_plan is null
0 \ No newline at end of file 9 \ No newline at end of file