⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmsmonthcustommanager.java

📁 MM7彩信对接网关示例
💻 JAVA
字号:
/*
 * Created on 2005-2-17
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.rainbow.mms.monthcustom;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;

import com.rainbow.util.tools.HibernateUtil;


/**
 * @author Rainbow MMS Group -- TrWorks
 *
 * TODO 管理彩信的包月定制业务
 */
public class MMSMonthCustomManager {
	
	/**
	 * MMSMonthCustomManager 单体
	 */
	private static MMSMonthCustomManager instance = null;
	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(MMSMonthCustomManager.class);

	
	/**
	 * 获得彩信内容生成者的实体
	 * 
	 * @return 彩信内容生成者的实体
	 */
	public static MMSMonthCustomManager getInstance() {

		if (instance == null) {

			instance = new MMSMonthCustomManager();
		}

		return instance;
	}
	
	/**
	 * 获得数据库中注册的所有包月定制业务的配置
	 * @return 包月定制业务的配置列表(MMSMonthCustom列表)
	 */
	public List showMonthCustom(){
		
		List list = new ArrayList();
		Connection dbConnection = null;
		CallableStatement statement = null;
		ResultSet set = null;
		int pContentID = 0;
		
		try {
			Session sess = HibernateUtil.currentSession();
			dbConnection = sess.connection();
			//Transaction tx1 = sess.beginTransaction();
			// 调用存储过程 MMS_PMonthCustomShow
			statement = dbConnection
					.prepareCall("{call MMS_PMonthCustomShow ()}");

			set = statement.executeQuery();
			
			// 组装结果集
			while (set.next() != false){
				MMSMonthCustom m = new MMSMonthCustom();
				m.setMcid(set.getInt("tnMCID"));
				m.setUniformID(set.getInt("tnUniformID"));
				m.setGateWayID(set.getInt("tnGateWayID"));
				m.setName(set.getString("tcName"));
				m.setLastContentID(set.getInt("tnLastContentID"));
				m.setLastContentIDBeSend(set.getInt("tnLastContentIDBeSend") == 0 ? false : true);
				m.setLastContentIDSendTime(set.getString("ttLastContentIDSendTime"));
				
				list.add(m);
			}

		} catch (Exception cnfe) {
			cnfe.printStackTrace();
			list = null;
		} finally {
			
			if (set != null){
				try {
					set.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			HibernateUtil.closeSession();
		}

		return list;
	}
	
	/**
	 * 生成并发送的包月定制内容
	 * @return 生成SUBMIT的总数
	 * @param mcid 要发的彩信业务编号,这个编号是由UniformID和GatewayID复合而成的Mcid
	 */
	public int sendMonthCustom(final int mcid){
		// 检查输入参数是否正确
		if (mcid <= 0){
			log.error("输入参数错误");
			return -1;
		}
		
		Connection dbConnection = null;
		CallableStatement statement = null;
		int result = -1;
		
		try {
			Session sess = HibernateUtil.currentSession();
			dbConnection = sess.connection();
			
			// 调用存储过程 MMS_PMonthCustomSend
			statement = dbConnection
					.prepareCall("{call MMS_PMonthCustomSend (?, ?, ?)}");
			statement.setInt(1, mcid);
			statement.registerOutParameter(2, Types.INTEGER);
			statement.registerOutParameter(3, Types.INTEGER);
			
			statement.execute();
			dbConnection.commit();
			
			result = (statement.getInt(2) == 0 ? -1 : 0);
			if (result == 0){
				result = statement.getInt(3);
			}

		} catch (Exception cnfe) {
			cnfe.printStackTrace();
			return result;
			
		} finally {
			
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			HibernateUtil.closeSession();
		}

		return result;
	}
	
	/**
	 * 设置制定彩信包月业务的彩信内容
	 * @param mcID 彩信业务编号
	 * @param contentID 彩信内容编号
	 * @return 是否设置成功
	 */
	public boolean setMonthCustomContent(final int mcID, final int contentID){

		// 检查输入参数是否正确
		if (mcID <= 0 || contentID <= 0){
			log.error("输入参数错误");
			return false;
		}
		
		Connection dbConnection = null;
		CallableStatement statement = null;
		boolean result = false;
		
		try {
			Session sess = HibernateUtil.currentSession();
			dbConnection = sess.connection();
			//Transaction tx = sess.beginTransaction();
			
			// 调用存储过程 MMS_PMonthCustomSetContent
			statement = dbConnection
					.prepareCall("{call MMS_PMonthCustomSetContent (?, ?, ?)}");
			statement.setInt(1, mcID);
			statement.setInt(2, contentID);
			statement.registerOutParameter(3, Types.INTEGER);
			
			statement.execute();
			dbConnection.commit();
			//tx.commit();
			
			result = (statement.getInt(3) == 0 ? false : true);
			
		} catch (Exception cnfe) {
			cnfe.printStackTrace();
			return false;
			
		} finally {
			
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}

			HibernateUtil.closeSession();
		}

		return result;
	}
	
	/**
	 * 显示定制下发的发送记录
	 * @param apid 定制业务代码
	 * @param sBeginTime 查询开始时间
	 * @param endTime 查询结束时间
	 * @return 定制下发的发送记录
	 */
	public List showSendRecord(final int apid, String sBeginTime, String endTime){
		//  检查输入参数
		if (apid <= 0 || sBeginTime == null || sBeginTime.length() == 0 ||
				endTime == null || endTime.length() == 0){
			return null;
		}
		
		List list = new ArrayList();
		Connection dbConnection = null;
		CallableStatement statement = null;
		ResultSet set = null;
		
		try {
			Session sess = HibernateUtil.currentSession();
			dbConnection = sess.connection();

			// 调用存储过程 MMS_PMonthCustomShowSendRecord
			statement = dbConnection
					.prepareCall("{call MMS_PMonthCustomShowSendRecord (?, ?, ?)}");
			statement.setInt(1, apid);
			statement.setString(2, sBeginTime);
			statement.setString(3, endTime);

			set = statement.executeQuery();
			
			// 组装结果集
			while (set.next() != false){
				MMSMonthCustomSendRecord m = new MMSMonthCustomSendRecord();
				m.setServiceName(set.getString("tcName"));
				m.setUniformID(set.getInt("tnUniformID"));
				m.setSendTime(set.getString("ttSendTime"));
				m.setCreateTime(set.getString("ttCreateTime"));
				m.setContentID(set.getInt("tnPContentID"));
				
				list.add(m);
			}

		} catch (Exception cnfe) {
			cnfe.printStackTrace();
			list = null;
			
		} finally {
			
			if (set != null){
				try {
					set.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			HibernateUtil.closeSession();
		}

		return list;		
	}
	
	/**
	 * 暂停发送包月定制下发
	 * @param mcid 定制编号
	 * @return 暂停影响的纪录条数
	 */
	public int pauseSendMonthCustom(final int mcid){
		// 检查输入参数是否正确
		if (mcid <= 0){
			log.error("输入参数错误");
			return -1;
		}
		
		Connection dbConnection = null;
		CallableStatement statement = null;
		int cancelNum = -1;
		
		try {
			Session sess = HibernateUtil.currentSession();
			dbConnection = sess.connection();

			// 调用存储过程 MMS_PMonthCustomPauseSend
			statement = dbConnection
					.prepareCall("{call MMS_PMonthCustomPauseSend (?, ?)}");
			statement.setInt(1, mcid);
			statement.registerOutParameter(2, Types.INTEGER);
			
			statement.execute();
			dbConnection.commit();
			
			cancelNum = statement.getInt(2);			

		} catch (Exception cnfe) {
			cnfe.printStackTrace();
			return -1;
		} finally {
			
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			HibernateUtil.closeSession();
		}

		return cancelNum;		
	}
	
	/**
	 * 恢复发送包月定制下发
	 * @param mcid 定制编号
	 * @return 恢复影响的纪录
	 */
	public int suspendSendMonthCustom(final int mcid){
		// 检查输入参数是否正确
		if (mcid <= 0){
			log.error("输入参数错误");
			return -1;
		}
		
		Connection dbConnection = null;
		CallableStatement statement = null;
		int cancelNum = -1;
		
		try {
			Session sess = HibernateUtil.currentSession();
			dbConnection = sess.connection();

			// 调用存储过程 MMS_PMonthCustomSuspendSend
			statement = dbConnection
					.prepareCall("{call MMS_PMonthCustomSuspendSend (?, ?)}");
			statement.setInt(1, mcid);
			statement.registerOutParameter(2, Types.INTEGER);
			
			statement.execute();
			dbConnection.commit();
			
			cancelNum = statement.getInt(2);			

		} catch (Exception cnfe) {
			cnfe.printStackTrace();
			return cancelNum;
		} finally {
			
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			HibernateUtil.closeSession();
		}

		return cancelNum;		
	}
	
	/**
	 * 撤销要发送的包月定制下发
	 * @param mcid 定制编号
	 * @return 撤销了多少条记录
	 */
	public int cancelSendMonthCustom(final int mcid){
		// 检查输入参数是否正确
		if (mcid <= 0){
			log.error("输入参数错误");
			return -1;
		}
		
		Connection dbConnection = null;
		CallableStatement statement = null;
		int cancelNum = -1;
		
		try {
			Session sess = HibernateUtil.currentSession();
			dbConnection = sess.connection();

			// 调用存储过程 MMS_PMonthCustomCancelSend
			statement = dbConnection
					.prepareCall("{call MMS_PMonthCustomCancelSend (?, ?)}");
			statement.setInt(1, mcid);
			statement.registerOutParameter(2, Types.INTEGER);
			
			statement.execute();
			dbConnection.commit();
			
			cancelNum = statement.getInt(2);			

		} catch (Exception cnfe) {
			cnfe.printStackTrace();
			return cancelNum;
		} finally {
			
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			HibernateUtil.closeSession();
		}

		return cancelNum;		
	}
	
	public static void main(String[] args) {
		
		MMSMonthCustomManager m = MMSMonthCustomManager.getInstance();
				
		List list = m.showMonthCustom();
		
		for (int i = 0; i < list.size(); i++){
			MMSMonthCustom c = (MMSMonthCustom)list.get(i);
			System.out.println(c.toString());
		}
		
		System.out.println("生成定制:" + m.sendMonthCustom(10));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -