Commit eec3144d by wjg

修改购物车数据格式

parent 7d83dd71
......@@ -12,6 +12,8 @@ import android.widget.ToggleButton;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.StringAppend;
import com.ihaoin.hooloo.device.util.Utils;
......@@ -31,7 +33,10 @@ public class TrolleyAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TrolleyGoods goods = (TrolleyGoods) this.getItem(position);
TrolleyGoods trolleyGoods = (TrolleyGoods) this.getItem(position);
Goods goods = trolleyGoods.getGoods();
Sku sku = trolleyGoods.getSku();
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_trolley, null);
ToggleButton butnState = convertView.findViewById(R.id.butn_state);
ImageView imgThumbnail = convertView.findViewById(R.id.img_thumbnail);
......@@ -44,12 +49,12 @@ public class TrolleyAdapter extends BaseAdapter {
TextView txtCount = convertView.findViewById(R.id.txt_count);
View butnAdd = convertView.findViewById(R.id.butn_add);
butnState.setChecked(goods.getChecked());
butnState.setChecked(trolleyGoods.getChecked());
butnState.setOnCheckedChangeListener((buttonView, isChecked) -> {
goods.setChecked(isChecked);
trolleyGoods.setChecked(isChecked);
if (isChecked) {
if (!trolleyView.checkGoodsCount()) { // 购物车选中数量超过阈值,不允许选中
goods.setChecked(false);
trolleyGoods.setChecked(false);
butnState.setChecked(false);
return;
}
......@@ -57,21 +62,21 @@ public class TrolleyAdapter extends BaseAdapter {
trolleyView.goodsChanged();
});
txtName.setText(goods.getName());
if (!CollectionUtils.isEmpty(goods.getRules())) {
if (!CollectionUtils.isEmpty(sku.getRules())) {
StringAppend stringAppend = new StringAppend("/");
goods.getRules().forEach(x -> stringAppend.append(x.getRuleName()));
sku.getRules().forEach(x -> stringAppend.append(x.getRuleName()));
txtOptions.setText(stringAppend.toString());
txtOptions.setVisibility(View.VISIBLE);
} else {
txtOptions.setVisibility(View.GONE);
}
txtPrice.setText(Utils.toString(goods.getPrice()));
txtDiscount.setText(Utils.toString(goods.getDiscount()));
txtPrice.setText(Utils.toString(sku.getPrice()));
txtDiscount.setText(Utils.toString(sku.getDiscount()));
icoPrice.setPaintFlags(icoPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtPrice.setPaintFlags(txtPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtCount.setText(goods.getCount().toString());
txtCount.setText(trolleyGoods.getCount().toString());
butnSubtract.setOnClickListener(v -> trolleyView.subtractGoods(position));
butnAdd.setOnClickListener(v -> trolleyView.addGoods(position));
Utils.getGlide(mContext).load(goods.getPics().getThumbnail()).into(imgThumbnail);
......
package com.ihaoin.hooloo.device.data;
import com.ihaoin.hooloo.device.data.vo.Pics;
import com.ihaoin.hooloo.device.data.vo.SkuRule;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
public class TrolleyGoods implements Serializable {
/**
......@@ -16,60 +14,78 @@ public class TrolleyGoods implements Serializable {
* 是否选中
*/
private Boolean checked = true;
/** 商品信息 */
/**
* 商品id
*/
private Integer goodId;
/**
* 名称
*/
private String name;
/**
* 介绍
*/
private String desc;
/**
* 图片信息
*/
private Pics pics;
/**
* 标签
*/
private List<String> tags;
/** 购买sku信息 */
/**
* sku id
*/
private Integer skuId;
/**
* 状态:1-可售、2-不可售
*/
private Integer state;
/**
* 默认状态:0-否,1-是
*/
private Integer isDefault;
/**
* 原价
*/
private BigDecimal price;
/**
* 折扣价
*/
private BigDecimal discount;
/**
* SKU规格
*/
private List<SkuRule> rules;
/**
* 数量
*/
private Integer count;
private Goods goods;
private Sku sku;
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public Sku getSku() {
return sku;
}
public void setSku(Sku sku) {
this.sku = sku;
}
// /** 商品信息 */
// /**
// * 商品id
// */
// private Integer goodId;
// /**
// * 名称
// */
// private String name;
// /**
// * 介绍
// */
// private String desc;
// /**
// * 图片信息
// */
// private Pics pics;
// /**
// * 标签
// */
// private List<String> tags;
//
// /** 购买sku信息 */
// /**
// * sku id
// */
// private Integer skuId;
// /**
// * 状态:1-可售、2-不可售
// */
// private Integer state;
// /**
// * 默认状态:0-否,1-是
// */
// private Integer isDefault;
// /**
// * 原价
// */
// private BigDecimal price;
// /**
// * 折扣价
// */
// private BigDecimal discount;
// /**
// * SKU规格
// */
// private List<SkuRule> rules;
@Override
public boolean equals(Object o) {
if (o == null) {
......@@ -97,93 +113,93 @@ public class TrolleyGoods implements Serializable {
this.checked = checked;
}
public Integer getGoodId() {
return goodId;
}
public void setGoodId(Integer goodId) {
this.goodId = goodId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Pics getPics() {
return pics;
}
public void setPics(Pics pics) {
this.pics = pics;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
public Integer getSkuId() {
return skuId;
}
public void setSkuId(Integer skuId) {
this.skuId = skuId;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
public Integer getIsDefault() {
return isDefault;
}
public void setIsDefault(Integer isDefault) {
this.isDefault = isDefault;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getDiscount() {
return discount;
}
public void setDiscount(BigDecimal discount) {
this.discount = discount;
}
public List<SkuRule> getRules() {
return rules;
}
public void setRules(List<SkuRule> rules) {
this.rules = rules;
}
// public Integer getGoodId() {
// return goodId;
// }
//
// public void setGoodId(Integer goodId) {
// this.goodId = goodId;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDesc() {
// return desc;
// }
//
// public void setDesc(String desc) {
// this.desc = desc;
// }
//
// public Pics getPics() {
// return pics;
// }
//
// public void setPics(Pics pics) {
// this.pics = pics;
// }
//
// public List<String> getTags() {
// return tags;
// }
//
// public void setTags(List<String> tags) {
// this.tags = tags;
// }
//
// public Integer getSkuId() {
// return skuId;
// }
//
// public void setSkuId(Integer skuId) {
// this.skuId = skuId;
// }
//
// public Integer getState() {
// return state;
// }
//
// public void setState(Integer state) {
// this.state = state;
// }
//
// public Integer getIsDefault() {
// return isDefault;
// }
//
// public void setIsDefault(Integer isDefault) {
// this.isDefault = isDefault;
// }
//
// public BigDecimal getPrice() {
// return price;
// }
//
// public void setPrice(BigDecimal price) {
// this.price = price;
// }
//
// public BigDecimal getDiscount() {
// return discount;
// }
//
// public void setDiscount(BigDecimal discount) {
// this.discount = discount;
// }
//
// public List<SkuRule> getRules() {
// return rules;
// }
//
// public void setRules(List<SkuRule> rules) {
// this.rules = rules;
// }
public Integer getCount() {
return count;
......
package com.ihaoin.hooloo.device.data.po;
import com.ihaoin.hooloo.device.data.vo.Pics;
import com.ihaoin.hooloo.device.data.vo.Sku;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
public class ConfirmGoods implements Serializable {
......@@ -9,11 +13,24 @@ public class ConfirmGoods implements Serializable {
* 商品id
*/
private Integer goodsId;
/**
* sku列表
*/
private List<ConfirmSku> skus;
/** 名称 */
private String name;
/** 原价 */
private BigDecimal price;
/** 折扣价 */
private BigDecimal discount;
/** 介绍 */
private String desc;
/** 备注 */
private String remarks;
/** 图片信息 */
private Pics pics;
/** 标签 */
private List<String> tags;
/** 数量 */
private Integer count;
/** sku */
private Sku sku;
public Integer getGoodsId() {
return goodsId;
......@@ -23,11 +40,75 @@ public class ConfirmGoods implements Serializable {
this.goodsId = goodsId;
}
public List<ConfirmSku> getSkus() {
return skus;
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Sku getSku() {
return sku;
}
public void setSku(Sku sku) {
this.sku = sku;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getDiscount() {
return discount;
}
public void setDiscount(BigDecimal discount) {
this.discount = discount;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public Pics getPics() {
return pics;
}
public void setPics(Pics pics) {
this.pics = pics;
}
public List<String> getTags() {
return tags;
}
public void setSkus(List<ConfirmSku> skus) {
this.skus = skus;
public void setTags(List<String> tags) {
this.tags = tags;
}
}
......@@ -30,7 +30,6 @@ import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.data.po.ConfirmGoods;
import com.ihaoin.hooloo.device.data.po.ConfirmOrder;
import com.ihaoin.hooloo.device.data.po.ConfirmSku;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.network.HttpUtil;
......@@ -44,13 +43,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ConfirmOrderDialog extends Dialog {
private List<ConfirmGoods> goods = new ArrayList<>();
private List<ConfirmGoods> confirmGoods = new ArrayList<>();
private UIHandler uiHandler;
private ConfirmOrderHandler confirmOrderHandler;
private Thread expireThread;
......@@ -72,11 +69,11 @@ public class ConfirmOrderDialog extends Dialog {
}
public void setGoods(List<TrolleyGoods> trolleyGoods) {
this.goods = translate(trolleyGoods);
this.confirmGoods = translate(trolleyGoods);
}
public void setGoods(Goods goods, Sku sku, Integer count) {
this.goods = translate(goods, sku, count);
this.confirmGoods = translate(goods, sku, count);
}
@Override
......@@ -155,7 +152,7 @@ public class ConfirmOrderDialog extends Dialog {
confirmOrder.setMachineCode(AppConfig.MACHINE_CODE);
confirmOrder.setScreenNo(SharedPreferencesUtils.getScreenNo(getContext()));
confirmOrder.setSeqNo(genSeqNo());
confirmOrder.setGoods(goods);
confirmOrder.setGoods(confirmGoods);
String json = JsonUtils.getMapper().writeValueAsString(confirmOrder);
Log.d(AppConfig.DEBUG_TAG, json);
return json;
......@@ -340,29 +337,16 @@ public class ConfirmOrderDialog extends Dialog {
if (CollectionUtils.isEmpty(trolleyGoods)) {
return null;
}
Map<Integer, List<TrolleyGoods>> map = trolleyGoods.stream().collect(Collectors.groupingBy(TrolleyGoods::getGoodId));
if (CollectionUtils.isEmpty(map)) {
return null;
}
List<ConfirmGoods> confirmGoods = new ArrayList<>();
Iterator<Integer> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
Integer goodsId = iterator.next();
List<TrolleyGoods> goods = map.get(goodsId);
List<ConfirmSku> skus = goods.stream().map(x -> {
ConfirmSku confirmSku = new ConfirmSku();
confirmSku.setSkuId(x.getSkuId());
confirmSku.setCount(x.getCount());
return confirmSku;
}).collect(Collectors.toList());
ConfirmGoods g = new ConfirmGoods();
g.setGoodsId(goodsId);
g.setSkus(skus);
confirmGoods.add(g);
}
return confirmGoods;
List<ConfirmGoods> mConfirmGoods = new ArrayList<>();
trolleyGoods.forEach(x -> {
ConfirmGoods goods = new ConfirmGoods();
goods = copyGoodsAttr(x.getGoods(), goods);
goods.setSku(x.getSku());
goods.setCount(x.getCount());
mConfirmGoods.add(goods);
});
return mConfirmGoods;
}
public List<ConfirmGoods> translate(Goods goods, Sku sku, Integer count) {
......@@ -370,14 +354,22 @@ public class ConfirmOrderDialog extends Dialog {
return null;
}
ConfirmSku confirmSku = new ConfirmSku();
confirmSku.setSkuId(sku.getSkuId());
confirmSku.setCount(count);
List<ConfirmSku> skus = Arrays.asList(confirmSku);
ConfirmGoods confirmGoods = new ConfirmGoods();
confirmGoods.setGoodsId(goods.getGoodsId());
confirmGoods.setSkus(skus);
confirmGoods = copyGoodsAttr(goods, confirmGoods);
confirmGoods.setSku(sku);
confirmGoods.setCount(count);
return Arrays.asList(confirmGoods);
}
private ConfirmGoods copyGoodsAttr(Goods goods, ConfirmGoods confirmGoods) {
confirmGoods.setGoodsId(goods.getGoodsId());
confirmGoods.setName(goods.getName());
confirmGoods.setPrice(goods.getPrice());
confirmGoods.setDiscount(goods.getDiscount());
confirmGoods.setDesc(goods.getDesc());
confirmGoods.setRemarks(goods.getRemarks());
confirmGoods.setPics(goods.getPics());
confirmGoods.setTags(goods.getTags());
return confirmGoods;
}
}
......@@ -118,7 +118,7 @@ public class TrolleyView extends RelativeLayout {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return;
}
Optional<TrolleyGoods> optional = this.trolleyGoods.stream().filter(x -> x.getGoodId().equals(goods.getGoodsId()) && x.getSkuId().equals(sku.getSkuId())).findAny();
Optional<TrolleyGoods> optional = this.trolleyGoods.stream().filter(x -> x.getGoods().getGoodsId().equals(goods.getGoodsId()) && x.getSku().getSkuId().equals(sku.getSkuId())).findAny();
// 判断是否在购物车里存在同样规格的产品
if (optional.isPresent()) {
TrolleyGoods g = optional.get();
......@@ -127,17 +127,19 @@ public class TrolleyView extends RelativeLayout {
TrolleyGoods g = new TrolleyGoods();
g.setId(RandomUtils.nextLong(trolleyGoods.stream().map(TrolleyGoods::getId).collect(Collectors.toList())));
g.setChecked(true);
g.setGoodId(goods.getGoodsId());
g.setName(goods.getName());
g.setDesc(goods.getDesc());
g.setPics(goods.getPics());
g.setTags(goods.getTags());
g.setSkuId(sku.getSkuId());
g.setState(sku.getState());
g.setIsDefault(sku.getIsDefault());
g.setPrice(sku.getPrice());
g.setDiscount(sku.getDiscount());
g.setRules(sku.getRules());
g.setGoods(goods);
g.setSku(sku);
// g.setGoodId(goods.getGoodsId());
// g.setName(goods.getName());
// g.setDesc(goods.getDesc());
// g.setPics(goods.getPics());
// g.setTags(goods.getTags());
// g.setSkuId(sku.getSkuId());
// g.setState(sku.getState());
// g.setIsDefault(sku.getIsDefault());
// g.setPrice(sku.getPrice());
// g.setDiscount(sku.getDiscount());
// g.setRules(sku.getRules());
g.setCount(count);
this.trolleyGoods.add(g);
}
......@@ -196,11 +198,11 @@ public class TrolleyView extends RelativeLayout {
}
private BigDecimal getTotal() {
return this.getTrolleyGoods().stream().map(x -> x.getDiscount().multiply(new BigDecimal(x.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
return this.getTrolleyGoods().stream().map(x -> x.getSku().getDiscount().multiply(new BigDecimal(x.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
}
private BigDecimal getCheckedTotal() {
return this.getTrolleyGoods().stream().filter(TrolleyGoods::getChecked).map(x -> x.getDiscount().multiply(new BigDecimal(x.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
return this.getTrolleyGoods().stream().filter(TrolleyGoods::getChecked).map(x -> x.getSku().getDiscount().multiply(new BigDecimal(x.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
}
private void setView() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment