📄 customeraction.java
字号:
package com.iplan.portal.order.action;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import com.iplan.portal.admin.pojo.Area;
import com.iplan.portal.admin.service.IAreaService;
import com.iplan.portal.framework.Constants;
import com.iplan.portal.framework.base.struts.BaseAction;
import com.iplan.portal.order.pojo.Customer;
import com.iplan.portal.order.service.ICustomerService;
/**
* http://www.5ai7.net
*
* @author ws
*/
public class CustomerAction extends BaseAction {
ICustomerService customerService;
IAreaService areaService;
public ICustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(ICustomerService customerService) {
this.customerService = customerService;
}
public IAreaService getAreaService() {
return areaService;
}
public void setAreaService(IAreaService areaService) {
this.areaService = areaService;
}
public ActionForward select(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
List list = this.getAreaService().getUsedAreaListByUserId(
(httpServletRequest.getSession()
.getAttribute(Constants.CURRENT_USER_GUID)).toString());
httpServletRequest.setAttribute("items", list);
String sign = httpServletRequest.getParameter("sign");
httpServletRequest.setAttribute("sign", sign);
return actionMapping.findForward("AreaSelectList");
}
public ActionForward list(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
Customer customer = (Customer) daf.get("customer");
String areaId = customer.getAreaid();
if (areaId == null || "".equals(areaId)) {
areaId = (String) httpServletRequest.getSession().getAttribute(
"areaid");
} else {
httpServletRequest.getSession().setAttribute("areaid", areaId);
}
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
List list = this.getCustomerService().getCustomerList(areaId, userId);
httpServletRequest.setAttribute("items", list);
Area area = this.getAreaService().getAreaById(areaId);
httpServletRequest.setAttribute("areaName", area.getAreaName());
return actionMapping.findForward("CustomerList");
}
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("customer", this.getCustomerService().getCustomerById(id));
}
return actionMapping.findForward("CustomerEdit");
}
public ActionForward save(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
boolean flag = true;
DynaActionForm daf = (DynaActionForm) actionForm;
Customer customer = (Customer) daf.get("customer");
String areaId = (String) httpServletRequest.getSession().getAttribute(
"areaid");
String customerName = customer.getCustomerName().trim();
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
customer.setUserId(userId);
customer.setAreaid(areaId);
String id = customer.getGuid();
//保存时检查Customer
Customer checkCustomer = this.getCustomerService().getCustomerByName(areaId, userId,customerName);
ActionMessages messages = new ActionMessages();
if (id == null || "".equals(id)) {
if (checkCustomer == null) {
customer.setCreatetime(new Date());
customer.setUpdatetime(new Date());
this.getCustomerService().saveCustomer(customer);
} else {
flag = false;
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.addcustomer"));
saveMessages(httpServletRequest, messages);
}
} else {
Customer oldCustomer = this.getCustomerService().getCustomerById(id);
String oldCustomerName = oldCustomer.getCustomerName().trim();
//如果编辑过程中,客户名称被更改
if (!oldCustomerName.equals(customerName)) {
if (checkCustomer == null ){
customer.setUpdatetime(new Date());
this.getCustomerService().updateCustomer(customer);
} else {
flag = false;
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.editcustomer"));
saveMessages(httpServletRequest, messages);
}
} else {
customer.setUpdatetime(new Date());
this.getCustomerService().updateCustomer(customer);
}
}
if (flag) {
customer.setGuid(null);
customer.setCustomerName(null);
customer.setAddress(null);
daf.set("customer", customer);
}
return actionMapping.findForward("CustomerEdit");
}
public ActionForward delete(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
Customer customer = (Customer) daf.get("customer");
this.getCustomerService().deleteCustomer(customer);
return null;
}
public ActionForward search(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
Customer customer = (Customer) daf.get("customer");
String areaId = (String) httpServletRequest.getSession().getAttribute(
"areaid");
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
String customerName = customer.getCustomerName();
if (customerName == null) {
customerName = (String) httpServletRequest.getSession().getAttribute(Constants.Customer_CustomerName);
} else {
httpServletRequest.getSession().setAttribute(Constants.Customer_CustomerName, customerName.trim());
customerName = customerName.trim();
}
List list = this.getCustomerService().getCustomerListByCusName(areaId,
userId, customerName);
httpServletRequest.setAttribute("items", list);
Area area = this.getAreaService().getAreaById(areaId);
httpServletRequest.setAttribute("areaName", area.getAreaName());
customer.setCustomerName(customerName);
daf.set("customer", customer);
return actionMapping.findForward("CustomerList");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -