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

📄 customeraction.java

📁 基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰富
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.yuanchung.sales.struts.customer.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.customer.Customer;
import com.yuanchung.sales.model.user.User;
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.struts.customer.form.CustomerForm;
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.right.WebRightsView;
import com.yuanchung.sales.vo.taskEvent.ActivityTaskVo;
import com.yuanchung.sales.vo.taskEvent.CorrelationVo;
import com.yuanchung.sales.vo.taskEvent.EventVo;
import com.yuanchung.sales.vo.user.UserVo;

public class CustomerAction extends DispatchAction {
	private static Logger logger = Logger.getLogger(CustomerAction.class);
	private CustomerMgr customerMgr;
	private AuthorizationMgr authorizationMgr;

	public void setAuthorizationMgr(AuthorizationMgr authorizationMgr) {
		this.authorizationMgr = authorizationMgr;
	}

	public void setCustomerMgr(CustomerMgr customerMgr) {
		this.customerMgr = customerMgr;
	}

	private RelationManage relationManage;

	public RelationManage getRelationManage() {
		return relationManage;
	}

	public void setRelationManage(RelationManage relationManage) {
		this.relationManage = relationManage;
	}

	/**
	 * 快速添加客户;
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward addCustomer(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		PrintWriter out = null;
		try {
			out = response.getWriter();// 设置out输出流;
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		User user = SessionMgr.getCustSession(request);// 当前正在操作的用户;
		CustomerForm customerForm = (CustomerForm) form;
		Customer customer = new Customer();
		// 拷贝值;
		customer.setCustomerName(customerForm.getCustomerName());
		customer.setEmail(customerForm.getEmail());
		customer.setFax(customerForm.getFax());
		customer.setPhone(customerForm.getPhone());
		customer.setCommunAddr(customerForm.getCommunAddr());
		customer.setUser(user);

		customer.setModifyManId(user.getId());
		// 插入记录的时间
		customer.setInDate(DateTimeTool.dateToStrFormat("yyyy-MM-dd HH:mm:ss",
				new Date()));
		// 上次修改的时间
		customer.setModifyManId(user.getId());

		customer.setLastModifyTime(DateTimeTool.dateToStrFormat(
				"yyyy-MM-dd HH:mm:ss", new Date()));
		customer.setFlag(Constants.ACTIVEFLAG);// 设置激活状态;

		try {
			// 保存客户
			customerMgr.addCustomer(customer);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Constants.UNABLESAVEUSER);
			request.setAttribute(Constants.ERRMSG, Constants.UNABLESAVEUSER);
			throw new PersistentObjException(Constants.PERSISTENT_OBJEXCEPTION);
		}

		out
				.print("<script>window.opener.document.getElementById('recordId').value ='"
						+ customer.getId()
						+ "';window.opener.document.getElementById('recordName').value ='"
						+ customer.getCustomerName()
						+ "';window.close();</script>");// 关闭被打开的页面;

		return null;
	}

	/**
	 * 新建客户
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward newCreate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		CustomerForm customerForm = (CustomerForm) form;
		Customer customer = new Customer();
		String id = customerForm.getId();
		if (StringTool.isNotBlank(id)) {// 修改客户资料
			customer = customerMgr.getCustomerById(Integer.parseInt(id));
		}
		customer.setCustomerName(customerForm.getCustomerName());// 客户名称
		customer.setCreateTime(customerForm.getCreateTime());// 客户公司成立时间
		customer.setLegalRepresent(customerForm.getLegalRepresent());// 法人代表
		customer.setBizType(customerForm.getBizType());// 企业类型

		String registerCapital = customerForm.getRegisterCapital();
		if (registerCapital != null) {// 判断注册的地方是否是为空;
			String[] registerCapitals = registerCapital.split(",");
			StringBuffer formatCapital = new StringBuffer();
			for (int i = 0; i < registerCapitals.length; i++) {
				formatCapital.append(registerCapitals[i]);
			}
			if (StringTool.isNotBlank(formatCapital.toString())) {
				customer.setRegisterCapital(Integer.parseInt(formatCapital
						.toString()));// 注册资金
			}
		}

		String industryType = customerForm.getIndustryType();
		String industryOf = customerForm.getIndustryOf();
		if (StringTool.isNotBlank(industryType)) {// 如果所属行业不为空
			customer.setIndustryOf(industryOf);// 所属行业
			customer.setIndustryType(industryType + "/" + industryOf);// 行业类别
		}

		logger.debug("行业类别:" + customerForm.getIndustryType());

		// 职员数
		String employeeNum = customerForm.getEmployeeNum();
		customer.setEmployeeNum(employeeNum);
		if (employeeNum != null && employeeNum.equals(Constants.MINEMPLOYEE)) {
			customer.setEmployeeMinNum(0);
			customer.setEmployeeMaxNum(8);
		} else if (employeeNum != null
				&& employeeNum.equals(Constants.MAXEMPLOYEE)) {
			customer.setEmployeeMinNum(2000);
			customer.setEmployeeMaxNum(Constants.MAXINT);
		} else if (employeeNum != null && !employeeNum.equals("")) {
			String[] nums = employeeNum.split("-");
			customer.setEmployeeMinNum(Integer.parseInt(nums[0]));
			customer.setEmployeeMaxNum(Integer.parseInt(nums[1]));
		}
		// 区域
		StringBuffer regionOf = new StringBuffer();
		String s1 = customerForm.getS1();
		String s2 = customerForm.getS2();
		String s3 = customerForm.getS3();
		if (s1 != null && !s1.equals(Constants.PROVINCE)) {
			regionOf.append(s1);
			customer.setProvince(s1);
		}
		if (s2 != null && !s2.equals(Constants.CITY)) {
			regionOf.append(s2);
			customer.setCity(s2);
		}
		if (s3 != null && !s3.equals(Constants.COUNTY)) {
			regionOf.append(s3);
			customer.setCounty(s3);
		}
		customer.setRegionOf(regionOf.toString());

		customer.setCommunAddr(customerForm.getCommunAddr());// 通信地址
		customer.setPhone(customerForm.getPhone());// 联系电话
		customer.setFax(customerForm.getFax());// 传真
		customer.setZipCode(customerForm.getZipCode());// 邮政编码
		customer.setWebSite(customerForm.getWebSite());// 网址
		customer.setEmail(customerForm.getEmail());// 电子邮件
		customer.setHonestGrade(customerForm.getHonestGrade());// 诚信等级
		customer.setManagerLevel(customerForm.getManagerLevel());// 管理水平
		customer.setBreedVisualize(customerForm.getBreedVisualize());// 品牌形象
		customer.setCustomerState(customerForm.getCustomerState());// 客户状态
		customer.setCustomerSource(customerForm.getCustomerSource());// 客户来源
		customer.setRemark(customerForm.getRemark());// 备注
		customer.setFlag(Constants.ACTIVEFLAG);// 默认为激活
		// 插入记录的时间
		customer.setInDate(DateTimeTool.dateToStrFormat("yyyy-MM-dd HH:mm:ss",
				new Date()));
		// 上次修改的时间
		customer.setLastModifyTime(DateTimeTool.dateToStrFormat(
				"yyyy-MM-dd HH:mm:ss", new Date()));
		User user = SessionMgr.getCustSession(request);// 会话用户默认为客户所属用户
		customer.setUser(user);// 所属用户
		customer.setModifyManId(user.getId());// 做修改的用户ID
		try {
			// 保存客户
			customerMgr.addCustomer(customer);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Constants.UNABLESAVEUSER);
			request.setAttribute(Constants.ERRMSG, Constants.UNABLESAVEUSER);
			throw new PersistentObjException("can not persistent obj!");
		}

		String forward = "customerCorrelation";
		String param = request.getParameter("param");
		if (param != null && param.equals("newAgain")) {// 若是保存并新建
			forward = "newCustomer";
		} else {
			try {
				CustomerVo customerVo = new CustomerVo();
				if (StringTool.isNotBlank(id)) {// 若客户ID不为空
					// 根据ID查找所要的客户

					// 跳转到客户相关action
					return new ActionForward("/customer.do?method=correlation");

				} else {
					// 查找最新保存的客户
					Customer customerLastest = customerMgr.getCustomerDao()
							.getCustomerLastest();
					BeanUtils.copyProperties(customerVo, customerLastest);
				}
				request.setAttribute("customerVo", customerVo);
			} catch (Exception e) {
				e.printStackTrace();
				request.setAttribute(Constants.ERRMSG, Constants.ERRORSYSTEM);
				throw new ApplicationException("no find data");
			}

		}
		return mapping.findForward(forward);
	}

	/**
	 * 根据用户取得所有的客户
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	@SuppressWarnings("unchecked")
	public ActionForward customerAll(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		User user = SessionMgr.getCustSession(request);
		// 2009-02-05 add 数据范围
		Rights rights = SessionMgr.getJspRightsControl(request).get("1")
				.getRightsMap().get("104");
		String style = rights.getStyle();
		String userIds = authorizationMgr.findUserDataRange(rights.getId(),
				user);
		// if(!"".equals(userIds)){
		// userIds = userIds + "," + user.getId();
		// }else{
		// userIds = user.getId().toString();
		// }
		logger.debug("userIds : " + userIds);
		// 删除(数据范围)
		Rights delRights = SessionMgr.getJspRightsControl(request).get("1")
				.getRightsMap().get("103");
		String delUserIds = authorizationMgr.findUserDataRange(delRights
				.getId(), user);
		logger.debug("delUserIds : " + delUserIds);
		// 修改(数据范围)
		Rights modifyRights = SessionMgr.getJspRightsControl(request).get("1")
				.getRightsMap().get("102");
		String modifyUserIds = authorizationMgr.findUserDataRange(modifyRights
				.getId(), user);

		// end
		List<UserDefined> options = new ArrayList<UserDefined>();
		if (Constants.STYLE_BLOCK.equals(style)) {// 2009-02-05 add 数据范围
			options = customerMgr.getOptionsByUserAndType(user,
					Constants.ALLCUSTOMER_INT);// 根据用户获取所有用户自定义选项
		}
		request.setAttribute("options", options);
		String forward = "customerList";
		List<Customer> customers = null;
		if (user != null) {
			// 根据用户搜索所属客户
			// 2009-02-06 modify
			// customers = customerMgr.getCustomerByUser(user,
			// Constants.ACTIVEFLAG);
			customers = customerMgr.getCustomerByUser(userIds,
					Constants.ACTIVEFLAG);
			for (int i = 0; i < customers.size(); i++) {
				if (authorizationMgr.isRights(customers.get(i).getUser()
						.getId(), delUserIds)) {
					customers.get(i).setDelRights("y");
				}
				if (authorizationMgr.isRights(customers.get(i).getUser()
						.getId(), modifyUserIds)) {
					customers.get(i).setModifyRights("y");
				}
			}
			// end modify
			String currentPage = request.getParameter("currentPage");
			XPage xpage = new XPage(request.getContextPath()
					+ "/customer.do?method=customerAll", customers.size(), 1,
					10, customers);
			if (currentPage != null && !currentPage.equals("")) {
				xpage.setCurrentItems(Integer.parseInt(currentPage));
			} else {
				xpage.setCurrentItems(1);
			}
			xpage.setPageBar();
			request.setAttribute("xpage", xpage);

		} else {
			request.setAttribute("loginerror", Constants.MESSAGE);
			forward = "userLogin";
		}
		return mapping.findForward(forward);
	}

	/**
	 * 创建一个新选项
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return

⌨️ 快捷键说明

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