Commit 28957d2f by wubh

包活干V1.9.1-修改:大搜车设备验证逻辑

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@27956 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent edde1ac6
...@@ -218,6 +218,20 @@ public interface BizConstants { ...@@ -218,6 +218,20 @@ public interface BizConstants {
*/ */
public static final String ORDER_SERVICE_ITEM_DASOUCHE = "sys_order_service_item"; public static final String ORDER_SERVICE_ITEM_DASOUCHE = "sys_order_service_item";
/**
* 大搜车设备类型:无线
*/
long DSC_DEVICE_TYPE_WIRELESS = 0;
/**
* 大搜车设备类型:有线
*/
long DSC_DEVICE_TYPE_WIRED = 1;
/**
* 无线设备定位超时:24小时
*/
long DSC_WIRELESS_DEVICE_TIMEOUT = 24 * 60 * 60 * 1000;
/**
* 有线设备定位超时:30分钟
*/
long DSC_WIRED_DEVICE_TIMEOUT = 30 * 60 * 1000;
} }
package com.glsx.ordercenter.thread; package com.glsx.ordercenter.thread;
import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.common.constants.ResultCodeEnum;
import com.glsx.common.utils.HttpUtils; import com.glsx.common.utils.HttpUtils;
import com.glsx.common.utils.PropertiesUtil; import com.glsx.common.utils.PropertiesUtil;
import com.glsx.ordercenter.constants.BizConstants;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.req.DaSouCheRequest; import com.glsx.ordercenter.dto.req.DaSouCheRequest;
import com.glsx.ordercenter.dto.resp.DSCResultObject; import com.glsx.ordercenter.dto.resp.DSCResultObject;
import com.glsx.ordercenter.utils.DaSouCheUtil; import com.glsx.ordercenter.utils.DaSouCheUtil;
...@@ -51,7 +53,8 @@ public class DscDeviceVerifyTask implements Callable<DSCResultObject> { ...@@ -51,7 +53,8 @@ public class DscDeviceVerifyTask implements Callable<DSCResultObject> {
dscResult = this.processResult(JSON.parseObject(respJson, String.class)); dscResult = this.processResult(JSON.parseObject(respJson, String.class));
} catch (Exception e) { } catch (Exception e) {
this.logger.error("==== DscDeviceVerifyTask ERROR: ", e); this.logger.error("==== DscDeviceVerifyTask ERROR: ", e);
dscResult = new DSCResultObject(ResultCodeEnum.ERROR); dscResult = new DSCResultObject(ResultCodeEnum.ERROR.getCode() + "",
ResultCodeEnum.ERROR.getMsg());
} }
this.logger.info("==== DscDeviceVerifyTask result: {}", dscResult); this.logger.info("==== DscDeviceVerifyTask result: {}", dscResult);
...@@ -108,15 +111,52 @@ public class DscDeviceVerifyTask implements Callable<DSCResultObject> { ...@@ -108,15 +111,52 @@ public class DscDeviceVerifyTask implements Callable<DSCResultObject> {
private DSCResultObject processResult(String respJson) { private DSCResultObject processResult(String respJson) {
DSCResultObject dscResult = new DSCResultObject(); DSCResultObject dscResult = new DSCResultObject();
JSONObject resp = JSON.parseObject(respJson); JSONObject resp = JSON.parseObject(respJson);
//String code = resultObj.getString("code"); String respCode = resp.getString("code");
String status = resp.getString("status"); String respStatus = resp.getString("status");
String message = resp.getString("message"); String respMsg = resp.getString("message");
JSONObject data = JSON.parseObject(resp.getString("data")); JSONObject respData = JSON.parseObject(resp.getString("data"));
dscResult.setCode(status); if ("0".equals(respCode) && "200".equals(respStatus)) {
dscResult.setMessage(message); // 定位正常,判断是否在时效内
dscResult.setData(data); boolean inTime = this.isDeviceLocationInTime(respData);
dscResult.setCode(inTime ? respStatus : "-1");
dscResult.setMessage(inTime ? respMsg : ResultCodeEnum.DEVICE_GPS_VERIFY_FAIL.getMsg());
} else {
// 定位不正常
dscResult.setCode("-1");
dscResult.setMessage(ResultCodeEnum.DEVICE_GPS_VERIFY_FAIL.getMsg());
}
dscResult.setData(respData);
return dscResult; return dscResult;
} }
/**
* 判断返回的定位信息是否在时效内,通过gpsTime判断
*
* @param respData 返回的数据中的data
* @return true-在时效内;false-超时
*/
private boolean isDeviceLocationInTime(JSONObject respData) {
boolean inTime;
try {
JSONObject innerData = respData.getJSONObject("data");
Long gpsTime = innerData.getLong("gpsTime");
Integer type = innerData.getInteger("type");
long currentMs = new Date().getTime();
long timeoutMs = (BizConstants.DSC_DEVICE_TYPE_WIRELESS == type)
? BizConstants.DSC_WIRELESS_DEVICE_TIMEOUT
: BizConstants.DSC_WIRED_DEVICE_TIMEOUT;
long timeDiff = currentMs - gpsTime;
inTime = (timeDiff < timeoutMs);
} catch (NullPointerException e) {
// 发生空指针异常,可能为获取数据为空,即表示定位失败
this.logger.error("==== DscDeviceVerifyTask Error when getting data: ", e);
inTime = false;
}
return inTime;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!