|
@@ -1,6 +1,7 @@
|
|
|
package com.uas.platform.b2b.support;
|
|
package com.uas.platform.b2b.support;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -13,18 +14,19 @@ import com.uas.platform.core.util.encry.Md5Utils;
|
|
|
public class TokenService {
|
|
public class TokenService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private TokenDao tokenDao;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private TokenDao tokenDao;
|
|
|
|
|
+
|
|
|
public Token saveToken(Token token) {
|
|
public Token saveToken(Token token) {
|
|
|
- if (tokenDao.findTokenByUuAndUserType(token.getUu(), token.getUserType()) != null){
|
|
|
|
|
- tokenDao.delete(tokenDao.findTokenByUuAndUserType(token.getUu(), token.getUserType()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<Token> tokens = tokenDao.findByUuAndUserType(token.getUu(), token.getUserType());
|
|
|
|
|
+ if (!tokens.isEmpty())
|
|
|
|
|
+ tokenDao.delete(tokens);
|
|
|
token.setTime(new Date());
|
|
token.setTime(new Date());
|
|
|
return tokenDao.save(token);
|
|
return tokenDao.save(token);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取并保存
|
|
* 获取并保存
|
|
|
|
|
+ *
|
|
|
* @param userType
|
|
* @param userType
|
|
|
* @param uu
|
|
* @param uu
|
|
|
* @return
|
|
* @return
|
|
@@ -43,16 +45,17 @@ public class TokenService {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public boolean isCertified(String userType, Long uu, String encodeString) {
|
|
public boolean isCertified(String userType, Long uu, String encodeString) {
|
|
|
- Token token = tokenDao.findTokenByUuAndUserType(uu, userType);
|
|
|
|
|
- if (token != null) {
|
|
|
|
|
- String encode = Md5Utils.encode(uu, token.getId());
|
|
|
|
|
- boolean certified = !token.isOutofTime() && encode.equals(encodeString);
|
|
|
|
|
- // 只使用一次,即时删除
|
|
|
|
|
- tokenDao.delete(token);
|
|
|
|
|
- return certified;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<Token> tokens = tokenDao.findByUuAndUserType(uu, userType);
|
|
|
|
|
+ if (!tokens.isEmpty()) {
|
|
|
|
|
+ for (Token token : tokens) {
|
|
|
|
|
+ String encode = Md5Utils.encode(uu, token.getId());
|
|
|
|
|
+ boolean certified = !token.isOutofTime() && encode.equals(encodeString);
|
|
|
|
|
+ // 只使用一次,即时删除
|
|
|
|
|
+ tokenDao.delete(token);
|
|
|
|
|
+ if (certified)
|
|
|
|
|
+ return certified;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|