Merge remote-tracking branch 'origin/master'

master
eason.qian 7 years ago
commit ea7e9506f1

@ -21,7 +21,7 @@ public class SysConfigController {
@Resource @Resource
private ClearDateManager clearDateManager; private ClearDateManager clearDateManager;
@ManagerMapping(value = "/base", method = RequestMethod.GET, role = ManagerRole.DEVELOPER) @ManagerMapping(value = "/base", method = RequestMethod.GET)
public JSONObject getBaseConfig() { public JSONObject getBaseConfig() {
return sysConfigManager.getSysConfig(); return sysConfigManager.getSysConfig();
} }

@ -1,6 +1,10 @@
package au.com.royalpay.payment.manage.task; package au.com.royalpay.payment.manage.task;
import java.util.ArrayList;
import java.util.List; 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;
@ -24,11 +28,32 @@ public class CustomerImpressionTask {
@Resource @Resource
private CustomerImpressionService customerImpressionService; private CustomerImpressionService customerImpressionService;
private ThreadPoolExecutor generatePool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@Scheduled(cron = "0 0 3 * * ?") @Scheduled(cron = "0 0 3 * * ?")
public void generate() { public void generate() {
List<JSONObject> clients = clientMapper.listValidClient(); List<JSONObject> clients = clientMapper.listValidClient();
clients.forEach(p -> { List<List<JSONObject>> splitList = new ArrayList<>();
customerImpressionService.generate(p.getIntValue("client_id")); 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));
}
}
for (List<JSONObject> splitClients : splitList) {
Runnable task = () -> splitClients.forEach((p)->{
System.out.println("当前执行到"+p.getIntValue("client_id"));
customerImpressionService.generate(p.getIntValue("client_id"));
});
generatePool.execute(task);
}
generatePool.shutdown();
try {
generatePool.awaitTermination(5, TimeUnit.HOURS);
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
} }

@ -1,9 +1,12 @@
package au.com.royalpay.payment.manage.apps.core.impls; package au.com.royalpay.payment.manage.apps.core.impls;
import au.com.royalpay.payment.manage.apps.core.CustomerImpressionService; import java.util.ArrayList;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.alibaba.fastjson.JSONObject; import javax.annotation.Resource;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -11,9 +14,10 @@ import org.springframework.boot.test.context.SpringBootTest;
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.util.List; import com.alibaba.fastjson.JSONObject;
import javax.annotation.Resource; import au.com.royalpay.payment.manage.apps.core.CustomerImpressionService;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
/** /**
* Created by wangning on 05/01/2018. * Created by wangning on 05/01/2018.
@ -26,6 +30,9 @@ public class CustomerImpressionImplTest {
private CustomerImpressionService customerImpression; private CustomerImpressionService customerImpression;
@Resource @Resource
private ClientMapper clientMapper; private ClientMapper clientMapper;
private ThreadPoolExecutor generatePool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@Test @Test
public void generate() throws Exception { public void generate() throws Exception {
customerImpression.generate(9); customerImpression.generate(9);
@ -34,9 +41,28 @@ public class CustomerImpressionImplTest {
@Test @Test
public void generateAll(){ public void generateAll(){
List<JSONObject> clients = clientMapper.listValidClient(); List<JSONObject> clients = clientMapper.listValidClient();
clients.forEach(p -> { List<List<JSONObject>> splitList = new ArrayList<>();
customerImpression.generate(p.getIntValue("client_id")); 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));
}
}
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…
Cancel
Save