Commit a35800c6111e9cb215e47a3a99f2e676097868e5
1 parent
ffcbb698
1.指令回复查询接口增加
Showing
3 changed files
with
215 additions
and
62 deletions
src/main/java/com/bsth/entity/D60.java
0 → 100644
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| 4 | +import com.fasterxml.jackson.annotation.JsonProperty; | ||
| 5 | + | ||
| 6 | +import javax.persistence.*; | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author PanZhao | ||
| 11 | + * @ClassName: D60 | ||
| 12 | + * @Description: TODO(调度指令) | ||
| 13 | + * @date 2016年6月7日 上午10:21:59 | ||
| 14 | + */ | ||
| 15 | +@Entity | ||
| 16 | +@Table(name = "bsth_v_directive_60") | ||
| 17 | +public class D60 { | ||
| 18 | + | ||
| 19 | + @Id | ||
| 20 | + @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 21 | + private Integer id; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 设备编号 | ||
| 25 | + */ | ||
| 26 | + @JsonIgnore | ||
| 27 | + private String deviceId; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 时间戳 | ||
| 31 | + */ | ||
| 32 | + @JsonIgnore | ||
| 33 | + private Long timestamp; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 唯一标识 | ||
| 37 | + */ | ||
| 38 | + @JsonProperty("msgId") | ||
| 39 | + private Integer msgId; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 46收到时间 | ||
| 43 | + */ | ||
| 44 | + @JsonProperty("deviceReplyTime") | ||
| 45 | + private Long reply46Time; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 47收到时间 | ||
| 49 | + */ | ||
| 50 | + @JsonProperty("jsyReplyTime") | ||
| 51 | + private Long reply47Time; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 指令日期 | ||
| 55 | + */ | ||
| 56 | + @JsonIgnore | ||
| 57 | + private String rq; | ||
| 58 | + | ||
| 59 | + public Integer getId() { | ||
| 60 | + return id; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setId(Integer id) { | ||
| 64 | + this.id = id; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public String getDeviceId() { | ||
| 68 | + return deviceId; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setDeviceId(String deviceId) { | ||
| 72 | + this.deviceId = deviceId; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public Long getTimestamp() { | ||
| 76 | + return timestamp; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setTimestamp(Long timestamp) { | ||
| 80 | + this.timestamp = timestamp; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public Integer getMsgId() { | ||
| 84 | + return msgId; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setMsgId(Integer msgId) { | ||
| 88 | + this.msgId = msgId; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public Long getReply46Time() { | ||
| 92 | + return reply46Time; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setReply46Time(Long reply46Time) { | ||
| 96 | + this.reply46Time = reply46Time; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public Long getReply47Time() { | ||
| 100 | + return reply47Time; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public void setReply47Time(Long reply47Time) { | ||
| 104 | + this.reply47Time = reply47Time; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public String getRq() { | ||
| 108 | + return rq; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setRq(String rq) { | ||
| 112 | + this.rq = rq; | ||
| 113 | + } | ||
| 114 | +} |
src/main/java/com/bsth/repository/DirectiveRepository.java
0 → 100644
| 1 | +package com.bsth.repository; | ||
| 2 | + | ||
| 3 | +import com.bsth.entity.D60; | ||
| 4 | +import com.bsth.entity.ScheduleRealInfo; | ||
| 5 | +import org.springframework.data.jpa.repository.EntityGraph; | ||
| 6 | +import org.springframework.data.jpa.repository.Query; | ||
| 7 | +import org.springframework.data.repository.PagingAndSortingRepository; | ||
| 8 | +import org.springframework.stereotype.Repository; | ||
| 9 | + | ||
| 10 | +import java.util.Date; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +@Repository | ||
| 14 | +public interface DirectiveRepository extends PagingAndSortingRepository<D60, Long> { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 根据日期获取班次信息 | ||
| 18 | + * @param schDate | ||
| 19 | + * @return | ||
| 20 | + */ | ||
| 21 | + @Query("select d from D60 d where d.rq=?1 and d.deviceId=?2 order by d.timestamp desc") | ||
| 22 | + List<D60> findByRqAndDevice(String rq, String device); | ||
| 23 | +} |
src/main/java/com/bsth/server_rs/directive/DirectiveRestService.java
| 1 | -package com.bsth.server_rs.directive; | ||
| 2 | - | ||
| 3 | -import com.alibaba.fastjson.JSON; | ||
| 4 | -import com.bsth.server_rs.schedule.real.SchRealDataBuffer; | ||
| 5 | -import com.bsth.util.ConfigUtil; | ||
| 6 | -import com.bsth.util.HttpClientUtils; | ||
| 7 | -import org.slf4j.Logger; | ||
| 8 | -import org.slf4j.LoggerFactory; | ||
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | -import org.springframework.stereotype.Component; | ||
| 11 | -import org.springframework.web.bind.annotation.RequestBody; | ||
| 12 | - | ||
| 13 | -import javax.ws.rs.*; | ||
| 14 | -import javax.ws.rs.core.MediaType; | ||
| 15 | -import java.util.List; | ||
| 16 | -import java.util.Map; | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * Created by panzhao on 2017/11/10. | ||
| 20 | - */ | ||
| 21 | -@Component | ||
| 22 | -@Path("/directive") | ||
| 23 | -@Produces({MediaType.APPLICATION_JSON}) | ||
| 24 | -public class DirectiveRestService { | ||
| 25 | - | ||
| 26 | - static String url; | ||
| 27 | - static String secretKey; | ||
| 28 | - | ||
| 29 | - @Autowired | ||
| 30 | - SchRealDataBuffer schRealDataBuffer; | ||
| 31 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 32 | - | ||
| 33 | - static { | ||
| 34 | - secretKey = ConfigUtil.get("http.control.secret.key"); | ||
| 35 | - url = ConfigUtil.get("http.control.service_data_url") + "/send60Phrase?secretKey=" + secretKey; | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - @POST | ||
| 39 | - @Path("/send") | ||
| 40 | - public int send(@RequestBody Map<String, Object> map){ | ||
| 41 | - try{ | ||
| 42 | - map.put("sender", "接口@系统"); | ||
| 43 | - StringBuilder sb = HttpClientUtils.post(url , JSON.toJSONString(map)); | ||
| 44 | - return Integer.parseInt(sb.toString()); | ||
| 45 | - }catch (Exception e){ | ||
| 46 | - logger.error("", e); | ||
| 47 | - return -500; | ||
| 48 | - } | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - @GET | ||
| 52 | - @Path("/reply/{msgIds}") | ||
| 53 | - public List<Map> reply(@PathParam("msgIds") String msgIds){ | ||
| 54 | - try{ | ||
| 55 | - StringBuilder sb = HttpClientUtils.get(url + "&msgIds=" + msgIds); | ||
| 56 | - return JSON.parseArray(sb.toString(), Map.class); | ||
| 57 | - }catch (Exception e){ | ||
| 58 | - logger.error("", e); | ||
| 59 | - return null; | ||
| 60 | - } | ||
| 61 | - } | ||
| 62 | -} | 1 | +package com.bsth.server_rs.directive; |
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.bsth.entity.D60; | ||
| 5 | +import com.bsth.repository.DirectiveRepository; | ||
| 6 | +import com.bsth.server_rs.schedule.real.SchRealDataBuffer; | ||
| 7 | +import com.bsth.util.ConfigUtil; | ||
| 8 | +import com.bsth.util.HttpClientUtils; | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.stereotype.Component; | ||
| 13 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 14 | + | ||
| 15 | +import javax.ws.rs.*; | ||
| 16 | +import javax.ws.rs.core.MediaType; | ||
| 17 | +import java.util.List; | ||
| 18 | +import java.util.Map; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * Created by panzhao on 2017/11/10. | ||
| 22 | + */ | ||
| 23 | +@Component | ||
| 24 | +@Path("/directive") | ||
| 25 | +@Produces({MediaType.APPLICATION_JSON}) | ||
| 26 | +public class DirectiveRestService { | ||
| 27 | + | ||
| 28 | + static String url; | ||
| 29 | + static String secretKey; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private DirectiveRepository directiveRepository; | ||
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + SchRealDataBuffer schRealDataBuffer; | ||
| 36 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 37 | + | ||
| 38 | + static { | ||
| 39 | + secretKey = ConfigUtil.get("http.control.secret.key"); | ||
| 40 | + url = ConfigUtil.get("http.control.service_data_url") + "/send60Phrase?secretKey=" + secretKey; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @POST | ||
| 44 | + @Path("/send") | ||
| 45 | + public int send(@RequestBody Map<String, Object> map){ | ||
| 46 | + try{ | ||
| 47 | + map.put("sender", "接口@系统"); | ||
| 48 | + StringBuilder sb = HttpClientUtils.post(url , JSON.toJSONString(map)); | ||
| 49 | + return Integer.parseInt(sb.toString()); | ||
| 50 | + }catch (Exception e){ | ||
| 51 | + logger.error("", e); | ||
| 52 | + return -500; | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @GET | ||
| 57 | + @Path("/reply/{msgIds}") | ||
| 58 | + public List<Map> reply(@PathParam("msgIds") String msgIds){ | ||
| 59 | + try{ | ||
| 60 | + StringBuilder sb = HttpClientUtils.get(url + "&msgIds=" + msgIds); | ||
| 61 | + return JSON.parseArray(sb.toString(), Map.class); | ||
| 62 | + }catch (Exception e){ | ||
| 63 | + logger.error("", e); | ||
| 64 | + return null; | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @GET | ||
| 69 | + @Path("/reply/{rq}/{device}") | ||
| 70 | + public List<D60> reply(@PathParam("rq") String rq, @PathParam("device") String device){ | ||
| 71 | + try{ | ||
| 72 | + return directiveRepository.findByRqAndDevice(rq, device); | ||
| 73 | + }catch (Exception e){ | ||
| 74 | + logger.error("", e); | ||
| 75 | + return null; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | +} |