定时任务&&找出两个list的不同
/*-------------------------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();
} }
定时任务&&找出两个list的不同的更多相关文章
- Java - Collection 高效的找出两个List中的不同元素
如题:有List<String> list1和List<String> list2,两个集合各有上万个元素,怎样取出两个集合中不同的元素? 方法1:遍历两个集合 public ...
- python——快速找出两个电子表中数据的差异
最近刚接触python,找点小任务来练练手,希望自己在实践中不断的锻炼自己解决问题的能力. 公司里会有这样的场景:有一张电子表格的内容由两三个部门或者更多的部门用到,这些员工会在维护这些表格中不定期的 ...
- Java Collection - 003 高效的找出两个List中的不同元素
如题:有List<String> list1和List<String> list2,两个集合各有上万个元素,怎样取出两个集合中不同的元素? 方法1:遍历两个集合 public ...
- js-FCC算法Smallest Common Multiple。找出两个参数和它们之间的连续数字的最小公倍数。
存档. 找出能被两个给定参数和它们之间的连续数字整除的最小公倍数. function smallestCommons(arr) { //分解质因数法,分解为若干个质数相乘 var arrratio=[ ...
- leetcode 4 : Median of Two Sorted Arrays 找出两个数组的中位数
题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...
- 基于visual Studio2013解决面试题之0608找出两个只出现一次的数
题目
- [PHP] 算法-找出两个链表的第一个公共结点的PHP实现
输入两个链表,找出它们的第一个公共结点 1.两个单链表,有公共结点,那么必然,尾部公用 2.找出链表1的长度,找出链表2的长度,长的链表减去短的链表得出一个n值 3.长的链表先走n步,两个链表再同时移 ...
- leetcode实践:找出两个有序数组的中位数
题目 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n)). 代码实现 package com. ...
- 海量数据处理面试题(1) 找出两文件种包含的相同的url
问题:给定a.b两个文件,各存放50亿个url,每个url各占64字节,内存限制是4G,让你找出a.b文件共同的url? 分析:50亿个url,每个url64字节,就是320G,显然是无法一次读入内存 ...
随机推荐
- Mysql 语句单表查询
一基本查询 -- 创建商品表 CREATE TABLE products( pid INT PRIMARY KEY AUTO_INCREMENT, pname VARCHAR(20), price D ...
- RAID独立冗余磁盘阵列
独立冗余磁盘阵列(Redundant Array OF Independent Disks,RAID)开始于20世纪80年代美国加州大学伯克利分校的一个研究项目,当时RAID被称为廉价冗余磁盘阵列(R ...
- skynet启动读取配置文件浅析(skynet_main.c)
1.作为skynet的启动文件,主要完成了一些初始化和读取并存取配置文件内容的工作. 在这里只将代码读取配置文件的部分抽取出来,就算没有skynet环境,这些代码也是可以运行的,了解以后再对照源码进行 ...
- JMS-activeMq点对点模式
上一篇对JMS进行介绍了一下,接下来总结一下activemq点对点模式以及订阅发布模式. (1)下载:首先到官网http://activemq.apache.org下载activemq (2)运行:解 ...
- Android中获取并设置屏幕亮度
最近在做一个Demo的时候用到了调节屏幕亮度的功能,于是上网搜索了一下,并且写了一个小Demo测试了一下,发现代码还是比较简单的.Android中的亮度调节,主要有三个方向,一个是针对于系统的亮度调节 ...
- Ubuntu 1210怎么获得root权限登录
Ubuntu 12.10 怎么用Root 登录?以下是Ubuntu 12.10 启用Root 登录的方法吗,希望对大家有些帮助吧! 方法如下: 1.先设定一个 Root 密码 sudo passwd ...
- 在OpenStack里怎样配置Neutron,让虚拟机访问外网
http://blog.csdn.net/zhangli_perdue/article/details/50264681 OpenStack里虚机(或者叫instance)只有在分配floating ...
- ubantu中让g++支持c++11的办法
g++ main.cpp -std=c++11 -o a 其中: main.cpp是要编译的源文件 a是编译后的文件名 注意-std=c++11不要写成-std=c11
- openstack-mitaka版本DRV基础
一.基础知识 1.1 路由 1.1.1 策略路由 1.1.2 路由表 (使用 ip route 命令操作静态路由表) 1.1.3 路由分类之静态路由 1.1.4 路由分类之动态路由 1.1.5 ip ...
- 更新增加一个门店ID字段的值
MYSQL因为不能查询一张表时同时更新一张表,同时又会有子查询大于等于一条的情况出现. 分两种情况: 1 直接JOIN 得到一张表. 然后导出做筛选 CREATE TABLE TEST SELECT ...