Commit b6d025514b61ed151a1c77dd1deca2a2fc852c79

Authored by 潘钊
2 parents 1c67c679 269f7238

Merge branch 'minhang' of http://222.66.0.204:8090/panzhaov5/bsth_control into minhang

# Conflicts:
#	src/main/resources/static/real_control_v2/fragments/line_schedule/context_menu/temp_sch/main.html

Too many changes to show.

To preserve performance only 16 of 37 files are displayed.

.gitignore
@@ -10,7 +10,8 @@ test_coverage/ @@ -10,7 +10,8 @@ test_coverage/
10 .DS_Store 10 .DS_Store
11 *.iml 11 *.iml
12 tmp 12 tmp
  13 +E:/
13 14
14 # git忽略空文件夹,按照惯例,空文件夹下放置.gitkeep文件避免文件夹被忽略不上传。 15 # git忽略空文件夹,按照惯例,空文件夹下放置.gitkeep文件避免文件夹被忽略不上传。
15 -!.gitkeep  
16 -/target/ 16 +!.gitkeep
  17 +/target/
src/main/java/com/bsth/controller/gps/GpsController.java
@@ -3,8 +3,10 @@ package com.bsth.controller.gps; @@ -3,8 +3,10 @@ package com.bsth.controller.gps;
3 import com.bsth.data.BasicData; 3 import com.bsth.data.BasicData;
4 import com.bsth.data.gpsdata.GpsEntity; 4 import com.bsth.data.gpsdata.GpsEntity;
5 import com.bsth.data.gpsdata.GpsRealData; 5 import com.bsth.data.gpsdata.GpsRealData;
  6 +import com.bsth.entity.excep.Speeding;
6 import com.bsth.service.gps.GpsService; 7 import com.bsth.service.gps.GpsService;
7 import com.bsth.service.gps.entity.GpsSpeed; 8 import com.bsth.service.gps.entity.GpsSpeed;
  9 +import com.bsth.util.PageObject;
8 import com.google.common.base.Splitter; 10 import com.google.common.base.Splitter;
9 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.web.bind.annotation.*; 12 import org.springframework.web.bind.annotation.*;
@@ -192,4 +194,13 @@ public class GpsController { @@ -192,4 +194,13 @@ public class GpsController {
192 return listGpsSpeed; 194 return listGpsSpeed;
193 } 195 }
194 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 +
195 } 206 }
src/main/java/com/bsth/controller/schedule/core/TTInfoController.java
@@ -6,10 +6,7 @@ import com.bsth.entity.schedule.TTInfo; @@ -6,10 +6,7 @@ import com.bsth.entity.schedule.TTInfo;
6 import com.bsth.service.schedule.TTInfoService; 6 import com.bsth.service.schedule.TTInfoService;
7 import com.bsth.service.schedule.exception.ScheduleException; 7 import com.bsth.service.schedule.exception.ScheduleException;
8 import org.springframework.beans.factory.annotation.Autowired; 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 import java.util.HashMap; 11 import java.util.HashMap;
15 import java.util.Map; 12 import java.util.Map;
@@ -87,4 +84,18 @@ public class TTInfoController extends BController&lt;TTInfo, Long&gt; { @@ -87,4 +84,18 @@ public class TTInfoController extends BController&lt;TTInfo, Long&gt; {
87 return rtn; 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 \ No newline at end of file 102 \ No newline at end of file
src/main/java/com/bsth/entity/schedule/TTInfo.java
1 package com.bsth.entity.schedule; 1 package com.bsth.entity.schedule;
2 2
3 import com.bsth.entity.Line; 3 import com.bsth.entity.Line;
  4 +import com.bsth.service.schedule.utils.TimeTableProto;
4 import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5 6
6 import javax.persistence.*; 7 import javax.persistence.*;
@@ -63,6 +64,9 @@ public class TTInfo extends BEntity { @@ -63,6 +64,9 @@ public class TTInfo extends BEntity {
63 /** 特殊有效日期(格式:2001-01-01,多个用逗号隔开) */ 64 /** 特殊有效日期(格式:2001-01-01,多个用逗号隔开) */
64 private String special_days; 65 private String special_days;
65 66
  67 + /** 最近备份日期 */
  68 + private Date lastBackUpDate;
  69 +
66 public TTInfo() {} 70 public TTInfo() {}
67 public TTInfo(Object id, Object xlid, Object name, Object nds, Object sds) { 71 public TTInfo(Object id, Object xlid, Object name, Object nds, Object sds) {
68 if (id != null) { 72 if (id != null) {
@@ -83,6 +87,32 @@ public class TTInfo extends BEntity { @@ -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 public Long getId() { 116 public Long getId() {
87 return id; 117 return id;
88 } 118 }
@@ -178,4 +208,12 @@ public class TTInfo extends BEntity { @@ -178,4 +208,12 @@ public class TTInfo extends BEntity {
178 public void setIsCancel(Boolean isCancel) { 208 public void setIsCancel(Boolean isCancel) {
179 this.isCancel = isCancel; 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,6 +3,7 @@ package com.bsth.entity.schedule;
3 import com.bsth.entity.CarPark; 3 import com.bsth.entity.CarPark;
4 import com.bsth.entity.Line; 4 import com.bsth.entity.Line;
5 import com.bsth.entity.Station; 5 import com.bsth.entity.Station;
  6 +import com.bsth.service.schedule.utils.TimeTableProto;
6 import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 7 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7 8
8 import javax.persistence.*; 9 import javax.persistence.*;
@@ -99,6 +100,35 @@ public class TTInfoDetail extends BEntity { @@ -99,6 +100,35 @@ public class TTInfoDetail extends BEntity {
99 /** 备注 */ 100 /** 备注 */
100 private String remark; 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 public Long getId() { 132 public Long getId() {
103 return id; 133 return id;
104 } 134 }
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/service/excep/impl/SpeedingServiceImpl.java
@@ -14,13 +14,11 @@ import java.util.List; @@ -14,13 +14,11 @@ import java.util.List;
14 import java.util.Map; 14 import java.util.Map;
15 15
16 import org.springframework.jdbc.core.JdbcTemplate; 16 import org.springframework.jdbc.core.JdbcTemplate;
17 -import org.springframework.jdbc.core.RowMapper;  
18 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
19 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
20 19
21 import com.bsth.data.BasicData; 20 import com.bsth.data.BasicData;
22 import com.bsth.entity.excep.Speeding; 21 import com.bsth.entity.excep.Speeding;
23 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
24 import com.bsth.service.excep.SpeedingService; 22 import com.bsth.service.excep.SpeedingService;
25 import com.bsth.util.EchartConver; 23 import com.bsth.util.EchartConver;
26 import com.bsth.util.PageHelper; 24 import com.bsth.util.PageHelper;
@@ -42,7 +40,7 @@ public class SpeedingServiceImpl implements SpeedingService { @@ -42,7 +40,7 @@ public class SpeedingServiceImpl implements SpeedingService {
42 ResultSet rs = null; 40 ResultSet rs = null;
43 int page=Integer.parseInt(map.get("page").toString()); 41 int page=Integer.parseInt(map.get("page").toString());
44 List<Speeding> list=new ArrayList<Speeding>(); 42 List<Speeding> list=new ArrayList<Speeding>();
45 - String sql="select * from bsth_c_speeding where speed > 60 "; 43 + String sql="select * from bsth_c_speeding where 1=1 ";
46 Object line=map.get("line"); 44 Object line=map.get("line");
47 Object nbbm=map.get("nbbm"); 45 Object nbbm=map.get("nbbm");
48 Object updown=map.get("updown"); 46 Object updown=map.get("updown");
@@ -204,22 +202,40 @@ public class SpeedingServiceImpl implements SpeedingService { @@ -204,22 +202,40 @@ public class SpeedingServiceImpl implements SpeedingService {
204 int totalPage;//总页数 202 int totalPage;//总页数
205 int totalData = 0; 203 int totalData = 0;
206 if(list.size()>1){ 204 if(list.size()>1){
207 - Speeding speedingNow;//下标为i的车  
208 - Speeding speedingLast;//下标为i-1的车 205 + Speeding speedingNow;//下标为i的车辆行驶记录
  206 + Speeding speedingLast;//下标为i-1的车辆行驶记录
  207 + Speeding spped = null;//整合后的车辆行驶记录
209 String strNow; 208 String strNow;
210 String strLast; 209 String strLast;
  210 + boolean Flag = false;//判断是否有连续超速记录,默认没有
211 for(int i = 1;i<list.size();i++){ 211 for(int i = 1;i<list.size();i++){
212 speedingNow = list.get(i); 212 speedingNow = list.get(i);
213 speedingLast = list.get(i-1); 213 speedingLast = list.get(i-1);
214 - strNow = speedingNow.getVehicle()+speedingNow.getLine()+speedingNow.getUpDown();//同一车辆同一线路同一方向 214 + strNow = speedingNow.getVehicle()+speedingNow.getLine()+speedingNow.getUpDown();
215 strLast = speedingLast.getVehicle()+speedingLast.getLine()+speedingLast.getUpDown(); 215 strLast = speedingLast.getVehicle()+speedingLast.getLine()+speedingLast.getUpDown();
216 - //同一车辆同一线路同一方向并且该记录的超速的开始时间减去上一条超速记录的结束时间小于等于10s,证明该车超速。//PS:祛除数据库中的重复发送数据  
217 - if(strNow.equals(strLast) && Math.abs(speedingNow.getTimestamp()-speedingLast.getTimestamp())<=10*1000 && (speedingNow.getTimestamp()-speedingLast.getTimestamp()!=0)){  
218 - speedingLast.setEndtimestamp(speedingNow.getTimestamp());//设置结束时间时间戳  
219 - speedingLast.setEndtimestampDate(sdf.format(new Date(speedingNow.getTimestamp())));//设置结束时间  
220 - speedingLast.setEndlon(speedingNow.getLon());//设置结束时的经度  
221 - speedingLast.setEndlat(speedingNow.getLat());//设置结束时的纬度  
222 - 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 + }
223 } 239 }
224 } 240 }
225 Iterator<Speeding> speedIt = listResult.iterator(); 241 Iterator<Speeding> speedIt = listResult.iterator();
src/main/java/com/bsth/service/forms/impl/FormsServiceImpl.java
@@ -1020,19 +1020,19 @@ public class FormsServiceImpl implements FormsService { @@ -1020,19 +1020,19 @@ public class FormsServiceImpl implements FormsService {
1020 } 1020 }
1021 1021
1022 }); 1022 });
1023 - sql = "select name from bsth_c_line where sfyy = 0"; 1023 + sql = "select line_code from bsth_c_line where sfyy = 0";
1024 List<String> strList = new ArrayList<>(); 1024 List<String> strList = new ArrayList<>();
1025 strList = jdbcTemplate.query(sql, 1025 strList = jdbcTemplate.query(sql,
1026 new RowMapper<String>(){ 1026 new RowMapper<String>(){
1027 @Override 1027 @Override
1028 public String mapRow(ResultSet rs, int rowNum) throws SQLException { 1028 public String mapRow(ResultSet rs, int rowNum) throws SQLException {
1029 - return rs.getString("name"); 1029 + return rs.getString("line_code");
1030 } 1030 }
1031 }); 1031 });
1032 lineSet.addAll(strList); 1032 lineSet.addAll(strList);
1033 1033
1034 for(Line line1 : lineList){ 1034 for(Line line1 : lineList){
1035 - if(lineSet.contains(line1.getName())){ 1035 + if(lineSet.contains(line1.getLineCode())){
1036 continue; 1036 continue;
1037 } 1037 }
1038 if(line.trim().length() == 0 || line1.getLineCode().equals(line)){ 1038 if(line.trim().length() == 0 || line1.getLineCode().equals(line)){
src/main/java/com/bsth/service/gps/GpsService.java
@@ -4,6 +4,7 @@ import com.bsth.data.gpsdata.GpsEntity; @@ -4,6 +4,7 @@ import com.bsth.data.gpsdata.GpsEntity;
4 import com.bsth.service.gps.entity.GpsOutbound_DTO; 4 import com.bsth.service.gps.entity.GpsOutbound_DTO;
5 import com.bsth.service.gps.entity.GpsSpeed; 5 import com.bsth.service.gps.entity.GpsSpeed;
6 import com.bsth.service.gps.entity.GpsSpeed_DTO; 6 import com.bsth.service.gps.entity.GpsSpeed_DTO;
  7 +import com.bsth.util.PageObject;
7 8
8 import javax.servlet.http.HttpServletResponse; 9 import javax.servlet.http.HttpServletResponse;
9 10
@@ -45,4 +46,6 @@ public interface GpsService { @@ -45,4 +46,6 @@ public interface GpsService {
45 46
46 List<GpsSpeed> findPosition(String deviceid, String startdate, 47 List<GpsSpeed> findPosition(String deviceid, String startdate,
47 String enddate) throws ParseException; 48 String enddate) throws ParseException;
  49 +
  50 + PageObject<GpsSpeed> Pagequery(Map<String, Object> map);
48 } 51 }
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
@@ -16,6 +16,8 @@ import com.bsth.repository.StationRepository; @@ -16,6 +16,8 @@ import com.bsth.repository.StationRepository;
16 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; 16 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
17 import com.bsth.service.gps.entity.*; 17 import com.bsth.service.gps.entity.*;
18 import com.bsth.util.DateUtils; 18 import com.bsth.util.DateUtils;
  19 +import com.bsth.util.PageHelper;
  20 +import com.bsth.util.PageObject;
19 import com.bsth.util.TransGPS; 21 import com.bsth.util.TransGPS;
20 import com.bsth.util.TransGPS.Location; 22 import com.bsth.util.TransGPS.Location;
21 import com.bsth.util.db.DBUtils_MS; 23 import com.bsth.util.db.DBUtils_MS;
@@ -44,6 +46,7 @@ import java.net.URLEncoder; @@ -44,6 +46,7 @@ import java.net.URLEncoder;
44 import java.sql.Connection; 46 import java.sql.Connection;
45 import java.sql.PreparedStatement; 47 import java.sql.PreparedStatement;
46 import java.sql.ResultSet; 48 import java.sql.ResultSet;
  49 +import java.sql.SQLException;
47 import java.text.DecimalFormat; 50 import java.text.DecimalFormat;
48 import java.text.ParseException; 51 import java.text.ParseException;
49 import java.text.SimpleDateFormat; 52 import java.text.SimpleDateFormat;
@@ -818,7 +821,7 @@ public class GpsServiceImpl implements GpsService { @@ -818,7 +821,7 @@ public class GpsServiceImpl implements GpsService {
818 @Override 821 @Override
819 public List<GpsSpeed_DTO> speeds(String nbbm, long st, long et) { 822 public List<GpsSpeed_DTO> speeds(String nbbm, long st, long et) {
820 String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); 823 String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
821 - String sql = "select vehicle, line, up_down, lon, lat, speed,timestamp from bsth_c_speeding where vehicle=? and timestamp>? and timestamp<?"; 824 + String sql = "select vehicle, line, up_down, lon, lat, speed,timestamp from bsth_c_GpsSpeed where vehicle=? and timestamp>? and timestamp<?";
822 825
823 return GpsSpeed_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql, deviceId, st * 1000, et * 1000)); 826 return GpsSpeed_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql, deviceId, st * 1000, et * 1000));
824 } 827 }
@@ -1048,4 +1051,182 @@ public class GpsServiceImpl implements GpsService { @@ -1048,4 +1051,182 @@ public class GpsServiceImpl implements GpsService {
1048 return listResult; 1051 return listResult;
1049 1052
1050 } 1053 }
  1054 +
  1055 + @Override
  1056 + public PageObject<GpsSpeed> Pagequery(Map<String, Object> map) {
  1057 +
  1058 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1059 + List<GpsSpeed> list=findAll(map);
  1060 + List<GpsSpeed> listResult = new ArrayList<GpsSpeed>();
  1061 + int curPage;//页码
  1062 + int pageData;//每页的记录条数
  1063 + int start;//起始数据下标
  1064 + int totalPage;//总页数
  1065 + int totalData = 0;
  1066 + if(list.size()>1){
  1067 + GpsSpeed GpsSpeedNow;//下标为i的车辆行驶记录
  1068 + GpsSpeed GpsSpeedLast;//下标为i-1的车辆行驶记录
  1069 + GpsSpeed spped = null;//整合后的车辆行驶记录
  1070 + String strNow;
  1071 + String strLast;
  1072 + boolean Flag = false;//判断是否有连续超速记录,默认没有
  1073 + for(int i = 1;i<list.size();i++){
  1074 + GpsSpeedNow = list.get(i);
  1075 + GpsSpeedLast = list.get(i-1);
  1076 + strNow = GpsSpeedNow.getVehicle()+GpsSpeedNow.getLine()+GpsSpeedNow.getUp_down();
  1077 + strLast = GpsSpeedLast.getVehicle()+GpsSpeedLast.getLine()+GpsSpeedLast.getUp_down();
  1078 + if(GpsSpeedNow.getSpeed()>60 && GpsSpeedLast.getSpeed()>60 && strNow.equals(strLast)){//如果两条连续的记录都是超速且属于同一辆车。
  1079 + if(Flag==false){//
  1080 + spped = new GpsSpeed();
  1081 + spped.setLine(GpsSpeedLast.getLine());//设置连续超速记录线路
  1082 + spped.setLineName(GpsSpeedLast.getLineName());//设置连续超速记录线路名称
  1083 + spped.setVehicle(GpsSpeedLast.getVehicle());//设置连续超速记录的车辆编号
  1084 + spped.setUp_down(GpsSpeedLast.getUp_down());//设置上下行
  1085 + spped.setLon(GpsSpeedLast.getLon());//设置开始时经度
  1086 + spped.setLat(GpsSpeedLast.getLat());//设置开始时纬度
  1087 + spped.setTimestamp(GpsSpeedLast.getTimestamp());//设置连续超速记录的开始时间
  1088 + spped.setTimestampDate(GpsSpeedLast.getTimestampDate());//设置连续超速记录的开始时间戳
  1089 + }
  1090 + spped.setEndtimestamp(GpsSpeedNow.getTimestamp());//设置结束时间戳
  1091 + spped.setEndtimestampDate(sdf.format(new Date(GpsSpeedNow.getTimestamp())));//设置结束时间
  1092 + spped.setEndlon(GpsSpeedNow.getLon());//设置结束时的经度
  1093 + spped.setEndlat(GpsSpeedNow.getLat());//设置结束时的纬度
  1094 + Flag = true;
  1095 + }else{
  1096 + if(Flag){//如果上一条记录超速。
  1097 + listResult.add(spped);
  1098 + Flag = false;
  1099 + }
  1100 + }
  1101 + }
  1102 + Iterator<GpsSpeed> speedIt = listResult.iterator();
  1103 + while(speedIt.hasNext()){
  1104 + GpsSpeed GpsSpeed = speedIt.next();
  1105 + if(GpsSpeed.getEndtimestamp()-GpsSpeed.getTimestamp()<=1000){
  1106 + speedIt.remove();
  1107 + }
  1108 + }
  1109 +
  1110 + totalData = listResult.size();//总记录条数。
  1111 + if(map.get("curPage") == null || map.get("curPage").equals("0")){
  1112 + curPage = 0;
  1113 + }else{
  1114 + curPage = Integer.parseInt((String) map.get("curPage"));
  1115 + }
  1116 + pageData = Integer.parseInt((String) map.get("pageData"));//每页的记录条数
  1117 + start = (curPage - 0) * pageData; //起始记录下标。
  1118 + totalPage = totalData % pageData == 0 ? totalData / pageData : totalData / pageData +1;//总页数
  1119 + if(curPage == totalPage-1){//如果当前页等于总页数。
  1120 + listResult = listResult.subList(start, totalData);
  1121 + }else{
  1122 + listResult = listResult.subList(start, start+pageData);
  1123 + }
  1124 + }else{
  1125 + curPage = 1;
  1126 + pageData = Integer.parseInt((String) map.get("pageData"));//每页的记录条数
  1127 + totalPage =1;
  1128 + }
  1129 + Map<String,Object> paramMap = new HashMap<String,Object>();
  1130 + paramMap.put("totalPage", totalPage);
  1131 + paramMap.put("curPage", curPage);
  1132 + paramMap.put("pageData", pageData);
  1133 + PageHelper pageHelper = new PageHelper(totalData, paramMap);
  1134 + pageHelper.getMap();
  1135 + PageObject<GpsSpeed> pageObject = pageHelper.getPageObject();
  1136 + pageObject.setDataList(listResult);
  1137 + return pageObject;
  1138 + }
  1139 +
  1140 + static List<GpsSpeed> findAll(Map<String, Object> map) {
  1141 + Connection conn = null;
  1142 + PreparedStatement ps = null;
  1143 + ResultSet rs = null;
  1144 + int page=Integer.parseInt(map.get("page").toString());
  1145 + List<GpsSpeed> list=new ArrayList<GpsSpeed>();
  1146 + String sql="select * from bsth_c_gps_info where 1=1 ";
  1147 + Object line=map.get("line");
  1148 + Object nbbm=map.get("nbbm");
  1149 + Object updown=map.get("updown");
  1150 + Object startDate=map.get("startDate");
  1151 + Object endDate=map.get("endDate");
  1152 +
  1153 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1154 + if(line!=null){
  1155 + sql +=" and line_id like'%"+line.toString().trim()+"%'";
  1156 + }
  1157 +
  1158 + if(nbbm!=null){
  1159 + nbbm=BasicData.deviceId2NbbmMap.inverse().get(nbbm);
  1160 + if(nbbm!=null)
  1161 + sql +=" and vehicle like '%"+nbbm.toString()+"%'";
  1162 + }
  1163 +
  1164 + if(updown!=null){
  1165 + sql +="and industry_code like '%"+updown.toString()+"%'";
  1166 + }
  1167 + if(startDate!=null){
  1168 + if (startDate.toString().length()>0) {
  1169 + try {
  1170 + Long t1=sdf.parse(startDate.toString()+" 00:00:00").getTime();
  1171 + sql += " and ts >="+t1;
  1172 + } catch (ParseException e) {
  1173 + e.printStackTrace();
  1174 + }
  1175 + }
  1176 +
  1177 + }
  1178 + if(endDate!=null){
  1179 + if (endDate.toString().length()>0) {
  1180 + try {
  1181 + Long t2=sdf.parse(endDate.toString()+" 23:59:59").getTime();
  1182 + sql += " and ts <="+t2;
  1183 + } catch (ParseException e) {
  1184 + e.printStackTrace();
  1185 + }
  1186 + }
  1187 +
  1188 + }
  1189 +
  1190 + try {
  1191 + conn = DBUtils_MS.getConnection();
  1192 + ps = conn.prepareStatement(sql);
  1193 + rs = ps.executeQuery();
  1194 + list = resultSet2Set(rs);
  1195 + } catch (SQLException e) {
  1196 + e.printStackTrace();
  1197 + }finally {
  1198 + DBUtils_MS.close(rs, ps, conn);
  1199 + }
  1200 +
  1201 + return list;
  1202 + }
  1203 +
  1204 + static List<GpsSpeed> resultSet2Set(ResultSet rs) throws SQLException{
  1205 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1206 + List<GpsSpeed> list=new ArrayList<GpsSpeed>();
  1207 + GpsSpeed GpsSpeed;
  1208 + Float lon, lat;
  1209 + Location location;
  1210 + while(rs.next()){
  1211 + lon = rs.getFloat("lon");
  1212 + lat = rs.getFloat("lat");
  1213 + location = TransGPS.LocationMake(lon, lat);
  1214 + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));
  1215 + GpsSpeed=new GpsSpeed();
  1216 + GpsSpeed.setLon((float)location.getLng());
  1217 + GpsSpeed.setLat((float)location.getLat());
  1218 + GpsSpeed.setLine(rs.getObject("line_id").toString());
  1219 + //run 时注解
  1220 + GpsSpeed.setLineName(BasicData.lineCode2NameMap.get(GpsSpeed.getLine().toString()));
  1221 + GpsSpeed.setSpeed(Float.valueOf(rs.getObject("speed_gps").toString()));
  1222 + GpsSpeed.setTimestamp((Long.valueOf(rs.getObject("ts").toString())));
  1223 + GpsSpeed.setTimestampDate(sdf.format(new Date(GpsSpeed.getTimestamp())));
  1224 + GpsSpeed.setUp_down(((Integer.valueOf(rs.getObject("service_state").toString())) & 0x10000000)==0?0:1);
  1225 + GpsSpeed.setVehicle(BasicData.deviceId2NbbmMap.get(rs.getObject("device_id").toString()));
  1226 + list.add(GpsSpeed);
  1227 + }
  1228 + return list;
  1229 + }
  1230 +
1051 } 1231 }
  1232 +
src/main/java/com/bsth/service/gps/entity/GpsSpeed.java
1 package com.bsth.service.gps.entity; 1 package com.bsth.service.gps.entity;
2 2
  3 +import javax.persistence.Transient;
  4 +
3 /** 5 /**
4 * 超速异常 -ms数据库格式 6 * 超速异常 -ms数据库格式
5 * Created by panzhao on 2017/4/7. 7 * Created by panzhao on 2017/4/7.
@@ -15,11 +17,59 @@ public class GpsSpeed { @@ -15,11 +17,59 @@ public class GpsSpeed {
15 private float lon; 17 private float lon;
16 18
17 private float lat; 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 private float speed; 35 private float speed;
20 - 36 +
21 private long timestamp; 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 public String getVehicle() { 73 public String getVehicle() {
24 return vehicle; 74 return vehicle;
25 } 75 }
@@ -75,4 +125,28 @@ public class GpsSpeed { @@ -75,4 +125,28 @@ public class GpsSpeed {
75 public void setTimestamp(long timestamp) { 125 public void setTimestamp(long timestamp) {
76 this.timestamp = timestamp; 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/report/impl/CulateMileageServiceImpl.java
@@ -738,6 +738,7 @@ public class CulateMileageServiceImpl implements CulateMileageService{ @@ -738,6 +738,7 @@ public class CulateMileageServiceImpl implements CulateMileageService{
738 // TODO Auto-generated method stub 738 // TODO Auto-generated method stub
739 double ljjcc=0.0; 739 double ljjcc=0.0;
740 double ljyy=0.0; 740 double ljyy=0.0;
  741 + double ljkfks=0.0;
741 for (int i = 0; i < lists.size(); i++) { 742 for (int i = 0; i < lists.size(); i++) {
742 ScheduleRealInfo t=lists.get(i); 743 ScheduleRealInfo t=lists.get(i);
743 if(t.isSflj()){ 744 if(t.isSflj()){
@@ -760,6 +761,24 @@ public class CulateMileageServiceImpl implements CulateMileageService{ @@ -760,6 +761,24 @@ public class CulateMileageServiceImpl implements CulateMileageService{
760 }*/ 761 }*/
761 } 762 }
762 763
  764 + if(t.getBcType().equals("ldks")){
  765 + Set<ChildTaskPlan> childTaskPlans = t.getcTasks();
  766 + if(childTaskPlans.isEmpty()){
  767 + if(!t.isDestroy()){
  768 + ljkfks =Arith.add(ljkfks, t.getJhlc());
  769 + }
  770 +
  771 + }
  772 + /*else{
  773 + //临加进出场子任务 待统计
  774 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  775 + double zrwlc=0.0;
  776 + boolean fage=false;
  777 + while (it.hasNext()) {
  778 + ChildTaskPlan childTaskPlan = it.next();
  779 + }
  780 + }*/
  781 + }
763 if(!isInOut(t)){ 782 if(!isInOut(t)){
764 Set<ChildTaskPlan> childTaskPlans = t.getcTasks(); 783 Set<ChildTaskPlan> childTaskPlans = t.getcTasks();
765 if(childTaskPlans.isEmpty()){ 784 if(childTaskPlans.isEmpty()){
@@ -774,6 +793,14 @@ public class CulateMileageServiceImpl implements CulateMileageService{ @@ -774,6 +793,14 @@ public class CulateMileageServiceImpl implements CulateMileageService{
774 if(childTaskPlan.getMileageType().equals("service")){ 793 if(childTaskPlan.getMileageType().equals("service")){
775 ljyy =Arith.add(ljyy,childTaskPlan.getMileage()); 794 ljyy =Arith.add(ljyy,childTaskPlan.getMileage());
776 } 795 }
  796 + if(childTaskPlan.getMileageType().equals("empty")){
  797 + if(childTaskPlan.getType2().equals("2")||childTaskPlan.getType2().equals("3")){
  798 + ljjcc =Arith.add(ljjcc, childTaskPlan.getMileage());
  799 + }
  800 + if(childTaskPlan.getType2().equals("1")){
  801 + ljkfks =Arith.add(ljkfks, childTaskPlan.getMileage());
  802 + }
  803 + }
777 } 804 }
778 } 805 }
779 } 806 }
@@ -784,6 +811,7 @@ public class CulateMileageServiceImpl implements CulateMileageService{ @@ -784,6 +811,7 @@ public class CulateMileageServiceImpl implements CulateMileageService{
784 Map<String, Double> map=new HashMap<String,Double>(); 811 Map<String, Double> map=new HashMap<String,Double>();
785 map.put("ljjcc", ljjcc); 812 map.put("ljjcc", ljjcc);
786 map.put("ljyy", ljyy); 813 map.put("ljyy", ljyy);
  814 + map.put("ljkfks", ljkfks);
787 return map; 815 return map;
788 } 816 }
789 817
@@ -858,20 +886,32 @@ public class CulateMileageServiceImpl implements CulateMileageService{ @@ -858,20 +886,32 @@ public class CulateMileageServiceImpl implements CulateMileageService{
858 double zrwjcclc=0.0; 886 double zrwjcclc=0.0;
859 for (int i = 0; i < lists.size(); i++) { 887 for (int i = 0; i < lists.size(); i++) {
860 ScheduleRealInfo t=lists.get(i); 888 ScheduleRealInfo t=lists.get(i);
861 - if(!isInOut(t)){  
862 - Set<ChildTaskPlan> childTaskPlans = t.getcTasks();  
863 - if(!childTaskPlans.isEmpty()){  
864 - Iterator<ChildTaskPlan> it = childTaskPlans.iterator();  
865 - while (it.hasNext()) {  
866 - ChildTaskPlan childTaskPlan = it.next();  
867 - if(childTaskPlan.getType2().equals("2")||childTaskPlan.getType2().equals("3")){  
868 - if (childTaskPlan.isDestroy()) {  
869 - if(childTaskPlan.getReason().equals(item)){  
870 - zrwjcclc=Arith.add(zrwjcclc,childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage());  
871 - }  
872 - }  
873 - }  
874 - } 889 + if(!t.isSflj()){
  890 + if(!isInOut(t)){
  891 + Set<ChildTaskPlan> childTaskPlans = t.getcTasks();
  892 + if(!childTaskPlans.isEmpty()){
  893 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  894 + while (it.hasNext()) {
  895 + ChildTaskPlan childTaskPlan = it.next();
  896 + if(item.equals("空放")){
  897 + if(childTaskPlan.getType2().equals("1")){
  898 + if (!childTaskPlan.isDestroy()) {
  899 + if(childTaskPlan.getReason().equals(item)){
  900 + zrwjcclc=Arith.add(zrwjcclc,childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage());
  901 + }
  902 + }
  903 + }
  904 + }else{
  905 + if(childTaskPlan.getType2().equals("2")||childTaskPlan.getType2().equals("3")){
  906 + if (!childTaskPlan.isDestroy()) {
  907 + if(childTaskPlan.getReason().equals(item)){
  908 + zrwjcclc=Arith.add(zrwjcclc,childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage());
  909 + }
  910 + }
  911 + }
  912 + }
  913 + }
  914 + }
875 } 915 }
876 } 916 }
877 } 917 }
src/main/java/com/bsth/service/report/impl/ReportServiceImpl.java
@@ -37,6 +37,10 @@ import java.util.*; @@ -37,6 +37,10 @@ import java.util.*;
37 @Service 37 @Service
38 public class ReportServiceImpl implements ReportService{ 38 public class ReportServiceImpl implements ReportService{
39 39
  40 + private static long zgf1 = 6 * 60 + 31,
  41 + zgf2 = 8 * 60 + 30,
  42 + wgf1 = 16 * 60 + 1,
  43 + wgf2 = 18 * 60;
40 44
41 private Logger logger = LoggerFactory.getLogger(this.getClass()); 45 private Logger logger = LoggerFactory.getLogger(this.getClass());
42 46
@@ -466,38 +470,35 @@ public class ReportServiceImpl implements ReportService{ @@ -466,38 +470,35 @@ public class ReportServiceImpl implements ReportService{
466 System.out.println(609360/60); 470 System.out.println(609360/60);
467 System.out.println(609360%60); 471 System.out.println(609360%60);
468 } 472 }
469 - @Override 473 +/* @Override
470 public List<Map<String, Object>> tbodyTime3(String line, String ttinfo) { 474 public List<Map<String, Object>> tbodyTime3(String line, String ttinfo) {
471 // TODO Auto-generated method stub 475 // TODO Auto-generated method stub
472 List<Map<String, Object>> list=new ArrayList<Map<String,Object>>(); 476 List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
473 477
474 478
475 479
476 - String sqlZd=" select t.*,x.station_name as qdz_name from ("  
477 - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'zqc' as lx "  
478 - + " from bsth_c_s_ttinfo_detail where "  
479 - + " bc_type='normal' and ttinfo ='"+ttinfo+"' "  
480 - + " and fcsj>'06:31' and fcsj<'08:00' group by qdz,lp) t1"  
481 - + " group by qdz " 480 + String sqlZd="select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqc' AS lx from ("
  481 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"' "
  482 + + " and bc_type ='normal'"
  483 + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))"
  484 + + " group by cl_zbh,qdz_name) a group by a.qdz_name"
482 + " union " 485 + " union "
483 - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'wqc' as lx "  
484 - + " from bsth_c_s_ttinfo_detail where "  
485 - + " bc_type='normal' and ttinfo ='"+ttinfo+"' "  
486 - + " and fcsj>'16:01' and fcsj<'18:00' group by qdz,lp) t2"  
487 - + " group by qdz " 486 + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqc' AS lx from ("
  487 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'"
  488 + + " and bc_type ='normal' "
  489 + + " and fcsj >'16:01' and fcsj<'18:00' group by cl_zbh,qdz_name "
  490 + + " ) a group by a.qdz_name "
488 + " union " 491 + " union "
489 - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'zqj' as lx "  
490 - + " from bsth_c_s_ttinfo_detail where "  
491 - + " bc_type='region' and ttinfo ='"+ttinfo+"' "  
492 - + " and fcsj>'06:31' and fcsj<'08:00' group by qdz,lp) t3"  
493 - + " group by qdz " 492 + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqj' AS lx from ("
  493 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'"
  494 + + " and bc_type ='region' "
  495 + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))"
  496 + + " group by cl_zbh,qdz_name) a group by a.qdz_name"
494 + " union " 497 + " union "
495 - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'wqj' as lx "  
496 - + " from bsth_c_s_ttinfo_detail where "  
497 - + " bc_type='region' and ttinfo ='"+ttinfo+"' "  
498 - + " and fcsj>'16:01' and fcsj<'18:00' group by qdz,lp) t4"  
499 - + " group by qdz ) t left join bsth_c_station x on t.qdz=x.id";  
500 - 498 + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqj' AS lx from ("
  499 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'"
  500 + + " and bc_type ='region' and fcsj >'16:01' and fcsj<'18:00'"
  501 + + " group by cl_zbh,qdz_name) a group by a.qdz_name";
501 List<Map<String, Object>> lists= jdbcTemplate.query(sqlZd, 502 List<Map<String, Object>> lists= jdbcTemplate.query(sqlZd,
502 new RowMapper<Map<String, Object>>(){ 503 new RowMapper<Map<String, Object>>(){
503 @Override 504 @Override
@@ -556,6 +557,208 @@ public class ReportServiceImpl implements ReportService{ @@ -556,6 +557,208 @@ public class ReportServiceImpl implements ReportService{
556 557
557 } 558 }
558 return list; 559 return list;
  560 + }*/
  561 + @Override
  562 + public List<Map<String, Object>> tbodyTime3(String line, String ttinfo) {
  563 + // TODO Auto-generated method stub
  564 + List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
  565 + List<Map<String, Object>> list_s=new ArrayList<Map<String,Object>>();
  566 +
  567 +
  568 + /*String sqlZd="select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqc' AS lx from ("
  569 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"' "
  570 + + " and bc_type ='normal'"
  571 + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))"
  572 + + " group by cl_zbh,qdz_name) a group by a.qdz_name"
  573 + + " union "
  574 + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqc' AS lx from ("
  575 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'"
  576 + + " and bc_type ='normal' "
  577 + + " and fcsj >'16:01' and fcsj<'18:00' group by cl_zbh,qdz_name "
  578 + + " ) a group by a.qdz_name "
  579 + + " union "
  580 + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqj' AS lx from ("
  581 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'"
  582 + + " and bc_type ='region' "
  583 + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))"
  584 + + " group by cl_zbh,qdz_name) a group by a.qdz_name"
  585 + + " union "
  586 + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqj' AS lx from ("
  587 + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'"
  588 + + " and bc_type ='region' and fcsj >'16:01' and fcsj<'18:00'"
  589 + + " group by cl_zbh,qdz_name) a group by a.qdz_name";*/
  590 +
  591 + String sqlCl="SELECT cl_zbh,qdz_name,bc_type,fcsj,bcsj FROM"
  592 + + " bsth_c_s_sp_info WHERE tt_info = '"+ttinfo+"' "
  593 + + " AND bc_type = 'normal' order by qdz_name";
  594 +
  595 + List<Map<String, Object>> listj= jdbcTemplate.query(sqlCl,
  596 + new RowMapper<Map<String, Object>>(){
  597 + @Override
  598 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  599 + Map<String, Object> m=new HashMap<String,Object>();
  600 + m.put("cl_zbh", rs.getString("cl_zbh"));
  601 + m.put("qdz_name", rs.getString("qdz_name"));
  602 + m.put("bcType", rs.getString("bc_type"));
  603 + m.put("fcsj", rs.getString("fcsj"));
  604 + m.put("bcsj", rs.getString("bcsj"));
  605 + return m;
  606 + }
  607 + });
  608 +
  609 + String sqlZd="select qdz_name ,bc_type from bsth_c_s_sp_info WHERE tt_info = '"+ttinfo+"' "
  610 + + " AND (bc_type = 'normal' or bc_type='region') group by qdz_name ,bc_type "
  611 + + " order by qdz_name";
  612 + List<Map<String, Object>> lists= jdbcTemplate.query(sqlZd,
  613 + new RowMapper<Map<String, Object>>(){
  614 + @Override
  615 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  616 + Map<String, Object> m=new HashMap<String,Object>();
  617 + m.put("zdm", rs.getString("qdz_name"));
  618 + m.put("bcType", rs.getString("bc_type"));
  619 + return m;
  620 + }
  621 + });
  622 +
  623 + for (int i = 0; i < lists.size(); i++) {
  624 + Map<String, Object> z=new HashMap<String,Object>();
  625 + Map<String, Object> w=new HashMap<String,Object>();
  626 + Map<String, Object> p=lists.get(i);
  627 + int zbcs=0;
  628 + int wbcs=0;
  629 + if(p.get("bcType").toString().equals("normal")){
  630 + for (int j = 0; j < listj.size(); j++) {
  631 + if(listj.get(j).get("qdz_name").toString().equals(p.get("zdm").toString()) &&
  632 + listj.get(j).get("bcType").toString().equals("normal")){
  633 + String time=listj.get(j).get("fcsj").toString();
  634 + long bcsj= Long.parseLong(listj.get(j).get("bcsj").toString());
  635 + String clZbh=listj.get(j).get("cl_zbh").toString();
  636 + String[] fcsjStr = time.split(":");
  637 + long fcsj= Long.parseLong(fcsjStr[0])*60+Long.parseLong(fcsjStr[1]);
  638 + long ddsj=fcsj+bcsj;
  639 + if((fcsj>=zgf1 && fcsj<=zgf2) || (ddsj>=zgf1&&ddsj<=zgf2)
  640 + || (fcsj<zgf1&&ddsj>zgf2)){
  641 + if(p.get("z"+clZbh)==null){
  642 + zbcs++;
  643 + p.put("z"+clZbh, clZbh);
  644 + }
  645 + }
  646 +
  647 + if((fcsj>=wgf1 && fcsj<=wgf2) || (ddsj>=wgf1&&ddsj<=wgf2)
  648 + || (fcsj<wgf1&&ddsj>wgf2)){
  649 + if(p.get("w"+clZbh)==null){
  650 + wbcs++;
  651 + p.put("w"+clZbh, clZbh);
  652 + }
  653 + }
  654 + }
  655 +
  656 + }
  657 + if(zbcs>0){
  658 + z.put("zdm", p.get("zdm"));
  659 + z.put("cls", zbcs);
  660 + z.put("lx", "zqc");
  661 + list_s.add(z);
  662 + }
  663 + if(wbcs>0){
  664 + w.put("zdm", p.get("zdm"));
  665 + w.put("cls", zbcs);
  666 + w.put("lx", "wqc");
  667 + list_s.add(w);
  668 + }
  669 +
  670 + }
  671 +
  672 + if(p.get("bcType").equals("region")){
  673 + for (int j = 0; j < listj.size(); j++) {
  674 + if(listj.get(j).get("qdz_name").toString().equals(p.get("zdm").toString()) &&
  675 + listj.get(j).get("bcType").toString().equals("region")){
  676 + String time=listj.get(j).get("fcsj").toString();
  677 + long bcsj= Long.parseLong(listj.get(j).get("bcsj").toString());
  678 + String clZbh=listj.get(j).get("cl_zbh").toString();
  679 + String[] fcsjStr = time.split(":");
  680 + long fcsj= Long.parseLong(fcsjStr[0])*60+Long.parseLong(fcsjStr[1]);
  681 + long ddsj=fcsj+bcsj;
  682 + if((fcsj>=zgf1 && fcsj<=zgf2) || (ddsj>=zgf1&&ddsj<=zgf2)
  683 + || (fcsj<zgf1&&ddsj>zgf2)){
  684 + if(p.get("z"+clZbh)==null){
  685 + zbcs++;
  686 + p.put("z"+clZbh, clZbh);
  687 + }
  688 + }
  689 +
  690 + if((fcsj>=wgf1 && fcsj<=wgf2) || (ddsj>=wgf1&&ddsj<=wgf2)
  691 + || (fcsj<wgf1&&ddsj>wgf2)){
  692 + if(p.get("w"+clZbh)==null){
  693 + wbcs++;
  694 + p.put("w"+clZbh, clZbh);
  695 + }
  696 + }
  697 + }
  698 +
  699 + }
  700 + if(zbcs>0){
  701 + z.put("zdm", p.get("zdm"));
  702 + z.put("cls", zbcs);
  703 + z.put("lx", "zqj");
  704 + list_s.add(z);
  705 + }
  706 + if(wbcs>0){
  707 + w.put("zdm", p.get("zdm"));
  708 + w.put("cls", zbcs);
  709 + w.put("lx", "wqj");
  710 + list_s.add(w);
  711 + }
  712 + }
  713 +
  714 + }
  715 + int a=0;
  716 + int b=0;
  717 + int c=0;
  718 + int d=0;
  719 + for(int i=0;i<list_s.size();i++){
  720 + boolean fage=true;
  721 + Map<String, Object> newMap= new HashMap<String, Object>();
  722 + list.add(newMap);
  723 + Map<String, Object> maps=list_s.get(i);
  724 + if(maps.get("lx").equals("zqc")){
  725 + list.get(a).put("zqcZm", maps.get("zdm"));
  726 + list.get(a).put("zqcCls", maps.get("cls"));
  727 + a++;
  728 + fage=false;
  729 + }else if(maps.get("lx").equals("wqc")){
  730 + list.get(b).put("wqcZm", maps.get("zdm"));
  731 + list.get(b).put("wqcCls", maps.get("cls"));
  732 + b++;
  733 + fage=false;
  734 + }else if(maps.get("lx").equals("zqj")){
  735 + list.get(c).put("zqjZm", maps.get("zdm"));
  736 + list.get(c).put("zqjCls", maps.get("cls"));
  737 + c++;
  738 + fage=false;
  739 + }else if(maps.get("lx").equals("wqj")){
  740 + list.get(d).put("wqjZm", maps.get("zdm"));
  741 + list.get(d).put("wqjCls", maps.get("cls"));
  742 + d++;
  743 + fage=false;
  744 + }
  745 + if(fage){
  746 + break;
  747 + }
  748 + }
  749 + boolean status=true;
  750 + while (status) {
  751 + for (int i = 0; i < list.size(); i++) {
  752 + if(list.get(i).isEmpty()){
  753 + list.remove(i);
  754 + status=true;
  755 + }else{
  756 + status=false;
  757 + }
  758 + }
  759 +
  760 + }
  761 + return list;
559 } 762 }
560 763
561 @Override 764 @Override
@@ -1501,11 +1704,18 @@ public class ReportServiceImpl implements ReportService{ @@ -1501,11 +1704,18 @@ public class ReportServiceImpl implements ReportService{
1501 Map<String, Object> m = new HashMap<String, Object>(); 1704 Map<String, Object> m = new HashMap<String, Object>();
1502 m.put("date", date); 1705 m.put("date", date);
1503 m.put("date1", date2); 1706 m.put("date1", date2);
  1707 + String by=map.get("by").toString();
  1708 + String xls="";
  1709 + if(by.equals("sj")){
  1710 + xls="countByLine.xls";
  1711 + }else{
  1712 + xls="countByLines.xls";
  1713 + }
1504 ReportUtils ee = new ReportUtils(); 1714 ReportUtils ee = new ReportUtils();
1505 try { 1715 try {
1506 listI.add(lMap.iterator()); 1716 listI.add(lMap.iterator());
1507 String path = this.getClass().getResource("/").getPath() + "static/pages/forms/"; 1717 String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
1508 - ee.excelReplace(listI, new Object[]{m}, path + "mould/countByLine.xls", 1718 + ee.excelReplace(listI, new Object[]{m}, path + "mould/"+xls,
1509 path + "export/线路公里统计表.xls"); 1719 path + "export/线路公里统计表.xls");
1510 } catch (Exception e) { 1720 } catch (Exception e) {
1511 // TODO: handle exception 1721 // TODO: handle exception
@@ -1572,9 +1782,12 @@ public class ReportServiceImpl implements ReportService{ @@ -1572,9 +1782,12 @@ public class ReportServiceImpl implements ReportService{
1572 Map<String, Double> culateLjMile=culateService.culateLjMile(lists); 1782 Map<String, Double> culateLjMile=culateService.culateLjMile(lists);
1573 double ljyy=culateLjMile.get("ljyy"); 1783 double ljyy=culateLjMile.get("ljyy");
1574 double ljjcc=culateLjMile.get("ljjcc"); 1784 double ljjcc=culateLjMile.get("ljjcc");
  1785 + double ljkfks=culateLjMile.get("ljkfks");
1575 map.put("ljyy", ljyy); 1786 map.put("ljyy", ljyy);
1576 map.put("ljjcc", ljjcc); 1787 map.put("ljjcc", ljjcc);
1577 - double ljlc=Arith.add(ljyy, ljjcc); 1788 + map.put("ljkfks", ljkfks);
  1789 +
  1790 + double ljlc=Arith.add(Arith.add(ljyy, ljjcc),ljkfks);
1578 1791
1579 double lbss=culateService.culateSsMile(list);//烂班少驶 1792 double lbss=culateService.culateSsMile(list);//烂班少驶
1580 map.put("lbss", lbss); 1793 map.put("lbss", lbss);
@@ -1594,18 +1807,18 @@ public class ReportServiceImpl implements ReportService{ @@ -1594,18 +1807,18 @@ public class ReportServiceImpl implements ReportService{
1594 double zrwjcclc=culateService.culateZrwJccLc(list, "故障"); 1807 double zrwjcclc=culateService.culateZrwJccLc(list, "故障");
1595 double zrwjcclc1=culateService.culateZrwJccLc(list, "肇事"); 1808 double zrwjcclc1=culateService.culateZrwJccLc(list, "肇事");
1596 double zrwjcclc2=culateService.culateZrwJccLc(list, "纠纷"); 1809 double zrwjcclc2=culateService.culateZrwJccLc(list, "纠纷");
  1810 + double zrwjcclcqt=culateService.culateZrwJccLc(list, "其他");
  1811 + map.put("jhwjcclc_z", Arith.add(jhwjcclc,zrwjcclcqt));
1597 map.put("zrwjcclc", zrwjcclc); 1812 map.put("zrwjcclc", zrwjcclc);
1598 map.put("zrwjcclc1", zrwjcclc1); 1813 map.put("zrwjcclc1", zrwjcclc1);
1599 map.put("zrwjcclc2", zrwjcclc2); 1814 map.put("zrwjcclc2", zrwjcclc2);
1600 - double zrwjcc=Arith.add(Arith.add(zrwjcclc, zrwjcclc1), zrwjcclc2);  
1601 - double kfks=culateService.culateKfksLc(lists); 1815 + map.put("zrwjcclcqt", zrwjcclcqt);
  1816 + double zrwjcc=Arith.add(Arith.add(Arith.add(zrwjcclc, zrwjcclc1), zrwjcclc2),zrwjcclcqt);
  1817 + double kfks=Arith.add(culateService.culateKfksLc(lists),culateService.culateZrwJccLc(list, "空放"));
1602 map.put("kfks", kfks); 1818 map.put("kfks", kfks);
1603 double zlc=Arith.add(Arith.add(Arith.add(zrwjcc, ljlc), 1819 double zlc=Arith.add(Arith.add(Arith.add(zrwjcc, ljlc),
1604 Arith.add(zjcclc, zyylc)),kfks); 1820 Arith.add(zjcclc, zyylc)),kfks);
1605 -  
1606 -  
1607 map.put("zlc", zlc); 1821 map.put("zlc", zlc);
1608 -  
1609 } 1822 }
1610 return map; 1823 return map;
1611 } 1824 }
@@ -1830,10 +2043,22 @@ public class ReportServiceImpl implements ReportService{ @@ -1830,10 +2043,22 @@ public class ReportServiceImpl implements ReportService{
1830 m.put("date", date); 2043 m.put("date", date);
1831 m.put("date1", date2); 2044 m.put("date1", date2);
1832 String xls=""; 2045 String xls="";
  2046 + String by=map.get("by").toString();
  2047 +
  2048 +
1833 if(zt.equals("zbh")){ 2049 if(zt.equals("zbh")){
1834 - xls="countByBus1.xls"; 2050 + if(by.equals("sj")){
  2051 + xls="countByBus1.xls";
  2052 + }else{
  2053 + xls="countByBus1s.xls";
  2054 + }
1835 }else{ 2055 }else{
1836 - xls="countByBus2.xls"; 2056 +
  2057 + if(by.equals("sj")){
  2058 + xls="countByBus2.xls";
  2059 + }else{
  2060 + xls="countByBus2s.xls";
  2061 + }
1837 } 2062 }
1838 ReportUtils ee = new ReportUtils(); 2063 ReportUtils ee = new ReportUtils();
1839 try { 2064 try {
@@ -1896,7 +2121,8 @@ public class ReportServiceImpl implements ReportService{ @@ -1896,7 +2121,8 @@ public class ReportServiceImpl implements ReportService{
1896 String jGh= m.get("jGh")==null?"":m.get("jGh").toString(); 2121 String jGh= m.get("jGh")==null?"":m.get("jGh").toString();
1897 String sGh= m.get("sGh")==null?"":m.get("sGh").toString(); 2122 String sGh= m.get("sGh")==null?"":m.get("sGh").toString();
1898 double jhzlc = 0.0,jhlc= 0.0,jcclc= 0.0,zlc= 0.0,jhnlc= 0.0,jhwlc= 0.0, 2123 double jhzlc = 0.0,jhlc= 0.0,jcclc= 0.0,zlc= 0.0,jhnlc= 0.0,jhwlc= 0.0,
1899 - jhnjcclc= 0.0,jhwjcclc= 0.0,zrwjcclc= 0.0,lbss= 0.0,ssgl_lz= 0.0, 2124 + jhnjcclc= 0.0,jhwjcclc= 0.0,jhwjcclc_z=0.0,zrwjcclc= 0.0,zrwjcclc1= 0.0,zrwjcclc2= 0.0,
  2125 + zrwjcclcqt=0.0,lbss= 0.0,ssgl_lz= 0.0,
1900 ssgl_dm= 0.0,ssgl_gz= 0.0,ssgl_jf= 0.0,ssgl_zs= 0.0,ssgl_qr= 0.0,ssgl_qc= 0.0, 2126 ssgl_dm= 0.0,ssgl_gz= 0.0,ssgl_jf= 0.0,ssgl_zs= 0.0,ssgl_qr= 0.0,ssgl_qc= 0.0,
1901 ssgl_kx= 0.0,ssgl_qh= 0.0,ssgl_yw= 0.0,ssgl_other= 0.0,ljyy=0.0,ljjcc=0.0, 2127 ssgl_kx= 0.0,ssgl_qh= 0.0,ssgl_yw= 0.0,ssgl_other= 0.0,ljyy=0.0,ljjcc=0.0,
1902 kfks=0.0,yhl=0.0,jzl=0.0,hyl=0.0,dhl=0.0,cdl=0.0; 2128 kfks=0.0,yhl=0.0,jzl=0.0,hyl=0.0,dhl=0.0,cdl=0.0;
@@ -1915,7 +2141,11 @@ public class ReportServiceImpl implements ReportService{ @@ -1915,7 +2141,11 @@ public class ReportServiceImpl implements ReportService{
1915 jhwlc=Arith.add(jhwlc, map.get("jhwlc")); 2141 jhwlc=Arith.add(jhwlc, map.get("jhwlc"));
1916 jhnjcclc=Arith.add(jhnjcclc, map.get("jhnjcclc")); 2142 jhnjcclc=Arith.add(jhnjcclc, map.get("jhnjcclc"));
1917 jhwjcclc=Arith.add(jhwjcclc, map.get("jhwjcclc")); 2143 jhwjcclc=Arith.add(jhwjcclc, map.get("jhwjcclc"));
  2144 + jhwjcclc_z=Arith.add(jhwjcclc_z, map.get("jhwjcclc_z"));
1918 zrwjcclc=Arith.add(zrwjcclc, map.get("zrwjcclc")); 2145 zrwjcclc=Arith.add(zrwjcclc, map.get("zrwjcclc"));
  2146 + zrwjcclc1=Arith.add(zrwjcclc1, map.get("zrwjcclc1"));
  2147 + zrwjcclc2=Arith.add(zrwjcclc2, map.get("zrwjcclc2"));
  2148 + zrwjcclcqt=Arith.add(zrwjcclcqt, map.get("zrwjcclcqt"));
1919 lbss=Arith.add(lbss, map.get("lbss")); 2149 lbss=Arith.add(lbss, map.get("lbss"));
1920 ssgl_lz=Arith.add(ssgl_lz, map.get("ssgl_lz")); 2150 ssgl_lz=Arith.add(ssgl_lz, map.get("ssgl_lz"));
1921 ssgl_dm=Arith.add(ssgl_dm, map.get("ssgl_dm")); 2151 ssgl_dm=Arith.add(ssgl_dm, map.get("ssgl_dm"));
@@ -1962,7 +2192,11 @@ public class ReportServiceImpl implements ReportService{ @@ -1962,7 +2192,11 @@ public class ReportServiceImpl implements ReportService{
1962 newMap.put("jhwlc", jhwlc); 2192 newMap.put("jhwlc", jhwlc);
1963 newMap.put("jhnjcclc", jhnjcclc); 2193 newMap.put("jhnjcclc", jhnjcclc);
1964 newMap.put("jhwjcclc", jhwjcclc); 2194 newMap.put("jhwjcclc", jhwjcclc);
  2195 + newMap.put("jhwjcclc_z", jhwjcclc_z);
1965 newMap.put("zrwjcclc", zrwjcclc); 2196 newMap.put("zrwjcclc", zrwjcclc);
  2197 + newMap.put("zrwjcclc1", zrwjcclc1);
  2198 + newMap.put("zrwjcclc2", zrwjcclc2);
  2199 + newMap.put("zrwjcclcqt", zrwjcclcqt);
1966 newMap.put("lbss", lbss); 2200 newMap.put("lbss", lbss);
1967 newMap.put("ssgl_lz", ssgl_lz); 2201 newMap.put("ssgl_lz", ssgl_lz);
1968 newMap.put("ssgl_dm",ssgl_dm); 2202 newMap.put("ssgl_dm",ssgl_dm);
src/main/java/com/bsth/service/schedule/TTInfoService.java
@@ -12,4 +12,6 @@ public interface TTInfoService extends BService&lt;TTInfo, Long&gt; { @@ -12,4 +12,6 @@ public interface TTInfoService extends BService&lt;TTInfo, Long&gt; {
12 void validate_s_d(TTInfo ttInfo) throws ScheduleException; 12 void validate_s_d(TTInfo ttInfo) throws ScheduleException;
13 void toggleCancel(Long id) throws ScheduleException; 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/TTInfoServiceImpl.java
1 package com.bsth.service.schedule.impl; 1 package com.bsth.service.schedule.impl;
2 2
3 import com.bsth.entity.schedule.TTInfo; 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 import com.bsth.service.schedule.TTInfoService; 9 import com.bsth.service.schedule.TTInfoService;
  10 +import com.bsth.service.schedule.exception.ScheduleException;
  11 +import com.bsth.service.schedule.utils.TimeTableProto;
6 import org.apache.commons.lang3.StringUtils; 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 import org.springframework.stereotype.Service; 16 import org.springframework.stereotype.Service;
  17 +import org.springframework.transaction.annotation.Isolation;
  18 +import org.springframework.transaction.annotation.Propagation;
8 import org.springframework.transaction.annotation.Transactional; 19 import org.springframework.transaction.annotation.Transactional;
9 import org.springframework.util.CollectionUtils; 20 import org.springframework.util.CollectionUtils;
10 21
  22 +import java.io.PrintWriter;
  23 +import java.io.StringWriter;
  24 +import java.util.Date;
11 import java.util.HashMap; 25 import java.util.HashMap;
12 import java.util.List; 26 import java.util.List;
13 import java.util.Map; 27 import java.util.Map;
@@ -17,6 +31,15 @@ import java.util.Map; @@ -17,6 +31,15 @@ import java.util.Map;
17 */ 31 */
18 @Service 32 @Service
19 public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTInfoService { 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 @Override 44 @Override
22 public void validate_name(TTInfo ttInfo) throws ScheduleException { 45 public void validate_name(TTInfo ttInfo) throws ScheduleException {
@@ -112,4 +135,60 @@ public class TTInfoServiceImpl extends BServiceImpl&lt;TTInfo, Long&gt; implements TTI @@ -112,4 +135,60 @@ public class TTInfoServiceImpl extends BServiceImpl&lt;TTInfo, Long&gt; implements TTI
112 ttInfo.setIsCancel(true); 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 }