?? informationdetailaction.java
字號:
package com.longtime.wap.module.front.web.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.GenericValidator;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.longtime.wap.common.WapConstant;
import com.longtime.wap.common.enums.CategoryEnum;
import com.longtime.wap.frame.common.UserSessionVO;
import com.longtime.wap.model.Information;
import com.longtime.wap.model.Payment;
import com.longtime.wap.model.UserInfo;
import com.longtime.wap.module.front.common.FrontConstant;
import com.longtime.wap.module.front.service.FrontService;
import com.longtime.wap.module.front.web.form.InformationDetailForm;
/**
* 處理詳細信息請求
*
* @author bulc
* @date Nov 19, 2007
*/
public class InformationDetailAction extends FrontBaseAction {
private static final Log LOGGER = LogFactory
.getLog(InformationDetailAction.class);
private FrontService frontService;
/**
* 注入服務對象
*
* @param frontService
* 服務對象
*/
public void setFrontService(FrontService frontService) {
this.frontService = frontService;
}
/**
* 獲取信息請求處理
*
* @param mapping
* ActionMapping對象
* @param form
* ActionForm對象
* @param request
* HttpServletRequest對象
* @param response
* HttpServletResponse對象
* @return ActionForward對象
* @throws Exception
* 異常對象
*/
public ActionForward getInformation(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (!this.isUser(request)) {
// 禁止訪問頁面信息
return mapping.findForward("error");
} else {
// 正常訪問
try {
UserSessionVO usVo = (UserSessionVO) request.getSession()
.getAttribute(WapConstant.USER_SESSION);
long userId = usVo.getUserId();
long infoId = Long.parseLong(request.getParameter("id"));
Information info = super.filtInformationContent(frontService
.getInfoById(infoId), frontService);
if (null == info) {
throw new RuntimeException("您所查看的信息不存在");
}
InformationDetailForm idForm = new InformationDetailForm();
idForm
.setInformationId(String.valueOf(info
.getInformationId()));
idForm.setTitle(info.getTitle());
idForm.setCpName(info.getBusiness().getCp().getCompanyName());
idForm.setCategory(String.valueOf(info.getBusiness()
.getCategory()));
idForm.setCategoryName(CategoryEnum.getValue(
info.getBusiness().getCategory()).toChinese());
Payment payment = frontService.getPaymentByUserIdAndInfoId(
userId, infoId);
if (null != payment) {
// 買過
idForm.setContent(info.getContent());
if (!GenericValidator.isBlankOrNull(info.getFilePath())) {
idForm.setFilePath(info.getFilePath());
}
idForm.setDetailFlug("detail");
} else {
// 沒買過
idForm
.setBusinessName(info.getBusiness()
.getBusinessName());
idForm.setPrice(String.valueOf(info.getPrice()));
idForm.setDetailFlug("temp");
}
request.setAttribute(FrontConstant.INFORMATION_DETAIL_FORM,
idForm);
} catch (Exception ex) {
LOGGER.error(ex);
ex.printStackTrace();
}
super.setHeader(request, frontService);
super.setLeft(request, frontService);
return mapping.findForward("infoDetail");
}
}
/**
* 購買信息請求處理
*
* @param mapping
* ActionMapping對象
* @param form
* ActionForm對象
* @param request
* HttpServletRequest對象
* @param response
* HttpServletResponse對象
* @return ActionForward對象
* @throws Exception
* 異常對象
*/
public ActionForward buyInformation(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
try {
InformationDetailForm idForm = (InformationDetailForm) form;
UserSessionVO usVo = (UserSessionVO) request.getSession()
.getAttribute(WapConstant.USER_SESSION);
long userId = usVo.getUserId();
long infoId = Long.parseLong(request.getParameter("id"));
frontService.savePurchaseInfo(userId, infoId);
// 更新顯示用戶的余額
UserInfo user = frontService.getUserById(userId);
usVo.setMoney(String.valueOf(user.getMoney()));
Information info = this.filtInformationContent(frontService
.getInfoById(infoId), frontService);
idForm.setContent(info.getContent());
if (!GenericValidator.isBlankOrNull(info.getFilePath())) {
idForm.setFilePath(info.getFilePath());
}
idForm.setDetailFlug("detail");
} catch (RuntimeException ex) {
request.setAttribute(FrontConstant.BUY_INFO_ERROR, ex.getMessage());
} catch (Exception ex) {
LOGGER.error(ex);
ex.printStackTrace();
}
super.setHeader(request, frontService);
super.setLeft(request, frontService);
return mapping.findForward("infoDetail");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -