Commit d264e5f1 by wjg

init

parent 29b287db
......@@ -56,7 +56,10 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.alibaba:fastjson:2.0.2.android'
// implementation 'com.alibaba:fastjson:2.0.2.android'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.0.pr3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.0.pr3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0.pr3'
implementation 'com.aliyun.alink.linksdk:iot-linkkit:1.7.2'
implementation 'com.aliyun.alink.linksdk:public-channel-core:0.7.7.1'
......
......@@ -75,6 +75,16 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
Sku sku = getSku(goods.getSkus());
if (sku == null) {
helper.setText(R.id.txt_price, String.valueOf(goods.getPrice()));
helper.setText(R.id.txt_discount, String.valueOf(goods.getDiscount()));
helper.setGone(R.id.txt_sellout, true);
helper.setGone(R.id.butn_add, false);
} else {
helper.setText(R.id.txt_price, String.valueOf(sku.getPrice()));
helper.setText(R.id.txt_discount, String.valueOf(sku.getDiscount()));
if (Base.FALSE.equals(sku.getState())) {
helper.setGone(R.id.txt_sellout, true);
helper.setGone(R.id.butn_add, false);
} else {
......@@ -86,6 +96,7 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
ViewGroup layoutItem = helper.getView(R.id.layout_item);
Utils.setTouchDelegate(layoutItem, Arrays.asList(butnAdd), 15);
}
}
View layoutItem = helper.getView(R.id.layout_item);
layoutItem.setOnClickListener(v -> Utils.showGoodsDetail(mContext, goods));
......@@ -104,6 +115,6 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
if (optional.isPresent()) {
return optional.get();
}
return null;
return skus.get(0);
}
}
......@@ -41,21 +41,21 @@ public class OrderAdapter extends BaseAdapter {
@Override
public boolean isEmpty() {
return CollectionUtils.isEmpty(orders);
return CollectionUtils.isEmpty(getOrders());
}
@Override
public int getCount() {
return isEmpty() ? 0 : orders.size();
return isEmpty() ? 0 : getOrders().size();
}
@Override
public Object getItem(int position) {
return isEmpty() ? null : orders.get(position);
return isEmpty() ? null : getOrders().get(position);
}
@Override
public long getItemId(int position) {
return isEmpty() ? 0 : orders.get(position).getOrderId();
return isEmpty() ? 0 : getOrders().get(position).getOrderId();
}
}
package com.ihaoin.hooloo.device.component;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
......@@ -14,17 +13,13 @@ import com.ihaoin.hooloo.device.config.AppConfig;
*/
public abstract class NetworkHandler extends Handler {
private static final String TAG = "Network";
private Context mContext;
public NetworkHandler(@NonNull Context context) {
this.mContext = context;
}
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (AppConfig.DEBUG) {
String msgText = String.format("返回状态:%s, 返回内容:%s", msg.what, msg.obj);
String url = msg.getData().getString("url");
String msgText = String.format("请求:%s, 返回状态:%s, 返回内容:%s", url, msg.what, msg.obj);
Log.d(TAG, msgText);
}
if (msg == null || msg.what == 0) {
......
......@@ -16,6 +16,10 @@ public class Order implements Serializable {
* 流水号
*/
private String orderNumber;
/**
* 状态
*/
private Integer state;
public Integer getOrderId() {
return orderId;
......@@ -41,6 +45,14 @@ public class Order implements Serializable {
this.orderNumber = orderNumber;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......
package com.ihaoin.hooloo.device.data.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.math.BigDecimal;
......@@ -17,7 +17,7 @@ public class Sku implements Serializable {
/** 原价 */
private BigDecimal price;
/** 折扣价 */
@JSONField(name = "disCount")
@JsonProperty("disCount")
private BigDecimal discount;
/** SKU规格 */
private List<SkuRule> rules;
......
package com.ihaoin.hooloo.device.network;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.util.JsonUtils;
import java.io.IOException;
import java.net.NetworkInterface;
......@@ -62,44 +62,56 @@ 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);
}
// if (AppConfig.DEBUG) {
// String msgText = String.format("返回状态:%s, 请求:%s, 返回内容:%s", 0, call.request().url(), e.getMessage());
// Log.e(TAG, msgText);
// }
if (handler == null) {
return;
}
Message msg = handler.obtainMessage(0, e);
handler.sendMessage(msg);
sendHandlerMessage(0, handler, call, e);
} catch (Exception ex) {
onFailure(handler, call, e);
}
}
private static void sendHandlerMessage(Integer what, Handler handler, Call call, Object o) {
Message msg = handler.obtainMessage(what, o);
Bundle bundle = new Bundle();
bundle.putString("url", call.request().url().toString());
msg.setData(bundle);
handler.sendMessage(msg);
}
private static void onResponse(Handler handler, Call call, Response response) {
try {
String responseBody = response.body().string();
if (AppConfig.DEBUG) {
String msgText = String.format("返回状态:%s, 请求:%s, 返回内容:%s", 1, call.request().url(), responseBody);
Log.i(TAG, msgText);
}
// if (AppConfig.DEBUG) {
// String msgText = String.format("返回状态:%s, 请求:%s, 返回内容:%s", 1, call.request().url(), responseBody);
// Log.i(TAG, msgText);
// }
if (handler == null) {
return;
}
if (call.request().url().toString().contains("checkSku")) {
responseBody = "{\"msg\":\"该产品已经不存在\",\"code\":500}";
}
JSONObject jsonObject = JSON.parseObject(responseBody);
// if (call.request().url().toString().contains("checkSku")) {
// responseBody = "{\"msg\":\"该产品已经不存在\",\"code\":500}";
// }
String responseBody = response.body().string();
JsonNode jsonObject = JsonUtils.getMapper().readValue(responseBody, JsonNode.class);
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")));
if (jsonObject.get("code").asInt() != 200) {
onFailure(handler, call, new BizException(jsonObject.get("msg").asText()));
return;
}
Message msg = handler.obtainMessage(1, jsonObject.get("data") == null ? "" : jsonObject.get("data").toString());
handler.sendMessage(msg);
sendHandlerMessage(1, handler, call, jsonObject.get("data") == null ? "" : jsonObject.get("data").toString());
// Message msg = handler.obtainMessage(1, );
// Bundle bundle = new Bundle();
// bundle.putString("url", call.request().url().toString());
// msg.setData(bundle);
// handler.sendMessage(msg);
} catch (Exception e) {
onFailure(handler, call, e);
}
......
package com.ihaoin.hooloo.device.util;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonUtils {
// public static <T> T parse(String content, Class<T> valueType) {
// ObjectMapper objectMapper = new ObjectMapper();
// try {
// return objectMapper.readValue(content, valueType);
// } catch (Exception e) {
// e.printStackTrace();
// }
// return null;
// }
//
// public static <T> List<T> parseList(String content, Class<T> valueType) {
// ObjectMapper objectMapper = new ObjectMapper();
// try {
// return objectMapper.readValue(content, new TypeReference<ArrayList<T>>() {
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// return null;
// }
public static ObjectMapper getMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
}
}
......@@ -17,7 +17,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import com.alibaba.fastjson2.JSON;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
......@@ -36,6 +35,7 @@ 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.JsonUtils;
import com.ihaoin.hooloo.device.util.RandomUtils;
import com.ihaoin.hooloo.device.util.SharedPreferencesUtils;
import com.ihaoin.hooloo.device.util.Utils;
......@@ -123,7 +123,7 @@ public class ConfirmOrderDialog extends Dialog {
try {
startLoading();
confirmOrderHandler = new ConfirmOrderHandler(getContext());
confirmOrderHandler = new ConfirmOrderHandler();
HttpUtil.postConfirmOrder(genJson(), confirmOrderHandler);
} catch (Exception e) {
e.printStackTrace();
......@@ -155,7 +155,7 @@ public class ConfirmOrderDialog extends Dialog {
confirmOrder.setScreenNo(SharedPreferencesUtils.getScreenNo(getContext()));
confirmOrder.setSeqNo(genSeqNo());
confirmOrder.setGoods(goods);
String json = JSON.toJSONString(confirmOrder);
String json = JsonUtils.getMapper().writeValueAsString(confirmOrder);
Log.d("TEST", json);
return json;
} catch (Exception e) {
......@@ -262,10 +262,6 @@ public class ConfirmOrderDialog extends Dialog {
/** 服务器保存购物车信息回调 */
class ConfirmOrderHandler extends NetworkHandler {
public ConfirmOrderHandler(@NonNull Context context) {
super(context);
}
@Override
public void handleMessage(@NonNull Message msg) {
try {
......
......@@ -92,6 +92,8 @@ public class GoodsDetailDialog extends Dialog {
}
txtName.setText(goods.getName());
txtPrice.setText(String.valueOf(goods.getPrice()));
txtDiscount.setText(String.valueOf(goods.getDiscount()));
butnSubtract.setOnClickListener(v -> subtractGoods());
butnAdd.setOnClickListener(v -> addGoods());
......@@ -185,11 +187,10 @@ public class GoodsDetailDialog extends Dialog {
View v = layoutSpecs.getChildAt(i);
RadioGroup group = v.findViewById(R.id.group_spec);
RadioButton button = group.findViewById(group.getCheckedRadioButtonId());
rules.add((GoodsRule) button.getTag());
if (button == null) {
continue;
}
if (CollectionUtils.isEmpty(rules)) {
Toast.makeText(getContext(), R.string.error_choose_spec, Toast.LENGTH_LONG).show();
return;
rules.add((GoodsRule) button.getTag());
}
checkSku = matchSku(rules);
if (checkSku == null) {
......@@ -201,6 +202,9 @@ public class GoodsDetailDialog extends Dialog {
}
private Sku matchSku(List<GoodsRule> rules) {
if (CollectionUtils.isEmpty(rules)) {
return null;
}
if (CollectionUtils.isEmpty(goods.getSkus())) {
return null;
}
......@@ -267,6 +271,7 @@ public class GoodsDetailDialog extends Dialog {
layoutOperate.setVisibility(View.GONE);
layoutButns.setVisibility(View.GONE);
txtSellout.setVisibility(View.VISIBLE);
setAllRuleSellouts(); // 所有规格设置为售罄
}
private void setRuleState(SkuRule skuRule, Integer ruleState) {
......@@ -285,6 +290,18 @@ public class GoodsDetailDialog extends Dialog {
});
}
private void setAllRuleSellouts() {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) {
return;
}
goods.getSpecs().forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getRules())) {
return;
}
spec.getRules().forEach(rule -> rule.setState(Base.FALSE));
});
}
private Integer checkRuleState(SkuRule skuRule, List<Sku> sellIns) {
if (CollectionUtils.isEmpty(sellIns)) {
return Base.FALSE;
......
......@@ -5,15 +5,14 @@ import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.widget.GridView;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import com.alibaba.fastjson2.JSON;
import com.bumptech.glide.Glide;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.OrderAdapter;
......@@ -26,8 +25,10 @@ import com.ihaoin.hooloo.device.data.vo.Order;
import com.ihaoin.hooloo.device.data.vo.OrderPkg;
import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.JsonUtils;
import com.ihaoin.hooloo.device.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
......@@ -116,18 +117,26 @@ public class MenuPresentation extends Presentation {
}
private void loadDatas() {
loadOrdersHandler = new LoadOrdersHandler(getContext());
loadOrdersHandler = new LoadOrdersHandler();
HttpUtil.getOrders(loadOrdersHandler);
}
private void setDatas(String json) {
pkgs = JSON.parseArray(json, OrderPkg.class);
try {
pkgs = JsonUtils.getMapper().readValue(json, new TypeReference<List<OrderPkg>>() {
});
orderDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
private void orderDataChanged() {
cookingOrders = getOrders(OrderState.COOKING.getCode());
waitingOrders = getOrders(OrderState.WAITING.getCode());
completedOrders = getOrders(OrderState.COMPLETED.getCode());
cookingAdapter.setOrders(completedOrders);
cookingAdapter.setOrders(cookingOrders);
waitingAdapter.setOrders(waitingOrders);
completedAdapter.setOrders(completedOrders);
......@@ -160,14 +169,14 @@ public class MenuPresentation extends Presentation {
}
class LoadOrdersHandler extends NetworkHandler {
public LoadOrdersHandler(@NonNull Context context) {
super(context);
}
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what != 1) {
return;
}
String body = "[{\"state\":1,\"desc\":\"制作中\",\"orders\":[{\"orderId\":1011,\"orderNo\":\"N20220220A19231\",\"orderNumber\":\"Mon101\"},{\"orderId\":1012,\"orderNo\":\"N20220220A19232\",\"orderNumber\":\"Mon102\"},{\"orderId\":1013,\"orderNo\":\"N20220220A19233\",\"orderNumber\":\"Mon103\"}]},{\"state\":2,\"desc\":\"待制作\",\"orders\":[{\"orderId\":1014,\"orderNo\":\"N20220220A19234\",\"orderNumber\":\"Mon104\"},{\"orderId\":1015,\"orderNo\":\"N20220220A19235\",\"orderNumber\":\"Mon105\"},{\"orderId\":1016,\"orderNo\":\"N20220220A19236\",\"orderNumber\":\"Mon106\"},{\"orderId\":1017,\"orderNo\":\"N20220220A19237\",\"orderNumber\":\"Mon107\"},{\"orderId\":1018,\"orderNo\":\"N20220220A19238\",\"orderNumber\":\"Mon108\"}]},{\"state\":3,\"desc\":\"可取餐\",\"orders\":[{\"orderId\":1019,\"orderNo\":\"N20220220A19239\",\"orderNumber\":\"Mon109\"},{\"orderId\":1001,\"orderNo\":\"N20220220A19221\",\"orderNumber\":\"Mon121\"},{\"orderId\":1002,\"orderNo\":\"N20220220A19222\",\"orderNumber\":\"Mon122\"},{\"orderId\":1003,\"orderNo\":\"N20220220A19223\",\"orderNumber\":\"Mon123\"},{\"orderId\":1004,\"orderNo\":\"N20220220A19224\",\"orderNumber\":\"Mon124\"},{\"orderId\":1005,\"orderNo\":\"N20220220A19241\",\"orderNumber\":\"Mon141\"},{\"orderId\":1006,\"orderNo\":\"N20220220A19251\",\"orderNumber\":\"Mon151\"}]}]";
// setDatas(msg.obj.toString());
setDatas(body);
}
}
......@@ -175,9 +184,58 @@ public class MenuPresentation extends Presentation {
class OrderStateChangeHandler extends Handler {
@Override
public void handleMessage(@NonNull Message msg) {
try {
super.handleMessage(msg);
if (msg.obj == null) {
return;
}
String msgBody = msg.obj.toString();
if (StringUtils.isEmpty(msgBody)) {
return;
}
Order order = JsonUtils.getMapper().readValue(msgBody, Order.class);
if (order == null || order.getState() == null || order.getOrderId() == null || order.getOrderId() <= 0
|| StringUtils.isEmpty(order.getOrderNo()) || StringUtils.isEmpty(order.getOrderNumber())) {
return;
}
if (CollectionUtils.isEmpty(pkgs)) {
pkgs = new ArrayList<>();
List<Order> orders = new ArrayList<>();
orders.add(order);
OrderPkg pkg = new OrderPkg();
pkg.setState(order.getState());
pkg.setOrders(orders);
pkgs.add(pkg);
} else {
// 删除订单
pkgs.forEach(pkg -> {
if (CollectionUtils.isEmpty(pkg.getOrders())) {
return;
}
pkg.getOrders().remove(order);
});
Log.d("TEST", msg.obj.toString());
// 添加新订单状态
pkgs.forEach(pkg -> {
if (!pkg.getState().equals(order.getState())) {
return;
}
List<Order> orders = pkg.getOrders();
if (CollectionUtils.isEmpty(orders)) {
orders = new ArrayList<>();
}
orders.add(order);
pkg.setOrders(orders);
});
}
orderDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
......@@ -19,6 +19,7 @@ import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.TrolleyAdapter;
import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
......@@ -72,7 +73,7 @@ public class TrolleyView extends RelativeLayout {
}
public void prepareAddGoods(Goods goods, Sku sku, Integer count) {
Handler handler = new Handler() {
NetworkHandler handler = new NetworkHandler() {
@Override
public void handleMessage(@NonNull Message msg) {
if (msg.what != 1) {
......
......@@ -45,7 +45,7 @@
android:textColor="@color/textSecondPrimary"
android:textSize="12sp" />
<LinearLayout
android:id="@+id/layout_butn"
android:id="@+id/layout_butns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
......
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