From 2f1abf902a312aaa79ed507b9102530822111562 Mon Sep 17 00:00:00 2001
From: wangning <164851225@qq.com>
Date: Thu, 19 Apr 2018 09:23:26 +0800
Subject: [PATCH] add mongo
---
pom.xml | 4 +
.../manage/PaymentManageApplication.java | 8 +-
.../beans/mongo/ClientConfigLog.java | 91 +++++++++++++++++++
.../core/impls/ClientModifySupportImpl.java | 8 +-
.../merchants/entity/ClientConfigModify.java | 59 +++++-------
.../manage/merchants/entity/ClientModify.java | 55 ++++-------
src/main/resources/application.properties | 4 +
.../ofei/core/impl/OfeiClientImplTest.java | 17 ++++
8 files changed, 171 insertions(+), 75 deletions(-)
create mode 100644 src/main/java/au/com/royalpay/payment/manage/merchants/beans/mongo/ClientConfigLog.java
diff --git a/pom.xml b/pom.xml
index 689bc1b0e..6c9ab7a3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,10 @@
org.springframework.boot
spring-boot-starter
+
+ org.springframework.boot
+ spring-boot-starter-data-mongodb
+
org.springframework.boot
spring-boot-starter-web
diff --git a/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java b/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java
index caaed476a..020502652 100644
--- a/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java
+++ b/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java
@@ -3,7 +3,10 @@ package au.com.royalpay.payment.manage;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
+
import com.maxmind.geoip.LookupService;
+import com.mongodb.MongoClientOptions;
+
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
@@ -65,7 +68,10 @@ public class PaymentManageApplication {
DefaultKaptcha producer = new DefaultKaptcha();
producer.setConfig(config);
return producer;
+ }
-
+ @Bean
+ public MongoClientOptions mongoOptions() {
+ return MongoClientOptions.builder().maxConnectionIdleTime(6000).build();
}
}
diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/beans/mongo/ClientConfigLog.java b/src/main/java/au/com/royalpay/payment/manage/merchants/beans/mongo/ClientConfigLog.java
new file mode 100644
index 000000000..fcaa8d522
--- /dev/null
+++ b/src/main/java/au/com/royalpay/payment/manage/merchants/beans/mongo/ClientConfigLog.java
@@ -0,0 +1,91 @@
+package au.com.royalpay.payment.manage.merchants.beans.mongo;
+
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.Date;
+
+@Document(collection = "client_config_log") // here is solution
+public class ClientConfigLog {
+
+ private long id;
+ private int clientId;
+ private String business;
+ private String userType;
+ private String userId;
+ private String userName;
+ private String originData;
+ private String newData;
+ private Date createTime;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public int getClientId() {
+ return clientId;
+ }
+
+ public void setClientId(int clientId) {
+ this.clientId = clientId;
+ }
+
+ public String getBusiness() {
+ return business;
+ }
+
+ public void setBusiness(String business) {
+ this.business = business;
+ }
+
+ public String getUserType() {
+ return userType;
+ }
+
+ public void setUserType(String userType) {
+ this.userType = userType;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getOriginData() {
+ return originData;
+ }
+
+ public void setOriginData(String originData) {
+ this.originData = originData;
+ }
+
+ public String getNewData() {
+ return newData;
+ }
+
+ public void setNewData(String newData) {
+ this.newData = newData;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+}
diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientModifySupportImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientModifySupportImpl.java
index 1b525406e..b97dc6175 100644
--- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientModifySupportImpl.java
+++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientModifySupportImpl.java
@@ -7,6 +7,8 @@ import au.com.royalpay.payment.manage.merchants.core.ClientModifySupport;
import au.com.royalpay.payment.manage.merchants.entity.ClientConfigModify;
import au.com.royalpay.payment.manage.merchants.entity.ClientModify;
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
+
+import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -24,15 +26,17 @@ public class ClientModifySupportImpl implements ClientModifySupport {
private ClientMapper clientMapper;
@Resource
private ClientConfigMapper clientConfigMapper;
+ @Resource
+ private MongoTemplate mongoTemplate;
@Override
public void processClientModify(ClientModify modify) {
- int clientId = modify.doModify(merchantInfoProvider, clientMapper);
+ int clientId = modify.doModify(merchantInfoProvider, clientMapper,mongoTemplate);
clientInfoCacheSupport.clearClientCache(clientId);
}
@Override
public void processClientConfigModify(ClientConfigModify clientConfigModify) {
- clientConfigModify.doModify(merchantInfoProvider, clientConfigMapper);
+ clientConfigModify.doModify(merchantInfoProvider, clientConfigMapper,mongoTemplate);
}
}
diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientConfigModify.java b/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientConfigModify.java
index 26de3ec74..91e231aff 100644
--- a/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientConfigModify.java
+++ b/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientConfigModify.java
@@ -1,19 +1,20 @@
package au.com.royalpay.payment.manage.merchants.entity;
import au.com.royalpay.payment.manage.mappers.system.ClientConfigMapper;
+import au.com.royalpay.payment.manage.merchants.beans.mongo.ClientConfigLog;
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
+import au.com.royalpay.payment.tools.utils.id.IdUtil;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.transaction.annotation.Transactional;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.util.Date;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* Create by yixian at 2018-04-12 16:19
@@ -34,55 +35,39 @@ public abstract class ClientConfigModify {
protected abstract JSONObject getModifyResult();
@Transactional
- public int doModify(MerchantInfoProvider merchantInfoProvider, ClientConfigMapper clientConfigMapper) {
+ public int doModify(MerchantInfoProvider merchantInfoProvider, ClientConfigMapper clientConfigMapper, MongoTemplate mongoTemplate) {
JSONObject client = merchantInfoProvider.getClientInfoByMoniker(clientMoniker);
JSONObject modifyResult = getModifyResult();
- saveModifyHistory(client, modifyResult);
+ saveModifyHistory(client, modifyResult,mongoTemplate);
int clientId = client.getIntValue("client_id");
modifyResult.put("client_id", clientId);
clientConfigMapper.update(modifyResult);
return clientId;
}
- private void saveModifyHistory(JSONObject client, JSONObject modifyResult) {
+ private void saveModifyHistory(JSONObject client, JSONObject modifyResult,MongoTemplate mongoTemplate) {
if (account == null) {
return;
}
+ ClientConfigLog clientConfigLog = new ClientConfigLog();
+ clientConfigLog.setId(IdUtil.getId());
+ clientConfigLog.setBusiness(business());
+ clientConfigLog.setClientId(client.getIntValue("client_id"));
+
boolean isPartner = true;
- JSONObject modifyHistory = new JSONObject();
- modifyHistory.put("client_id", client.getIntValue("client_id"));
- modifyHistory.put("client_moniker", client.getIntValue("client_moniker"));
- modifyHistory.put("business", business());
if (StringUtils.isNotEmpty(account.getString("account_id"))) {
isPartner = true;
}
if (StringUtils.isNotEmpty(account.getString("manager_id"))) {
isPartner = false;
}
- modifyHistory.put("user_type", isPartner ? "Merchant" : "Manager");
- modifyHistory.put("user_id", isPartner ? account.getString("account_id") : account.getString("manager_id"));
- modifyHistory.put("username", isPartner ? account.getString("display_name") : account.getString("display_name"));
- modifyHistory.put("origin_data", modifyResult.toJSONString());
- modifyHistory.put("update_column", modifyResult.toJSONString());
- modifyHistory.put("create_time", new Date());
-
- BufferedWriter out = null;
- try {
- // TODO: 2018/4/12 kira 文件地址
- File file = new File("/Users/wangning/Desktop/asd.txt");
- if (file == null) {
- file.createNewFile();
- }
- out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
- out.write("asdasdasdasd" + "\r\n");
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ clientConfigLog.setUserType(isPartner ? "Merchant" : "Manager");
+ clientConfigLog.setCreateTime(new Date());
+ clientConfigLog.setNewData(modifyResult.toJSONString());
+ clientConfigLog.setUserId(isPartner ? account.getString("account_id") : account.getString("manager_id"));
+ Map beforeModify = modifyResult.keySet().stream().collect(Collectors.toMap(key -> key, client::get));
+ clientConfigLog.setOriginData(JSON.toJSONString(beforeModify));
+ clientConfigLog.setUserName(isPartner ? account.getString("display_name") : account.getString("display_name"));
+ mongoTemplate.insert(clientConfigLog);
}
}
diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientModify.java b/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientModify.java
index 7d9d1afa8..2831f31da 100644
--- a/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientModify.java
+++ b/src/main/java/au/com/royalpay/payment/manage/merchants/entity/ClientModify.java
@@ -1,19 +1,18 @@
package au.com.royalpay.payment.manage.merchants.entity;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
+import au.com.royalpay.payment.manage.merchants.beans.mongo.ClientConfigLog;
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
+import au.com.royalpay.payment.tools.utils.id.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.transaction.annotation.Transactional;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.util.Date;
import java.util.Map;
import java.util.stream.Collectors;
@@ -36,53 +35,39 @@ public abstract class ClientModify {
protected abstract JSONObject getModifyResult();
@Transactional
- public int doModify(MerchantInfoProvider merchantInfoProvider, ClientMapper clientMapper) {
+ public int doModify(MerchantInfoProvider merchantInfoProvider, ClientMapper clientMapper, MongoTemplate mongoTemplate) {
JSONObject client = merchantInfoProvider.getClientInfoByMoniker(clientMoniker);
JSONObject modifyResult = getModifyResult();
- saveModifyHistory(client, modifyResult);
+ saveModifyHistory(client, modifyResult, mongoTemplate);
int clientId = client.getIntValue("client_id");
modifyResult.put("client_id", clientId);
clientMapper.update(modifyResult);
return clientId;
}
- private void saveModifyHistory(JSONObject client, JSONObject modifyResult) {
+ private void saveModifyHistory(JSONObject client, JSONObject modifyResult, MongoTemplate mongoTemplate) {
if (account == null) {
return;
}
+ ClientConfigLog clientConfigLog = new ClientConfigLog();
+ clientConfigLog.setId(IdUtil.getId());
+ clientConfigLog.setBusiness(business());
+ clientConfigLog.setClientId(client.getIntValue("client_id"));
+
boolean isPartner = true;
- Map beforeModify = modifyResult.keySet().stream().collect(Collectors.toMap(key -> key, client::get));
- JSONObject modifyHistory = new JSONObject();
- modifyHistory.put("client_id", client.getIntValue("client_id"));
- modifyHistory.put("business", business());
if (StringUtils.isNotEmpty(account.getString("account_id"))) {
isPartner = true;
}
if (StringUtils.isNotEmpty(account.getString("manager_id"))) {
isPartner = false;
}
- modifyHistory.put("user_type", isPartner ? "Merchant" : "Manager");
- modifyHistory.put("user_id", isPartner ? account.getString("account_id") : account.getString("manager_id"));
- modifyHistory.put("username", isPartner ? account.getString("display_name") : account.getString("display_name"));
- modifyHistory.put("origin_data", JSON.toJSONString(beforeModify));
- modifyHistory.put("new_data", modifyResult.toJSONString());
- BufferedWriter out = null;
- try {
- // TODO: 2018/4/12 kira 文件地址
- File file = new File("/Users/wangning/Desktop/asd.txt");
- if (file == null) {
- file.createNewFile();
- }
- out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
- out.write("asdasdasdasd" + "\r\n");
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ clientConfigLog.setUserType(isPartner ? "Merchant" : "Manager");
+ clientConfigLog.setCreateTime(new Date());
+ clientConfigLog.setNewData(modifyResult.toJSONString());
+ clientConfigLog.setUserId(isPartner ? account.getString("account_id") : account.getString("manager_id"));
+ Map beforeModify = modifyResult.keySet().stream().collect(Collectors.toMap(key -> key, client::get));
+ clientConfigLog.setOriginData(JSON.toJSONString(beforeModify));
+ clientConfigLog.setUserName(isPartner ? account.getString("display_name") : account.getString("display_name"));
+ mongoTemplate.save(clientConfigLog);
}
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 672e6befb..c75deb1a3 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -22,6 +22,10 @@ spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.database=1
+spring.data.mongodb.host=192.168.99.103
+spring.data.mongodb.port=27017
+spring.data.mongodb.database=royalpay_production
+
mybatis.autosql.default-dialect=mysql
app.redis.prefix=payment
diff --git a/src/test/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiClientImplTest.java b/src/test/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiClientImplTest.java
index 6f59dff81..3b9127fe3 100644
--- a/src/test/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiClientImplTest.java
+++ b/src/test/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiClientImplTest.java
@@ -2,12 +2,17 @@ package au.com.royalpay.payment.manage.ofei.core.impl;
import au.com.royalpay.payment.manage.ofei.core.OfeiClient;
+import com.alibaba.fastjson.JSONObject;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
+import java.math.BigDecimal;
+
import javax.annotation.Resource;
/**
@@ -19,9 +24,21 @@ import javax.annotation.Resource;
public class OfeiClientImplTest {
@Resource
private OfeiClient ofeiClient;
+ @Resource
+ private MongoTemplate mongoTemplate;
+
@Test
public void qbTopUp() throws Exception {
ofeiClient.qbTopUp("10","164851225");
}
+ @Test
+ public void testMongo(){
+ JSONObject test = new JSONObject();
+ test.put("id","asd");
+ test.put("name","kira");
+ test.put("age",123);
+ test.put("amount", BigDecimal.ONE);
+ mongoTemplate.save(test);
+ }
}
\ No newline at end of file