Commit 882b8856 by fz

1.添加ice的getLatesGpsBsRecords服务接口

2.优化集合处理代码
1 parent d0b095bc
Showing 39 changed files with 1170 additions and 276 deletions
package com.glsx.base.aop;
import com.glsx.exception.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.CodeSignature;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
@Aspect
@Slf4j
......@@ -34,7 +31,7 @@ public class LogAspect {
* @date 2020年12月22日
*/
@Around("methodAspect()")
public Object doAround(ProceedingJoinPoint point) throws Throwable {
public Object doAround(ProceedingJoinPoint point) {
//获取类名
String className = point.getTarget().getClass().getName();
......@@ -42,21 +39,33 @@ public class LogAspect {
MethodSignature signature = (MethodSignature) point.getSignature();
String methodName = signature.getMethod().getName();
//访问目标方法的参数:
Map<String, Object> params = new HashMap<>();
Object[] paramValues = point.getArgs();
String[] paramNames = ((CodeSignature)point.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) {
params.put(paramNames[i], paramValues[i]);
}
//访问目标方法的参数名和参数值
Object[] paramVals = point.getArgs();
//todo 打印接口的入参
/*//stream转为List
String[] paramNames = ((CodeSignature) point.getSignature()).getParameterNames();
List<Object> listValues = Arrays.stream(paramVals).collect(Collectors.toList());
List<String> listNames = Arrays.stream(paramNames).collect(Collectors.toList());
//将2个分为为key,value的list转为map,打印参数对象
Map<String, Object> params = MapUtils.listToMap(listNames, listValues);*/
log.info(className+"===调用"+methodName+"开始===" + params);
log.info(className + "===调用" + methodName + "开始===");
//用改变后的参数执行目标方法
Object returnValue = point.proceed(paramValues);
Object returnValue = null;
try {
returnValue = point.proceed(paramVals);
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new ApiException(className+"调用"+methodName+"失败,message:"+throwable.getMessage());
}
log.info(className+"==="+methodName+"返回===" + returnValue);
log.info(className + "===" + methodName + "返回===" + returnValue);
return returnValue;
}
}
......@@ -14,4 +14,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD) // 方法注解
@Retention(RetentionPolicy.RUNTIME) // 运行时可见
public @interface SysLog {
// String name();
}
package com.glsx.base.controller;
import com.glsx.model.BO.DeviceStatusBo;
import com.glsx.model.BO.DeviceStayBo;
import com.glsx.model.BO.GpsBsRecordsBo;
import com.glsx.model.BaseMapModel;
import com.glsx.model.Basemodel;
import com.glsx.utils.JwtUtil;
import com.glsx.service.CommonParam;
import com.glsx.utils.SystemProperty;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -22,8 +17,6 @@ public class BaseService {
@Autowired
private SystemProperty systemProperty;
@Autowired
private JwtUtil jwtUtil;
/*
* 获取配置中心属性
......@@ -50,48 +43,17 @@ public class BaseService {
/*
* jwt方法
*/
private Claims getCustomerFromToken(Basemodel basemodel){
return jwtUtil.getClaimsFromToken(basemodel.getToken());
}
public String getCustomerStrProperty(Basemodel basemodel,String propertyName){
return (String) getCustomerFromToken(basemodel).get(propertyName);
}
public Integer getCustomerIntProperty(Basemodel basemodel,String propertyName){
return (Integer) getCustomerFromToken(basemodel).get(propertyName);
}
public Integer getCustomerID(Basemodel basemodel){
return (getCustomerIntProperty(basemodel,"appid"));
}
/*
* 公共参数相关方法
*/
public Long getSn(DeviceStatusBo deviceStatusBo){
return Long.parseLong(deviceStatusBo.getSn());
}
public Long getSn(GpsBsRecordsBo gpsBsRecordsBo){
return Long.parseLong(gpsBsRecordsBo.getSn());
}
public Integer getDeviceType(DeviceStatusBo deviceStatusBo){
return deviceStatusBo.getDevice_type();
}
public Integer getDeviceType(GpsBsRecordsBo gpsBsRecordsBo){
return gpsBsRecordsBo.getDevice_type();
public Long getSn(CommonParam commonParam){
return Long.parseLong(commonParam.getLongSn());
}
public Integer getDeviceType(DeviceStayBo deviceStayBo){
return deviceStayBo.getDevice_type();
public Integer getDeviceType(CommonParam commonParam){
return commonParam.getIntDeviceType();
}
public float getLat(BaseMapModel mapModel){
public Float getLat(BaseMapModel mapModel){
return mapModel.getLat().floatValue();
}
......
package com.glsx.base.controller;
import com.glsx.model.Basemodel;
import com.glsx.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
public class JwtService extends BaseService{
@Autowired
protected JwtUtil jwtUtil;
/*
* jwt方法
*/
private Claims getCustomerFromToken(Basemodel basemodel){
return jwtUtil.getClaimsFromToken(basemodel.getToken());
}
public String getCustomerStrProperty(Basemodel basemodel,String propertyName){
return (String) getCustomerFromToken(basemodel).get(propertyName);
}
public Integer getCustomerIntProperty(Basemodel basemodel,String propertyName){
return (Integer) getCustomerFromToken(basemodel).get(propertyName);
}
public Integer getCustomerID(Basemodel basemodel){
return (getCustomerIntProperty(basemodel,"appid"));
}
}
......@@ -6,22 +6,38 @@ package com.glsx.constant;
* @version V1.0
*/
public class OpenAPIConstant {
public static final String TEST_PRIVATE_KEY = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAqx/pXk7cbNk8ZDLs9nYE/6ohPqjefpsTvjJCHyVlUIYH+bhg1hG6SwZ9C5dJBWNplku0jcEZ5lq5SJboVXRYOQIDAQABAkA8S7460KayY8j3tUnxfZw9SYD1RyM+kP3f4m2R8+dC+6IS3qVis3zeowZjhliJOB7tipNSG/TClf2919PLysgBAiEA8Q44UuszieMaIm15MJNBQTQDvZleHXVNA5fPA5OL/MECIQC1u9Jxf/0DX3RkH5hO0Ryc8mI0/BxQUB6Z7s0bqPUheQIgKJTFRKhV99uktbEKWvQfYzO3gX7FSl5KBdXTwv1e7sECIQCENqvolQO+s3Ba8z18gde+OvzFrXDv4QoSVVB1QhtsiQIhAKL54pZ3s1ViBA4lUcRxuRZ4hrvSbwn09ozvIwM3aqFn";
public static final String TEST_TOKEN = "yRaUk3pOtRxYLH2nNoNBXSEC4zvPicu2d6gAOh+NLXl7TIiR8kDL/aMJQcjN4LDqLAnBosahygnRro6ZCoR7KXoE0bmJ+5Ozhv3Hz+vvzUyGEjGmorIVXIlS/KkZWAwIguFYhXXSDLHwxfZZHMQxTtARAv3hpf7nM++YeGCnNUQ=";
public static final String TEST_PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKsf6V5O3GzZPGQy7PZ2BP+qIT6o3n6bE74yQh8lZVCGB/m4YNYRuksGfQuXSQVjaZZLtI3BGeZauUiW6FV0WDkCAwEAAQ==";
public static final String TEST_PRIVATE_KEY = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAj7MKbIEiAK2wOIrEhvJtYZDi3wLy4qUxMbbTd8L64R7JI/+U+zFo5Pg1VNQpObEnc74fhppSSvrVzHo3sHx5rQIDAQABAkBlCF7l1w0PKQ9jUb3Hm59oH7RDVBFtZPPnnkGkTISTzj2AQmssY0DPlcOVfz/4vRxUMWPWuLSATmqUGi2LxLKBAiEA5KO7GYrdrA5ixkd7VvmkvObCtiO0R9InDsMSdiIyFNECIQCg5TSmvHYcOgHPTguN4XA5ySn9xRmO/ozY5rug2s2+HQIgJq7M6PVlq8aDT6ioZX63MH6aUtaXmc8kbIr0hKgkcQECIDGlR8/DCza+d1x+GnaW/0f1WG2jabWDufYbi/2gRifJAiAmtkTizcgcdvPc8BUZeKlWRnBR0dFATzfw9V91GJFkkQ==";
//public static final String TEST_TOKEN = "hlnE2oQB3oTG1adSEVzvxk5ZotIQcNV5niSmQbxzNGYhKeVpXS2Sk6VsuSiqE/MJwwBgSH7CJht2ohvvoMOLGQ==";
public static final String TEST_PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAI+zCmyBIgCtsDiKxIbybWGQ4t8C8uKlMTG203fC+uEeySP/lPsxaOT4NVTUKTmxJ3O+H4aaUkr61cx6N7B8ea0CAwEAAQ==";
/**
* 拦截器中,过期时间格式展示
*/
public static final String TIME_FROMAT_NORMAL = "yyyy-MM-dd HH:mm:ss";
/**
* 签名参数名
*/
public static final String PARAM_SIGN = "sign";
/**
* 配置中心的dubbo服务提供者
*/
public static final String DUBBO_SERVICE_URL = "openapi.dubbo.service.url";
/**
* 缺少必填参数
* 围栏,碰撞接口相关
*/
public final static String PARAM_IS_REQUIRED = "4000";
public static final String HTTP_OPENAPI_SERVER = "openapi.http.server";
public static final String HTTP_TIME_OUT = "openapi.http.timeout";
public static final String HTTP_OPENAPI_SERVER_1 = "openapi.http.server1";
public static final String METHOD_FENCE_RECORD = "openapi.fencereecords.name";
public static final String METHOD_RESCUE_RECORD = "openapi.rescuerecords.name";
public static final String HTTP_TIME_OUT = "openapi.http.timeout";
/**
* 设备状态,下发指令接口相关
*/
public static final String HTTP_OPENAPI_SERVER_2 = "openapi.http.server2";
public static final String METHOD_DEVICE_STATUS = "openapi.devicestatus.name";
public static final String METHOD_POST_COMMANDS = "openapi.postcommands.name";
}
......@@ -4,6 +4,7 @@ import com.glsx.model.BO.*;
import com.glsx.model.BaseMapModel;
import com.glsx.model.DTO.*;
import com.glsx.model.Result;
import com.glsx.service.IOpenApiHTTPService;
import com.glsx.service.IOpenApiICEService;
import com.glsx.service.IOpenApiService;
import lombok.extern.slf4j.Slf4j;
......@@ -26,7 +27,7 @@ import java.util.Map;
@Slf4j
public class OpenApiController {
/*
* 开放平台接口
* 开放平台接口(本服务实现)
*/
@Autowired
IOpenApiService openApiService;
......@@ -36,6 +37,12 @@ public class OpenApiController {
*/
@Autowired
IOpenApiICEService openApiICEService;
/*
* http协议的接口
*/
@Autowired
IOpenApiHTTPService openApiHTTPService;
/*
* =================================openApiService=====================================
*/
......@@ -82,24 +89,6 @@ public class OpenApiController {
*/
/*
* 下发指令
*/
@PostMapping("postCommands")
public Result postCommands(@Valid @RequestBody CommandsBo commandsBo){
openApiICEService.postCommands(commandsBo);
return Result.ok();
}
/*
* 查询设备状态
*/
@PostMapping("deviceStatus")
public Result getDeviceStatus(@Valid @RequestBody DeviceStatusBo deviceStatusBo){
Map<String,Integer> map = openApiICEService.getDeviceStatus(deviceStatusBo);
return Result.ok().data(map);
}
/*
* 查询最新位置点
*/
@PostMapping("latestGpsRecord")
......@@ -270,12 +259,17 @@ public class OpenApiController {
return Result.ok().data(map);
}
/*
* =================================Http协议接口=====================================
*/
/*
* 根据某段时间围栏触发记录
*/
@PostMapping("fenceTriggerRecords")
public String getFenceTriggerRecords(@Valid @RequestBody DeviceDateBo deviceDateBo){
return openApiICEService.getFenceTriggerRecords(deviceDateBo);
return openApiHTTPService.getFenceTriggerRecords(deviceDateBo);
}
/*
......@@ -283,7 +277,25 @@ public class OpenApiController {
*/
@PostMapping("rescueEventRecords")
public String getRescueEventRecords(@Valid @RequestBody DeviceSdeviceDateBo deviceDateBo){
return openApiICEService.getRescueEventRecords(deviceDateBo);
return openApiHTTPService.getRescueEventRecords(deviceDateBo);
}
/*
* 下发指令
*/
@PostMapping("commands")
public Result postCommands(@Valid @RequestBody CommandsBo commandsBo){
openApiHTTPService.postCommands(commandsBo);
return Result.ok();
}
/*
* 查询设备状态
*/
@PostMapping("deviceStatus")
public Result getDeviceStatus(@Valid @RequestBody DeviceStatusBo deviceStatusBo){
Map<String,Integer> map = openApiHTTPService.getDeviceStatus(deviceStatusBo);
return Result.ok().data(map);
}
}
package com.glsx.exception;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.glsx.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.FieldError;
......@@ -8,13 +9,13 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Description: 全局异常处理
* @author fengzhi
* @version V1.0
* @Description: 全局异常处理
*/
@Slf4j
@RestControllerAdvice
......@@ -35,10 +36,28 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
public Result handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
List<String> errs = new ArrayList<>();
for (FieldError error : e.getBindingResult().getFieldErrors()) {
errs.add(error.getDefaultMessage());
}
//遍历参数异常的提示信息拼接返回
List<String> errs = e.getBindingResult()
.getFieldErrors()
.stream()
.map(FieldError::getDefaultMessage)
.collect(Collectors.toList());
return ApiErrorMessage.ARGS_NULL.exception(errs).getResultEntity();
}
/**
* 业务异常处理
*
* @param req
* @param e
* @return
*/
@ExceptionHandler(value = InvalidFormatException.class)
public Result InvalidFormatHandler(HttpServletRequest req, Exception e) {
String errMsg = "jackson反序列化失败:" + e.getMessage();
log.error(errMsg);
return new ApiException(errMsg).getResultEntity();
}
}
// **********************************************************************
//
// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//
// Ice version 3.5.1
//
// <auto-generated>
//
// Generated from file `HDao_gps.ice'
//
// Warning: do not edit this file.
//
// </auto-generated>
//
package com.glsx.ice.HDaoGps;
public abstract class Callback_DaoGpsService_getLatestGpsBsRecord extends Ice.TwowayCallback
{
public abstract void response(boolean __ret, LatestGpsBsReponse res);
public final void __completed(Ice.AsyncResult __result)
{
DaoGpsServicePrx __proxy = (DaoGpsServicePrx)__result.getProxy();
boolean __ret = false;
LatestGpsBsReponseHolder res = new LatestGpsBsReponseHolder();
try
{
__ret = __proxy.end_getLatestGpsBsRecord(res, __result);
}
catch(Ice.LocalException __ex)
{
exception(__ex);
return;
}
response(__ret, res.value);
}
}
......@@ -22,6 +22,24 @@ package com.glsx.ice.HDaoGps;
public interface DaoGpsServicePrx extends Ice.ObjectPrx
{
public boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res);
public boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res, java.util.Map<String, String> __ctx);
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req);
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, java.util.Map<String, String> __ctx);
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, Ice.Callback __cb);
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, java.util.Map<String, String> __ctx, Ice.Callback __cb);
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, Callback_DaoGpsService_getLatestGpsBsRecord __cb);
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, java.util.Map<String, String> __ctx, Callback_DaoGpsService_getLatestGpsBsRecord __cb);
public boolean end_getLatestGpsBsRecord(LatestGpsBsReponseHolder res, Ice.AsyncResult __result);
public boolean getBsRecords(BsGetRequest req, BsGetResponseHolder res);
public boolean getBsRecords(BsGetRequest req, BsGetResponseHolder res, java.util.Map<String, String> __ctx);
......
......@@ -2334,6 +2334,142 @@ public final class DaoGpsServicePrxHelper extends Ice.ObjectPrxHelperBase implem
}
}
private static final String __getLatestGpsBsRecord_name = "getLatestGpsBsRecord";
public boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res)
{
return getLatestGpsBsRecord(req, res, null, false);
}
public boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res, java.util.Map<String, String> __ctx)
{
return getLatestGpsBsRecord(req, res, __ctx, true);
}
private boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res, java.util.Map<String, String> __ctx, boolean __explicitCtx)
{
if(__explicitCtx && __ctx == null)
{
__ctx = _emptyContext;
}
final Ice.Instrumentation.InvocationObserver __observer = IceInternal.ObserverHelper.get(this, "getLatestGpsBsRecord", __ctx);
int __cnt = 0;
try
{
while(true)
{
Ice._ObjectDel __delBase = null;
try
{
__checkTwowayOnly("getLatestGpsBsRecord");
__delBase = __getDelegate(false);
_DaoGpsServiceDel __del = (_DaoGpsServiceDel)__delBase;
return __del.getLatestGpsBsRecord(req, res, __ctx, __observer);
}
catch(IceInternal.LocalExceptionWrapper __ex)
{
__handleExceptionWrapper(__delBase, __ex, __observer);
}
catch(Ice.LocalException __ex)
{
__cnt = __handleException(__delBase, __ex, null, __cnt, __observer);
}
}
}
finally
{
if(__observer != null)
{
__observer.detach();
}
}
}
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req)
{
return begin_getLatestGpsBsRecord(req, null, false, null);
}
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, java.util.Map<String, String> __ctx)
{
return begin_getLatestGpsBsRecord(req, __ctx, true, null);
}
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, Ice.Callback __cb)
{
return begin_getLatestGpsBsRecord(req, null, false, __cb);
}
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, java.util.Map<String, String> __ctx, Ice.Callback __cb)
{
return begin_getLatestGpsBsRecord(req, __ctx, true, __cb);
}
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, Callback_DaoGpsService_getLatestGpsBsRecord __cb)
{
return begin_getLatestGpsBsRecord(req, null, false, __cb);
}
public Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, java.util.Map<String, String> __ctx, Callback_DaoGpsService_getLatestGpsBsRecord __cb)
{
return begin_getLatestGpsBsRecord(req, __ctx, true, __cb);
}
private Ice.AsyncResult begin_getLatestGpsBsRecord(LatestGpsGetRequest req, java.util.Map<String, String> __ctx, boolean __explicitCtx, IceInternal.CallbackBase __cb)
{
__checkAsyncTwowayOnly(__getLatestGpsBsRecord_name);
IceInternal.OutgoingAsync __result = new IceInternal.OutgoingAsync(this, __getLatestGpsBsRecord_name, __cb);
try
{
__result.__prepare(__getLatestGpsBsRecord_name, Ice.OperationMode.Normal, __ctx, __explicitCtx);
IceInternal.BasicStream __os = __result.__startWriteParams(Ice.FormatType.DefaultFormat);
req.__write(__os);
__result.__endWriteParams();
__result.__send(true);
}
catch(Ice.LocalException __ex)
{
__result.__exceptionAsync(__ex);
}
return __result;
}
public boolean end_getLatestGpsBsRecord(LatestGpsBsReponseHolder res, Ice.AsyncResult __result)
{
Ice.AsyncResult.__check(__result, this, __getLatestGpsBsRecord_name);
boolean __ok = __result.__wait();
try
{
if(!__ok)
{
try
{
__result.__throwUserException();
}
catch(Ice.UserException __ex)
{
throw new Ice.UnknownUserException(__ex.ice_name(), __ex);
}
}
IceInternal.BasicStream __is = __result.__startReadParams();
res.value = new LatestGpsBsReponse();
res.value.__read(__is);
boolean __ret;
__ret = __is.readBool();
__result.__endReadParams();
return __ret;
}
catch(Ice.LocalException ex)
{
Ice.Instrumentation.InvocationObserver __obsv = __result.__getObserver();
if(__obsv != null)
{
__obsv.failed(ex.ice_name());
}
throw ex;
}
}
private static final String __getLatestGpsRecord_name = "getLatestGpsRecord";
public boolean getLatestGpsRecord(LatestGpsGetRequest req, LatestGpsGetResponseHolder res)
......
// **********************************************************************
//
// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//
// Ice version 3.5.1
//
// <auto-generated>
//
// Generated from file `HDao_gps.ice'
//
// Warning: do not edit this file.
//
// </auto-generated>
//
package com.glsx.ice.HDaoGps;
public class LatestGpsBsRecord implements Cloneable, java.io.Serializable
{
public GpsRecord recordgps;
public BsRecord recordbs;
public LatestGpsBsRecord()
{
}
public LatestGpsBsRecord(GpsRecord recordgps, BsRecord recordbs)
{
this.recordgps = recordgps;
this.recordbs = recordbs;
}
public boolean
equals(Object rhs)
{
if(this == rhs)
{
return true;
}
LatestGpsBsRecord _r = null;
if(rhs instanceof LatestGpsBsRecord)
{
_r = (LatestGpsBsRecord)rhs;
}
if(_r != null)
{
if(recordgps != _r.recordgps)
{
if(recordgps == null || _r.recordgps == null || !recordgps.equals(_r.recordgps))
{
return false;
}
}
if(recordbs != _r.recordbs)
{
if(recordbs == null || _r.recordbs == null || !recordbs.equals(_r.recordbs))
{
return false;
}
}
return true;
}
return false;
}
public int
hashCode()
{
int __h = 5381;
__h = IceInternal.HashUtil.hashAdd(__h, "::HDaoGps::LatestGpsBsRecord");
__h = IceInternal.HashUtil.hashAdd(__h, recordgps);
__h = IceInternal.HashUtil.hashAdd(__h, recordbs);
return __h;
}
public Object
clone()
{
Object o = null;
try
{
o = super.clone();
}
catch(CloneNotSupportedException ex)
{
assert false; // impossible
}
return o;
}
public void
__write(IceInternal.BasicStream __os)
{
recordgps.__write(__os);
recordbs.__write(__os);
}
public void
__read(IceInternal.BasicStream __is)
{
recordgps = new GpsRecord();
recordgps.__read(__is);
recordbs = new BsRecord();
recordbs.__read(__is);
}
public static final long serialVersionUID = 723492379L;
}
// **********************************************************************
//
// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//
// Ice version 3.5.1
//
// <auto-generated>
//
// Generated from file `HDao_gps.ice'
//
// Warning: do not edit this file.
//
// </auto-generated>
//
package com.glsx.ice.HDaoGps;
public final class LatestGpsBsRecordHolder
{
public
LatestGpsBsRecordHolder()
{
}
public
LatestGpsBsRecordHolder(LatestGpsBsRecord value)
{
this.value = value;
}
public LatestGpsBsRecord value;
}
// **********************************************************************
//
// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//
// Ice version 3.5.1
//
// <auto-generated>
//
// Generated from file `HDao_gps.ice'
//
// Warning: do not edit this file.
//
// </auto-generated>
//
package com.glsx.ice.HDaoGps;
public class LatestGpsBsReponse implements Cloneable, java.io.Serializable
{
public int oprGpsResult;
public int oprBsResult;
public LatestGpsBsRecord record;
public LatestGpsBsReponse()
{
}
public LatestGpsBsReponse(int oprGpsResult, int oprBsResult, LatestGpsBsRecord record)
{
this.oprGpsResult = oprGpsResult;
this.oprBsResult = oprBsResult;
this.record = record;
}
public boolean
equals(Object rhs)
{
if(this == rhs)
{
return true;
}
LatestGpsBsReponse _r = null;
if(rhs instanceof LatestGpsBsReponse)
{
_r = (LatestGpsBsReponse)rhs;
}
if(_r != null)
{
if(oprGpsResult != _r.oprGpsResult)
{
return false;
}
if(oprBsResult != _r.oprBsResult)
{
return false;
}
if(record != _r.record)
{
if(record == null || _r.record == null || !record.equals(_r.record))
{
return false;
}
}
return true;
}
return false;
}
public int
hashCode()
{
int __h = 5381;
__h = IceInternal.HashUtil.hashAdd(__h, "::HDaoGps::LatestGpsBsReponse");
__h = IceInternal.HashUtil.hashAdd(__h, oprGpsResult);
__h = IceInternal.HashUtil.hashAdd(__h, oprBsResult);
__h = IceInternal.HashUtil.hashAdd(__h, record);
return __h;
}
public Object
clone()
{
Object o = null;
try
{
o = super.clone();
}
catch(CloneNotSupportedException ex)
{
assert false; // impossible
}
return o;
}
public void
__write(IceInternal.BasicStream __os)
{
__os.writeInt(oprGpsResult);
__os.writeInt(oprBsResult);
record.__write(__os);
}
public void
__read(IceInternal.BasicStream __is)
{
oprGpsResult = __is.readInt();
oprBsResult = __is.readInt();
record = new LatestGpsBsRecord();
record.__read(__is);
}
public static final long serialVersionUID = -2035334900L;
}
// **********************************************************************
//
// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//
// Ice version 3.5.1
//
// <auto-generated>
//
// Generated from file `HDao_gps.ice'
//
// Warning: do not edit this file.
//
// </auto-generated>
//
package com.glsx.ice.HDaoGps;
public final class LatestGpsBsReponseHolder
{
public
LatestGpsBsReponseHolder()
{
}
public
LatestGpsBsReponseHolder(LatestGpsBsReponse value)
{
this.value = value;
}
public LatestGpsBsReponse value;
}
......@@ -22,6 +22,9 @@ package com.glsx.ice.HDaoGps;
public interface _DaoGpsServiceDel extends Ice._ObjectDel
{
boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res, java.util.Map<String, String> __ctx, Ice.Instrumentation.InvocationObserver __obsv)
throws IceInternal.LocalExceptionWrapper;
boolean getBsRecords(BsGetRequest req, BsGetResponseHolder res, java.util.Map<String, String> __ctx, Ice.Instrumentation.InvocationObserver __obsv)
throws IceInternal.LocalExceptionWrapper;
......
......@@ -906,6 +906,58 @@ public final class _DaoGpsServiceDelD extends Ice._ObjectDelD implements _DaoGps
return __result.value;
}
public boolean getLatestGpsBsRecord(final LatestGpsGetRequest req, final LatestGpsBsReponseHolder res, java.util.Map<String, String> __ctx, Ice.Instrumentation.InvocationObserver __observer)
throws IceInternal.LocalExceptionWrapper
{
final Ice.Current __current = new Ice.Current();
__initCurrent(__current, "getLatestGpsBsRecord", Ice.OperationMode.Normal, __ctx);
final Ice.BooleanHolder __result = new Ice.BooleanHolder();
IceInternal.Direct __direct = null;
try
{
__direct = new IceInternal.Direct(__current)
{
public Ice.DispatchStatus run(Ice.Object __obj)
{
DaoGpsService __servant = null;
if(__obj == null || __obj instanceof DaoGpsService)
{
__servant = (DaoGpsService)__obj;
}
else
{
throw new Ice.OperationNotExistException(__current.id, __current.facet, __current.operation);
}
__result.value = __servant.getLatestGpsBsRecord(req, res, __current);
return Ice.DispatchStatus.DispatchOK;
}
};
try
{
Ice.DispatchStatus __status = __direct.getServant().__collocDispatch(__direct);
if(__status == Ice.DispatchStatus.DispatchUserException)
{
__direct.throwUserException();
}
assert __status == Ice.DispatchStatus.DispatchOK;
return __result.value;
}
finally
{
__direct.destroy();
}
}
catch(Ice.SystemException __ex)
{
throw __ex;
}
catch(Throwable __ex)
{
IceInternal.LocalExceptionWrapper.throwWrapper(__ex);
}
return __result.value;
}
public boolean getLatestGpsRecord(final LatestGpsGetRequest req, final LatestGpsGetResponseHolder res, java.util.Map<String, String> __ctx, Ice.Instrumentation.InvocationObserver __observer)
throws IceInternal.LocalExceptionWrapper
{
......
......@@ -873,6 +873,56 @@ public final class _DaoGpsServiceDelM extends Ice._ObjectDelM implements _DaoGps
}
public boolean
getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res, java.util.Map<String, String> __ctx, Ice.Instrumentation.InvocationObserver __observer)
throws IceInternal.LocalExceptionWrapper
{
IceInternal.Outgoing __og = __handler.getOutgoing("getLatestGpsBsRecord", Ice.OperationMode.Normal, __ctx, __observer);
try
{
try
{
IceInternal.BasicStream __os = __og.startWriteParams(Ice.FormatType.DefaultFormat);
req.__write(__os);
__og.endWriteParams();
}
catch(Ice.LocalException __ex)
{
__og.abort(__ex);
}
boolean __ok = __og.invoke();
try
{
if(!__ok)
{
try
{
__og.throwUserException();
}
catch(Ice.UserException __ex)
{
throw new Ice.UnknownUserException(__ex.ice_name(), __ex);
}
}
IceInternal.BasicStream __is = __og.startReadParams();
res.value = new LatestGpsBsReponse();
res.value.__read(__is);
boolean __ret;
__ret = __is.readBool();
__og.endReadParams();
return __ret;
}
catch(Ice.LocalException __ex)
{
throw new IceInternal.LocalExceptionWrapper(__ex, false);
}
}
finally
{
__handler.reclaimOutgoing(__og);
}
}
public boolean
getLatestGpsRecord(LatestGpsGetRequest req, LatestGpsGetResponseHolder res, java.util.Map<String, String> __ctx, Ice.Instrumentation.InvocationObserver __observer)
throws IceInternal.LocalExceptionWrapper
{
......
......@@ -155,6 +155,11 @@ public abstract class _DaoGpsServiceDisp extends Ice.ObjectImpl implements DaoGp
return getLatestBsRecord(req, res, null);
}
public final boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res)
{
return getLatestGpsBsRecord(req, res, null);
}
public final boolean getLatestGpsRecord(LatestGpsGetRequest req, LatestGpsGetResponseHolder res)
{
return getLatestGpsRecord(req, res, null);
......@@ -225,6 +230,23 @@ public abstract class _DaoGpsServiceDisp extends Ice.ObjectImpl implements DaoGp
return getVoltageRecords(req, res, null);
}
public static Ice.DispatchStatus ___getLatestGpsBsRecord(DaoGpsService __obj, IceInternal.Incoming __inS, Ice.Current __current)
{
__checkMode(Ice.OperationMode.Normal, __current.mode);
IceInternal.BasicStream __is = __inS.startReadParams();
LatestGpsGetRequest req;
req = new LatestGpsGetRequest();
req.__read(__is);
__inS.endReadParams();
LatestGpsBsReponseHolder res = new LatestGpsBsReponseHolder();
boolean __ret = __obj.getLatestGpsBsRecord(req, res, __current);
IceInternal.BasicStream __os = __inS.__startWriteParams(Ice.FormatType.DefaultFormat);
res.value.__write(__os);
__os.writeBool(__ret);
__inS.__endWriteParams(true);
return Ice.DispatchStatus.DispatchOK;
}
public static Ice.DispatchStatus ___getBsRecords(DaoGpsService __obj, IceInternal.Incoming __inS, Ice.Current __current)
{
__checkMode(Ice.OperationMode.Normal, __current.mode);
......@@ -771,6 +793,7 @@ public abstract class _DaoGpsServiceDisp extends Ice.ObjectImpl implements DaoGp
"getGpsWorkModeRecords",
"getLatestBatteryRecord",
"getLatestBsRecord",
"getLatestGpsBsRecord",
"getLatestGpsRecord",
"getLatestGpsRecordByImei",
"getLatestGpsRecordByMapSn",
......@@ -871,74 +894,78 @@ public abstract class _DaoGpsServiceDisp extends Ice.ObjectImpl implements DaoGp
}
case 17:
{
return ___getLatestGpsRecord(this, in, __current);
return ___getLatestGpsBsRecord(this, in, __current);
}
case 18:
{
return ___getLatestGpsRecordByImei(this, in, __current);
return ___getLatestGpsRecord(this, in, __current);
}
case 19:
{
return ___getLatestGpsRecordByMapSn(this, in, __current);
return ___getLatestGpsRecordByImei(this, in, __current);
}
case 20:
{
return ___getLatestGpsTime(this, in, __current);
return ___getLatestGpsRecordByMapSn(this, in, __current);
}
case 21:
{
return ___getLatestLocationByLbsRecord(this, in, __current);
return ___getLatestGpsTime(this, in, __current);
}
case 22:
{
return ___getLatestRgpsRecord(this, in, __current);
return ___getLatestLocationByLbsRecord(this, in, __current);
}
case 23:
{
return ___getLatestVolRecord(this, in, __current);
return ___getLatestRgpsRecord(this, in, __current);
}
case 24:
{
return ___getMaxVolDiff(this, in, __current);
return ___getLatestVolRecord(this, in, __current);
}
case 25:
{
return ___getParadeCarAlarmRecords(this, in, __current);
return ___getMaxVolDiff(this, in, __current);
}
case 26:
{
return ___getParadeCarGpsRecords(this, in, __current);
return ___getParadeCarAlarmRecords(this, in, __current);
}
case 27:
{
return ___getRecentBsRecords(this, in, __current);
return ___getParadeCarGpsRecords(this, in, __current);
}
case 28:
{
return ___getRecentGpsRecords(this, in, __current);
return ___getRecentBsRecords(this, in, __current);
}
case 29:
{
return ___getSnMapRecords(this, in, __current);
return ___getRecentGpsRecords(this, in, __current);
}
case 30:
{
return ___getVoltageRecords(this, in, __current);
return ___getSnMapRecords(this, in, __current);
}
case 31:
{
return ___ice_id(this, in, __current);
return ___getVoltageRecords(this, in, __current);
}
case 32:
{
return ___ice_ids(this, in, __current);
return ___ice_id(this, in, __current);
}
case 33:
{
return ___ice_isA(this, in, __current);
return ___ice_ids(this, in, __current);
}
case 34:
{
return ___ice_isA(this, in, __current);
}
case 35:
{
return ___ice_ping(this, in, __current);
}
}
......
......@@ -22,6 +22,8 @@ package com.glsx.ice.HDaoGps;
public interface _DaoGpsServiceOperations
{
boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res, Ice.Current __current);
boolean getBsRecords(BsGetRequest req, BsGetResponseHolder res, Ice.Current __current);
boolean getLatestBsRecord(LatestBsGetRequest req, LatestBsGetResponseHolder res, Ice.Current __current);
......
......@@ -22,6 +22,8 @@ package com.glsx.ice.HDaoGps;
public interface _DaoGpsServiceOperationsNC
{
boolean getLatestGpsBsRecord(LatestGpsGetRequest req, LatestGpsBsReponseHolder res);
boolean getBsRecords(BsGetRequest req, BsGetResponseHolder res);
boolean getLatestBsRecord(LatestBsGetRequest req, LatestBsGetResponseHolder res);
......
......@@ -5,16 +5,12 @@ import com.glsx.model.DTO.*;
import com.glsx.utils.SystemProperty;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class IceHDaoGpsClient {
static String url = SystemProperty.getProperty("ice.traceUrl");
// static String url = "HDaoGpsSvc:default -h 192.168.3.153 -p 23479";
static Ice.Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(url).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
static DaoGpsServicePrx prx = DaoGpsServicePrxHelper.checkedCast(base);
......@@ -26,13 +22,11 @@ public class IceHDaoGpsClient {
throw new Exception("Invalid proxy");
}
// 第2个参数:2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
LatestRgpsGetRequest req = new LatestRgpsGetRequest(sn, deviceType, mapType);
LatestRgpsGetResponseHolder res = new LatestRgpsGetResponseHolder();
boolean ret = false;
ret = prx.getLatestRgpsRecord(req, res);
if (ret) {
log.info("===getLatestRGPSRecord:" + res.value.record);
if (ret && res != null && res.value.oprResult==0) {
gpsRecord = new LatestGpsRecordDto();
gpsRecord.setSn(sn + "");
gpsRecord.setGlng(res.value.record.gLng / 1000000D);
......@@ -87,36 +81,56 @@ public class IceHDaoGpsClient {
return bsRecord;
}
public static LatestGpsBsRecordDto getDevicesGpsInfo(long[] userIds, int extraMapReq, int seqNo) {
LatestGpsBsRecordDto bsRecord = null;
public static LatestGpsBsRecordDto getLatestGpsBsRecord(long userID, int apType, int extraMapReq) {
LatestGpsBsRecordDto gpsbsRecord = null;
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
// 第2个参数:2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
BatchGpsDevInfoResponseHolder res = new BatchGpsDevInfoResponseHolder();
LatestGpsBsReponseHolder res = new LatestGpsBsReponseHolder();
boolean ret = false;
BatchGpsDevInfoRequest req = new BatchGpsDevInfoRequest(userIds, extraMapReq, seqNo);
ret = prx.getDevicesGpsInfo(req, res);
LatestGpsGetRequest req = new LatestGpsGetRequest(userID,apType,extraMapReq);
ret = prx.getLatestGpsBsRecord(req, res);
if (ret) {
log.info("===getDevicesGpsInfo:" + res.value.gpsDevInfos);
GpsDevInfo[] gpsDevInfos = res.value.gpsDevInfos;
if (null != gpsDevInfos && gpsDevInfos.length > 0) {
GpsDevInfo gpsDevInfo = gpsDevInfos[0];
bsRecord = new LatestGpsBsRecordDto();
bsRecord.setGpstime(gpsDevInfo.record.gpsTime);
//bsRecord.setMcc(gpsDevInfo.record.);
//bsRecord.setMnc(gpsDevInfo.record.mnc);
int gpsCode = res.value.oprGpsResult;
int bsCode = res.value.oprBsResult;
log.info("===getLatestGpsBsRecord===gpsCode:" + gpsCode+"===bsCode:" + bsCode);
LatestGpsBsRecord record = res.value.record;
if(gpsCode !=0 && bsCode != 0)
return null;
gpsbsRecord = new LatestGpsBsRecordDto();
gpsbsRecord.setSn(userID+"");
//List<BsRecordDto> bsInfos = Arrays.stream(res.value.record.bsInfos).map(bsInfo -> {
// BsRecordDto bsRecordDto = new BsRecordDto();
// bsRecordDto.setCi(bsInfo.cellId);
// bsRecordDto.setLac(bsInfo.lac);
// bsRecordDto.setSignal(bsInfo.signal);
// return bsRecordDto;
//}).collect(Collectors.toList());
//bsRecord.setBsrecord(bsInfos);
if (gpsCode ==0) {
GpsRecord gr = record.recordgps;
gpsbsRecord.setGpstime(gr.gpsTime);
gpsbsRecord.setLng(gr.lng / 1000000D);
gpsbsRecord.setLat(gr.lat / 1000000D);
gpsbsRecord.setSpeed(gr.speed);
gpsbsRecord.setAlt(gr.alt);
gpsbsRecord.setDir(gr.dir);
gpsbsRecord.setGlng(gr.gLng / 1000000D);
gpsbsRecord.setGlat(gr.gLat / 1000000D);
gpsbsRecord.setBlng(gr.bLng / 1000000D);
gpsbsRecord.setBlat(gr.bLat / 1000000D);
}
if (bsCode ==0) {
BsRecord br = record.recordbs;
//gpsbsRecord.setBsvalid(br.);
gpsbsRecord.setMcc(br.mcc);
gpsbsRecord.setMnc(br.mnc);
List<BsInfoDto> bsrecord = Arrays.stream(br.bsInfos).map(bi->{
BsInfoDto bsInfoDto = new BsInfoDto();
bsInfoDto.setCi(bi.cellId);
bsInfoDto.setLac(bi.lac);
bsInfoDto.setSignal(bi.signal);
return bsInfoDto;
}).collect(Collectors.toList());
gpsbsRecord.setBsrecord(bsrecord);
}
}
} catch (Ice.LocalException e) {
......@@ -124,7 +138,7 @@ public class IceHDaoGpsClient {
} catch (Exception e) {
log.error("===getDevicesGpsInfo_EXCEP:" + e.getMessage(), e);
}
return bsRecord;
return gpsbsRecord;
}
/**
......@@ -212,11 +226,11 @@ public class IceHDaoGpsClient {
GpsGetResponseHolder res = new GpsGetResponseHolder(new GpsGetResponse());
GpsGetRequest req = new GpsGetRequest();
req.apType = apType;
req.reqCount = 1;
req.reqCount = 0;
req.userID = sn;
req.extraMapReq = mapType;
prx.getFirstGpsRecord(req, res);
log.info("getFirstGpsRecord====="+res.value.oprResult);
if (res != null && res.value != null && res.value.oprResult == 0) {
GpsRecord[] r = res.value.records;
int len = r.length;
......@@ -307,16 +321,20 @@ public class IceHDaoGpsClient {
req.type = ConvType.valueOf(maptype);
prx.convGeoGps(req,res);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
if (res != null) {
log.info("convGeoGps====="+res.value.oprResult);
if(res.value != null && res.value.oprResult == 0){
map = new HashMap<>();
ConvResponse r = res.value.gps;
map.put("lng",r.lng / 1000000D);
map.put("lat",r.lat / 1000000D);
map.put("lng",(r.lng / 1000000D));
map.put("lat",(r.lat / 1000000D));
return map;
}
}
} catch (Ice.LocalException e) {
log.error("===getRecentBsRecords_ICE_EXCEP:" + e.getMessage(), e);
log.error("===convGeoGps_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getRecentBsRecords_EXCEP:" + e.getMessage(), e);
log.error("===convGeoGps_EXCEP:" + e.getMessage(), e);
}
return null;
}
......
......@@ -8,12 +8,13 @@ import com.glsx.ice.POI.geocoding_resultHolder;
import com.glsx.utils.SystemProperty;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class IcePoiSearchFTRClient {
// ice接口服务器地址
private static String ICE_URL = SystemProperty.getProperty("ice.poisearchUrl");
private static String ICE_URL = SystemProperty.getProperty("ice.poiSearchFTRUrl");
static Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
static IPOISearchFTRPrx ipoiSearchFTRPrx = IPOISearchFTRPrxHelper.checkedCast(base);
......@@ -23,7 +24,7 @@ public class IcePoiSearchFTRClient {
*
* @return
*/
public static Map<String,Object> Geocoding(String address) {
public static Map<String, Object> Geocoding(String address) {
//请求和响应对象
geocoding_resultHolder res = new geocoding_resultHolder();
try {
......@@ -31,11 +32,12 @@ public class IcePoiSearchFTRClient {
log.error("mapGeoConvert ice添加服务异常 servicePre is null");
return null;
}
ipoiSearchFTRPrx.Geocoding(address,res);
ipoiSearchFTRPrx.Geocoding(address, res);
Map<String, Object> map = null;
if (res != null && res.value != null) {
geocoding_result val = res.value;
map = new HashMap<>();
//POI层级 0~7
map.put("level", val.level);
//可信度,分度越高越可信
......
......@@ -29,7 +29,7 @@ public class IceRtMileStatClient {
*
* @return
*/
public static Map<String, Object> getJourneyByGpsRecords(long sn, int dType, int beginTime, int endTime) {
public static Map<String, Object> getJourneyByGpsRecords(long sn, int dType, long beginTime, long endTime) {
try {
if (mileagePrx == null) {
throw new Exception("Invalid proxy");
......@@ -40,16 +40,18 @@ public class IceRtMileStatClient {
req.userID = sn;
req.apType = dType;
//开始时间
req.beginTime = beginTime;
req.beginTime = parseTimeMillis(beginTime);
//结束时间
req.endTime = endTime;
req.endTime = parseTimeMillis(endTime);
//返回最后GPS记录时间
req.bRetGpsTime = true;
mileagePrx.endUserMileStat(req, res);
Map<String, Object> map = null;
log.info("getJourneyByGpsRecords====="+res.value.oprResult);
if (res != null && res.value != null && res.value.oprResult == 0) {
MileStatEndResponse val = res.value;
map = new HashMap<>();
//设备号
map.put("sn", sn);
//行驶里程:单位(米)
......@@ -95,7 +97,7 @@ public class IceRtMileStatClient {
//开始日期
//req.bgnDate = bgnDate;
//结束日期
// req.endDate = endDate;
//req.endDate = endDate;
//0:原始坐标 1:转换高德和百度坐标 2:转换高德坐标 3:转换百度坐标
req.extraMapReq = MapTypeEnum.DOUBLE_TYPE.getId();
......@@ -109,9 +111,11 @@ public class IceRtMileStatClient {
req.endDate = eDate;
mileagePrx.getJourneyRecords(req, res);
log.info("getJourneyRecords====="+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
JourneyRecord[] vals = res.value.jourRecords;
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> journeyrecords = Arrays.stream(vals).map(jrecord -> {
......@@ -167,9 +171,12 @@ public class IceRtMileStatClient {
req.endDate = eDate;
mileagePrx.getDailyMileageRecords(req, res);
log.info("getDailyMileageRecords====="+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
DailyMileRecord[] vals = res.value.dailMileRecords;
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> dailyrecords = Arrays.stream(vals).map(drecord -> {
......@@ -209,9 +216,13 @@ public class IceRtMileStatClient {
//默认0,非0:获取日里程记录
//req.bReqDailyRecord
mileagePrx.getToatlMileage(req, res);
log.info("getTotalMileageRecords=====code:"+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
DailyMileRecord[] vals = res.value.dailMileRecords;
log.info("getTotalMileageRecords=====list:"+vals.length);
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> dailyrecords = Arrays.stream(vals).map(drecord -> {
......@@ -263,9 +274,13 @@ public class IceRtMileStatClient {
req.endMonth = em;
mileagePrx.getMonthResideRecords(req, res);
log.info("getMonthResideRecords=====code:"+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
MonthResideRecord[] vals = res.value.monResideRecords;
log.info("getMonthResideRecords=====list:"+vals.length);
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> monthRecords = Arrays.stream(vals).map(mrecord -> {
......@@ -321,7 +336,7 @@ public class IceRtMileStatClient {
req.minDuration = min_duration;
req.extraMapReq = MapTypeEnum.DOUBLE_TYPE.getId();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");//注意月份是MM
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
Calendar calendar = Calendar.getInstance();
calendar.setTime(simpleDateFormat.parse(start_date)); //放入Date类型数据
......@@ -333,9 +348,13 @@ public class IceRtMileStatClient {
req.endDate = em;
mileagePrx.getStayPointRecords(req, res);
log.info("getStayPointRecords=====code:"+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
StayPointRecord[] vals = res.value.stayPoints;
log.info("getStayPointRecords=====list:"+vals.length);
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> stayRecords = Arrays.stream(vals).map(srecord -> {
......@@ -390,4 +409,10 @@ public class IceRtMileStatClient {
map.put("addr", beginPos.addr);
return map;
}
public static Integer parseTimeMillis(long time) throws Exception{
String s = String.valueOf(time);
return Integer.parseInt(s.substring(0, s.length()-3));
}
}
......@@ -3,6 +3,7 @@ package com.glsx.intercepter;
import com.glsx.constant.OpenAPIConstant;
import com.glsx.exception.ApiErrorMessage;
import com.glsx.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -62,9 +63,12 @@ public class AuthIntercepter implements HandlerInterceptor {
throw ApiErrorMessage.TOKEN_TIME_OUT.exception();
}
Claims claims = jwtUtil.getClaimsFromToken(jwtToken);
//todo 缓存接口的启用状态,key为appid+接口名,val为是否启用
//提示过期时间
SimpleDateFormat sdf = new SimpleDateFormat(OpenAPIConstant.TIME_FROMAT_NORMAL);
String expirTime = sdf.format(jwtUtil.getExpiredDateFromToken(jwtToken));
String expirTime = sdf.format(claims.getExpiration());
log.info("token过期时间:"+expirTime);
//验证成功,放行
......
package com.glsx.model.BO;
import com.glsx.model.Basemodel;
import com.glsx.service.CommonParam;
import lombok.Data;
import lombok.ToString;
......@@ -10,7 +11,7 @@ import javax.validation.constraints.NotNull;
@Data
@ToString(callSuper = true)
public class DeviceStatusBo extends Basemodel {
public class DeviceStatusBo extends Basemodel implements CommonParam {
//设备号
@NotBlank(message = "设备号sn不能为空")
private String sn;
......@@ -18,6 +19,16 @@ public class DeviceStatusBo extends Basemodel {
@NotNull(message = "设备类型不能为空")
private Integer device_type;
@Override
public String getLongSn() {
return this.sn;
}
@Override
public Integer getIntDeviceType() {
return this.device_type;
}
//# STR_DEV_TYPE_CHEYOU_CHEJI "01" 车机
//# STR_DEV_TYPE_GLSX_OBD "02" OBD
//# STR_DEV_TYPE_GBOX "03"
......
package com.glsx.model.BO;
import com.glsx.model.BaseTimeRangeModel;
import com.glsx.service.CommonParam;
import lombok.Data;
import lombok.ToString;
......@@ -9,11 +10,21 @@ import javax.validation.constraints.NotNull;
@Data
@ToString(callSuper = true)
public class GpsBsRecordsBo extends BaseTimeRangeModel {
public class GpsBsRecordsBo extends BaseTimeRangeModel implements CommonParam {
//设备号
@NotBlank(message = "设备号sn不能为空")
private String sn;
//设备类型
@NotNull(message = "设备类型不能为空")
private Integer device_type;
@Override
public String getLongSn() {
return this.sn;
}
@Override
public Integer getIntDeviceType() {
return this.device_type;
}
}
......@@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull;
@Data
@ToString(callSuper = true)
public class subscribeMessageBo extends Basemodel {
public class subscribeMessageBo extends Basemodel{
//消息类型ID
@NotNull(message = "消息类型ID不能为空")
private Integer msgid;
......
package com.glsx.service;
public interface CommonParam {
String getLongSn();
Integer getIntDeviceType();
}
package com.glsx.service;
import com.glsx.model.BO.CommandsBo;
import com.glsx.model.BO.DeviceDateBo;
import com.glsx.model.BO.DeviceSdeviceDateBo;
import com.glsx.model.BO.DeviceStatusBo;
import java.util.Map;
public interface IOpenApiHTTPService {
void postCommands(CommandsBo commandsBo);
Map<String,Integer> getDeviceStatus(DeviceStatusBo deviceStatusBo);
String getFenceTriggerRecords(DeviceDateBo deviceDateBo);
String getRescueEventRecords(DeviceSdeviceDateBo deviceDateBo);
}
......@@ -8,10 +8,6 @@ import java.util.Map;
public interface IOpenApiICEService {
void postCommands(CommandsBo commandsBo);
Map<String,Integer> getDeviceStatus(DeviceStatusBo deviceStatusBo);
LatestGpsRecordDto getLatestGPSRecord(DeviceStatusBo deviceStatusBo);
LatestBsRecordDto getLatestBsRecord(DeviceStatusBo deviceStatusBo);
......@@ -49,8 +45,4 @@ public interface IOpenApiICEService {
Map<String, Object> getMonthResideRecords(DeviceMonthBo deviceStatusBo);
Map<String, Object> getDeviceStayRecords(DeviceStayBo deviceStayBo);
String getFenceTriggerRecords(DeviceDateBo deviceDateBo);
String getRescueEventRecords(DeviceSdeviceDateBo deviceDateBo);
}
package com.glsx.service;
import com.glsx.model.BO.*;
import com.glsx.model.BO.DataViewBo;
import com.glsx.model.BO.DeviceListBo;
import com.glsx.model.BO.TokenBo;
import com.glsx.model.BO.subscribeMessageBo;
import java.util.Map;
......
......@@ -2,7 +2,9 @@ package com.glsx.service.component;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.glsx.constant.OpenAPIConstant;
import com.glsx.exception.ApiException;
import com.glsx.utils.SystemProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
......@@ -13,7 +15,7 @@ import java.util.Map;
* @author fengzhi
* @version 1.0.0
* @ClassName OpenApiInvoker.java
* @description: http协议调用围栏触发和碰撞预警
* @description: http协议接口
* @createTime 2020年10月21日 14:26:00
*/
@Slf4j
......@@ -22,28 +24,63 @@ public class OpenApiInvoker {
/**
*
*/
public String invokerSync(String methodName,Map<String,Object> params) {
private String invokeGet(String url,Map<String,Object> params) {
if (params==null) {
log.info("openapi data is NULL");
log.info("openapi data is NULL:"+url);
return null;
}
String res = null;
try {
String serverUrl = SystemProperty.getProperty(OpenAPIConstant.HTTP_OPENAPI_SERVER);
Integer timeOut = Integer.parseInt(SystemProperty.getProperty(OpenAPIConstant.HTTP_TIME_OUT));
String url = serverUrl+methodName;
log.info("invoker openapi serverUrl:" + url);
log.info("invoker openapiGet serverUrl:" + url);
HttpResponse httpResponse = HttpRequest.get(url).form(params).timeout(timeOut * 1000).execute();
log.info("httpResponse:"+httpResponse.getStatus());
if(httpResponse.getStatus() == 200)
res= httpResponse.body();
} catch (Exception e) {
log.error("invoker openapi error:" + e.getMessage());
e.printStackTrace();
log.error("invoker openapiGet error:" +url+"==="+ e.getMessage());
throw new ApiException(e.getMessage());
}
log.info("invoker openapi api res:" + res);
log.info("invoker openapiGet api res:" + res);
return res;
}
private String invokePost(String url,Map<String,Object> params) {
if (params==null) {
log.info("openapi data is NULL:"+url);
return null;
}
String res = null;
try {
Integer timeOut = Integer.parseInt(SystemProperty.getProperty(OpenAPIConstant.HTTP_TIME_OUT));
log.info("invoker openapiPost serverUrl:" + url);
HttpResponse httpResponse = HttpRequest.post(url).body(JSONObject.toJSONString(params)).timeout(timeOut * 1000).execute();
log.info("httpResponse:"+httpResponse.getStatus());
if(httpResponse.getStatus() == 200)
res= httpResponse.body();
} catch (Exception e) {
log.error("invoker openapiPost error:" +url+"==="+ e.getMessage());
throw new ApiException(e.getMessage());
}
log.info("invoker openapiPost api res:" +url+"==="+ res);
return res;
}
public String invokeFenceOrRescue(String methodName,Map<String,Object> params) {
String serverUrl = SystemProperty.getProperty(OpenAPIConstant.HTTP_OPENAPI_SERVER_1);
String url = serverUrl+methodName;
return invokeGet(url,params);
}
public String invokCommandOrDeviceStatus(String methodName,Map<String,Object> params) {
String serverUrl = SystemProperty.getProperty(OpenAPIConstant.HTTP_OPENAPI_SERVER_2);
String url = serverUrl+methodName;
return invokePost(url,params);
}
}
package com.glsx.service.impl;
import com.glsx.base.aop.SysLog;
import com.glsx.base.controller.BaseService;
import com.glsx.constant.OpenAPIConstant;
import com.glsx.exception.ApiException;
import com.glsx.model.BO.CommandsBo;
import com.glsx.model.BO.DeviceDateBo;
import com.glsx.model.BO.DeviceSdeviceDateBo;
import com.glsx.model.BO.DeviceStatusBo;
import com.glsx.service.IOpenApiHTTPService;
import com.glsx.service.component.OpenApiInvoker;
import com.glsx.utils.SystemProperty;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @author fengzhi
* @version V1.0
* @Description: http协议接口实现类
*/
@Service
public class OpenApiHTTPServiceImpl extends BaseService implements IOpenApiHTTPService {
@Autowired
OpenApiInvoker apiInvoker;
@SysLog
@Override
public void postCommands(CommandsBo commandsBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_POST_COMMANDS);
Map<String, Object> params = new HashMap<>();
params.put("sn", commandsBo.getSn());
params.put("device_type", commandsBo.getDevice_type());
params.put("commandid", commandsBo.getCommandid());
params.put("command", commandsBo.getCommand());
String jsonRes = apiInvoker.invokCommandOrDeviceStatus(methodName, params);
JSONObject jsonObj = JSONObject.fromObject(jsonRes);
boolean isSuccess= jsonObj.getBoolean("success");
if(!isSuccess){
String msg = jsonObj.getString("msg");
logi("postCommands=====Failed====msg:"+msg);
throw new ApiException(msg);
}
}
@SysLog
@Override
public Map<String, Integer> getDeviceStatus(DeviceStatusBo deviceStatusBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_DEVICE_STATUS);
Map<String, Object> params = new HashMap<>();
params.put("sn", deviceStatusBo.getSn());
params.put("device_type", deviceStatusBo.getDevice_type());
String jsonRes = apiInvoker.invokCommandOrDeviceStatus(methodName, params);
JSONObject jsonObj = JSONObject.fromObject(jsonRes);
boolean isSuccess= jsonObj.getBoolean("success");
if(!isSuccess){
String msg = jsonObj.getString("msg");
logi("getDeviceStatus=====Failed====msg:"+msg);
throw new ApiException(msg);
}
JSONObject result = jsonObj.getJSONObject("result");
Integer status = result.getInt("status");
Map<String, Integer> map = new HashMap<>();
map.put("status", status);
return map;
}
@Override
public String getFenceTriggerRecords(DeviceDateBo deviceDateBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_FENCE_RECORD);
Map<String, Object> params = new HashMap<>();
params.put("sn", deviceDateBo.getSn());
params.put("device_type", deviceDateBo.getDevice_type());
params.put("start_date", deviceDateBo.getStart_date());
params.put("end_date", deviceDateBo.getEnd_date());
return apiInvoker.invokeFenceOrRescue(methodName, params);
}
@Override
public String getRescueEventRecords(DeviceSdeviceDateBo deviceDateBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_RESCUE_RECORD);
Map<String, Object> params = new HashMap<>();
params.put("sn", deviceDateBo.getSn());
//这里的type为string(SOS:紧急救援,COLLIDE:碰撞,CUSTOMER_SUBMIT 客服提交)
params.put("device_type", deviceDateBo.getDevice_type());
params.put("start_date", deviceDateBo.getStart_date());
params.put("end_date", deviceDateBo.getEnd_date());
return apiInvoker.invokeFenceOrRescue(methodName, params);
}
}
......@@ -3,17 +3,13 @@ package com.glsx.service.impl;
import com.glsx.base.aop.SysLog;
import com.glsx.base.controller.BaseService;
import com.glsx.base.enums.MapTypeEnum;
import com.glsx.constant.OpenAPIConstant;
import com.glsx.ice.iceClient.*;
import com.glsx.model.BO.*;
import com.glsx.model.BaseMapModel;
import com.glsx.model.DTO.*;
import com.glsx.service.IOpenApiICEService;
import com.glsx.service.component.OpenApiInvoker;
import com.glsx.utils.SystemProperty;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......@@ -21,29 +17,10 @@ import java.util.Map;
/**
* @author fengzhi
* @version V1.0
* @Description: 开放平台接口实现类
* @Description: ICE接口实现类
*/
@Service
public class OpenApiICEServiceImpl extends BaseService implements IOpenApiICEService {
@Autowired
OpenApiInvoker apiInvoker;
//todo 接口还没给
@SysLog
@Override
public void postCommands(CommandsBo commandsBo) {
}
//todo 接口还没给
@SysLog
@Override
public Map<String, Integer> getDeviceStatus(DeviceStatusBo deviceStatusBo) {
Map<String, Integer> map = new HashMap<>();
map.put("status", 1);
return map;
}
@SysLog
@Override
public LatestGpsRecordDto getLatestGPSRecord(DeviceStatusBo deviceStatusBo) {
......@@ -65,16 +42,10 @@ public class OpenApiICEServiceImpl extends BaseService implements IOpenApiICESer
@SysLog
@Override
public LatestGpsBsRecordDto getLatestGpsBsRecord(DeviceStatusBo deviceStatusBo) {
//todo ice接口有问题,暂用组合代替
long sn = getSn(deviceStatusBo);
Integer dType = getDeviceType(deviceStatusBo);
LatestGpsRecordDto gpsRecord = IceHDaoGpsClient.getLatestGpsRecord(sn, dType, MapTypeEnum.DOUBLE_TYPE.getId());
LatestBsRecordDto bsRecord = IceHDaoGpsClient.getLatestBsRecord(sn, dType);
LatestGpsBsRecordDto gpsBsRecordDto = new LatestGpsBsRecordDto();
BeanUtils.copyProperties(gpsRecord, gpsBsRecordDto);
BeanUtils.copyProperties(bsRecord, gpsBsRecordDto);
//LatestGpsBsRecordDto latestGpsBsRecordDto = IceHDaoGpsClient.getDevicesGpsInfo(dId, 0, 0);
return gpsBsRecordDto;
LatestGpsBsRecordDto res = IceHDaoGpsClient.getLatestGpsBsRecord(sn, dType, MapTypeEnum.DOUBLE_TYPE.getId());
return res;
}
@SysLog
......@@ -155,7 +126,7 @@ public class OpenApiICEServiceImpl extends BaseService implements IOpenApiICESer
public Map<String, Object> getReverseGeocoding(BaseMapModel mapModel) {
float lat = getLat(mapModel);
float lng = getLng(mapModel);
String address = IcePoiSearchNearClient.getReverseGeocoding(lng, lat);
String address = IcePoiSearchNearClient.getReverseGeocoding(lat, lng);
Map<String, Object> map = new HashMap<>();
map.put("address", address);
return map;
......@@ -164,7 +135,7 @@ public class OpenApiICEServiceImpl extends BaseService implements IOpenApiICESer
@SysLog
@Override
public Map<String, Object> getCoordTransForMap(CoordTransForMapBo coordTransForMapBo) {
int lat = (int) getLat(coordTransForMapBo);
int lat = getLat(coordTransForMapBo).intValue();
int lng = getLng(coordTransForMapBo).intValue();
int map_type = coordTransForMapBo.getMaptype();
Map<String, Object> map = IceHDaoGpsClient.convGeoGps(lng, lat, map_type);
......@@ -176,8 +147,9 @@ public class OpenApiICEServiceImpl extends BaseService implements IOpenApiICESer
public Map<String, Object> getJourneyByGpsRecords(GpsBsRecordsBo gpsBsRecordsBo) {
long sn = getSn(gpsBsRecordsBo);
Integer dType = getDeviceType(gpsBsRecordsBo);
int start_time = Integer.parseInt(gpsBsRecordsBo.getStartTime().getTime() + "");
int end_time = Integer.parseInt(gpsBsRecordsBo.getEndTime().getTime() + "");
long start_time = gpsBsRecordsBo.getStartTime().getTime();
long end_time = gpsBsRecordsBo.getEndTime().getTime();
logi("getJourneyByGpsRecords====="+gpsBsRecordsBo.getStartTime().getTime()+"==="+end_time);
Map<String, Object> map = IceRtMileStatClient.getJourneyByGpsRecords(sn, dType, start_time, end_time);
return map;
}
......@@ -237,27 +209,4 @@ public class OpenApiICEServiceImpl extends BaseService implements IOpenApiICESer
Map<String, Object> map = IceRtMileStatClient.getDeviceStayRecords(sn, dType, start_date, end_date, period_type, max_duration, min_duration);
return map;
}
@Override
public String getFenceTriggerRecords(DeviceDateBo deviceDateBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_FENCE_RECORD);
Map<String,Object> params = new HashMap<>();
params.put("sn",deviceDateBo.getSn());
params.put("device_type",deviceDateBo.getDevice_type());
params.put("start_date",deviceDateBo.getStart_date());
params.put("end_date",deviceDateBo.getEnd_date());
return apiInvoker.invokerSync(methodName,params);
}
@Override
public String getRescueEventRecords(DeviceSdeviceDateBo deviceDateBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_RESCUE_RECORD);
Map<String,Object> params = new HashMap<>();
params.put("sn",deviceDateBo.getSn());
//这里的type为string(SOS:紧急救援,COLLIDE:碰撞,CUSTOMER_SUBMIT 客服提交)
params.put("device_type",deviceDateBo.getDevice_type());
params.put("start_date",deviceDateBo.getStart_date());
params.put("end_date",deviceDateBo.getEnd_date());
return apiInvoker.invokerSync(methodName,params);
}
}
......@@ -3,12 +3,15 @@ package com.glsx.service.impl;
import cn.com.glsx.openplatform.service.OpenApiService;
import cn.hutool.db.Page;
import com.glsx.base.aop.SysLog;
import com.glsx.base.controller.BaseService;
import com.glsx.base.controller.JwtService;
import com.glsx.constant.OpenAPIConstant;
import com.glsx.exception.ApiErrorMessage;
import com.glsx.model.BO.*;
import com.glsx.exception.ApiException;
import com.glsx.model.BO.DataViewBo;
import com.glsx.model.BO.DeviceListBo;
import com.glsx.model.BO.TokenBo;
import com.glsx.model.BO.subscribeMessageBo;
import com.glsx.service.IOpenApiService;
import com.glsx.utils.JwtUtil;
import com.glsx.utils.MapUtils;
import com.glsx.utils.RSAUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,13 +24,13 @@ import java.util.TreeMap;
/**
* @author fengzhi
* @version V1.0
* @Description: 开放平台接口实现类
* @Description: 开放平台业务层实现类
*/
@Service
public class OpenApiServiceImpl extends BaseService implements IOpenApiService {
@Autowired
JwtUtil jwtTokenUtil;
public class OpenApiServiceImpl extends JwtService implements IOpenApiService {
/*
* 数据层服务
*/
@Autowired
OpenApiService openApiService;
......@@ -39,17 +42,14 @@ public class OpenApiServiceImpl extends BaseService implements IOpenApiService {
public String getToken(TokenBo tokenBo) {
//校验必传参数
TreeMap<String, String> params = MapUtils.transBean2Map(tokenBo);
//logi("参数对象:" + params);
// boolean miss = params.entrySet().stream().anyMatch(kv -> StringUtils.isEmpty(kv.getValue()));
//if (miss)
// throw ApiErrorMessage.ARGS_NULL.exception();
logi("参数对象:" + params);
//获取私钥
Integer appId = tokenBo.getAppId();
//todo 测试参数修改
//String privateKey = openApiService.getPrivateSecret(appId);
String privateKey = OpenAPIConstant.TEST_PRIVATE_KEY;
//todo 测试参数,如果需要测试可以修改
String privateKey = openApiService.getPrivateSecret(appId);
//String privateKey = OpenAPIConstant.TEST_PRIVATE_KEY;
logi("getToken私钥======"+privateKey);
//获取公钥加密的密文
String sign = tokenBo.getSign();
......@@ -60,7 +60,7 @@ public class OpenApiServiceImpl extends BaseService implements IOpenApiService {
} catch (Exception e) {
throw ApiErrorMessage.ARGS_ERROR.exception("RSA解密错误==签名或私钥错误" + sign);
}
logi("获取明文:" + originalStr);
//除了sign以外,按照参数字母升序(参数+参数值)拼接
StringBuffer paramsStrbuf = new StringBuffer();
params.remove(OpenAPIConstant.PARAM_SIGN);
......@@ -77,7 +77,7 @@ public class OpenApiServiceImpl extends BaseService implements IOpenApiService {
//根据appid查询用户信息,将客户信息转化为jwt
Map<String, Object> infos = openApiService.getCustomerInfo(appId);
logi("OpenApiServiceImpl===Userinfos===" + infos);
String jwtToken = jwtTokenUtil.generateToken(infos);
String jwtToken = jwtUtil.generateToken(infos);
return jwtToken;
}
......@@ -98,17 +98,26 @@ public class OpenApiServiceImpl extends BaseService implements IOpenApiService {
@SysLog
@Override
public Map<String, Integer> getDataView(DataViewBo deviceStatusBo) {
Integer customerId = getCustomerID(deviceStatusBo);
logi("OpenApiServiceImpl===getDataView==customerId:" + customerId);
Map<String, Integer> res = openApiService.getDataView(customerId, deviceStatusBo.getDevice_type());
Integer appid = getCustomerID(deviceStatusBo);
logi("OpenApiServiceImpl===getDataView==customerId:" + appid);
Map<String, Integer> res = openApiService.getDataView(appid, deviceStatusBo.getDevice_type());
return res;
}
//todo 接口自己实现
@SysLog
@Override
public void subscribeMessage(subscribeMessageBo subscribeMessageBo) {
Integer appid = getCustomerID(subscribeMessageBo);
int msgID = subscribeMessageBo.getMsgid();
int deviceType = subscribeMessageBo.getDevice_type();
int method = subscribeMessageBo.getMethod();
String pushUrl = subscribeMessageBo.getPushurl();
Map<String, Object> res = openApiService.subscribeMessage(appid,msgID,deviceType,method,pushUrl);
boolean isSuccess= (boolean) res.get("success");
if(!isSuccess){
String msg = (String) res.get("msg");
logi("subscribeMessage=====Failed====msg:"+msg);
throw new ApiException(msg);
}
}
}
......@@ -4,7 +4,10 @@ import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
/**
......@@ -42,4 +45,13 @@ public class MapUtils {
return map;
}
/**
* 方案一:直接转map,key直接设置,val的index由key计算
* @Title: listToMap
* @Description: 把两个List转换为Map
*/
public static <K, V> Map<K, V> listToMap(List<K> keys, List<V> values) {
return keys.stream().collect(Collectors.toMap(key -> key, key -> values.get(keys.indexOf(key))));
}
}
......@@ -4,13 +4,12 @@ import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Component;
import javax.crypto.Cipher;
import java.security.*;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
/**
......@@ -20,26 +19,28 @@ import java.util.Map;
*/
@Component
public class RSAUtils {
private static Map<Integer, String> keyMap = new HashMap<Integer, String>(); //用于封装随机产生的公钥与私钥
/*private static Map<Integer, String> keyMap = new HashMap<Integer, String>(); //用于封装随机产生的公钥与私钥
public static void main(String[] args) throws Exception {
//生成公钥和私钥
genKeyPair();
//加密字符串
String message = "appId1grantType1time123456";
System.out.println("随机生成的公钥为:" + keyMap.get(0));
System.out.println("随机生成的私钥为:" + keyMap.get(1));
String message = "appId100000grantType1time123456";
String pubkey = OpenAPIConstant.TEST_PUBLIC_KEY;
String prikey = OpenAPIConstant.TEST_PRIVATE_KEY;
System.out.println("随机生成的公钥为:" + pubkey*//*keyMap.get(0)*//*);
System.out.println("随机生成的私钥为:" + prikey*//*keyMap.get(1)*//*);
//String messageEn = encrypt(message, OpenAPIConstant.TEST_PUBLIC_KEY);
String messageEn = encrypt(message,keyMap.get(0));
String messageEn = encrypt(message,pubkey*//*keyMap.get(0)*//*);
System.out.println(message + "\t加密后的字符串为:" + messageEn);
String messageDe = decrypt(messageEn,keyMap.get(1));
String messageDe = decrypt(messageEn,prikey*//*keyMap.get(1)*//*);
System.out.println("还原后的字符串为:" + messageDe);
}
/**
*//**
* 随机生成密钥对
* @throws NoSuchAlgorithmException
*/
*//*
public static void genKeyPair() throws NoSuchAlgorithmException {
// KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
......@@ -55,7 +56,7 @@ public class RSAUtils {
// 将公钥和私钥保存到Map
keyMap.put(0,publicKeyString); //0表示公钥
keyMap.put(1,privateKeyString); //1表示私钥
}
}*/
/**
* RSA公钥加密
......
......@@ -4,7 +4,7 @@ server.servlet.context-path=/open-platform-api
server.servlet.application-display-name=open-platform-api
logging.config=classpath:logback.xml
#logging.path=/data/java_log/jetty/open-platform-api/open-platform-api.log
logging.path=/data/java_log/jetty/open-platform-api/open-platform-api.log
logging.level.root=INFO
ore.starter.class-name=Main
......
......@@ -3,7 +3,7 @@
<property resource="config/application.properties" />
<property name="APP_NAME" value="${server.display-name}" />
<!-- <property name="LOG_PATH" value="${logging.path}" />-->
<property name="LOG_PATH" value="${logging.path}" />
<property name="LOG_LEVEL" value="${logging.level}" />
<contextName>${APP_NAME}</contextName>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!