Commit e3a699e2 authored by zhouzihao's avatar zhouzihao

dev-添加车体检接口的实现

parent c476b21c
package com.vandyo.sentry.core; package com.vandyo.sentry.core;
import com.vandyo.sentry.core.cases.CarInfoDecorator; import com.vandyo.sentry.core.cases.*;
import com.vandyo.sentry.core.cases.CarListDecorator;
import com.vandyo.sentry.core.cases.Case;
import com.vandyo.sentry.core.cases.LoginCase;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -31,6 +28,7 @@ public class Tmp { ...@@ -31,6 +28,7 @@ public class Tmp {
case1 = new LoginCase(mobile,pwd); case1 = new LoginCase(mobile,pwd);
case1 = new CarListDecorator(case1); case1 = new CarListDecorator(case1);
case1 = new CarInfoDecorator(case1); case1 = new CarInfoDecorator(case1);
case1 = new CarDetectDecorator(case1);
case1.check(); case1.check();
} }
......
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.tools.Signature;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* 车体检案例
*/
public class CarDetectDecorator extends CaseDecorator {
private final static String carDetectUrl = "/car/car_detect";
public CarDetectDecorator(Case aCase) {
super(aCase);
}
/**
* FIXME: 需要优化相同的代码有些请求 只需要修改一个url
* @return
*/
@Override
public Res<Map<String, String>> 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 + carDetectUrl + "?"
+ 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;
}
}
}
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