📄 voicemain.java
字号:
package com.gctech.sms.voice.api;
import java.util.*;
import java.text.*;
import java.sql.*;
import org.apache.log4j.Logger;
import com.gctech.sms.voice.*;
import com.gctech.sms.voice.dao.*;
import com.gctech.sms.voice.common.*;
/**
* 与116平台交互的接口
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author lijz@gctech.com.cn
* @version 1.0
*/
public class VoiceMain
{
private static VoiceMain api = new VoiceMain();
Map reqMap = new LRUHashMap();
static Logger logger = Logger.getLogger(VoiceMain.class);
SimpleDateFormat df = new SimpleDateFormat("MMddHHmm");
SimpleDateFormat adf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final String caller = Config.instance().getCaller();
public VoiceMain()
{
}
public static VoiceMain instance()
{
return api;
}
public static void init() throws Voice116Exception
{
}
public void add(VoiceRequest request,Integer smsSeqId)
{
synchronized(APIFacade.SMSLock)
{
this.reqMap.put(smsSeqId,request);
}
// System.out.println("reqMap size "+reqMap.size());
//现在计费还是不支持,所以直接发送
// try
// {
// send(smsSeqId);
// }
// catch(VoiceException ve)
// {
// logger.info("写预拨号表失败",ve);
// }
}
public void send(Integer seqId) throws VoiceException
{
try
{
VoiceRequest req = (VoiceRequest)reqMap.get(seqId);
if(req == null)
{
//不过能发生
}
else
{
send(req);
}
}
catch(VoiceException ex)
{
logger.debug("发送声迅请求失败",ex);
throw ex;
}
}
/**
* 将语音发送请求写到预拨号表
* @param req
* @throws Voice116Exception
*/
protected void send(VoiceRequest req) throws VoiceException
{
Integer id = req.getId();
VoiceFacade vf = new VoiceFacade();
try
{
logger.info("send voice to db");
//写历史记录,增加用户点击数,不考虑事务
UserHistoryDAO hdao = new UserHistoryDAO();
UserHistoryValueObject uvo = new UserHistoryValueObject();
VoiceValueObject vo = null;
Connection conn = null;
try
{
conn = DBHelper.getConn();
//增加用户点击数
VoiceDAO vdao = new VoiceDAO();
vo = vdao.getByPrimaryKey(conn,id);
VoiceValueObject vvo = new VoiceValueObject();
vvo.setCount(new Integer(vo.getCount().intValue()+1));
vvo.setId(vo.getId());
vdao.update(conn,vvo);
//插入历史记录
Integer hid = new Integer(DBHelper.nextHistorySeqId(conn));
uvo.setId(hid);
uvo.setPrice(vo.getPrice());
uvo.setType(vo.getType());
uvo.setConsumeDate(new java.util.Date());
uvo.setUserId(req.getUserId());
uvo.setVoiceId(req.getId());
hdao.insert(conn,uvo);
}
catch(SQLException ex)
{
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
PredialtaskDAO pdao = new PredialtaskDAO();
//预备插入第一条内容
PredialtaskValueObject pvo = new PredialtaskValueObject();
Calendar cal = Calendar.getInstance();
String serviceBegDate = null;
if(req.getSendDate()==null)
{
//web服务器与预拨号表存在时间差
cal.add(Calendar.MINUTE,-20);
req.setSendDate(cal.getTime());
}
else
{
//客户指定时间
cal.setTime(req.getSendDate());
}
serviceBegDate = adf.format(req.getSendDate());
cal.add(Calendar.HOUR_OF_DAY ,1);
String serviceStopDate = adf.format(cal.getTime());
String strType = Cache.instance().getBigCatalog(vo.getCatalogId())!=Consts.VOICE_CATALOG_ZG?"1":"2";
String privateDate = strType+"^"+vo.getName()+"^"+req.getCaller()+"^"+req.getCalled();
//设置主建
pvo.setSerialnum(this.getSerialNum(req.getCaller(),req.getSendDate()));
pvo.setCallorder(new Integer(this.getCallOrder()));
//设置拨号时间
pvo.setServicebegintime(serviceBegDate);
pvo.setServicestoptime(serviceStopDate);
pvo.setDialbegintime(serviceBegDate);
pvo.setDialendtime(serviceStopDate);
//设置号码
pvo.setCalled(req.getCalled());
pvo.setOrigcalled(req.getCaller());
pvo.setOrigcaller(req.getCaller());
//设置prviate date
pvo.setPrivatedata(privateDate);
/*
//第二条数据
cal = Calendar.getInstance();
cal.setTime(req.getSendDate());
cal.add(Calendar.MINUTE,4);
serviceBegDate = adf.format(cal.getTime());
cal.add(Calendar.HOUR_OF_DAY,1);
serviceStopDate = adf.format(cal.getTime());
PredialtaskValueObject pvo1 = new PredialtaskValueObject();
privateDate = "2^"+vo.getName()+"^"+req.getCaller()+"^"+req.getCalled();
//设置主建
pvo1.setSerialnum(this.getSerialNum(req.getCaller(),req.getSendDate()));
pvo1.setCallorder(new Integer(this.getCallOrder()));
//设置拨号时间
pvo1.setServicebegintime(serviceBegDate);
pvo1.setServicestoptime(serviceStopDate);
pvo1.setDialbegintime(serviceBegDate);
pvo1.setDialendtime(serviceStopDate);
//设置号码
pvo1.setCalled(req.getCalled());
pvo1.setOrigcalled(req.getCaller());
pvo1.setOrigcaller(req.getCaller());
//设置prviate date
pvo1.setPrivatedata(privateDate);
*/
//保存到数据库里
try
{
conn = DBHelper.get116Conn();
pdao.insert(conn,pvo);
// pdao.insert(conn,pvo1);
}
catch(SQLException sqle)
{
throw new VoiceException("数据库错误"+sqle.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
catch(VoiceException ve)
{
throw ve;
}
}
private String getSerialNum(String caller,java.util.Date d)
{
return caller+df.format(d);
}
private int getCallOrder()
{
return (int)(Math.random()*10000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -