码迷,mamicode.com
首页 > 其他好文 > 详细

购物车整理

时间:2015-06-03 21:28:12      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

@RequestMapping(value = "/shopper")
public String shopperIndex(HttpServletRequest request, Model model, boolean isClient) throws BusinessException
{
String dealerId = super.getDealerParentRefrenceId(request);
List<DealerShoper> dealerShoperList = dealerShoperService.getAllDealerShopersBy(dealerId);
// 购物车记录 不存在时
if (dealerShoperList == null || dealerShoperList.isEmpty()) { return isClient ? "dealer/shopper_index_erp_v2" : "dealer/shopper_index_v2"; }
//sku属性装入实体
for(DealerShoper dealerShoper : dealerShoperList)
{
List<DealerShopers> dealerShopersList = dealerShopersService.getEntityByProductId(dealerShoper.getProductId());
dealerShoper.setDealerShopersList(dealerShopersList);
}
//封装数据
Map<String,ShopersModel> shoperModelMap = transDealerShopperToShoperModelList(dealerShoperList);
List<ShopersModel> shopersModelList = Lists.newArrayList();
for(ShopersModel shoperModel : shoperModelMap.values() )
{
shopersModelList.add(shoperModel);
}
model.addAttribute("shopersModelList",shopersModelList);
return isClient ? "dealer/shopper_index_erp_v2" : "dealer/shopper_index_v2";
}



public Map<String,ShopersModel> transDealerShopperToShoperModelList(List<DealerShoper> dealerShoperList) {
Integer purchaseNumAllSum = 0;
BigDecimal purchasePriceAllSum = BigDecimal.ZERO;
Map<String,ShopersModel> shoperModelMap=Maps.newHashMap();
for(DealerShoper item : dealerShoperList)
{
String brandesId = item.getBrandsId();
if(shoperModelMap.get(brandesId) == null)
{
ShopersModel shopersModel = new ShopersModel();
shopersModel.setBrandId(item.getBrandId());
shopersModel.setBrandName(item.getBrandName());
shopersModel.setBrandesId(item.getBrandsId());
shopersModel.setBrandesName(item.getBrandsName());
shopersModel.getDealerShoperList().add(item);
shoperModelMap.put(brandesId,shopersModel);
}else{
ShopersModel shopersModel = shoperModelMap.get(brandesId);
shopersModel.getDealerShoperList().add(item);
}
if(item.getPurchaseNumSum() != null && item.getPurchaseNumSum() > 0)
{
ShopersModel shopersModel = shoperModelMap.get(brandesId);
shopersModel.setPurchasePriceAllSum(shopersModel.getPurchasePriceAllSum().add(item.getPurchasePriceSum()));
shopersModel.setPurchaseNumAllSum(shopersModel.getPurchaseNumAllSum()+item.getPurchaseNumSum());
}
}
return shoperModelMap;
}

private void countDealerOrdersToDealerOrder(DealerShoper dealerShoper, List<DealerShopers> dealerShopersList) {
//按产品id分类,购买该产品下的所有sku数量总和,对应shopper_balace_v2.jsp中的数量小计
Integer purchaseNum_byProduct = 0;
//按产品id分类,购买该产品下所有的sku数量总和的总价格,对应shopper_balace_v2.jsp中的金额小计
BigDecimal purchasePrice_byProduct = BigDecimal.ZERO;
for(int i = 0 ; i < dealerShopersList.size() ; i++)
{
DealerShopers item = dealerShopersList.get(i);
if(item.getPurchaseNum() == null || item.getPurchaseNum().equals(0))
{
dealerShopersList.remove(i); //去除后,list长度变了,所以需要相应的改变 i 的值
i--;
}
}
for(DealerShopers item : dealerShopersList)
{
purchaseNum_byProduct = purchaseNum_byProduct + item.getPurchaseNum();
purchasePrice_byProduct = purchasePrice_byProduct.add(dealerShoper.getProductPrice().multiply(new BigDecimal(item.getPurchaseNum())));
}
dealerShoper.setPurchaseNumSum(purchaseNum_byProduct);
dealerShoper.setPurchasePriceSum(purchasePrice_byProduct);
dealerShoper.setDealerShopersList(dealerShopersList);
}
 

购物车整理

标签:

原文地址:http://www.cnblogs.com/yiyongyao/p/4550194.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!