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

📄 ismssenderbean.java

📁 国内很牛的软件公司花费两年半开发的用EJB3开发的代码,采用STRUTS和EJB3,目前系统进行第二版.所以拿出来共享
💻 JAVA
字号:
package com.ufmobile.platform.mstreet.sms;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.sql.DataSource;

import oracle.jdbc.driver.OracleTypes;

import com.ufmobile.business.account.bo.Account;
import com.ufmobile.business.account.bo.Account.AccountType;
import com.ufmobile.business.exception.AccountException;
import com.ufmobile.common.BaseBean;
import com.ufmobile.common.UFMobileUUID;
import com.ufmobile.mstreet.entity.BoothEntity;
import com.ufmobile.platform.InitListener;
import com.ufmobile.platform.ejb.BaseFunction;
import com.ufmobile.platform.ejb.EJBBoClient;
import com.ufmobile.platform.log.RunTimeLogger;
import com.ufmobile.platform.mstreet.processor.ProcessorFactory;

public @Stateless class ISMSSenderBean extends BaseBean  implements ISMSSender {	
	/*
	 * 
	 * 商街端发送短信接口函数,传入MTRequest信息,目标手机号存储于数组传入

	 * 
	 * @param  smsInfo 发送短信提交信息

	 * @param  mobileList 目标手机号数组

	 * @return	String 返回本次提交的BATCHNO信息
	 * */
	public String MtSubmit(int localId, MTRequest smsInfo, String[] mobileList) throws AccountException {	
		RunTimeLogger.info(this, "mobileList.size=" + mobileList.length);
		RunTimeLogger.info(this, "smsInfo.smsContent=" + smsInfo.getSmsContent());
		String account = null;
		String strBatchNo=smsInfo.getBatchNo();
		if(strBatchNo == null || strBatchNo.compareTo("") == 0){
			UFMobileUUID uuid = UFMobileUUID.randomUUID();
			strBatchNo = uuid.toString();
		}
		if(smsInfo.getApplicantType() == 1){
			Query query = this.getManager().createQuery(" from BoothEntity where boothid = ?1");
			query.setParameter(1, new Long(smsInfo.getApplicant()));
			List<BoothEntity> list = query.getResultList();
			if(list != null && list.size() > 0){
				BoothEntity booth = list.get(0);
				if(booth.getBoothpropertyid() == 2){//判断是否是标准商铺

					account = booth.getAccountid();
					if(account == null || account.compareTo("") == 0){
						throw new AccountException(this, "账户信息有误");
					}
				}								
			}
			
		}						
		//计数短信条数并调用商街提供接口进行扣费

		int nSmsCount=0;//占用实际短信条数
		String category = "";
		if(smsInfo.getSmsType()==0)//普通短信

		{
			nSmsCount=ISMSConnectorBean.GetSMSCount(smsInfo.getSmsContent());
			if(smsInfo.getOperationType() == 3){
				category = "00002";
			}
			else{
				category = "00001";
			}			
		}else if(smsInfo.getSmsType()==1)//WAPPUSH
		{
			nSmsCount=ISMSConnectorBean.GetWapPushCount(smsInfo.getSmsContent(),smsInfo.getPushUrl());
			category = "00100";
		}
		if(account != null){
			//扣费并且更新payOff
			Account bean = (Account)EJBBoClient.getClient(localId, "AccountBean");			
			bean.deduct(account, AccountType.Flow, new Integer(nSmsCount), new Long(mobileList.length), category, smsInfo.getApplicantType()+"|"+smsInfo.getApplicant(), strBatchNo);		
		}

		/*
		 * 调用存储过程(完成分条存储)
		 * */			
		StringBuffer strMobileList = new StringBuffer();
		int nCurCount=0;	
		String retPort = smsInfo.getPort();
		String retSeqNo = smsInfo.getSeqNo();		
		for(int n = 0; n < mobileList.length; n++)
		{
			if(nCurCount > 0)
			{
				strMobileList.append(",");				
			}
			RunTimeLogger.info(this, "mobileList["+n+"]=" + mobileList[n]);
			strMobileList.append(mobileList[n]);
			nCurCount++;
			
			if(nCurCount >= 250 || n == mobileList.length-1)
			{
				//调用存储过程  要保证只生成一个strBatchNo
				/////////				
				Connection conn = null;
				try
				{				
					conn = BaseFunction.getDataSource(localId).getConnection();
					CallableStatement cstmt = conn.prepareCall("{call pro_Sms_SendSms(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
					cstmt.setString(1,smsInfo.getSmsContent());
					cstmt.setInt(2,mobileList.length);
					cstmt.setString(3,strMobileList.toString());
					cstmt.setInt(4,smsInfo.getOperationType());
					cstmt.setInt(5,smsInfo.getBusinessType());
					cstmt.setInt(6,smsInfo.getApplicantType());
					cstmt.setInt(7,smsInfo.getApplicant());
					cstmt.setInt(8,smsInfo.getSmsType());
					cstmt.setString(9,smsInfo.getPushUrl());
					cstmt.setString(10,smsInfo.getLinkID());
					cstmt.setInt(11,smsInfo.getPriLevel());
					cstmt.setString(12,smsInfo.getMainNumber());
					cstmt.setString(13,retPort);
					cstmt.setString(14,retSeqNo);
					cstmt.setString(15,strBatchNo);
					cstmt.setString(16,((account == null)? "" : account));
					cstmt.registerOutParameter(13, java.sql.Types.VARCHAR);
					cstmt.registerOutParameter(14, java.sql.Types.VARCHAR);
					cstmt.registerOutParameter(15, java.sql.Types.VARCHAR);
	
					cstmt.executeQuery();
	
					retPort = cstmt.getString(13);
					retSeqNo = cstmt.getString(14);
					strBatchNo = cstmt.getString(15);							
					
					cstmt.close();
				}catch(Exception e)
				{
					RunTimeLogger.error(ISMSSenderBean.class, "MtSubmit", e);			
					strBatchNo = null;
				}
				finally{
					if(conn != null){
						try{
							conn.close();
						}
						catch(Exception e){
							RunTimeLogger.error(this, e.getMessage(), e);
						}
					}
				}
				//
				strMobileList.delete(0, strMobileList.length());
				nCurCount=0;
			}
			
		}
		if(localId != InitListener.CENTER_ID){
			ProcessorFactory.getMTInstance(localId);
		}
		return strBatchNo;
	}

	
	/*
	 * 用于查询短信发送状态情况

	 * 
	 * @param  batchNO  发送时返回的批次号,用户查询定位

	 * @param  mobileNumber  查询的手机号信息
	 * @return	List<MTDetailInfo>  返回查询结果对应的MTDetailInfo数组 null表示没有找到符合条件的短信

	 * */
	public List<MTDetailInfo> getMtDetails(String batchNo, String mobileNumber) {
		List<MTDetailInfo> retList;
		try{
		String sql = "from MTDetailInfo where BATCHNO = ?1 and USERNUMBER = ?2";
		Query query = this.getManager().createQuery(sql);
		query.setParameter(1, batchNo);
		query.setParameter(2, mobileNumber);
		retList = query.getResultList();
		}catch(Exception e)		
		{
			RunTimeLogger.error(ISMSSenderBean.class, "getMtDetails(String,int)", e);			
			return null;
		}
		return retList;
	}

	/*
	 * 用于查询短信发送状态情况

	 * 
	 * @param  batchNO  发送时返回的批次号,用户查询定位

	 * @param  begin  起始位置
	 * @param  end    终止位置
	 * @return	List<MTDetailInfo>  返回查询结果对应的MTDetailInfo数组  null表示没有找到符合条件的短信

	 * */
	public List<MTDetailInfo> getMtDetails(String batchNo, int begin, int end) {
		List<MTDetailInfo> retList;
		try
		{
		String sql = "from MTDetailInfo where BATCHNO = ?1 ";
		Query query = this.getManager().createQuery(sql);
		query.setParameter(1, batchNo);
		query.setFirstResult(begin);
		query.setMaxResults(end - begin);
		retList = query.getResultList();
		}catch(Exception e)
		{
			RunTimeLogger.error(ISMSSenderBean.class, "getMtDetails(String,int,int)", e);		
			return null;
		}
		return retList;

	}

	/*
	 * 将向商街提交的MRInfo数据写入商街数据库表
	 * 
	 *@param  MRInfos  状态报告数组

	 *@return	int 返回1表示成功,返回0表示失败
	 **/
	public int setMR(MRInfo[] MRInfos) {
		MRInforDAO dao = new MRInforDAO(); 
		
		try{	
			for(int i=0;i<MRInfos.length;i++)
			{
				MRInfo mrinfor=MRInfos[i];			
				dao.save(this.getManager(), mrinfor);		
			}
			return 1;
		}catch(Exception e)		
		{
			RunTimeLogger.error(ISMSSenderBean.class, "ISMSSenderBean", e);		
			return 0;
		}		
		
	}

	/*
	 * 将向商街提交的MOInfos数据写入商街数据库表
	 * 
	 *@param  MRInfos  状态报告数组

	 *@return	int 返回1表示成功,返回0表示失败
	 **/
	public int setMO(int localId, MOInfo[] MOInfos) {		
		MOInfoDAO dao = new MOInfoDAO(); 
		
		try{	
			for(int i=0;i<MOInfos.length;i++)
			{
				MOInfo moinfor=MOInfos[i];
				moinfor.setDISPATCHEDFLAG(0);
				dao.save(this.getManager(), moinfor);
			}
			ProcessorFactory.getMOInstance(localId);
			return 1;
		}catch(Exception e)		
		{
			RunTimeLogger.error(ISMSSenderBean.class, "ISMSSenderBean", e);		
			return 0;
		}			
		
	}
	public List<WapSearchResult> wapSearch(int localId, String keyWord, int startRow, int endRow) {		
		List<WapSearchResult> ret = new ArrayList<WapSearchResult>();
		Connection conn = null;
		try{
			DataSource ds = BaseFunction.getDataSource(localId);
			conn = ds.getConnection();
			CallableStatement cs = conn.prepareCall("{call pkg_Search.pro_Search_GetResultWap(?,?,?,?)}");
			cs.setString(1, keyWord);
			cs.setInt(2, startRow);
			cs.setInt(3, endRow);
			cs.registerOutParameter(4, OracleTypes.CURSOR);
			cs.execute();
			ResultSet rs = (ResultSet)cs.getObject(4);		
			while(rs.next()){
				WapSearchResult result = new WapSearchResult();
				result.setSerialNum(rs.getInt("serialnumber"));
				result.setBoothId(rs.getInt("boothid"));
				result.setBoothName(rs.getString("boothname"));
				int n = rs.getInt("isRealName");
				if(n == 1){
					result.setRealName(true);
				}
				else{
					result.setRealName(false);
				}
				ret.add(result);
			}
			rs.close();
			cs.close();
		}
		catch(Exception e){
			RunTimeLogger.error(this, "call pkg_Search.pro_Search_GetResultWap ", e);
		}
		finally{			
			if(conn != null){
				try {
					conn.close();
				} catch (SQLException e) {
					RunTimeLogger.error(this, "conn.close()", e);
				}
				conn = null;
			}
		}	
		return ret;
	}
	public List<String> getHotSearchKeyWord(int count) {
		List<String> ret = new ArrayList<String>();
		EntityManager manager = super.getManager();
		Query query = manager.createQuery(" from SearchResultSetPreEntity a order by a.searchCount desc");
		query.setMaxResults(count);
		List list = query.getResultList();
		if(list != null && list.size() > 0){
			for(int i = 0; i < list.size(); i++){
				ret.add(((SearchResultSetPreEntity)list.get(i)).getSearchString());
			}
		}
		return ret;
	}
	
	public int MtSubmit(MTSubmit[] mtSubmit) {
		MTSubmitDAO dao = new MTSubmitDAO(); 		
		try{	
			for(int i=0;i<mtSubmit.length;i++)
			{
				MTSubmit submit=mtSubmit[i];			
				dao.save(super.getManager(), submit);		
			}
			return 1;
		}catch(Exception e)		
		{
			RunTimeLogger.error(this, "MtSubmit", e);		
			return 0;
		}
	}
}

⌨️ 快捷键说明

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