Commit 6de39d305f0bd1e10ff9af4eda8217f2b0f514fb
1 parent
4df634e6
1.加入kafka传电子路单至数据中台
Showing
3 changed files
with
390 additions
and
324 deletions
pom.xml
| ... | ... | @@ -151,6 +151,11 @@ |
| 151 | 151 | <artifactId>geronimo-jaxws_2.2_spec</artifactId> |
| 152 | 152 | <version>1.0</version> |
| 153 | 153 | </dependency> |
| 154 | + | |
| 155 | + <dependency> | |
| 156 | + <groupId>org.springframework.kafka</groupId> | |
| 157 | + <artifactId>spring-kafka</artifactId> | |
| 158 | + </dependency> | |
| 154 | 159 | </dependencies> |
| 155 | 160 | |
| 156 | 161 | <build> | ... | ... |
src/main/java/com/bsth/repository/ScheduleRealInfoRepository.java
| 1 | -package com.bsth.repository; | |
| 2 | - | |
| 3 | -import com.bsth.entity.ScheduleRealInfo; | |
| 4 | -import org.springframework.data.jpa.repository.EntityGraph; | |
| 5 | -import org.springframework.data.jpa.repository.Query; | |
| 6 | -import org.springframework.data.repository.PagingAndSortingRepository; | |
| 7 | -import org.springframework.stereotype.Repository; | |
| 8 | - | |
| 9 | -import java.util.Date; | |
| 10 | -import java.util.List; | |
| 11 | - | |
| 12 | -@Repository | |
| 13 | -public interface ScheduleRealInfoRepository extends PagingAndSortingRepository<ScheduleRealInfo, Long> { | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * 根据日期获取班次信息 | |
| 17 | - * @param schDate | |
| 18 | - * @return | |
| 19 | - */ | |
| 20 | - @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 21 | - @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1") | |
| 22 | - List<ScheduleRealInfo> findAll(String schDate); | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * 根据日期和线路编码获取班次信息 | |
| 26 | - * @param schDate | |
| 27 | - * @param lineCode | |
| 28 | - * @return | |
| 29 | - */ | |
| 30 | - @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 31 | - @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1 and s.xlBm=?2") | |
| 32 | - List<ScheduleRealInfo> findAll(String schDate, String lineCode); | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * 获取大于指定日期的班次信息 | |
| 36 | - * @param schDate | |
| 37 | - * @return | |
| 38 | - */ | |
| 39 | - @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 40 | - @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr>?1") | |
| 41 | - List<ScheduleRealInfo> findByDateLT(String schDate); | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * 根据日期和公司编码获取班次信息 | |
| 45 | - * @param schDate | |
| 46 | - * @param companyCode | |
| 47 | - * @return | |
| 48 | - */ | |
| 49 | - @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 50 | - @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1 and s.gsBm=?2 and s.updateDate>=?3") | |
| 51 | - List<ScheduleRealInfo> findByDateAndCompany(String schDate, String companyCode, Date timestamp); | |
| 52 | -} | |
| 1 | +package com.bsth.repository; | |
| 2 | + | |
| 3 | +import com.bsth.entity.ScheduleRealInfo; | |
| 4 | +import org.springframework.data.jpa.repository.EntityGraph; | |
| 5 | +import org.springframework.data.jpa.repository.Query; | |
| 6 | +import org.springframework.data.repository.PagingAndSortingRepository; | |
| 7 | +import org.springframework.stereotype.Repository; | |
| 8 | + | |
| 9 | +import java.util.Date; | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +@Repository | |
| 13 | +public interface ScheduleRealInfoRepository extends PagingAndSortingRepository<ScheduleRealInfo, Long> { | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 根据日期获取班次信息 | |
| 17 | + * @param schDate | |
| 18 | + * @return | |
| 19 | + */ | |
| 20 | + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 21 | + @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1") | |
| 22 | + List<ScheduleRealInfo> findAll(String schDate); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 根据日期和线路编码获取班次信息 | |
| 26 | + * @param schDate | |
| 27 | + * @param lineCode | |
| 28 | + * @return | |
| 29 | + */ | |
| 30 | + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 31 | + @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1 and s.xlBm=?2") | |
| 32 | + List<ScheduleRealInfo> findAll(String schDate, String lineCode); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 获取大于指定日期的班次信息 | |
| 36 | + * @param schDate | |
| 37 | + * @return | |
| 38 | + */ | |
| 39 | + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 40 | + @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr>?1") | |
| 41 | + List<ScheduleRealInfo> findByDateLT(String schDate); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 根据日期和公司编码获取班次信息 | |
| 45 | + * @param schDate | |
| 46 | + * @param companyCode | |
| 47 | + * @return | |
| 48 | + */ | |
| 49 | + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 50 | + @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1 and s.gsBm=?2 and s.updateDate>=?3") | |
| 51 | + List<ScheduleRealInfo> findByDateAndCompany(String schDate, String companyCode, Date timestamp); | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * 根据日期和公司编码获取班次信息 | |
| 55 | + * @param schDates | |
| 56 | + * @param timestamp | |
| 57 | + * @return | |
| 58 | + */ | |
| 59 | + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 60 | + @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr in (?1) and s.updateDate>=?2") | |
| 61 | + List<ScheduleRealInfo> findByDates(List<String> schDates, Date timestamp); | |
| 62 | +} | ... | ... |
src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
| 1 | -package com.bsth.server_rs.schedule.real; | |
| 2 | - | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | -import com.alibaba.fastjson.JSONArray; | |
| 5 | -import com.alibaba.fastjson.JSONObject; | |
| 6 | -import com.bsth.common.BasicData; | |
| 7 | -import com.bsth.common.ResponseCode; | |
| 8 | -import com.bsth.entity.ScheduleRealInfo; | |
| 9 | -import com.bsth.redis.ScheduleRedisService; | |
| 10 | -import com.bsth.repository.ScheduleRealInfoRepository; | |
| 11 | -import com.bsth.server_rs.base_info.line.Line; | |
| 12 | -import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | |
| 13 | -import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig; | |
| 14 | -import com.bsth.server_rs.schedule.dto.ScheduleInOut; | |
| 15 | -import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK; | |
| 16 | -import com.bsth.util.ConfigUtil; | |
| 17 | -import com.bsth.util.HttpClientUtils; | |
| 18 | -import com.google.common.base.Splitter; | |
| 19 | -import org.apache.commons.lang3.StringUtils; | |
| 20 | -import org.joda.time.DateTime; | |
| 21 | -import org.joda.time.DateTimeZone; | |
| 22 | -import org.joda.time.format.DateTimeFormat; | |
| 23 | -import org.joda.time.format.DateTimeFormatter; | |
| 24 | -import org.slf4j.Logger; | |
| 25 | -import org.slf4j.LoggerFactory; | |
| 26 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 27 | -import org.springframework.stereotype.Component; | |
| 28 | - | |
| 29 | -import javax.ws.rs.*; | |
| 30 | -import javax.ws.rs.core.MediaType; | |
| 31 | -import java.net.URLEncoder; | |
| 32 | -import java.util.*; | |
| 33 | - | |
| 34 | -/** | |
| 35 | - * Created by panzhao on 2017/8/24. | |
| 36 | - */ | |
| 37 | -@Component | |
| 38 | -@Path("/schedule_real") | |
| 39 | -@Produces({MediaType.APPLICATION_JSON}) | |
| 40 | -public class ScheduleRealService { | |
| 41 | - | |
| 42 | - @Autowired | |
| 43 | - ScheduleRedisService redisService; | |
| 44 | - | |
| 45 | - @Autowired | |
| 46 | - SchRealDataBuffer schRealDataBuffer; | |
| 47 | - | |
| 48 | - @Autowired | |
| 49 | - private ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 50 | - | |
| 51 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 52 | - | |
| 53 | - static String url; | |
| 54 | - static String secretKey; | |
| 55 | - | |
| 56 | - static { | |
| 57 | - secretKey = ConfigUtil.get("http.control.secret.key"); | |
| 58 | - url = ConfigUtil.get("http.control.service_data_url");// + "/execSchList?secretKey=" + secretKey; | |
| 59 | - } | |
| 60 | - | |
| 61 | - @POST | |
| 62 | - @Path("tcc_tzrc") | |
| 63 | - public Map<String, Object> tccTzrc(String jsonStr) { | |
| 64 | - JSONObject rs = new JSONObject(); | |
| 65 | - try { | |
| 66 | - StringBuilder sb = HttpClientUtils.post(url + "/tccHrhc?secretKey=" + secretKey, jsonStr); | |
| 67 | - | |
| 68 | - rs = JSONObject.parseObject(sb.toString()); | |
| 69 | - | |
| 70 | - if ("SUCCESS".equals(rs.get("status"))) { | |
| 71 | - rs.put("list", ScheduleInOut.getMultiInstance(JSONArray.parseArray(rs.getJSONArray("list").toJSONString(), ScheduleRealInfo.class))); | |
| 72 | - } | |
| 73 | - } catch (Exception e) { | |
| 74 | - logger.error("", e); | |
| 75 | - rs.put("status", ResponseCode.ERROR); | |
| 76 | - rs.put("msg", "接口服务器出现异常!"); | |
| 77 | - } | |
| 78 | - return rs; | |
| 79 | - } | |
| 80 | - | |
| 81 | - @POST | |
| 82 | - @Path("tcc_dftz") | |
| 83 | - public Map<String, Object> tccDftz(String jsonStr) { | |
| 84 | - JSONObject rs = new JSONObject(); | |
| 85 | - try { | |
| 86 | - StringBuilder sb = HttpClientUtils.post(url + "/dftzAndDestroy?secretKey=" + secretKey, jsonStr); | |
| 87 | - | |
| 88 | - rs = JSON.parseObject(sb.toString()); | |
| 89 | - | |
| 90 | - if ("SUCCESS".equals(rs.get("status"))) { | |
| 91 | - rs.put("t", new ScheduleInOut(JSON.toJavaObject(JSON.parseObject(rs.get("t").toString()), ScheduleRealInfo.class))); | |
| 92 | - } | |
| 93 | - //ScheduleInOut.getMultiInstance | |
| 94 | - } catch (Exception e) { | |
| 95 | - logger.error("", e); | |
| 96 | - rs.put("status", ResponseCode.ERROR); | |
| 97 | - rs.put("msg", "接口服务器出现异常!"); | |
| 98 | - } | |
| 99 | - return rs; | |
| 100 | - } | |
| 101 | - | |
| 102 | - /** | |
| 103 | - * 获取路牌下的班次信息 | |
| 104 | - * | |
| 105 | - * @param lineCode | |
| 106 | - * @param lpName | |
| 107 | - * @return | |
| 108 | - */ | |
| 109 | - @GET | |
| 110 | - @Path("/findByLpName/{lineCode}/{lpName}") | |
| 111 | - public List<ScheduleRealInfo> findByLpName(@PathParam("lineCode") String lineCode, @PathParam("lpName") String lpName) { | |
| 112 | - List<ScheduleRealInfo> list = new ArrayList<>(); | |
| 113 | - try { | |
| 114 | - if (StringUtils.isEmpty(lineCode) || StringUtils.isEmpty(lpName)) | |
| 115 | - return list; | |
| 116 | - | |
| 117 | - lpName = URLEncoder.encode(lpName, "UTF-8"); | |
| 118 | - StringBuilder sb = HttpClientUtils.get(url + "/findByLpName?secretKey=" + secretKey + "&lineCode=" + lineCode + "&lpName=" + lpName); | |
| 119 | - list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class); | |
| 120 | - } catch (Exception e) { | |
| 121 | - logger.error("", e); | |
| 122 | - } | |
| 123 | - return list; | |
| 124 | - } | |
| 125 | - | |
| 126 | - /** | |
| 127 | - * 获取当天指定停车场的进出场排班数据 | |
| 128 | - * | |
| 129 | - * @return | |
| 130 | - */ | |
| 131 | - @GET | |
| 132 | - @Path("/in_out/{code}") | |
| 133 | - public List<ScheduleInOut> findInOut(@PathParam("code") String code) { | |
| 134 | - Set<String> lineArray = BasicData.lineDateMap.keySet(); | |
| 135 | - | |
| 136 | - List<ScheduleInOut> all = new ArrayList<>(); | |
| 137 | - for (String lineCode : lineArray) { | |
| 138 | - all.addAll(ScheduleInOut.getMultiInstance(redisService.read(BasicData.lineDateMap.get(lineCode), lineCode), code)); | |
| 139 | - } | |
| 140 | - return all; | |
| 141 | - } | |
| 142 | - | |
| 143 | - /** | |
| 144 | - * 获取指定日期,指定公司的人员车辆配置情况(实际排班) | |
| 145 | - * | |
| 146 | - * @param company | |
| 147 | - * @param rq | |
| 148 | - * @return | |
| 149 | - */ | |
| 150 | - @GET | |
| 151 | - @Path("/ccConfig/{company}/{rq}") | |
| 152 | - public List<ScheduleCcInfoConfig> ccInfoConfig(@PathParam("company") String company, @PathParam("rq") String rq) { | |
| 153 | - List<Line> lines = LineBufferData.findByCompany(company); | |
| 154 | - | |
| 155 | - List<ScheduleCcInfoConfig> all = new ArrayList<>(); | |
| 156 | - for (Line line : lines) { | |
| 157 | - all.addAll(ScheduleCcInfoConfig.getMultiInstance(redisService.read(rq, line.getLineCode()))); | |
| 158 | - } | |
| 159 | - return all; | |
| 160 | - } | |
| 161 | - | |
| 162 | - /** | |
| 163 | - * 根据车辆自编号获取对应执行的班次信息 | |
| 164 | - * | |
| 165 | - * @param nbbm | |
| 166 | - * @return | |
| 167 | - */ | |
| 168 | - @GET | |
| 169 | - @Path("/exec/{nbbm}") | |
| 170 | - public JSONObject getExecPlan(@PathParam("nbbm") String nbbm) { | |
| 171 | - return schRealDataBuffer.getExecPlan(nbbm); | |
| 172 | - } | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * 获取全部的 车辆 和班次对照信息 | |
| 176 | - * | |
| 177 | - * @param | |
| 178 | - * @return | |
| 179 | - */ | |
| 180 | - @GET | |
| 181 | - @Path("/execs") | |
| 182 | - public Collection<JSONObject> execs(){ | |
| 183 | - return schRealDataBuffer.execs(); | |
| 184 | - } | |
| 185 | - | |
| 186 | - /** | |
| 187 | - * 获取当天指定停车场的进出场排班数据(潘钊场站VIP特供版 -高实时) | |
| 188 | - * | |
| 189 | - * @return | |
| 190 | - */ | |
| 191 | - @GET | |
| 192 | - @Path("/in_out/pz_vip/{code}") | |
| 193 | - public List<ScheduleInOut> findInOut_real(@PathParam("code") String code) { | |
| 194 | - logger.info("in_out -" + code); | |
| 195 | - return ScheduleInOut.getMultiInstance(schRealDataBuffer.findByParkCode(code)); | |
| 196 | - } | |
| 197 | - | |
| 198 | - @GET | |
| 199 | - @Path("/sch_jk/{company}/{rq}") | |
| 200 | - public List<ScheduleRealInfoDTO_JK> find_JK(@PathParam("company") String company, @PathParam("rq") String rq) { | |
| 201 | - List<ScheduleRealInfoDTO_JK> all = new ArrayList<>(); | |
| 202 | - | |
| 203 | - List<Line> lines = LineBufferData.findByCompany(company); | |
| 204 | - for (Line line : lines) { | |
| 205 | - all.addAll(ScheduleRealInfoDTO_JK.getMultiInstance(redisService.read(rq, line.getLineCode()))); | |
| 206 | - } | |
| 207 | - return all; | |
| 208 | - } | |
| 209 | - | |
| 210 | - @GET | |
| 211 | - @Path("/sch_jk4modify/{company}/{rq}/{timestamp}") | |
| 212 | - public List<ScheduleRealInfoDTO_JK> sch_jk4modify(@PathParam("company") String company, @PathParam("rq") String rq, @PathParam("timestamp") long timestamp) { | |
| 213 | - DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd"); | |
| 214 | - DateTime dateTime = fmt.parseDateTime(rq); | |
| 215 | - List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company, new Date(timestamp)); | |
| 216 | - redisService.calcTime(scheduleRealInfos); | |
| 217 | - List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos); | |
| 218 | - | |
| 219 | - return result; | |
| 220 | - } | |
| 221 | - | |
| 222 | - /** | |
| 223 | - * 读取指定日期的redis 数据,计算程序调用 | |
| 224 | - * | |
| 225 | - * @param rqs | |
| 226 | - * @return | |
| 227 | - */ | |
| 228 | - @GET | |
| 229 | - @Path("/pz_vip/read/{rqs}") | |
| 230 | - public List<ScheduleRealInfo> read(@PathParam("rqs") String rqs) { | |
| 231 | - List<ScheduleRealInfo> all = new ArrayList<>(), rs = new ArrayList<>(); | |
| 232 | - List<Line> lines = LineBufferData.findAll(); | |
| 233 | - List<String> rqArray = Splitter.on(",").splitToList(rqs); | |
| 234 | - | |
| 235 | - for (Line line : lines) { | |
| 236 | - for (String rq : rqArray) | |
| 237 | - all.addAll(redisService.read(rq, line.getLineCode())); | |
| 238 | - } | |
| 239 | - | |
| 240 | - for (ScheduleRealInfo sch : all) { | |
| 241 | - if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks")) | |
| 242 | - continue; | |
| 243 | - | |
| 244 | - //烂班,临加,有子任务的 | |
| 245 | - if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0)) | |
| 246 | - rs.add(sch); | |
| 247 | - } | |
| 248 | - return rs; | |
| 249 | - } | |
| 250 | - | |
| 251 | - /** | |
| 252 | - * 读取指定日期线路的redis 数据,计算程序调用 | |
| 253 | - * | |
| 254 | - * @param rq | |
| 255 | - * @return | |
| 256 | - */ | |
| 257 | - @GET | |
| 258 | - @Path("/pz_vip/readByRqAndLine/{rq}/{lineCode}") | |
| 259 | - public List<ScheduleRealInfo> readByLine(@PathParam("rq") String rq, @PathParam("lineCode") String lineCode) { | |
| 260 | - List<ScheduleRealInfo> all = redisService.read(rq, lineCode), rs = new ArrayList<>(); | |
| 261 | - | |
| 262 | - for (ScheduleRealInfo sch : all) { | |
| 263 | - if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks")) | |
| 264 | - continue; | |
| 265 | - | |
| 266 | - //烂班,临加,有子任务的 | |
| 267 | - if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0)) | |
| 268 | - rs.add(sch); | |
| 269 | - } | |
| 270 | - return rs; | |
| 271 | - } | |
| 272 | -} | |
| 1 | +package com.bsth.server_rs.schedule.real; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.alibaba.fastjson.JSONArray; | |
| 5 | +import com.alibaba.fastjson.JSONObject; | |
| 6 | +import com.bsth.Application; | |
| 7 | +import com.bsth.common.BasicData; | |
| 8 | +import com.bsth.common.ResponseCode; | |
| 9 | +import com.bsth.entity.ScheduleRealInfo; | |
| 10 | +import com.bsth.entity.ScheduleRealInfoVo; | |
| 11 | +import com.bsth.redis.ScheduleRedisService; | |
| 12 | +import com.bsth.repository.ScheduleRealInfoRepository; | |
| 13 | +import com.bsth.server_rs.base_info.line.Line; | |
| 14 | +import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | |
| 15 | +import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig; | |
| 16 | +import com.bsth.server_rs.schedule.dto.ScheduleInOut; | |
| 17 | +import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK; | |
| 18 | +import com.bsth.util.ConfigUtil; | |
| 19 | +import com.bsth.util.HttpClientUtils; | |
| 20 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
| 21 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 22 | +import com.google.common.base.Splitter; | |
| 23 | +import org.apache.commons.lang3.StringUtils; | |
| 24 | +import org.apache.kafka.clients.producer.ProducerRecord; | |
| 25 | +import org.joda.time.DateTime; | |
| 26 | +import org.joda.time.format.DateTimeFormat; | |
| 27 | +import org.joda.time.format.DateTimeFormatter; | |
| 28 | +import org.slf4j.Logger; | |
| 29 | +import org.slf4j.LoggerFactory; | |
| 30 | +import org.springframework.beans.BeanUtils; | |
| 31 | +import org.springframework.beans.factory.InitializingBean; | |
| 32 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 33 | +import org.springframework.kafka.core.KafkaTemplate; | |
| 34 | +import org.springframework.messaging.Message; | |
| 35 | +import org.springframework.stereotype.Component; | |
| 36 | + | |
| 37 | +import javax.ws.rs.*; | |
| 38 | +import javax.ws.rs.core.MediaType; | |
| 39 | +import java.net.URLEncoder; | |
| 40 | +import java.util.*; | |
| 41 | +import java.util.concurrent.*; | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * Created by panzhao on 2017/8/24. | |
| 45 | + */ | |
| 46 | +@Component | |
| 47 | +@Path("/schedule_real") | |
| 48 | +@Produces({MediaType.APPLICATION_JSON}) | |
| 49 | +public class ScheduleRealService implements InitializingBean { | |
| 50 | + | |
| 51 | + @Autowired | |
| 52 | + ScheduleRedisService redisService; | |
| 53 | + | |
| 54 | + @Autowired | |
| 55 | + SchRealDataBuffer schRealDataBuffer; | |
| 56 | + | |
| 57 | + @Autowired | |
| 58 | + private ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 59 | + | |
| 60 | + @Autowired | |
| 61 | + private KafkaTemplate kafkaTemplate; | |
| 62 | + | |
| 63 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 64 | + | |
| 65 | + static String url; | |
| 66 | + static String secretKey; | |
| 67 | + | |
| 68 | + private volatile long timestamp; | |
| 69 | + | |
| 70 | + static { | |
| 71 | + secretKey = ConfigUtil.get("http.control.secret.key"); | |
| 72 | + url = ConfigUtil.get("http.control.service_data_url");// + "/execSchList?secretKey=" + secretKey; | |
| 73 | + } | |
| 74 | + | |
| 75 | + @POST | |
| 76 | + @Path("tcc_tzrc") | |
| 77 | + public Map<String, Object> tccTzrc(String jsonStr) { | |
| 78 | + JSONObject rs = new JSONObject(); | |
| 79 | + try { | |
| 80 | + StringBuilder sb = HttpClientUtils.post(url + "/tccHrhc?secretKey=" + secretKey, jsonStr); | |
| 81 | + | |
| 82 | + rs = JSONObject.parseObject(sb.toString()); | |
| 83 | + | |
| 84 | + if ("SUCCESS".equals(rs.get("status"))) { | |
| 85 | + rs.put("list", ScheduleInOut.getMultiInstance(JSONArray.parseArray(rs.getJSONArray("list").toJSONString(), ScheduleRealInfo.class))); | |
| 86 | + } | |
| 87 | + } catch (Exception e) { | |
| 88 | + logger.error("", e); | |
| 89 | + rs.put("status", ResponseCode.ERROR); | |
| 90 | + rs.put("msg", "接口服务器出现异常!"); | |
| 91 | + } | |
| 92 | + return rs; | |
| 93 | + } | |
| 94 | + | |
| 95 | + @POST | |
| 96 | + @Path("tcc_dftz") | |
| 97 | + public Map<String, Object> tccDftz(String jsonStr) { | |
| 98 | + JSONObject rs = new JSONObject(); | |
| 99 | + try { | |
| 100 | + StringBuilder sb = HttpClientUtils.post(url + "/dftzAndDestroy?secretKey=" + secretKey, jsonStr); | |
| 101 | + | |
| 102 | + rs = JSON.parseObject(sb.toString()); | |
| 103 | + | |
| 104 | + if ("SUCCESS".equals(rs.get("status"))) { | |
| 105 | + rs.put("t", new ScheduleInOut(JSON.toJavaObject(JSON.parseObject(rs.get("t").toString()), ScheduleRealInfo.class))); | |
| 106 | + } | |
| 107 | + //ScheduleInOut.getMultiInstance | |
| 108 | + } catch (Exception e) { | |
| 109 | + logger.error("", e); | |
| 110 | + rs.put("status", ResponseCode.ERROR); | |
| 111 | + rs.put("msg", "接口服务器出现异常!"); | |
| 112 | + } | |
| 113 | + return rs; | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * 获取路牌下的班次信息 | |
| 118 | + * | |
| 119 | + * @param lineCode | |
| 120 | + * @param lpName | |
| 121 | + * @return | |
| 122 | + */ | |
| 123 | + @GET | |
| 124 | + @Path("/findByLpName/{lineCode}/{lpName}") | |
| 125 | + public List<ScheduleRealInfo> findByLpName(@PathParam("lineCode") String lineCode, @PathParam("lpName") String lpName) { | |
| 126 | + List<ScheduleRealInfo> list = new ArrayList<>(); | |
| 127 | + try { | |
| 128 | + if (StringUtils.isEmpty(lineCode) || StringUtils.isEmpty(lpName)) | |
| 129 | + return list; | |
| 130 | + | |
| 131 | + lpName = URLEncoder.encode(lpName, "UTF-8"); | |
| 132 | + StringBuilder sb = HttpClientUtils.get(url + "/findByLpName?secretKey=" + secretKey + "&lineCode=" + lineCode + "&lpName=" + lpName); | |
| 133 | + list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class); | |
| 134 | + } catch (Exception e) { | |
| 135 | + logger.error("", e); | |
| 136 | + } | |
| 137 | + return list; | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * 获取当天指定停车场的进出场排班数据 | |
| 142 | + * | |
| 143 | + * @return | |
| 144 | + */ | |
| 145 | + @GET | |
| 146 | + @Path("/in_out/{code}") | |
| 147 | + public List<ScheduleInOut> findInOut(@PathParam("code") String code) { | |
| 148 | + Set<String> lineArray = BasicData.lineDateMap.keySet(); | |
| 149 | + | |
| 150 | + List<ScheduleInOut> all = new ArrayList<>(); | |
| 151 | + for (String lineCode : lineArray) { | |
| 152 | + all.addAll(ScheduleInOut.getMultiInstance(redisService.read(BasicData.lineDateMap.get(lineCode), lineCode), code)); | |
| 153 | + } | |
| 154 | + return all; | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * 获取指定日期,指定公司的人员车辆配置情况(实际排班) | |
| 159 | + * | |
| 160 | + * @param company | |
| 161 | + * @param rq | |
| 162 | + * @return | |
| 163 | + */ | |
| 164 | + @GET | |
| 165 | + @Path("/ccConfig/{company}/{rq}") | |
| 166 | + public List<ScheduleCcInfoConfig> ccInfoConfig(@PathParam("company") String company, @PathParam("rq") String rq) { | |
| 167 | + List<Line> lines = LineBufferData.findByCompany(company); | |
| 168 | + | |
| 169 | + List<ScheduleCcInfoConfig> all = new ArrayList<>(); | |
| 170 | + for (Line line : lines) { | |
| 171 | + all.addAll(ScheduleCcInfoConfig.getMultiInstance(redisService.read(rq, line.getLineCode()))); | |
| 172 | + } | |
| 173 | + return all; | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * 根据车辆自编号获取对应执行的班次信息 | |
| 178 | + * | |
| 179 | + * @param nbbm | |
| 180 | + * @return | |
| 181 | + */ | |
| 182 | + @GET | |
| 183 | + @Path("/exec/{nbbm}") | |
| 184 | + public JSONObject getExecPlan(@PathParam("nbbm") String nbbm) { | |
| 185 | + return schRealDataBuffer.getExecPlan(nbbm); | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * 获取全部的 车辆 和班次对照信息 | |
| 190 | + * | |
| 191 | + * @param | |
| 192 | + * @return | |
| 193 | + */ | |
| 194 | + @GET | |
| 195 | + @Path("/execs") | |
| 196 | + public Collection<JSONObject> execs(){ | |
| 197 | + return schRealDataBuffer.execs(); | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * 获取当天指定停车场的进出场排班数据(潘钊场站VIP特供版 -高实时) | |
| 202 | + * | |
| 203 | + * @return | |
| 204 | + */ | |
| 205 | + @GET | |
| 206 | + @Path("/in_out/pz_vip/{code}") | |
| 207 | + public List<ScheduleInOut> findInOut_real(@PathParam("code") String code) { | |
| 208 | + logger.info("in_out -" + code); | |
| 209 | + return ScheduleInOut.getMultiInstance(schRealDataBuffer.findByParkCode(code)); | |
| 210 | + } | |
| 211 | + | |
| 212 | + @GET | |
| 213 | + @Path("/sch_jk/{company}/{rq}") | |
| 214 | + public List<ScheduleRealInfoDTO_JK> find_JK(@PathParam("company") String company, @PathParam("rq") String rq) { | |
| 215 | + List<ScheduleRealInfoDTO_JK> all = new ArrayList<>(); | |
| 216 | + | |
| 217 | + List<Line> lines = LineBufferData.findByCompany(company); | |
| 218 | + for (Line line : lines) { | |
| 219 | + all.addAll(ScheduleRealInfoDTO_JK.getMultiInstance(redisService.read(rq, line.getLineCode()))); | |
| 220 | + } | |
| 221 | + return all; | |
| 222 | + } | |
| 223 | + | |
| 224 | + @GET | |
| 225 | + @Path("/sch_jk4modify/{company}/{rq}/{timestamp}") | |
| 226 | + public List<ScheduleRealInfoDTO_JK> sch_jk4modify(@PathParam("company") String company, @PathParam("rq") String rq, @PathParam("timestamp") long timestamp) { | |
| 227 | + DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd"); | |
| 228 | + DateTime dateTime = fmt.parseDateTime(rq); | |
| 229 | + List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company, new Date(timestamp)); | |
| 230 | + redisService.calcTime(scheduleRealInfos); | |
| 231 | + List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos); | |
| 232 | + | |
| 233 | + return result; | |
| 234 | + } | |
| 235 | + | |
| 236 | + /** | |
| 237 | + * 读取指定日期的redis 数据,计算程序调用 | |
| 238 | + * | |
| 239 | + * @param rqs | |
| 240 | + * @return | |
| 241 | + */ | |
| 242 | + @GET | |
| 243 | + @Path("/pz_vip/read/{rqs}") | |
| 244 | + public List<ScheduleRealInfo> read(@PathParam("rqs") String rqs) { | |
| 245 | + List<ScheduleRealInfo> all = new ArrayList<>(), rs = new ArrayList<>(); | |
| 246 | + List<Line> lines = LineBufferData.findAll(); | |
| 247 | + List<String> rqArray = Splitter.on(",").splitToList(rqs); | |
| 248 | + | |
| 249 | + for (Line line : lines) { | |
| 250 | + for (String rq : rqArray) | |
| 251 | + all.addAll(redisService.read(rq, line.getLineCode())); | |
| 252 | + } | |
| 253 | + | |
| 254 | + for (ScheduleRealInfo sch : all) { | |
| 255 | + if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks")) | |
| 256 | + continue; | |
| 257 | + | |
| 258 | + //烂班,临加,有子任务的 | |
| 259 | + if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0)) | |
| 260 | + rs.add(sch); | |
| 261 | + } | |
| 262 | + return rs; | |
| 263 | + } | |
| 264 | + | |
| 265 | + /** | |
| 266 | + * 读取指定日期线路的redis 数据,计算程序调用 | |
| 267 | + * | |
| 268 | + * @param rq | |
| 269 | + * @return | |
| 270 | + */ | |
| 271 | + @GET | |
| 272 | + @Path("/pz_vip/readByRqAndLine/{rq}/{lineCode}") | |
| 273 | + public List<ScheduleRealInfo> readByLine(@PathParam("rq") String rq, @PathParam("lineCode") String lineCode) { | |
| 274 | + List<ScheduleRealInfo> all = redisService.read(rq, lineCode), rs = new ArrayList<>(); | |
| 275 | + | |
| 276 | + for (ScheduleRealInfo sch : all) { | |
| 277 | + if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks")) | |
| 278 | + continue; | |
| 279 | + | |
| 280 | + //烂班,临加,有子任务的 | |
| 281 | + if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0)) | |
| 282 | + rs.add(sch); | |
| 283 | + } | |
| 284 | + return rs; | |
| 285 | + } | |
| 286 | + | |
| 287 | + @Override | |
| 288 | + public void afterPropertiesSet() throws Exception { | |
| 289 | + Application.mainServices.scheduleWithFixedDelay(new Runnable() { | |
| 290 | + @Override | |
| 291 | + public void run() { | |
| 292 | + try { | |
| 293 | + DateTime dateTime = DateTime.now(), preDate = dateTime.minusDays(1); | |
| 294 | + List<String> dates = new ArrayList<>(); | |
| 295 | + dates.add(dateTime.toString("yyyy-MM-dd")); | |
| 296 | + dates.add(preDate.toString("yyyy-MM-dd")); | |
| 297 | + if (timestamp == 0) { | |
| 298 | + timestamp = dateTime.minusHours(1).getMillis(); | |
| 299 | + } | |
| 300 | + List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDates(dates, new Date(timestamp)); | |
| 301 | + timestamp = dateTime.getMillis(); | |
| 302 | + | |
| 303 | + List<ScheduleRealInfoVo> scheduleRealInfoVos = new ArrayList<>(); | |
| 304 | + for (ScheduleRealInfo sch : scheduleRealInfos) { | |
| 305 | + ScheduleRealInfoVo scheduleRealInfoVo = new ScheduleRealInfoVo(); | |
| 306 | + BeanUtils.copyProperties(sch, scheduleRealInfoVo); | |
| 307 | + scheduleRealInfoVos.add(scheduleRealInfoVo); | |
| 308 | + } | |
| 309 | + Map<String, Object> data = new HashMap<>(); | |
| 310 | + data.put("datatype", "waybill"); | |
| 311 | + data.put("datas", scheduleRealInfoVos); | |
| 312 | + | |
| 313 | + ObjectMapper mapper = new ObjectMapper(); | |
| 314 | + String json = mapper.writeValueAsString(data); | |
| 315 | + logger.info(json); | |
| 316 | + kafkaTemplate.send("PDGJ_JQDD", json); | |
| 317 | + } catch (Exception e) { | |
| 318 | + logger.error("kafka发电子路单调度异常", e); | |
| 319 | + } | |
| 320 | + } | |
| 321 | + }, 0, 4, TimeUnit.MINUTES); | |
| 322 | + } | |
| 323 | +} | ... | ... |