📄 senduservoiceaction.java
字号:
package com.gctech.sms.voice.web;
import java.util.*;
import java.io.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import com.gctech.sms.voice.*;
import com.gctech.sms.voice.dao.*;
import com.gctech.sms.voice.common.*;
import com.gctech.sms.voice.api.*;
import org.apache.struts.upload.FormFile;
public class SendUserVoiceAction extends Action
{
VoiceFacade f = new VoiceFacade();
APIFacade api = new APIFacade();
static Logger logger = Logger.getLogger(SendUserVoiceAction.class);
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
{
/**@todo: complete the business logic here, this is just a skeleton.*/
UserVoiceActionForm form = (UserVoiceActionForm)actionForm;
try
{
HttpSession session = httpServletRequest.getSession();
VoiceUserValueObject user = (VoiceUserValueObject)session.getAttribute("User") ;
if(user==null) throw new VoiceException("用户还没有登录");
Date sendDate = getSendDate(httpServletRequest);
//保存文件到116平台
FormFile uploadFile = form.getVoiceFile();
FileOutputStream fileOut = new FileOutputStream(Consts.VOX_USER_PATH_ROOT +
java.io.File.separator + uploadFile.getFileName());
byte str[] = new byte[uploadFile.getFileSize()];
uploadFile.getInputStream().read(str);
fileOut.write(str);
fileOut.flush();
fileOut.close();
UpdateFlow.run();
VoiceValueObject voice = new VoiceValueObject();
voice.setUserId(user.getId());
voice.setName(Consts.VOX_116_USER_ROOT+"\\"+uploadFile.getFileName());
voice.setPrice(new Integer(100));
voice.setCatalogId(new Integer(0));
voice.setCreateDate(new Date());
voice.setCount(new Integer(0));
voice.setDescription(httpServletRequest.getParameter("content"));
voice.setId(f.addUserVoiceById(voice));
voice.setUserName(user.getName());
logger.debug("save success");
//发送该语音文件
String[] dests = new String[]{form.getPhone1(),form.getPhone2(),form.getPhone3(),form.getPhone4()};
SMSRequest smsReq = null;
VoiceRequest voiceReq = null;
for(int i=0;i<dests.length;i++)
{
if(dests[i]!=null&&dests[i].length()!=0)
{
smsReq = SMSRequest.createFeeRequest(user.getName(),Util.getServiceId(voice.getPrice().intValue()),"您已经为"+dests[i]+"点播了一条语音短信,收费"+voice.getPrice()+"分");
voiceReq = new VoiceRequest(voice.getId(),user.getName(),dests[i],sendDate,user.getId());
api.addVoiceRequest(voiceReq,smsReq);
}
}
httpServletRequest.setAttribute("successMessage","发送成功 ");
return actionMapping.findForward("success");
}
catch(Exception ex)
{
logger.debug(ex.getMessage());
httpServletRequest.setAttribute("errorMessage","系统发送失败 "+ex.getMessage());
return actionMapping.findForward("error");
}
}
private Date getSendDate(HttpServletRequest request)
{
String strMonth = request.getParameter("strMonth");
String strDay = request.getParameter("strDay");
String strHour = request.getParameter("strHour");
String strMin = request.getParameter("strMin");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH,Integer.parseInt(strMonth)-1);
cal.set(Calendar.DAY_OF_MONTH,Integer.parseInt(strDay));
cal.set(Calendar.HOUR_OF_DAY,Integer.parseInt(strHour));
cal.set(Calendar.MINUTE,Integer.parseInt(strMin));
if((cal.getTime().getTime()-new Date().getTime())<Consts.SIX_HOUR)
{
throw new IllegalArgumentException("输入的时间应该至少在六小时候以后");
}
return cal.getTime();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -