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

📄 productlistaction.java

📁 工厂版本管理系统,STRUTS2框架,用于管理商品的版本,便于有效的控制版本
💻 JAVA
字号:
package com.bluesky.elecall.web.struts.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bluesky.elecall.dao.IManufactoryDao;
import com.bluesky.elecall.domain.CategoryItem;
import com.bluesky.elecall.domain.IProductCategory;
import com.bluesky.elecall.domain.Manufactory;
import com.bluesky.elecall.domain.Product;
import com.bluesky.elecall.domain.ProductAttribute;
import com.bluesky.elecall.domain.cart.ShoppingCart;
import com.bluesky.elecall.domain.search.AttributeStatistics;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;

public class ProductListAction extends ProductCategoryBaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -905631074830993753L;

	// form bean	
	private CategoryItem family;
	

	// shopping cart
	private String productId;
	private long quantity;

	private Manufactory manufactory;
	private ProductAttribute productAttribute;


	// statistics
	private List familyStatistics;
	private List manufactoryStatistics;
	private AttributeStatistics attributeStatistics;

	private List products;

	public ProductListAction() {

		family = new CategoryItem();
		manufactory = new Manufactory();
		productAttribute = new ProductAttribute();
		
	}


	public List getProducts() {
		return products;
	}
	
	public long getQuantity() {
		return quantity;
	}

	public String getProductId() {
		return productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public void setQuantity(long quantity) {
		this.quantity = quantity;
	}

	public CategoryItem getFamily() {
		return family;
	}

	public void setFamily(CategoryItem family) {
		this.family = family;
	}

	public Manufactory getManufactory() {
		return manufactory;
	}

	public void setManufactory(Manufactory manufactory) {
		this.manufactory = manufactory;
	}

	public ProductAttribute getProductAttribute() {
		return productAttribute;
	}

	public void setProductAttribute(ProductAttribute productAttribute) {
		this.productAttribute = productAttribute;
	}


	public void setProducts(List products) {
		this.products = products;
	}


	public String chooseFamily() {
		family = productCategory.getCategoryItem(family.getId());
		setChoosenFamily(family);

		
		return SUCCESS;
	}

	public String unchooseFamily() {
		setChoosenFamily(null);

		
		return SUCCESS;
	}

	public String chooseManufactory() {
		manufactory = manufactoryDao.get(manufactory.getId());
		setChoosenManufactory(manufactory);

		
		return SUCCESS;
	}

	public String chooseAttribute() {
		getChoosenAttributes().put(productAttribute.getName(),
				productAttribute.getValue());

		
		return SUCCESS;
	}

	public String unchooseAttribute() {
		getChoosenAttributes().remove(productAttribute.getName());

		
		return SUCCESS;
	}

	public String addToShoppingCart() {
		Product p = productCategory.getProduct(productId);
		getShoppingCart().addItem(p.getId(), quantity, p);

		
		return SUCCESS;
	}

	public String list() {
		// clear session
		setChoosenAttributes(null);
		setChoosenFamily(null);
		setChoosenManufactory(null);

		
		return SUCCESS;
	}

	@Override
	public String execute() throws Exception {
		return list();
	}

	public AttributeStatistics getAttributeStatistics() {
		return attributeStatistics;
	}

	public void setAttributeStatistics(AttributeStatistics attributeStatistics) {
		this.attributeStatistics = attributeStatistics;
	}
	
	@Override
	public void beforeResult(ActionInvocation arg0, String arg1) {
		// load the selected subsection
		CategoryItem subsection = productCategory.getCategoryItem(
				categoryItemId, 1);

		
		

		if (keywords == null)
			keywords = "";
		keywords = keywords.trim();

		// load families
		familyStatistics = productCategory.getFamilyStatistics(subsection,
				getChoosenFamily(), getChoosenManufactory(),
				getChoosenAttributes(), keywords);
		manufactoryStatistics = productCategory.getManufactoryStatistics(
				subsection, getChoosenFamily(), getChoosenManufactory(),
				getChoosenAttributes(), keywords);
		attributeStatistics = productCategory.getAttributeStatistics(
				subsection, getChoosenFamily(), getChoosenManufactory(),
				getChoosenAttributes(), keywords);

		products = productCategory.findProduct(subsection, getChoosenFamily(),
				getChoosenManufactory(), getChoosenAttributes(), keywords);
		
		
		
		super.beforeResult(arg0, arg1);
	}

	

	public List getFamilyStatistics() {
		return familyStatistics;
	}

	public void setFamilyStatistics(List familyStatistics) {
		this.familyStatistics = familyStatistics;
	}

	public List getManufactoryStatistics() {
		return manufactoryStatistics;
	}

	public void setManufactoryStatistics(List manufactoryStatistics) {
		this.manufactoryStatistics = manufactoryStatistics;
	}

	public CategoryItem getChoosenFamily() {
		return (CategoryItem) session.get("choosenFamily");
	}

	public void setChoosenFamily(CategoryItem choosenFamily) {
		session.put("choosenFamily", choosenFamily);

	}

	public Manufactory getChoosenManufactory() {
		return (Manufactory) session.get("choosenManufactory");
	}

	public void setChoosenManufactory(Manufactory choosenManufactory) {
		session.put("choosenManufactory", choosenManufactory);
	}

	public Map getChoosenAttributes() {
		Map map = (Map) session.get("choosenAttributes");
		if (map == null) {
			map = new HashMap<String, String>();
			setChoosenAttributes(map);
		}

		return map;
	}

	public void setChoosenAttributes(Map choosenAttributes) {
		session.put("choosenAttributes", choosenAttributes);
	}

}

⌨️ 快捷键说明

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