Commit 59abf235505580cd0a36f315c9a3c8703a92d375

Authored by 徐烜
1 parent 22c4d88d

Update

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/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/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/schedule/TTInfoService.java
... ... @@ -12,4 +12,6 @@ public interface TTInfoService extends BService&lt;TTInfo, Long&gt; {
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/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&lt;TTInfo, Long&gt; 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 }
... ...
src/main/resources/static/pages/scheduleApp/module/common/prj-common-globalservice.js
... ... @@ -699,7 +699,25 @@ angular.module(&#39;ScheduleApp&#39;).factory(
699 699 return dst;
700 700 }
701 701 }
702   - },
  702 + }
  703 + }
  704 + ),
  705 +
  706 + backup: $resource(
  707 + '/tic_ec/backup/:ttinfoid',
  708 + {},
  709 + {
  710 + do: {
  711 + method: 'GET',
  712 + transformResponse: function(rs) {
  713 + var dst = angular.fromJson(rs);
  714 + if (dst.status == 'SUCCESS') {
  715 + return dst.data;
  716 + } else {
  717 + return dst; // 业务错误留给控制器处理
  718 + }
  719 + }
  720 + }
703 721 }
704 722 )
705 723 };
... ...
src/main/resources/static/pages/scheduleApp/module/core/ttInfoManage/list.html
... ... @@ -9,7 +9,7 @@
9 9 <th style="width: 180px;">时刻表名称</th>
10 10 <th style="width: 80px">上下行</th>
11 11 <th style="width: 50px;">启用</th>
12   - <th style="width: 120px">启用日期</th>
  12 + <th style="width: 120px">启用/备份日期</th>
13 13 <th style="width: 80px">状态</th>
14 14 <th style="width: 60%">时刻表明细</th>
15 15 <th style="width: 40%">操作</th>
... ... @@ -76,7 +76,24 @@
76 76 <span ng-bind="info.isEnableDisTemplate | dict:'truefalseType':'未知' "></span>
77 77 </td>
78 78 <td>
79   - <span ng-bind="info.qyrq | date: 'yyyy-MM-dd'"></span>
  79 + <div>
  80 + <a href="#">
  81 + <span ng-bind="info.qyrq | date: 'yyyy-MM-dd'"></span>
  82 + </a>
  83 + </div>
  84 + <div>
  85 + <a href="#"
  86 + tooltip-animation="false"
  87 + tooltip-placement="top"
  88 + uib-tooltip="备份时间:{{info.lastBackUpDate | date: 'yyyy-MM-dd HH:mm:ss' }}"
  89 + tooltip-class="headClass">
  90 +
  91 + <i class="fa fa-hdd-o" aria-hidden="true"></i>
  92 + <span ng-bind="info.lastBackUpDate | date: 'yyyy-MM-dd'"></span>
  93 + </a>
  94 +
  95 + </div>
  96 +
80 97 </td>
81 98 <td>
82 99 <span class="glyphicon glyphicon-ok" ng-if="info.isCancel == '0'"></span>
... ... @@ -94,6 +111,10 @@
94 111 <a ui-sref="ttInfoDetailManage_form({xlid: info.xl.id, ttid : info.id, xlname: info.xl.name, ttname : info.name})"
95 112 class="btn btn-info btn-sm" ng-if="info.isCancel == '0'"> 导入 </a>
96 113 <a href="javascript:" class="btn btn-info btn-sm" ng-click="ctrl.exportData(info.id)"> 导出 </a>
  114 + <a sweetalert
  115 + sweet-options="{title: '是否备份时刻表?',text: '时刻表名称:' + info.name + '</br>TODO:已备份信息!', html: true,type: 'warning',showCancelButton: true,confirmButtonColor: '#DD6B55',confirmButtonText: '是',cancelButtonText: '取消'}"
  116 + sweet-on-confirm="ctrl.backupinfo(info.id)"
  117 + class="btn btn-danger btn-sm">备份</a>
97 118 </td>
98 119 <td>
99 120 <!--<a href="details.html?lineId={{obj.id}}" class="btn default blue-stripe btn-sm"> 详细 </a>-->
... ...
src/main/resources/static/pages/scheduleApp/module/core/ttInfoManage/module.js
... ... @@ -60,6 +60,16 @@ angular.module(&#39;ScheduleApp&#39;).factory(
60 60 param.type = 'exportFile';
61 61 param.ttinfoid = ttinfoid;
62 62 return dservice.dataTools.dataExport(param).$promise;
  63 + },
  64 +
  65 + /**
  66 + * 备份。
  67 + * @returns {*|Function|promise|n}
  68 + */
  69 + backupinfo: function(ttinfoid) {
  70 + var param = {};
  71 + param.ttinfoid = ttinfoid;
  72 + return service.backup.do(param).$promise;
63 73 }
64 74  
65 75  
... ... @@ -136,6 +146,19 @@ angular.module(&#39;ScheduleApp&#39;).controller(
136 146 );
137 147 };
138 148  
  149 + // 备份信息
  150 + self.backupinfo = function(ttinfoid) {
  151 + service.backupinfo(ttinfoid).then(
  152 + function(result) {
  153 + self.doPage();
  154 + console.log("备份成功!");
  155 + },
  156 + function(result) {
  157 + console.log("备份失败:" + result);
  158 + }
  159 + );
  160 + };
  161 +
139 162 self.doPage();
140 163  
141 164 // 自动生成时刻表
... ...
src/main/resources/static/pages/scheduleApp/module/core/ttInfoManage/service.js
... ... @@ -33,7 +33,25 @@ angular.module(&#39;ScheduleApp&#39;).factory(
33 33 return dst;
34 34 }
35 35 }
36   - },
  36 + }
  37 + }
  38 + ),
  39 +
  40 + backup: $resource(
  41 + '/tic_ec/backup/:ttinfoid',
  42 + {},
  43 + {
  44 + do: {
  45 + method: 'GET',
  46 + transformResponse: function(rs) {
  47 + var dst = angular.fromJson(rs);
  48 + if (dst.status == 'SUCCESS') {
  49 + return dst.data;
  50 + } else {
  51 + return dst; // 业务错误留给控制器处理
  52 + }
  53 + }
  54 + }
37 55 }
38 56 )
39 57 };
... ...