Commit 6c2011be by 王欣伟

请款接口测试完成

1 parent 438223c0
...@@ -129,6 +129,16 @@ public final class Constants { ...@@ -129,6 +129,16 @@ public final class Constants {
public static class DeviceOnline { public static class DeviceOnline {
/** /**
* 离线时间:三天(单位毫秒)
*/
public static final long TIME_TWENTY_HOURS = 259200000;
/**
* 离线时间:六分钟;单位毫秒
*/
public static final long TIME_SIX_MINITES = 360000;
/**
* 行驶 * 行驶
*/ */
public static final int DRIVING = 0; public static final int DRIVING = 0;
......
...@@ -1134,7 +1134,7 @@ public class WorkOrderService { ...@@ -1134,7 +1134,7 @@ public class WorkOrderService {
//查车辆 //查车辆
Vehicle vehicle = vehicleMapper.selectByWorkOrderId(workOrder.getId()); Vehicle vehicle = vehicleMapper.selectByWorkOrderId(workOrder.getId());
if (vehicle==null) { if (vehicle==null) {
throw new StdInterfaceException("656565", String.format("工单%s未完成", verifyBO.getBizWorkOrderNo())); throw new StdInterfaceException("656565", String.format("工单%s未完成车辆激活", verifyBO.getBizWorkOrderNo()));
} }
verifyDTO.setLesseeName(vehicle.getOwnerName()); verifyDTO.setLesseeName(vehicle.getOwnerName());
...@@ -1145,10 +1145,6 @@ public class WorkOrderService { ...@@ -1145,10 +1145,6 @@ public class WorkOrderService {
List<String> snList = deviceList.stream().map(VehicleDevice::getSn).collect(Collectors.toList()); List<String> snList = deviceList.stream().map(VehicleDevice::getSn).collect(Collectors.toList());
List<WorkOrderDeviceAddressItem> list = Lists.newArrayList(); List<WorkOrderDeviceAddressItem> list = Lists.newArrayList();
//位置是否有效的配置
long wiredTime = Constants.Verification.WIRED_TIME;
long wirelessTime = Constants.Verification.WIRELESS_TIME;
//查位置点 //查位置点
Map<String, GpsBsData> gpsBsDataMap = getLastGpsBsBatchBySns(snList); Map<String, GpsBsData> gpsBsDataMap = getLastGpsBsBatchBySns(snList);
snList.forEach(sn -> { snList.forEach(sn -> {
...@@ -1159,7 +1155,7 @@ public class WorkOrderService { ...@@ -1159,7 +1155,7 @@ public class WorkOrderService {
addressItem.setSn(sn); addressItem.setSn(sn);
addressItem.setSim(deviceDTO.getSim()); addressItem.setSim(deviceDTO.getSim());
addressItem.setDeviceType(deviceDTO.getSource()==Constants.DeviceSource.WIRED ? "有线设备" : "无线设备"); addressItem.setDeviceType((deviceDTO.getSource()!=null && deviceDTO.getSource()==Constants.DeviceSource.WIRED) ? "有线设备" : "无线设备");
GpsBsData gpsBsData = gpsBsDataMap.get(sn); GpsBsData gpsBsData = gpsBsDataMap.get(sn);
if (gpsBsData != null) { if (gpsBsData != null) {
......
...@@ -58,6 +58,9 @@ public class DateUtils extends com.glsx.plat.common.utils.DateUtils { ...@@ -58,6 +58,9 @@ public class DateUtils extends com.glsx.plat.common.utils.DateUtils {
* @return * @return
*/ */
public static Date toDate(String dateStr, String pattern) { public static Date toDate(String dateStr, String pattern) {
if (StringUtils.isBlank(dateStr)) {
return null;
}
try { try {
return getDateFormat(pattern).parse(dateStr); return getDateFormat(pattern).parse(dateStr);
} catch (ParseException e) { } catch (ParseException e) {
......
...@@ -23,7 +23,8 @@ public class DeviceLocationUtil { ...@@ -23,7 +23,8 @@ public class DeviceLocationUtil {
return Constants.Verification.SN_INVALID; return Constants.Verification.SN_INVALID;
} }
int currentSource = (source==null)?Constants.DeviceSource.WIRED:Constants.DeviceSource.WIRELESS; // 初始化设备有源无源状态:默认无源
int currentSource = (source==null)?Constants.DeviceSource.WIRELESS:source;
long differBase = (currentSource==Constants.DeviceSource.WIRED)?Constants.Verification.WIRED_TIME: Constants.Verification.WIRELESS_TIME; long differBase = (currentSource==Constants.DeviceSource.WIRED)?Constants.Verification.WIRED_TIME: Constants.Verification.WIRELESS_TIME;
if (StringUtils.isBlank(gpsTime)) { if (StringUtils.isBlank(gpsTime)) {
...@@ -34,7 +35,7 @@ public class DeviceLocationUtil { ...@@ -34,7 +35,7 @@ public class DeviceLocationUtil {
if (currentSource==Constants.DeviceSource.WIRELESS) { if (currentSource==Constants.DeviceSource.WIRELESS) {
long gpsDiffer = DateUtils.getTimeDifference(gpsTime); long gpsDiffer = DateUtils.getTimeDifference(gpsTime);
long bsDiffer = DateUtils.getTimeDifference(bsTime); long bsDiffer = DateUtils.getTimeDifference(bsTime);
timeDiff = (gpsDiffer>bsDiffer)?gpsDiffer:bsDiffer; timeDiff = (gpsDiffer>bsDiffer)?bsDiffer:gpsDiffer;
} }
return timeDiff>differBase ? Constants.Verification.SN_INVALID: Constants.Verification.SN_VALID; return timeDiff>differBase ? Constants.Verification.SN_INVALID: Constants.Verification.SN_VALID;
} }
...@@ -50,7 +51,7 @@ public class DeviceLocationUtil { ...@@ -50,7 +51,7 @@ public class DeviceLocationUtil {
if (StringUtils.isBlank(addressItem.getGpsTime())) { if (StringUtils.isBlank(addressItem.getGpsTime())) {
return Constants.DeviceOnline.OFFLINE; return Constants.DeviceOnline.OFFLINE;
} }
int currentSource = (source==null)?Constants.DeviceSource.WIRED:Constants.DeviceSource.WIRELESS; int currentSource = (source==null)?Constants.DeviceSource.WIRELESS:source;
int speed = StringUtils.isEmpty(speedValue)?0:Integer.parseInt(speedValue); int speed = StringUtils.isEmpty(speedValue)?0:Integer.parseInt(speedValue);
Date gpsDate = DateUtils.toDate(addressItem.getGpsTime(), DateUtils.pattern19); Date gpsDate = DateUtils.toDate(addressItem.getGpsTime(), DateUtils.pattern19);
...@@ -85,13 +86,13 @@ public class DeviceLocationUtil { ...@@ -85,13 +86,13 @@ public class DeviceLocationUtil {
*/ */
private static int commonResolutionOnline(long now, long rtTrckTime, int speed, int currentSource) { private static int commonResolutionOnline(long now, long rtTrckTime, int speed, int currentSource) {
int status = Constants.DeviceOnline.DRIVING; int status = Constants.DeviceOnline.DRIVING;
if (now - rtTrckTime > 3 * 24 * 60 * 60 * 1000) { if (now - rtTrckTime > Constants.DeviceOnline.TIME_TWENTY_HOURS) {
status = Constants.DeviceOnline.OFFLINE; status = Constants.DeviceOnline.OFFLINE;
} else { } else {
if (currentSource== Constants.DeviceSource.WIRELESS) { if (currentSource== Constants.DeviceSource.WIRELESS) {
status = Constants.DeviceOnline.ONLINE; status = Constants.DeviceOnline.ONLINE;
} else { } else {
if (now - rtTrckTime > 6 * 60 * 1000) { if (now - rtTrckTime > Constants.DeviceOnline.TIME_SIX_MINITES) {
//大于6分钟 有源在线 //大于6分钟 有源在线
status = Constants.DeviceOnline.ONLINE; status = Constants.DeviceOnline.ONLINE;
} else { } else {
......
package cn.com.glsx.stdinterface.modules.controller;
import cn.com.glsx.Application;
import cn.com.glsx.stdinterface.modules.api.WorkOrderApiController;
import cn.com.glsx.stdinterface.modules.model.CommonApiRequest;
import cn.com.glsx.stdinterface.modules.util.Sm4EncryptUtils;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WorkOrderApiControllerTest {
@Autowired
private WorkOrderApiController workOrderApiController;
@Test
public void test() {
String company = "zlgj";
Map<String, String> finalParamsMap = Maps.newHashMap();
String workOrderNo = "ZL2022022200002";
String standno = "LGBF5AE08FR305952";
finalParamsMap.put("bizWorkOrderNo", workOrderNo);
finalParamsMap.put("vin", standno);
finalParamsMap.put("xVeriTime", null);
finalParamsMap.put("yVeriTime", null);
String originData = JSONUtil.toJsonStr(finalParamsMap);
log.info("同步安装工单到新e盾工单原始参数 {}", originData);
String encryptData = Sm4EncryptUtils.encryptCbc("E76F7D9A27F63E6BA5F4282D81BA9E50", originData);
CommonApiRequest commonApiRequest = new CommonApiRequest();
commonApiRequest.setTimestamp(System.currentTimeMillis());
commonApiRequest.setOrganization(company);
commonApiRequest.setData(encryptData);
commonApiRequest.setDataType(1);
log.info("同步安装工单到新e盾工单参数 {}", commonApiRequest);
R rResult = workOrderApiController.addrVerify(commonApiRequest);
System.out.println("===" + JSONObject.toJSONString(rResult.getData()));
}
}
...@@ -2,6 +2,8 @@ package cn.com.glsx.stdinterface.modules.service; ...@@ -2,6 +2,8 @@ package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.Application; import cn.com.glsx.Application;
import cn.com.glsx.notify.dto.MailTemplateMessageDTO; import cn.com.glsx.notify.dto.MailTemplateMessageDTO;
import cn.com.glsx.stdinterface.dto.WorkOrderAddrVerifyBO;
import cn.com.glsx.stdinterface.dto.WorkOrderAddrVerifyDTO;
import cn.com.glsx.stdinterface.modules.entity.Vehicle; import cn.com.glsx.stdinterface.modules.entity.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.WorkOrder; import cn.com.glsx.stdinterface.modules.entity.WorkOrder;
import cn.com.glsx.stdinterface.modules.entity.WorkOrderDocs; import cn.com.glsx.stdinterface.modules.entity.WorkOrderDocs;
...@@ -11,6 +13,7 @@ import cn.com.glsx.stdinterface.modules.model.WorkOrderInfoBO; ...@@ -11,6 +13,7 @@ import cn.com.glsx.stdinterface.modules.model.WorkOrderInfoBO;
import cn.com.glsx.stdinterface.modules.remote.NotifyCenterService; import cn.com.glsx.stdinterface.modules.remote.NotifyCenterService;
import cn.com.glsx.stdinterface.modules.util.Sm4EncryptUtils; import cn.com.glsx.stdinterface.modules.util.Sm4EncryptUtils;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
...@@ -115,4 +118,14 @@ public class WorkOrderServiceTest { ...@@ -115,4 +118,14 @@ public class WorkOrderServiceTest {
workOrderDocsMapper.insertList(workOrderDocList); workOrderDocsMapper.insertList(workOrderDocList);
} }
@Test
public void testVerificationDevice() {
WorkOrderAddrVerifyBO verifyBO = new WorkOrderAddrVerifyBO();
verifyBO.setOrderSource("zlgj");
verifyBO.setBizWorkOrderNo("ZL1111111763");
verifyBO.setVin("LGBF5AE08FR305123");
boolean isApiCall = true;
WorkOrderAddrVerifyDTO workOrderAddrVerifyDTO = workOrderService.addrVerify(verifyBO, isApiCall);
System.out.println("==" + JSONObject.toJSONString(workOrderAddrVerifyDTO));
}
} }
package cn.com.glsx.stdinterface.modules.util;
import cn.com.glsx.stdinterface.common.constants.Constants;
import cn.com.glsx.stdinterface.dto.WorkOrderDeviceAddressItem;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.Date;
public class TestDeviceLocationOfflineUtil {
private WorkOrderDeviceAddressItem instanceAddressItem(String gpsTime, String bsTime) {
WorkOrderDeviceAddressItem workOrderDeviceAddressItem = new WorkOrderDeviceAddressItem();
workOrderDeviceAddressItem.setGpsTime(gpsTime);
workOrderDeviceAddressItem.setBsTime(bsTime);
return workOrderDeviceAddressItem;
}
@Test
public void testDeviceType01() {
// 无效位置数据状态验证:离线
String gpsTime = "";
String bsTime = "";
Integer source = null;
WorkOrderDeviceAddressItem addressItem = instanceAddressItem(gpsTime, bsTime);
String speed = "30";
Integer onlineStatus = DeviceLocationUtil.resolutionDeviceOnlineStatus(addressItem, source, speed);
Assert.assertSame(onlineStatus, Constants.DeviceOnline.OFFLINE);
}
@Test
public void testDeviceType02() {
// 无效位置数据状态验证;不存在的设备类型source 离线
String gpsTime = "";
String bsTime = "";
Integer source = 2;
WorkOrderDeviceAddressItem addressItem = instanceAddressItem(gpsTime, bsTime);
String speed = "30";
Integer onlineStatus = DeviceLocationUtil.resolutionDeviceOnlineStatus(addressItem, source, speed);
Assert.assertSame(onlineStatus, Constants.DeviceOnline.OFFLINE);
}
@Test
public void testDeviceType03() {
// 有线无线设备:三天离线 基站GPS都离线才认为离线
Date gpsDate = DateUtil.offsetHour(new Date(), -73);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = "";
Integer source = Constants.DeviceSource.WIRED;
WorkOrderDeviceAddressItem addressItem = instanceAddressItem(gpsTime, bsTime);
String speed = "30";
Integer onlineStatus = DeviceLocationUtil.resolutionDeviceOnlineStatus(addressItem, source, speed);
Assert.assertSame(onlineStatus, Constants.DeviceOnline.OFFLINE);
}
@Test
public void testDeviceType04() {
// 有线无线设备:三天离线 基站GPS都离线才认为离线
Date gpsDate = DateUtil.offsetHour(new Date(), -73);
Date bsDate = DateUtil.offsetHour(new Date(), -73);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
Integer source = Constants.DeviceSource.WIRED;
WorkOrderDeviceAddressItem addressItem = instanceAddressItem(gpsTime, bsTime);
String speed = "30";
Integer onlineStatus = DeviceLocationUtil.resolutionDeviceOnlineStatus(addressItem, source, speed);
Assert.assertSame(onlineStatus, Constants.DeviceOnline.OFFLINE);
}
@Test
public void testDeviceType05() {
// 有线无线设备:三天离线 基站GPS都离线才认为离线
Date gpsDate = DateUtil.offsetHour(new Date(), -25);
Date bsDate = DateUtil.offsetHour(new Date(), -75);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
Integer source = Constants.DeviceSource.WIRED;
WorkOrderDeviceAddressItem addressItem = instanceAddressItem(gpsTime, bsTime);
String speed = "30";
Integer onlineStatus = DeviceLocationUtil.resolutionDeviceOnlineStatus(addressItem, source, speed);
Assert.assertSame(onlineStatus, Constants.DeviceOnline.ONLINE);
}
@Test
public void testDeviceType06() {
// 有线无线设备:三天离线 基站GPS都离线才认为离线 行驶状态测试
Date gpsDate = DateUtil.offsetMinute(new Date(), -5);
Date bsDate = DateUtil.offsetHour(new Date(), -75);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
Integer source = Constants.DeviceSource.WIRED;
WorkOrderDeviceAddressItem addressItem = instanceAddressItem(gpsTime, bsTime);
String speed = "30";
Integer onlineStatus = DeviceLocationUtil.resolutionDeviceOnlineStatus(addressItem, source, speed);
Assert.assertSame(onlineStatus, Constants.DeviceOnline.DRIVING);
}
@Test
public void testDeviceType07() {
// 有线无线设备:三天离线 基站GPS都离线才认为离线 行驶状态测试
Date gpsDate = DateUtil.offsetMinute(new Date(), -5);
Date bsDate = DateUtil.offsetHour(new Date(), -75);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
Integer source = Constants.DeviceSource.WIRED;
WorkOrderDeviceAddressItem addressItem = instanceAddressItem(gpsTime, bsTime);
String speed = "0";
Integer onlineStatus = DeviceLocationUtil.resolutionDeviceOnlineStatus(addressItem, source, speed);
Assert.assertSame(onlineStatus, Constants.DeviceOnline.STANDSTILL);
}
}
package cn.com.glsx.stdinterface.modules.util;
import cn.com.glsx.stdinterface.common.constants.Constants;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.Date;
public class TestDeviceLocationUtil {
@Test
public void testDeviceType01() {
// 无效位置数据状态验证
String gpsTime = "";
String bsTime = "";
Integer source = null;
Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
}
@Test
public void testDeviceType02() {
// 无效位置数据状态验证;不存在的设备类型source
String gpsTime = "";
String bsTime = "";
Integer source = 2;
Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
}
@Test
public void testDeviceType03() {
// 有线设备:无效位置数据状态验证,4小时内上报的数据为有效
Date gpsDate = DateUtil.offsetHour(new Date(), -4);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = "";
Integer source = Constants.DeviceSource.WIRED;
Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
}
@Test
public void testDeviceType04() {
// 有线设备:无效位置数据状态验证,4小时内上报的数据为有效
// 有线设备只做GPS数据的验证
Date gpsDate = DateUtil.offsetHour(new Date(), -5);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = "2022-02-23 09:16:17";
Integer source = Constants.DeviceSource.WIRED;
Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
}
@Test
public void testDeviceType05() {
// 有线设备:有效位置数据状态验证,4小时内上报的数据为有效
// 有线设备只做GPS数据的验证
Date gpsDate = DateUtil.offsetHour(new Date(), -3);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = "2022-02-23 09:16:17";
Integer source = Constants.DeviceSource.WIRED;
Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
Assert.assertSame(deviceType, Constants.Verification.SN_VALID);
}
@Test
public void testDeviceType06() {
// 无线设备:无效位置数据状态验证,24小时内上报的数据为有效
// 无线设备GPS和基站数据取最新的数据
Date gpsDate = DateUtil.offsetHour(new Date(), -25);
Date bsDate = DateUtil.offsetHour(new Date(), -25);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
Integer source = Constants.DeviceSource.WIRELESS;
Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
}
@Test
public void testDeviceType07() {
// 无线设备:有效位置数据状态验证,24小时内上报的数据为有效
// 无线设备GPS和基站数据取最新的数据
Date gpsDate = DateUtil.offsetHour(new Date(), -25);
Date bsDate = DateUtil.offsetHour(new Date(), -5);
String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
Integer source = Constants.DeviceSource.WIRELESS;
Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
Assert.assertSame(deviceType, Constants.Verification.SN_VALID);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!