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

📄 customeraction.java

📁 基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰富
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * @throws ApplicationException
	 */
	public ActionForward newOption(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		// 可用选项
		List<String> enableOptions = new ArrayList<String>();
		enableOptions.add(Constants.CREATETIME);
		enableOptions.add(Constants.REPRESENT);
		enableOptions.add(Constants.BIZTYPE);
		enableOptions.add(Constants.REGISTERCAPITAL);
		enableOptions.add(Constants.EMPLOYEENUM);
		enableOptions.add(Constants.REGIONOF);
		enableOptions.add(Constants.FAX);
		enableOptions.add(Constants.ZIPCODE);
		enableOptions.add(Constants.WEBSITE);
		enableOptions.add(Constants.EMAIL);
		enableOptions.add(Constants.HONESTGRADE);
		enableOptions.add(Constants.MANAGERLEVEL);
		enableOptions.add(Constants.BREEDVISUALIZE);
		enableOptions.add(Constants.CUSTOMERSTATE);
		enableOptions.add(Constants.CUSTOMERSOURCE);
		enableOptions.add(Constants.REMARK);
		// 预选选项
		List<String> preOptions = new ArrayList<String>();
		preOptions.add(Constants.CUSTOMER_NAME);
		preOptions.add(Constants.INDUSTRYOf);
		preOptions.add(Constants.COMMUNADDR);
		preOptions.add(Constants.PHONE);

		request.setAttribute("enableOptions", enableOptions);
		request.setAttribute("preOptions", preOptions);
		return mapping.findForward("newOption");
	}

	/**
	 * 创建客户新选项
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward newCreateOption(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws ApplicationException {
		String optionName = request.getParameter("optionName");
		User user = SessionMgr.getCustSession(request);
		UserDefined ud = null;
		UserFilter uf = null;
		if (user != null) {
			ud = new UserDefined();
			ud.setDefinedName(optionName);
			ud.setType(Constants.ALLCUSTOMER_INT);// 设置选项类型
			ud.setUser(user);
			customerMgr.addUserDefined(ud); // 保存用户选项
			for (int i = 1; i <= 20; i++) {
				uf = new UserFilter();
				String fieldId = request.getParameter("field" + i);// 字段
				String operatorPre = request.getParameter("operator" + i);// 预运算符
				String value = request.getParameter("value" + i);// 值
				uf.setOperatorName(operatorPre);// 保存操作名
				uf.setFilter(value);// 保存值
				if (!StringTool.isNotBlank(fieldId)
						|| !StringTool.isNotBlank(operatorPre)
						|| !StringTool.isNotBlank(value)) {// 若字段为空
					break;
				}
				String field = StringTool.getStringByField(fieldId);// 字段
				String operator = StringTool.transformStr(operatorPre);// 转换运算符
				if (operatorPre.equals(Constants.STARTCHAR)) {// 若运算符是起始字符
					value = "'" + value + "%'";
				} else if (operator.equals("like") || operator.equals("!like")) {// 若是模糊查询
					value = "'%" + value + "%'";
				} else {// 其余为数值或字符
					value = StringTool.transformString(fieldId, value);
				}
				uf.setFilterName(field);
				uf.setOperator(operator);
				uf.setFilterValue(value);
				uf.setUserDefined(ud);
				customerMgr.addUserFilter(uf);// 保存过滤条件
			}
			String optionFields = request.getParameter("preOptions"); // 分离预选项
			UserField userField = new UserField();
			;
			userField.setFieldName(optionFields);
			userField.setUserDefined(ud);
			customerMgr.addUserField(userField);// 保存显示字段
			System.out.println("显示字段" + userField.getFieldName());
			request.setAttribute("isSuccess", Constants.SAVESUCCESS);
		}
		return mapping.findForward("newOptionAgain");
	}

	/**
	 * 搜索所有的选项
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward searchOption(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		User user = SessionMgr.getCustSession(request);
		List<UserDefined> options = customerMgr.getOptionsByUserAndType(user,
				Constants.ALLCUSTOMER_INT);
		request.setAttribute("options", options);
		return mapping.findForward("customerList");
	}

	/**
	 * 修改客户信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward modifyCustomer(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		CustomerForm cForm = (CustomerForm)form;
//		String customerId = request.getParameter("id");
		String customerId = cForm.getId();
		String forward = "login";
		// 前置条件
		if (!StringTool.isNotBlank(customerId)) {
			request.setAttribute(Constants.ERRMSG, Constants.INPUTBANK);
			throw new ApplicationException("the param you input is illegal");
		}
		try {
			Customer customer = customerMgr.getCustomerDao().getById(
					Integer.parseInt(customerId));
			CustomerVo customerVo = new CustomerVo();
			// 将客户实体的属性复制给客户VO
			BeanUtils.copyProperties(customerVo, customer);
			//2009-02-25 add
			customerVo.setDelRights(cForm.getDelRights());
			customerVo.setModifyRights(cForm.getModifyRights());
			//end add
			request.setAttribute("customerVo", customerVo);
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute(Constants.ERRMSG, Constants.WITHOUTDATA);
			throw new ApplicationException("not find data!");
		}
		forward = "editCustomer";
		return mapping.findForward(forward);
	}

	/**
	 * 删除客户---只更改客户的状态
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward deleteCustomer(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		String customerId = request.getParameter("id");
		logger.debug("有到这里吗..." + customerId);
		if (!StringTool.isNotBlank(customerId)) {
			throw new ApplicationException("the param you input is illegal!!!");
		}
		User user = SessionMgr.getCustSession(request);
		// 删除客户
		relationManage.updateEntitysStates(user.getId(), DateTimeTool
				.getCurrentDate("yyyy-MM-dd HH:mm:ss"),
				ClassCodeMgr.CUSTOMERINT, Integer.parseInt(customerId),
				Constants.DELETESELF, Constants.PASSIVITY);
		logger.debug("有到这里吗...呵呵");
		return mapping.findForward("customerAll");
	}

	/**
	 * 编辑客户选项
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward editOption(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		String optionId = request.getParameter("optionId");
		UserDefined customerDefined = null;
		if (StringTool.isNotBlank(optionId)) {// 若选项id不空
			// 根据选项id搜索客户选项
			customerDefined = customerMgr.getUserDefinedById(Integer
					.parseInt(optionId));
		}
		// 将选项封装成vo
		CustomerDefinedVo customerDefinedVo = customerMgr
				.transaformCustomerDefinedPoToVo(customerDefined);
		System.out.println("可选字段" + customerDefinedVo.getNoUserFields());
		request.setAttribute("customerDefinedVo", customerDefinedVo);
		return mapping.findForward("editOption");
	}

	/**
	 * 修改客户选项
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward modifyOption(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		String optionId = request.getParameter("optionId");
		UserDefined ud = null;
		if (StringTool.isNotBlank(optionId)) {// 若选项不为空
			ud = customerMgr.getUserDefinedById(Integer.parseInt(optionId));
		}
		String optionName = request.getParameter("optionName");
		User user = SessionMgr.getCustSession(request);
		if (user != null) {
			ud.setDefinedName(optionName);//视图名称
			ud.setType(Constants.ALLCUSTOMER_INT);// 设置选项类型
			ud.setUser(user);
			ud.setInDate(new Date());
			customerMgr.updateOption(ud);// 保存用户选项(视图)
			
			UserFilter uf = null;
			for (int i = 1; i <= 20; i++) {// 遍历所有的过滤条件
				/**过滤条件id*/
				String filterId = request.getParameter("filterId" + i);
				
				String fieldId = request.getParameter("field" + i);// 字段
				String operatorPre = request.getParameter("operator" + i);// 预运算符名
				System.out.println("运算符为空吗" + operatorPre);
				String value = request.getParameter("value" + i);// 值
				
				boolean isDel = false;//要删除该过滤条件吗,初始值不为
				
				if (StringTool.isNotBlank(filterId)) {// 若过滤条件不为空,则从数据库中搜索该过滤条件
					
					uf = customerMgr.getUserFilterById(filterId);
					
					// 若字段名或运算符为空,则删除该过滤条件
					if (fieldId.equals("") || operatorPre.equals("")) {						
						customerMgr.deleteFilter(uf);
						isDel = true;
					}
					
				} else {
					//初始化一个过滤条件
					uf = new UserFilter();
					System.out.println("有到这里吗1..." + uf);
				}
				//若没有删除,则保存当前过滤条件
				if(!isDel) {
					
					uf.setOperatorName(operatorPre);// 保存运算符名
					uf.setFilter(value);// 保存SQL值
					
					String field = StringTool.getStringByField(fieldId);// 字段
					String operator = StringTool.transformStr(operatorPre);// 转换运算符
					if (operatorPre.equals(Constants.STARTCHAR)) {// 若运算符是起始字符
						value = "'" + value + "%'";
					} else if (operatorPre.equals(Constants.INCLUDE) || operatorPre.equals(Constants.EXCLUDE)) {// 若是模糊查询
						value = "'%" + value + "%'";
					} else {// 其余为数值或字符
						value = StringTool.transformString(fieldId, value);
					}
					
					uf.setFilterName(field);//过滤字段名称
					uf.setOperator(operator);//经转换后的运算符值
					uf.setFilterValue(value);//组合后的SQL值
					uf.setUserDefined(ud);
					
					if (StringTool.isNotBlank(filterId)) {// 若过滤条件不为空,则修改该过滤条件
						customerMgr.updateUserFilter(uf);// 修改过滤条件
					} else {
						customerMgr.addUserFilter(uf);// 保存过滤条件
						System.out.println("保存..." + uf);
					}
				}			
			}

			String optionFields = request.getParameter("preOptions"); // 分离预选项
			UserField userField = customerMgr.getUserFieldByOption(ud);
			userField.setFieldName(optionFields);
			userField.setUserDefined(ud);
			customerMgr.updateUserField(userField);// 修改显示字段
			System.out.println(userField.getFieldName());
			request.setAttribute("isSuccess", Constants.SAVESUCCESS);
		}
		return mapping.findForward("editOptionAgain");
	}

	/**
	 * 罗列左边页面的客户列表;
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward leftCustomer(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws ApplicationException {
		List<Customer> topCustomerList = customerMgr.getTopCustomer();
		request.setAttribute("topCustomerList", topCustomerList);
		System.out.println("测试:" + topCustomerList);
		return mapping.findForward("leftCustomer");
	}

	/**
	 * 根据客户名称搜索客户;
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws ApplicationException
	 */
	public ActionForward findCustomerByName(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws ApplicationException {
		String nameLike = "";
		try {
			nameLike = URLDecoder.decode(request.getParameter("nameLike"),
					"utf-8");// 传中文参数转编码;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		User user = SessionMgr.getCustSession(request);
		List<UserDefined> options = customerMgr.getOptionsByUserAndType(user,
				Constants.ALLCUSTOMER_INT);// 根据用户获取所有用户自定义选项
		request.setAttribute("options", options);
		String forward = "customerList";
		System.out.println(nameLike);
		List<Customer> customers = null;
		if (user != null) {
			customers = customerMgr.getCustomerByName(nameLike);
			System.out.println("一共有几个选项:" + customers.size());
			String currentPage = request.getParameter("currentPage");
			XPage xpage = new XPage(request.getContextPath()
					+ "/customer.do?method=findCustomerByName&nameLike="
					+ nameLike, 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("loginerror", Constants.MESSAGE);

⌨️ 快捷键说明

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