📄 paymentaction.java
字号:
package com.iplan.portal.order.action;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BasicDynaBean;
import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import com.iplan.portal.framework.Constants;
import com.iplan.portal.framework.base.struts.BaseAction;
import com.iplan.portal.framework.utils.PortalUtil;
import com.iplan.portal.order.pojo.Payment;
import com.iplan.portal.order.service.ICustomerService;
import com.iplan.portal.order.service.IPaymentService;
/**
* http://www.hao-se.cn
*
* @author ws
*/
public class PaymentAction extends BaseAction {
IPaymentService paymentService;
ICustomerService customerService;
public IPaymentService getPaymentService() {
return paymentService;
}
public void setPaymentService(IPaymentService paymentService) {
this.paymentService = paymentService;
}
public ICustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(ICustomerService customerService) {
this.customerService = customerService;
}
public ActionForward list(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
httpServletRequest.getSession().removeAttribute("areaid");
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
List list = this.getPaymentService().getPaymentList(userId);
setPaymentInfo(list, httpServletRequest);
return actionMapping.findForward("PaymentList");
}
public ActionForward edit(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
String update = (String) httpServletRequest.getParameter("update");
if (update != null && !"".equals(update)) {
httpServletRequest.setAttribute("update", update);
String id = (String) httpServletRequest.getParameter("editnumber");
daf.set("payment", this.getPaymentService().getPaymentById(id));
}
setCustomerInfo(httpServletRequest);
return actionMapping.findForward("PaymentEdit");
}
public ActionForward save(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
Payment payment = (Payment) daf.get("payment");
payment.setUserId((httpServletRequest.getSession()
.getAttribute(Constants.CURRENT_USER_GUID)).toString());
String id = payment.getGuid();
if (id == null || "".equals(id)) {
payment.setCreatetime(new Date());
payment.setUpdatetime(new Date());
this.getPaymentService().savePayment(payment);
} else {
payment.setUpdatetime(new Date());
this.getPaymentService().updatePayment(payment);
}
setCustomerInfo(httpServletRequest);
payment.setGuid(null);
payment.setCustomerName(null);
payment.setCash(null);
payment.setPayDate(null);
payment.setRemark(null);
daf.set("payment", payment);
return actionMapping.findForward("PaymentEdit");
}
public ActionForward delete(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
Payment payment = (Payment) daf.get("payment");
this.getPaymentService().deletePayment(payment);
return null;
}
public ActionForward search(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
Payment payment = (Payment) daf.get("payment");
String payDateStr1 = payment.getPayDateStr1();
if (payDateStr1 == null) {
payDateStr1 = (String) httpServletRequest.getSession().getAttribute(Constants.Payment_PayDateStr1);
} else {
httpServletRequest.getSession().setAttribute(Constants.Payment_PayDateStr1, payDateStr1);
}
String payDateStr2 = payment.getPayDateStr2();
if (payDateStr2 == null) {
payDateStr2 = (String) httpServletRequest.getSession().getAttribute(Constants.Payment_PayDateStr2);
} else {
httpServletRequest.getSession().setAttribute(Constants.Payment_PayDateStr2, payDateStr2);
}
String customerName = payment.getCustomerName();
if (customerName == null) {
customerName = (String) httpServletRequest.getSession().getAttribute(Constants.Payment_CustomerName);
} else {
httpServletRequest.getSession().setAttribute(Constants.Payment_CustomerName, customerName.trim());
customerName = customerName.trim();
}
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
List list = this.getPaymentService().getCustomerListByCusName(userId,
payDateStr1,payDateStr2, customerName);
setPaymentInfo(list, httpServletRequest);
payment.setCustomerName(customerName);
payment.setPayDateStr1(payDateStr1);
payment.setPayDateStr2(payDateStr2);
daf.set("payment", payment);
return actionMapping.findForward("PaymentList");
}
private void setCustomerInfo(HttpServletRequest httpServletRequest) {
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
// 客户信息列表
List customerList = this.getCustomerService().getCustomerListByUser(
userId, null);
List customerNameList = new ArrayList();
customerNameList.add("");
for (int i = 0; i < customerList.size(); i++) {
BasicDynaBean bean = (BasicDynaBean) customerList.get(i);
customerNameList.add(bean.get("customername"));
}
httpServletRequest.setAttribute("customerNameList", customerNameList);
}
private void setPaymentInfo(List list, HttpServletRequest httpServletRequest) {
try {
List viewList = new ArrayList();
DynaProperty[] property = {
new DynaProperty("guid", Class.forName("java.lang.String")),
new DynaProperty("paydate", Class.forName("java.lang.String")),
new DynaProperty("customername", Class.forName("java.lang.String")),
new DynaProperty("cash", Class.forName("java.lang.String"))};
DynaClass dynaClass = new BasicDynaClass("bean", null, property);
DynaBean bean;
BasicDynaBean beanTemp;
for (int i = 0; i < list.size(); i++) {
beanTemp = (BasicDynaBean) list.get(i);
bean = dynaClass.newInstance();
bean.set("guid", beanTemp.get("guid"));
bean.set("paydate", convertDateToString(beanTemp.get("paydate")));
bean.set("customername", beanTemp.get("customername"));
bean.set("cash", PortalUtil.getFormatNumber(beanTemp.get("cash")));
viewList.add(bean);
}
httpServletRequest.setAttribute("items", viewList);
} catch (Exception e) {
e.printStackTrace();
}
}
private String convertDateToString(Object object) {
String time = "";
if (object != null && !"".equals(object)) {
time = object.toString().substring(0, 16);
}
return time;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -