批量数据同步

1、核心代码:

/**
	 * 
	* @Title: synStuDataToPorsche
	* @Description: 同步销售学生数据到量子系统
	* @return
	* @throws
	 */
	public String synStuDataToPorsche() {
		// 查询学生表数据数量
		while(studentWechatService.countStudentWechat()>0) {
			List<StudentWechatEntity> stuWechatList = studentWechatService.selectStudentWechatList(0, synPageSize);
			if (CollectionUtils.isNotEmpty(stuWechatList)) {
				List<Long> idList=stuWechatList.stream().map(t -> t.getId()).collect(Collectors.toList());
				studentWechatService.batchUpdateEntity(idList);
				dealStuData(stuWechatList);
			}
		}
		return "操作成功";
	}
	
	/**
	 * 
	* @Title: synGroupStuDataToPorsche
	* @Description: 同步销售群学生数据到量子系统
	* @param index
	* @return
	* @throws
	 */
	public String synGroupStuDataToPorsche() {
		while(studentWechatGroupService.countGroupStudentWechat()>0) {
			List<StudentWechatGroupEntity> groupStuWechatList = studentWechatGroupService.selectStudentWechatGroupList(0,
					synPageSize);
			if (CollectionUtils.isNotEmpty(groupStuWechatList)) {
				List<Long> idList=groupStuWechatList.stream().map(t -> t.getId()).collect(Collectors.toList());
				studentWechatGroupService.batchUpdateEntity(idList);
				dealGroupData(groupStuWechatList);
			}
		}
		return "操作成功";
	}

	@Async("pushSaleDataToEsThreadExecutor")
	public void dealStuData(List<StudentWechatEntity> stuWechatList) {
		for (StudentWechatEntity entity : stuWechatList) {
			if (StringUtils.isBlank(entity.getWxNo()) || entity.getState() != 1 || entity.getIsDeleted() == 1
					|| entity.getDealStatus() == 1) {
				continue;
			}
			StudentRelatedDTO studentRelatedDTO = new StudentRelatedDTO();
			studentRelatedDTO.setWxNo(entity.getWxNo());
			studentRelatedDTO.setState(entity.getState());
			studentRelatedDTO.setStuId(entity.getStuId());
			studentRelatedDTO.setWxName(entity.getWxName());
			studentRelatedDTO.setDeleted(entity.getIsDeleted());
			stuRelatedBiz.dealStuData(JSONObject.toJSONString(studentRelatedDTO));
		}
	}
	
	

	@Async("pushSaleDataToEsThreadExecutor")
	private void dealGroupData(List<StudentWechatGroupEntity> groupStuWechatList) {
		for (StudentWechatGroupEntity entity : groupStuWechatList) {
			if (entity.getState() != 1 || entity.getDeleted() == 1 || entity.getDealStatus() == 1) {
				continue;
			}
			GroupStudentRelatedDTO groupStudentRelatedDTO = new GroupStudentRelatedDTO();
			groupStudentRelatedDTO.setGroupId(entity.getGroupId());
			groupStudentRelatedDTO.setGroupName(entity.getGroupName());
			groupStudentRelatedDTO.setState(entity.getState());
			groupStudentRelatedDTO.setStuId(entity.getStuId());
			groupStudentRelatedDTO.setDeleted(entity.getDeleted());
			groupStuRelatedBiz.dealGroupStuData(JSONObject.toJSONString(groupStudentRelatedDTO));
		}
	}

2、线程池配置:

 @Value("${push.sale.es.thread.core.poolsize:10}")
    private int pushSaleEsThreadCorePoolSize;
    @Value("${push.sale.es.thread.max.poolsize:25}")
    private int pushSaleEsThreadMaxPoolSize;
    @Value("${push.sale.es.thread.queue.capacity:100}")
    private int pushSaleEsThreadQueueCapacity;
    @Value("${push.sale.es.thread.keepalive.sec:600}")
    private int pushSaleEsThreadKeepAliveSec;
    
    @Bean("pushSaleDataToEsThreadExecutor")
    public Executor pushStuDataToEsThreadExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(pushSaleEsThreadCorePoolSize);
        executor.setMaxPoolSize(pushSaleEsThreadMaxPoolSize);
        executor.setQueueCapacity(pushSaleEsThreadQueueCapacity);
        executor.setKeepAliveSeconds(pushSaleEsThreadKeepAliveSec);
        executor.setThreadNamePrefix("pushSaleDataToEsThread-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(60);
        return executor;
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值