⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderaction.java

📁 基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰富
💻 JAVA
字号:
package com.yuanchung.sales.struts.order.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.yuanchung.sales.config.ClassCodeMgr;
import com.yuanchung.sales.config.ConfigMgr;
import com.yuanchung.sales.constants.CorrelationConstant;
import com.yuanchung.sales.constants.SystemConstant;
import com.yuanchung.sales.exception.ApplicationException;
import com.yuanchung.sales.exception.IllegalParameterException;
import com.yuanchung.sales.exception.PersistentObjException;
import com.yuanchung.sales.model.admin.Rights;
import com.yuanchung.sales.model.businessOpportunity.BusinessOpportunity;
import com.yuanchung.sales.model.customer.Customer;
import com.yuanchung.sales.model.customer.CustomerContact;
import com.yuanchung.sales.model.user.User;
import com.yuanchung.sales.model.userDefined.UserDefined;
import com.yuanchung.sales.model.order.Order; //import com.yuanchung.sales.model.userDefined.UserDefined;
//import com.yuanchung.sales.model.userDefined.UserField;
//import com.yuanchung.sales.model.userDefined.UserFilter;
import com.yuanchung.sales.service.RelationManage;
import com.yuanchung.sales.service.admin.authorization.AuthorizationMgr;
import com.yuanchung.sales.service.customer.CustomerMgr;
import com.yuanchung.sales.service.order.OrderMgr;
import com.yuanchung.sales.service.order.impl.OrderMgrImpl;
import com.yuanchung.sales.struts.busiOpport.form.BusiOpportForm;
import com.yuanchung.sales.struts.customer.form.CustomerForm;
import com.yuanchung.sales.struts.order.form.OrderForm;
import com.yuanchung.sales.util.Constants;
import com.yuanchung.sales.util.DateTimeTool;
import com.yuanchung.sales.util.SessionMgr;
import com.yuanchung.sales.util.StringTool;
import com.yuanchung.sales.util.XPage;
import com.yuanchung.sales.vo.CustomerDefinedVo;
import com.yuanchung.sales.vo.CustomerVo;
import com.yuanchung.sales.vo.busiOpport.BusinessOpportunityVo;
import com.yuanchung.sales.vo.contact.ContactVo;
import com.yuanchung.sales.vo.order.*;

public class OrderAction extends DispatchAction {
	private static Logger logger = Logger.getLogger(OrderAction.class);
	private OrderMgr orderMgr;

	public OrderMgr getOrderMgr() {
		return orderMgr;
	}

	public void setOrderMgr(OrderMgr orderMgr) {
		this.orderMgr = orderMgr;
	}

	// 新增订单并保存
	public ActionForward newCreateOrder(ActionMapping mappig, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		OrderForm orderForm = (OrderForm) form;
		Order order = new Order();
		User user = SessionMgr.getCustSession(request);
		order.setUser(user);
		
		// 根据客户ID查找客户
		int customerId = orderForm.getCustomerId();
		//根据ID查找联系人
		int customercontactId = orderForm.getCustomercontactId();
		
		Date deliveryDate=orderForm.getDeliveryDate();
		String productName=orderForm.getProductName();
		Integer productId=orderForm.getProductId();
		String productUnit=orderForm.getProductUnit();
		Integer productAmount=orderForm.getProductAmount();
		Double productPrice=orderForm.getProductPrice();
		Double productDiscountRate=orderForm.getProductDiscountRate();
		Double productTaxRate=orderForm.getProductTaxRate();
		Double productTaxAmount=orderForm.getProductTaxAmount();
		Double productTotalAmount=orderForm.getProductTotalAmount();
		
		//跳转到订单详细信息页面
		String forward = "orderDetail";
		// return mappig.findForward(forward);

		try {
			Customer customer = orderMgr.getCustomerById(customerId);
			CustomerContact customercontact=orderMgr.getCustomerContactById(customercontactId);
			order.setCustomer(customer);
			int orderId = StringTool.createID();
			order.setOrderId(orderId);
			order.setOrderDate(DateTimeTool.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
			order.setCustomer(customer);
			order.setCustomercontact(customercontact);
			order.setDeliveryDate(deliveryDate);
			order.setDeliveryAddress(orderForm.getDeliveryAddress());
			order.setOrderDiscount(orderForm.getOrderDiscount());
			order.setTotalAmount(orderForm.getTotalAmount());
			order.setProductName(productName);
			order.setProductId(productId);
			order.setProductUnit(productUnit);
			order.setProductAmount(productAmount);
			order.setProductPrice(productPrice);
			order.setProductDiscountRate(productDiscountRate);
			order.setProductTaxRate(productTaxRate);
			order.setProductTaxAmount(productTaxAmount);
			order.setProductTotalAmount(productTotalAmount);

			// 保存
			orderMgr.addOrder(order);

			// 查询最近的订单
			Order orderLast = orderMgr.getOrderDao().getLastestOrder();
			logger.debug("联系人ID:" + customercontactId);
			if (customercontactId > 0) {
				// 根据联系人ID查找联系人
				CustomerContact contact = orderMgr.getOrderDao()
						.getCustomerContactById(customercontactId);
				List<ContactVo> contacts = new ArrayList<ContactVo>();
				ContactVo contactVo = new ContactVo(contact.getId(), contact
						.getName(), contact.getCustomer().getId(), contact
						.getCustomer().getCustomerName(),
						contact.getComPhone(), contact.getEmail(), null, null);
				contacts.add(contactVo);
				request.setAttribute("contacts", contactVo);
			}

			String param = request.getParameter("param");
			if (param != null && param.equals("newAgain")) { // 保存并新建订单
				forward = "newOrder";
			} else {
				try {
					OrderVo orderVo = new OrderVo();
					BeanUtils.copyProperties(orderVo, orderLast);
					request.setAttribute("orderVo", orderVo);
				} catch (Exception e) {
					e.printStackTrace();
					request.setAttribute(Constants.ERRMSG,
							Constants.ERRORSYSTEM);
					throw new ApplicationException("Copy Exception!");
				}
			}

		} catch (Exception e) {
			request.setAttribute(Constants.ERRMSG, Constants.UNABLESAVEUSER);
		}

		return mappig.findForward(forward);
	}

	/**
	 * 查找所有的客户
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward allCustomer(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		User user = SessionMgr.getCustSession(request);
		String forward = "customerList";
		if (user != null) {
			// 查找所有的客户
			List<CustomerVo> customers = orderMgr.getCustomerByUser(user,
					Constants.ACTIVEFLAG);
			String currentPage = request.getParameter("currentPage");
			// 封装客户到XPage
			XPage xpage = new XPage(request.getContextPath()
					+ "/order.do?method=allCustomer", customers.size(), 1,
					8, customers);
			if (currentPage != null && !currentPage.equals("")) {
				xpage.setCurrentItems(Integer.parseInt(currentPage));
			} else {
				xpage.setCurrentItems(1);
			}
			xpage.setPageBar();
			request.setAttribute("xpage", xpage);
		} else {
			request.setAttribute("Login Error", Constants.MESSAGE);
			forward = "userLogin";
		}
		return mapping.findForward(forward);
	}

	/**
	 * 所有订单
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward allOrder(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		
        //System.out.println("有没有到这里???");
		User user = SessionMgr.getCustSession(request);
       // logger.debug("跳得下去吗???");
		// 获取所有订单
		List<OrderVo> orders = orderMgr.getAllOrder(user);
		//System.out.println("看看这里!!!"+orders.size());
		String currentPage = request.getParameter("currentPage");
		XPage xpage = new XPage(request.getContextPath()+ "/order.do?method=allOrder", orders.size(), 1, 10, orders);
		if (currentPage != null && !currentPage.equals("")) {
			xpage.setCurrentItems(Integer.parseInt(currentPage));
		} else {
			xpage.setCurrentItems(1);
		}
		xpage.setPageBar();
		request.setAttribute("xpage", xpage);
		return mapping.findForward("orderList");
	}

	// 根据客户名称查找订单
	public ActionForward getOrderByCustomerName(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {

		User user = SessionMgr.getCustSession(request);
		//OrderForm orderForm = (OrderForm) form;
		String customerName=request.getParameter("customerName");
		List<CustomerOrderVo> orders=orderMgr.getOrderByCustomerName(customerName);
		String currentPage = request.getParameter("currentPage");
		XPage xpage = new XPage(request.getContextPath()
				+ "/order.do?method=getOrderByCustomerName", orders.size(), 1, 8, orders);
		if (currentPage != null && !currentPage.equals("")) {
			xpage.setCurrentItems(Integer.parseInt(currentPage));
		} else {
			xpage.setCurrentItems(1);
		}
		xpage.setPageBar(); 
		return mapping.findForward("orderList");
	}

	/**
	 * 编辑订单
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward editOrder(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		//获取订单号
		OrderForm orderForm=new OrderForm();
		Integer orderId = orderForm.getOrderId();
		Order order = null;
		if (orderId!=null) {// 根据订单号查找
			order = orderMgr.getOrderById(orderId);
		}
		if (order != null) {
			OrderVo orderVo = new OrderVo();
			try {
				BeanUtils.copyProperties(orderVo, order);
			} catch (Exception e) {

			}
			//orderMgr.updateOrder(order);
			request.setAttribute("orderVo", orderVo);
		}
		return mapping.findForward("editOrder");
	}
	
	/**
	 * 删除订单
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward deleteOrder(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws ApplicationException {
		//OrderForm orderForm=new OrderForm();
        try
        {
        	String orderId=request.getParameter("orderId");
    		int order_Id = Integer.parseInt(orderId);
            Order order = orderMgr.getOrderById(order_Id);
            request.setAttribute("order", order);
        	orderMgr.deletOrder(order);
        }
        catch(Exception e)
        {
        	e.printStackTrace();
        	logger.debug(Constants.DELETEORDEREXCEPTION);
        }
		
		return mapping.findForward("orderList");
	}
	
	/**
	 * 订单详细信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward showDetail(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		//System.out.println("能不能到这里呢???");
	    //OrderForm orderForm=new OrderForm();
		try
		{
			String orderId = request.getParameter("orderId");
			  //System.out.println("有没有值??"+orderId);
		    int order_Id = Integer.parseInt(orderId);
	        Order order = orderMgr.getOrderById(order_Id);
	        request.setAttribute("order",order);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		//Integer orderId = request.getParameter("orderId");
		
		return mapping.findForward("orderDetail");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -