package com.lyq.action.product;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.lyq.action.BaseAction;
import com.lyq.model.PageModel;
import com.lyq.model.order.OrderItem;
import com.lyq.model.product.Comments;
import com.lyq.model.product.ProductCategory;
import com.lyq.model.product.ProductInfo;
import com.lyq.model.product.UploadFile;
import com.lyq.util.StringUitl;
import com.opensymphony.xwork2.ModelDriven;
/**
* 商品Action
*/
@Scope("prototype")
@Controller("productAction")
public class ProductAction extends BaseAction implements ModelDriven<ProductInfo>{
private static final long serialVersionUID = 1L;
/**
* 根据id查看商品信息(查看后更新人气点击次数)
* @return String
* @throws Exception
*/
public String select() throws Exception {
if(product.getId() != null && product.getId() > 0){
product = productDao.get(product.getId());
//计算当前已参数人数
String where = "where productId = ? and signs = 'N'";
Object[] queryParams = {product.getId()};
List<OrderItem> list = orderItemDao.find(-1, -1, where, queryParams).getList();
String where1 = "where pid = ?";
Object[] queryParams1 = {product.getId()};
List<Comments> list1 = commentsDao.find(-1, -1, where1, queryParams1).getList();
//上期获奖者
String where2 = "where productId = ? and signs = 'Y' and flag = 'Y' order by periods desc ";
Object[] queryParams2 = {product.getId()};
List<OrderItem> list2 = orderItemDao.find(-1, -1, where2, queryParams2).getList();
product.setClickcount(product.getClickcount() + 1);
productDao.update(product);
product.setCynum(list.size());
product.setWcynum(product.getNum() - product.getCynum());
product.setListOrderItem(list);
if(list2.size() > 0){
product.setOrderItem(list2.get(0));
}
product.setListComments(list1);
}
return SELECT;
}
public String zhongjiang() throws Exception{
String where2 = "where signs = 'Y' and flag = 'Y' order by periods desc ";
Object[] queryParams2 = {};
pageModel1 = orderItemDao.find(pageNo, pageSize, where2, queryParams2 );//执行查询方法
return "zhongjiang";
}
public String select1() throws Exception {
if(product.getId() != null && product.getId() > 0){
product = productDao.get(product.getId());
//计算当前已参数人数
String where = "where productId = ? and signs = 'N'";
Object[] queryParams = {product.getId()};
List<OrderItem> list = orderItemDao.find(-1, -1, where, queryParams).getList();
String where1 = "where pid = ?";
Object[] queryParams1 = {product.getId()};
List<Comments> list1 = commentsDao.find(-1, -1, where1, queryParams1).getList();
product.setCynum(list.size());
product.setWcynum(product.getNum() - product.getCynum());
product.setListOrderItem(list);
product.setListComments(list1);
}
return "select1";
}
/**
* 根据类别id查询所有商品信息
* @return String
* @throws Exception
*/
public String getByCategoryId() throws Exception{
if(product.getCategory().getId() != null){
String where = "where category.id = ?";
Object[] queryParams = {product.getCategory().getId()};
pageModel = productDao.find(pageNo, pageSize, where, queryParams);
}
return LIST;
}
/**
* 新品上市
* @return
* @throws Exception
*/
public String findNewProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("createTime", "desc");//为Map集合赋值
pageModel = productDao.find(pageNo,pageSize, orderby );//执行查找方法
image.put("url", "01.gif");//设置副标题图片
return "list";//返回商品列表页面
}
/**
* 热销商品
* @return
* @throws Exception
*/
public String findSellProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("sellCount", "desc");//为Map集合赋值
pageModel = productDao.find(pageNo,pageSize, orderby );//执行查找方法
image.put("url", "03.gif");
return "list";//返回商品列表页面
}
/**
* 推荐商品
* @return
* @throws Exception
*/
public String findCommendProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("createTime", "desc");//为Map集合赋值
String where = "where commend = ?";//设置条件语句
Object[] queryParams = {true};//设置参数值
pageModel = productDao.find(where, queryParams, orderby, pageNo,pageSize);//执行查询方法
image.put("url", "06.gif");
return "list";//返回商品列表页面
}
/**
* 人气商品
* @return
* @throws Exception
*/
public String findEnjoyProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("clickcount", "desc");//为Map集合赋值
pageModel = productDao.find(1, 8, orderby );//执行查找方法
image.put("url", "07.gif");
return "list";//返回商品列表页面
}
/**
* 根据名称模糊查询
* @return String
* @throws Exception
*/
public String findByName() throws Exception {
if(product.getName() != null){
String where = "where name like ?";//查询的条件语句
Object[] queryParams = {"%" + product.getName() + "%"};//为参数赋值
pageModel = productDao.find(pageNo, pageSize, where, queryParams );//执行查询方法
}
image.put("url", "04.gif");
return LIST;//返回列表首页
}
/**
* 按人气查询
* @return String
* @throws Exception
*/
public String findByClick() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("clickcount", "desc");//为Map集合赋值
pageModel = productDao.find(pageNo,pageSize, orderby );//执行查找方法
return "clickList";//返回product_click_list.jsp页面
}
/**
* 按推荐查询
* @return String
* @throws Exception
*/
public String findByCommend() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("sellCount", "desc");//为Map集合赋值
String where = "where commend = ?";//设置条件语句
Object[] queryParams = {true};//设置参数值
pageModel = productDao.find(where, queryParams, orderby, pageNo, pageSize);//执行查询方法
return "findList";//返回product_find_list.jsp页面
}
/**
* 按销量查询
* @return String
* @throws Exception
*/
public String findBySellCount() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("sellCount", "desc");//为Map集合赋值
pageModel = productDao.find(1, 8, orderby );//执行查询方法
return "findList";//返回热销商品列表
}
/**
* 添加商品
*/
@Override
public String add() throws Exception {
createCategoryTree();
return INPUT;
}
public String yaojiang() throws Exception{
String where = "where productId = ? and signs = 'N'";
Object[] queryParams = {product.getId()};
List<OrderItem> list = orderItemDao.find(-1, -1, where, queryParams).getList();
if(list.size()!=0){
int index = (int) (Math.random() * list.size());
orderItem = list.get(index);
}else{
orderItem = new OrderItem();
}
return "yaojiang";//返回商品列表页面
}
public String gental() throws Exception{
String where = "where productId = ? and signs = 'N'";
Object[] queryParams = {orderItem.getProductId()};
List<OrderItem> list = orderItemDao.find(-1, -1, where, queryParams).getList();
for(OrderItem oItem : list){
oItem.setPeriods(new SimpleDateFormat("yyyyMMdd").format(new Date()));
oItem.setSigns("Y");
qq_26337883
- 粉丝: 0
- 资源: 2