package com.chinacreator.process.dao;

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;

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

@Component
public class ActiveMango3JSDao{
	
	private static Logger logger = Logger.getLogger(ActiveMango3JSDao.class);
	
	@SuppressWarnings("unchecked")
	public List<String> queryNeedSmsDeal(){
		String sql = " select userid from TD_BUSSINESS_HANDLE_MANGO3JS where inserttime>=sysdate-10 and inserttime<sysdate-3 and smsstatus='1' ";
		
		PreparedDBUtil pdb = new PreparedDBUtil();
		try {
			return pdb.executeSelectForList("net3g", sql, 0L, 500, String.class);
		} catch (Exception e) {
			logger.error("查询需要发短信处理的数据失败", e);
		}
		return null;
	}
	
	public void sendSmsSuccess(String userid) {
		String sql = "update net3g.TD_BUSSINESS_HANDLE_MANGO3JS set smsstatus='0',smstime=sysdate where userid=?";
		try {
			SQLExecutor.updateWithDBName("net3g", sql, new Object[] { userid });
		} catch (SQLException e) {
			logger.error("更改TB_USERID_FAKEID失败", e);
		}
	}
	
	public void sendSmsfail(String userid) {
		String sql = "update net3g.TD_BUSSINESS_HANDLE_MANGO3JS set smsstatus='2',smstime=sysdate where userid=?";
		try {
			SQLExecutor.updateWithDBName("net3g", sql, new Object[] { userid });
		} catch (SQLException e) {
			logger.error("更改TB_USERID_FAKEID失败", e);
		}
	}
	
	public void sendSmsNot(String userid) {
		String sql = "update net3g.TD_BUSSINESS_HANDLE_MANGO3JS set smsstatus='3',smstime=sysdate where userid=?";
		try {
			SQLExecutor.updateWithDBName("net3g", sql, new Object[] { userid });
		} catch (SQLException e) {
			logger.error("更改TB_USERID_FAKEID失败", e);
		}
	}
	
	public void sendSmsExeception(String userid) {
		String sql = "update net3g.TD_BUSSINESS_HANDLE_MANGO3JS set smsstatus='4',smstime=sysdate where userid=?";
		try {
			SQLExecutor.updateWithDBName("net3g", sql, new Object[] { userid });
		} catch (SQLException e) {
			logger.error("更改TB_USERID_FAKEID失败", e);
		}
	}
	
	
	public boolean queryOrderRelation16(String userid) throws SQLException{
		String sql = "select count(1) totals from TD_ORDER_RELATIONS where userid =? and cpid ='mangtv16' and spid='1006' and status='0'";
		return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid))>0;
	}
  
}