SSM项目中定时任务中批数据处理的实现。

SSM项目中定时任务中批数据处理的实现。

1.POM文件添加依赖
	<!-- Quartz -->
		<dependency>
			 <groupId>org.quartz-scheduler</groupId>
			 <artifactId>quartz</artifactId>
			 <version>1.8.4</version>
		</dependency>
2.添加定时任务配置文件xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
        >
         
    <!-- 线程执行器配置,用于任务注册 -->
	<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
		 <property name="corePoolSize" value="10" />
		 <property name="maxPoolSize" value="100" />
		 <property name="queueCapacity" value="500" />
	</bean>

 <!--每天晚上12点定时向C端同步新增会员的相关信息 0 0/3 * * * ?    0 0 0 * * ? *-->
   <!-- <bean id="UpdateOmoMemberToCTaskMa" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <bean
                    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                <property name="targetObject">
                    <bean
                            class="com.omo.job.controller.UpdateOmoMemberToCTask" />
                </property>
                <property name="targetMethod" value="excute" />
            </bean>
        </property>
        <property name="cronExpression" value="0 0 0 * * ? *" />
    </bean>-->

	<!-- 设置调度 -->
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		 <property name="triggers">
			  <list>
              <ref bean="UpdateOmoMemberToCTaskMa" />
			  </list>
		 </property>
		 <property name="taskExecutor" ref="executor" />
	</bean
</beans>
3.定时任务代码:
import com.omo.facade.OmoMemberService;
import com.omo.vo.OmoMember;
import com.omo.vo.ResultMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Bob
 * @Date 2019/4/18 17:29
 */
public class UpdateOmoMemberToCTask {
     @Autowired
     private OmoMemberService omoMemberService;
    
    Logger logger = LoggerFactory.getLogger(UpdateOmoMemberToCTask.class);
    static boolean IS_RUNNING;
    //每次发100
    static Integer limitNum =150;
        OmoMember omoMember;
    
    public void excute() {
        try {
            logger.info("同步omo会员信息到C端信息开始。。。。");
            Long asqId = 0L;
            List<OmoMember> entitys = new ArrayList<>();
            //查询会员记录准备发送到C端新增会员的接口
            do {
                // 查询待发送至hro用户信息
                Map<String, Object> param = new HashMap<String, Object>();
                param.put("limitNum",limitNum);
                param.put("asqId",asqId);
                //需要添加各种条件
               entitys = omoMemberService.getMemberAboutInfo(param);
                if(entitys==null&&entitys.size()==0){
                    return;
                }
                for (OmoMember omoMember : entitys) {
                    try {
                        logger.info("omo新增会员信息同步到C端定时任务开始UpdateOmoMemberToCTask:"+omoMember.getMobile());
                        this.omoMember=omoMember;
                        //通过队列activeMQ发送信息到C端
                        ResultMessage resultMessage = omoMemberService.setMemberAboutInfo(omoMember);
                    } catch (Exception e) {
                        // TODO: handle exception
                        logger.error("新增会员到C端定时任务失败,"+omoMember.getMobile()+","+e.toString());
                    }
                }
                asqId = (asqId > omoMember.getId()) ? asqId :omoMember.getId();
            }while (null!=entitys && entitys.size()==limitNum.intValue());
        } catch (Exception e) {
            // TODO: handle exception
            logger.error("新增会员到C端定时任务失败"+e.toString());
        }
    }
}
具体的Service层代码以及sql信息:
 @Override
    public List<OmoMember> getMemberAboutInfo(Map<String, Object> searchParams) {
        return omoMemberDao.getMemberAboutInfo(searchParams);
    }
<!-- 查询需要调用C端新增会员接口时要传给C端的会员相关信息-->
    <select id="getMemberAboutInfo" resultMap="getMemberAboutInfo">
           SELECT om.*, (SELECT rip.id FROM resume_intention_place rip WHERE  rip.resume_id = om.resume_id ORDER BY rip.id DESC LIMIT 1 ) AS ripid
        FROM
        omo_member om
        WHERE
        om.id >= #{asqId}
        GROUP BY
        om.id
        ORDER BY
        om.id ASC
        LIMIT #{limitNum}
    </select>

ssm项目中定时任务中批数据的处理,谢谢。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值