package com.chinacreator.process.dao;

import com.chinacreator.process.bean.NetOrderBean;
import com.chinacreator.process.util.DataSource;
import com.frameworkset.common.poolman.PreparedDBUtil;
import com.frameworkset.common.poolman.SQLExecutor;

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

import org.apache.commons.lang.math.NumberUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

@Component
public class PreToOrderDao
{

	  private static Logger logger = Logger.getLogger(PreToOrderDao.class);
	  
	  @SuppressWarnings("unchecked")
	  public List<NetOrderBean> queryNeedDo()
	  {
	    String sql = "select * from td_pre_order_relations where cpid ='tencent' and spid='101'  and to_char(ordertime,'yyyymm')<to_char(sysdate,'yyyymm') and SYNCSTATUS=1";

	    PreparedDBUtil pdb = new PreparedDBUtil();
	    try {
	      return pdb.executeSelectForList(DataSource.NET3G, sql, 0,500, NetOrderBean.class);
	    } catch (Exception e) {
	      logger.error("查询失败", e);
	    }
	    return null;
	  }
	  
	  public long getSize() throws SQLException{
		  String sql = "select count(1) from td_pre_order_relations where  cpid ='tencent' and spid='101'  and to_char(ordertime,'yyyymm')<to_char(sysdate,'yyyymm') and SYNCSTATUS=1 ";
		  return  NumberUtils.toLong(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql),0);
	  }
	  
	  public void update(String id,String status) throws SQLException{
		  String sql = "update td_pre_order_relations set SYNCSTATUS=? , SYNCTIME=sysdate where id =?";
		  SQLExecutor.updateWithDBName(DataSource.NET3G, sql, status,id);
	  }
	  
//	  public Integer querysize() throws SQLException{
//		  String sql = "select count(distinct userid) from td_pre_order_relations where cpid ='tencent' and spid='84' and status=0 and to_char(ordertime,'yyyymm')<to_char(sysdate,'yyyymm')";
//		  return SQLExecutor.queryObjectBeanWithDBName(Integer.class,DataSource.NET3G, sql,null)/500+1;
//	  }

public static void main(String[] args) throws SQLException {
	PreToOrderDao dao = new PreToOrderDao();
//	List<String>  list = dao.queryNeedDo(0);
//	System.out.println(list.size());
//	List<String>  list2 = dao.queryNeedDo(1);
//	System.out.println(list2.size());
//	for (String string : list2) {
//		for (String str : list) {
//			if(string.equals(str)){
//				System.out.println(str);
//			}
//		}
//	}
	System.out.println(dao.getSize()/500);
}
}