commit
615064d1b9
@ -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;
|
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 javax.annotation.Resource;
|
||||||
|
|
||||||
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.redis.core.BoundListOperations;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
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 com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
import au.com.royalpay.payment.manage.apps.core.CustomerImpressionService;
|
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
|
||||||
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by wangning on 05/01/2018.
|
* Created by wangning on 05/01/2018.
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ActiveProfiles({"production","alipay","wechat","jd","bestpay"})
|
@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class CustomerImpressionImplTest {
|
public class CustomerImpressionImplTest {
|
||||||
@Resource
|
@Resource
|
||||||
private CustomerImpressionService customerImpression;
|
private OrderMapper orderMapper;
|
||||||
@Resource
|
|
||||||
private ClientMapper clientMapper;
|
|
||||||
|
|
||||||
private ThreadPoolExecutor generatePool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
|
||||||
|
|
||||||
@Test
|
@Resource
|
||||||
public void generate() throws Exception {
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
customerImpression.generate(9);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateAll(){
|
public void redisQueue() {
|
||||||
List<JSONObject> clients = clientMapper.listValidClient();
|
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
|
||||||
List<List<JSONObject>> splitList = new ArrayList<>();
|
JSONObject order = orderMapper.find("00009201711300930013961422");
|
||||||
for (int i = 0; i < clients.size(); i+=200) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
if(i+200>clients.size()){
|
ops.rightPush(order.toJSONString());
|
||||||
splitList.add(clients.subList(i,clients.size()));
|
|
||||||
}else {
|
|
||||||
splitList.add(clients.subList(i,i+200));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
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