Salesforce 如何把签卡数据同步到中控系统
Posted lovoo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Salesforce 如何把签卡数据同步到中控系统相关的知识,希望对你有一定的参考价值。
一、考勤界面
二、分析
1)同步数据首先要得到数据,如何得到数据呢?
第一步:创建签卡数据的触发器
第二步:创建同步日志类,把所有的签卡信息都添加到同步日志里
2)从数据源得到数据后以Json格式传递
3)创建一个SpringMVC的Maven工程,
a、以阿里巴巴的Druid配置数据源,
b、创建个定时器,每隔一分钟从Salesforce的日志里读取信息
c、在Dao层里写数据同步的代码
d、测试
三、同步示意图:
四、触发器代码:
trigger attendanceSyncTrigger on attendance__c (after insert) {
//查询类型
List<RecordType> rtList = [SELECT Id, Name, DeveloperName, SobjectType FROM RecordType WHERE SobjectType='attendance__c'];
Map<String,String> recordMap = new Map<String,String>();
for(RecordType r:rtList){
recordMap.put(r.Name,r.Id);
}
attendance__c order = Trigger.new[0];
//如果是插入状态,判断是不是“考勤“
if(Trigger.isInsert && recordMap.get('考勤管理').equals(order.RecordTypeId)){
if(order != null){
String projson = json.serialize(order);
system.debug('jjjjjjj:'+projson);
//创建日志
SynLog__c syn = new SynLog__c();
syn.Name=String.valueOf(order.Id).subString(0,15);
//把数据赋给日志参数
syn.parameter__c = projson;
syn.ObjectName__c = 'attendance__c';
syn.Operation__c = 'Insert';
syn.Flag__c ='No';
insert syn;
}
}
}
日志类:
五、SpringMVC的Maven工程
1)架构图:
2)pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>dzjg</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<spring.version>4.0.5.RELEASE</spring.version>
<slf4j.version>1.7.5</slf4j.version>
<logback.version>1.0.13</logback.version>
<fastjson.version>1.1.34</fastjson.version>
<cio.version>2.2</cio.version>
<clang.version>3.1</clang.version>
</properties>
<dependencies>
<!-- +++Spring相关配置 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.1.7</version>
</dependency>
<!-- +++Web容器接口 -->
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>5.0-3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- 数据库配置 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>0.2.25</version>
</dependency>
<!--mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<!-- +++ 日志配置 +++ -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Apache Commons常用类库 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${clang.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${cio.version}</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>net.sf.jxls</groupId>
<artifactId>jxls-core</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<artifactId>commons-beanutils</artifactId>
<groupId>commons-beanutils</groupId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>poi-ooxml-schemas</artifactId>
<groupId>org.apache.poi</groupId>
</exclusion>
<exclusion>
<artifactId>poi</artifactId>
<groupId>org.apache.poi</groupId>
</exclusion>
<exclusion>
<artifactId>poi-ooxml</artifactId>
<groupId>org.apache.poi</groupId>
</exclusion>
<exclusion>
<artifactId>commons-digester</artifactId>
<groupId>commons-digester</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- httpClient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3-beta2</version>
</dependency>
<!-- httpClient end -->
<!-- +++ 测试框架 +++ -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- +++ 测试框架 +++ -->
<dependency>
<groupId>ent</groupId>
<artifactId>ent</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/WebRoot/WEB-INF/lib/enterprise.jar</systemPath>
</dependency>
<dependency>
<groupId>wsc</groupId>
<artifactId>wsc</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/WebRoot/WEB-INF/lib/force-wsc-34.2.1-uber.jar</systemPath>
</dependency>
<dependency>
<groupId>sql</groupId>
<artifactId>sql</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/WebRoot/WEB-INF/lib/sqljdbc4-3.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<outputDirectory>${basedir}/WebRoot/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webappDirectory>${basedir}/WebRoot</webappDirectory>
<warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
3)定时器配置文件:app-scheduling.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans default-lazy-init="true">
<!-- 中控考勤系统定时查询信息 -->
<bean id="SfToZKScheduler" class="com.dzjg.TimedTask.SfToZKScheduler" />
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
<property name="triggers">
<list>
<ref local="SfToZKSchedulerTrigger" />
</list>
</property>
</bean>
<!-- *****************中控系统********************************** -->
<bean id="SfToZKSchedulerTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<!-- 每一分钟执行一次 -->
<property name="cronExpression" value="0 0/1 * * * ?" />
<property name="jobDetail" ref="SfToZKSchedulerData" />
</bean>
<!-- Detail -->
<bean id="SfToZKSchedulerData"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="SfToZKScheduler" />
<property name="targetMethod" value="sync" />
<property name="concurrent" value="false" />
</bean>
</beans>
4)数据层配置
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>
<bean id="logDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close" lazy-init="true">
<property name="driverClassName" value="${jdbc.log.driverClassName}"/>
<property name="url" value="${jdbc.log.url}"/>
<property name="username" value="${jdbc.log.username}"/>
<property name="password" value="${jdbc.log.password}"/>
<property name="dbType" value="mysql"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="1800" />
<property name="maxActive" value="20"/>
<property name="initialSize" value="5"/>
<property name="maxWait" value="2000"/>
<property name="minIdle" value="5"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="300000"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="poolPreparedStatements" value="true"/>
<property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>
<property name="validationQuery" value="SELECT 'x'"/>
<!-- 开启Druid的监控统计功能 -->
<property name="filters" value="stat"/>
</bean>
<!--中控考勤系统-->
<bean id="dataSourceZK" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close" lazy-init="true">
<property name="driverClassName" value="${jdbc.zk.driverClassName}"/>
<property name="url" value="${jdbc.zk.url}"/>
<property name="username" value="${jdbc.zk.username}"/>
<property name="password" value="${jdbc.zk.password}"/>
<property name="dbType" value="sqlServer"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="1800" />
<property name="maxActive" value="20"/>
<property name="initialSize" value="5"/>
<property name="maxWait" value="2000"/>
<property name="minIdle" value="5"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="300000"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="poolPreparedStatements" value="true"/>
<property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>
<property name="validationQuery" value="SELECT 'x'"/>
<!-- 开启Druid的监控统计功能 -->
<property name="filters" value="stat"/>以上是关于Salesforce 如何把签卡数据同步到中控系统的主要内容,如果未能解决你的问题,请参考以下文章