package com.steering.pss.ydm.task;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
public class CoreBalanceTask extends TimerTask{
    public void run() {
        DBCommon db = new DBCommon();
        Connection con = null;
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
        String bathYearMoth = df.format(now);
        try {
            con = db.getDao(CoreConstantData.sysbeanstr).getConnection();
            con.setAutoCommit(false);
            String strSql = CoreXmlSqlParsersFactory.getSql("CoreBalanceTask.task");
            strSql = strSql.replaceAll("#vDate#", bathYearMoth);
            PreparedStatement ps = con.prepareStatement(strSql);
            ps.execute();
            ps.close();
            con.commit();            
            
        }catch (Exception e) {  
            e.printStackTrace();
            try {
                con.rollback(); // 回滚事务
            }
            catch (Exception e2) {
                e2.printStackTrace();
            }            
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            }
            catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
