Commit db92728e94d465753217ee0aae22efd50e873144

Authored by zlz
1 parent d256804a

表“车载上报停靠站”建表分区,代码重写

src/main/java/com/bsth/controller/traffic/VehicleInoutStopController.java
... ... @@ -2,8 +2,17 @@ package com.bsth.controller.traffic;
2 2  
3 3 import com.bsth.controller.BaseController;
4 4 import com.bsth.entity.traffic.VehicleInoutStop;
  5 +import com.bsth.service.traffic.VehicleInoutStopService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.data.domain.Page;
  8 +import org.springframework.data.domain.PageImpl;
  9 +import org.springframework.data.domain.PageRequest;
5 10 import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RequestParam;
6 12 import org.springframework.web.bind.annotation.RestController;
  13 +
  14 +import java.util.Map;
  15 +
7 16 /**
8 17 *
9 18 * @author BSTH
... ... @@ -12,4 +21,26 @@ import org.springframework.web.bind.annotation.RestController;
12 21 @RestController
13 22 @RequestMapping("vehicle_stop")
14 23 public class VehicleInoutStopController extends BaseController<VehicleInoutStop,Integer> {
  24 +
  25 + @Autowired
  26 + VehicleInoutStopService vehicleInoutStopService;
  27 +
  28 + /**
  29 + * 给定条件查车载上报停靠站
  30 + * @param map
  31 + * @param page
  32 + * @param size
  33 + * @return
  34 + */
  35 + @RequestMapping(value = "getVehicleInoutStopByParam")
  36 + public Page<Map<String, Object>> getVehicleInoutStopByParam(@RequestParam Map<String, Object> map,
  37 + @RequestParam(defaultValue = "0") int page,
  38 + @RequestParam(defaultValue = "10") int size) {
  39 + map.put("page",page);
  40 + map.put("size",size);
  41 + long total = vehicleInoutStopService.getVehicleInoutStopCountByParam(map);
  42 + Page<Map<String, Object>> result = new PageImpl<>(vehicleInoutStopService.getVehicleInoutStopByParam(map),
  43 + new PageRequest(page, size, null),total);
  44 + return result;
  45 + }
15 46 }
... ...
src/main/java/com/bsth/entity/traffic/VehicleInoutStop.java
1 1 package com.bsth.entity.traffic;
2 2  
3   -import com.bsth.entity.Cars;
4   -import com.bsth.entity.Line;
5   -
6 3 import javax.persistence.*;
7 4 import java.util.Date;
8 5  
... ... @@ -27,11 +24,9 @@ public class VehicleInoutStop {
27 24 @GeneratedValue(strategy = GenerationType.IDENTITY)
28 25 private Integer id;
29 26  
30   - @ManyToOne
31   - private Line line;
  27 + private int line;
32 28  
33   - @ManyToOne
34   - private Cars cars;
  29 + private int cars;
35 30  
36 31 // 站点序号
37 32 private Integer stop;
... ... @@ -46,7 +41,7 @@ public class VehicleInoutStop {
46 41 private Integer inOutStop;
47 42  
48 43 // 上报时间
49   - private long reportDate;
  44 + private Date reportDate;
50 45  
51 46 public Integer getId() {
52 47 return id;
... ... @@ -56,19 +51,19 @@ public class VehicleInoutStop {
56 51 this.id = id;
57 52 }
58 53  
59   - public Line getLine() {
  54 + public int getLine() {
60 55 return line;
61 56 }
62 57  
63   - public void setLine(Line line) {
  58 + public void setLine(int line) {
64 59 this.line = line;
65 60 }
66 61  
67   - public Cars getCars() {
  62 + public int getCars() {
68 63 return cars;
69 64 }
70 65  
71   - public void setCars(Cars cars) {
  66 + public void setCars(int cars) {
72 67 this.cars = cars;
73 68 }
74 69  
... ... @@ -104,7 +99,11 @@ public class VehicleInoutStop {
104 99 this.inOutStop = inOutStop;
105 100 }
106 101  
107   - public long getReportDate() { return reportDate; }
  102 + public Date getReportDate() {
  103 + return reportDate;
  104 + }
108 105  
109   - public void setReportDate(long reportDate) { this.reportDate = reportDate; }
  106 + public void setReportDate(Date reportDate) {
  107 + this.reportDate = reportDate;
  108 + }
110 109 }
... ...
src/main/java/com/bsth/service/traffic/VehicleInoutStopService.java
... ... @@ -3,10 +3,26 @@ package com.bsth.service.traffic;
3 3 import com.bsth.entity.traffic.VehicleInoutStop;
4 4 import com.bsth.service.BaseService;
5 5  
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
6 9  
7 10 /**
8 11 * 时刻模板上传日志
9 12 */
10 13 public interface VehicleInoutStopService extends BaseService<VehicleInoutStop,Integer> {
11 14  
  15 + /**
  16 + * 给定条件查车载上报停靠站
  17 + * @param map
  18 + * @return
  19 + */
  20 + List<Map<String, Object>> getVehicleInoutStopByParam(Map<String,Object> map);
  21 +
  22 + /**
  23 + * 给定条件查车载上报停靠站的记录数
  24 + * @param map
  25 + * @return
  26 + */
  27 + long getVehicleInoutStopCountByParam(Map<String,Object> map);
12 28 }
... ...
src/main/java/com/bsth/service/traffic/impl/VehicleInoutStopServiceImpl.java
... ... @@ -3,10 +3,14 @@ package com.bsth.service.traffic.impl;
3 3 import com.bsth.entity.traffic.VehicleInoutStop;
4 4 import com.bsth.service.impl.BaseServiceImpl;
5 5 import com.bsth.service.traffic.VehicleInoutStopService;
6   -import org.slf4j.Logger;
7   -import org.slf4j.LoggerFactory;
  6 +import com.bsth.util.DateUtils;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.jdbc.core.JdbcTemplate;
8 9 import org.springframework.stereotype.Service;
9 10  
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +
10 14 /**
11 15 *
12 16 * @ClassName: TrafficManageServiceImpl(运管处接口service业务层实现类)
... ... @@ -26,6 +30,70 @@ import org.springframework.stereotype.Service;
26 30 @Service
27 31 public class VehicleInoutStopServiceImpl extends BaseServiceImpl<VehicleInoutStop,Integer> implements VehicleInoutStopService {
28 32  
29   - Logger logger = LoggerFactory.getLogger(this.getClass());
  33 + @Autowired
  34 + JdbcTemplate jdbcTemplate;
  35 +
  36 + /**
  37 + * 拼装sql
  38 + * @param map
  39 + * @param flag
  40 + * @return
  41 + */
  42 + private String packageParam(Map<String,Object> map,String flag){
  43 + StringBuffer sql = new StringBuffer(" where 1 = 1 ");
  44 + String lineId = map.get("lineId")+"";
  45 + String insideCode = map.get("insideCode")+"";
  46 + String carPlate = map.get("carPlate")+"";
  47 + String reportDate_start = map.get("reportDate_start")+"";
  48 + String reportDate_end = map.get("reportDate_end")+"";
  49 + int page = Integer.valueOf(map.get("page")+"");
  50 + int size = Integer.valueOf(map.get("size")+"");
  51 + String order = " order by report_date asc"+ " LIMIT "+page*size+","+size;
  52 + int dayNum = DateUtils.calcDaynumberInYear(reportDate_start.substring(0,8)) -1;
  53 + if(!lineId.equals("")){
  54 + sql.append(" and l.id = ").append(lineId);
  55 + }
  56 + if(!insideCode.equals("")){
  57 + sql.append(" and c.inside_code = ").append("'").append(insideCode.toUpperCase()).append("'");
  58 + }
  59 + if(!carPlate.equals("")){
  60 + sql.append(" and c.car_plate = ").append("'").append("沪").append(carPlate.substring(0,1)).append("-")
  61 + .append(carPlate.substring(1)).append("'");
  62 + }
  63 + sql.append(" and FROM_UNIXTIME(REPORT_DATE/1000,'%Y%m%d%H') between '").append(reportDate_start).
  64 + append("' and '").append(reportDate_end).append("'").append(" and r.day_year = ").append(dayNum);
  65 + if(flag.equals("count")){
  66 + return sql.toString();
  67 + }else{
  68 + return sql + order;
  69 + }
  70 + }
  71 +
  72 + /**
  73 + * 给定条件查车载上报停靠站
  74 + * @param map
  75 + * @return
  76 + */
  77 + public List<Map<String, Object>> getVehicleInoutStopByParam(Map<String,Object> map){
  78 + String sql = "SELECT c.branche_company,c.company,l.name,l.shanghai_linecode,inside_code,equipment_code,car_plate," +
  79 + "if( r.service_state= 0,'营运','停运') as service_state ," +
  80 + "if( r.up_down= 0,'上行','下行') as up_down ," +
  81 + "if( r.in_out_stop= 0,'站内','站外') as in_out_stop , " +
  82 + "r.stop,r.report_date FROM bsth_c_shreal r LEFT JOIN bsth_c_cars c on r.cars = c.id " +
  83 + "LEFT JOIN bsth_c_line l on r.line = l.id" + packageParam(map,"") ;
  84 + List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
  85 + return result;
  86 + }
30 87  
  88 + /**
  89 + * 给定条件查车载上报停靠站的记录数
  90 + * @param map
  91 + * @return
  92 + */
  93 + public long getVehicleInoutStopCountByParam(Map<String,Object> map){
  94 + String sql = "SELECT count(1) COUNT FROM bsth_c_shreal r LEFT JOIN bsth_c_cars c on r.cars = c.id " +
  95 + "LEFT JOIN bsth_c_line l on r.line = l.id" + packageParam(map,"count");
  96 + long result = Long.valueOf(jdbcTemplate.queryForMap(sql).get("COUNT")+"");
  97 + return result;
  98 + }
31 99 }
... ...
src/main/resources/static/pages/trafficManage/js/lineStationUploadRecord.js
... ... @@ -114,30 +114,12 @@
114 114 $.each(inputs, function(i, element) {
115 115 params[$(element).attr("name")] = $(element).val();
116 116 });
117   -
118   - var startDate = params['startDate'];
119   - var endDate = params['endDate'];
  117 + var startDate = params['startDate'] == "" ? "0" : params['startDate'];
  118 + var endDate = params['endDate'] == "" ? "23" : params['endDate'];
120 119 var reportDate = params['reportDate'];
121   - if($("#carPlate").val() != ''){
122   - params['cars.carPlate_eq'] = changeCarPlate($("#carPlate").val());
123   - }
124   - if($("#insideCode").val() != ''){
125   - params['cars.insideCode_eq'] = $("#insideCode").val().toUpperCase();
126   - }
127   - // 默认开始时间
128   - params['reportDate_ge'] = str2datetime(reportDate+" 00:00:00");
129   - // 默认结束时间
130   - params['reportDate_le'] = str2datetime(reportDate+" 23:59:59");
131   -
132   - // 指定的开始时间
133   - if(startDate != ''){
134   - params['reportDate_gt'] = str2datetime(reportDate+" "+ (startDate > 9 ? startDate : "0"+startDate + ":00:00"));
135   - }
136   - // 指定的结束时间
137   - if(endDate != ''){
138   - params['reportDate_lt'] = str2datetime(reportDate+" "+ (endDate > 9 ? endDate : "0"+endDate + ":59:59"));
139   - }
140   - $get('/vehicle_stop', params, function(data) {
  120 + params['reportDate_start'] = reportDate.replace(/-/g,'') + (startDate > 9 ? startDate : "0"+startDate);
  121 + params['reportDate_end'] = reportDate.replace(/-/g,'') + (endDate > 9 ? endDate : "0"+endDate);
  122 + $get('/vehicle_stop/getVehicleInoutStopByParam', params, function(data) {
141 123 var content = data.content;
142 124 _dateFormat(content);
143 125 var bodyHtm = template('lineStationUploadRecord_list_temp', {
... ... @@ -183,7 +165,7 @@
183 165 function _dateFormat(list) {
184 166 var fs = 'YYYY-MM-DD HH:mm:ss';
185 167 $.each(list, function(i, obj) {
186   - obj.reportDate = moment(obj.reportDate).format(fs);
  168 + obj['report_date'] = moment(obj['report_date']).format(fs);
187 169 });
188 170 }
189 171  
... ... @@ -191,10 +173,4 @@
191 173 function str2datetime(stringTime){
192 174 return Date.parse(new Date(stringTime));
193 175 }
194   -
195   - // 时间字符串转成时间戳
196   - function changeCarPlate(carPlate){
197   - var tmp = "沪" + carPlate.substr(0, 1) + "-" + carPlate.substr(1, carPlate.length);
198   - return tmp.toUpperCase();;
199   - }
200 176 })();
201 177 \ No newline at end of file
... ...
src/main/resources/static/pages/trafficManage/lineStationUploadRecord.html
... ... @@ -20,15 +20,15 @@
20 20 </div>
21 21 <div class="inLine_block" style="display: inline-block;margin-left: 15px;">
22 22 <span class="item-label" style="width: 80px;">线路名称:</span>
23   - <select class="form-control" name="line.id_eq" id="line" style="width: 150px;"></select>
  23 + <select class="form-control" name="lineId" id="line" style="width: 150px;"></select>
24 24 </div>
25 25 <div class="inLine_block" style="display: inline-block;margin-left: 15px;">
26 26 <span class="item-label" style="width: 80px;">内部编码:</span>
27   - <input type="text" name="cars.insideCode_eq" id="insideCode" style="width: 120px;" maxlength="40"/>
  27 + <input type="text" name="insideCode" id="insideCode" style="width: 120px;" maxlength="40"/>
28 28 </div>
29 29 <div class="inLine_block" style="display: inline-block;margin-left: 15px;">
30 30 <span class="item-label" style="width: 80px;">车牌号:</span>
31   - <input type="text" name="cars.carPlate_eq" id="carPlate" style="width: 120px;" maxlength="40"/>
  31 + <input type="text" name="carPlate" id="carPlate" style="width: 120px;" maxlength="40"/>
32 32 <span style="color: red;width: 80px;">(沪D-12345 '沪'和'-'去掉)</span>
33 33 </div>
34 34 <div class="form-group" style="display: inline-block;margin-left: 15px;">
... ... @@ -76,114 +76,40 @@
76 76 {{i+1}}
77 77 </td>
78 78 <td>
79   - {{if obj.line.company == '55'}}
80   - 上南公司
81   - {{else if obj.line.company == '22'}}
82   - 金高公司
83   - {{else if obj.line.company == '05'}}
84   - 杨高公司
85   - {{else if obj.line.company == '26'}}
86   - 南汇公司
87   - {{else if obj.line.company == '77'}}
88   - 闵行公司
89   - {{/if}}
  79 + {{obj['branche_company']}}
90 80 </td>
91 81 <td>
92   - {{if obj.line.company == '55'}}
93   -
94   - {{if obj.line.brancheCompany == '1'}}
95   - 上南二分公司
96   - {{else if obj.line.brancheCompany == '2'}}
97   - 上南三分公司
98   - {{else if obj.line.brancheCompany == '3'}}
99   - 上南六分公司
100   - {{else if obj.line.brancheCompany == '4'}}
101   - 上南一分公司
102   - {{/if}}
103   -
104   - {{else if obj.line.company == '22'}}
105   -
106   - {{if obj.line.brancheCompany == '1'}}
107   - 四分公司
108   - {{else if obj.line.brancheCompany == '2'}}
109   - 二分公司
110   - {{else if obj.line.brancheCompany == '3'}}
111   - 三分公司
112   - {{else if obj.line.brancheCompany == '5'}}
113   - 一分公司
114   - {{/if}}
115   -
116   - {{else if obj.line.company == '05'}}
117   -
118   - {{if obj.line.brancheCompany == '1'}}
119   - 川沙分公司
120   - {{else if obj.line.brancheCompany == '2'}}
121   - 金桥分公司
122   - {{else if obj.line.brancheCompany == '3'}}
123   - 芦潮港分公司
124   - {{else if obj.line.brancheCompany == '5'}}
125   - 杨高分公司
126   - {{else if obj.line.brancheCompany == '6'}}
127   - 周浦分公司
128   - {{/if}}
129   -
130   - {{else if obj.line.company == '26'}}
131   -
132   - {{if obj.line.brancheCompany == '1'}}
133   - 南汇一分
134   - {{else if obj.line.brancheCompany == '2'}}
135   - 南汇二分
136   - {{else if obj.line.brancheCompany == '3'}}
137   - 南汇三分
138   - {{else if obj.line.brancheCompany == '4'}}
139   - 南汇维修公司
140   - {{else if obj.line.brancheCompany == '5'}}
141   - 南汇公司
142   - {{/if}}
143   -
144   - {{/if}}
  82 + {{obj['company']}}
145 83 </td>
146 84 <td>
147   - {{obj.line.name}}
  85 + {{obj['name']}}
148 86 </td>
149 87 <td>
150   - {{obj.line.shanghaiLinecode}}
  88 + {{obj['shanghai_linecode']}}
151 89 </td>
152 90 <td>
153   - {{obj.cars.insideCode}}
  91 + {{obj['inside_code']}}
154 92 </td>
155 93 <td>
156   - {{obj.cars.equipmentCode}}
  94 + {{obj['equipment_code']}}
157 95 </td>
158 96 <td>
159   - {{obj.cars.carPlate}}
  97 + {{obj['car_plate']}}
160 98 </td>
161 99 <td>
162   - {{obj.stop}}
  100 + {{obj['stop']}}
163 101 </td>
164 102 <td>
165   - {{if obj.serviceState == 0}}
166   - 营运
167   - {{else if obj.serviceState == 1}}
168   - 停运
169   - {{/if}}
  103 + {{obj['service_state']}}
170 104 </td>
171 105 <td>
172   - {{if obj.upDown == 0}}
173   - 上行
174   - {{else if obj.upDown == 1}}
175   - 下行
176   - {{/if}}
  106 + {{obj['up_down']}}
177 107 </td>
178 108 <td>
179   - {{if obj.inOutStop == 0}}
180   - 站内
181   - {{else if obj.inOutStop == 1}}
182   - 站外
183   - {{/if}}
  109 + {{obj['in_out_stop']}}
184 110 </td>
185 111 <td>
186   - {{obj.reportDate}}
  112 + {{obj['report_date']}}
187 113 </td>
188 114 </tr>
189 115 {{/each}}
... ...