Commit 043969f7ffe21be26dd7dd0b6f756a135131be57

Authored by 娄高锋
1 parent c146dcd0

按车辆统计营运公里的接口

src/main/java/com/bsth/repository/ScheduleRealInfoRepository.java
@@ -69,4 +69,14 @@ public interface ScheduleRealInfoRepository extends PagingAndSortingRepository<S @@ -69,4 +69,14 @@ public interface ScheduleRealInfoRepository extends PagingAndSortingRepository<S
69 @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) 69 @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH)
70 @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr in (?1) and s.updateDate>=?2") 70 @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr in (?1) and s.updateDate>=?2")
71 List<ScheduleRealInfo> findByDates(List<String> schDates, Date timestamp); 71 List<ScheduleRealInfo> findByDates(List<String> schDates, Date timestamp);
  72 +
  73 + /**
  74 + * 根据日期区间获取班次信息
  75 + * @param startDate
  76 + * @param endDate
  77 + * @return
  78 + */
  79 + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH)
  80 + @Query(value="select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr between ?1 and ?2 order by s.scheduleDateStr, s.gsBm, s.fgsBm, s.xlBm")
  81 + List<ScheduleRealInfo> findScheduleByDates(String startDate, String endDate);
72 } 82 }
src/main/java/com/bsth/server_rs/bigdata/BigdataService.java
@@ -3,12 +3,16 @@ package com.bsth.server_rs.bigdata; @@ -3,12 +3,16 @@ package com.bsth.server_rs.bigdata;
3 import java.sql.ResultSet; 3 import java.sql.ResultSet;
4 import java.sql.SQLException; 4 import java.sql.SQLException;
5 import java.text.DecimalFormat; 5 import java.text.DecimalFormat;
  6 +import java.text.ParseException;
6 import java.text.SimpleDateFormat; 7 import java.text.SimpleDateFormat;
  8 +import java.util.ArrayList;
7 import java.util.Calendar; 9 import java.util.Calendar;
8 import java.util.Date; 10 import java.util.Date;
9 import java.util.HashMap; 11 import java.util.HashMap;
  12 +import java.util.HashSet;
10 import java.util.List; 13 import java.util.List;
11 import java.util.Map; 14 import java.util.Map;
  15 +import java.util.Set;
12 16
13 import javax.ws.rs.GET; 17 import javax.ws.rs.GET;
14 import javax.ws.rs.Path; 18 import javax.ws.rs.Path;
@@ -19,11 +23,20 @@ import javax.ws.rs.core.MediaType; @@ -19,11 +23,20 @@ import javax.ws.rs.core.MediaType;
19 import org.slf4j.Logger; 23 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory; 24 import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired; 25 import org.springframework.beans.factory.annotation.Autowired;
  26 +import org.springframework.data.redis.support.collections.RedisMap;
22 import org.springframework.jdbc.core.JdbcTemplate; 27 import org.springframework.jdbc.core.JdbcTemplate;
23 import org.springframework.jdbc.core.RowMapper; 28 import org.springframework.jdbc.core.RowMapper;
24 import org.springframework.stereotype.Component; 29 import org.springframework.stereotype.Component;
25 30
26 import com.alibaba.fastjson.JSONObject; 31 import com.alibaba.fastjson.JSONObject;
  32 +import com.bsth.entity.ChildTaskPlan;
  33 +import com.bsth.entity.DestroySituation;
  34 +import com.bsth.entity.ScheduleRealInfo;
  35 +import com.bsth.repository.DestroySituationRepository;
  36 +import com.bsth.repository.ScheduleRealInfoRepository;
  37 +import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  38 +import com.bsth.util.Arith;
  39 +import com.mysql.fabric.xmlrpc.base.Array;
27 40
28 @Component 41 @Component
29 @Path("/bigdata") 42 @Path("/bigdata")
@@ -34,6 +47,12 @@ public class BigdataService { @@ -34,6 +47,12 @@ public class BigdataService {
34 @Autowired 47 @Autowired
35 JdbcTemplate jdbcTemplate; 48 JdbcTemplate jdbcTemplate;
36 49
  50 + @Autowired
  51 + private DestroySituationRepository destroySituationRepository;
  52 +
  53 + @Autowired
  54 + private ScheduleRealInfoRepository scheduleRealInfoRepository;
  55 +
37 DecimalFormat df = new DecimalFormat("0.00"); 56 DecimalFormat df = new DecimalFormat("0.00");
38 57
39 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 58 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -1287,14 +1306,15 @@ public class BigdataService { @@ -1287,14 +1306,15 @@ public class BigdataService {
1287 * @param starDate 1306 * @param starDate
1288 * @param endDate 1307 * @param endDate
1289 * @return 1308 * @return
  1309 + * @throws ParseException
1290 */ 1310 */
1291 @GET 1311 @GET
1292 - @Path("/getScheduleZs/starDate/{starDate}/endDate/{endDate}")  
1293 - public List<Map<String, Object>> getScheduleZs(@PathParam("starDate") String starDate,  
1294 - @PathParam("endDate") String endDate) { 1312 + @Path("/getScheduleAccident/startDate/{startDate}/endDate/{endDate}")
  1313 + public List<Map<String, Object>> getScheduleAccident(@PathParam("startDate") String startDate,
  1314 + @PathParam("endDate") String endDate) throws ParseException {
1295 String sql="select gs_bm,fgs_bm,real_exec_date,fcsj,fcsj_actual,xl_name,j_gh,j_name,cl_zbh,car_plate,remarks " 1315 String sql="select gs_bm,fgs_bm,real_exec_date,fcsj,fcsj_actual,xl_name,j_gh,j_name,cl_zbh,car_plate,remarks "
1296 + " from bsth_c_s_sp_info_real r left join bsth_c_cars c on r.cl_zbh = c.inside_code " 1316 + " from bsth_c_s_sp_info_real r left join bsth_c_cars c on r.cl_zbh = c.inside_code "
1297 - + " where schedule_date_str>='"+starDate+"' and schedule_date_str<= '"+endDate+"' " 1317 + + " where schedule_date_str>='"+startDate+"' and schedule_date_str<= '"+endDate+"' "
1298 + " and adjust_exps like '%肇事%' and status = '-1' " 1318 + " and adjust_exps like '%肇事%' and status = '-1' "
1299 + " order by real_exec_date, schedule_date_str, fcsj"; 1319 + " order by real_exec_date, schedule_date_str, fcsj";
1300 1320
@@ -1317,7 +1337,116 @@ public class BigdataService { @@ -1317,7 +1337,116 @@ public class BigdataService {
1317 return m; 1337 return m;
1318 } 1338 }
1319 }); 1339 });
  1340 +
  1341 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1342 + Date d1 = sdf.parse(startDate);
  1343 + Date d2 = sdf.parse(endDate);
  1344 + while(d1.getTime() <= d2.getTime()){
  1345 + String rq = sdf.format(d1);
  1346 + List<DestroySituation> destroys = destroySituationRepository.findByDateAndReason(rq, "肇事");
  1347 + for(DestroySituation ds : destroys){
  1348 + ScheduleRealInfo s = scheduleRealInfoRepository.findOne(Long.parseLong(ds.getIdsStr().split(",")[0]));
  1349 + Map<String, Object> m = new HashMap<String, Object>();
  1350 + m.put("gs_bm", ds.getGsBm());
  1351 + m.put("fgs_bm", ds.getFgsBm());
  1352 + m.put("real_exec_date", rq);
  1353 + m.put("fcsj", s==null?"00:00":(s.getFcsj()!=null&&s.getFcsj().trim().length()>0?s.getFcsj():""));
  1354 + m.put("fcsj_actual", s==null?"00:00":(s.getFcsjActual()!=null&&s.getFcsjActual().trim().length()>0?s.getFcsjActual():""));
  1355 + m.put("xl_name", ds.getLineName());
  1356 + m.put("j_gh", ds.getjGh());
  1357 + m.put("j_name", s==null?"":(s.getjName()!=null&&s.getjName().trim().length()>0?s.getjName():""));
  1358 + m.put("cl_zbh", ds.getNbbm());
  1359 + m.put("car_plate", CarBufferData.findOne(ds.getNbbm()).getCarPlate());
  1360 + m.put("remarks", (s==null?"":(s.getQdzName()+"->"+s.getZdzName()+";"))+ds.getRemark());
  1361 + }
  1362 + }
  1363 +
1320 return list; 1364 return list;
1321 } 1365 }
1322 1366
  1367 + /**
  1368 + * 给机务(徐铉、郑鑫)按车辆统计营运公里
  1369 + * @param starDate
  1370 + * @param endDate
  1371 + * @return
  1372 + * @throws ParseException
  1373 + */
  1374 + @GET
  1375 + @Path("/mileageByVehicle/startDate/{startDate}/endDate/{endDate}")
  1376 + public List<Map<String, Object>> mileageByVehicle(@PathParam("startDate") String starDate,
  1377 + @PathParam("endDate") String endDate) throws ParseException {
  1378 + List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
  1379 +
  1380 + String yyxlSql="SELECT line_code from bsth_c_line "
  1381 + + " where nature in ('yxl','cgxl','gjxl','csbs','cctxl')";
  1382 + List<Map<String, Object>> yyxlList=jdbcTemplate.query(yyxlSql,
  1383 + new RowMapper<Map<String, Object>>(){
  1384 + @Override
  1385 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1386 + Map<String, Object> m=new HashMap<String,Object>();
  1387 + m.put("lineCode", rs.getString("line_code"));
  1388 + return m;
  1389 + }
  1390 + });
  1391 + Set<String> yyLine = new HashSet<String>();
  1392 + for(Map<String, Object> t : yyxlList){
  1393 + if(t.get("lineCode") != null){
  1394 + yyLine.add(t.get("lineCode").toString());
  1395 + }
  1396 + }
  1397 +
  1398 + BigscreenService bigscreenService = new BigscreenService();
  1399 + List<ScheduleRealInfo> dataList = scheduleRealInfoRepository.findScheduleByDates(starDate, endDate);
  1400 + Map<String, List<ScheduleRealInfo>> keyMap = new HashMap<String, List<ScheduleRealInfo>>();
  1401 + List<String> keyList = new ArrayList<String>();
  1402 +
  1403 + for(ScheduleRealInfo s : dataList){
  1404 + if(s.getXlBm() != null && yyLine.contains(s.getXlBm())){//营运线路
  1405 + String dateStr = s.getScheduleDateStr();
  1406 + String gsBm = s.getGsBm();
  1407 + String cl = s.getClZbh();
  1408 + String key = dateStr + "/" + gsBm + "/" + cl;
  1409 + if(!(keyMap.containsKey(key))){
  1410 + keyMap.put(key, new ArrayList<ScheduleRealInfo>());
  1411 + keyList.add(key);
  1412 + }
  1413 + keyMap.get(key).add(s);
  1414 + }
  1415 + }
  1416 +
  1417 + for(String key : keyList){
  1418 + List<ScheduleRealInfo> list = keyMap.get(key);
  1419 + List<ScheduleRealInfo> listSche = new ArrayList<ScheduleRealInfo>();//全部班次
  1420 + List<ScheduleRealInfo> list_s = new ArrayList<ScheduleRealInfo>();//已执行班次
  1421 + for(ScheduleRealInfo s : list){
  1422 + listSche.add(s);
  1423 + Set<ChildTaskPlan> cts = s.getcTasks();
  1424 + if (cts != null && cts.size() > 0) {
  1425 + list_s.add(s);
  1426 + } else {
  1427 + if (s.getZdsjActual() != null && s.getFcsjActual() != null) {
  1428 + list_s.add(s);
  1429 + }
  1430 + }
  1431 + }
  1432 +
  1433 + double sjgl = bigscreenService.culateSjgl(list_s);//实际营运公里(不含临加)
  1434 + double sjljgl = bigscreenService.culateLjgl(listSche);//实际临加公里
  1435 + double sjyygl = Arith.add(sjgl, sjljgl);//实际营运公里
  1436 + double sjjccgl = bigscreenService.culateJccgl(list_s);
  1437 + double sjksgl = bigscreenService.culateKsgl(list_s);
  1438 + double zksgl = Arith.add(sjjccgl, sjksgl);//实际空驶总公里
  1439 +
  1440 + Map<String, Object> m = new HashMap<String, Object>();
  1441 + m.put("date", key.split("/")[0]);
  1442 + m.put("companyCode", key.split("/")[1]);
  1443 + m.put("car", key.split("/")[2]);
  1444 + m.put("businessMileage", sjyygl);
  1445 + m.put("emptyMileage", zksgl);
  1446 + resList.add(m);
  1447 + }
  1448 +
  1449 + return resList;
  1450 + }
  1451 +
1323 } 1452 }