Commit ea227a05 authored by 廖旭伟's avatar 廖旭伟

修改token存取方式

parent 0d7fef77
...@@ -3,10 +3,12 @@ package com.mortals.xhx.protocol.complex; ...@@ -3,10 +3,12 @@ package com.mortals.xhx.protocol.complex;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.protocol.complex.matter.model.req.DeviceLoginReq; import com.mortals.xhx.protocol.complex.matter.model.req.DeviceLoginReq;
import com.mortals.xhx.protocol.complex.matter.model.rsp.LoginRspInfo; import com.mortals.xhx.protocol.complex.matter.model.rsp.LoginRspInfo;
import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService; import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -28,11 +30,18 @@ public abstract class AbstractComplexService implements IComplexMatterService { ...@@ -28,11 +30,18 @@ public abstract class AbstractComplexService implements IComplexMatterService {
//综窗接件token deviceCode--对应tokenMap //综窗接件token deviceCode--对应tokenMap
public static Map<String, String> tokenMap=new HashMap<>(); public static Map<String, String> tokenMap=new HashMap<>();
public static String DEVICE_LOGO_TOKEN = "device:logo:token";
/***/
public static Long TOKEN_TIMEOUT = 3600l;
@Autowired
private ICacheService iCacheService;
@Override @Override
public String getToken(String deviceLogo) { public String getToken(String deviceLogo) {
try { try {
String deviceToken = tokenMap.getOrDefault(deviceLogo, ""); String deviceToken = iCacheService.get(DEVICE_LOGO_TOKEN);
if (ObjectUtils.isEmpty(deviceToken)) { if (ObjectUtils.isEmpty(deviceToken)) {
DeviceLoginReq loginReq = new DeviceLoginReq(); DeviceLoginReq loginReq = new DeviceLoginReq();
loginReq.setDeviceLogo(deviceLogo); loginReq.setDeviceLogo(deviceLogo);
...@@ -47,4 +56,9 @@ public abstract class AbstractComplexService implements IComplexMatterService { ...@@ -47,4 +56,9 @@ public abstract class AbstractComplexService implements IComplexMatterService {
} }
} }
@Override
public void setToken(String token){
iCacheService.set(DEVICE_LOGO_TOKEN,token,TOKEN_TIMEOUT);
}
} }
...@@ -7,4 +7,5 @@ package com.mortals.xhx.protocol.complex; ...@@ -7,4 +7,5 @@ package com.mortals.xhx.protocol.complex;
*/ */
public interface IComplexService { public interface IComplexService {
String getToken(String deviceLogo); String getToken(String deviceLogo);
void setToken(String token);
} }
...@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSON; ...@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.protocol.complex.AbstractComplexService; import com.mortals.xhx.protocol.complex.AbstractComplexService;
import com.mortals.xhx.protocol.complex.ComplexApiRest; import com.mortals.xhx.protocol.complex.ComplexApiRest;
import com.mortals.xhx.protocol.complex.matter.model.req.AcceptReq; import com.mortals.xhx.protocol.complex.matter.model.req.AcceptReq;
...@@ -23,6 +24,7 @@ import com.mortals.xhx.protocol.complex.matter.model.rsp.matter.MatterWorkInfo; ...@@ -23,6 +24,7 @@ import com.mortals.xhx.protocol.complex.matter.model.rsp.matter.MatterWorkInfo;
import com.mortals.xhx.protocol.complex.matter.model.rsp.work.WorkInfo; import com.mortals.xhx.protocol.complex.matter.model.rsp.work.WorkInfo;
import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService; import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -41,6 +43,8 @@ import java.util.Map; ...@@ -41,6 +43,8 @@ import java.util.Map;
@Slf4j @Slf4j
public class ComplexMatterServiceImpl extends AbstractComplexService implements IComplexMatterService { public class ComplexMatterServiceImpl extends AbstractComplexService implements IComplexMatterService {
//token有效期 10小时 //token有效期 10小时
@Override @Override
public Rest<LoginRspInfo> deviceLogin(DeviceLoginReq loginReq) { public Rest<LoginRspInfo> deviceLogin(DeviceLoginReq loginReq) {
...@@ -54,7 +58,8 @@ public class ComplexMatterServiceImpl extends AbstractComplexService implements ...@@ -54,7 +58,8 @@ public class ComplexMatterServiceImpl extends AbstractComplexService implements
//更新token //更新token
String deviceLoginToken = complexApiRest.getResult().getToken(); String deviceLoginToken = complexApiRest.getResult().getToken();
String deviceLogo = complexApiRest.getResult().getSelfDeviceInfo().getDeviceLogo(); String deviceLogo = complexApiRest.getResult().getSelfDeviceInfo().getDeviceLogo();
this.tokenMap.put(deviceLogo, deviceLoginToken); //this.tokenMap.put(deviceLogo, deviceLoginToken);
this.setToken(deviceLoginToken);
return Rest.ok(complexApiRest.getMessage(), complexApiRest.getResult()); return Rest.ok(complexApiRest.getMessage(), complexApiRest.getResult());
} }
return Rest.fail(complexApiRest.getMessage()); return Rest.fail(complexApiRest.getMessage());
......
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