Browse Source

本地、云端菜谱

桌面小炒机
liup 7 months ago
parent
commit
71a1a813aa
19 changed files with 660 additions and 216 deletions
  1. +240
    -0
      app/src/main/java/com/bonait/bnframework/Model/GoodsClassifyBean.java
  2. +57
    -0
      app/src/main/java/com/bonait/bnframework/Model/ProcessValueUtil.java
  3. +8
    -7
      app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java
  4. +0
    -5
      app/src/main/java/com/bonait/bnframework/business/ConfigData.java
  5. +2
    -4
      app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
  6. +0
    -7
      app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_ATTRIBUTE.java
  7. +2
    -0
      app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_CLASSIFY.java
  8. +0
    -7
      app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_SUBATTRIBUTE.java
  9. +15
    -0
      app/src/main/java/com/bonait/bnframework/common/db/util/AttributeDBUtil.java
  10. +15
    -0
      app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeDBUtil.java
  11. +14
    -0
      app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeGroupDBUtil.java
  12. +0
    -10
      app/src/main/java/com/bonait/bnframework/common/model/mode/GoodsClassifyBean.java
  13. +9
    -33
      app/src/main/java/com/bonait/bnframework/ui/adapter/CloudGoodsAdapter.java
  14. +14
    -39
      app/src/main/java/com/bonait/bnframework/ui/adapter/LocalGoodsAdapter.java
  15. +146
    -14
      app/src/main/java/com/bonait/bnframework/ui/fragment/CloudGoodsFragment.java
  16. +60
    -29
      app/src/main/java/com/bonait/bnframework/ui/fragment/HomeFoodsFragment.java
  17. +29
    -13
      app/src/main/java/com/bonait/bnframework/ui/fragment/LocalGoodsFragment.java
  18. +43
    -0
      app/src/main/res/layout/fragment_cloud_goods.xml
  19. +6
    -48
      app/src/main/res/layout/fragment_home_foods.xml

+ 240
- 0
app/src/main/java/com/bonait/bnframework/Model/GoodsClassifyBean.java View File

@@ -0,0 +1,240 @@
package com.bonait.bnframework.Model;

import java.util.List;

/**
* @author: liup
* @description: 菜谱分类云端数据
* @date: 2024/5/9 11:19.
*/
public class GoodsClassifyBean {

private String goodsTypeId;
private String goodsTypeName;
private List<GoodsAttributeListBean> goodsAttributeList;
private List<GoodsInfoListBean> goodsInfoList;

public String getGoodsTypeId() {
return goodsTypeId;
}

public void setGoodsTypeId(String goodsTypeId) {
this.goodsTypeId = goodsTypeId;
}

public String getGoodsTypeName() {
return goodsTypeName;
}

public void setGoodsTypeName(String goodsTypeName) {
this.goodsTypeName = goodsTypeName;
}

public List<GoodsAttributeListBean> getGoodsAttributeList() {
return goodsAttributeList;
}

public void setGoodsAttributeList(List<GoodsAttributeListBean> goodsAttributeList) {
this.goodsAttributeList = goodsAttributeList;
}

public List<GoodsInfoListBean> getGoodsInfoList() {
return goodsInfoList;
}

public void setGoodsInfoList(List<GoodsInfoListBean> goodsInfoList) {
this.goodsInfoList = goodsInfoList;
}

public static class GoodsAttributeListBean {
private String goodsAttributeId;
private String goodsAttributeName;
private List<GoodsAttributeValueListBean> goodsAttributeValueList;

public String getGoodsAttributeId() {
return goodsAttributeId;
}

public void setGoodsAttributeId(String goodsAttributeId) {
this.goodsAttributeId = goodsAttributeId;
}

public String getGoodsAttributeName() {
return goodsAttributeName;
}

public void setGoodsAttributeName(String goodsAttributeName) {
this.goodsAttributeName = goodsAttributeName;
}

public List<GoodsAttributeValueListBean> getGoodsAttributeValueList() {
return goodsAttributeValueList;
}

public void setGoodsAttributeValueList(List<GoodsAttributeValueListBean> goodsAttributeValueList) {
this.goodsAttributeValueList = goodsAttributeValueList;
}

public static class GoodsAttributeValueListBean {
private String goodsAttributeId;
private String goodsAttributeValueId;
private String attributeValue;

public String getGoodsAttributeId() {
return goodsAttributeId;
}

public void setGoodsAttributeId(String goodsAttributeId) {
this.goodsAttributeId = goodsAttributeId;
}

public String getGoodsAttributeValueId() {
return goodsAttributeValueId;
}

public void setGoodsAttributeValueId(String goodsAttributeValueId) {
this.goodsAttributeValueId = goodsAttributeValueId;
}

public String getAttributeValue() {
return attributeValue;
}

public void setAttributeValue(String attributeValue) {
this.attributeValue = attributeValue;
}
}
}

public static class GoodsInfoListBean {
private String goodsId;
private String goodsName;
private List<GoodsTechnologyActionListBean> goodsTechnologyActionList;

public String getGoodsId() {
return goodsId;
}

public void setGoodsId(String goodsId) {
this.goodsId = goodsId;
}

public String getGoodsName() {
return goodsName;
}

public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}

public List<GoodsTechnologyActionListBean> getGoodsTechnologyActionList() {
return goodsTechnologyActionList;
}

public void setGoodsTechnologyActionList(List<GoodsTechnologyActionListBean> goodsTechnologyActionList) {
this.goodsTechnologyActionList = goodsTechnologyActionList;
}

public static class GoodsTechnologyActionListBean {
/**
* 工序名称
*/
private String stepName;
/**
* 工序参数
*/
private String actionJson;
/**
* 子属性组合
*/
private String goodsAttributeId;
private boolean isBatch;
private String chnologyId;
private String groupId;
private int sort;
private String goodsId;
private String deviceId;
private String warehousrTemplateId;

public String getStepName() {
return stepName;
}

public void setStepName(String stepName) {
this.stepName = stepName;
}

public String getActionJson() {
return actionJson;
}

public void setActionJson(String actionJson) {
this.actionJson = actionJson;
}

public String getGoodsAttributeId() {
return goodsAttributeId;
}

public void setGoodsAttributeId(String goodsAttributeId) {
this.goodsAttributeId = goodsAttributeId;
}

public boolean isIsBatch() {
return isBatch;
}

public void setIsBatch(boolean isBatch) {
this.isBatch = isBatch;
}

public String getChnologyId() {
return chnologyId;
}

public void setChnologyId(String chnologyId) {
this.chnologyId = chnologyId;
}

public String getGroupId() {
return groupId;
}

public void setGroupId(String groupId) {
this.groupId = groupId;
}

public int getSort() {
return sort;
}

public void setSort(int sort) {
this.sort = sort;
}

public String getGoodsId() {
return goodsId;
}

public void setGoodsId(String goodsId) {
this.goodsId = goodsId;
}

public String getDeviceId() {
return deviceId;
}

public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}

public String getWarehousrTemplateId() {
return warehousrTemplateId;
}

public void setWarehousrTemplateId(String warehousrTemplateId) {
this.warehousrTemplateId = warehousrTemplateId;
}
}
}
}

