/*-------------------------application-context.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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd "> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> --> <!-- Connection Info --> <!-- Oracle <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@192.168.13.105:1521:acuems" /> <property name="username" value="emsuser" /> <property name="password" value="123456" /> --> <!-- mysql <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/eds?useUnicode=true&characterEncoding=UTF-8" /> <property name="url" value="jdbc:mysql://192.168.13.102:3306/eds?useUnicode=true&characterEncoding=UTF-8" /> <property name="username" value="root" /> <property name="password" value="123456" /> --> <!-- SQLServer --> <!-- <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /> <property name="url" value="jdbc:sqlserver://192.168.13.104\\MSSQLSERVER:1433;DatabaseName=acuems"/> <property name="username" value="sa" /> <property name="password" value="123456" /> --> <!-- Connection Pooling Info <property name="maxActive" value="50" /> <property name="maxIdle" value="200" /> <property name="defaultAutoCommit" value="false" /> <property name="timeBetweenEvictionRunsMillis" value="3600000"/> <property name="minEvictableIdleTimeMillis" value="3600000"/>--> <!-- </bean> --> <!-- 以下三个数据源是为了在处理报警数据时,把报警记录、短信、邮件放到一个事务里, 这三个数据源是在tomcat下配置的,需要修改tomcat/conf/context.xml,并在tomcat/lib下添加必要的jar,这两个资源在jtaresources里--> <jee:jndi-lookup id="edsDS" jndi-name="java:comp/env/jdbc/edsDS" /> <jee:jndi-lookup id="smDS" jndi-name="java:comp/env/jdbc/smDS" /> <jee:jndi-lookup id="mailDS" jndi-name="java:comp/env/jdbc/mailDS" /> <bean id="springContextHolder" class="com.accu.framework.spring.SpringContextHolder" /> <!-- lishuai acu_scheduleconfig这个表没用了 <bean id="scheduleInitial" class="com.accu.business.eds.schedule.ScheduleInitial" /> --> <!--MyBatis integration with Spring define sqlSessionFactory --> <bean id="sqlSessionFactory4EDS" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis-configuration.xml"/> <property name="dataSource" ref="edsDS" /> </bean> <bean id="mapperScanner4EDS" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.accu.persistence.eds" /> <property name="sqlSessionFactory" ref="sqlSessionFactory4EDS" /> </bean> <bean id="sqlSessionFactory4SM" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis-configuration4sm.xml"/> <property name="dataSource" ref="smDS" /> </bean> <bean id="mapperScanner4SM" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.accu.persistence.sm" /> <property name="sqlSessionFactory" ref="sqlSessionFactory4SM" /> </bean> <bean id="sqlSessionFactory4Mail" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis-configuration4mail.xml"/> <property name="dataSource" ref="mailDS" /> </bean> <bean id="mapperScanner4Mail" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.accu.persistence.mail" /> <property name="sqlSessionFactory" ref="sqlSessionFactory4Mail" /> </bean> <!-- enable autowire --> <context:annotation-config /> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 扫描service --> <context:component-scan base-package="com.accu.**.impl" /> <!-- transaction manager, use JtaTransactionManager for global tx --> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" /> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 定时任务 for 子系统更新数据 --> <bean name="updateSqlTable" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="com.accu.business.eds.updateSqlTable.updateSqlTableImpl" /> </bean> <bean name="systemTask" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="com.accu.business.eds.task.impl.TaskForSubSystemImpl" /> </bean> <bean name="warningTask" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="com.accu.business.eds.warning.WarningPushProcessor" /> </bean> <bean name="reportTask" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="com.accu.business.dms.task.ReportExportTaskImpl" /> </bean> <bean name="mailTask" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="com.accu.controller.eds.report.MailReport" /> </bean> <!-- 触发器 --> <bean id="updateSqlTableTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 指向我们的任务 --> <property name="jobDetail" ref="updateSqlTable" /> <!-- 从30秒开始,每1分钟执行一次 --> <property name="cronExpression" value="30 */1 * * * ?" /> </bean> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 指向我们的任务 --> <property name="jobDetail" ref="systemTask" /> <!-- 从30秒开始,每1分钟执行一次 --> <property name="cronExpression" value="30 */1 * * * ?" /> </bean> <bean id="warningTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 指向我们的任务 --> <property name="jobDetail" ref="warningTask" /> <!-- 从30秒开始,每1分钟执行一次 --> <property name="cronExpression" value="30 */1 * * * ?" /> </bean> <bean id="reportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 指向我们的任务 --> <property name="jobDetail" ref="reportTask" /> <!-- 从30秒开始,每1分钟执行一次 --> <!-- 0 0 */1 * * ? 每小时执行一次 --> <property name="cronExpression" value="30 */1 * * * ?" /> </bean> <bean id="mailTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 指向我们的任务 --> <property name="jobDetail" ref="mailTask" /> <!-- 每周一1时执行 --> <property name="cronExpression" value="0 */5 * ? * *" /> <!-- 0 0 0 ? * MON --> </bean> <!-- 调度器 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <!-- 触发器列表 --> <ref bean="cronTrigger" /> <!-- <ref bean="updateSqlTableTrigger" /> --> <!-- <ref bean="warningTrigger" /> --> <!-- <ref bean="reportTrigger" /> --> <!-- <ref bean="mailTrigger" /> --> </list> </property> <!-- <property name="configLocation" value="classpath:quartz.properties" /> --> </bean> </beans> /*----------------------------updateSqlTableImpl.java---------------------------*/ package com.accu.business.eds.updateSqlTable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.apache.log4j.Logger; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import com.accu.business.pms.measureparamsettting.MeasureDeviceWebService; import com.accu.common.util.FileUtils; import com.accu.framework.spring.SpringContextHolder; import com.accu.framework.webservice.AcuWebServiceClient; import com.accu.persistence.eds.mapper.MetersMapper; import com.accu.persistence.eds.mapper.MeasureParamMapper; import com.accu.persistence.pms.beans.MeasureParam; import com.accu.persistence.pms.beans.Meters; public class updateSqlTableImpl implements org.quartz.Job{ private static Logger log = Logger.getLogger(updateSqlTableImpl.class); private static List<Meters> theDiffMeterList(List<Meters> a,List<Meters> b,Boolean isAdd){ List<Meters> diff = new ArrayList<Meters>(); List<Meters> tmpa = new ArrayList<Meters>(Arrays.asList(new Meters[a.size()])); Collections.copy(tmpa, a); List<Meters> tmpb = new ArrayList<Meters>(Arrays.asList(new Meters[b.size()])); Collections.copy(tmpb, b); if(isAdd){ tmpa.removeAll(tmpb); for(Meters u : tmpa){ diff.add(u); } }else{ tmpb.removeAll(tmpa); for(Meters u : tmpb){ diff.add(u); } } return diff; } private static List<MeasureParam> theDiffMPList(List<MeasureParam> a,List<MeasureParam> b,Boolean isAdd){ List<MeasureParam> diff = new ArrayList<MeasureParam>(); List<MeasureParam> tmpa = new ArrayList<MeasureParam>(Arrays.asList(new MeasureParam[a.size()])); Collections.copy(tmpa, a); List<MeasureParam> tmpb = new ArrayList<MeasureParam>(Arrays.asList(new MeasureParam[b.size()])); Collections.copy(tmpb, b); if(isAdd){ tmpa.removeAll(tmpb); for(MeasureParam u : tmpa){ diff.add(u); } }else{ tmpb.removeAll(tmpa); for(MeasureParam u : tmpb){ diff.add(u); } } return diff; } public void updateMeterTab(){ String wsPath = FileUtils.getProperties("accuwebservice", "measureDeviceWebService"); AcuWebServiceClient<MeasureDeviceWebService> acu = new AcuWebServiceClient<MeasureDeviceWebService>(wsPath, MeasureDeviceWebService.class); MeasureDeviceWebService mdw = acu.getServiceClass(); List<Meters> pms_mList = mdw.getAllMeters(); MetersMapper mmapper = SpringContextHolder.getBeanbyClass(MetersMapper.class); List<Meters> dms_mList = mmapper.queryMeters(); List<Meters> res = theDiffMeterList(pms_mList,dms_mList,true); List<Meters> res2 = theDiffMeterList(pms_mList,dms_mList,false); if(res2.size()>0){ for(Meters m1 : res2){ int upd = mmapper.deleteMeter(m1.getGuidmeterid()); log.info(upd > 0 ? "仪表删除成功" : "仪表删除失败"); } } if(res.size()>0){ for(Meters m : res){ int add = mmapper.insertMeter(m); log.info(add > 0 ? "仪表插入成功" : "仪表插入失败"); } } } public void updateParamTab() { String wsPath = FileUtils.getProperties("accuwebservice", "measureDeviceWebService"); AcuWebServiceClient<MeasureDeviceWebService> acu = new AcuWebServiceClient<MeasureDeviceWebService>(wsPath, MeasureDeviceWebService.class); MeasureDeviceWebService mdw = acu.getServiceClass(); List<MeasureParam> pms_mpList = mdw.getAllMeasureParam(); MeasureParamMapper measureParamMapper = SpringContextHolder.getBeanbyClass(MeasureParamMapper.class); List<MeasureParam> dms_mpList = measureParamMapper.queryMeasureParams(); List<MeasureParam> res = theDiffMPList(pms_mpList,dms_mpList,true); List<MeasureParam> res2 = theDiffMPList(pms_mpList,dms_mpList,false); if(res2.size()>0){ for(MeasureParam m1 : res2){ int del = measureParamMapper.deleteMeasureParam(m1.getGuidMeasureParamId()); log.info(del > 0 ? "测量参数删除成功" : "测量参数删除失败"); } } if(res.size()>0){ for(MeasureParam m : res){ int add = measureParamMapper.insertMeasureParam(m); log.info(add > 0 ? "测量参数插入成功" : "测量参数插入失败"); } } } @Override public void execute(JobExecutionContext arg0) throws JobExecutionException { updateMeterTab(); updateParamTab(); } }