📄 moprocessor.java
字号:
ps.setString(1, port);
ps.setInt(2, 1);
ps.setInt(3, 1);
ResultSet rs = ps.executeQuery();
if(rs.next()){
ret = rs.getInt(1);
String s = rs.getString(2);
Timestamp ts = rs.getTimestamp(3);
if(ts != null){
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
if(ts.before(c.getTime())){
ret = 0;
}
}
else{
if(ret == 1){
ret = 0;
}
}
if(s != null){
boothId.append(s);
}
}
rs.close();
ps.close();
return ret;
}
private static final String PARAM_ContextID = "ContextID";
private static final String PARAM_PageNO = "PageNO";
private static final String PARAM_Port = "Port";
private static final String PARAM_SeqNo = "SeqNo";
private static final String PARAM_UserId = "UserId";
private static final String PARAM_BatchNo = "BatchNo";
private static final String PARAM_UserType = "UserType";
private static final String PARAM_SmsTitle = "SmsTitle";
private static final String PARAM_SmsTail = "SmsTail";
private static final String PARAM_SmsPageCount = "SmsPageCount";
private static int search(int localId, Connection conn, MOInfo info) throws SQLException{
int ret = 1;
int boothId = 0;
String command = "";
String value = info.getMSGCONTENT();
boolean msgIsRealName = false;
boolean isCommand = false;
if(info.getMSGCONTENT() != null && info.getMSGCONTENT().trim().length() > 0){
// 判断指令是否是"W 搜索词"或者"WAP 搜索词"
value = value.trim();
int i = 0;
for(; i < value.length(); i++){
String ch = value.substring(i, i+1);
if(MOCommandFactroy.isCommandSplit(ch)){
command = value.substring(0, i);
value = value.substring(i + 1);
break;
}
}
if(command.compareTo("") != 0){
isCommand = MOCommandFactroy.isCommand(command);
if(isCommand){
if(value != null && value.length() > 0){
boothId = getBoothId(conn, value.trim());
}
}
else{
boothId = getBoothId(conn, info.getMSGCONTENT().trim());
if(boothId > 0) msgIsRealName = true;
}
}
else{
boothId = getBoothId(conn, info.getMSGCONTENT().trim());
if(boothId > 0) msgIsRealName = true;
}
}
if(info.getMSGCONTENT() != null && command.compareTo("") == 0 && MOCommandFactroy.isCommand(info.getMSGCONTENT().trim())){
PlatFormConfig bean = (PlatFormConfig) EJBBoClient.getClient(localId, "PlatFormConfigBean");
String url = "";
try {
PublicParam param = (PublicParam)EJBBoClient.getClient(localId, "PublicParamBean");
List<PlatformConfigEntity> list = bean.getConfig(param.getIntParam(PublicParam.LOCAL_ID));
for(PlatformConfigEntity e : list){
if(e.getObjectId() == InitListener.CENTER_ID){
url = e.getWapUrl();
break;
}
}
} catch (Exception e) {
RunTimeLogger.error(MOProcessor.class, e.getMessage(), e);
ret = 0;
}
if(url != null && url.compareTo("") != 0){
createMOMT(localId, conn, MSG_KEY_W_WAPPUSH, info.getUSERNUMBER(), 0, "0", info.getLINKID(), info.getID(), "", "", "", 1, 1, url);
ret = 1;
}
else{
ret =0;
}
}
else{
// 如果搜索词是否是实名,则调用接口指定商铺,处理指令
if(boothId > 0){
StreetMOCommand bean = (StreetMOCommand)EJBBoClient.getClient(localId, "StreetMOCommandBean");
if(msgIsRealName){
MOCommandInfo commandInfo = new MOCommandInfo();
info.setMSGCONTENT("");
commandInfo.setMoInfo(info);
commandInfo.setUserId(String.valueOf(boothId));
commandInfo.setUserType(1);
info.setPORT("");
info.setSEQNO("");
ret = bean.MOCommand(localId, commandInfo, new String[]{""});
}
else{
ret = bean.boothCommand(localId, boothId, 1, command, value, info);
}
}
//否则,作为搜索处理
else{
if(isCommand){
info.setMSGCONTENT(value);
}
if(info.getPORT() != null && info.getPORT().compareTo("") != 0){
ret = searchFromDB(localId, conn, info);
}
else{
ret = processWithoutPort(localId, conn, info);
}
}
}
return ret;
}
private static int searchFromDB(int localId, Connection conn, MOInfo info) throws SQLException{
int ret = 1;
Hashtable<String, String> param = new Hashtable<String, String>();
getContextID(conn, info, param);
String contextId = param.get(PARAM_ContextID);
int pageNo = Integer.parseInt(param.get(PARAM_PageNO));
pageNo++;
boolean hasMOMT = false;
if(contextId == null || contextId.length() == 0){
if(info.getMSGCONTENT() == null || info.getMSGCONTENT().trim().compareTo("") == 0){
ret = 0;
hasMOMT = true;
}
else{
ret = createSearchContext(localId, conn, info, param);
if(ret == 1){
contextId = param.get(PARAM_ContextID);
info.setPORT(param.get(PARAM_Port));
info.setSEQNO(param.get(PARAM_SeqNo));
}
hasMOMT = true;
}
}
else{
if(checkMOCommand(info.getMSGCONTENT())){
hasMOMT = true;
}
}
if(hasMOMT){
if(ret == 1){
ArrayList<SMSSearchResult> list = new ArrayList<SMSSearchResult>();
getSearchContext(conn, pageNo, param, list);
param.put(PARAM_Port, info.getPORT());
param.put(PARAM_SeqNo, info.getSEQNO());
createSearchMOMT(localId, conn, pageNo, info, param, list);
}
else if(ret == 0){
createNotPortMOMT(localId, conn, MSG_ERROR_MESSAGE, info);
ret = 1;
}
else{
ret = 1;
}
}
else{
String msg = info.getMSGCONTENT();
boolean isNum = false;
int serialNum = 0;
if(msg != null && msg.length() > 0){
try{
serialNum = Integer.parseInt(msg);
if(serialNum > 0){
isNum = true;
}
}
catch(Exception e){
isNum = false;
}
}
if(isNum){
int boothId = getBoothIdBySerialNum(conn, param.get(PARAM_ContextID), serialNum);
if(boothId > 0){
info.setPORT("");
info.setSEQNO("");
info.setMSGCONTENT("");
ret = invokeMOCommand(localId, boothId, 1, info, param);
}
else{
//下行短信“无效的序号,请回复序号访问短信门户,或N看下一条”(MOMT)
param.put(PARAM_Port, info.getPORT());
param.put(PARAM_SeqNo, info.getSEQNO());
createNotSerialNumMOMT(localId, conn, MSG_NOTFOUND_BOOTHID, info, param);
}
}
else{
//如短信内容不是数字直接下行短信:请回复序号访问短信门户,或N看下一条(MOMT)
param.put(PARAM_Port, info.getPORT());
param.put(PARAM_SeqNo, info.getSEQNO());
createNotNumberMOMT(localId, conn, MSG_NOTFOUND_SERIALNUM, info, param);
}
}
return ret;
}
private static void getContextID(Connection conn, MOInfo info, Hashtable<String, String> param) throws SQLException{
//取UserNumber,Port,SeqNo调用存储过程pro_Search_GetContext
返回ContextId,PageNo
CallableStatement cs = conn.prepareCall("{call pro_Search_GetContext(?,?,?,?,?)}");
cs.setString(1, info.getUSERNUMBER());
cs.setString(2, info.getPORT());
cs.setString(3, info.getSEQNO());
cs.registerOutParameter(4, java.sql.Types.VARCHAR);
cs.registerOutParameter(5, java.sql.Types.INTEGER);
cs.execute();
String s = cs.getString(4);
if(s != null){
param.put(PARAM_ContextID, s);
}
s = cs.getString(5);
if(s != null){
param.put(PARAM_PageNO, s);
}
cs.close();
}
/**
*
* @param conn
* @param info
* @param param
* @return 0表示没有搜索到内容,1表示有搜索结果,2表示搜索关键字过长
* @throws SQLException
*/
private static int createSearchContext(int localId, Connection conn, MOInfo info, Hashtable<String, String> param) throws SQLException{
int ret = 0;
//生成搜索上下文,取得ContextId,Port,SeqNo
//取MsgContent,UserNumber调用存储过程pro_Search_GetNewContext 返回ContextId,Port,SeqNo
if(info.getMSGCONTENT().length() > 20){
createMOMT(localId, conn, MSG_KEY_MSG_TOO_LENGTH, info.getUSERNUMBER(), 2, "0", info.getLINKID(), info.getID(), "", "", "", 1, 1, null);
ret = 2;
}
else{
CallableStatement cs = conn.prepareCall("{call pro_Search_GetNewContext(?,?,?,?,?)}");
cs.setString(1, info.getUSERNUMBER());
cs.setString(2, info.getMSGCONTENT());
cs.registerOutParameter(3, java.sql.Types.VARCHAR);
cs.registerOutParameter(4, java.sql.Types.VARCHAR);
cs.registerOutParameter(5, java.sql.Types.INTEGER);
cs.execute();
String s = cs.getString(3);
if(s != null && s.compareTo("") != 0){
param.put(PARAM_ContextID, s);
param.put(PARAM_Port, cs.getString(4));
param.put(PARAM_SeqNo, cs.getString(5));
ret = 1;
}
cs.close();
}
return ret;
}
private static void getSearchContext(Connection conn, int pageNo, Hashtable<String, String> param, ArrayList<SMSSearchResult> list) throws SQLException{
//取上下文对应的短信信息(PageNo=1或上下文中的PageNo+1)
//取ContextId,PageNo调用存储过程pkg_Search.pro_Search_GetResultByCtxIdSms返回SmsTitle,SmsTail,SmsPageCount,SmsDetailResultSet
CallableStatement cs = conn.prepareCall("{call pkg_Search.pro_Search_GetResultByCtxIdSms(?,?,?,?,?,?)}");
cs.setString(1, param.get(PARAM_ContextID));
cs.setInt(2, pageNo);
cs.registerOutParameter(3, java.sql.Types.VARCHAR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -