package com.chinacreator.process.dao;

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

import org.springframework.stereotype.Component;

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

@Component
public class SmsSendDao {

	public void updateFlowVipSms(String id,String result) throws SQLException{
		String sql = "update TD_BUSSINESS_HANDLE set fvsms = ? where id =?";
		SQLExecutor.updateWithDBName(DataSource.NET3G, sql,result,id);
	}
	
	@SuppressWarnings("unchecked")
	public List<SmsSendBean> selectFlowVipSms() throws SQLException{
		String sql = "select id,userid from TD_BUSSINESS_HANDLE where to_char(effectivetime,'yyyymm') = to_char(sysdate,'yyyymm')   and effectivetime>=to_date('20161108010000','yyyymmddhh24miss') and sysdate-(1/(24*60)*30) >= effectivetime and flowtime is null and viptime is null and fvsms =0 and province in(select province from TB_ACTIVITYPROVINCE_CONTROL where status =0)";
		PreparedDBUtil pdb = new PreparedDBUtil();
		try {
			return pdb.executeSelectForList(DataSource.NET3G,  sql, 0, 500, SmsSendBean.class);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public void updateActivateSms(String id,String result) throws SQLException{
		String sql = "update TD_BUSSINESS_HANDLE set asms = ? where id =?";
		SQLExecutor.updateWithDBName(DataSource.NET3G, sql,result,id);
	}
	
	@SuppressWarnings("unchecked")
	public List<SmsSendBean> selectActivateSms() throws SQLException{
		String sql = "select * from TD_BUSSINESS_HANDLE where usertype =1 and activitytime>=to_date('20161108010000','yyyymmddhh24miss') and asms=0 and province in(select province from TB_ACTIVITYPROVINCE_CONTROL where status =0)";
		PreparedDBUtil pdb = new PreparedDBUtil();
		try {
			return pdb.executeSelectForList(DataSource.NET3G,  sql, 0, 500, SmsSendBean.class);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public void updateVipSms(String id,String result) throws SQLException{
		String sql = "update TD_BUSSINESS_HANDLE set vsms = ? where id =?";
		SQLExecutor.updateWithDBName(DataSource.NET3G, sql,result,id);
		}
	
	@SuppressWarnings("unchecked")
	public List<SmsSendBean> selectVipSms() throws SQLException{
		String sql = "select * from TD_BUSSINESS_HANDLE where to_char(effectivetime,'yyyymm') = to_char(sysdate,'yyyymm') and effectivetime>=to_date('20161108010000','yyyymmddhh24miss') and sysdate-(1/(24*60)*30) >= effectivetime and flowtime is not null and viptime is null and vsms =0 and province in(select province from TB_ACTIVITYPROVINCE_CONTROL where status =0)";
		PreparedDBUtil pdb = new PreparedDBUtil();
		try {
			return pdb.executeSelectForList(DataSource.NET3G,  sql, 0, 500, SmsSendBean.class);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
