Commit 29b287db by wjg

init

parent c08b2d1c
package com.ihaoin.hooloo.device.data.po;
import java.io.Serializable;
import java.util.List;
public class ConfirmGoods implements Serializable {
......@@ -11,14 +11,9 @@ public class ConfirmGoods implements Serializable {
private Integer goodsId;
/**
* skuId
*/
private Integer skuId;
/**
* 数量
* sku列表
*/
private Integer count;
private List<ConfirmSku> skus;
public Integer getGoodsId() {
return goodsId;
......@@ -28,19 +23,11 @@ public class ConfirmGoods implements Serializable {
this.goodsId = goodsId;
}
public Integer getSkuId() {
return skuId;
}
public void setSkuId(Integer skuId) {
this.skuId = skuId;
}
public Integer getCount() {
return count;
public List<ConfirmSku> getSkus() {
return skus;
}
public void setCount(Integer count) {
this.count = count;
public void setSkus(List<ConfirmSku> skus) {
this.skus = skus;
}
}
package com.ihaoin.hooloo.device.data.po;
import java.io.Serializable;
public class ConfirmSku implements Serializable {
/**
* skuId
*/
private Integer skuId;
/**
* 数量
*/
private Integer count;
public Integer getSkuId() {
return skuId;
}
public void setSkuId(Integer skuId) {
this.skuId = skuId;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}
......@@ -61,6 +61,7 @@ public class HttpUtil {
}
private static void onFailure(Handler handler, Call call, Exception e) {
try {
if (AppConfig.DEBUG) {
String msgText = String.format("返回状态:%s, 请求:%s, 返回内容:%s", 0, call.request().url(), e.getMessage());
Log.e(TAG, msgText);
......@@ -68,13 +69,11 @@ public class HttpUtil {
if (handler == null) {
return;
}
try {
Thread.sleep(3000);
} catch (Exception e3) {
e3.printStackTrace();
}
Message msg = handler.obtainMessage(0, e);
handler.sendMessage(msg);
} catch (Exception ex) {
onFailure(handler, call, e);
}
}
private static void onResponse(Handler handler, Call call, Response response) {
......@@ -87,10 +86,16 @@ public class HttpUtil {
if (handler == null) {
return;
}
// Thread.sleep(3000);
if (call.request().url().toString().contains("checkSku")) {
responseBody = "{\"msg\":\"该产品已经不存在\",\"code\":500}";
}
JSONObject jsonObject = JSON.parseObject(responseBody);
if (jsonObject == null || jsonObject.getInteger("code") == null || jsonObject.getInteger("code") != 200) {
onFailure(handler, call, new BizException("返回状态错误"));
if (jsonObject == null) {
onFailure(handler, call, new BizException("返回body为空"));
return;
}
if (jsonObject.getInteger("code") == null || jsonObject.getInteger("code") != 200) {
onFailure(handler, call, new BizException(jsonObject.getString("msg")));
return;
}
Message msg = handler.obtainMessage(1, jsonObject.get("data") == null ? "" : jsonObject.get("data").toString());
......
......@@ -14,7 +14,6 @@ import androidx.coordinatorlayout.widget.ViewGroupUtils;
import com.ihaoin.hooloo.device.component.TouchDelegateComposite;
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.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.view.ConfirmOrderDialog;
......@@ -22,9 +21,7 @@ import com.ihaoin.hooloo.device.view.GoodsDetailDialog;
import com.ihaoin.hooloo.device.view.SettingsActivity;
import com.ihaoin.hooloo.device.view.TipsDialog;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Utils {
......@@ -107,30 +104,6 @@ public class Utils {
return (int) ((dp * displayMetrics.density) + 0.5f);
}
public static List<ConfirmGoods> translate(List<TrolleyGoods> trolleyGoods) {
if (CollectionUtils.isEmpty(trolleyGoods)) {
return null;
}
return trolleyGoods.stream().map(x -> {
ConfirmGoods g = new ConfirmGoods();
g.setGoodsId(x.getGoodId());
g.setSkuId(x.getSkuId());
g.setCount(x.getCount());
return g;
}).collect(Collectors.toList());
}
public static List<ConfirmGoods> translate(Goods goods, Sku sku, Integer count) {
if (goods == null || sku == null || count <= 0) {
return null;
}
ConfirmGoods g = new ConfirmGoods();
g.setGoodsId(goods.getGoodsId());
g.setSkuId(sku.getSkuId());
g.setCount(count);
return Arrays.asList(g);
}
@SuppressLint("RestrictedApi")
public static void setTouchDelegate(ViewGroup group, List<View> views, Integer dp) {
Integer px = Utils.dpToPx(group.getContext(), dp);
......
......@@ -9,6 +9,7 @@ import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -30,18 +31,23 @@ 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;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.RandomUtils;
import com.ihaoin.hooloo.device.util.SharedPreferencesUtils;
import com.ihaoin.hooloo.device.util.Utils;
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<>();
......@@ -66,11 +72,11 @@ public class ConfirmOrderDialog extends Dialog {
}
public void setGoods(List<TrolleyGoods> trolleyGoods) {
this.goods = Utils.translate(trolleyGoods);
this.goods = translate(trolleyGoods);
}
public void setGoods(Goods goods, Sku sku, Integer count) {
this.goods = Utils.translate(goods, sku, count);
this.goods = translate(goods, sku, count);
}
@Override
......@@ -149,7 +155,9 @@ public class ConfirmOrderDialog extends Dialog {
confirmOrder.setScreenNo(SharedPreferencesUtils.getScreenNo(getContext()));
confirmOrder.setSeqNo(genSeqNo());
confirmOrder.setGoods(goods);
return JSON.toJSONString(confirmOrder);
String json = JSON.toJSONString(confirmOrder);
Log.d("TEST", json);
return json;
} catch (Exception e) {
e.printStackTrace();
}
......@@ -178,6 +186,10 @@ public class ConfirmOrderDialog extends Dialog {
confirmOrderHandler.removeCallbacksAndMessages(null);
confirmOrderHandler = null;
}
if (qrCodeVisitedHandler != null) {
qrCodeVisitedHandler.removeCallbacksAndMessages(null);
qrCodeVisitedHandler = null;
}
unregsitQRCodeVisitedListener();
}
};
......@@ -323,4 +335,50 @@ public class ConfirmOrderDialog extends Dialog {
private void unregsitQRCodeVisitedListener() {
PushMessageReceiver.unsubscribe(Base.NOTIFY_ACTION_QRCODE_VISITED);
}
/** 将购物车列表按商品id分组保存 */
public List<ConfirmGoods> translate(List<TrolleyGoods> trolleyGoods) {
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;
}
public List<ConfirmGoods> translate(Goods goods, Sku sku, Integer count) {
if (goods == null || sku == null || count <= 0) {
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);
return Arrays.asList(confirmGoods);
}
}
......@@ -323,6 +323,7 @@ public class LauncherActivity extends Activity {
private TrolleyReceiver trolleyReceiver = null;
/** 注册购物车广播 */
private void registTrolleyReceiver() {
if (trolleyReceiver == null) {
trolleyReceiver = new TrolleyReceiver();
......@@ -341,6 +342,7 @@ public class LauncherActivity extends Activity {
}
}
/** 购物车操作广播接收器 */
class TrolleyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
......@@ -348,7 +350,7 @@ public class LauncherActivity extends Activity {
Goods goods = (Goods) intent.getSerializableExtra("goods");
Sku sku = (Sku) intent.getSerializableExtra("sku");
Integer count = intent.getIntExtra("count", 1);
trolleyView.addGoods(goods, sku, count);
trolleyView.prepareAddGoods(goods, sku, count);
} else if (intent.getAction().equals(Base.GOODS_CHANGED_ACTION)) {
trolleyView.goodsChanged();
} else if (intent.getAction().equals(Base.CLEAR_GOODS_ACTION)) {
......@@ -363,6 +365,7 @@ public class LauncherActivity extends Activity {
}
}
/** 显示菜单屏KDS */
private void showMenuView() {
DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = displayManager.getDisplays();
......
......@@ -22,6 +22,7 @@ import com.ihaoin.hooloo.device.adapter.TrolleyAdapter;
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.network.HttpUtil;
import com.ihaoin.hooloo.device.util.RandomUtils;
import com.ihaoin.hooloo.device.util.Utils;
......@@ -70,11 +71,26 @@ public class TrolleyView extends RelativeLayout {
butnPay.setOnClickListener(v -> showPayDialog());
}
public void addGoods(Goods goods, Sku sku, Integer count) {
if (!checkSkuState(sku.getSkuId())) {
Toast.makeText(this.getContext(), R.string.error_sku_state, Toast.LENGTH_SHORT).show();
public void prepareAddGoods(Goods goods, Sku sku, Integer count) {
Handler handler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
if (msg.what != 1) {
Toast.makeText(getContext(), ((Exception) msg.obj).getMessage(), Toast.LENGTH_SHORT).show();
return;
}
addGoods(goods, sku, count);
}
};
HttpUtil.checkSku(sku.getSkuId(), handler);
}
/** 添加商品到购物车 - 商品详情、商品列表 */
public void addGoods(Goods goods, Sku sku, Integer count) {
// if (!checkSkuState(sku.getSkuId())) {
// Toast.makeText(this.getContext(), R.string.error_sku_state, Toast.LENGTH_SHORT).show();
// return;
// }
if (getCount() >= HLApplication.getMainData().getCountOfOrder()) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return;
......@@ -106,24 +122,22 @@ public class TrolleyView extends RelativeLayout {
this.goodsChanged();
}
/** 购物车商品增加数量 */
public void addGoods(Integer position) {
// if (!checkSkuState(goods.getSkuId())) {
// Toast.makeText(this.getContext(), R.string.error_sku_state, Toast.LENGTH_SHORT).show();
// return;
// }
if (getCount() >= HLApplication.getMainData().getCountOfOrder()) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return;
}
TrolleyGoods goods = this.trolleyGoods.get(position);
if (!checkSkuState(goods.getSkuId())) {
Toast.makeText(this.getContext(), R.string.error_sku_state, Toast.LENGTH_SHORT).show();
return;
}
goods.setCount(goods.getCount() + 1);
this.goodsChanged();
}
private boolean checkSkuState(Integer skuId) {
return true;
}
/** 购物车商品减少数量 */
public void subtractGoods(Integer position) {
TrolleyGoods goods = this.trolleyGoods.get(position);
if (goods.getCount() <= 1) {
......
## 未解决事项
*****
1. 首页获取商品列表
2. 添加购物车时的SKU是否售罄校验
3. 生成二维码图片
4. 推送对接
5. 菜单屏
\ No newline at end of file
1. 菜单屏 订单状态变化推送对接
\ No newline at end of file
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