springConfig配置文件:
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="dataSource" ref="dataSource" /> </bean> <!-- 启用支持Annotation注解方式的事务管理 --> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 把标记了@Controller等注解的类转换为bean --> <context:component-scan base-package="com.qdshop" /> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> --> <!--文件上传设置--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize"> <value>10485760</value><!-- 文件上传最大为10M --> </property> <property name="maxInMemorySize" value="4096" /> </bean> <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --> <bean id="velocityCongfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath"> <value>/</value> </property> <property name="velocityProperties"> <props> <prop key="input.encoding">UTF-8</prop> <prop key="output.encoding ">UTF-8</prop> </props> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityView" /> <property name="contentType"> <value>text/html;charset=UTF-8</value> </property> </bean> <!-- property-placeholder是一个属性遍历器,定位一个属性文件,属性文件存放的是jdbc一些连接数据 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!--配置velocity engine默认路径--> <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> <property name="resourceLoaderPath" value="/velocity/"></property> </bean> <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driverClassName}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="initialSize" value="${initialSize}" /> <property name="maxActive" value="${maxActive}" /> <property name="maxIdle" value="${maxIdle}" /> <property name="minIdle" value="${minIdle}" /> </bean> <bean name="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceXmlLocation" value="classpath:persistence.xml" /> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="MYSQL" /> <property name="showSql" value="true" /> <property name="generateDdl" value="false" /> </bean> </property> <property name="jpaProperties"> <props> <!-- 自定义方言 --> <prop key="hibernate.dialect"> com.qdshop.core.dialect.SystemMySQL5Dialect </prop> <!-- 二级缓存配置 --> <prop key="hibernate.cache.provider_class"> net.sf.ehcache.hibernate.SingletonEhCacheProvider </prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache"> true </prop> <prop key="hibernate.use_sql_comments">false</prop> <prop key="hibernate.format_sql">false</prop> <prop key="hibernate.generate_statistics">true</prop> </props> </property> </bean> <!-- 定义了与实体相关的dao --> <bean id="genericEntityDao" class="com.qdshop.core.base.GenericEntityDao" scope="prototype" lazy-init="true"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <!--使用泛型DAO作为抽象基类 abstract="true" --> <bean id="genericDAO" class="com.qdshop.core.base.GenericDAO" abstract="true" depends-on="genericEntityDao"> <property name="geDao"> <ref bean="genericEntityDao" /> </property> </bean> <!-- 系统调度控制器 --> <bean id="statTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用的类 --> <property name="targetObject" ref="shop_stat" /> <!-- 调用类中的方法 --> <property name="targetMethod" value="execute" /> <property name="concurrent" value="false" /> </bean> <bean id="stat_cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="statTask" /> <property name="cronExpression" value="0 */30 * * * ?" /> </bean> <bean id="jobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用的类 --> <property name="targetObject" ref="shop_job" /> <!-- 调用类中的方法 --> <property name="targetMethod" value="execute" /> <property name="concurrent" value="false" /> </bean> <bean id="job_cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="jobTask" /> <property name="cronExpression" value="1 0 0 * * ?" /> </bean> <bean id="orderJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用的类 --> <property name="targetObject" ref="order_job" /> <!-- 调用类中的方法 --> <property name="targetMethod" value="execute" /> <property name="concurrent" value="false" /> </bean> <bean id="orderJob_cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="orderJobTask" /> <property name="cronExpression" value="0/10 * * * * ?" /> </bean> <bean id="schdulerFactory" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="stat_cronTrigger" /> <ref bean="job_cronTrigger" /> <ref bean="orderJob_cronTrigger" /> </list> </property> </bean> <bean id="sensitiveWordInitUtil" class ="com.qdshop.sensitive.util.SensitiveWordInitUtil" scope="singleton" init-method="initKeyWord"> <property name="xmlFile"> <value>classpath:sensitive-word.xml</value> </property> </bean> <!-- Loads MongoDB configuraton --> <import resource="mongo-config.xml"/> </beans>
定时执行类
package com.qdshop.manage.timer; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; import org.apache.zookeeper.Op.Delete; import org.hibernate.annotations.Where; import org.hibernate.sql.Update; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.qdshop.core.tools.CommUtil; import com.qdshop.foundation.domain.ApplyRefund; import com.qdshop.foundation.domain.Complaint; import com.qdshop.foundation.domain.Evaluate; import com.qdshop.foundation.domain.OrderForm; import com.qdshop.foundation.domain.OrderFormLogBean; import com.qdshop.foundation.domain.Quartz; import com.qdshop.foundation.domain.User; import com.qdshop.foundation.service.IApplyRefundService; import com.qdshop.foundation.service.IComplaintService; import com.qdshop.foundation.service.IEvaluateService; import com.qdshop.foundation.service.IOrderFormLogService; import com.qdshop.foundation.service.IOrderFormService; import com.qdshop.foundation.service.IQuartzService; import com.qdshop.foundation.service.ISysConfigService; import com.qdshop.foundation.service.ITemplateService; import com.qdshop.foundation.service.IUserService; import com.qdshop.manage.admin.tools.MsgTools; import com.sun.org.apache.xpath.internal.operations.And; /** * @ClassName: OrderJobManageAction * @Description: 订单相关定时任务 * @author * @date 2016-5-7 下午5:45:43 * */ @SuppressWarnings({"rawtypes","unchecked","unused"}) @Component("order_job") public class OrderJobManageAction { @Autowired private ISysConfigService configService; //投诉接口 @Autowired private IComplaintService complaintService; @Autowired private MsgTools msgTools; public void execute() throws Exception{ Calendar cal = null; Map params = new HashMap(); List<Quartz> quartzs=new ArrayList<Quartz>(); List<ApplyRefund> applyRefunds=new ArrayList<ApplyRefund>(); /**订单超过X天未付款,自动取消**/ int auto_order_cancel = this.configService.getSysConfig().getAuto_order_cancel(); cal = Calendar.getInstance(); params.clear(); cal.add(6, -auto_order_cancel); params.put("order_time", cal.getTime()); params.put("order_status", Integer.valueOf(1));//未付款 List<OrderForm> cancel_ofs = this.orderFormService .query("select obj from OrderForm obj where obj.order_time<=:order_time and obj.order_status=:order_status", params, -1, -1); for (OrderForm of : cancel_ofs){ //订单取消 of.setOrder_status(10); this.orderFormService.update(of); } } /** * * 功能描述:根据传入name,查询出value值 * 创建人: * 创建日期:2016年7月28日 * @param name * @return */ private List<Quartz> getQuartzList(String name){ Map map = new HashMap(); map.put("name", name);//取确认订单值 List<Quartz> quartzs=this.quartzService.query("select obj from Quartz obj where obj.name=:name", map, -1, -1); return quartzs; } }
时间: 2024-10-10 01:32:31