+ 57
- 0
app/src/main/java/com/bonait/bnframework/Model/ProcessValueUtil.java View File

@@ -0,0 +1,57 @@
package com.bonait.bnframework.Model;

import com.apkfuns.logutils.LogUtils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;

/**
* @author: liup
* @description:
* @date: 2024/5/9 16:57.
*/
public class ProcessValueUtil {

public static String dealProcessJsonToValue(String json){
StringBuilder stringBuffer = new StringBuilder();
try{
JSONArray array = new JSONArray(json);
for (int i =0 ;i<array.length();i++){
HashMap<String,String> map = new HashMap<>();
JSONObject dataJson = array.getJSONObject(i);
if(!dataJson.optString("actionName").equals("执行步骤")){
stringBuffer.append(dataJson.optString("actionName")).append(",").append(dataJson.optString("actionValue")).append("|");
}
}
if(stringBuffer.length()>0){
stringBuffer.deleteCharAt(stringBuffer.length()-1);

}

}catch (Exception e){
e.printStackTrace();
}
LogUtils.d("ProcessValueUtil dealProcessJsonToValue json="+json);
LogUtils.d("ProcessValueUtil dealProcessJsonToValue stringBuffer="+stringBuffer.toString());
return stringBuffer.toString();
}

public static HashMap<String,String> dealProcessValueToJson(String value){
HashMap<String,String> map = new HashMap<>();
if (value.contains("|")) {
String[] res = value.split("[|]");
for (String re : res) {
if (re != null && re.contains(",")) {
String[] process = re.split("[,]");
if (process.length > 1) {
map.put("actionName", process[0]);
map.put("actionValue", process[1]);
}
}
}
}
return map;
}
}

+ 8
- 7
app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java View File

@@ -1,7 +1,5 @@
package com.bonait.bnframework.ViewModel.ActivityViewModel;

import androidx.viewpager.widget.ViewPager;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
@@ -9,12 +7,16 @@ import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.HBL.Logs.MessageLog;
import com.bonait.bnframework.HBL.Thread.IThread;
import com.bonait.bnframework.HBL.Thread.ThreadManager;
import com.bonait.bnframework.R;
import com.bonait.bnframework.Service.ModbusHelper;
import com.bonait.bnframework.ViewModel.Adapter.FragmentAdapter;
import com.bonait.bnframework.ViewModel.FragmentViewModel.Home4Fragment;
import com.bonait.bnframework.ViewModel.FragmentViewModel.HomeDeviceFragment;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.business.ExecuteTheRecipe;
@@ -22,8 +24,8 @@ import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.MessageName;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_OLD;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_OLD;
import com.bonait.bnframework.common.helper.CountDownTimerExt;
import com.bonait.bnframework.common.helper.I.MyClickListener;
import com.bonait.bnframework.common.message.MessageLooper;
@@ -32,9 +34,7 @@ import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.common.view.BottomNavigationBar;
import com.bonait.bnframework.manager.ActivityLifecycleManager;
import com.bonait.bnframework.ViewModel.Adapter.FragmentAdapter;
import com.bonait.bnframework.ViewModel.FragmentViewModel.Home4Fragment;
import com.bonait.bnframework.ViewModel.FragmentViewModel.HomeFragmentPR;
import com.bonait.bnframework.ui.fragment.HomeFoodsFragment;
import com.lzy.okgo.OkGo;
import com.qmuiteam.qmui.widget.QMUIViewPager;

