/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.lang.StringUtils
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.orm.ibatis.SqlMapClientTemplate
 *  org.springframework.stereotype.Repository
 */
package com.hst.task.dao;

import com.hst.common.exception.DBReleaseException;
import com.hst.common.util.DBUtil;
import com.hst.framework.common.HstSqlMapClientTemplate;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.dao.BaseDao;
import com.hst.framework.util.HstEncodeUtil;
import com.hst.task.domain.SqlScriptData;
import com.hst.task.domain.TaskData;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class JhsjTsDaoImp
implements BaseDao {
    public static Log _logger = LogFactory.getLog(JhsjTsDaoImp.class);
    @Autowired
    private SqlMapClientTemplate smzbsSqlMapClientTemplate;
    @Autowired
    private HstSqlMapClientTemplate sqlMapClientTemplate;

    public List<TaskData> queryTaskList(String csbz) throws Exception {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("bsdt_djxh", WebConstants.SMZ_RXBD_BSDT_DJXH);
        map.put("bz", csbz);
        ArrayList<TaskData> dataList = new ArrayList();
        this.sqlMapClientTemplate.queryForObjectByCurr("pNsfwJhGetSjtbrw", "dataList", map);
        dataList = (List)map.get("dataList");
        return dataList;
    }

    public List<SqlScriptData> querySqlScriptList() throws Exception {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("bsdt_djxh", WebConstants.SMZ_RXBD_BSDT_DJXH);
        ArrayList<SqlScriptData> dataList = new ArrayList();
        this.sqlMapClientTemplate.queryForObjectByCurr("pNsfwJhGetSql", "dataList", map);
        dataList = (List)map.get("dataList");
        return dataList;
    }

    public Map<String, Object> doExecuteSqlScript(SqlScriptData data) throws Exception {
        Statement csmt = null;
        Connection conn = null;
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("mess", "");
        try {
            try {
                _logger.info((Object)("\u6267\u884cSQL\u811a\u672c,SQL_XH:" + data.getSql_xh()));
                conn = this.smzbsSqlMapClientTemplate.getDataSource().getConnection();
                conn.setAutoCommit(false);
                csmt = conn.createStatement();
                csmt.execute(data.getSql());
                conn.commit();
                _logger.info((Object)("\u6267\u884cSQL\u811a\u672c\u6210\u529f,SQL_XH:" + data.getSql_xh()));
            }
            catch (Exception e) {
                _logger.info((Object)("\u6267\u884cSQL\u811a\u672c\u51fa\u9519,SQL_XH:" + data.getSql_xh()), (Throwable)e);
                if (e.getMessage().length() > 1000) {
                    map.put("mess", e.getMessage().substring(0, 1000));
                } else {
                    map.put("mess", e.getMessage());
                }
                map.put("code", "01");
                conn.rollback();
            }
        }
        catch (Throwable throwable) {}
        DBUtil.close(conn);
        if (csmt != null) {
            try {
                csmt.close();
                csmt = null;
            }
            catch (SQLException sqle) {
                throw new DBReleaseException(sqle);
            }
        }
        return map;
    }

    public void doExecuteSqlScriptHxcl(SqlScriptData data, Map<String, Object> resMap) throws Exception {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("bsdt_djxh", WebConstants.SMZ_RXBD_BSDT_DJXH);
        map.put("sql_xh", data.getSql_xh());
        if ("0".equals(resMap.get("code"))) {
            map.put("cgbz", "Y");
        } else {
            map.put("cgbz", "N");
        }
        String uploadDbEncode = WebConstants.JHXT_XTCS.get("2003");
        if (StringUtils.isBlank((String)uploadDbEncode)) {
            uploadDbEncode = "ISO";
        }
        if ("ISO".equals(uploadDbEncode)) {
            map.put("mess", HstEncodeUtil.GBK2ISO((String)resMap.get("mess")));
        } else {
            map.put("mess", resMap.get("mess"));
        }
        this.sqlMapClientTemplate.queryForObject("pNsfwJhGetSqlHxcl", map);
    }
}
