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

📄 moprocessor.java

📁 国内很牛的软件公司花费两年半开发的用EJB3开发的代码,采用STRUTS和EJB3,目前系统进行第二版.所以拿出来共享
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		cs.registerOutParameter(4, java.sql.Types.VARCHAR);
		cs.registerOutParameter(5, java.sql.Types.INTEGER);
		cs.registerOutParameter(6, OracleTypes.CURSOR);
		cs.execute();
		param.put(PARAM_SmsTitle, cs.getString(3));
		param.put(PARAM_SmsTail, cs.getString(4));
		param.put(PARAM_SmsPageCount, cs.getString(5));
		ResultSet rs = (ResultSet)cs.getObject(6);		
		while(rs.next()){
			SMSSearchResult result = new SMSSearchResult();
			result.setSerialNumber(rs.getString("serialnumber"));
			result.setBoothId(rs.getInt("boothid"));
			result.setBoothName(rs.getString("boothname"));
			list.add(result);
		}
		rs.close();
		cs.close();
	}
	private static void createSearchMOMT(int localId, Connection conn, int pageNo, MOInfo info, Hashtable<String, String> param, ArrayList<SMSSearchResult> list) throws SQLException{
		//如果PageNo <SmsPageCount,短信内容SmsContent = SmsTitle + SmsDetailResultSet +SmsTail
		//否则
SmsContent =SmsTitle + SmsDetailResultSet				
		if(list.size() == 0){
			String msg = MessageFormat.format(MSG_NO_RESULT, info.getMSGCONTENT());
			createMOMT(localId, conn, msg, info.getUSERNUMBER(), 2, "0", info.getLINKID(), info.getID(), "", "", "", 1, 1, null);
		}
		else{
			int smsPageCount = Integer.parseInt(param.get(PARAM_SmsPageCount));
			StringBuffer sbuff = new StringBuffer();
			sbuff.append(param.get(PARAM_SmsTitle) + "\r\n");
			for(SMSSearchResult result : list){
				sbuff.append(MessageFormat.format(SMS_SEARCH_TEMPLATE, result.getSerialNumber(), result.getBoothName()));
				sbuff.append("\r\n");
			}
			if(pageNo < smsPageCount){
				sbuff.append(param.get(PARAM_SmsTail));
			}
			else{ 				
				String sTail = param.get(PARAM_SmsTail);
				if(sTail != null){
					String [] ss = sTail.split("[,|,|.|。]");
					if(ss.length > 1){
						sbuff.append(ss[0]);
					}
				}				
			}
			createMOMT(localId, conn, sbuff.toString(), info.getUSERNUMBER(), 0, 
					"0", info.getLINKID(), info.getID(), param.get(PARAM_Port),
					param.get(PARAM_SeqNo), "", 2, 1, null);
		}
		
	}
	private static void createNotPortMOMT(int localId, Connection conn, String msg, MOInfo info) throws SQLException{
		createMOMT(localId, conn, msg, info.getUSERNUMBER(), 2, "0", info.getLINKID(), info.getID(), "", "", "", 1, 1, null);
	}
	private static void createNotNumberMOMT(int localId, Connection conn, String msg, MOInfo info, Hashtable<String, String> param) throws SQLException{
		createMOMT(localId, conn, msg, info.getUSERNUMBER(), 0, "0", info.getLINKID(), info.getID(), 
				param.get(PARAM_Port), param.get(PARAM_SeqNo), "", 2, 1, null);
	}
	private static void createNotSerialNumMOMT(int localId, Connection conn, String msg, MOInfo info, Hashtable<String, String> param) throws SQLException{
		createMOMT(localId, conn, msg, info.getUSERNUMBER(), 0, "0", info.getLINKID(), info.getID(), 
				param.get(PARAM_Port), param.get(PARAM_SeqNo), "", 2, 1, null);
	}
	private static void createMOMT(int localId, Connection conn, String msg, String phoneNum, int userType, String userID, String linkId, 
			int MOId, String port, String seqNo, String batchNo, int operatorType, int businessType, String url) throws SQLException{
		CallableStatement cs = conn.prepareCall("{call pro_Sms_SendSms(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
		cs.setString(1, msg);
		cs.setInt(2, 1);
		cs.setString(3, phoneNum);
		cs.setInt(4, operatorType);
		cs.setInt(5, businessType);
		cs.setInt(6, userType);
		cs.setString(7, userID);
		cs.setInt(8, (url==null)?0:1);
		cs.setString(9, (url == null)?"":url);
		if(linkId == null || linkId.length() == 0){
			linkId = "MO" + MOId;
		}
		cs.setString(10, linkId);
		cs.setInt(11, 9);
		cs.setString(12, "");
		cs.setString(13, port);
		cs.setString(14, seqNo);
		cs.setString(15, batchNo);
		cs.setString(16, "");
		cs.execute();
		cs.close();
		if(localId != InitListener.CENTER_ID){
			ProcessorFactory.getMTInstance(localId);
		}
	}
	private static int shopProcess(int localId, Connection conn, MOInfo info, StringBuffer boothIdBuff) throws SQLException{
		Hashtable<String, String> param = new Hashtable<String, String>();
		int boothId = 0;
		boothId = Integer.parseInt(boothIdBuff.toString());
		param.put(PARAM_UserId, boothIdBuff.toString());
		getShopInfo(conn, info, param, 1);
		boothId = Integer.parseInt(param.get(PARAM_UserId));
		return invokeMOCommand(localId, boothId, 1, info, param);
	}
	private static int OperatorProcess(int localId, Connection conn, MOInfo info, StringBuffer boothIdBuff) throws SQLException{
		Hashtable<String, String> param = new Hashtable<String, String>();
		int operatorId = 0;
		getShopInfo(conn, info, param, 0);
		if(param.get(PARAM_UserId) != null){
			operatorId = Integer.parseInt(param.get(PARAM_UserId));
		}		
		return invokeMOCommand(localId, operatorId, 0, info, param);
	}
	private static void getShopInfo(Connection conn, MOInfo info, Hashtable<String, String> param, int userType) throws SQLException{		
		//取特服号及序列号关联的用户类型(1),用户标识及关联标识(BatchNo) 
		//涉及结构 TB_PORT_SEQNO_SPECIALLIST:port 特服号 SeqNo 序列号 UserType -1搜索1商铺 UserId 用户标识 RelatedId 关联标识
		PreparedStatement ps = conn.prepareStatement("select USERID,RELATEDID from TB_PORT_SEQNO_SPECIALLIST" +
				" where port = ? and SEQNO = ? and USERTYPE = ?");
		ps.setString(1, info.getPORT());
		ps.setString(2, info.getSEQNO());
		ps.setInt(3, userType);
		ResultSet rs = ps.executeQuery();
		if(rs.next()){
			param.put(PARAM_UserId, rs.getString(1));
			param.put(PARAM_BatchNo, rs.getString(2));
		}
		ps.close();
	}
	private static int invokeMOCommand(int localId, int boothId, int type, MOInfo info, Hashtable<String, String> param){
		//调用商街MO指令业务处理接口
		ISmsMOCommandInterface bean = (ISmsMOCommandInterface)EJBBoClient.getClient(localId, "StreetMOCommandBean");
		MOCommandInfo command = new MOCommandInfo();
		if(param.get(PARAM_BatchNo) != null){
			command.setBatchNo(param.get(PARAM_BatchNo));
		}		
		command.setMoInfo(info);
		command.setUserId(String.valueOf(boothId));
		command.setUserType(type);
		return bean.MOCommand(localId, command, new String[]{""});
	}
	private static int userShareProcess(int localId, Connection conn, MOInfo info) throws SQLException{
		Hashtable<String, String> param = new Hashtable<String, String>();
		getUserInfo(conn, info, param);
		if(param.get(PARAM_UserId) == null || param.get(PARAM_UserId).compareTo("") == 0){
			return search(localId, conn, info);
		}
		else{
			int userId = Integer.parseInt(param.get(PARAM_UserId));
			int userType = Integer.parseInt(param.get(PARAM_UserType));
			return invokeMOCommand(localId, userId, userType, info, param);
		}		
	}
	private static void getUserInfo(Connection conn, MOInfo info, Hashtable<String, String> param) throws SQLException{
		//取长特服号关联的用户类型,用户标识
		//涉及结构 TB_PORT_SHAREDLIST port 长特服号(Port +SeqNo) ApplicantType 用户类型(0运营人员,1商铺,2会员,3代理商) Applicant 用户标识
		PreparedStatement ps = conn.prepareStatement("select APPLICANTTYPE,APPLICANT from TB_PORT_SHAREDLIST where port = ?");
		String port = info.getPORT() + "00000";		
		ps.setString(1, port.substring(0,5) + info.getSEQNO());
		ResultSet rs = ps.executeQuery();
		if(rs.next()){
			param.put(PARAM_UserType, rs.getString(1));
			param.put(PARAM_UserId, rs.getString(2));			
		}
		ps.close();
	}
	private static int processWithoutPort(int localId, Connection conn, MOInfo info) throws SQLException{
		int ret = 1;
		Hashtable<String, String> param = new Hashtable<String, String>();
		int boothId = getBoothId(conn, info.getMSGCONTENT());		
		if(boothId > 0){
			ret = invokeMOCommand(localId, boothId, 1, info, param);
		}
		else{
			ret = createSearchContext(localId, conn, info, param);
			if(ret == 1){
				int pageNo = 1;
				ArrayList<SMSSearchResult> list = new ArrayList<SMSSearchResult>();
				getSearchContext(conn, pageNo, param, list);
				createSearchMOMT(localId, conn, pageNo, info, param, list);
			}
			else if(ret == 0){
				createNotPortMOMT(localId, conn, MSG_ERROR_MESSAGE, info);
				ret = 1;
			}
			else{
				ret = 1;
			}
			
		}
		return ret;
	}
	private static int getBoothId(Connection conn, String realName) throws SQLException{
		//取短信内容对应的实名所属的商铺
(boothid)
		//涉及结构 tb_realname: realnameid,realname,enable(1-正常),deleteflag(1启用)
		//tb_booth_realname:realnameid,boothid,state(0-停止1-启用),deadline
		//使用fn_ForPlat_GetRealNameOwner
		int ret = 0;
		if(realName != null){
			try{
				CallableStatement cs = conn.prepareCall("{? = call fn_ForPlat_GetRealNameOwner(?)}");		
				cs.registerOutParameter(1, java.sql.Types.INTEGER);
				cs.setString(2, realName);
				cs.execute();
				ret = cs.getInt(1);
				cs.close();
			}
			catch(Exception e){
				RunTimeLogger.error(MOProcessor.class, "待查实名词:" + realName, e);
			}			
		}		
		return ret;
	}
	private static boolean checkMOCommand(String content){
		//搜索指令内容为空或N(NEXT)或下(下一页)
		boolean ret = true;
		if(content == null || content.trim().length() == 0 || content.compareToIgnoreCase("N") == 0 
		   || content.compareToIgnoreCase("next") == 0 || content.compareTo("下") == 0 || content.compareTo("下一页") == 0){
			ret = true;
		}
		else{
			ret = false;
		}
		return ret;
	}
	private static int getBoothIdBySerialNum(Connection conn, String contextId, int SerialNum) throws SQLException{
		//根据上下文标识及用户回复的序号取得目标商铺
boothid
		//取上下文标识及序列号(数字型短信内容)调用存储过程pro_Search_GetTargetBooth
		//返回目标商铺boothid		
		int ret = 0;
		CallableStatement cs = conn.prepareCall("{call pro_Search_GetTargetBooth(?,?,?)}");		
		cs.setString(1, contextId);
		cs.setInt(2, SerialNum);
		cs.registerOutParameter(3, java.sql.Types.INTEGER);		
		cs.execute();
		ret = cs.getInt(3);
		cs.close();
		return ret;
	}
	
	private static int multiSend(int localId, Connection conn, MOInfo info) throws SQLException{
		info.setPORT(getSearchPort(conn));
		return search(localId, conn, info);
	}
	private static String getSearchPort(Connection conn) throws SQLException{
		String ret = "";
		PreparedStatement ps = conn.prepareStatement("select port from TB_PORT" +
				" where porttype = ? and deadline > ? and deleteflag <> ? and localstate=?");
		ps.setInt(1, -1);
		ps.setTimestamp(2, new Timestamp(new Date().getTime()));
		ps.setInt(3, 1);
		ps.setInt(4, 1);
		ResultSet rs = ps.executeQuery();
		if(rs.next()){
			ret = rs.getString(1);
		}
		rs.close();
		ps.close();
		return ret;
	}
}
class SMSSearchResult{
	private String serialNumber;
	private int boothId;
	private String boothName;
	public int getBoothId() {
		return boothId;
	}
	public void setBoothId(int boothId) {
		this.boothId = boothId;
	}
	public String getBoothName() {
		return boothName;
	}
	public void setBoothName(String boothName) {
		this.boothName = boothName;
	}
	public String getSerialNumber() {
		return serialNumber;
	}
	public void setSerialNumber(String serialNumber) {
		this.serialNumber = serialNumber;
	}
}

⌨️ 快捷键说明

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