@@ -124,7 +124,8 @@ public class BottomNavigationNewActivity extends BaseActivity {
*/
private void initFragment() {
FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager());
fragmentAdapter.addFragment(new HomeFragmentPR());
fragmentAdapter.addFragment(new HomeFoodsFragment());
// fragmentAdapter.addFragment(new HomeFragmentPR());
fragmentAdapter.addFragment(new Home4Fragment());
// fragmentAdapter.addFragment(new HomeFragmentSBKZ());
fragmentAdapter.addFragment(new HomeDeviceFragment());


+ 0
- 5
app/src/main/java/com/bonait/bnframework/business/ConfigData.java View File

@@ -526,11 +526,6 @@ public class ConfigData {
}
}

/**
* 获取所有商品信息
*/


/**
* 获取商品配方信息
*


+ 2
- 4
app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java View File

@@ -3,23 +3,20 @@ package com.bonait.bnframework.common.constant;
import android.app.Application;
import android.content.Context;

import com.bonait.bnframework.Model.GoodsClassifyBean;
import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS;
import com.bonait.bnframework.common.db.res.StatusMode;
import com.bonait.bnframework.common.model.AddrType;
import com.bonait.bnframework.common.model.mode.CloudGood;
import com.bonait.bnframework.common.model.mode.DeviceInformation;
import com.bonait.bnframework.common.model.mode.OrganizeMode;
import com.bonait.bnframework.common.model.mode.ProcessT;
import com.bonait.bnframework.common.model.mode.ResALLData;
import com.bonait.bnframework.common.model.mode.VersionSelectionEnum;
import com.bonait.bnframework.common.utils.ScreenUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -1030,6 +1027,7 @@ public class ConfigName {
* 云端商品
*/
public List<CloudGood> cloudGoods = new ArrayList<>();
public List<GoodsClassifyBean> cloudGoodsList = new ArrayList<>();
//endregion

//region 选配版本信息


+ 0
- 7
app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_ATTRIBUTE.java View File

@@ -19,13 +19,6 @@ public class BPA_ATTRIBUTE extends ModeBase {
*/
public String name;

public BPA_ATTRIBUTE(String name,String id){
this.name = name;
this.id = id;
}

public BPA_ATTRIBUTE(){}


@Override
public String toString() {


+ 2
- 0
app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_GOODS_CLASSIFY.java View File

@@ -15,6 +15,8 @@ public class BPA_GOODS_CLASSIFY extends ModeBase{
*/
public int state;



@Override
public String toString() {
return "BPA_GOODS_CLASSIFY{" +


+ 0
- 7
app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_SUBATTRIBUTE.java View File

@@ -24,13 +24,6 @@ public class BPA_SUBATTRIBUTE extends ModeBase {
*/
public String foreignId;

public BPA_SUBATTRIBUTE(String name, String parentAttributeId){
this.name = name;
this.parentAttributeId = parentAttributeId;
}

public BPA_SUBATTRIBUTE(){
}

@Override
public String toString() {


+ 15
- 0
app/src/main/java/com/bonait/bnframework/common/db/util/AttributeDBUtil.java View File

@@ -97,5 +97,20 @@ public class AttributeDBUtil {
return data;
}

/**
* 判断分类下的属性是否存在
* @param classifyId
* @param name
* @return
*/
public static boolean isExist(String classifyId,String name){
for(BPA_ATTRIBUTE attribute : getByClassify(classifyId)){
if(attribute.name.equals(name)){
return true;
}
}
return false;
}


}

+ 15
- 0
app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeDBUtil.java View File

@@ -80,4 +80,19 @@ public class SubAttributeDBUtil {

return data;
}

/**
* 判断子属性是否存在
* @param parentAttributeId
* @param name
* @return
*/
public static boolean isExist(String parentAttributeId,String name){
for(BPA_SUBATTRIBUTE subattribute : getByParentAttributeId(parentAttributeId)){
if(subattribute.name.equals(name)){
return true;
}
}
return false;
}
}

+ 14
- 0
app/src/main/java/com/bonait/bnframework/common/db/util/SubAttributeGroupDBUtil.java View File

@@ -133,4 +133,18 @@ public class SubAttributeGroupDBUtil {
update(bean);
}
}
/**
* 判断子属性组合是否存在
* @param goodsId
* @param name
* @return
*/
public static boolean isExist(String goodsId,String name){
for(BPA_GOODS_SUBATTRIBUTE_GROUP subattribute : getByGoodsId(goodsId)){
if(subattribute.name.equals(name)){
return true;
}
}
return false;
}
}

+ 0
- 10
app/src/main/java/com/bonait/bnframework/common/model/mode/GoodsClassifyBean.java View File

@@ -1,10 +0,0 @@
package com.bonait.bnframework.common.model.mode;

/**
* @author: liup
* @description:
* @date: 2024/5/9 11:19.
*/
public class GoodsClassifyBean {

}

+ 9
- 33
app/src/main/java/com/bonait/bnframework/ui/adapter/CloudGoodsAdapter.java View File

@@ -1,7 +1,6 @@
package com.bonait.bnframework.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -10,35 +9,20 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.common.base.BaseAdapter;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.glide.GlideUtil;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.databinding.ItemCloudGoodsBinding;

import java.util.ArrayList;

/**
* @author: liup
* @description: 商品列表
* @date: 2024/5/8 15:36.
*/
public class CloudGoodsAdapter extends RecyclerView.Adapter<CloudGoodsAdapter.GoodsViewHolder> {
private Context context;

private ArrayList<BPA_GOODS> dataList;
public abstract class CloudGoodsAdapter extends BaseAdapter<BPA_GOODS,CloudGoodsAdapter.GoodsViewHolder> {

/**
* 点击事件
*/
public GoodsOnClickListener mListener = null;

public CloudGoodsAdapter(Context context, int type, ArrayList<BPA_GOODS> data, GoodsOnClickListener _mListener) {
this.context = context;
dataList = data;
mListener = _mListener;
}

@NonNull
@Override
@@ -52,7 +36,7 @@ public class CloudGoodsAdapter extends RecyclerView.Adapter<CloudGoodsAdapter.Go
DisplayManager.scaleViewGroup(holder.binding.getRoot());
holder.binding.add.setVisibility(View.GONE);

BPA_GOODS goods = dataList.get(position);
BPA_GOODS goods = mData.get(position);
holder.binding.name.setText(goods.name);
//设置图片
String url = goods.url;
@@ -73,8 +57,10 @@ public class CloudGoodsAdapter extends RecyclerView.Adapter<CloudGoodsAdapter.Go
holder.binding.downLoad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ConfigData.getInstance().GetGoodProcess(holder.itemView.getContext(), goods.id, true);
holder.binding.downLoad.setVisibility(View.GONE);
if(downLoadGoods(view,position)){
ToastUtils.info("下载成功");
holder.binding.downLoad.setVisibility(View.GONE);
}
}
});

@@ -85,10 +71,7 @@ public class CloudGoodsAdapter extends RecyclerView.Adapter<CloudGoodsAdapter.Go
if (!goods.isLocal) {
ToastUtils.warning("请先下载该商品!");
} else {
if (mListener!=null)
{
mListener.jumpGoods(position, goods);
}
onItemClick(view,position);
}
}
});
@@ -97,11 +80,6 @@ public class CloudGoodsAdapter extends RecyclerView.Adapter<CloudGoodsAdapter.Go
}
}

@Override
public int getItemCount() {
return dataList.size();
}

public static class GoodsViewHolder extends RecyclerView.ViewHolder {
private ItemCloudGoodsBinding binding;

@@ -112,9 +90,7 @@ public class CloudGoodsAdapter extends RecyclerView.Adapter<CloudGoodsAdapter.Go
}
}

public interface GoodsOnClickListener{
void jumpGoods(int position,BPA_GOODS bean);
}
protected abstract boolean downLoadGoods(View v, int position);
}



+ 14
- 39
app/src/main/java/com/bonait/bnframework/ui/adapter/LocalGoodsAdapter.java View File

@@ -1,7 +1,6 @@
package com.bonait.bnframework.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -10,35 +9,19 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.common.base.BaseAdapter;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.glide.GlideUtil;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.ItemLocalGoodsBinding;

import java.util.ArrayList;

/**
* @author: liup
* @description: 商品列表
* @date: 2024/5/8 15:36.
*/
public class LocalGoodsAdapter extends RecyclerView.Adapter<LocalGoodsAdapter.GoodsViewHolder> {
private Context context;

private ArrayList<BPA_GOODS> dataList;

/**
* 点击事件
*/
public GoodsOnClickListener mListener = null;

public LocalGoodsAdapter(Context context, int type, ArrayList<BPA_GOODS> data, GoodsOnClickListener _mListener) {
this.context = context;
dataList = data;
mListener = _mListener;
}
public abstract class LocalGoodsAdapter extends BaseAdapter<BPA_GOODS,LocalGoodsAdapter.GoodsViewHolder> {

@NonNull
@Override
@@ -57,19 +40,17 @@ public class LocalGoodsAdapter extends RecyclerView.Adapter<LocalGoodsAdapter.Go
holder.binding.edit.setVisibility(View.GONE);
}

if(position == dataList.size()-1&&!ConfigName.getInstance().user.name.equals("一般用户")){
if(position == mData.size()-1&&!ConfigName.getInstance().user.name.equals("一般用户")){
holder.binding.add.setVisibility(View.VISIBLE);
holder.binding.add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mListener!=null){
mListener.addGoods();
}
addGoods();
}
});
return;
}
BPA_GOODS goods = dataList.get(position);
BPA_GOODS goods = mData.get(position);
holder.binding.name.setText(goods.name);
//设置图片
String url = goods.url;
@@ -83,7 +64,8 @@ public class LocalGoodsAdapter extends RecyclerView.Adapter<LocalGoodsAdapter.Go
holder.binding.upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ConfigData.getInstance().UploadGoods(holder.itemView.getContext(), goods.id);
// ConfigData.getInstance().UploadGoods(holder.itemView.getContext(), goods.id);
uploadGoods(view,position);
}
});

@@ -91,9 +73,7 @@ public class LocalGoodsAdapter extends RecyclerView.Adapter<LocalGoodsAdapter.Go
holder.binding.delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mListener != null) {
mListener.deleteGoods(position, goods);
}
deleteGoods(view,position);
}
});

@@ -101,10 +81,7 @@ public class LocalGoodsAdapter extends RecyclerView.Adapter<LocalGoodsAdapter.Go
holder.binding.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mListener!=null)
{
mListener.jumpGoods(position, goods);
}
onItemClick(view,position);
}
});
} catch (Exception e) {
@@ -115,9 +92,9 @@ public class LocalGoodsAdapter extends RecyclerView.Adapter<LocalGoodsAdapter.Go
@Override
public int getItemCount() {
if(!ConfigName.getInstance().user.name.equals("一般用户")){
return dataList.size()+1;
return mData.size()+1;
}
return dataList.size();
return mData.size();
}

public static class GoodsViewHolder extends RecyclerView.ViewHolder {
@@ -130,11 +107,9 @@ public class LocalGoodsAdapter extends RecyclerView.Adapter<LocalGoodsAdapter.Go
}
}

public interface GoodsOnClickListener{
void addGoods();
void deleteGoods(int position,BPA_GOODS bean);
void jumpGoods(int position,BPA_GOODS bean);
}
protected abstract void uploadGoods(View v, int position);
protected abstract void deleteGoods(View v, int position);
protected abstract void addGoods();
}



+ 146
- 14
app/src/main/java/com/bonait/bnframework/ui/fragment/CloudGoodsFragment.java View File

@@ -13,19 +13,32 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.Model.GoodsClassifyBean;
import com.bonait.bnframework.Model.ProcessValueUtil;
import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.mode.BPA_ATTRIBUTE;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_CLASSIFY;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_SUBATTRIBUTE_GROUP;
import com.bonait.bnframework.common.db.mode.BPA_SUBATTRIBUTE;
import com.bonait.bnframework.common.db.util.AttributeDBUtil;
import com.bonait.bnframework.common.db.util.GoodsClassifyDBUtil;
import com.bonait.bnframework.common.db.util.GoodsDBUtil;
import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil;
import com.bonait.bnframework.common.db.util.SubAttributeDBUtil;
import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.databinding.FragmentLocalGoodsBinding;
import com.bonait.bnframework.ui.activity.EditClassifyActivity;
import com.bonait.bnframework.ui.adapter.ClassifyAdapter;
import com.bonait.bnframework.ui.adapter.CloudGoodsAdapter;

import java.util.ArrayList;
import java.util.List;

/**
* @author: liup
@@ -47,9 +60,7 @@ public class CloudGoodsFragment extends BaseFragment {
super.handleMessage(msg);
switch (msg.what){
case MSG_FRESH_GOODS:
goodsList.clear();
goodsList.addAll(GoodsDBUtil.getByClassifyId(classifyList.get(classifyAdapter.getCurrentPosition()).id));
goodsAdapter.notifyDataSetChanged();
dealGoodsData(classifyAdapter.getCurrentPosition());
break;
}
}
@@ -57,7 +68,7 @@ public class CloudGoodsFragment extends BaseFragment {

@Override
protected View onCreateView() {
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_local_goods, null);
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_cloud_goods, null);
viewBinding = FragmentLocalGoodsBinding.bind(root);
return root;
}
@@ -77,13 +88,18 @@ public class CloudGoodsFragment extends BaseFragment {
OpenActivity(EditClassifyActivity.class);
});

goodsAdapter = new CloudGoodsAdapter(context, 2, goodsList, new CloudGoodsAdapter.GoodsOnClickListener() {
goodsAdapter = new CloudGoodsAdapter(){

@Override
public void jumpGoods(int position, BPA_GOODS bean) {
protected void onItemClick(View v, int position) {

}
});

@Override
protected boolean downLoadGoods(View v, int position) {
return downLoadCloudGoods(position);
}
};
viewBinding.recyclerGoods.setAdapter(goodsAdapter);

classifyAdapter =new ClassifyAdapter() {
@@ -91,7 +107,7 @@ public class CloudGoodsFragment extends BaseFragment {
protected void onItemClick(View v, int position) {
LogUtils.d("分类列表点击 position="+position+" name = "+mData.get(position).name);
handler.removeMessages(MSG_FRESH_GOODS);
handler.sendEmptyMessageDelayed(MSG_FRESH_GOODS,500L);//避免快速点击
handler.sendEmptyMessageDelayed(MSG_FRESH_GOODS,200L);//避免快速点击
}
};
viewBinding.recyclerClassify.setAdapter(classifyAdapter);
@@ -100,18 +116,40 @@ public class CloudGoodsFragment extends BaseFragment {
/**
* 初始化数据加载
*/
@SuppressLint("NotifyDataSetChanged")
public void updateData() {
goodsList.clear();
dealClassifyData();
dealGoodsData(0);
}

private void dealClassifyData(){
classifyList.clear();
classifyList.addAll(GoodsClassifyDBUtil.getAll());
if(!classifyList.isEmpty()){
goodsList.addAll(GoodsDBUtil.getByClassifyId(classifyList.get(0).id));
for (GoodsClassifyBean bean : ConfigName.getInstance().cloudGoodsList){
BPA_GOODS_CLASSIFY goodsClassify = new BPA_GOODS_CLASSIFY();
goodsClassify.id = bean.getGoodsTypeId();
goodsClassify.name = bean.getGoodsTypeName();
classifyList.add(goodsClassify);
}
classifyAdapter.setNewData(classifyList);
goodsAdapter.notifyDataSetChanged();
}

private void dealGoodsData(int position){
goodsList.clear();
if(!classifyList.isEmpty()){
String goodsId = classifyList.get(position).id;
for (GoodsClassifyBean bean : ConfigName.getInstance().cloudGoodsList){
if(goodsId.equals(bean.getGoodsTypeId())){
for(GoodsClassifyBean.GoodsInfoListBean goodsInfoListBean: bean.getGoodsInfoList() ){
BPA_GOODS goods = new BPA_GOODS();
goods.name = goodsInfoListBean.getGoodsName();
goods.id = goodsInfoListBean.getGoodsId();
goodsList.add(goods);
}
break;
}
}
}
goodsAdapter.notifyDataSetChanged();
}

@Override
public void onDestroy() {
@@ -131,4 +169,98 @@ public class CloudGoodsFragment extends BaseFragment {
handler = null;
}
}

/**
* 下载商品
* 同步分类 商品 属性 子属性 工序
* @param pos
* @return
*/
private boolean downLoadCloudGoods(int pos){
BPA_GOODS goods = goodsAdapter.getData().get(pos);
BPA_GOODS_CLASSIFY goodsClassify = classifyAdapter.getData().get(classifyAdapter.getCurrentPosition());
if(GoodsDBUtil.getById(goods.id)!=null){
ToastUtils.warning("请勿重复下载,本地商品已存在!!!");
return false;
}else {
//商品不存在情况
//判断分类是否存在
if(GoodsClassifyDBUtil.getByName(goodsClassify.name)==null){
GoodsClassifyDBUtil.add(goodsClassify);
}
//添加商品
GoodsDBUtil.add(goods);
//添加属性
for (GoodsClassifyBean bean : ConfigName.getInstance().cloudGoodsList){
if(goodsClassify.id.equals(bean.getGoodsTypeId())){
for(GoodsClassifyBean.GoodsAttributeListBean goodsAttributeListBean: bean.getGoodsAttributeList() ){
//判断是否已有属性 不存在则添加
if(!AttributeDBUtil.isExist(goodsClassify.id,goodsAttributeListBean.getGoodsAttributeName())){
BPA_ATTRIBUTE attribute = new BPA_ATTRIBUTE();
attribute.name = goodsAttributeListBean.getGoodsAttributeName();
attribute.id = goodsAttributeListBean.getGoodsAttributeId();
attribute.classifyId = goodsClassify.id;
AttributeDBUtil.add(attribute);
LogUtils.d(" 添加属性 成功"+goodsAttributeListBean.getGoodsAttributeName());
}else {
LogUtils.d(" 已存在属性 "+goodsAttributeListBean.getGoodsAttributeName());
}
//添加子属性
for(GoodsClassifyBean.GoodsAttributeListBean.GoodsAttributeValueListBean goodsAttributeValueListBean :goodsAttributeListBean.getGoodsAttributeValueList() ){
//判断是否已有子属性 不存在则添加
if(!SubAttributeDBUtil.isExist(goodsAttributeListBean.getGoodsAttributeId(),goodsAttributeValueListBean.getAttributeValue())){
BPA_SUBATTRIBUTE subattribute = new BPA_SUBATTRIBUTE();
subattribute.parentAttributeId = goodsAttributeListBean.getGoodsAttributeId();
subattribute.name = goodsAttributeValueListBean.getAttributeValue();
subattribute.id = goodsAttributeValueListBean.getGoodsAttributeValueId();
SubAttributeDBUtil.add(subattribute);
LogUtils.d(" 添加子属性 成功"+goodsAttributeValueListBean.getAttributeValue());
}else {
LogUtils.d(" 已存在子属性 "+goodsAttributeValueListBean.getAttributeValue());
}
}



}
for(GoodsClassifyBean.GoodsInfoListBean goodsInfoListBean: bean.getGoodsInfoList() ){
if(goodsInfoListBean.getGoodsName().equals(goods.name)){
List<String> groupList = new ArrayList<>();
GoodsProcessDetailDBUtil.deleteByGoodsId(goods.id);
for (GoodsClassifyBean.GoodsInfoListBean.GoodsTechnologyActionListBean goodsTechnologyActionListBean:goodsInfoListBean.getGoodsTechnologyActionList()){
//添加子属性组合
//TODO 需确定getGoodsAttributeId 是用id列表还是name组合 app上新增的id和云端的肯定不匹配 建议用name组合
if(!groupList.contains(goodsTechnologyActionListBean.getGoodsAttributeId())){
if(!SubAttributeGroupDBUtil.isExist(goods.id,goodsTechnologyActionListBean.getGoodsAttributeId())){
BPA_GOODS_SUBATTRIBUTE_GROUP group = new BPA_GOODS_SUBATTRIBUTE_GROUP();
group.name = goodsTechnologyActionListBean.getGoodsAttributeId();
group.id = goodsTechnologyActionListBean.getGoodsAttributeId();
group.goodsId = goods.id;
groupList.add(goodsTechnologyActionListBean.getGoodsAttributeId());
SubAttributeGroupDBUtil.add(group);
}
}
BPA_GOODS_PROCESS_DETAIL processDetail = new BPA_GOODS_PROCESS_DETAIL();
processDetail.goodsSubAttributeGroupId = goodsTechnologyActionListBean.getGoodsAttributeId();
processDetail.materialType = goodsTechnologyActionListBean.getStepName().contains("液体")?0:1;
String value = ProcessValueUtil.dealProcessJsonToValue(goodsTechnologyActionListBean.getActionJson());
processDetail.processms = "";
processDetail.processname = goodsTechnologyActionListBean.getStepName();
processDetail.processvalue = value;
GoodsProcessDetailDBUtil.add(processDetail);

}
}
break;
}
break;
}
}

//添加所有工序
}
return true;
}


}

+ 60
- 29
app/src/main/java/com/bonait/bnframework/ui/fragment/HomeFoodsFragment.java View File

@@ -12,17 +12,24 @@ import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.Model.GoodsClassifyBean;
import com.bonait.bnframework.R;
import com.bonait.bnframework.Service.ModbusHelper;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback;
import com.bonait.bnframework.common.message.MessageManager;
import com.bonait.bnframework.common.model.ResListAPI;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.databinding.FragmentHomeFoodsBinding;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.Response;
import com.orhanobut.logger.Logger;

import butterknife.ButterKnife;
@@ -36,8 +43,7 @@ import butterknife.OnClick;
public class HomeFoodsFragment extends BaseFragment {
private static final String TAG = "HomeFoodsFragment==> ";
private FragmentHomeFoodsBinding viewBinding;


private BaseFragment fragment;
/**
* 选中行
*/
@@ -80,6 +86,7 @@ public class HomeFoodsFragment extends BaseFragment {
DisplayManager.scaleViewGroup(viewBinding.getRoot());
initTopBar();
SelectTab(1);
requestData();
}

/**
@@ -91,22 +98,6 @@ public class HomeFoodsFragment extends BaseFragment {
viewBinding.topbar.addRightTextButton("设备状态:"+ (ModbusHelper.get().getConnected() ? "已连接" : "未连接"),R.id.status_image);
handler.sendEmptyMessageDelayed(1,1000L);

viewBinding.searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}

@Override
public boolean onQueryTextChange(String s) {
initData();
return false;
}
});
}

private void initView(){

}

/**
@@ -116,6 +107,47 @@ public class HomeFoodsFragment extends BaseFragment {

}

private void requestData(){
if (NetworkUtils.checkNetworkAvailable(context)) {
if(ConfigName.getInstance().cloudGoodsList.isEmpty()){
//TODO 对接后台接口
if (ConfigName.getInstance().organizeMode == null) {
return;
}
ToastUtils.info("正在请求云端数据");
OkGo.<ResListAPI<GoodsClassifyBean>>get(String.format(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetGoods,
ConfigName.getInstance().organizeMode.id, ConfigName.getInstance().DeviceId))
.tag(context)
.headers(new HttpHeaders("TenantId", ConfigName.getInstance().organizeMode.companyId))
.execute(new JsonDialogCallback<ResListAPI<GoodsClassifyBean>>(context) {
@Override
public void onSuccess(Response<ResListAPI<GoodsClassifyBean>> response) {
ResListAPI<GoodsClassifyBean> allDataResAPI = response.body();

if (allDataResAPI.succeeded && allDataResAPI.data != null && allDataResAPI.data.size() > 0) {
ConfigName.getInstance().cloudGoodsList.clear();
ConfigName.getInstance().cloudGoodsList.addAll(allDataResAPI.data);
}
if(handler!=null){
handler.post(new Runnable() {
@Override
public void run() {
if(fragment!=null){
if(fragment instanceof CloudGoodsFragment){
((CloudGoodsFragment) fragment).updateData();
}
}
}
});
}
}
});
}
} else {
ToastUtils.warning("无网络,请先连接网络!!!");
}
}

/**
* 点击事件
*
@@ -131,11 +163,8 @@ public class HomeFoodsFragment extends BaseFragment {
case R.id.cloudFoods:
LogUtils.d("//////2");
SelectTab(2);
requestData();
break;
// case R.id.search_view:
// search_view.setIconifiedByDefault(false);
// search_view.requestFocus();
// break;
}
}

@@ -146,19 +175,21 @@ public class HomeFoodsFragment extends BaseFragment {
*/
public void SelectTab(int index) {
SelectIndex = index;
if(index == 1){
fragment = new LocalGoodsFragment();
}else {
fragment = new CloudGoodsFragment();
}
getChildFragmentManager().beginTransaction()
.replace(R.id.frame, fragment)
.commit();
switch (index) {
case 1:
if(ConfigName.getInstance().user.name.equals("一般用户")){
viewBinding.addClassify.setVisibility(View.GONE);
}else {
viewBinding.addClassify.setVisibility(View.VISIBLE);
}
viewBinding.localFoods.setTextColor(Color.parseColor("#BEAA6A"));
viewBinding.cloudFoods.setTextColor(Color.parseColor("#797373"));
initData();
break;
case 2:
viewBinding.addClassify.setVisibility(View.GONE);
viewBinding.localFoods.setTextColor(Color.parseColor("#797373"));
viewBinding.cloudFoods.setTextColor(Color.parseColor("#BEAA6A"));
initData();


+ 29
- 13
app/src/main/java/com/bonait/bnframework/ui/fragment/LocalGoodsFragment.java View File

@@ -18,6 +18,7 @@ import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_CLASSIFY;
import com.bonait.bnframework.common.db.util.GoodsClassifyDBUtil;
import com.bonait.bnframework.common.db.util.GoodsDBUtil;
import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil;
import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil;
@@ -82,15 +83,21 @@ public class LocalGoodsFragment extends BaseFragment {
OpenActivity(EditClassifyActivity.class);
});

goodsAdapter = new LocalGoodsAdapter(context, 1, goodsList, new LocalGoodsAdapter.GoodsOnClickListener() {
goodsAdapter = new LocalGoodsAdapter(){

@Override
protected void onItemClick(View v, int position) {

}

@Override
public void addGoods() {
//添加菜品弹窗
protected void uploadGoods(View v, int position) {
}

@Override
public void deleteGoods(int position, BPA_GOODS bean) {
protected void deleteGoods(View v, int position) {
AlertDialogUtils.showCancelAndConfirmDialog((AppCompatActivity) getActivity(), R.layout.dialog_delete_classify, (layoutView, xCom) -> {
BPA_GOODS bean = mData.get(position);
DialogDeleteClassifyBinding binding = DialogDeleteClassifyBinding.bind(layoutView);
DisplayManager.scaleViewGroup(binding.getRoot());
binding.title.setText("删除菜品");
@@ -111,10 +118,9 @@ public class LocalGoodsFragment extends BaseFragment {
}

@Override
public void jumpGoods(int position, BPA_GOODS bean) {
//弹窗 fragmentdialog
protected void addGoods() {
}
});
};
viewBinding.recyclerGoods.setAdapter(goodsAdapter);

classifyAdapter =new ClassifyAdapter() {
@@ -136,21 +142,31 @@ public class LocalGoodsFragment extends BaseFragment {
goodsList.clear();
classifyList.clear();


// classifyList.addAll(GoodsClassifyDBUtil.getAll());
// if(!classifyList.isEmpty()){
// goodsList.addAll(GoodsDBUtil.getByClassifyId(classifyList.get(0).id));
// }

classifyList.addAll(GoodsClassifyDBUtil.getAll());
if(!classifyList.isEmpty()){
goodsList.addAll(GoodsDBUtil.getByClassifyId(classifyList.get(0).id));
}

classifyAdapter.setNewData(classifyList);
goodsAdapter.notifyDataSetChanged();
}

@Override
public void onPause() {
super.onPause();
LogUtils.d("LocalGoodsFragment onPause");
}

@Override
public void onResume() {
super.onResume();
LogUtils.d("LocalGoodsFragment onResume");
}

@Override
public void onDestroy() {
super.onDestroy();
LogUtils.d("LocalGoodsFragment onDestroy");
if(goodsList!=null){
goodsList.clear();
classifyList.clear();


+ 43
- 0
app/src/main/res/layout/fragment_cloud_goods.xml View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_classify"
android:layout_width="@dimen/dp_140"
android:orientation="vertical"
android:layout_marginBottom="@dimen/dp_95"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>

<TextView
android:id="@+id/line1"
android:layout_width="@dimen/dp_1"
android:layout_height="match_parent"
android:background="@color/color3"
android:layout_marginLeft="@dimen/dp_140"
/>

<TextView
android:id="@+id/line2"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_3"
android:background="@color/color3"
/>

<androidx.recyclerview.widget.RecyclerView
android:layout_marginLeft="@dimen/dp_141"
android:id="@+id/recycler_goods"
android:layout_width="match_parent"
android:layout_marginBottom="@dimen/dp_95"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
app:spanCount="3"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>

+ 6
- 48
app/src/main/res/layout/fragment_home_foods.xml View File

@@ -13,8 +13,9 @@
android:layout_marginTop="?attr/qmui_topbar_height"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="@dimen/dp_70">
<TextView
android:id="@+id/localFoods"
android:layout_width="@dimen/dp_140"
@@ -48,54 +49,11 @@
android:background="@drawable/ssk" />

</LinearLayout>

<TextView
android:id="@+id/add_classify"
android:layout_width="@dimen/dp_140"
android:visibility="gone"
tools:visibility="visible"
android:layout_below="@+id/line2"
android:layout_height="@dimen/dp_70"
android:maxLines="1"
android:ellipsize="middle"
android:textSize="@dimen/sp_28"
android:text="添加分类"
android:textColor="#823E17"
android:gravity="center"
android:background="#EFE9D2"/>

<androidx.recyclerview.widget.RecyclerView
android:layout_marginBottom="@dimen/dp_95"
android:id="@+id/recycler_classify"
android:layout_width="@dimen/dp_140"
android:layout_below="@+id/add_classify"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>

<TextView
android:id="@+id/line1"
android:layout_width="@dimen/dp_1"
android:layout_marginTop="@dimen/dp_80"
android:layout_height="match_parent"
android:background="@color/color3"
android:layout_marginLeft="@dimen/dp_140"
/>

<TextView
android:id="@+id/line2"
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/dp_77"
android:layout_height="@dimen/dp_3"
android:background="@color/color3"
android:layout_height="match_parent"
android:layout_below="@id/tab"
/>

<androidx.recyclerview.widget.RecyclerView
android:layout_marginLeft="@dimen/dp_141"
android:layout_marginTop="@dimen/dp_80"
android:layout_marginBottom="@dimen/dp_70"
android:id="@+id/recycler_goods"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
</com.qmuiteam.qmui.widget.QMUIWindowInsetLayout>

Loading…
Cancel
Save