master
wangning 7 years ago
parent 9f428e2bd8
commit 2f1abf902a

@ -40,6 +40,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>

@ -3,7 +3,10 @@ package au.com.royalpay.payment.manage;
import com.google.code.kaptcha.Producer; import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha; import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config; import com.google.code.kaptcha.util.Config;
import com.maxmind.geoip.LookupService; import com.maxmind.geoip.LookupService;
import com.mongodb.MongoClientOptions;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
@ -65,7 +68,10 @@ public class PaymentManageApplication {
DefaultKaptcha producer = new DefaultKaptcha(); DefaultKaptcha producer = new DefaultKaptcha();
producer.setConfig(config); producer.setConfig(config);
return producer; return producer;
}
@Bean
public MongoClientOptions mongoOptions() {
return MongoClientOptions.builder().maxConnectionIdleTime(6000).build();
} }
} }

@ -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;
}
}

@ -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.ClientConfigModify;
import au.com.royalpay.payment.manage.merchants.entity.ClientModify; import au.com.royalpay.payment.manage.merchants.entity.ClientModify;
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -24,15 +26,17 @@ public class ClientModifySupportImpl implements ClientModifySupport {
private ClientMapper clientMapper; private ClientMapper clientMapper;
@Resource @Resource
private ClientConfigMapper clientConfigMapper; private ClientConfigMapper clientConfigMapper;
@Resource
private MongoTemplate mongoTemplate;
@Override @Override
public void processClientModify(ClientModify modify) { public void processClientModify(ClientModify modify) {
int clientId = modify.doModify(merchantInfoProvider, clientMapper); int clientId = modify.doModify(merchantInfoProvider, clientMapper,mongoTemplate);
clientInfoCacheSupport.clearClientCache(clientId); clientInfoCacheSupport.clearClientCache(clientId);
} }
@Override @Override
public void processClientConfigModify(ClientConfigModify clientConfigModify) { public void processClientConfigModify(ClientConfigModify clientConfigModify) {
clientConfigModify.doModify(merchantInfoProvider, clientConfigMapper); clientConfigModify.doModify(merchantInfoProvider, clientConfigMapper,mongoTemplate);
} }
} }

@ -1,19 +1,20 @@
package au.com.royalpay.payment.manage.merchants.entity; package au.com.royalpay.payment.manage.merchants.entity;
import au.com.royalpay.payment.manage.mappers.system.ClientConfigMapper; 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.merchants.core.MerchantInfoProvider;
import au.com.royalpay.payment.tools.utils.id.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.transaction.annotation.Transactional; 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.Date;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* Create by yixian at 2018-04-12 16:19 * Create by yixian at 2018-04-12 16:19
@ -34,55 +35,39 @@ public abstract class ClientConfigModify {
protected abstract JSONObject getModifyResult(); protected abstract JSONObject getModifyResult();
@Transactional @Transactional
public int doModify(MerchantInfoProvider merchantInfoProvider, ClientConfigMapper clientConfigMapper) { public int doModify(MerchantInfoProvider merchantInfoProvider, ClientConfigMapper clientConfigMapper, MongoTemplate mongoTemplate) {
JSONObject client = merchantInfoProvider.getClientInfoByMoniker(clientMoniker); JSONObject client = merchantInfoProvider.getClientInfoByMoniker(clientMoniker);
JSONObject modifyResult = getModifyResult(); JSONObject modifyResult = getModifyResult();
saveModifyHistory(client, modifyResult); saveModifyHistory(client, modifyResult,mongoTemplate);
int clientId = client.getIntValue("client_id"); int clientId = client.getIntValue("client_id");
modifyResult.put("client_id", clientId); modifyResult.put("client_id", clientId);
clientConfigMapper.update(modifyResult); clientConfigMapper.update(modifyResult);
return clientId; return clientId;
} }
private void saveModifyHistory(JSONObject client, JSONObject modifyResult) { private void saveModifyHistory(JSONObject client, JSONObject modifyResult,MongoTemplate mongoTemplate) {
if (account == null) { if (account == null) {
return; return;
} }
ClientConfigLog clientConfigLog = new ClientConfigLog();
clientConfigLog.setId(IdUtil.getId());
clientConfigLog.setBusiness(business());
clientConfigLog.setClientId(client.getIntValue("client_id"));
boolean isPartner = true; 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"))) { if (StringUtils.isNotEmpty(account.getString("account_id"))) {
isPartner = true; isPartner = true;
} }
if (StringUtils.isNotEmpty(account.getString("manager_id"))) { if (StringUtils.isNotEmpty(account.getString("manager_id"))) {
isPartner = false; isPartner = false;
} }
modifyHistory.put("user_type", isPartner ? "Merchant" : "Manager"); clientConfigLog.setUserType(isPartner ? "Merchant" : "Manager");
modifyHistory.put("user_id", isPartner ? account.getString("account_id") : account.getString("manager_id")); clientConfigLog.setCreateTime(new Date());
modifyHistory.put("username", isPartner ? account.getString("display_name") : account.getString("display_name")); clientConfigLog.setNewData(modifyResult.toJSONString());
modifyHistory.put("origin_data", modifyResult.toJSONString()); clientConfigLog.setUserId(isPartner ? account.getString("account_id") : account.getString("manager_id"));
modifyHistory.put("update_column", modifyResult.toJSONString()); Map<String, Object> beforeModify = modifyResult.keySet().stream().collect(Collectors.toMap(key -> key, client::get));
modifyHistory.put("create_time", new Date()); clientConfigLog.setOriginData(JSON.toJSONString(beforeModify));
clientConfigLog.setUserName(isPartner ? account.getString("display_name") : account.getString("display_name"));
BufferedWriter out = null; mongoTemplate.insert(clientConfigLog);
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();
}
}
} }
} }

