package org.whatisjava.dd.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.hibernate.Session;
import org.whatisjava.dd.domain.Category;
import org.whatisjava.dd.domain.Product;
import org.whatisjava.dd.util.DDUtils;
public class ProductServiceImpl implements ProductService {
Map<Integer, String> orderQuerys = new HashMap<Integer, String>();
public ProductServiceImpl() {
orderQuery();
}
public List<Product> findProdectByCategoryId(Integer cateId) {
Session session = DDUtils.getSession();
Query query = session
.createQuery("from Product p join fetch p.categorys c where c.id = ?");
query.setParameter(0, cateId);
List<Product> proList = query.list();
session.close();
return proList;
}
public Product findProductById(Integer id) {
Session session = DDUtils.getSession();
Query query = session
.createQuery("from Product p join fetch p.categorys where p.id = ?");
query.setParameter(0, id);
Product product = (Product) query.uniqueResult();
session.close();
return product;
}
public void deleteProductById(Integer id) {
Session session = DDUtils.getSession();
Query query = session
.createQuery("from Product p join fetch p.categorys where p.id = ?");
query.setParameter(0, id);
Product product = (Product) query.uniqueResult();
session.beginTransaction();
session.delete(product);
session.getTransaction().commit();
session.close();
}
public void updateProduct(Product product) {
// TODO Auto-generated method stub
}
public void addProduct(Product product) {
// TODO Auto-generated method stub
}
public Integer perCategoryNumber(Integer id) {
// TODO Auto-generated method stub
return null;
}
public List<Product> findHotProdect() {
Session session = DDUtils.getSession();
Query query = session.createQuery("from Product p where p.keyset = ?");
query.setParameter(0, 2);
List<Product> hotList = query.list();
session.close();
return hotList;
}
public List<Product> findNewProdect() {
Session session = DDUtils.getSession();
Query query = session.createQuery("from Product p where p.keyset = ?");
query.setParameter(0, 1);
List<Product> newList = query.list();
session.close();
return newList;
}
public List<Product> findRecommendProdect() {
Session session = DDUtils.getSession();
Query query = session.createQuery("from Product p where p.keyset = ?");
query.setParameter(0, 3);
List<Product> recList = query.list();
session.close();
return recList;
}
public int totalHotPage(int rowsPerPage) {
Session session = DDUtils.getSession();
Query query = session
.createQuery("select count(*) from Product b where b.keyset = ?");
query.setParameter(0, 1);
int totalRows = ((Number) query.list().get(0)).intValue();
int totalPage;
session.close();
if (totalRows % rowsPerPage == 0) {
totalPage = totalRows / rowsPerPage;
} else {
totalPage = totalRows / rowsPerPage + 1;
}
return totalPage;
}
public int totalNewPage(int rowsPerPage) {
Session session = DDUtils.getSession();
Query query = session
.createQuery("select count(*) from Product b where b.keyset = ?");
query.setParameter(0, 0);
int totalRows = ((Number) query.list().get(0)).intValue();
int totalPage;
session.close();
if (totalRows % rowsPerPage == 0) {
totalPage = totalRows / rowsPerPage;
} else {
totalPage = totalRows / rowsPerPage + 1;
}
return totalPage;
}
public int totalRecommendPage(int rowsPerPage) {
Session session = DDUtils.getSession();
Query query = session
.createQuery("select count(*) from Product b where b.keyset = ?");
query.setParameter(0, 2);
int totalRows = ((Number) query.list().get(0)).intValue();
int totalPage;
session.close();
if (totalRows % rowsPerPage == 0) {
totalPage = totalRows / rowsPerPage;
} else {
totalPage = totalRows / rowsPerPage + 1;
}
return totalPage;
}
public List<Product> findProductByCategoryId(Integer cateId, int page,
int rowsPerPage, int order) {
Session session = DDUtils.getSession();
Query query = session
.createQuery("from Product p join fetch p.categorys c where c.id=?"
+ orderQuerys.get(order));
query.setParameter(0, cateId);
query.setFirstResult((page - 1) * rowsPerPage);
query.setMaxResults(rowsPerPage);
List<Product> list = query.list();
session.close();
return list;
}
public int totalProductPageByCategoryId(Integer cateId, int rowsPerPage) {
Session session = DDUtils.getSession();
Category cat = (Category) session.get(Category.class, cateId);
session.close();
int rows = cat.getProductNum();
if (rows % rowsPerPage == 0) {
return rows / rowsPerPage;
} else {
return rows / rowsPerPage + 1;
}
}
public Map<Integer, String> getOrderOptions() {
Map<Integer, String> orderOptions = new HashMap<Integer, String>();
orderOptions.put(ProductService.ORDER_DEFAULT,"默认排序");
orderOptions.put(ProductService.ORDER_AUTHOR_ASC,"作者升序");
orderOptions.put(ProductService.ORDER_AUTHOR_DESC,"作者降序");
orderOptions.put(ProductService.ORDER_PRODUCTNAME_ASC,"商品名升序");
orderOptions.put(ProductService.ORDER_PRODUCTNAME_DESC,"商品名降序");
orderOptions.put(ProductService.ORDER_PUBLISHDATE_ASC,"出版时间升序");
orderOptions.put(ProductService.ORDER_PUBLISHDATE_DESC,"出版时间降序");
orderOptions.put(ProductService.ORDER_ADDTIME_ASC,"上架时间升序");
orderOptions.put(ProductService.ORDER_ADDTIME_DESC,"上架时间降序");
orderOptions.put(ProductService.ORDER_DDPRICE_ASC,"当当价格升序");
orderOptions.put(ProductService.ORDER_DDPRICE_DESC,"当当价格降序");
orderOptions.put(ProductService.ORDER_PUBLISHER_ASC,"出版社升序");
orderOptions.put(ProductService.ORDER_PUBLISHER_DESC,"出版社降序");
return orderOptions;
}
public void orderQuery() {
orderQuerys.put(ProductService.ORDER_DEFAULT, "");
orderQuerys.put(ProductService.ORDER_AUTHOR_ASC,
"order by p.author asc");
orderQuerys.put(ProductService.ORDER_AUTHOR_DESC,
"order by p.author desc");
orderQuerys.put(ProductService.ORDER_PRODUCTNAME_ASC,
"order by p.productName asc");
orderQuerys.put(ProductService.ORDER_PRODUCTNAME_DESC,
"order by p.productName desc");
orderQuerys.put(ProductService.ORDER_PUBLISHDATE_ASC,
"order by p.publishDate asc");
orderQuerys.put(ProductService.ORDER_PUBLISHDATE_DESC,
"order by p.publishDate desc");
orderQuerys.put(ProductService.ORDER_ADDTIME_ASC,
"order by p.addTime asc");
orderQuerys.put(ProductService.ORDER_ADDTIME_DESC,
"order by p.addTime desc");
orderQuerys.put(ProductService.ORDER_DDPRICE_ASC,
"order by p.ddPrice asc");
orderQuerys.put(ProductService.ORDER_DDPRICE_DESC,
"order by p.ddPrice desc");
orderQuerys.put(ProductService.ORDER_PUBLISHER_ASC,
"order by p.publisher asc");
orderQuerys.put(ProductService.ORDER_PUBLISHER_DESC,
"order by p.publisher desc");
}
public List<Product> findAllProduct() {
Session session = DDUtils.getSession();
List<Product> list = session.createQuery("select distinct p from Product p join fetch p.categorys").list();
session.close();
return list;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
当当源码2超好DangDang_Struts2_hibernate (766个子文件)
ProductServiceImpl.class 7KB
OrderServiceImpl.class 5KB
User.class 4KB
CartServiceImpl.class 4KB
ProductByCategorySearchAction.class 4KB
UserServiceImpl.class 4KB
Order.class 3KB
Book.class 3KB
VerifyCodeAction.class 3KB
UserRegisterAction.class 3KB
CartItemListAction.class 3KB
Product.class 3KB
UserUpdateInformationAction.class 3KB
UserLoginAction.class 3KB
AuthorizeFilter.class 3KB
ProductUpdateFormAction.class 3KB
OrderBuildAction.class 3KB
CartSumPriceAction.class 2KB
OrderListAction.class 2KB
OrderDetailsAction.class 2KB
Category.class 2KB
ServiceFactory.class 2KB
CategoryServiceImpl.class 2KB
UserUpdateInformationFormAction.class 2KB
ProvinceServiceImpl.class 2KB
ProductListAction.class 2KB
UserListAction.class 2KB
BaseAction.class 2KB
UserRegisterCheckAction.class 2KB
Item.class 2KB
CartItemAddAction.class 2KB
Address.class 2KB
ProductService.class 2KB
AddressServiceImpl.class 2KB
DDUtils.class 2KB
GetAddressAction.class 2KB
PaymentServiceImpl.class 2KB
UserUpdatePasswordAction.class 1KB
CheckUserPasswordAction.class 1KB
ProductDetailsListAction.class 1KB
GetProvinceAction.class 1KB
CheckVerifyCodeAction.class 1KB
Province.class 1KB
CheckUserEmailAction.class 1KB
CartItemNumberUpdateAction.class 1KB
UserUpdateEmailAction.class 1KB
RecommendProductAction.class 1KB
HotProductAction.class 1KB
NewProductAction.class 1KB
CategoryAction.class 1KB
LogInfoAction.class 1KB
CartItemRecoveryAction.class 1KB
CartItemDeleteAction.class 1KB
OrderDeleteAction.class 1KB
ProductDeleteAction.class 1KB
UserDeleteAction.class 1000B
UserUpdatePasswordFormAction.class 999B
UserUpdateEmailFormAction.class 990B
ProductShowAction.class 970B
CartService.class 818B
City.class 796B
Payment.class 793B
CartItemClearAction.class 778B
ValiUtil.class 722B
UserLoginFormAction.class 700B
OrderService.class 694B
UserService.class 675B
UserLogoutAction.class 603B
CategoryService.class 522B
UserRegisterFormAction.class 485B
PorductAddFormAction.class 475B
ProductUpdateAction.class 472B
ProductAddAction.class 463B
ProvinceService.class 426B
AddressService.class 362B
PaymentService.class 342B
.classpath 3KB
book.css 25KB
second.css 20KB
register_login.css 14KB
book_head090107.css 13KB
login.css 13KB
my_dd.css 11KB
list.css 10KB
my_order.css 10KB
my_archives.css 8KB
gwap.css 8KB
address_pw.css 6KB
shopping_head.css 5KB
booksaleslist.css 5KB
mydd_leftnavi.css 3KB
tarena.css 3KB
page_bottom.css 3KB
mydd_title.css 2KB
mydd_public.css 2KB
public_footer.css 2KB
research.css 2KB
secBook_Show.css 1KB
navi.css 1KB
pubsug090107.css 555B
共 766 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
- zx859631522013-08-13架构看上去弄好了,但是没有实际内容,不适合初学者
- bike82012-05-03架构看上去弄好了,但是没有实际内容,不适合初学者。
shoulder2010
- 粉丝: 1
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功