From 3e3635b9120fb42c1bfc6187431911db983c489c Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 30 Sep 2020 10:08:21 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0=E4=BA=BF?= =?UTF-8?q?=E9=98=B3=E8=AE=BE=E5=A4=87=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/YiYangAbilityImpl.java | 9 +- .../common/YiYangDisposeAbilityInfo.java | 37 +++++++++ .../common/YiYangDisposeAbilityRsp.java | 31 +++++++ .../yiyang/dispose/common/YiYangLoginRsp.java | 4 - .../dispose/common/YiYangStartTaskItem.java | 38 +++++++++ .../dispose/common/YiYangStartTaskReq.java | 24 ++++++ .../dispose/common/YiYangStartTaskRsp.java | 29 +++++++ .../dispose/common/YiYangStartedItem.java | 34 ++++++++ .../dispose/common/YiYangStopTaskReq.java | 22 +++++ .../dispose/common/YiYangStopTaskRsp.java | 28 +++++++ .../dispose/common/YiYangStoppedItem.java | 40 +++++++++ .../dispose/protocol/YiYangInterface.java | 82 +++++++++++++++++-- 12 files changed, 366 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityInfo.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityRsp.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskItem.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskReq.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskRsp.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangStartedItem.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskReq.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskRsp.java create mode 100644 src/main/java/com/dispose/yiyang/dispose/common/YiYangStoppedItem.java diff --git a/src/main/java/com/dispose/ability/impl/YiYangAbilityImpl.java b/src/main/java/com/dispose/ability/impl/YiYangAbilityImpl.java index 1e61715c..2665f558 100644 --- a/src/main/java/com/dispose/ability/impl/YiYangAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/YiYangAbilityImpl.java @@ -146,14 +146,16 @@ public class YiYangAbilityImpl implements DisposeAbility { @Override public boolean getDeviceLinkStatus() { try { + String url = urlRootPath + "dispose_device/information/linkstatus"; + if (token == null || token.length() == 0) { return false; } - ErrorCode err = restfulInterface.getLinkStatus(urlRootPath, token); + ErrorCode err = restfulInterface.getLinkStatus(url, token); if (err == ErrorCode.ERR_LOGOUT) { - err = restfulInterface.getLinkStatus(urlRootPath, token); + err = restfulInterface.getLinkStatus(url, token); } return err == ErrorCode.ERR_OK; @@ -188,7 +190,8 @@ public class YiYangAbilityImpl implements DisposeAbility { */ private void upgradeToken() { try { - ProtocolRespDTO logInfo = restfulInterface.login(urlRootPath, username, password); + String url = urlRootPath + "dispose_device/auth/login"; + ProtocolRespDTO logInfo = restfulInterface.login(url, username, password); if (logInfo != null && logInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) { this.token = logInfo.getMsgContent().getToken(); diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityInfo.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityInfo.java new file mode 100644 index 00000000..76b9995b --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityInfo.java @@ -0,0 +1,37 @@ +package com.dispose.yiyang.dispose.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang dispose ability info. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class YiYangDisposeAbilityInfo { + /** + * The Type. + */ + private Integer type; + + /** + * The Object type. + */ + private Integer objectType; + + /** + * The Ip type. + */ + private Integer IPType; + + /** + * The Protect ip. + */ + private String disposeIp; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityRsp.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityRsp.java new file mode 100644 index 00000000..091820c0 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangDisposeAbilityRsp.java @@ -0,0 +1,31 @@ +package com.dispose.yiyang.dispose.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * The type Yi yang dispose ability rsp. + * + * @author + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class YiYangDisposeAbilityRsp extends YiYangBaseResp { + /** + * The Device name. + */ + private String deviceName; + + /** + * The Capacity. + */ + List capacity; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginRsp.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginRsp.java index ca6861d8..79a9fabd 100644 --- a/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginRsp.java +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginRsp.java @@ -1,9 +1,7 @@ package com.dispose.yiyang.dispose.common; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -15,11 +13,9 @@ import lombok.NoArgsConstructor; */ @EqualsAndHashCode(callSuper = true) @Data -@Builder @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"}) public class YiYangLoginRsp extends YiYangBaseResp { /** * The User name. diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskItem.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskItem.java new file mode 100644 index 00000000..abf018e5 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskItem.java @@ -0,0 +1,38 @@ +package com.dispose.yiyang.dispose.common; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang start task items. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class YiYangStartTaskItem { + /** + * The Task req id. + */ + private String taskReqId; + /** + * The Type. + */ + private Integer type; + /** + * The Object type. + */ + private Integer objectType; + /** + * The Dispose object. + */ + private String disposeObject; + /** + * The Dispose time. + */ + private Long disposeTime; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskReq.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskReq.java new file mode 100644 index 00000000..9bf2c6c5 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskReq.java @@ -0,0 +1,24 @@ +package com.dispose.yiyang.dispose.common; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * The type Yi yang start task req. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class YiYangStartTaskReq { + /** + * The Items. + */ + List items; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskRsp.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskRsp.java new file mode 100644 index 00000000..0da0a146 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartTaskRsp.java @@ -0,0 +1,29 @@ +package com.dispose.yiyang.dispose.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * The type Yi yang start task rsp. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class YiYangStartTaskRsp { + /** + * The Device name. + */ + private String deviceName; + + /** + * The Items. + */ + List items; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartedItem.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartedItem.java new file mode 100644 index 00000000..343debb1 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStartedItem.java @@ -0,0 +1,34 @@ +package com.dispose.yiyang.dispose.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang started item. + * + * @author + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class YiYangStartedItem extends YiYangBaseResp { + /** + * The Task req id. + */ + private String taskReqId; + + /** + * The Task id. + */ + private String taskId; + + /** + * The Expire time. + */ + private Long expireTime; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskReq.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskReq.java new file mode 100644 index 00000000..769d835c --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskReq.java @@ -0,0 +1,22 @@ +package com.dispose.yiyang.dispose.common; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang stop task req. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class YiYangStopTaskReq { + /** + * The Task id. + */ + private String[] taskId; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskRsp.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskRsp.java new file mode 100644 index 00000000..f7215713 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStopTaskRsp.java @@ -0,0 +1,28 @@ +package com.dispose.yiyang.dispose.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * The type Yi yang stop task rsp. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class YiYangStopTaskRsp { + /** + * The Device name. + */ + private String deviceName; + /** + * The Items. + */ + private List items; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangStoppedItem.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStoppedItem.java new file mode 100644 index 00000000..50fbfdd4 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangStoppedItem.java @@ -0,0 +1,40 @@ +package com.dispose.yiyang.dispose.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang stopped item. + * + * @author + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class YiYangStoppedItem extends YiYangBaseResp { + /** + * The Task id. + */ + private String taskId; + /** + * The Type. + */ + private Integer type; + /** + * The Object type. + */ + private Integer objectType; + /** + * The Dispose object. + */ + private String disposeObject; + /** + * The Left time. + */ + private Long leftTime; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/protocol/YiYangInterface.java b/src/main/java/com/dispose/yiyang/dispose/protocol/YiYangInterface.java index 403901b6..2945b090 100644 --- a/src/main/java/com/dispose/yiyang/dispose/protocol/YiYangInterface.java +++ b/src/main/java/com/dispose/yiyang/dispose/protocol/YiYangInterface.java @@ -5,11 +5,18 @@ import com.dispose.pojo.dto.protocol.base.BaseProtocolDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.restful.RestfulInterface; import com.dispose.yiyang.dispose.common.YiYangBaseResp; +import com.dispose.yiyang.dispose.common.YiYangDisposeAbilityRsp; import com.dispose.yiyang.dispose.common.YiYangLoginReq; import com.dispose.yiyang.dispose.common.YiYangLoginRsp; +import com.dispose.yiyang.dispose.common.YiYangStartTaskItem; +import com.dispose.yiyang.dispose.common.YiYangStartTaskReq; +import com.dispose.yiyang.dispose.common.YiYangStartTaskRsp; +import com.dispose.yiyang.dispose.common.YiYangStopTaskReq; +import com.dispose.yiyang.dispose.common.YiYangStopTaskRsp; import org.springframework.web.bind.annotation.RequestMethod; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * The type Yi yang interface. @@ -58,7 +65,7 @@ public class YiYangInterface { reqInfo.setVer(this.ver); reqInfo.setTimeStamp(System.currentTimeMillis()); - return RestfulInterface.baseProRun(baseUrlPath + "dispose_device/auth/login", + return RestfulInterface.baseProRun(baseUrlPath, null, reqInfo, YiYangLoginRsp.class, @@ -73,19 +80,84 @@ public class YiYangInterface { * @return the link status */ public ErrorCode getLinkStatus(String baseUrlPath, String token) { - ProtocolRespDTO rspInfo = RestfulInterface.baseProRun(baseUrlPath + "dispose_device/information/linkstatus", + ProtocolRespDTO rspInfo = RestfulInterface.baseProRun(baseUrlPath, token, null, YiYangBaseResp.class, RequestMethod.GET); - if(rspInfo != null && rspInfo.getMsgContent() != null) { - if(rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) { + if (rspInfo != null && rspInfo.getMsgContent() != null) { + if (rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) { return ErrorCode.ERR_LOGOUT; - } else if(rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) { + } else if (rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) { return ErrorCode.ERR_OK; } } return ErrorCode.ERR_UNKNOWNCMD; } + + /** + * Start dispose task protocol resp dto. + * + * @param baseUrlPath the base url path + * @param token the token + * @param items the items + * @return the protocol resp dto + */ + public ProtocolRespDTO startDisposeTask(String baseUrlPath, String token, + List items) { + BaseProtocolDTO reqInfo = new BaseProtocolDTO<>(); + reqInfo.setMsgContent(new YiYangStartTaskReq()); + + reqInfo.getMsgContent().setItems(items); + reqInfo.setCryptoType(this.cryptoType); + reqInfo.setVer(this.ver); + reqInfo.setTimeStamp(System.currentTimeMillis()); + + return RestfulInterface.baseProRun(baseUrlPath, + token, + reqInfo, + YiYangStartTaskRsp.class, + RequestMethod.POST); + } + + /** + * Stop dispose task protocol resp dto. + * + * @param baseUrlPath the base url path + * @param token the token + * @param taskId the task id + * @return the protocol resp dto + */ + public ProtocolRespDTO stopDisposeTask(String baseUrlPath, String token, String[] taskId) { + BaseProtocolDTO reqInfo = new BaseProtocolDTO<>(); + + reqInfo.setMsgContent(new YiYangStopTaskReq()); + + reqInfo.getMsgContent().setTaskId(taskId); + reqInfo.setCryptoType(this.cryptoType); + reqInfo.setVer(this.ver); + reqInfo.setTimeStamp(System.currentTimeMillis()); + + return RestfulInterface.baseProRun(baseUrlPath, + token, + reqInfo, + YiYangStopTaskRsp.class, + RequestMethod.POST); + } + + /** + * Gets device dispose ability. + * + * @param baseUrlPath the base url path + * @param token the token + * @return the device dispose ability + */ + public ProtocolRespDTO getDeviceDisposeAbility(String baseUrlPath, String token) { + return RestfulInterface.baseProRun(baseUrlPath, + token, + null, + YiYangDisposeAbilityRsp.class, + RequestMethod.GET); + } }