<?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:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<task:annotation-driven /> <!-- 定时器开关-->
<!-- <bean id="jobDetail" class="com.wanke.manager.quartz.TestQuartz"></bean>
<task:scheduled-tasks>
这里表示的是每隔五秒执行一次
<task:scheduled ref="jobDetail" method="show" cron="*/5 * * * * ?" />
<task:scheduled ref="jobDetail" method="print" cron="*/10 * * * * ?"/>
</task:scheduled-tasks> -->
<!-- 自动扫描的包名 -->
<context:component-scan base-package="com.wanke.manager.quartz" />
</beans>
后台
package com.wanke.manager.quartz;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.wanke.common.third.express.ExpressData;
import com.wanke.common.third.sms.Sms;
import com.wanke.manager.service.ExpressService;
import com.wanke.manager.service.OrderService;
import com.wanke.model.Express;
import com.wanke.model.Order;
/**
* 基于注解的定时器
*/
@Component
public class UserQuartz {
private static final Logger LOGGER = LoggerFactory.getLogger(UserQuartz.class);
@Autowired
public ExpressService expressService;
@Autowired
public OrderService orderService;
// @Scheduled(cron = "0 0 1 * * ?")//每天凌晨1点整
// @Scheduled(cron = "0 30 0 * * ?")//每天凌晨0点30分
// @Scheduled(cron = "0 */60 * * * ?")//1小时处理一次
/**
* 定时计算。每天凌晨 08:00 执行一次
*/
@Scheduled(cron = "0 0 8 * * ?")
public void remindUser() {
// 每天早上8点给用户发送短息提示用户吃药.....
//发送订单成功短信
//单独测试一个用户是否能正常发送短息
String mobile = "13655459823";
String name = "范女士";
String content = "尊敬的"+name+"您好!请按时服用为期一个月的高血压精准管理产品,万克医学祝您体验愉快!咨询电话010-56021932";
Boolean bool = Sms.sendBase(mobile, content);
//张杰
Sms.sendBase("13552593242", content);
//宏伟
Sms.sendBase("13260434372", content);
if(bool){
LOGGER.info(">>>>>>每天早上8:00发送用户吃药提醒短信成功:mobile="+mobile);
}else{
LOGGER.error(">>>>>>每天早上8:00发送用户吃药提醒短信失败:mobile="+mobile);
}
//以下为正常逻辑
//type----寄送类型(0-采样盒寄出,1-采样盒寄回,2-产品寄出
//Status----0-未寄出,1-已寄出,2-已收货
/*try {
List<Express> list = expressService.queryByTypeAndStatus(2,2);
for (Express express : list) {
//针对每个用户发送短信提醒
Order order = orderService.queryOrderById(express.getOrderId());
//定制不同用户的发送信息
//String content = "您的检测报告及方案已完成,请进入公众号的个人中心查看,客服会尽快联系您预约报告解读, 咨询热线:010-56021932";
Boolean result = Sms.sendBase(order.getMobile(), content);
if(result){
LOGGER.info(">>>>>>每天早上8:00发送用户吃药提醒短信成功:mobile="+mobile);
}else{
LOGGER.error(">>>>>>每天早上8:00发送用户吃药提醒短信失败:mobile="+mobile);
}
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(">>>>>>每天早上8:00发送用户吃药提醒短信失败!---错误信息="+e);
}*/
}
/**
* 启动时执行一次,之后每隔1小时秒执行一次
*/
@Scheduled(cron = "0 */60 * * * ?")
public void updateExpressAndOrderStatus() {
// 定时查询物流信息更新物流表和订单表中产品的状态.....
//type----寄送类型(0-采样盒寄出,1-采样盒寄回,2-产品寄出
//Status----0-未寄出,1-已寄出,2-已收货
/*try {
List<Express> list = expressService.queryByTypeAndStatus(2,1);
for (Express express : list) {
boolean result = ExpressData.isSuccess(express.getExpressCompany(), express.getExpressNo());
if(result){
//用户收货成功,则更新数据库记录(更新订单表和物流表...)
expressService.updateExpressAndOrder(express);
//Order order = orderService.queryOrderById(express.getOrderId());
//express.setStatus(2);
//order.setExpressProductOutStatus(2);
//expressService.updateExpress(express);
//orderService.updateOrder(order)
}
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(">>>>>>定时执行产品寄出物流信息和订单信息状态失败!---错误信息="+e);
}*/
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>暂未开通更新物流用户收货成功的标记");
}
}
pom
<!-- 定时任务 -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
<exclusions>
<exclusion>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>${quartz.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
</dependencies>
1933

被折叠的 条评论
为什么被折叠?



