|
@@ -14,13 +14,13 @@ import java.util.Date;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
public class MongoDBUtil {
|
|
|
- private static final String host="192.168.50.41";
|
|
|
- private static final Integer port=27018;
|
|
|
- private static final String username="admin";
|
|
|
- private static final String database="B2BMall";
|
|
|
- private static final String password="360lj.ocm";
|
|
|
-
|
|
|
- public static MongoDatabase mongoDatabase(){
|
|
|
+ private static final String host="192.168.50.41";
|
|
|
+ private static final Integer port=27018;
|
|
|
+ private static final String username="admin";
|
|
|
+ private static final String database="B2BMall";
|
|
|
+ private static final String password="360lj.ocm";
|
|
|
+
|
|
|
+ public static MongoDatabase mongoDatabase(){
|
|
|
// List<ServerAddress> adds = new ArrayList<ServerAddress>();
|
|
|
// ServerAddress serverAddress = new ServerAddress(host, port);
|
|
|
// adds.add(serverAddress);
|
|
@@ -29,43 +29,43 @@ public class MongoDBUtil {
|
|
|
// credentials.add(mongoCredential);
|
|
|
// MongoClient mongoClient = new MongoClient(adds, credentials);
|
|
|
// MongoDatabase mongoDatabase = mongoClient.getDatabase(database);
|
|
|
- MongoClient mongoClient = new MongoClient("192.168.50.41", 27018);
|
|
|
- MongoDatabase mongoDatabase = mongoClient.getDatabase(database);
|
|
|
- return mongoDatabase;
|
|
|
- }
|
|
|
-
|
|
|
- public static void insertVLoginToken(Date expirationDate,String accountId,String token,Integer type){
|
|
|
- MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
- Document document = new Document("_id", UUID.randomUUID().toString())
|
|
|
- .append("_time",new Date())
|
|
|
- .append("Token", token)
|
|
|
- .append("ExpirationDate", expirationDate)
|
|
|
- .append("AccountId",accountId)
|
|
|
- .append("AccountType",type);
|
|
|
- collection.insertOne(document);
|
|
|
- }
|
|
|
-
|
|
|
- public static Document queryVLoginToken(String accountId){
|
|
|
- MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
- Bson filter = Filters.eq("AccountId", accountId);
|
|
|
- FindIterable findIterable = collection.find(filter);
|
|
|
- MongoCursor cursor = findIterable.iterator();
|
|
|
- return (Document) findIterable.first();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static Document queryVLoginTokenByToken(String token){
|
|
|
- MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
- Bson filter = Filters.eq("Token", token);
|
|
|
- FindIterable findIterable = collection.find(filter);
|
|
|
- MongoCursor cursor = findIterable.iterator();
|
|
|
- return (Document) findIterable.first();
|
|
|
- }
|
|
|
-
|
|
|
- public static void updateVLoginTOken(Date expirationDate,String accountId,String token){
|
|
|
- MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
- Bson filter = Filters.eq("AccountId", accountId);
|
|
|
- Document document = new Document("$set", new Document("Token", token).append("ExpirationDate",expirationDate));
|
|
|
- collection.updateOne(filter, document);
|
|
|
- }
|
|
|
+ MongoClient mongoClient = new MongoClient("192.168.50.41", 27018);
|
|
|
+ MongoDatabase mongoDatabase = mongoClient.getDatabase(database);
|
|
|
+ return mongoDatabase;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void insertVLoginToken(Date expirationDate,String accountId,String token,Integer type){
|
|
|
+ MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
+ Document document = new Document("_id", UUID.randomUUID().toString())
|
|
|
+ .append("_time",new Date())
|
|
|
+ .append("Token", token)
|
|
|
+ .append("ExpirationDate", expirationDate)
|
|
|
+ .append("AccountId",accountId)
|
|
|
+ .append("AccountType",type);
|
|
|
+ collection.insertOne(document);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Document queryVLoginToken(String accountId){
|
|
|
+ MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
+ Bson filter = Filters.eq("AccountId", accountId);
|
|
|
+ FindIterable findIterable = collection.find(filter);
|
|
|
+ MongoCursor cursor = findIterable.iterator();
|
|
|
+ return (Document) findIterable.first();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Document queryVLoginTokenByToken(String token){
|
|
|
+ MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
+ Bson filter = Filters.eq("Token", token);
|
|
|
+ FindIterable findIterable = collection.find(filter);
|
|
|
+ MongoCursor cursor = findIterable.iterator();
|
|
|
+ return (Document) findIterable.first();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void updateVLoginTOken(Date expirationDate,String accountId,String token){
|
|
|
+ MongoCollection<Document> collection = mongoDatabase().getCollection("VLoginToken");
|
|
|
+ Bson filter = Filters.eq("AccountId", accountId);
|
|
|
+ Document document = new Document("$set", new Document("Token", token).append("ExpirationDate",expirationDate));
|
|
|
+ collection.updateOne(filter, document);
|
|
|
+ }
|
|
|
}
|