Commit 13886e75632aef796c1b0760d01deaf8c275dc4f
1 parent
31c980a7
时刻表数据带线路版本v2.1
1、将所有的线路版本相关查询移到ttinforepository,service,controller中 2、由于lineVersions里有个isUpdate字段设置为int类型,但是数据库里确为空值,导致直接实体查询映射出错,所以所有的版本查询都用指定的hql查询
Showing
7 changed files
with
95 additions
and
32 deletions
src/main/java/com/bsth/controller/schedule/core/TTInfoController.java
| ... | ... | @@ -55,6 +55,23 @@ public class TTInfoController extends BController<TTInfo, Long> { |
| 55 | 55 | return rtn; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + @RequestMapping(value = "/versiondesc2/{lineid}/{status}") | |
| 59 | + public Map<String, Object> getLineVersionDesc2( | |
| 60 | + @PathVariable(value = "lineid") Integer lineid, | |
| 61 | + @PathVariable(value = "status") Integer status) { | |
| 62 | + Map<String, Object> rtn = new HashMap<>(); | |
| 63 | + try { | |
| 64 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 65 | + rtn.put("data", ttInfoService.getLineVersions(lineid, status)); | |
| 66 | + | |
| 67 | + } catch (Exception exp) { | |
| 68 | + rtn.put("status", ResponseCode.ERROR); | |
| 69 | + rtn.put("msg", exp.getMessage()); | |
| 70 | + } | |
| 71 | + | |
| 72 | + return rtn; | |
| 73 | + } | |
| 74 | + | |
| 58 | 75 | @RequestMapping(value = "/validate_name", method = RequestMethod.GET) |
| 59 | 76 | public Map<String, Object> validate_name(@RequestParam Map<String, Object> param) { |
| 60 | 77 | Map<String, Object> rtn = new HashMap<>(); | ... | ... |
src/main/java/com/bsth/repository/schedule/TTInfoRepository.java
| ... | ... | @@ -11,7 +11,9 @@ import org.springframework.data.jpa.repository.EntityGraph; |
| 11 | 11 | import org.springframework.data.jpa.repository.Query; |
| 12 | 12 | import org.springframework.stereotype.Repository; |
| 13 | 13 | |
| 14 | +import javax.persistence.Tuple; | |
| 14 | 15 | import java.util.List; |
| 16 | +import java.util.Map; | |
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | 19 | * Created by xu on 16/5/12. |
| ... | ... | @@ -31,4 +33,19 @@ public interface TTInfoRepository extends BaseRepository<TTInfo, Long> { |
| 31 | 33 | |
| 32 | 34 | @Query("select t from TTInfo t where t.xl = ?1 and t.isCancel = false") |
| 33 | 35 | List<TTInfo> findInCanceledByXl(Line xl); |
| 36 | + | |
| 37 | + @Query(value = "select new map(lv.name as name, lv.startDate as sd, " + | |
| 38 | + "lv.status as status, lv.versions as version) " + | |
| 39 | + "from LineVersions lv where lv.line.id = ?1 ") | |
| 40 | + List<Map<String, Object>> findLineVersionDescs(Integer lineId); | |
| 41 | + | |
| 42 | + @Query(value = "select new map(lv.name as name, lv.startDate as sd, " + | |
| 43 | + "lv.status as status, lv.versions as version) " + | |
| 44 | + "from LineVersions lv where lv.line.id = ?1 and lv.versions = ?2 ") | |
| 45 | + List<Map<String, Object>> findLineVersionDescs2(Integer lineId, Integer version); | |
| 46 | + | |
| 47 | + @Query(value = "select new map(lv.name as name, lv.versions as version) " + | |
| 48 | + "from LineVersions lv where lv.line.id = ?1 and lv.status = ?2 ") | |
| 49 | + List<Map<String, Object>> findLineVersionDescs3(Integer lineId, Integer status); | |
| 50 | + | |
| 34 | 51 | } | ... | ... |
src/main/java/com/bsth/service/schedule/TTInfoService.java
src/main/java/com/bsth/service/schedule/impl/TTInfoServiceImpl.java
| 1 | 1 | package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | -import com.bsth.entity.LineVersions; | |
| 4 | 3 | import com.bsth.entity.schedule.TTInfo; |
| 5 | 4 | import com.bsth.entity.schedule.TTInfoBackup; |
| 6 | 5 | import com.bsth.entity.schedule.TTInfoDetail; |
| 7 | 6 | import com.bsth.repository.schedule.TTInfoBackupRepository; |
| 8 | 7 | import com.bsth.repository.schedule.TTInfoDetailRepository; |
| 9 | 8 | import com.bsth.repository.schedule.TTInfoRepository; |
| 10 | -import com.bsth.service.LineVersionsService; | |
| 11 | 9 | import com.bsth.service.schedule.TTInfoService; |
| 12 | 10 | import com.bsth.service.schedule.exception.ScheduleException; |
| 13 | 11 | import com.bsth.service.schedule.utils.TimeTableProto; |
| ... | ... | @@ -24,6 +22,7 @@ import org.springframework.util.CollectionUtils; |
| 24 | 22 | |
| 25 | 23 | import java.io.PrintWriter; |
| 26 | 24 | import java.io.StringWriter; |
| 25 | +import java.sql.Timestamp; | |
| 27 | 26 | import java.util.*; |
| 28 | 27 | |
| 29 | 28 | /** |
| ... | ... | @@ -40,8 +39,6 @@ public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTI |
| 40 | 39 | private TTInfoDetailRepository ttInfoDetailRepository; |
| 41 | 40 | @Autowired |
| 42 | 41 | private TTInfoBackupRepository ttInfoBackupRepository; |
| 43 | - @Autowired | |
| 44 | - private LineVersionsService lineVersionsService; | |
| 45 | 42 | |
| 46 | 43 | @Override |
| 47 | 44 | public void validate_name(TTInfo ttInfo) throws ScheduleException { |
| ... | ... | @@ -140,15 +137,18 @@ public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTI |
| 140 | 137 | |
| 141 | 138 | @Override |
| 142 | 139 | public List<Map<String, Object>> getLineStationRouteVersions(Integer lineId) { |
| 143 | - // 获取线路版本 | |
| 144 | - List<LineVersions> lineVersionsList = lineVersionsService.findByLineCode(lineId); | |
| 140 | + // 获取线路版本数据 | |
| 141 | + List<Map<String, Object>> lineVersionDescs = ttInfoRepository.findLineVersionDescs(lineId); | |
| 145 | 142 | // 按照version版本降序排序 |
| 146 | - Collections.sort(lineVersionsList, new Comparator<LineVersions>() { | |
| 143 | + Collections.sort(lineVersionDescs, new Comparator<Map<String, Object>>() { | |
| 147 | 144 | @Override |
| 148 | - public int compare(LineVersions o1, LineVersions o2) { | |
| 149 | - if (o1.getVersions() > o2.getVersions()) { | |
| 145 | + public int compare(Map<String, Object> o1, Map<String, Object> o2) { | |
| 146 | + int o1_v = Integer.parseInt(o1.get("version").toString()); | |
| 147 | + int o2_v = Integer.parseInt(o2.get("version").toString()); | |
| 148 | + | |
| 149 | + if (o1_v > o2_v) { | |
| 150 | 150 | return -1; |
| 151 | - } else if (o1.getVersions() < o2.getVersions()) { | |
| 151 | + } else if (o1_v < o2_v) { | |
| 152 | 152 | return 1; |
| 153 | 153 | } else { |
| 154 | 154 | return 0; |
| ... | ... | @@ -158,14 +158,19 @@ public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTI |
| 158 | 158 | |
| 159 | 159 | // 取最开始的2条记录 |
| 160 | 160 | List<Map<String, Object>> mapList = new ArrayList<>(); |
| 161 | - for (LineVersions lv: lineVersionsList) { | |
| 162 | - String vname = lv.getName(); | |
| 163 | - String rq = lv.getStartDate() == null ? "未知启用日期" : new DateTime(lv.getStartDate()).toString("YYYY年MM月dd日"); | |
| 164 | - String sdesc = lv.getStatus() == 0 ? "历史" : (lv.getStatus() == 1 ? "当前" : "待更新"); | |
| 161 | + for (Map<String, Object> lv: lineVersionDescs) { | |
| 162 | + String t_name = (String) lv.get("name"); | |
| 163 | + Timestamp t_sd = (Timestamp) lv.get("sd"); | |
| 164 | + int status = Integer.parseInt(lv.get("status").toString()); | |
| 165 | + int version = Integer.parseInt(lv.get("version").toString()); | |
| 166 | + | |
| 167 | + String vname = t_name; | |
| 168 | + String rq = t_sd == null ? "未知启用日期" : new DateTime(t_sd).toString("YYYY年MM月dd日"); | |
| 169 | + String sdesc = status == 0 ? "历史" : (status == 1 ? "当前" : "待更新"); | |
| 165 | 170 | |
| 166 | 171 | Map<String, Object> value = new HashMap<>(); |
| 167 | 172 | value.put("desc", vname + "-" + rq + "-" + sdesc); |
| 168 | - value.put("version", lv.getVersions()); | |
| 173 | + value.put("version", version); | |
| 169 | 174 | |
| 170 | 175 | mapList.add(value); |
| 171 | 176 | |
| ... | ... | @@ -180,28 +185,34 @@ public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTI |
| 180 | 185 | @Override |
| 181 | 186 | public String getLineVersionDesc(Integer lineId, Integer version) { |
| 182 | 187 | // 查找指定版本,并判定 |
| 183 | - Map<String, Object> param = new HashMap<>(); | |
| 184 | - param.put("line_eq", lineId); | |
| 185 | - param.put("versions_eq", version); | |
| 186 | - List<LineVersions> lineVersionsList = (List<LineVersions>) lineVersionsService.list(param); | |
| 188 | + List<Map<String, Object>> lineVersionDescs = ttInfoRepository.findLineVersionDescs2(lineId, version); | |
| 187 | 189 | |
| 188 | - LineVersions lv; | |
| 189 | - if (CollectionUtils.isEmpty(lineVersionsList)) { | |
| 190 | + Map<String, Object> lv; | |
| 191 | + if (CollectionUtils.isEmpty(lineVersionDescs)) { | |
| 190 | 192 | return "未知版本"; |
| 191 | - } else if (lineVersionsList.size() > 1) { | |
| 193 | + } else if (lineVersionDescs.size() > 1) { | |
| 192 | 194 | return "重复版本"; |
| 193 | 195 | } else { |
| 194 | - lv = lineVersionsList.get(0); | |
| 196 | + lv = lineVersionDescs.get(0); | |
| 195 | 197 | } |
| 196 | 198 | |
| 197 | - String vname = lv.getName(); | |
| 198 | - String rq = lv.getStartDate() == null ? "未知启用日期" : new DateTime(lv.getStartDate()).toString("YYYY年MM月dd日"); | |
| 199 | - String sdesc = lv.getStatus() == 0 ? "历史" : (lv.getStatus() == 1 ? "当前" : "待更新"); | |
| 199 | + String t_name = (String) lv.get("name"); | |
| 200 | + Timestamp t_sd = (Timestamp) lv.get("sd"); | |
| 201 | + int status = Integer.parseInt(lv.get("status").toString()); | |
| 202 | + | |
| 203 | + String vname = t_name; | |
| 204 | + String rq = t_sd == null ? "未知启用日期" : new DateTime(t_sd).toString("YYYY年MM月dd日"); | |
| 205 | + String sdesc = status == 0 ? "历史" : (status == 1 ? "当前" : "待更新"); | |
| 200 | 206 | |
| 201 | 207 | return String.format("%s-%s-%s", vname, rq, sdesc); |
| 202 | 208 | } |
| 203 | 209 | |
| 204 | 210 | @Override |
| 211 | + public List<Map<String, Object>> getLineVersions(Integer lineId, Integer status) { | |
| 212 | + return ttInfoRepository.findLineVersionDescs3(lineId, status); | |
| 213 | + } | |
| 214 | + | |
| 215 | + @Override | |
| 205 | 216 | @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.REPEATABLE_READ) |
| 206 | 217 | public void backUp(Long ttInfoId) throws ScheduleException { |
| 207 | 218 | LOG.info(">>>>>>开始备份时刻表<<<<<<"); | ... | ... |
src/main/resources/static/pages/scheduleApp/module/common/prj-common-globalservice.js
| ... | ... | @@ -748,12 +748,20 @@ angular.module('ScheduleApp').factory( |
| 748 | 748 | ), |
| 749 | 749 | |
| 750 | 750 | lineverions: $resource( |
| 751 | - '/lineVersions/all', | |
| 751 | + '/tic_ec/versiondesc2/:lineId/:status', | |
| 752 | 752 | {}, |
| 753 | 753 | { |
| 754 | 754 | list: { |
| 755 | 755 | method: 'GET', |
| 756 | - isArray: true | |
| 756 | + isArray: true, | |
| 757 | + transformResponse: function(rs) { | |
| 758 | + var dst = angular.fromJson(rs); | |
| 759 | + if (dst.status == 'SUCCESS') { | |
| 760 | + return dst.data; | |
| 761 | + } else { | |
| 762 | + return dst; // 业务错误留给控制器处理 | |
| 763 | + } | |
| 764 | + } | |
| 757 | 765 | } |
| 758 | 766 | } |
| 759 | 767 | ) | ... | ... |
src/main/resources/static/pages/scheduleApp/module/core/ttInfoManage/detailedit/module.js
| ... | ... | @@ -25,7 +25,7 @@ angular.module('ScheduleApp').factory( |
| 25 | 25 | * @returns {*|Function|promise|n} |
| 26 | 26 | */ |
| 27 | 27 | getCurrentLineVersion: function(xlid) { |
| 28 | - var params = {'line.id_eq': xlid, 'status_eq': 1}; | |
| 28 | + var params = {'lineId': xlid, 'status': 1}; | |
| 29 | 29 | return service2.lineverions.list(params).$promise; |
| 30 | 30 | |
| 31 | 31 | } |
| ... | ... | @@ -69,7 +69,7 @@ angular.module('ScheduleApp').controller( |
| 69 | 69 | } else if (result.length > 1) { |
| 70 | 70 | alert("有多个线路当前版本"); |
| 71 | 71 | } else { |
| 72 | - self.ttInfoDetailManageForForm.lineversion = result[0].versions; | |
| 72 | + self.ttInfoDetailManageForForm.lineversion = result[0].version; | |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | ); | ... | ... |
src/main/resources/static/pages/scheduleApp/module/core/ttInfoManage/service.js
| ... | ... | @@ -74,12 +74,20 @@ angular.module('ScheduleApp').factory( |
| 74 | 74 | ), |
| 75 | 75 | |
| 76 | 76 | lineverions: $resource( |
| 77 | - '/lineVersions/all', | |
| 77 | + '/tic_ec/versiondesc2/:lineId/:status', | |
| 78 | 78 | {}, |
| 79 | 79 | { |
| 80 | 80 | list: { |
| 81 | 81 | method: 'GET', |
| 82 | - isArray: true | |
| 82 | + isArray: true, | |
| 83 | + transformResponse: function(rs) { | |
| 84 | + var dst = angular.fromJson(rs); | |
| 85 | + if (dst.status == 'SUCCESS') { | |
| 86 | + return dst.data; | |
| 87 | + } else { | |
| 88 | + return dst; // 业务错误留给控制器处理 | |
| 89 | + } | |
| 90 | + } | |
| 83 | 91 | } |
| 84 | 92 | } |
| 85 | 93 | ) | ... | ... |