3 changed files with 170 additions and 86 deletions
@ -0,0 +1,19 @@ |
|||||
|
package com.elink.esua.epdc.task.screen; |
||||
|
|
||||
|
/** |
||||
|
* 大屏项目信息统计上报 |
||||
|
* |
||||
|
* @Author: wangtong |
||||
|
* @Date: 2021/2/24 14:16 |
||||
|
*/ |
||||
|
public interface ScreenProjectPushTask { |
||||
|
/** |
||||
|
* 大屏数据推送 |
||||
|
* |
||||
|
* @param param 入参 |
||||
|
* @return void |
||||
|
* @author wangtong |
||||
|
* @since 2021/2/24 14:16 |
||||
|
*/ |
||||
|
void run(String param); |
||||
|
} |
@ -0,0 +1,140 @@ |
|||||
|
package com.elink.esua.epdc.task.screen; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.tools.utils.DateUtils; |
||||
|
import com.elink.esua.epdc.dao.ScreenRecordDao; |
||||
|
import com.elink.esua.epdc.dto.screen.form.ScreenProjectFormDTO; |
||||
|
import com.elink.esua.epdc.entity.ScreenRecordEntity; |
||||
|
import com.elink.esua.epdc.feign.AnalysisFeignClient; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.concurrent.Callable; |
||||
|
import java.util.concurrent.ExecutorService; |
||||
|
import java.util.concurrent.Executors; |
||||
|
import java.util.concurrent.Future; |
||||
|
|
||||
|
/** |
||||
|
* @program: esua-epdc |
||||
|
* @description: 大屏【事件/项目分析】信息统计上报 |
||||
|
* @author: wangtong |
||||
|
* @create: 2021-02-24 13:48 |
||||
|
**/ |
||||
|
@Component("screenProjectPushTask") |
||||
|
public class ScreenProjectPushTaskImpl implements ScreenProjectPushTask { |
||||
|
|
||||
|
private final Logger logger = LoggerFactory.getLogger(getClass()); |
||||
|
|
||||
|
private static final ExecutorService service = Executors.newFixedThreadPool(100); |
||||
|
|
||||
|
@Autowired |
||||
|
private AnalysisFeignClient analysisFeignClient; |
||||
|
|
||||
|
@Autowired |
||||
|
private ScreenRecordDao screenRecordDao; |
||||
|
|
||||
|
@Override |
||||
|
public void run(String param) { |
||||
|
for (int i = 0; i < 2; i++) { |
||||
|
createThread(i); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Integer createThread(Integer methodIndex) { |
||||
|
Future<Integer> future = service.submit(new Callable<Integer>() { |
||||
|
@Override |
||||
|
public Integer call() throws Exception { |
||||
|
Thread.sleep(200); |
||||
|
if (methodIndex == 0) { |
||||
|
uploadProjectInfo(); |
||||
|
} else if (methodIndex == 1) { |
||||
|
uploadProjectProcess(); |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
}); |
||||
|
Integer isSuccess = 0; |
||||
|
try { |
||||
|
isSuccess = future.get(); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
return isSuccess; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return void |
||||
|
* @Description 项目信息上报 |
||||
|
* @Author songyunpeng |
||||
|
* @Date 2021/2/24 |
||||
|
* @Param [] |
||||
|
**/ |
||||
|
private void uploadProjectInfo() { |
||||
|
// 方法名
|
||||
|
String methodName = Thread.currentThread().getStackTrace()[2].getMethodName(); |
||||
|
logger.info("<" + methodName + "|项目信息上报>定时任务开始执行"); |
||||
|
//获取上次统计时间
|
||||
|
Map<String, Object> param = new HashMap<>(); |
||||
|
param.put("JOB_NAME", "uploadProjectInfo"); |
||||
|
List<ScreenRecordEntity> screenRecordEntities = screenRecordDao.selectByMap(param); |
||||
|
ScreenRecordEntity screenRecordEntity = new ScreenRecordEntity(); |
||||
|
ScreenProjectFormDTO screenProjectFormDTO = new ScreenProjectFormDTO(); |
||||
|
if (screenRecordEntities == null || screenRecordEntities.size() == 0) { |
||||
|
screenProjectFormDTO.setYearMonthDay("2020-01-01"); |
||||
|
} else { |
||||
|
screenRecordEntity = screenRecordEntities.get(0); |
||||
|
screenProjectFormDTO.setYearMonthDay(DateUtils.format(screenRecordEntity.getStatisticsTime(), DateUtils.DATE_PATTERN)); |
||||
|
} |
||||
|
//记录此次统计时间 并更新时间或者新增
|
||||
|
screenRecordEntity.setStatisticsTime(DateUtils.addDateDays(new Date(), -1)); |
||||
|
if (StringUtils.isNotBlank(screenRecordEntity.getId())) { |
||||
|
screenRecordDao.updateById(screenRecordEntity); |
||||
|
} else { |
||||
|
screenRecordEntity.setJobName("uploadProjectInfo"); |
||||
|
screenRecordDao.insert(screenRecordEntity); |
||||
|
} |
||||
|
analysisFeignClient.uploadProjectInfo(screenProjectFormDTO); |
||||
|
logger.info("<" + methodName + "|项目信息上报>定时任务执行结束"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return void |
||||
|
* @Description 项目处理流程信息上报 |
||||
|
* @Author songyunpeng |
||||
|
* @Date 2021/2/24 |
||||
|
* @Param [] |
||||
|
**/ |
||||
|
private void uploadProjectProcess() { |
||||
|
// 方法名
|
||||
|
String methodName = Thread.currentThread().getStackTrace()[2].getMethodName(); |
||||
|
logger.info("<" + methodName + "|项目处理流程信息上报>定时任务开始执行"); |
||||
|
//获取上次统计时间
|
||||
|
Map<String, Object> param = new HashMap<>(); |
||||
|
param.put("JOB_NAME", "uploadProjectProcess"); |
||||
|
List<ScreenRecordEntity> screenRecordEntities = screenRecordDao.selectByMap(param); |
||||
|
ScreenRecordEntity screenRecordEntity = new ScreenRecordEntity(); |
||||
|
ScreenProjectFormDTO screenProjectFormDTO = new ScreenProjectFormDTO(); |
||||
|
if (screenRecordEntities == null || screenRecordEntities.size() == 0) { |
||||
|
screenProjectFormDTO.setYearMonthDay("2020-01-01"); |
||||
|
} else { |
||||
|
screenRecordEntity = screenRecordEntities.get(0); |
||||
|
screenProjectFormDTO.setYearMonthDay(DateUtils.format(screenRecordEntity.getStatisticsTime(), DateUtils.DATE_PATTERN)); |
||||
|
} |
||||
|
//记录此次统计时间 并更新时间或者新增
|
||||
|
screenRecordEntity.setStatisticsTime(DateUtils.addDateDays(new Date(), -1)); |
||||
|
if (StringUtils.isNotBlank(screenRecordEntity.getId())) { |
||||
|
screenRecordDao.updateById(screenRecordEntity); |
||||
|
} else { |
||||
|
screenRecordEntity.setJobName("uploadProjectProcess"); |
||||
|
screenRecordDao.insert(screenRecordEntity); |
||||
|
} |
||||
|
analysisFeignClient.uploadProjectProcess(screenProjectFormDTO); |
||||
|
logger.info("<" + methodName + "|项目处理流程信息上报>定时任务执行结束"); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue