1;新增线程管理 批量同步数据
This commit is contained in:
parent
6d9480ad5d
commit
5b6112890f
|
@ -84,4 +84,29 @@ public class ThreadPoolConfig
|
||||||
executor.initialize();
|
executor.initialize();
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//1、自定义asyncServiceExecutor线程池
|
||||||
|
@Bean(name = "asyncDayServiceExecutor")
|
||||||
|
public ThreadPoolTaskExecutor asyncDayServiceExecutor() {
|
||||||
|
System.out.println(("start asyncDayServiceExecutor......"));
|
||||||
|
//在这里修改
|
||||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
|
//配置核心线程数
|
||||||
|
executor.setCorePoolSize(corePoolSize);
|
||||||
|
//配置最大线程数
|
||||||
|
executor.setMaxPoolSize(maxPoolSize);
|
||||||
|
//设置线程空闲等待时间 s
|
||||||
|
executor.setKeepAliveSeconds(keepAliveSeconds);
|
||||||
|
//配置队列大小 设置任务等待队列的大小
|
||||||
|
executor.setQueueCapacity(queueCapacity);
|
||||||
|
//配置线程池中的线程的名称前缀
|
||||||
|
//设置线程池内线程名称的前缀-------阿里编码规约推荐--方便出错后进行调试
|
||||||
|
executor.setThreadNamePrefix("youshi-day-schedule-pool-%d");
|
||||||
|
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
|
||||||
|
// CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
|
||||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
|
||||||
|
//执行初始化
|
||||||
|
executor.initialize();
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.ruoyi.business.service.IAiService;
|
||||||
import com.ruoyi.business.service.IBusFifteenInfoService;
|
import com.ruoyi.business.service.IBusFifteenInfoService;
|
||||||
import com.ruoyi.business.service.IMeituanService;
|
import com.ruoyi.business.service.IMeituanService;
|
||||||
import com.ruoyi.business.service.impl.AsyncTaskImpl;
|
import com.ruoyi.business.service.impl.AsyncTaskImpl;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Component("ryTask")
|
@Component("ryTask")
|
||||||
public class RyTask {
|
public class RyTask {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -50,7 +52,10 @@ public class RyTask {
|
||||||
* 统计昨日营销数 每天8点执行一次
|
* 统计昨日营销数 每天8点执行一次
|
||||||
*/
|
*/
|
||||||
public void getReturnInfo() {
|
public void getReturnInfo() {
|
||||||
|
log.error("***********history************************");
|
||||||
|
iMeituanService.getComments(null);
|
||||||
iMeituanService.getReturnInfo(null);
|
iMeituanService.getReturnInfo(null);
|
||||||
|
log.error("***********historyEnd************************");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.business.service;
|
package com.ruoyi.business.service;
|
||||||
|
|
||||||
import com.ruoyi.business.domain.BusOrderInfo;
|
import com.ruoyi.business.domain.BusOrderInfo;
|
||||||
|
import com.ruoyi.business.domain.BusStoreInfo;
|
||||||
import com.ruoyi.business.domain.SysCookie;
|
import com.ruoyi.business.domain.SysCookie;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
@ -61,4 +62,6 @@ public interface IMeituanService {
|
||||||
|
|
||||||
String getComment(Long id);
|
String getComment(Long id);
|
||||||
String receiveTime(String getUrl,String storeCode,String cookie,String orderNo);
|
String receiveTime(String getUrl,String storeCode,String cookie,String orderNo);
|
||||||
|
|
||||||
|
void getCOne(BusStoreInfo store);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,21 @@ public class AsyncTaskImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Async("asyncDayServiceExecutor")
|
||||||
|
public void executeDayAsync(List<BusStoreInfo> busStoreInfoList,
|
||||||
|
CountDownLatch countDownLatch) {
|
||||||
|
try{
|
||||||
|
log.info("=============start executeDayAsync=============");
|
||||||
|
//异步线程要做的事情
|
||||||
|
for (BusStoreInfo store : busStoreInfoList) {
|
||||||
|
iMeituanService.getCOne(store);
|
||||||
|
}
|
||||||
|
log.error("==================end executeDayAsync===============");
|
||||||
|
}finally {
|
||||||
|
countDownLatch.countDown();// 很关键, 无论上面程序是否异常必须执行countDown,否则await无法释放
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void clearStoreKey(){
|
public void clearStoreKey(){
|
||||||
LocalDate localDate = LocalDate.now();
|
LocalDate localDate = LocalDate.now();
|
||||||
LocalDate prevDay = localDate.minusDays(1);
|
LocalDate prevDay = localDate.minusDays(1);
|
||||||
|
|
|
@ -198,7 +198,7 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
if("3".equals(storeInfo.getSelfDeliveryStatus())){
|
if("3".equals(storeInfo.getSelfDeliveryStatus())){
|
||||||
storeInfo.setSelfDeliveryStatus("1");
|
storeInfo.setSelfDeliveryStatus("1");
|
||||||
}
|
}
|
||||||
busStoreInfoService.updateBusStoreInfo(storeInfo);
|
busStoreInfoMapper.updateBusStoreInfo(storeInfo);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "授权失败,请联系管理员!";
|
return "授权失败,请联系管理员!";
|
||||||
|
@ -223,28 +223,42 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
if(accountName != null){
|
if(accountName != null){
|
||||||
busStoreInfo.setBindUser(SecurityUtils.getUsername());
|
busStoreInfo.setBindUser(SecurityUtils.getUsername());
|
||||||
}
|
}
|
||||||
List<BusStoreInfo> busStoreInfoList = busStoreInfoMapper.selectBusStoreInfoListA(busStoreInfo);
|
List<BusStoreInfo> busStoreInfoList = busStoreInfoMapper.selectBusStoreInfoList(busStoreInfo);
|
||||||
for (BusStoreInfo store : busStoreInfoList) {
|
long startTime = System.currentTimeMillis(); // 开始时间
|
||||||
Boolean flag1 = getScoreOne(store);
|
List<List<BusStoreInfo>> list1= SplitListUtils.pagingList(busStoreInfoList,20); //拆分集合
|
||||||
if (!flag1) {
|
CountDownLatch countDownLatch = new CountDownLatch(list1.size());
|
||||||
log.error("获取评分信息返回错误...");
|
for (List<BusStoreInfo> list2 : list1) {
|
||||||
}
|
asyncTask.executeDayAsync(list2,countDownLatch);
|
||||||
Boolean flag2 = getCommentsOne(store);
|
}
|
||||||
if (!flag2) {
|
try {
|
||||||
log.error("获取好评信息返回错误...");
|
countDownLatch.await(); //保证之前的所有的线程都执行完成,才会走下面的;
|
||||||
}
|
long endTime = System.currentTimeMillis(); //结束时间
|
||||||
Boolean flag3 = yesterdayCountOne(store);
|
log.error(("executeDayAsync一共耗时time: " + (endTime - startTime) / 1000 + " s"));
|
||||||
if (!flag3) {
|
// 这样就可以在下面拿到所有线程执行完的集合结果
|
||||||
log.error("获取昨日单量信息返回错误...");
|
} catch (Exception e) {
|
||||||
}
|
log.error("executeDayAsync阻塞异常:"+e.getMessage());
|
||||||
Boolean flag4 = updateDayInfo(store);
|
|
||||||
if (!flag4) {
|
|
||||||
log.error("获取昨日营销信息返回错误...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getCOne(BusStoreInfo store){
|
||||||
|
Boolean flag1 = getScoreOne(store);
|
||||||
|
if (!flag1) {
|
||||||
|
log.error("获取评分信息返回错误...");
|
||||||
|
}
|
||||||
|
Boolean flag2 = getCommentsOne(store);
|
||||||
|
if (!flag2) {
|
||||||
|
log.error("获取好评信息返回错误...");
|
||||||
|
}
|
||||||
|
Boolean flag3 = yesterdayCountOne(store);
|
||||||
|
if (!flag3) {
|
||||||
|
log.error("获取昨日单量信息返回错误...");
|
||||||
|
}
|
||||||
|
Boolean flag4 = updateDayInfo(store);
|
||||||
|
if (!flag4) {
|
||||||
|
log.error("获取昨日营销信息返回错误...");
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 获取昨日评分、好评、有效单量
|
* 获取昨日评分、好评、有效单量
|
||||||
*
|
*
|
||||||
|
@ -268,8 +282,7 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
}
|
}
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
// @Resource(name = "asyncServiceExecutor")
|
|
||||||
// private ThreadPoolTaskExecutor asyncServiceExecutor;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AsyncTaskImpl asyncTask;
|
private AsyncTaskImpl asyncTask;
|
||||||
/**
|
/**
|
||||||
|
@ -360,7 +373,7 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
}
|
}
|
||||||
} else if ("1001".equals(code)) {
|
} else if ("1001".equals(code)) {
|
||||||
storeInfo.setGrantStatus("2");
|
storeInfo.setGrantStatus("2");
|
||||||
busStoreInfoService.updateBusStoreInfo(storeInfo);
|
busStoreInfoMapper.updateBusStoreInfo(storeInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -842,7 +855,6 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getReturnInfo(Long id) {
|
public void getReturnInfo(Long id) {
|
||||||
log.error("***********history************************");
|
|
||||||
List<BusStoreDayHistoryInfo> addList = new ArrayList<>();
|
List<BusStoreDayHistoryInfo> addList = new ArrayList<>();
|
||||||
List<BusStoreDayHistoryInfo> editList = new ArrayList<>();
|
List<BusStoreDayHistoryInfo> editList = new ArrayList<>();
|
||||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
@ -851,26 +863,20 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
if (id != null){
|
if (id != null){
|
||||||
storeInfo.setStoreId(id);
|
storeInfo.setStoreId(id);
|
||||||
}
|
}
|
||||||
// List<BusStoreInfo> storeInfoList = busStoreInfoMapper.selectBusStoreInfoListA(storeInfo);
|
|
||||||
List<BusStoreDayInfo> list1 = busStoreDayInfoMapper.selectBusStoreDayInfoListByDate(storeInfo.getStoreId(),date.format(dateTimeFormatter));
|
List<BusStoreDayInfo> list1 = busStoreDayInfoMapper.selectBusStoreDayInfoListByDate(storeInfo.getStoreId(),date.format(dateTimeFormatter));
|
||||||
for (BusStoreDayInfo busStoreDayInfo : list1) {
|
for (BusStoreDayInfo busStoreDayInfo : list1) {
|
||||||
// if (list1.size() == 1) {
|
|
||||||
// BusStoreDayInfo busStoreDayInfo = list1.get(0);
|
|
||||||
List<BusStoreDayHistoryInfo> list2 = busStoreDayHistoryInfoMapper.selectBusStoreDayHistoryInfoListByDate(busStoreDayInfo.getStoreId(),date.format(dateTimeFormatter));
|
List<BusStoreDayHistoryInfo> list2 = busStoreDayHistoryInfoMapper.selectBusStoreDayHistoryInfoListByDate(busStoreDayInfo.getStoreId(),date.format(dateTimeFormatter));
|
||||||
if (list2.size() == 0){
|
if (list2.size() == 0){
|
||||||
BusStoreDayHistoryInfo target = new BusStoreDayHistoryInfo();
|
BusStoreDayHistoryInfo target = new BusStoreDayHistoryInfo();
|
||||||
BeanUtils.copyProperties(busStoreDayInfo, target);
|
BeanUtils.copyProperties(busStoreDayInfo, target);
|
||||||
target.setId(null);
|
target.setId(null);
|
||||||
target.setCreateTime(Date.from(date.atZone(ZoneId.systemDefault()).toInstant()));
|
target.setCreateTime(Date.from(date.atZone(ZoneId.systemDefault()).toInstant()));
|
||||||
// busStoreDayHistoryInfoMapper.insertBusStoreDayHistoryInfo(target);
|
|
||||||
addList.add(target);
|
addList.add(target);
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
if(addList.size()>0){
|
if(addList.size()>0){
|
||||||
busStoreDayHistoryInfoMapper.insertBatchStoreDayHistoryInfo(addList);
|
busStoreDayHistoryInfoMapper.insertBatchStoreDayHistoryInfo(addList);
|
||||||
}
|
}
|
||||||
log.error("***********historyEnd************************");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRate(int a, int b){
|
private String getRate(int a, int b){
|
||||||
|
@ -954,7 +960,7 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
}
|
}
|
||||||
}else if ("1001".equals(jsonObject.getString("code"))) {
|
}else if ("1001".equals(jsonObject.getString("code"))) {
|
||||||
store.setGrantStatus("2");
|
store.setGrantStatus("2");
|
||||||
busStoreInfoService.updateBusStoreInfo(store);
|
busStoreInfoMapper.updateBusStoreInfo(store);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1000,7 +1006,7 @@ public class MeituanServiceImpl implements IMeituanService {
|
||||||
if ("1001".equals(code)) {
|
if ("1001".equals(code)) {
|
||||||
log.error("掉线"+result);
|
log.error("掉线"+result);
|
||||||
store.setGrantStatus("2");
|
store.setGrantStatus("2");
|
||||||
busStoreInfoService.updateBusStoreInfo(store);
|
busStoreInfoMapper.updateBusStoreInfo(store);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
JSONArray array = jsonObject.getJSONObject("data").getJSONArray("list");
|
JSONArray array = jsonObject.getJSONObject("data").getJSONArray("list");
|
||||||
|
|
Loading…
Reference in New Issue