118 lines
4.8 KiB
Java
118 lines
4.8 KiB
Java
package com.tenwa.message;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.amarsoft.are.jbo.*;
|
||
import com.tenwa.lease.util.SendMessageUtil;
|
||
import jbo.com.tenwa.lease.comm.LB_SMS_NOTICE_TASKS;
|
||
import org.apache.commons.logging.Log;
|
||
import org.apache.commons.logging.LogFactory;
|
||
import org.quartz.Job;
|
||
import org.quartz.JobExecutionContext;
|
||
import org.quartz.JobExecutionException;
|
||
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.Date;
|
||
|
||
public class JobSendMessage implements Job{
|
||
|
||
private Log logger = LogFactory.getLog(this.getClass());
|
||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
|
||
@Override
|
||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||
JBOTransaction tx = null;
|
||
String smsnoticeid = null;
|
||
try {
|
||
tx= JBOFactory.createJBOTransaction();
|
||
smsnoticeid = context.getJobDetail().getJobDataMap().getString("smsnoticeid");
|
||
logger.info("short message running..... LB_SMS_NOTICE_TASKS[ID]: "+smsnoticeid);
|
||
BizObjectManager bomNotice = JBOFactory.getBizObjectManager(LB_SMS_NOTICE_TASKS.CLASS_NAME,tx);
|
||
BizObject notice = bomNotice.createQuery("id=:id").setParameter("id", smsnoticeid).getSingleResult(true);
|
||
if(notice != null){
|
||
if(notice.getAttribute("send_flag").getInt() == 0){
|
||
String result = null;
|
||
boolean flagErrStatus = true;
|
||
try {
|
||
result = SendMessageUtil.sendMessageByHttpClient(notice.getAttribute("phone_number").getString(), notice.getAttribute("sms_content").getString());
|
||
if(!result.matches("^[0-9].*")){
|
||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||
if(jsonObject.getIntValue("status")==100){
|
||
flagErrStatus = false;
|
||
result = "È«²¿³É¹¦";
|
||
}else{
|
||
result = getResultCodeInfoNew(jsonObject.getString("status"));
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
logger.error("¶ÌÐÅ·¢ËÍÈÎÎñÖ´ÐÐʧ°Ü,LB_SMS_NOTICE_TASKS[ID] : "+smsnoticeid, e);
|
||
result = "·¢ËÍʧ°Ü£¬·¢ËÍÓöµ½Òì³££º" + e.getMessage();
|
||
}
|
||
notice.setAttributeValue("sms_type", "IMMEDIATELY");
|
||
notice.setAttributeValue("send_result", result);
|
||
notice.setAttributeValue("send_time", sdf.format(new Date()));
|
||
notice.setAttributeValue("send_flag", flagErrStatus ? 0 : 1);
|
||
bomNotice.saveObject(notice);
|
||
}
|
||
}
|
||
tx.commit();
|
||
} catch (Exception e) {
|
||
logger.error("short message error LB_SMS_NOTICE_TASKS[ID] : "+smsnoticeid ,e);
|
||
try {
|
||
tx.rollback();
|
||
} catch (JBOException e1) {
|
||
e1.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
|
||
public static String getResultCodeInfoNew(String code){
|
||
String codeMessage = "";
|
||
switch(code){
|
||
case "101": codeMessage = "²ÎÊý´íÎó"; break;
|
||
case "102": codeMessage = "ºÅÂë´íÎó"; break;
|
||
case "103": codeMessage = "µ±ÈÕÓàÁ¿²»×ã"; break;
|
||
case "104": codeMessage = "ÇëÇó³¬Ê±"; break;
|
||
case "105": codeMessage = "Óû§ÓàÁ¿²»×ã"; break;
|
||
case "106": codeMessage = "·Ç·¨Óû§"; break;
|
||
case "107": codeMessage = "Ìá½»ºÅÂ볬ÏÞ"; break;
|
||
case "111": codeMessage = "Ç©Ãû²»ºÏ·¨"; break;
|
||
case "120": codeMessage = "ÄÚÈݳ¤¶È³¬³¤£¬Çë²»Òª³¬¹ý500¸ö×Ö"; break;
|
||
case "121": codeMessage = "ÄÚÈÝÖÐÓÐÆÁ±Î´Ê"; break;
|
||
case "131": codeMessage = "IP·Ç·¨"; break;
|
||
default : codeMessage = code ; break;
|
||
}
|
||
return codeMessage;
|
||
}
|
||
|
||
public static String getResultCodeInfo(String code){
|
||
String codeMessage = "";
|
||
switch(code){
|
||
case "-1": codeMessage = "ǩȨʧ°Ü"; break;
|
||
case "-2": codeMessage = "δ¼ìË÷µ½±»½ÐºÅÂë"; break;
|
||
case "-3": codeMessage = "±»½ÐºÅÂë¹ý¶à"; break;
|
||
case "-4": codeMessage = "ÄÚÈÝδǩÃû"; break;
|
||
case "-5": codeMessage = "ÄÚÈݹý³¤"; break;
|
||
case "-6": codeMessage = "Óà¶î²»×ã"; break;
|
||
case "-7": codeMessage = "ÔÝÍ£·¢ËÍ"; break;
|
||
case "-8": codeMessage = "±£Áô"; break;
|
||
case "-9": codeMessage = "¶¨Ê±·¢ËÍʱ¼ä¸ñʽ´íÎó"; break;
|
||
case "-10": codeMessage = "Ï·¢ÄÚÈÝΪ¿Õ"; break;
|
||
case "-11": codeMessage = "ÕË»§ÎÞЧ"; break;
|
||
case "-12": codeMessage = "IpµØÖ··Ç·¨"; break;
|
||
case "-13": codeMessage = "²Ù×÷ƵÂÊ¿ì"; break;
|
||
case "-14": codeMessage = "²Ù×÷ʧ°Ü"; break;
|
||
case "-15": codeMessage = "ÍØÕ¹ÂëÎÞЧ"; break;
|
||
case "-16": codeMessage = "È¡Ïû¶¨Ê±,seqid´íÎó"; break;
|
||
case "-18": codeMessage = "ÔÝÁô"; break;
|
||
case "-19": codeMessage = "δ¿ªÍ¨ÉÏÐÐ"; break;
|
||
case "-20": codeMessage = "ÔÝÁô"; break;
|
||
case "-21": codeMessage = "°üº¬ÆÁ±Î´Ê"; break;
|
||
default : codeMessage = code; break;
|
||
}
|
||
if("0".equals(codeMessage.substring(0,1))){
|
||
codeMessage = "²Ù×÷³É¹¦";
|
||
}
|
||
return codeMessage;
|
||
}
|
||
}
|