commit
48184d9b60
@ -0,0 +1,28 @@
|
||||
package au.com.royalpay.payment.manage.apps.events.listeners;
|
||||
|
||||
import au.com.royalpay.payment.core.events.AfterPaymentFinishEvent;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.data.redis.core.BoundListOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Created by wangning on 17/01/2018.
|
||||
*/
|
||||
@Service
|
||||
public class AfterPaymentFinishListener implements ApplicationListener<AfterPaymentFinishEvent> {
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(AfterPaymentFinishEvent event) {
|
||||
JSONObject order = event.getFinishedEvent().getOrder();
|
||||
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
|
||||
ops.rightPush(order.toJSONString());
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Created by wangning on 17/01/2018.
|
||||
*/
|
||||
package au.com.royalpay.payment.manage.apps.events;
|
@ -1,68 +1,39 @@
|
||||
package au.com.royalpay.payment.manage.apps.core.impls;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.BoundListOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import au.com.royalpay.payment.manage.apps.core.CustomerImpressionService;
|
||||
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
||||
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
|
||||
|
||||
/**
|
||||
* Created by wangning on 05/01/2018.
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ActiveProfiles({"production","alipay","wechat","jd","bestpay"})
|
||||
@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
|
||||
@RunWith(SpringRunner.class)
|
||||
public class CustomerImpressionImplTest {
|
||||
@Resource
|
||||
private CustomerImpressionService customerImpression;
|
||||
@Resource
|
||||
private ClientMapper clientMapper;
|
||||
|
||||
private ThreadPoolExecutor generatePool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Test
|
||||
public void generate() throws Exception {
|
||||
customerImpression.generate(9);
|
||||
}
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Test
|
||||
public void generateAll(){
|
||||
List<JSONObject> clients = clientMapper.listValidClient();
|
||||
List<List<JSONObject>> splitList = new ArrayList<>();
|
||||
for (int i = 0; i < clients.size(); i+=200) {
|
||||
if(i+200>clients.size()){
|
||||
splitList.add(clients.subList(i,clients.size()));
|
||||
}else {
|
||||
splitList.add(clients.subList(i,i+200));
|
||||
}
|
||||
public void redisQueue() {
|
||||
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
|
||||
JSONObject order = orderMapper.find("00009201711300930013961422");
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
ops.rightPush(order.toJSONString());
|
||||
|
||||
}
|
||||
for (List<JSONObject> splitClients : splitList) {
|
||||
Runnable task = () -> splitClients.forEach((p)->{
|
||||
System.out.println("当前执行到"+p.getIntValue("client_id"));
|
||||
customerImpression.generate(p.getIntValue("client_id"));
|
||||
});
|
||||
generatePool.execute(task);
|
||||
}
|
||||
generatePool.shutdown();
|
||||
try {
|
||||
generatePool.awaitTermination(5, TimeUnit.HOURS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue