Commit eec3144d by wjg

修改购物车数据格式

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