@ -1,19 +1,18 @@
package au.com.royalpay.payment.manage.merchants.entity; package au.com.royalpay.payment.manage.merchants.entity;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper; 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.merchants.core.MerchantInfoProvider;
import au.com.royalpay.payment.tools.utils.id.IdUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.BufferedWriter; import java.util.Date;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -36,53 +35,39 @@ public abstract class ClientModify {
protected abstract JSONObject getModifyResult(); protected abstract JSONObject getModifyResult();
@Transactional @Transactional
public int doModify(MerchantInfoProvider merchantInfoProvider, ClientMapper clientMapper) { public int doModify(MerchantInfoProvider merchantInfoProvider, ClientMapper clientMapper, MongoTemplate mongoTemplate) {
JSONObject client = merchantInfoProvider.getClientInfoByMoniker(clientMoniker); JSONObject client = merchantInfoProvider.getClientInfoByMoniker(clientMoniker);
JSONObject modifyResult = getModifyResult(); JSONObject modifyResult = getModifyResult();
saveModifyHistory(client, modifyResult); saveModifyHistory(client, modifyResult, mongoTemplate);
int clientId = client.getIntValue("client_id"); int clientId = client.getIntValue("client_id");
modifyResult.put("client_id", clientId); modifyResult.put("client_id", clientId);
clientMapper.update(modifyResult); clientMapper.update(modifyResult);
return clientId; return clientId;
} }
private void saveModifyHistory(JSONObject client, JSONObject modifyResult) { private void saveModifyHistory(JSONObject client, JSONObject modifyResult, MongoTemplate mongoTemplate) {
if (account == null) { if (account == null) {
return; return;
} }
ClientConfigLog clientConfigLog = new ClientConfigLog();
clientConfigLog.setId(IdUtil.getId());
clientConfigLog.setBusiness(business());
clientConfigLog.setClientId(client.getIntValue("client_id"));
boolean isPartner = true; boolean isPartner = true;
Map<String, Object> 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"))) { if (StringUtils.isNotEmpty(account.getString("account_id"))) {
isPartner = true; isPartner = true;
} }
if (StringUtils.isNotEmpty(account.getString("manager_id"))) { if (StringUtils.isNotEmpty(account.getString("manager_id"))) {
isPartner = false; isPartner = false;
} }
modifyHistory.put("user_type", isPartner ? "Merchant" : "Manager"); clientConfigLog.setUserType(isPartner ? "Merchant" : "Manager");
modifyHistory.put("user_id", isPartner ? account.getString("account_id") : account.getString("manager_id")); clientConfigLog.setCreateTime(new Date());
modifyHistory.put("username", isPartner ? account.getString("display_name") : account.getString("display_name")); clientConfigLog.setNewData(modifyResult.toJSONString());
modifyHistory.put("origin_data", JSON.toJSONString(beforeModify)); clientConfigLog.setUserId(isPartner ? account.getString("account_id") : account.getString("manager_id"));
modifyHistory.put("new_data", modifyResult.toJSONString()); Map<String, Object> beforeModify = modifyResult.keySet().stream().collect(Collectors.toMap(key -> key, client::get));
BufferedWriter out = null; clientConfigLog.setOriginData(JSON.toJSONString(beforeModify));
try { clientConfigLog.setUserName(isPartner ? account.getString("display_name") : account.getString("display_name"));
// TODO: 2018/4/12 kira 文件地址 mongoTemplate.save(clientConfigLog);
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();
}
}
} }
} }

@ -22,6 +22,10 @@ spring.redis.host=127.0.0.1
spring.redis.port=6379 spring.redis.port=6379
spring.redis.database=1 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 mybatis.autosql.default-dialect=mysql
app.redis.prefix=payment app.redis.prefix=payment

@ -2,12 +2,17 @@ package au.com.royalpay.payment.manage.ofei.core.impl;
import au.com.royalpay.payment.manage.ofei.core.OfeiClient; import au.com.royalpay.payment.manage.ofei.core.OfeiClient;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; 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.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal;
import javax.annotation.Resource; import javax.annotation.Resource;
/** /**
@ -19,9 +24,21 @@ import javax.annotation.Resource;
public class OfeiClientImplTest { public class OfeiClientImplTest {
@Resource @Resource
private OfeiClient ofeiClient; private OfeiClient ofeiClient;
@Resource
private MongoTemplate mongoTemplate;
@Test @Test
public void qbTopUp() throws Exception { public void qbTopUp() throws Exception {
ofeiClient.qbTopUp("10","164851225"); 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);
}
} }
Loading…
Cancel
Save