

package com.chinacreator.process.dao;

import com.chinacreator.process.bean.ContinueBean;
import com.frameworkset.common.poolman.PreparedDBUtil;
import com.frameworkset.common.poolman.SQLExecutor;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

@Component
public class ContinueOrderDao {
    private static Logger logger = Logger.getLogger(ContinueOrderDao.class);

    public ContinueOrderDao() {
    }

    public List<ContinueBean> queryNeedVipDo() {
//        String sql = "select  userid,cpid,spid,fhcpid,fhspid,vippool,orderchannel2,cancelchannel2 from TL_CONTINUEORDER_LOG where  trunc(inserttime)=trunc(sysdate)  and resultcode='0' and VIPREULTCODE='-1' order by inserttime";
        String sql = "select  acid,userid,cpid,spid,fhcpid,fhspid,vippool,orderchannel2,cancelchannel2 from TL_CONTINUEORDER_LOG where  trunc(inserttime)=trunc(sysdate)  and resultcode='0' and VIPREULTCODE='-1' order by inserttime";
        PreparedDBUtil pdb = new PreparedDBUtil();

        try {
            return pdb.executeSelectForList("net3g", sql, 0L, 2000, ContinueBean.class);
        } catch (Exception var4) {
            logger.error("查询TL_CONTINUEORDER_LOG失败", var4);
            return null;
        }
    }

    public static void main(String[] args) {
        ContinueOrderDao dao = new ContinueOrderDao();

        try {
            List<HashMap> hm = dao.getActivityTypeByFh("fhcptest", "99134241");
            System.out.println(hm);
        } catch (SQLException var3) {
            var3.printStackTrace();
        }

    }

    public List<ContinueBean> queryNeedOrderDo() {
        String sql = "select  userid,cpid,spid  from TL_CONTINUEORDER_LOG where  trunc(inserttime)=trunc(sysdate)  and resultcode='-1' ";
        PreparedDBUtil pdb = new PreparedDBUtil();

        try {
            return pdb.executeSelectForList("net3g", sql, 0L, 500, ContinueBean.class);
        } catch (Exception var4) {
            logger.error("查询TL_CONTINUEORDER_LOG失败", var4);
            return null;
        }
    }

    public void saveResult(String userid, String resultcode, String errorinfo, String cpid, String spid) throws SQLException {
        String sql = "update TL_CONTINUEORDER_LOG set resultcode=? , errorinfo=? where cpid=? and spid=? and userid=? and trunc(inserttime)=trunc(sysdate) and fhcpid is null and fhspid is null";
        SQLExecutor.updateWithDBName("net3g", sql, new Object[]{resultcode, errorinfo, cpid, spid, userid});
    }

    public void saveResultByFh(String userid, String resultcode, String errorinfo, String cpid, String spid, String fhcpid, String fhspid) throws SQLException {
        String sql = "update TL_CONTINUEORDER_LOG set resultcode=? , errorinfo=? where cpid=? and spid=? and fhcpid=? and fhspid=? and userid=? and trunc(inserttime)=trunc(sysdate) ";
        SQLExecutor.updateWithDBName("net3g", sql, new Object[]{resultcode, errorinfo, cpid, spid, fhcpid, fhspid, userid});
    }

    public void saveVipResult(String userid, String resultcode, String errorinfo, String cpid, String spid) throws SQLException {
        String sql = "update TL_CONTINUEORDER_LOG set VIPREULTCODE=? , VIPERRORINFO=? where cpid=? and spid=? and userid=? and trunc(inserttime)=trunc(sysdate) and fhcpid is null and fhspid is null";
        SQLExecutor.updateWithDBName("net3g", sql, new Object[]{resultcode, errorinfo, cpid, spid, userid});
    }

    public void saveVipResultByFh(String userid, String resultcode, String errorinfo, String cpid, String spid, String fhcpid, String fhspid) throws SQLException {
        String sql = "update TL_CONTINUEORDER_LOG set VIPREULTCODE=? , VIPERRORINFO=? where cpid=? and spid=? and fhcpid=? and fhspid=? and userid=? and trunc(inserttime)=trunc(sysdate) ";
        SQLExecutor.updateWithDBName("net3g", sql, new Object[]{resultcode, errorinfo, cpid, spid, fhcpid, fhspid, userid});
    }

    public List<HashMap> getActivityTypeByFh(String fhcpid, String fhspid) throws SQLException {
        String sql = "SELECT ACTIVETYPE,PROVINCE FROM TB_ACTIVITY_CONFIG where cpid=? and spid=? ";
        return SQLExecutor.queryListWithDBName(HashMap.class, "net3g", sql, new Object[]{fhcpid, fhspid});
    }
}
