Commit c476b21c authored by zhouzihao's avatar zhouzihao

dev-添加获取车辆信息的接口

parent a44aa406
package com.vandyo.sentry.core; package com.vandyo.sentry.core;
import com.vandyo.sentry.core.cases.CarInfoDecorator;
import com.vandyo.sentry.core.cases.CarListDecorator; import com.vandyo.sentry.core.cases.CarListDecorator;
import com.vandyo.sentry.core.cases.Case; import com.vandyo.sentry.core.cases.Case;
import com.vandyo.sentry.core.cases.LoginCase; import com.vandyo.sentry.core.cases.LoginCase;
...@@ -29,6 +30,7 @@ public class Tmp { ...@@ -29,6 +30,7 @@ public class Tmp {
Case case1 = null; Case case1 = null;
case1 = new LoginCase(mobile,pwd); case1 = new LoginCase(mobile,pwd);
case1 = new CarListDecorator(case1); case1 = new CarListDecorator(case1);
case1 = new CarInfoDecorator(case1);
case1.check(); case1.check();
} }
......
package com.vandyo.sentry.core.cases; package com.vandyo.sentry.core.cases;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.vandyo.sentry.core.dto.ErrStatus;
import com.vandyo.sentry.core.dto.Res; import com.vandyo.sentry.core.dto.Res;
import com.vandyo.sentry.core.tools.Signature;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* 获取车信息接口 * 获取车信息接口
*/ */
public class CarInfoDecorator extends CaseDecorator { public class CarInfoDecorator extends CaseDecorator {
private final static String carInfoUrl = "/car/my_car/info";
public CarInfoDecorator(Case aCase) { public CarInfoDecorator(Case aCase) {
super(aCase); super(aCase);
} }
@Override @Override
public Res<Map<String, String>> check() { public Res<Map<String, String>> check() {
return super.check(); Res<Map<String,String>> oldRes = super.check();
if (oldRes.getSuccess()) {
Map<String, String> carMap = oldRes.getData();
Res<Map<String,String>> newRes = new Res<>();
newRes.setSId(oldRes.getSId());
newRes.setUId(oldRes.getUId());
if (Objects.isNull(carMap) || !carMap.containsKey("cid")){
newRes.setStatus(ErrStatus.ErrUnexpected);
newRes.setSuccess(false);
}else {
String cid = carMap.get("cid");
Map<String,String> paramMap = new HashMap<>();
paramMap.put("cid",cid);
paramMap.put("uid",oldRes.getUId());
HttpResponse response = HttpRequest.get(
Signature.host + carInfoUrl + "?"
+ Signature.getUrlParamsByMap(Signature.sign(paramMap,oldRes.getSId()))
).execute();
if (response.isOk()){
JSONObject jsonObject = JSONUtil.parseObj(response.body());
//todo 检测 返回值可用性
newRes.setData(carMap);
newRes.setSuccess(true);
}else {
newRes.setStatus(Signature.matchStatus(response.getStatus()));
newRes.setSuccess(false);
}
}
return newRes;
}else {
return oldRes;
}
} }
} }
...@@ -47,6 +47,7 @@ public class CarListDecorator extends CaseDecorator { ...@@ -47,6 +47,7 @@ public class CarListDecorator extends CaseDecorator {
newRes.setSuccess(true); newRes.setSuccess(true);
} }
}else { }else {
newRes.setStatus(Signature.matchStatus(response.getStatus()));
newRes.setSuccess(false); newRes.setSuccess(false);
} }
return newRes; return newRes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment