Commit 03447ef0f95e42de4524a8554c56be3a95e6c44d
1 parent
999fff42
充电量接口接入到集调的表中
Showing
2 changed files
with
70 additions
and
15 deletions
src/main/java/com/bsth/repository/ScheduleRealInfoRepository.java
| ... | ... | @@ -92,4 +92,10 @@ public interface ScheduleRealInfoRepository extends PagingAndSortingRepository<S |
| 92 | 92 | @Query(value = " select bc_type from bsth_c_s_sp_info where id = ?1 ", nativeQuery = true) |
| 93 | 93 | List<String> findoOriginalType(Long spId); |
| 94 | 94 | |
| 95 | + @Query("select s from ScheduleRealInfo s where s.clZbh = ?1 and s.scheduleDateStr = ?2 and s.realExecDate = ?3 order by fcsj asc") | |
| 96 | + List<ScheduleRealInfo> getFirstByClZbhAndScheduleDateStrAndRealExecDateOrderByFcsjAsc(String clZbh, String scheduleDateStr, String realExecDate); | |
| 97 | + | |
| 98 | + @Query("select s from ScheduleRealInfo s where s.clZbh = ?1 and s.scheduleDateStr >= ?2 and s.scheduleDateStr <= ?3 order by scheduleDateStr desc") | |
| 99 | + List<ScheduleRealInfo> getFirstByClZbhAndScheduleDateStrBetweenOrderByScheduleDateStrDesc(String clZbh, String scheduleDateStr1, String scheduleDateStr2); | |
| 100 | + | |
| 95 | 101 | } | ... | ... |
src/main/java/com/bsth/server_rs/electric/ElectricService.java
| ... | ... | @@ -2,7 +2,9 @@ package com.bsth.server_rs.electric; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | 4 | import com.bsth.entity.JdlReception; |
| 5 | +import com.bsth.entity.ScheduleRealInfo; | |
| 5 | 6 | import com.bsth.repository.JdlReceptionRepository; |
| 7 | +import com.bsth.repository.ScheduleRealInfoRepository; | |
| 6 | 8 | import com.bsth.server_ws.electric_oil.entity.Electric; |
| 7 | 9 | import org.slf4j.Logger; |
| 8 | 10 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -19,6 +21,7 @@ import javax.ws.rs.PathParam; |
| 19 | 21 | import javax.ws.rs.Produces; |
| 20 | 22 | import javax.ws.rs.core.MediaType; |
| 21 | 23 | |
| 24 | +import java.text.SimpleDateFormat; | |
| 22 | 25 | import java.util.Date; |
| 23 | 26 | import java.util.HashMap; |
| 24 | 27 | import java.util.List; |
| ... | ... | @@ -39,6 +42,9 @@ public class ElectricService { |
| 39 | 42 | |
| 40 | 43 | @Autowired |
| 41 | 44 | JdlReceptionRepository jdlReceptionRepository; |
| 45 | + | |
| 46 | + @Autowired | |
| 47 | + ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 42 | 48 | |
| 43 | 49 | @GET |
| 44 | 50 | @Path("/{company}/{rq}") |
| ... | ... | @@ -61,25 +67,68 @@ public class ElectricService { |
| 61 | 67 | public Map<String, Object> orderDataEnter(@RequestBody JSONObject body){ |
| 62 | 68 | Map<String, Object> resMap = new HashMap<String, Object>(); |
| 63 | 69 | try { |
| 70 | + System.out.println(body); | |
| 71 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | |
| 72 | + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 73 | + | |
| 74 | + String startTime = body.getString("startTime"); | |
| 75 | + String endTime = body.getString("endTime"); | |
| 76 | + | |
| 64 | 77 | JdlReception jdlReception = new JdlReception(); |
| 65 | - jdlReception.setStationName(body.getString("StationName")); | |
| 66 | - jdlReception.setConnectorId(body.getString("ConnectorID")); | |
| 67 | - jdlReception.setOrderNo(body.getString("OrderNo")); | |
| 68 | - jdlReception.setStartTime(body.getString("StartTime")); | |
| 69 | - jdlReception.setEndTime(body.getString("EndTime")); | |
| 70 | - jdlReception.setStartSoc(body.getDouble("StartSoc")); | |
| 71 | - jdlReception.setEndSoc(body.getDouble("EndSoc")); | |
| 72 | - jdlReception.setStopReason(body.getString("StopReason")); | |
| 73 | - jdlReception.setChargeCapacity(body.getDouble("ChargeCapacity")); | |
| 74 | - jdlReception.setElectricCharge(body.getDouble("ElectricCharge")); | |
| 75 | - jdlReception.setServiceCharge(body.getDouble("ServiceCharge")); | |
| 76 | - jdlReception.setTotalAmount(body.getDouble("TotalAmount")); | |
| 77 | - jdlReception.setVinCode(body.getString("VinCode")); | |
| 78 | - jdlReception.setCardNo(body.getString("CardNo")); | |
| 79 | - jdlReception.setCarCode(body.getString("CarCode")); | |
| 78 | + jdlReception.setStationName(body.getString("stationName")); | |
| 79 | + jdlReception.setConnectorId(body.getString("connectorId")); | |
| 80 | + jdlReception.setOrderNo(body.getString("orderNo")); | |
| 81 | + jdlReception.setStartTime(startTime); | |
| 82 | + jdlReception.setEndTime(endTime); | |
| 83 | + jdlReception.setStartSoc(body.getDouble("startSoc")); | |
| 84 | + jdlReception.setEndSoc(body.getDouble("endSoc")); | |
| 85 | + jdlReception.setStopReason(body.getString("stopReason")); | |
| 86 | + jdlReception.setChargeCapacity(body.getDouble("chargeCapacity")); | |
| 87 | + jdlReception.setElectricCharge(body.getDouble("electricCharge")); | |
| 88 | + jdlReception.setServiceCharge(body.getDouble("serviceCharge")); | |
| 89 | + jdlReception.setTotalAmount(body.getDouble("totalAmount")); | |
| 90 | + jdlReception.setVinCode(body.getString("vinCode")); | |
| 91 | + jdlReception.setCardNo(body.getString("cardNo")); | |
| 92 | + jdlReception.setCarCode(body.getString("carCode")); | |
| 80 | 93 | jdlReception.setOrigin(0); |
| 81 | 94 | jdlReception.setCreateBy("接口接入"); |
| 82 | 95 | jdlReception.setCreateDate(new Date()); |
| 96 | + String carCode = body.getString("carCode"); | |
| 97 | + | |
| 98 | + String startDate = startTime.split(" ")[0]; | |
| 99 | +// String startCTime = startTime.split(" ")[1]; | |
| 100 | + | |
| 101 | + //根据充电开始时间保存到调度系统的充电量的表中,逻辑为根据充电开始时间来根据该车辆最后营运班次所在线路的次日首班车发车时间前 | |
| 102 | + //比如这条记录的开始时间,日期是15号,按15号查路单,拿一个最早的发车时间,开始充电时间比这个发车时间早的算前一天 | |
| 103 | + List<ScheduleRealInfo> scheduleRealInfo = scheduleRealInfoRepository.getFirstByClZbhAndScheduleDateStrAndRealExecDateOrderByFcsjAsc(carCode, startDate, startDate); | |
| 104 | + | |
| 105 | + String searchDate; | |
| 106 | + //如果存在路单,则作为当天的数据,保存到开始充电时间那一天,如果不存在路单,则直接作为前一天的数据保存 | |
| 107 | + if (scheduleRealInfo != null && scheduleRealInfo.size() > 0) { | |
| 108 | +// log.info("存在路单,作为当天的数据保存"); | |
| 109 | + //保存到当天的数据 | |
| 110 | + searchDate = startDate; | |
| 111 | + } else { | |
| 112 | +// log.info("不存在路单,直接作为前一天的数据保存"); | |
| 113 | +// String oldDate = DateUtils.getBeforeDate(30, DateUtils.parseDate(startDate)); | |
| 114 | + Date parse = sdf.parse(startDate); | |
| 115 | + parse.setTime(parse.getTime() - (30l*1000*60*60*24)); | |
| 116 | + String oldDate = sdf.format(parse); | |
| 117 | + List<ScheduleRealInfo> scheduleRealInfo1 = scheduleRealInfoRepository.getFirstByClZbhAndScheduleDateStrBetweenOrderByScheduleDateStrDesc(carCode, oldDate, startDate); | |
| 118 | + if (scheduleRealInfo1 != null && scheduleRealInfo1.size() > 0) { | |
| 119 | + //DateUtils.getBeforeDate(1, DateUtils.parseDate(startDate)); | |
| 120 | + searchDate = oldDate; | |
| 121 | + } else { | |
| 122 | + //如果是新车,则作为当天的数据 | |
| 123 | + searchDate = startDate; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + Date startTime_Date = df.parse(startTime); | |
| 128 | + Date endTime_Date = df.parse(endTime); | |
| 129 | + jdlReception.setDateStr(searchDate); | |
| 130 | + jdlReception.setSumTime(Integer.valueOf(((endTime_Date.getTime() - startTime_Date.getTime()) / 60000)+"")); | |
| 131 | + | |
| 83 | 132 | jdlReceptionRepository.save(jdlReception); |
| 84 | 133 | |
| 85 | 134 | resMap.put("Status", 0); | ... | ... |