Commit 29b287db by wjg

init

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