码迷,mamicode.com
首页 > 其他好文 > 详细

Salesforce 如何把签卡数据同步到中控系统

时间:2016-05-18 18:07:11      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

一、考勤界面

技术分享

二、分析

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"/>
    </bean>

    <!-- ******************中控考勤事务控制************************************ -->
    <bean id="zkJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSourceZK"/>
    </bean>

    <!-- 事务管理器  -->
    <bean id="txZK" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSourceZK"/>
    </bean>

    <!-- ******************salesforce事务控制************************************ -->
    <bean id="logJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="logDataSource"/>
    </bean>

    <!-- 事务管理器  -->
    <bean id="logTx" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="logDataSource"/>
    </bean>

    <context:component-scan base-package="com.dzjg.dao"/>

</beans>

5)动作配置app-action.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:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 添加注解驱动 -->
    <mvc:annotation-driven/>

    <!--  程序代码扫描配置修改处    -->
    <context:component-scan base-package="com.dzjg.controller"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <mvc:resources mapping="/static/**" location="/static/"/>


    <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
        <property name="maxUploadSize" value="200000000000"/>
    </bean>

    <!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->
    <!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->
    <bean id="exceptionResolver"
          class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 -->
                <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">/web/error_upload
                </prop>
            </props>
        </property>
    </bean>

</beans>

6)实体类配置

<?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="appUtil" class="com.dzjg.common.AppUtil"/>

    <context:component-scan base-package="com.dzjg.TimedTask"/>



</beans>

7)从Salesforce读取信息

public class SyncLogDao {
    /**
     * 查询salesforce同步日志
     *
     * @return
     */
    public static List<SynLog__c> getSynLogList() {
        String soql = "select parameter__c,errorMsg__c,Flag__c,ObjectName__c,Operation__c,id  from SynLog__c where  Flag__c = ‘No‘";
        try {
            return (List<SynLog__c>) SFDaoUtils.queryListBySql(soql);
        } catch (ConnectionException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 回写成功日志
     *
     * @param id
     */
    public static void markFinishedById(String id) {
        try {
            SynLog__c synLog = new SynLog__c();
            synLog.setId(id);
            //设置处理时间
            Date date = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            synLog.setCompleteDate__c(cal);
            synLog.setFlag__c("Yes");
            SFDaoUtils.updateSObject(synLog);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 回写失败信息
     * @param id
     * @param errorMsg
     */
    public static void markErrorMsgById(String id, String errorMsg) {
        try {
            SynLog__c a = new SynLog__c();
            a.setId(id);
            a.setErrorMsg__c(errorMsg);
            //设置处理时间
            Date date = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            a.setCompleteDate__c(cal);
            a.setFlag__c("Error");
            SFDaoUtils.updateSObject(a);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

8)把数据写入到数据库

/**
 * salesforce 同步到中控考勤系统
 * 
 * @Project dzjg
 * @Package com.dzjg.TimedTask
 * @author chenlin
 * @version 1.0
 * @Date 2016年5月16日
 */
@Service
public class SfToZKScheduler {
    /**
     * 记录日志文件
     */
    private Logger log = LoggerFactory.getLogger(SfToZKScheduler.class);

    /**
     * 在app-scheduling.xml里<property name="targetMethod" value="sync" />调用,进行定时扫描
     */
    public void sync() {
        List<SynLog__c> synLogList = SyncLogDao.getSynLogList();
        for (SynLog__c synLog : synLogList) {
            handleItem(synLog);
        }
    }

    public void handleItem(final SynLog__c synLog) {
        try {
            if(synLog == null){
                return;
            }
            if (LogDao.isExit(synLog.getId())) {
                SyncLogDao.markFinishedById(synLog.getId());// 回写成功日志
                return;
            }

            if ("attendance__c".equalsIgnoreCase(synLog.getObjectName__c())) {
                log.info("同步用户名称,id,签卡时间,签卡类型到中控考勤系统:" + synLog.getParameter__c());
                final Attendance__c order = JSON.parseObject(synLog.getParameter__c(), Attendance__c.class);
                ERPDao.commit(new VoidWrapper() {
                    public void doWork() {
                        if (order != null) {
                            try {
                                System.out.println("order == "+ order);
                                ERPDao.saveAttendenc(order);
                                log.info("考勤数据到中控:SUCCESS!!!");
                            } catch (Exception e) {
                                e.printStackTrace();
                                log.info("考勤数据到中控:ERROR!!!");
                            }

                        }
                        SyncLogDao.markFinishedById(synLog.getId());// 回写成功日志
                        LogDao.insertLog(synLog);

                    }
                });
            } 

        } catch (Exception e) {
            log.error(ExceptionUtils.getStackTrace(e));
            SyncLogDao.markErrorMsgById(synLog.getId(), e.getMessage());// 回写错误日志
        }
    }

}

9)数据层处理

public static void saveAttendenc(final Attendance__c order) {
        if (order == null) {
            return;
        }
        String uid = order.getAttend_userid__c();
        if (TextUtil.isEmpty(uid)) {
            return;
        }

        String userSql = "select userid from userinfo where badgenumber = ? ";
        List<String> list = zkJdbcTemplate.queryForList(userSql, new Object[] { uid.trim() }, String.class);
        if (list == null || list.size() <= 0) {
            return;
        }
        final String userid = list.get(0).toString();
        if (!TextUtil.isEmpty(userid) && TextUtil.isNum(userid)) {

            String sql = "insert into checkexact  "
                    + " (change_time, create_operator, create_time,  UserID, CHECKTIME, YUYIN , audit_status, CHECKTYPE, status, ISMODIFY, ISDELETE, INCOUNT, ISCOUNT) "
                    + " values (?, ?, ?, ?, ?, ?, 2, ‘l‘, 0, 0, 0, 0, 0)";

            zkJdbcTemplate.update(sql, new PreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps) throws SQLException {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    ps.setString(1, sdf.format(new Date()));
                    ps.setString(2, order.getAttend_name__c());
                    ps.setString(3, sdf.format(new Date()));
                    ps.setInt(4, Integer.parseInt(userid));
                    // 添加异常打卡时间
                    ps.setString(5, order.getAttend_time__c());
                    ps.setString(6, order.getAttend_type__c());
                }
            });
        }
    }

10)获取Spring 的jdbcTemplate工具类

public class AppUtil implements ApplicationContextAware {

    private static ApplicationContext appCtx;

    /**
     * 此方法可以把ApplicationContext对象inject到当前类中作为一个静态成员变量。
     *
     * @param applicationContext ApplicationContext 对象
     * @throws org.springframework.beans.BeansException
     */
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        appCtx = applicationContext;
    }

    /**
     * 这是一个便利的方法,帮助我们快速得到一个BEAN
     *
     * @param beanName bean的名字
     * @return 返回一个bean对象
     */
    public static <T> T getBean(String beanName) {
        checkApplicationContext(appCtx);
        return (T) appCtx.getBean(beanName);
    }

    /**
     * 用于方便单元测试
     * @param applicationContext
     */
    private static void checkApplicationContext(ApplicationContext applicationContext) {
        if (appCtx == null) {
            synchronized (AppUtil.class) {
                if (applicationContext == null) {
                    appCtx = new ClassPathXmlApplicationContext("spring/app-context.xml","spring/app-dao.xml","spring/app-action.xml");
                }
            }
        }

    }

}

Salesforce 如何把签卡数据同步到中控系统

标签:

原文地址:http://blog.csdn.net/lovoo/article/details/51444213

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!