Commit 269f72383a889baa4bab974dea1aa0d9d2586839
Merge branch 'minhang' of
http://222.66.0.204:8090/panzhaov5/bsth_control into minhang
Showing
24 changed files
with
905 additions
and
35 deletions
Too many changes to show.
To preserve performance only 24 of 49 files are displayed.
.gitignore
pom.xml
| ... | ... | @@ -292,6 +292,13 @@ |
| 292 | 292 | <artifactId>mina-core</artifactId> |
| 293 | 293 | <version>2.0.13</version> |
| 294 | 294 | </dependency> |
| 295 | + | |
| 296 | + <dependency> | |
| 297 | + <groupId>com.google.protobuf</groupId> | |
| 298 | + <artifactId>protobuf-java</artifactId> | |
| 299 | + <version>3.3.0</version> | |
| 300 | + </dependency> | |
| 301 | + | |
| 295 | 302 | </dependencies> |
| 296 | 303 | |
| 297 | 304 | <dependencyManagement> | ... | ... |
src/main/java/com/bsth/Application.java
| ... | ... | @@ -10,6 +10,8 @@ import org.springframework.context.annotation.Bean; |
| 10 | 10 | import org.springframework.context.annotation.Primary; |
| 11 | 11 | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| 12 | 12 | |
| 13 | +import java.util.Calendar; | |
| 14 | +import java.util.Date; | |
| 13 | 15 | import java.util.concurrent.Executors; |
| 14 | 16 | import java.util.concurrent.ScheduledExecutorService; |
| 15 | 17 | ... | ... |
src/main/java/com/bsth/controller/gps/GpsController.java
| ... | ... | @@ -3,12 +3,18 @@ package com.bsth.controller.gps; |
| 3 | 3 | import com.bsth.data.BasicData; |
| 4 | 4 | import com.bsth.data.gpsdata.GpsEntity; |
| 5 | 5 | import com.bsth.data.gpsdata.GpsRealData; |
| 6 | +import com.bsth.entity.excep.Speeding; | |
| 6 | 7 | import com.bsth.service.gps.GpsService; |
| 8 | +import com.bsth.service.gps.entity.GpsSpeed; | |
| 9 | +import com.bsth.util.PageObject; | |
| 7 | 10 | import com.google.common.base.Splitter; |
| 8 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 12 | import org.springframework.web.bind.annotation.*; |
| 10 | 13 | |
| 11 | 14 | import javax.servlet.http.HttpServletResponse; |
| 15 | + | |
| 16 | +import java.text.ParseException; | |
| 17 | +import java.util.ArrayList; | |
| 12 | 18 | import java.util.List; |
| 13 | 19 | import java.util.Map; |
| 14 | 20 | |
| ... | ... | @@ -179,4 +185,22 @@ public class GpsController { |
| 179 | 185 | @RequestParam(defaultValue = "DESC") String direction){ |
| 180 | 186 | return gpsService.safeDrivList(map , page, size, order, direction); |
| 181 | 187 | } |
| 188 | + | |
| 189 | + @RequestMapping(value = "/findPosition", method = RequestMethod.GET) | |
| 190 | + public List<GpsSpeed> findPosition(@RequestParam String vehicle,@RequestParam String startdate,@RequestParam String enddate) throws ParseException { | |
| 191 | + String deviceid = BasicData.deviceId2NbbmMap.inverse().get(vehicle); | |
| 192 | + List<GpsSpeed> listGpsSpeed = new ArrayList<GpsSpeed>(); | |
| 193 | + listGpsSpeed = gpsService.findPosition(deviceid,startdate,enddate); | |
| 194 | + return listGpsSpeed; | |
| 195 | + } | |
| 196 | + | |
| 197 | + @RequestMapping(value = "/pagequery",method = RequestMethod.GET) | |
| 198 | + public PageObject<GpsSpeed> pagequery(@RequestParam Map<String, Object> map){ | |
| 199 | + PageObject<GpsSpeed> pageObject = null; | |
| 200 | + map.put("curPage", map.get("page").toString()); | |
| 201 | + map.put("pageData","10"); | |
| 202 | + pageObject=gpsService.Pagequery(map); | |
| 203 | + return pageObject; | |
| 204 | + } | |
| 205 | + | |
| 182 | 206 | } | ... | ... |
src/main/java/com/bsth/controller/schedule/core/TTInfoController.java
| ... | ... | @@ -6,10 +6,7 @@ import com.bsth.entity.schedule.TTInfo; |
| 6 | 6 | import com.bsth.service.schedule.TTInfoService; |
| 7 | 7 | import com.bsth.service.schedule.exception.ScheduleException; |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 10 | -import org.springframework.web.bind.annotation.RequestMethod; | |
| 11 | -import org.springframework.web.bind.annotation.RequestParam; | |
| 12 | -import org.springframework.web.bind.annotation.RestController; | |
| 9 | +import org.springframework.web.bind.annotation.*; | |
| 13 | 10 | |
| 14 | 11 | import java.util.HashMap; |
| 15 | 12 | import java.util.Map; |
| ... | ... | @@ -87,4 +84,18 @@ public class TTInfoController extends BController<TTInfo, Long> { |
| 87 | 84 | return rtn; |
| 88 | 85 | } |
| 89 | 86 | |
| 87 | + @RequestMapping(value = "/backup/{ttinfo}", method = RequestMethod.GET) | |
| 88 | + public Map<String, Object> backup(@PathVariable(value = "ttinfo") Long ttInfoId) { | |
| 89 | + Map<String, Object> rtn = new HashMap<>(); | |
| 90 | + try { | |
| 91 | + // 备份时刻表 | |
| 92 | + this.ttInfoService.backUp(ttInfoId); | |
| 93 | + } catch (ScheduleException exp) { | |
| 94 | + rtn.put("status", ResponseCode.ERROR); | |
| 95 | + rtn.put("msg", exp.getMessage()); | |
| 96 | + } | |
| 97 | + | |
| 98 | + return rtn; | |
| 99 | + } | |
| 100 | + | |
| 90 | 101 | } |
| 91 | 102 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/controller/sys/IntervalController.java
0 → 100644
| 1 | +package com.bsth.controller.sys; | |
| 2 | + | |
| 3 | +import java.util.Map; | |
| 4 | + | |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 | +import org.springframework.web.bind.annotation.RequestMethod; | |
| 8 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 9 | +import org.springframework.web.bind.annotation.RestController; | |
| 10 | + | |
| 11 | +import com.alibaba.fastjson.JSON; | |
| 12 | +import com.bsth.entity.sys.Interval; | |
| 13 | +import com.bsth.service.sys.IntervalService; | |
| 14 | + | |
| 15 | +@RestController | |
| 16 | +@RequestMapping("interval") | |
| 17 | +public class IntervalController { | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + IntervalService intervalService; | |
| 21 | + | |
| 22 | + @RequestMapping(value = "/save", method = RequestMethod.POST) | |
| 23 | + public Map<String, Object> save(@RequestParam String array){ | |
| 24 | + return intervalService.saveList(JSON.parseArray(array, Interval.class)); | |
| 25 | + } | |
| 26 | +} | ... | ... |
src/main/java/com/bsth/data/Station2ParkBuffer.java
| ... | ... | @@ -2,6 +2,7 @@ package com.bsth.data; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.common.ResponseCode; |
| 4 | 4 | import com.bsth.entity.realcontrol.ChildTaskPlan; |
| 5 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 5 | 6 | import com.bsth.entity.realcontrol.StationToPark; |
| 6 | 7 | import com.bsth.repository.realcontrol.StationToParkRepository; |
| 7 | 8 | import com.bsth.util.Arith; |
| ... | ... | @@ -28,14 +29,13 @@ public class Station2ParkBuffer implements CommandLineRunner { |
| 28 | 29 | |
| 29 | 30 | private static ArrayListMultimap listMultimap; |
| 30 | 31 | |
| 31 | - private static Set<StationToPark> pstBuff; | |
| 32 | + private static Set<StationToPark> pstBuff = new HashSet<>(); | |
| 32 | 33 | |
| 33 | 34 | static Logger log = LoggerFactory.getLogger(Station2ParkBuffer.class); |
| 34 | 35 | |
| 35 | 36 | @Override |
| 36 | 37 | public void run(String... strings) throws Exception { |
| 37 | 38 | listMultimap = ArrayListMultimap.create(); |
| 38 | - pstBuff = new HashSet<>(); | |
| 39 | 39 | Iterator<StationToPark> iterator = stationToParkRepository.findAll().iterator(); |
| 40 | 40 | StationToPark stp; |
| 41 | 41 | while (iterator.hasNext()) { |
| ... | ... | @@ -102,6 +102,47 @@ public class Station2ParkBuffer implements CommandLineRunner { |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | + public static void put(ScheduleRealInfo sch){ | |
| 106 | + try{ | |
| 107 | + String type = sch.getBcType(); | |
| 108 | + String lineCode = sch.getXlBm(), sName, eName; | |
| 109 | + | |
| 110 | + if (type.equals("in")) { | |
| 111 | + sName = sch.getQdzName(); | |
| 112 | + eName = sch.getZdzName(); | |
| 113 | + } else if (type.equals("out")) { | |
| 114 | + eName = sch.getQdzName(); | |
| 115 | + sName = sch.getZdzName(); | |
| 116 | + } else | |
| 117 | + return; | |
| 118 | + | |
| 119 | + long dt = sch.getZdsjT() - sch.getDfsjT(); | |
| 120 | + Float time = Float.parseFloat(String.valueOf(Arith.div(Arith.div(dt, 1000), 60))); | |
| 121 | + Float mileage = Float.parseFloat(sch.getJhlc().toString()); | |
| 122 | + | |
| 123 | + StationToPark stp = get(lineCode, sName, eName); | |
| 124 | + if (stp == null) { | |
| 125 | + stp = new StationToPark(); | |
| 126 | + stp.setLineCode(lineCode); | |
| 127 | + stp.setStationName(sName); | |
| 128 | + stp.setParkName(eName); | |
| 129 | + listMultimap.put(lineCode, stp); | |
| 130 | + } | |
| 131 | + | |
| 132 | + if (type.equals("in")) { | |
| 133 | + stp.setTime1(time); | |
| 134 | + stp.setMileage1(mileage); | |
| 135 | + } else { | |
| 136 | + stp.setTime2(time); | |
| 137 | + stp.setMileage2(mileage); | |
| 138 | + } | |
| 139 | + | |
| 140 | + pstBuff.add(stp); | |
| 141 | + }catch (Exception e){ | |
| 142 | + log.error("", e); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 105 | 146 | public static Float calcMinute(ChildTaskPlan ctask) { |
| 106 | 147 | long t = 0; |
| 107 | 148 | ... | ... |
src/main/java/com/bsth/data/pilot80/PilotReport.java
| ... | ... | @@ -189,7 +189,7 @@ public class PilotReport { |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | public boolean isEmpty(Double v) { |
| 192 | - return v == null || v.equals(0); | |
| 192 | + return v == null || v.equals(0.0); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | public void defaultReply(String nbbm, short requestCode, boolean agree) { | ... | ... |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| ... | ... | @@ -944,8 +944,11 @@ public class DayOfSchedule { |
| 944 | 944 | ScheduleRealInfo sch = schAttrCalculator.calcCurrentExecSch(list); |
| 945 | 945 | carExecutePlanMap.put(nbbm, sch); |
| 946 | 946 | |
| 947 | - if(sch==null) | |
| 947 | + if(sch==null){ | |
| 948 | + logger.info("车辆" + nbbm + "无可执行任务,切换至非营运状态"); | |
| 949 | + DirectivePushQueue.put6003(nbbm, 1, Integer.parseInt(sch.getXlDir()), null, "系统"); | |
| 948 | 950 | return; |
| 951 | + } | |
| 949 | 952 | try { |
| 950 | 953 | GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); |
| 951 | 954 | if(gps != null && gps.isOnline()){ | ... | ... |
src/main/java/com/bsth/entity/excep/Speeding.java
| ... | ... | @@ -52,6 +52,33 @@ public class Speeding { |
| 52 | 52 | private Float lat; |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | + * 超速结束时的经度 | |
| 56 | + */ | |
| 57 | + private Float endlon; | |
| 58 | + | |
| 59 | + public Float getEndlon() { | |
| 60 | + return endlon; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public void setEndlon(Float endlon) { | |
| 64 | + this.endlon = endlon; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public Float getEndlat() { | |
| 68 | + return endlat; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public void setEndlat(Float endlat) { | |
| 72 | + this.endlat = endlat; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * 超速结束时的纬度 | |
| 77 | + */ | |
| 78 | + private Float endlat; | |
| 79 | + | |
| 80 | + | |
| 81 | + /** | |
| 55 | 82 | * 速度 |
| 56 | 83 | */ |
| 57 | 84 | private Float speed; | ... | ... |
src/main/java/com/bsth/entity/schedule/TTInfo.java
| 1 | 1 | package com.bsth.entity.schedule; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Line; |
| 4 | +import com.bsth.service.schedule.utils.TimeTableProto; | |
| 4 | 5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 5 | 6 | |
| 6 | 7 | import javax.persistence.*; |
| ... | ... | @@ -63,6 +64,9 @@ public class TTInfo extends BEntity { |
| 63 | 64 | /** 特殊有效日期(格式:2001-01-01,多个用逗号隔开) */ |
| 64 | 65 | private String special_days; |
| 65 | 66 | |
| 67 | + /** 最近备份日期 */ | |
| 68 | + private Date lastBackUpDate; | |
| 69 | + | |
| 66 | 70 | public TTInfo() {} |
| 67 | 71 | public TTInfo(Object id, Object xlid, Object name, Object nds, Object sds) { |
| 68 | 72 | if (id != null) { |
| ... | ... | @@ -83,6 +87,32 @@ public class TTInfo extends BEntity { |
| 83 | 87 | } |
| 84 | 88 | } |
| 85 | 89 | |
| 90 | + /** | |
| 91 | + * 输出proto生成的builder | |
| 92 | + * @return | |
| 93 | + */ | |
| 94 | + public TimeTableProto.TTInfo.Builder toProtoBuilder() { | |
| 95 | + // 注意部份空值处理,必须覆默认值,否则报nullexceptio | |
| 96 | + return TimeTableProto.TTInfo.newBuilder() | |
| 97 | + .setId(id) | |
| 98 | + .setName(name) | |
| 99 | + .setXl(xl.getId()) | |
| 100 | + .setXlName(xl.getName()) | |
| 101 | + .setXlDir(xlDir) | |
| 102 | + .setQyrq(qyrq.getTime()) | |
| 103 | + .setIsEnableDisTemplate(isEnableDisTemplate) | |
| 104 | + .setIsCancel(isCancel) | |
| 105 | + .setRuleDays(rule_days) | |
| 106 | + .setSpecialDays(special_days) | |
| 107 | + .setCreateUser(getCreateBy() == null ? 0 : getCreateBy().getId()) | |
| 108 | + .setCreateUserName(getCreateBy() == null ? "" : getCreateBy().getUserName()) | |
| 109 | + .setUpdateUser(getUpdateBy() == null ? 0 : getUpdateBy().getId()) | |
| 110 | + .setUpdateUserName(getUpdateBy() == null ? "" : getUpdateBy().getUserName()) | |
| 111 | + .setCreateDate(getCreateDate() == null ? 0l : getCreateDate().getTime()) | |
| 112 | + .setUpdateDate(getUpdateDate() == null ? 0l : getUpdateDate().getTime()); | |
| 113 | + | |
| 114 | + } | |
| 115 | + | |
| 86 | 116 | public Long getId() { |
| 87 | 117 | return id; |
| 88 | 118 | } |
| ... | ... | @@ -178,4 +208,12 @@ public class TTInfo extends BEntity { |
| 178 | 208 | public void setIsCancel(Boolean isCancel) { |
| 179 | 209 | this.isCancel = isCancel; |
| 180 | 210 | } |
| 211 | + | |
| 212 | + public Date getLastBackUpDate() { | |
| 213 | + return lastBackUpDate; | |
| 214 | + } | |
| 215 | + | |
| 216 | + public void setLastBackUpDate(Date lastBackUpDate) { | |
| 217 | + this.lastBackUpDate = lastBackUpDate; | |
| 218 | + } | |
| 181 | 219 | } | ... | ... |
src/main/java/com/bsth/entity/schedule/TTInfoBackup.java
0 → 100644
| 1 | +package com.bsth.entity.schedule; | |
| 2 | + | |
| 3 | +import javax.persistence.*; | |
| 4 | +import java.util.Date; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 时刻表信息备份。 | |
| 8 | + * --不做关联信息,保存相应的关联id | |
| 9 | + */ | |
| 10 | +@Entity | |
| 11 | +@Table(name="bsth_c_s_ttinfo_bak") | |
| 12 | +public class TTInfoBackup { | |
| 13 | + | |
| 14 | + /** 主键Id */ | |
| 15 | + @Id | |
| 16 | + @GeneratedValue | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + /** 关联 bsth_c_line 主键,不做mapping */ | |
| 20 | + @Column(nullable = false) | |
| 21 | + private Integer xl; | |
| 22 | + /** 线路名称 */ | |
| 23 | + @Column(nullable = false) | |
| 24 | + private String xlName; | |
| 25 | + | |
| 26 | + /** 关联 bsth_c_s_ttinfo 主键,不做mapping */ | |
| 27 | + @Column(nullable = false) | |
| 28 | + private Long ttInfo; | |
| 29 | + /** 关联的时刻表名字 */ | |
| 30 | + private String ttInfoName; | |
| 31 | + | |
| 32 | + /** 备份日期 */ | |
| 33 | + @Column(nullable = false) | |
| 34 | + private Date backUpDate; | |
| 35 | + /** 备份的二进制内容(google protobuf格式) */ | |
| 36 | + @Lob | |
| 37 | + private byte[] backUpInfo; | |
| 38 | + | |
| 39 | + public Long getId() { | |
| 40 | + return id; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void setId(Long id) { | |
| 44 | + this.id = id; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public Integer getXl() { | |
| 48 | + return xl; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setXl(Integer xl) { | |
| 52 | + this.xl = xl; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public String getXlName() { | |
| 56 | + return xlName; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void setXlName(String xlName) { | |
| 60 | + this.xlName = xlName; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public Long getTtInfo() { | |
| 64 | + return ttInfo; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setTtInfo(Long ttInfo) { | |
| 68 | + this.ttInfo = ttInfo; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public String getTtInfoName() { | |
| 72 | + return ttInfoName; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public void setTtInfoName(String ttInfoName) { | |
| 76 | + this.ttInfoName = ttInfoName; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public Date getBackUpDate() { | |
| 80 | + return backUpDate; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public void setBackUpDate(Date backUpDate) { | |
| 84 | + this.backUpDate = backUpDate; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public byte[] getBackUpInfo() { | |
| 88 | + return backUpInfo; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public void setBackUpInfo(byte[] backUpInfo) { | |
| 92 | + this.backUpInfo = backUpInfo; | |
| 93 | + } | |
| 94 | +} | ... | ... |
src/main/java/com/bsth/entity/schedule/TTInfoDetail.java
| ... | ... | @@ -3,6 +3,7 @@ package com.bsth.entity.schedule; |
| 3 | 3 | import com.bsth.entity.CarPark; |
| 4 | 4 | import com.bsth.entity.Line; |
| 5 | 5 | import com.bsth.entity.Station; |
| 6 | +import com.bsth.service.schedule.utils.TimeTableProto; | |
| 6 | 7 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 7 | 8 | |
| 8 | 9 | import javax.persistence.*; |
| ... | ... | @@ -99,6 +100,35 @@ public class TTInfoDetail extends BEntity { |
| 99 | 100 | /** 备注 */ |
| 100 | 101 | private String remark; |
| 101 | 102 | |
| 103 | + /** | |
| 104 | + * 输出proto生成的builder | |
| 105 | + * @return | |
| 106 | + */ | |
| 107 | + public TimeTableProto.TTInfoDetail.Builder toProtoBuilder() { | |
| 108 | + // 注意部份空值处理,必须覆默认值,否则报nullexception | |
| 109 | + return TimeTableProto.TTInfoDetail.newBuilder() | |
| 110 | + .setId(id) | |
| 111 | + .setXl(xl.getId()) | |
| 112 | + .setXlName(xl.getName()) | |
| 113 | + .setLp(lp.getId()) | |
| 114 | + .setLpName(lp.getLpName()) | |
| 115 | + .setFcno(fcno) | |
| 116 | + .setXlDir(xlDir) | |
| 117 | + .setQdzCode(qdzCode) | |
| 118 | + .setQdzName(qdzName) | |
| 119 | + .setZdzCode(zdzCode) | |
| 120 | + .setZdzName(zdzName) | |
| 121 | + .setFcsj(fcsj) | |
| 122 | + .setBcs(bcs) | |
| 123 | + .setJhlc(jhlc) | |
| 124 | + .setBcsj(bcsj) | |
| 125 | + .setBcType(bcType) | |
| 126 | + .setIsFB(isFB == null ? false : isFB) | |
| 127 | + .setIsTS(isTS == null ? false : isTS) | |
| 128 | + .setRemark(remark == null ? "" : remark) | |
| 129 | + ; | |
| 130 | + } | |
| 131 | + | |
| 102 | 132 | public Long getId() { |
| 103 | 133 | return id; |
| 104 | 134 | } | ... | ... |
src/main/java/com/bsth/entity/sys/Interval.java
0 → 100644
| 1 | +package com.bsth.entity.sys; | |
| 2 | + | |
| 3 | +import java.util.Date; | |
| 4 | + | |
| 5 | +import javax.persistence.Column; | |
| 6 | +import javax.persistence.Entity; | |
| 7 | +import javax.persistence.GeneratedValue; | |
| 8 | +import javax.persistence.GenerationType; | |
| 9 | +import javax.persistence.Id; | |
| 10 | +import javax.persistence.Table; | |
| 11 | + | |
| 12 | + | |
| 13 | +@Entity | |
| 14 | +@Table(name = "bsth_c_interval") | |
| 15 | +public class Interval { | |
| 16 | + | |
| 17 | + @Id | |
| 18 | + @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 19 | + private Integer id; | |
| 20 | + | |
| 21 | + /** 大间隔等级 */ | |
| 22 | + private String level; | |
| 23 | + /** 高峰*/ | |
| 24 | + private Integer peak; | |
| 25 | + public Integer getPeak() { | |
| 26 | + return peak; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public void setPeak(Integer peak) { | |
| 30 | + this.peak = peak; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public Integer getTrough() { | |
| 34 | + return trough; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void setTrough(Integer trough) { | |
| 38 | + this.trough = trough; | |
| 39 | + } | |
| 40 | + | |
| 41 | + | |
| 42 | + public Integer getCreateBy() { | |
| 43 | + return createBy; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void setCreateBy(Integer createBy) { | |
| 47 | + this.createBy = createBy; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public Date getCreateDate() { | |
| 51 | + return createDate; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setCreateDate(Date createDate) { | |
| 55 | + this.createDate = createDate; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public Integer getUpdateBy() { | |
| 59 | + return updateBy; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setUpdateBy(Integer updateBy) { | |
| 63 | + this.updateBy = updateBy; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public Date getUpdateDate() { | |
| 67 | + return updateDate; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public void setUpdateDate(Date updateDate) { | |
| 71 | + this.updateDate = updateDate; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** 低谷 */ | |
| 75 | + private Integer trough; | |
| 76 | + | |
| 77 | + @Column(name = "create_by") | |
| 78 | + private Integer createBy; | |
| 79 | + | |
| 80 | + @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | |
| 81 | + private Date createDate; | |
| 82 | + | |
| 83 | + @Column(name = "update_by") | |
| 84 | + private Integer updateBy; | |
| 85 | + | |
| 86 | + @Column(name = "update_date", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") | |
| 87 | + private Date updateDate; | |
| 88 | + | |
| 89 | + public Integer getId() { | |
| 90 | + return id; | |
| 91 | + } | |
| 92 | + | |
| 93 | + public void setId(Integer id) { | |
| 94 | + this.id = id; | |
| 95 | + } | |
| 96 | + | |
| 97 | + public String getLevel() { | |
| 98 | + return level; | |
| 99 | + } | |
| 100 | + | |
| 101 | + public void setLevel(String level) { | |
| 102 | + this.level = level; | |
| 103 | + } | |
| 104 | + | |
| 105 | +} | ... | ... |
src/main/java/com/bsth/repository/schedule/TTInfoBackupRepository.java
0 → 100644
| 1 | +package com.bsth.repository.schedule; | |
| 2 | + | |
| 3 | +import com.bsth.entity.schedule.TTInfoBackup; | |
| 4 | +import com.bsth.repository.BaseRepository; | |
| 5 | +import org.springframework.stereotype.Repository; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by xu on 17/7/13. | |
| 9 | + */ | |
| 10 | +@Repository | |
| 11 | +public interface TTInfoBackupRepository extends BaseRepository<TTInfoBackup, Long> { | |
| 12 | +} | ... | ... |
src/main/java/com/bsth/repository/sys/IntervalRepository.java
0 → 100644
| 1 | +package com.bsth.repository.sys; | |
| 2 | + | |
| 3 | + | |
| 4 | +import org.springframework.stereotype.Repository; | |
| 5 | +import com.bsth.entity.sys.Interval; | |
| 6 | +import com.bsth.repository.BaseRepository; | |
| 7 | + | |
| 8 | +@Repository | |
| 9 | +public interface IntervalRepository extends BaseRepository<Interval, Integer> { | |
| 10 | + | |
| 11 | +} | ... | ... |
src/main/java/com/bsth/service/excep/impl/SpeedingServiceImpl.java
| ... | ... | @@ -9,21 +9,22 @@ import java.text.SimpleDateFormat; |
| 9 | 9 | import java.util.ArrayList; |
| 10 | 10 | import java.util.Date; |
| 11 | 11 | import java.util.HashMap; |
| 12 | +import java.util.Iterator; | |
| 12 | 13 | import java.util.List; |
| 13 | 14 | import java.util.Map; |
| 14 | 15 | |
| 15 | 16 | import org.springframework.jdbc.core.JdbcTemplate; |
| 16 | -import org.springframework.jdbc.core.RowMapper; | |
| 17 | 17 | import org.springframework.stereotype.Service; |
| 18 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 19 | 19 | |
| 20 | 20 | import com.bsth.data.BasicData; |
| 21 | 21 | import com.bsth.entity.excep.Speeding; |
| 22 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 23 | 22 | import com.bsth.service.excep.SpeedingService; |
| 24 | 23 | import com.bsth.util.EchartConver; |
| 25 | 24 | import com.bsth.util.PageHelper; |
| 26 | 25 | import com.bsth.util.PageObject; |
| 26 | +import com.bsth.util.TransGPS; | |
| 27 | +import com.bsth.util.TransGPS.Location; | |
| 27 | 28 | import com.bsth.util.db.DBUtils_MS; |
| 28 | 29 | import com.github.abel533.echarts.Option; |
| 29 | 30 | import com.google.gson.Gson; |
| ... | ... | @@ -83,7 +84,6 @@ public class SpeedingServiceImpl implements SpeedingService { |
| 83 | 84 | |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | - | |
| 87 | 87 | /*sql +=" order by id limit ?,?";*/ |
| 88 | 88 | |
| 89 | 89 | |
| ... | ... | @@ -104,17 +104,23 @@ public class SpeedingServiceImpl implements SpeedingService { |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | static List<Speeding> resultSet2Set(ResultSet rs) throws SQLException{ |
| 107 | - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); | |
| 107 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 108 | 108 | List<Speeding> list=new ArrayList<Speeding>(); |
| 109 | 109 | Speeding speeding; |
| 110 | + Float lon, lat; | |
| 111 | + Location location; | |
| 110 | 112 | while(rs.next()){ |
| 113 | + lon = rs.getFloat("lon"); | |
| 114 | + lat = rs.getFloat("lat"); | |
| 115 | + location = TransGPS.LocationMake(lon, lat); | |
| 116 | + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 111 | 117 | speeding=new Speeding(); |
| 112 | 118 | speeding.setId(Integer.valueOf(rs.getObject("id").toString())); |
| 113 | - speeding.setLat(Float.valueOf(rs.getObject("lat").toString())); | |
| 119 | + speeding.setLon((float)location.getLng()); | |
| 120 | + speeding.setLat((float)location.getLat()); | |
| 114 | 121 | speeding.setLine(Integer.valueOf(rs.getObject("line").toString())); |
| 115 | 122 | //run 时注解 |
| 116 | 123 | speeding.setLineName(BasicData.lineCode2NameMap.get(speeding.getLine().toString())); |
| 117 | - speeding.setLon(Float.valueOf(rs.getObject("lon").toString())); | |
| 118 | 124 | speeding.setSpeed(Float.valueOf(rs.getObject("speed").toString())); |
| 119 | 125 | speeding.setTimestamp((Long.valueOf(rs.getObject("timestamp").toString()))); |
| 120 | 126 | speeding.setTimestampDate(sdf.format(new Date(speeding.getTimestamp()))); |
| ... | ... | @@ -127,14 +133,12 @@ public class SpeedingServiceImpl implements SpeedingService { |
| 127 | 133 | |
| 128 | 134 | @Override |
| 129 | 135 | public PageObject<Speeding> Pagequery(Map<String, Object> map) { |
| 130 | - String sql="select count(*) record from bsth_c_speeding where 1=1 "; | |
| 136 | +/* String sql="select count(*) record from bsth_c_speeding where 1=1 "; | |
| 131 | 137 | Object line=map.get("line"); |
| 132 | 138 | Object nbbm=map.get("nbbm"); |
| 133 | 139 | Object updown=map.get("updown"); |
| 134 | 140 | Object startDate=map.get("startDate"); |
| 135 | 141 | Object endDate=map.get("endDate"); |
| 136 | - //时间转换 | |
| 137 | - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 138 | 142 | |
| 139 | 143 | if(line!=null){ |
| 140 | 144 | sql +=" and line like'%"+line.toString().trim()+"%'"; |
| ... | ... | @@ -186,31 +190,61 @@ public class SpeedingServiceImpl implements SpeedingService { |
| 186 | 190 | e.printStackTrace(); |
| 187 | 191 | }finally { |
| 188 | 192 | DBUtils_MS.close(rs, ps, conn); |
| 189 | - } | |
| 193 | + }*/ | |
| 190 | 194 | |
| 195 | + //时间转换 | |
| 196 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 191 | 197 | List<Speeding> list=findAll(map); |
| 192 | 198 | List<Speeding> listResult = new ArrayList<Speeding>(); |
| 193 | 199 | int curPage;//页码 |
| 194 | 200 | int pageData;//每页的记录条数 |
| 195 | 201 | int start;//起始数据下标 |
| 196 | 202 | int totalPage;//总页数 |
| 203 | + int totalData = 0; | |
| 197 | 204 | if(list.size()>1){ |
| 198 | - Speeding speedingNow;//下标为i的车 | |
| 199 | - Speeding speedingLast;//下标为i-1的车 | |
| 205 | + Speeding speedingNow;//下标为i的车辆行驶记录 | |
| 206 | + Speeding speedingLast;//下标为i-1的车辆行驶记录 | |
| 207 | + Speeding spped = null;//整合后的车辆行驶记录 | |
| 200 | 208 | String strNow; |
| 201 | 209 | String strLast; |
| 210 | + boolean Flag = false;//判断是否有连续超速记录,默认没有 | |
| 202 | 211 | for(int i = 1;i<list.size();i++){ |
| 203 | 212 | speedingNow = list.get(i); |
| 204 | 213 | speedingLast = list.get(i-1); |
| 205 | - strNow = speedingNow.getVehicle()+speedingNow.getLine()+speedingNow.getUpDown();//同一车辆同一线路同一方向 | |
| 214 | + strNow = speedingNow.getVehicle()+speedingNow.getLine()+speedingNow.getUpDown(); | |
| 206 | 215 | strLast = speedingLast.getVehicle()+speedingLast.getLine()+speedingLast.getUpDown(); |
| 207 | - //同一车辆同一线路同一方向并且该记录的超速的开始时间减去上一条超速记录的结束时间小于等于10s,证明该车超速。//PS:祛除数据库中的重复发送数据 | |
| 208 | - if(strNow.equals(strLast) && Math.abs(speedingNow.getTimestamp()-speedingLast.getTimestamp())<=10*1000 && (speedingNow.getTimestamp()-speedingLast.getTimestamp()!=0)){ | |
| 209 | - speedingLast.setEndtimestamp(speedingNow.getTimestamp()); | |
| 210 | - speedingLast.setEndtimestampDate(sdf.format(new Date(speedingNow.getTimestamp())));//设置结束时间 | |
| 211 | - listResult.add(speedingLast); | |
| 216 | + if(speedingNow.getSpeed()>60 && speedingLast.getSpeed()>60 && strNow.equals(strLast)){//如果两条连续的记录都是超速且属于同一辆车。 | |
| 217 | + if(Flag==false){// | |
| 218 | + spped = new Speeding(); | |
| 219 | + spped.setId(speedingLast.getId());//设置连续超速记录Id | |
| 220 | + spped.setLine(speedingLast.getLine());//设置连续超速记录线路 | |
| 221 | + spped.setLineName(speedingLast.getLineName());//设置连续超速记录线路名称 | |
| 222 | + spped.setVehicle(speedingLast.getVehicle());//设置连续超速记录的车辆编号 | |
| 223 | + spped.setUpDown(speedingLast.getUpDown());//设置上下行 | |
| 224 | + spped.setLon(speedingLast.getLon());//设置开始时经度 | |
| 225 | + spped.setLat(speedingLast.getLat());//设置开始时纬度 | |
| 226 | + spped.setTimestamp(speedingLast.getTimestamp());//设置连续超速记录的开始时间 | |
| 227 | + spped.setTimestampDate(speedingLast.getTimestampDate());//设置连续超速记录的开始时间戳 | |
| 228 | + } | |
| 229 | + spped.setEndtimestamp(speedingNow.getTimestamp());//设置结束时间戳 | |
| 230 | + spped.setEndtimestampDate(sdf.format(new Date(speedingNow.getTimestamp())));//设置结束时间 | |
| 231 | + spped.setEndlon(speedingNow.getLon());//设置结束时的经度 | |
| 232 | + spped.setEndlat(speedingNow.getLat());//设置结束时的纬度 | |
| 233 | + Flag = true; | |
| 234 | + }else{ | |
| 235 | + if(Flag){//如果上一条记录超速。 | |
| 236 | + listResult.add(spped); | |
| 237 | + Flag = false; | |
| 238 | + } | |
| 212 | 239 | } |
| 213 | 240 | } |
| 241 | + Iterator<Speeding> speedIt = listResult.iterator(); | |
| 242 | + while(speedIt.hasNext()){ | |
| 243 | + Speeding speeding = speedIt.next(); | |
| 244 | + if(speeding.getEndtimestamp()-speeding.getTimestamp()<=1000){ | |
| 245 | + speedIt.remove(); | |
| 246 | + } | |
| 247 | + } | |
| 214 | 248 | |
| 215 | 249 | totalData = listResult.size();//总记录条数。 |
| 216 | 250 | if(map.get("curPage") == null || map.get("curPage").equals("0")){ | ... | ... |
src/main/java/com/bsth/service/gps/GpsService.java
| 1 | 1 | package com.bsth.service.gps; |
| 2 | 2 | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 3 | 4 | import com.bsth.service.gps.entity.GpsOutbound_DTO; |
| 5 | +import com.bsth.service.gps.entity.GpsSpeed; | |
| 4 | 6 | import com.bsth.service.gps.entity.GpsSpeed_DTO; |
| 7 | +import com.bsth.util.PageObject; | |
| 5 | 8 | |
| 6 | 9 | import javax.servlet.http.HttpServletResponse; |
| 10 | + | |
| 11 | +import java.text.ParseException; | |
| 7 | 12 | import java.util.List; |
| 8 | 13 | import java.util.Map; |
| 9 | 14 | |
| ... | ... | @@ -38,4 +43,9 @@ public interface GpsService { |
| 38 | 43 | void abnormalExcel(String nbbm, long st, long et, HttpServletResponse resp); |
| 39 | 44 | |
| 40 | 45 | void arrivalExcel(String nbbm, long st, long et, HttpServletResponse resp); |
| 46 | + | |
| 47 | + List<GpsSpeed> findPosition(String deviceid, String startdate, | |
| 48 | + String enddate) throws ParseException; | |
| 49 | + | |
| 50 | + PageObject<GpsSpeed> Pagequery(Map<String, Object> map); | |
| 41 | 51 | } | ... | ... |
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
| ... | ... | @@ -16,6 +16,8 @@ import com.bsth.repository.StationRepository; |
| 16 | 16 | import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; |
| 17 | 17 | import com.bsth.service.gps.entity.*; |
| 18 | 18 | import com.bsth.util.DateUtils; |
| 19 | +import com.bsth.util.PageHelper; | |
| 20 | +import com.bsth.util.PageObject; | |
| 19 | 21 | import com.bsth.util.TransGPS; |
| 20 | 22 | import com.bsth.util.TransGPS.Location; |
| 21 | 23 | import com.bsth.util.db.DBUtils_MS; |
| ... | ... | @@ -44,7 +46,10 @@ import java.net.URLEncoder; |
| 44 | 46 | import java.sql.Connection; |
| 45 | 47 | import java.sql.PreparedStatement; |
| 46 | 48 | import java.sql.ResultSet; |
| 49 | +import java.sql.SQLException; | |
| 47 | 50 | import java.text.DecimalFormat; |
| 51 | +import java.text.ParseException; | |
| 52 | +import java.text.SimpleDateFormat; | |
| 48 | 53 | import java.util.*; |
| 49 | 54 | |
| 50 | 55 | @Service |
| ... | ... | @@ -804,7 +809,7 @@ public class GpsServiceImpl implements GpsService { |
| 804 | 809 | @Override |
| 805 | 810 | public List<GpsSpeed_DTO> speeds(String nbbm, long st, long et) { |
| 806 | 811 | String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); |
| 807 | - String sql = "select vehicle, line, up_down, lon, lat, speed,timestamp from bsth_c_speeding where vehicle=? and timestamp>? and timestamp<?"; | |
| 812 | + String sql = "select vehicle, line, up_down, lon, lat, speed,timestamp from bsth_c_GpsSpeed where vehicle=? and timestamp>? and timestamp<?"; | |
| 808 | 813 | |
| 809 | 814 | return GpsSpeed_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql, deviceId, st * 1000, et * 1000)); |
| 810 | 815 | } |
| ... | ... | @@ -981,4 +986,235 @@ public class GpsServiceImpl implements GpsService { |
| 981 | 986 | } |
| 982 | 987 | return true; |
| 983 | 988 | } |
| 989 | + | |
| 990 | + @Override | |
| 991 | + public List<GpsSpeed> findPosition(String deviceid, String startdate, | |
| 992 | + String enddate) throws ParseException{ | |
| 993 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 994 | + Calendar c = Calendar.getInstance(); | |
| 995 | + Date date = sdf.parse(startdate); | |
| 996 | + c.setTime(date); | |
| 997 | + int daysYear = c.get(Calendar.DAY_OF_YEAR);//获取当前是今年的第几天。 | |
| 998 | + | |
| 999 | + long startTime = sdf.parse(startdate).getTime(); | |
| 1000 | + long endTime = sdf.parse(enddate).getTime(); | |
| 1001 | + | |
| 1002 | + String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,speed_gps from bsth_c_gps_info where days_year=? and device_id=? and ts >= ? and ts <= ?" + | |
| 1003 | + " ORDER BY TS "; | |
| 1004 | + Connection conn = null; | |
| 1005 | + PreparedStatement ps = null; | |
| 1006 | + ResultSet rs = null; | |
| 1007 | + List<GpsSpeed> listResult = new ArrayList<GpsSpeed>(); | |
| 1008 | + GpsSpeed gpsSpeed = null; | |
| 1009 | + try { | |
| 1010 | + conn = DBUtils_MS.getConnection(); | |
| 1011 | + ps = conn.prepareStatement(sql); | |
| 1012 | + ps.setInt(1, daysYear); | |
| 1013 | + ps.setString(2, deviceid); | |
| 1014 | + ps.setLong(3,startTime); | |
| 1015 | + ps.setLong(4,endTime); | |
| 1016 | + rs = ps.executeQuery(); | |
| 1017 | + Float lon, lat; | |
| 1018 | + Location location; | |
| 1019 | + while (rs.next()) { | |
| 1020 | + gpsSpeed = new GpsSpeed(); | |
| 1021 | + // to 百度坐标 | |
| 1022 | + lon = rs.getFloat("LON"); | |
| 1023 | + lat = rs.getFloat("LAT"); | |
| 1024 | + location = TransGPS.LocationMake(lon, lat); | |
| 1025 | + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 1026 | + gpsSpeed.setVehicle(rs.getString("device_id")); | |
| 1027 | + gpsSpeed.setLon((float)location.getLng()); | |
| 1028 | + gpsSpeed.setLat((float)location.getLat()); | |
| 1029 | + gpsSpeed.setSpeed(rs.getFloat("speed_gps")); | |
| 1030 | + gpsSpeed.setTimestamp(rs.getLong("TS")); | |
| 1031 | + // 上下行 | |
| 1032 | + listResult.add(gpsSpeed); | |
| 1033 | + } | |
| 1034 | + } catch (Exception e) { | |
| 1035 | + e.printStackTrace(); | |
| 1036 | + } finally { | |
| 1037 | + DBUtils_MS.close(rs, ps, conn); | |
| 1038 | + } | |
| 1039 | + return listResult; | |
| 1040 | + | |
| 1041 | + } | |
| 1042 | + | |
| 1043 | + @Override | |
| 1044 | + public PageObject<GpsSpeed> Pagequery(Map<String, Object> map) { | |
| 1045 | + | |
| 1046 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1047 | + List<GpsSpeed> list=findAll(map); | |
| 1048 | + List<GpsSpeed> listResult = new ArrayList<GpsSpeed>(); | |
| 1049 | + int curPage;//页码 | |
| 1050 | + int pageData;//每页的记录条数 | |
| 1051 | + int start;//起始数据下标 | |
| 1052 | + int totalPage;//总页数 | |
| 1053 | + int totalData = 0; | |
| 1054 | + if(list.size()>1){ | |
| 1055 | + GpsSpeed GpsSpeedNow;//下标为i的车辆行驶记录 | |
| 1056 | + GpsSpeed GpsSpeedLast;//下标为i-1的车辆行驶记录 | |
| 1057 | + GpsSpeed spped = null;//整合后的车辆行驶记录 | |
| 1058 | + String strNow; | |
| 1059 | + String strLast; | |
| 1060 | + boolean Flag = false;//判断是否有连续超速记录,默认没有 | |
| 1061 | + for(int i = 1;i<list.size();i++){ | |
| 1062 | + GpsSpeedNow = list.get(i); | |
| 1063 | + GpsSpeedLast = list.get(i-1); | |
| 1064 | + strNow = GpsSpeedNow.getVehicle()+GpsSpeedNow.getLine()+GpsSpeedNow.getUp_down(); | |
| 1065 | + strLast = GpsSpeedLast.getVehicle()+GpsSpeedLast.getLine()+GpsSpeedLast.getUp_down(); | |
| 1066 | + if(GpsSpeedNow.getSpeed()>60 && GpsSpeedLast.getSpeed()>60 && strNow.equals(strLast)){//如果两条连续的记录都是超速且属于同一辆车。 | |
| 1067 | + if(Flag==false){// | |
| 1068 | + spped = new GpsSpeed(); | |
| 1069 | + spped.setLine(GpsSpeedLast.getLine());//设置连续超速记录线路 | |
| 1070 | + spped.setLineName(GpsSpeedLast.getLineName());//设置连续超速记录线路名称 | |
| 1071 | + spped.setVehicle(GpsSpeedLast.getVehicle());//设置连续超速记录的车辆编号 | |
| 1072 | + spped.setUp_down(GpsSpeedLast.getUp_down());//设置上下行 | |
| 1073 | + spped.setLon(GpsSpeedLast.getLon());//设置开始时经度 | |
| 1074 | + spped.setLat(GpsSpeedLast.getLat());//设置开始时纬度 | |
| 1075 | + spped.setTimestamp(GpsSpeedLast.getTimestamp());//设置连续超速记录的开始时间 | |
| 1076 | + spped.setTimestampDate(GpsSpeedLast.getTimestampDate());//设置连续超速记录的开始时间戳 | |
| 1077 | + } | |
| 1078 | + spped.setEndtimestamp(GpsSpeedNow.getTimestamp());//设置结束时间戳 | |
| 1079 | + spped.setEndtimestampDate(sdf.format(new Date(GpsSpeedNow.getTimestamp())));//设置结束时间 | |
| 1080 | + spped.setEndlon(GpsSpeedNow.getLon());//设置结束时的经度 | |
| 1081 | + spped.setEndlat(GpsSpeedNow.getLat());//设置结束时的纬度 | |
| 1082 | + Flag = true; | |
| 1083 | + }else{ | |
| 1084 | + if(Flag){//如果上一条记录超速。 | |
| 1085 | + listResult.add(spped); | |
| 1086 | + Flag = false; | |
| 1087 | + } | |
| 1088 | + } | |
| 1089 | + } | |
| 1090 | + Iterator<GpsSpeed> speedIt = listResult.iterator(); | |
| 1091 | + while(speedIt.hasNext()){ | |
| 1092 | + GpsSpeed GpsSpeed = speedIt.next(); | |
| 1093 | + if(GpsSpeed.getEndtimestamp()-GpsSpeed.getTimestamp()<=1000){ | |
| 1094 | + speedIt.remove(); | |
| 1095 | + } | |
| 1096 | + } | |
| 1097 | + | |
| 1098 | + totalData = listResult.size();//总记录条数。 | |
| 1099 | + if(map.get("curPage") == null || map.get("curPage").equals("0")){ | |
| 1100 | + curPage = 0; | |
| 1101 | + }else{ | |
| 1102 | + curPage = Integer.parseInt((String) map.get("curPage")); | |
| 1103 | + } | |
| 1104 | + pageData = Integer.parseInt((String) map.get("pageData"));//每页的记录条数 | |
| 1105 | + start = (curPage - 0) * pageData; //起始记录下标。 | |
| 1106 | + totalPage = totalData % pageData == 0 ? totalData / pageData : totalData / pageData +1;//总页数 | |
| 1107 | + if(curPage == totalPage-1){//如果当前页等于总页数。 | |
| 1108 | + listResult = listResult.subList(start, totalData); | |
| 1109 | + }else{ | |
| 1110 | + listResult = listResult.subList(start, start+pageData); | |
| 1111 | + } | |
| 1112 | + }else{ | |
| 1113 | + curPage = 1; | |
| 1114 | + pageData = Integer.parseInt((String) map.get("pageData"));//每页的记录条数 | |
| 1115 | + totalPage =1; | |
| 1116 | + } | |
| 1117 | + Map<String,Object> paramMap = new HashMap<String,Object>(); | |
| 1118 | + paramMap.put("totalPage", totalPage); | |
| 1119 | + paramMap.put("curPage", curPage); | |
| 1120 | + paramMap.put("pageData", pageData); | |
| 1121 | + PageHelper pageHelper = new PageHelper(totalData, paramMap); | |
| 1122 | + pageHelper.getMap(); | |
| 1123 | + PageObject<GpsSpeed> pageObject = pageHelper.getPageObject(); | |
| 1124 | + pageObject.setDataList(listResult); | |
| 1125 | + return pageObject; | |
| 1126 | + } | |
| 1127 | + | |
| 1128 | + static List<GpsSpeed> findAll(Map<String, Object> map) { | |
| 1129 | + Connection conn = null; | |
| 1130 | + PreparedStatement ps = null; | |
| 1131 | + ResultSet rs = null; | |
| 1132 | + int page=Integer.parseInt(map.get("page").toString()); | |
| 1133 | + List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1134 | + String sql="select * from bsth_c_gps_info where 1=1 "; | |
| 1135 | + Object line=map.get("line"); | |
| 1136 | + Object nbbm=map.get("nbbm"); | |
| 1137 | + Object updown=map.get("updown"); | |
| 1138 | + Object startDate=map.get("startDate"); | |
| 1139 | + Object endDate=map.get("endDate"); | |
| 1140 | + | |
| 1141 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1142 | + if(line!=null){ | |
| 1143 | + sql +=" and line_id like'%"+line.toString().trim()+"%'"; | |
| 1144 | + } | |
| 1145 | + | |
| 1146 | + if(nbbm!=null){ | |
| 1147 | + nbbm=BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 1148 | + if(nbbm!=null) | |
| 1149 | + sql +=" and vehicle like '%"+nbbm.toString()+"%'"; | |
| 1150 | + } | |
| 1151 | + | |
| 1152 | + if(updown!=null){ | |
| 1153 | + sql +="and industry_code like '%"+updown.toString()+"%'"; | |
| 1154 | + } | |
| 1155 | + if(startDate!=null){ | |
| 1156 | + if (startDate.toString().length()>0) { | |
| 1157 | + try { | |
| 1158 | + Long t1=sdf.parse(startDate.toString()+" 00:00:00").getTime(); | |
| 1159 | + sql += " and ts >="+t1; | |
| 1160 | + } catch (ParseException e) { | |
| 1161 | + e.printStackTrace(); | |
| 1162 | + } | |
| 1163 | + } | |
| 1164 | + | |
| 1165 | + } | |
| 1166 | + if(endDate!=null){ | |
| 1167 | + if (endDate.toString().length()>0) { | |
| 1168 | + try { | |
| 1169 | + Long t2=sdf.parse(endDate.toString()+" 23:59:59").getTime(); | |
| 1170 | + sql += " and ts <="+t2; | |
| 1171 | + } catch (ParseException e) { | |
| 1172 | + e.printStackTrace(); | |
| 1173 | + } | |
| 1174 | + } | |
| 1175 | + | |
| 1176 | + } | |
| 1177 | + | |
| 1178 | + try { | |
| 1179 | + conn = DBUtils_MS.getConnection(); | |
| 1180 | + ps = conn.prepareStatement(sql); | |
| 1181 | + rs = ps.executeQuery(); | |
| 1182 | + list = resultSet2Set(rs); | |
| 1183 | + } catch (SQLException e) { | |
| 1184 | + e.printStackTrace(); | |
| 1185 | + }finally { | |
| 1186 | + DBUtils_MS.close(rs, ps, conn); | |
| 1187 | + } | |
| 1188 | + | |
| 1189 | + return list; | |
| 1190 | + } | |
| 1191 | + | |
| 1192 | + static List<GpsSpeed> resultSet2Set(ResultSet rs) throws SQLException{ | |
| 1193 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1194 | + List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1195 | + GpsSpeed GpsSpeed; | |
| 1196 | + Float lon, lat; | |
| 1197 | + Location location; | |
| 1198 | + while(rs.next()){ | |
| 1199 | + lon = rs.getFloat("lon"); | |
| 1200 | + lat = rs.getFloat("lat"); | |
| 1201 | + location = TransGPS.LocationMake(lon, lat); | |
| 1202 | + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 1203 | + GpsSpeed=new GpsSpeed(); | |
| 1204 | + GpsSpeed.setLon((float)location.getLng()); | |
| 1205 | + GpsSpeed.setLat((float)location.getLat()); | |
| 1206 | + GpsSpeed.setLine(rs.getObject("line_id").toString()); | |
| 1207 | + //run 时注解 | |
| 1208 | + GpsSpeed.setLineName(BasicData.lineCode2NameMap.get(GpsSpeed.getLine().toString())); | |
| 1209 | + GpsSpeed.setSpeed(Float.valueOf(rs.getObject("speed_gps").toString())); | |
| 1210 | + GpsSpeed.setTimestamp((Long.valueOf(rs.getObject("ts").toString()))); | |
| 1211 | + GpsSpeed.setTimestampDate(sdf.format(new Date(GpsSpeed.getTimestamp()))); | |
| 1212 | + GpsSpeed.setUp_down(((Integer.valueOf(rs.getObject("service_state").toString())) & 0x10000000)==0?0:1); | |
| 1213 | + GpsSpeed.setVehicle(BasicData.deviceId2NbbmMap.get(rs.getObject("device_id").toString())); | |
| 1214 | + list.add(GpsSpeed); | |
| 1215 | + } | |
| 1216 | + return list; | |
| 1217 | + } | |
| 1218 | + | |
| 984 | 1219 | } |
| 1220 | + | ... | ... |
src/main/java/com/bsth/service/gps/entity/GpsSpeed.java
| 1 | 1 | package com.bsth.service.gps.entity; |
| 2 | 2 | |
| 3 | +import javax.persistence.Transient; | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * 超速异常 -ms数据库格式 |
| 5 | 7 | * Created by panzhao on 2017/4/7. |
| ... | ... | @@ -15,11 +17,59 @@ public class GpsSpeed { |
| 15 | 17 | private float lon; |
| 16 | 18 | |
| 17 | 19 | private float lat; |
| 20 | + | |
| 21 | + private String lineName; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 超速结束时的纬度 | |
| 25 | + */ | |
| 26 | + @Transient | |
| 27 | + private Float endlat; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 超速结束时的经度 | |
| 31 | + */ | |
| 32 | + @Transient | |
| 33 | + private Float endlon; | |
| 18 | 34 | |
| 19 | 35 | private float speed; |
| 20 | - | |
| 36 | + | |
| 21 | 37 | private long timestamp; |
| 22 | - | |
| 38 | + | |
| 39 | + @Transient | |
| 40 | + private String timestampDate; | |
| 41 | + | |
| 42 | + public String getTimestampDate() { | |
| 43 | + return timestampDate; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void setTimestampDate(String timestampDate) { | |
| 47 | + this.timestampDate = timestampDate; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public Long getEndtimestamp() { | |
| 51 | + return endtimestamp; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setEndtimestamp(Long endtimestamp) { | |
| 55 | + this.endtimestamp = endtimestamp; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public String getEndtimestampDate() { | |
| 59 | + return endtimestampDate; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setEndtimestampDate(String endtimestampDate) { | |
| 63 | + this.endtimestampDate = endtimestampDate; | |
| 64 | + } | |
| 65 | + | |
| 66 | + //结束时间,单位:秒/s | |
| 67 | + @Transient | |
| 68 | + private Long endtimestamp; | |
| 69 | + | |
| 70 | + @Transient | |
| 71 | + private String endtimestampDate; | |
| 72 | + | |
| 23 | 73 | public String getVehicle() { |
| 24 | 74 | return vehicle; |
| 25 | 75 | } |
| ... | ... | @@ -75,4 +125,28 @@ public class GpsSpeed { |
| 75 | 125 | public void setTimestamp(long timestamp) { |
| 76 | 126 | this.timestamp = timestamp; |
| 77 | 127 | } |
| 128 | + | |
| 129 | + public Float getEndlon() { | |
| 130 | + return endlon; | |
| 131 | + } | |
| 132 | + | |
| 133 | + public void setEndlon(Float endlon) { | |
| 134 | + this.endlon = endlon; | |
| 135 | + } | |
| 136 | + | |
| 137 | + public Float getEndlat() { | |
| 138 | + return endlat; | |
| 139 | + } | |
| 140 | + | |
| 141 | + public void setEndlat(Float endlat) { | |
| 142 | + this.endlat = endlat; | |
| 143 | + } | |
| 144 | + | |
| 145 | + public String getLineName() { | |
| 146 | + return lineName; | |
| 147 | + } | |
| 148 | + | |
| 149 | + public void setLineName(String lineName) { | |
| 150 | + this.lineName = lineName; | |
| 151 | + } | |
| 78 | 152 | } | ... | ... |
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
| ... | ... | @@ -10,6 +10,7 @@ import com.bsth.controller.realcontrol.dto.DfsjChange; |
| 10 | 10 | import com.bsth.controller.realcontrol.dto.LpData; |
| 11 | 11 | import com.bsth.data.BasicData; |
| 12 | 12 | import com.bsth.data.LineConfigData; |
| 13 | +import com.bsth.data.Station2ParkBuffer; | |
| 13 | 14 | import com.bsth.data.schedule.DayOfSchedule; |
| 14 | 15 | import com.bsth.data.schedule.SchAttrCalculator; |
| 15 | 16 | import com.bsth.data.schedule.ScheduleComparator; |
| ... | ... | @@ -590,6 +591,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 590 | 591 | //重新计算车辆当前执行班次 |
| 591 | 592 | dayOfSchedule.reCalcExecPlan(t.getClZbh()); |
| 592 | 593 | |
| 594 | + //记录站到场历时数据 | |
| 595 | + Station2ParkBuffer.put(t); | |
| 593 | 596 | |
| 594 | 597 | rs.put("ts", ts); |
| 595 | 598 | rs.put("t", t); | ... | ... |
src/main/java/com/bsth/service/schedule/TTInfoService.java
| ... | ... | @@ -12,4 +12,6 @@ public interface TTInfoService extends BService<TTInfo, Long> { |
| 12 | 12 | void validate_s_d(TTInfo ttInfo) throws ScheduleException; |
| 13 | 13 | void toggleCancel(Long id) throws ScheduleException; |
| 14 | 14 | |
| 15 | + void backUp(Long ttInfoId) throws ScheduleException; | |
| 16 | + | |
| 15 | 17 | } | ... | ... |
src/main/java/com/bsth/service/schedule/impl/TTInfoDetailServiceImpl.java
| ... | ... | @@ -157,7 +157,7 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im |
| 157 | 157 | } else { |
| 158 | 158 | Cell[] cells = sheet.getRow(0); // 获取第一行数据列 |
| 159 | 159 | for (int i = 0; i < cells.length; i++) { |
| 160 | - String cell_con = cells[i].getContents(); | |
| 160 | + String cell_con = StringUtils.trimToEmpty(cells[i].getContents()); // trimToEmpty | |
| 161 | 161 | |
| 162 | 162 | if (StringUtils.isEmpty(cell_con)) { |
| 163 | 163 | throw new Exception(String.format("第1行,第%d列数据不能为空", i + 1)); |
| ... | ... | @@ -199,7 +199,7 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im |
| 199 | 199 | Map<String, Integer> gbindexmap = new HashMap<>(); // 记录每个路牌在第几行 |
| 200 | 200 | for (int i = 1; i < sheet.getRows(); i++) { // 从第2行开始验证数据 |
| 201 | 201 | Cell bcell = sheet.getRow(i)[0]; // 获取第1列 |
| 202 | - String bcell_con = bcell.getContents(); | |
| 202 | + String bcell_con = StringUtils.trimToEmpty(bcell.getContents()); // trimToEmpty | |
| 203 | 203 | if (StringUtils.isEmpty(bcell_con)) { |
| 204 | 204 | throw new Exception(String.format("第%d行,第1列路牌无数据", i + 1)); |
| 205 | 205 | } else if (gbindexmap.get(bcell_con.trim()) != null) { |
| ... | ... | @@ -233,7 +233,7 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im |
| 233 | 233 | for (int i = 1; i < sheet.getRows(); i++) { // 从第2行开始验证数据 |
| 234 | 234 | Cell[] bcells = sheet.getRow(i); |
| 235 | 235 | for (int j = 1; j < bcells.length; j++) { // 从第2列开始 |
| 236 | - String bcell_con = bcells[j].getContents(); | |
| 236 | + String bcell_con = StringUtils.trimToEmpty(bcells[j].getContents()); // trimToEmpty | |
| 237 | 237 | if (StringUtils.isNotEmpty(bcell_con)) { |
| 238 | 238 | Matcher m1 = p1.matcher(bcell_con.trim()); |
| 239 | 239 | Matcher m2 = p2.matcher(bcell_con.trim()); | ... | ... |
src/main/java/com/bsth/service/schedule/impl/TTInfoServiceImpl.java
| 1 | 1 | package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.TTInfo; |
| 4 | -import com.bsth.service.schedule.exception.ScheduleException; | |
| 4 | +import com.bsth.entity.schedule.TTInfoBackup; | |
| 5 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 6 | +import com.bsth.repository.schedule.TTInfoBackupRepository; | |
| 7 | +import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 8 | +import com.bsth.repository.schedule.TTInfoRepository; | |
| 5 | 9 | import com.bsth.service.schedule.TTInfoService; |
| 10 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 11 | +import com.bsth.service.schedule.utils.TimeTableProto; | |
| 6 | 12 | import org.apache.commons.lang3.StringUtils; |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | 16 | import org.springframework.stereotype.Service; |
| 17 | +import org.springframework.transaction.annotation.Isolation; | |
| 18 | +import org.springframework.transaction.annotation.Propagation; | |
| 8 | 19 | import org.springframework.transaction.annotation.Transactional; |
| 9 | 20 | import org.springframework.util.CollectionUtils; |
| 10 | 21 | |
| 22 | +import java.io.PrintWriter; | |
| 23 | +import java.io.StringWriter; | |
| 24 | +import java.util.Date; | |
| 11 | 25 | import java.util.HashMap; |
| 12 | 26 | import java.util.List; |
| 13 | 27 | import java.util.Map; |
| ... | ... | @@ -17,6 +31,15 @@ import java.util.Map; |
| 17 | 31 | */ |
| 18 | 32 | @Service |
| 19 | 33 | public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTInfoService { |
| 34 | + /** 日志记录器 */ | |
| 35 | + private static final Logger LOG = LoggerFactory.getLogger(TTInfoServiceImpl.class); | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private TTInfoRepository ttInfoRepository; | |
| 39 | + @Autowired | |
| 40 | + private TTInfoDetailRepository ttInfoDetailRepository; | |
| 41 | + @Autowired | |
| 42 | + private TTInfoBackupRepository ttInfoBackupRepository; | |
| 20 | 43 | |
| 21 | 44 | @Override |
| 22 | 45 | public void validate_name(TTInfo ttInfo) throws ScheduleException { |
| ... | ... | @@ -112,4 +135,60 @@ public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTI |
| 112 | 135 | ttInfo.setIsCancel(true); |
| 113 | 136 | } |
| 114 | 137 | } |
| 138 | + | |
| 139 | + @Override | |
| 140 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | |
| 141 | + public void backUp(Long ttInfoId) throws ScheduleException { | |
| 142 | + LOG.info(">>>>>>开始备份时刻表<<<<<<"); | |
| 143 | + | |
| 144 | + try { | |
| 145 | + // 获取原始数据 | |
| 146 | + TTInfo ttInfo = ttInfoRepository.findOne(ttInfoId); | |
| 147 | + List<TTInfoDetail> ttInfoDetails = ttInfoDetailRepository.findByTtinfoId(ttInfoId); | |
| 148 | + | |
| 149 | + // protobuf序列化成二进制数据 | |
| 150 | + TimeTableProto.TTInfo.Builder tb = ttInfo.toProtoBuilder(); | |
| 151 | + for (TTInfoDetail ttInfoDetail : ttInfoDetails) { | |
| 152 | + tb.addBcInfo(ttInfoDetail.toProtoBuilder()); | |
| 153 | + } | |
| 154 | + byte[] backupbytes = tb.build().toByteArray(); | |
| 155 | + LOG.info("......时刻表={}", ttInfo.getName()); | |
| 156 | + LOG.info("......时刻表protoBuf字节数={}", backupbytes.length); | |
| 157 | + | |
| 158 | + // 更新备份日期 | |
| 159 | + Date backupdate = new Date(); | |
| 160 | + ttInfo.setLastBackUpDate(backupdate); | |
| 161 | + | |
| 162 | + // 保存备份数据 | |
| 163 | + TTInfoBackup ttInfoBackup = new TTInfoBackup(); | |
| 164 | + ttInfoBackup.setXl(ttInfo.getXl().getId()); | |
| 165 | + ttInfoBackup.setXlName(ttInfo.getXl().getName()); | |
| 166 | + ttInfoBackup.setTtInfo(ttInfoId); | |
| 167 | + ttInfoBackup.setTtInfoName(ttInfo.getName()); | |
| 168 | + ttInfoBackup.setBackUpDate(backupdate); | |
| 169 | + ttInfoBackup.setBackUpInfo(backupbytes); | |
| 170 | + | |
| 171 | + ttInfoBackupRepository.save(ttInfoBackup); | |
| 172 | +// System.out.println(backupbytes.length); | |
| 173 | +// try { | |
| 174 | +// | |
| 175 | +// TimeTableProto.TTInfo tt1 = TimeTableProto.TTInfo.parseFrom(backupbytes); | |
| 176 | +// System.out.println(tt1.getName()); | |
| 177 | +// System.out.println(tt1.getBcInfoCount()); | |
| 178 | +// } catch (Exception exp) { | |
| 179 | +// exp.printStackTrace(); | |
| 180 | +// } | |
| 181 | + | |
| 182 | + LOG.info(">>>>>>备份时刻表success<<<<<<"); | |
| 183 | + } catch (Exception exp) { | |
| 184 | + StringWriter stringWriter = new StringWriter(); | |
| 185 | + PrintWriter printWriter = new PrintWriter(stringWriter); | |
| 186 | + exp.printStackTrace(printWriter); | |
| 187 | + LOG.info("......异常stack->{}", stringWriter.toString()); | |
| 188 | + LOG.info(">>>>>>备份时刻表failed<<<<<<"); | |
| 189 | + throw new ScheduleException(exp); | |
| 190 | + } | |
| 191 | + | |
| 192 | + | |
| 193 | + } | |
| 115 | 194 | } | ... | ... |