package action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.persistence.criteria.Order;
import org.apache.struts2.ServletActionContext;
import org.hibernate.mapping.Collection;
import utils.MyFileUtil;
import com.opensymphony.xwork2.ActionSupport;
import dao.EvaluationDao;
import dao.OrderShoesDao;
import dao.ShoesDao;
import daoImpl.ShoesDaoImpl;
import entity.Brand;
import entity.Client;
import entity.Evaluation;
import entity.OrderShoes;
import entity.Shoes;
public class ShoesAction extends SuperAction {
private ShoesDao shoesDao;
private Brand brand;
private List<OrderShoes> shoppingCarShoes;
private Shoes shoes;
private Evaluation evaluation;
private EvaluationDao evaluationDao;
private MyFileUtil brandPhoto;
private MyFileUtil evaluationPhoto;
private MyFileUtil smallPhoto;
private MyFileUtil bigPhoto;
private OrderShoesDao orderShoesDao;
private String searchStr;
public MyFileUtil getBrandPhoto() {
return brandPhoto;
}
public void setBrandPhoto(MyFileUtil brandPhoto) {
this.brandPhoto = brandPhoto;
}
public String getSearchStr() {
return searchStr;
}
public void setSearchStr(String searchStr) {
this.searchStr = searchStr;
}
public OrderShoesDao getOrderShoesDao() {
return orderShoesDao;
}
public void setOrderShoesDao(OrderShoesDao orderShoesDao) {
this.orderShoesDao = orderShoesDao;
}
public MyFileUtil getEvaluationPhoto() {
return evaluationPhoto;
}
public void setEvaluationPhoto(MyFileUtil evaluationPhoto) {
this.evaluationPhoto = evaluationPhoto;
}
public MyFileUtil getSmallPhoto() {
return smallPhoto;
}
public void setSmallPhoto(MyFileUtil smallPhoto) {
this.smallPhoto = smallPhoto;
}
public MyFileUtil getBigPhoto() {
return bigPhoto;
}
public void setBigPhoto(MyFileUtil bigPhoto) {
this.bigPhoto = bigPhoto;
}
public Evaluation getEvaluation() {
return evaluation;
}
public void setEvaluation(Evaluation evaluation) {
this.evaluation = evaluation;
}
public EvaluationDao getEvaluationDao() {
return evaluationDao;
}
public void setEvaluationDao(EvaluationDao evaluationDao) {
this.evaluationDao = evaluationDao;
}
public Shoes getShoes() {
return shoes;
}
public void setShoes(Shoes shoes) {
this.shoes = shoes;
}
public ShoesDao getShoesDao() {
return shoesDao;
}
public void setShoesDao(ShoesDao shoesDao) {
this.shoesDao = shoesDao;
}
public Brand getBrand() {
return brand;
}
public void setBrand(Brand brand) {
this.brand = brand;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("execute");
// queryShoesByBrand();
return SUCCESS;
}
public String queryAllShoes() {
queryAllBrand();
List<Shoes> shoesList = shoesDao.getAllShoes();
if (shoesList != null && shoesList.size() > 0) {
session.setAttribute("shoes_list", shoesList);
}
System.out.println(shoesList.size());
if (request.getParameter("user") != null) {
return "admin_shoes_list";
}
return "shoes_list";
}
public String queryShoesById() {
int sid = Integer.valueOf(request.getParameter("sid"));
System.out.println("sid"+sid);
Shoes s = shoesDao.getShoesById(sid);
session.setAttribute("shoes_detial", s);
List<Evaluation> allEvaluations = new ArrayList<Evaluation>();
List<OrderShoes> orderShoes = orderShoesDao.queryOrderByShoes(sid);
for(OrderShoes os:orderShoes){
List<Evaluation> evaluations = evaluationDao.queryEvaluationByOidUserInShoesDetial(os.getOid());
allEvaluations.addAll(evaluations);
}
//System.out.println(allEvaluations.get(0).getOrderShoes().getClient().getNickName());
session.setAttribute("allEvaluations", allEvaluations);
if (request.getParameter("fuction").equals("update")) {
return "admin_shoes_detial";
}else {
return "shoes_detial";
}
}
public String jumpEvaluation() {
int oid = Integer.valueOf(request.getParameter("eOId"));
Evaluation evaluation = evaluationDao.queryEvaluationByOid(oid);
if (evaluation!=null) {
session.setAttribute("evaluation",evaluation);
return "browser_evaluation_succuss";
}
session.setAttribute("eOId", oid);
return "jumpEvaluation_success";
}
public String insertEvaluation() throws Exception {
int oid = (Integer) session.getAttribute("eOId");
OrderShoes orderShoes = orderShoesDao.queryOrderByOid(oid);
System.out.println(oid);
String pathString = evaluationPhoto.uploadPhoto("evalue");
evaluation.setOrderShoes(orderShoes);
evaluation.setEvaluePicturePath(pathString);
evaluationDao.saveEvaluation(evaluation);
return "evalue_success";
}
public String insertShoes() throws Exception {
System.out.println(brand.getBid());
brand = shoesDao.queryBrandById(brand.getBid());
shoes.setBrand(brand);
String smallPicturePath = smallPhoto.uploadPhoto("shoesSmall");
String bigPicturePath = bigPhoto.uploadPhoto("shoesBig");
shoes.setBigPicturePath(bigPicturePath);
shoes.setSmallPicturePath(smallPicturePath);
shoesDao.saveShoes(shoes);
List<Shoes> shoess = (List<Shoes>) session.getAttribute("shoes_list");
if (shoess==null) {
shoess=new ArrayList<Shoes>();
}
shoess.add(shoes);
session.setAttribute("shoes_list", shoess);
return "shoes_insert";
}
public String showGenderShoes() {
String gender = request.getParameter("gender");
if (gender.equals("boy")) {
gender = "男";
} else {
gender = "女";
}
List<Shoes> shoesGenderList = shoesDao.queryShoesByGender(gender);
session.setAttribute("shoes_gender_list", shoesGenderList);
return "shoes_gender";
}
public String updateShoes() throws Exception {
Shoes s = (Shoes) session.getAttribute("shoes_detial");
shoes.setSid(s.getSid());
if (smallPhoto != null) {
String smallPicturePath = smallPhoto.uploadPhoto("shoesSmall");
shoes.setSmallPicturePath(smallPicturePath);
} else {
shoes.setSmallPicturePath(s.getSmallPicturePath());
}
if (bigPhoto != null) {
String bigPicturePath = bigPhoto.uploadPhoto("shoesBig");
shoes.setBigPicturePath(bigPicturePath);
} else {
shoes.setBigPicturePath(s.getBigPicturePath());
}
shoesDao.updateShoes(shoes);
return "shoes_update";
}
public String insertBrand() throws Exception {
System.out.println("调用");
//System.out.println("photo"+brandPhoto);
//String str = brandPhoto.uploadPhoto("brand");
//brand.setBrandPhoto(str);
shoesDao.saveBrand(brand);
return "brand_save_success";
}
public String queryAllBrand() {
List<Brand> brands = shoesDao.queryAllBrand();
System.out.println(brands.size());
System.out.println(brands.get(0).getBcname());
session.setAttribute("brand_list", brands);
return "brand_query_success";
}
public String addShoppingCar() {
int tempShoesNum = Integer
.valueOf(request.getParameter("tempShoesNum"));
System.out.println(tempShoesNum);
if (session.getAttribute("online_client") == null) {
return "add_shopingcar_faliure";
}
if (session.getAttribute("shoppingcar") == null) {
shoppingCarShoes = new ArrayList<OrderShoes>();
} else {
shoppingCarShoes = (List<OrderShoes>) session
.getAttribute("shoppingcar");
}
Shoes shoes = (Shoes) session.getAttribute("shoes_detial");
OrderShoes shoesBuy = new OrderShoes();
shoesBuy.setNum(tempShoesNum);
shoesBuy.setShoes(shoes);
System.out.println(shoesBuy.getNum());
shoesBuy.setPayment(tempShoesNum * shoes.getPrice());
System.out.print