Commit 5ac25204 by wjg

增加sku状态变更通知处理

parent 0f8ff26c
package com.ihaoin.hooloo.device; package com.ihaoin.hooloo.device;
import android.app.Application; import android.app.Application;
import android.os.Handler;
import android.os.Message;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.data.MainData; import com.ihaoin.hooloo.device.data.MainData;
import com.ihaoin.hooloo.device.data.enums.OrderState;
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.network.HttpUtil;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.JsonUtils;
import com.ihaoin.hooloo.device.util.SharedPreferencesUtils; import com.ihaoin.hooloo.device.util.SharedPreferencesUtils;
import com.ihaoin.hooloo.device.util.StringUtils; import com.ihaoin.hooloo.device.util.StringUtils;
import com.umeng.commonsdk.UMConfigure; import com.umeng.commonsdk.UMConfigure;
import java.util.ArrayList;
import java.util.List;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
public class HLApplication extends Application { public class HLApplication extends Application {
...@@ -45,4 +57,5 @@ public class HLApplication extends Application { ...@@ -45,4 +57,5 @@ public class HLApplication extends Application {
public void onTerminate() { public void onTerminate() {
super.onTerminate(); super.onTerminate();
} }
} }
package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable;
import java.util.List;
public class SkuStateChangedVo implements Serializable {
/**
* 机器编码
*/
private String machineCode;
/**
* 商品id
*/
private Integer goodsId;
/**
* skuid列表
*/
private List<Integer> skuIds;
/**
* sku状态
*/
private Integer state;
public String getMachineCode() {
return machineCode;
}
public void setMachineCode(String machineCode) {
this.machineCode = machineCode;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public List<Integer> getSkuIds() {
return skuIds;
}
public void setSkuIds(List<Integer> skuIds) {
this.skuIds = skuIds;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
}
...@@ -149,6 +149,7 @@ public class ConfirmOrderDialog extends Dialog { ...@@ -149,6 +149,7 @@ public class ConfirmOrderDialog extends Dialog {
private String genJson() { private String genJson() {
try { try {
// Toast.makeText(getContext(), "屏幕编码:" + SharedPreferencesUtils.getScreenNo(getContext()), Toast.LENGTH_SHORT).show();
ConfirmOrder confirmOrder = new ConfirmOrder(); ConfirmOrder confirmOrder = new ConfirmOrder();
confirmOrder.setMachineCode(AppConfig.MACHINE_CODE); confirmOrder.setMachineCode(AppConfig.MACHINE_CODE);
confirmOrder.setScreenNo(SharedPreferencesUtils.getScreenNo(getContext())); confirmOrder.setScreenNo(SharedPreferencesUtils.getScreenNo(getContext()));
......
...@@ -429,6 +429,12 @@ public class GoodsDetailDialog extends Dialog { ...@@ -429,6 +429,12 @@ public class GoodsDetailDialog extends Dialog {
showSelloutViews(); showSelloutViews();
return; return;
} }
mGoods.getSpecs().forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getRules())) {
return;
}
spec.getRules().forEach(rule -> rule.setState(SkuState.SELLIN.getCode()));
});
// 将商品所有SKU列表按售罄和未售罄分组 // 将商品所有SKU列表按售罄和未售罄分组
Map<Integer, List<Sku>> map = mGoods.getSkus().stream().collect(Collectors.groupingBy(Sku::getState)); Map<Integer, List<Sku>> map = mGoods.getSkus().stream().collect(Collectors.groupingBy(Sku::getState));
if (CollectionUtils.isEmpty(map)) { if (CollectionUtils.isEmpty(map)) {
......
...@@ -10,6 +10,7 @@ import android.graphics.Rect; ...@@ -10,6 +10,7 @@ import android.graphics.Rect;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
...@@ -29,14 +30,17 @@ import com.ihaoin.hooloo.device.R; ...@@ -29,14 +30,17 @@ import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.GoodsAdapter; import com.ihaoin.hooloo.device.adapter.GoodsAdapter;
import com.ihaoin.hooloo.device.adapter.RecommendAdapter; import com.ihaoin.hooloo.device.adapter.RecommendAdapter;
import com.ihaoin.hooloo.device.component.NetworkHandler; import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.component.PushMessageReceiver;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.config.Base; import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.MainData; import com.ihaoin.hooloo.device.data.MainData;
import com.ihaoin.hooloo.device.data.ScrollBean; import com.ihaoin.hooloo.device.data.ScrollBean;
import com.ihaoin.hooloo.device.data.enums.SkuState;
import com.ihaoin.hooloo.device.data.vo.Category; import com.ihaoin.hooloo.device.data.vo.Category;
import com.ihaoin.hooloo.device.data.vo.Goods; import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Recommend; import com.ihaoin.hooloo.device.data.vo.Recommend;
import com.ihaoin.hooloo.device.data.vo.Sku; import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.data.vo.SkuStateChangedVo;
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.CollectionUtils;
import com.ihaoin.hooloo.device.util.JsonUtils; import com.ihaoin.hooloo.device.util.JsonUtils;
...@@ -48,6 +52,7 @@ import java.util.ArrayList; ...@@ -48,6 +52,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class LauncherActivity extends Activity { public class LauncherActivity extends Activity {
private SkuStateChangeHandler skuStateChangeHandler;
private RadioGroup groupCategory; private RadioGroup groupCategory;
private RecyclerView recGoods; private RecyclerView recGoods;
...@@ -99,6 +104,7 @@ public class LauncherActivity extends Activity { ...@@ -99,6 +104,7 @@ public class LauncherActivity extends Activity {
registTrolleyStateChangedReceiver(); registTrolleyStateChangedReceiver();
registSettingChangedReceiver(); registSettingChangedReceiver();
prepareMenuView(); prepareMenuView();
regsitSkuChangeListener();
startLoadDataThread(); startLoadDataThread();
} }
...@@ -344,6 +350,7 @@ public class LauncherActivity extends Activity { ...@@ -344,6 +350,7 @@ public class LauncherActivity extends Activity {
this.unregistTrolleyGoodsChangedReceiver(); this.unregistTrolleyGoodsChangedReceiver();
this.unregistTrolleyStateChangedReceiver(); this.unregistTrolleyStateChangedReceiver();
this.unregistSettingChangedReceiver(); this.unregistSettingChangedReceiver();
this.unregsitSkuChangeListener();
System.exit(0); System.exit(0);
} }
...@@ -505,4 +512,83 @@ public class LauncherActivity extends Activity { ...@@ -505,4 +512,83 @@ public class LauncherActivity extends Activity {
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100); requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
} }
} }
private void regsitSkuChangeListener() {
skuStateChangeHandler = new SkuStateChangeHandler();
PushMessageReceiver.subscribe(Base.PUSH_ACTION_SKU_STATE_CHANGED, skuStateChangeHandler);
}
private void unregsitSkuChangeListener() {
PushMessageReceiver.unsubscribe(Base.PUSH_ACTION_SKU_STATE_CHANGED);
}
class SkuStateChangeHandler 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;
}
MainData mainData = HLApplication.getMainData();
if (mainData == null) {
return;
}
SkuStateChangedVo stateChangedVo = JsonUtils.getMapper().readValue(msgBody, SkuStateChangedVo.class);
if (StringUtils.isEmpty(stateChangedVo.getMachineCode())) {
return;
}
if (!stateChangedVo.getMachineCode().equals(AppConfig.MACHINE_CODE)) {
return;
}
if (stateChangedVo.getGoodsId() == null || CollectionUtils.isEmpty(stateChangedVo.getSkuIds())) {
return;
}
SkuState state = SkuState.get(stateChangedVo.getState());
if (state == null) {
return;
}
if (!CollectionUtils.isEmpty(mainData.getCategorys())) {
mainData.getCategorys().forEach(category -> {
if (CollectionUtils.isEmpty(category.getGoods())) {
return;
}
category.getGoods().forEach(goods -> {
if (CollectionUtils.isEmpty(goods.getSkus())) {
return;
}
goods.getSkus().forEach(sku -> {
if (stateChangedVo.getSkuIds().contains(sku.getSkuId())) {
sku.setState(state.getCode());
}
});
});
});
}
if (!CollectionUtils.isEmpty(mainData.getRecommends())) {
mainData.getRecommends().forEach(recommend -> {
if (recommend.getGoods() == null || CollectionUtils.isEmpty(recommend.getGoods().getSkus())) {
return;
}
recommend.getGoods().getSkus().forEach(sku -> {
if (stateChangedVo.getSkuIds().contains(sku.getSkuId())) {
sku.setState(state.getCode());
}
});
});
}
mainDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} }
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