// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   ProductAppraisalAction.java

package com.keyshop.shop.product.controller;

import com.keyshop.pub.controller.PubAction;
import com.keyshop.pub.model.PubBean;
import com.keyshop.pub.util.*;
import com.keyshop.shop.product.bo.ProductAppraisalBO;
import com.keyshop.shop.product.model.ProductAppraisal;
import com.keyshop.shop.product.util.ProductHelper;
import java.util.ArrayList;
import javax.servlet.http.*;
import org.apache.struts.action.*;

// Referenced classes of package com.keyshop.shop.product.controller:
//            ProductAppraisalForm

public class ProductAppraisalAction extends PubAction
{

    public boolean isRedirect;

    public ProductAppraisalAction()
    {
        isRedirect = false;
    }

    public String getSelectSQL()
    {
        ProductAppraisalForm pform = (ProductAppraisalForm)thisform;
        ProductAppraisal bean = (ProductAppraisal)pform.getBean();
        String sql = "from ProductAppraisal as productAppraisal where 1=1";
        if(!StringUtil.isEmpty(bean.getProductId()))
            sql = sql + " and productAppraisal.productId='" + bean.getProductId() + "'";
        if(!StringUtil.isEmpty(bean.getSubject()))
            sql = sql + " and productAppraisal.subject='" + bean.getSubject() + "'";
        if(!StringUtil.isEmpty(bean.getGood()))
            sql = sql + " and productAppraisal.good='" + bean.getGood() + "'";
        if(!StringUtil.isEmpty(bean.getShortArea()))
            sql = sql + " and productAppraisal.shortArea='" + bean.getShortArea() + "'";
        sql = sql + " order by productAppraisal.createTime desc";
        return sql;
    }

    public void initClassName()
    {
        boClass = "com.keyshop.shop.product.bo.ProductAppraisalBO";
        beanClass = "com.keyshop.shop.product.model.ProductAppraisal";
        formBeanClass = "com.keyshop.shop.order.controller.ProductAppraisalForm";
    }

    public ActionForward performFgadd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        ProductAppraisalForm pform = (ProductAppraisalForm)form;
        try
        {
            String productId = request.getParameter("bean.productId");
            if(!StringUtil.isEmpty(productId))
            {
                com.keyshop.shop.product.model.Product p = ProductHelper.getProductById(productId);
                if(p != null)
                    pform.setProduct(p);
            }
            if(!StringUtil.isEmpty(productId))
            {
                ProductAppraisalBO bo = new ProductAppraisalBO();
                Pager page = new Pager(pform.getCurrentPageNo());
                request.setAttribute("pager", page);
                java.util.List list = bo.list(page, "from ProductAppraisal as pa where pa.productId='" + productId + "' order by pa.createTime desc");
                request.setAttribute("searchresult", list);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return mapping.findForward("fgadd");
    }

    public ActionForward performList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        String productId = request.getParameter("bean.productId");
        if(!StringUtil.isEmpty(productId))
        {
            return super.performList(mapping, form, request, response);
        } else
        {
            request.setAttribute("searchresult", new ArrayList());
            return mapping.findForward("list");
        }
    }

    public ActionForward performFgsave(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        String productId = request.getParameter("bean.productId");
        if(session.getAttribute("app" + productId) != null)
        {
            request.setAttribute("existed", "true");
            return performFgadd(mapping, form, request, response);
        }
        ProductAppraisalForm pform = (ProductAppraisalForm)form;
        ProductAppraisal bean = (ProductAppraisal)pform.getBean();
        bean.setCreateTime(DateUtil.getSysDateTimeString());
        if(!StringUtil.isEmpty(productId) && !StringUtil.isEmpty(bean.getSubject()) && StringUtil.isEmpty(bean.getId()))
            try
            {
                if(!StringUtil.isEmpty(productId))
                {
                    ProductAppraisalBO bo = new ProductAppraisalBO();
                    bo.addBean(bean);
                    request.setAttribute("save_success", "true");
                    session.setAttribute("app" + productId, "true");
                    bean.clear();
                }
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        return performFgadd(mapping, form, request, response);
    }

    protected boolean isObjectExisted(PubBean bean)
    {
        return false;
    }
}
