Browse Source

批量上传修改

授权码生成工具
pry 5 months ago
parent
commit
506a17c1f5
15 changed files with 933 additions and 827 deletions
  1. +5
    -12
      .idea/deploymentTargetDropDown.xml
  2. +6
    -0
      .idea/git_toolbox_blame.xml
  3. +3
    -0
      app/build.gradle
  4. +2
    -0
      app/src/main/AndroidManifest.xml
  5. +4
    -4
      app/src/main/java/com/bonait/bnframework/common/http/callback/json/JsonDialogCallback.java
  6. +20
    -1
      app/src/main/java/com/bonait/bnframework/ui/adapter/goods/LocalGoodsAdapter.java
  7. +91
    -7
      app/src/main/java/com/bonait/bnframework/ui/fragment/goods/LocalGoodsFragment.java
  8. +2
    -0
      app/src/main/java/com/bonait/bnframework/ui/viewmodel/HomeGoodsViewModel.java
  9. +450
    -543
      app/src/main/java/com/bonait/bnframework/ui/viewmodel/UpdateAllDataService.java
  10. +106
    -207
      app/src/main/java/com/bonait/bnframework/ui/viewmodel/UpdateDataService.java
  11. +51
    -0
      app/src/main/java/com/bonait/bnframework/ui/widget/WaitProcessUtil.java
  12. +27
    -0
      app/src/main/res/drawable/all_edit_btn.xml
  13. +132
    -33
      app/src/main/res/layout/fragment_local_goods.xml
  14. +5
    -1
      app/src/main/res/layout/item/layout/good_show.xml
  15. +29
    -19
      app/src/main/res/layout/item/layout/item_local_goods.xml

+ 5
- 12
.idea/deploymentTargetDropDown.xml View File

@@ -1,17 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="127.0.0.1:7555" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-08-05T02:04:42.367559500Z" />
<value>
<entry key="app">
<State />
</entry>
</value>
</component>
</project>

+ 6
- 0
.idea/git_toolbox_blame.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxBlameSettings">
<option name="version" value="2" />
</component>
</project>

+ 3
- 0
app/build.gradle View File

@@ -29,6 +29,9 @@ android {
}

debug {
debuggable true
minifyEnabled false
shrinkResources false
resValue("string", "PORT_NUMBER", "8081")
resValue("bool","superAdminTest","true")
}


+ 2
- 0
app/src/main/AndroidManifest.xml View File

@@ -18,8 +18,10 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<application
android:vmSafeMode="true"
android:name=".MainApplication"
android:allowBackup="true"
android:hardwareAccelerated="false"


+ 4
- 4
app/src/main/java/com/bonait/bnframework/common/http/callback/json/JsonDialogCallback.java View File

@@ -29,10 +29,10 @@ public abstract class JsonDialogCallback<T> extends JsonCallback<T> {
* 初始化加载框
* */
private void initDialog(Context context) {
tipDialog = new QMUITipDialog.Builder(context)
.setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
.setTipWord("正在加载")
.create();
// tipDialog = new QMUITipDialog.Builder(context)
// .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
// .setTipWord("正在加载")
// .create();
}

/**


+ 20
- 1
app/src/main/java/com/bonait/bnframework/ui/adapter/goods/LocalGoodsAdapter.java View File

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@@ -26,11 +27,16 @@ import com.bonait.bnframework.ui.util.DisplayManager;
public abstract class LocalGoodsAdapter extends BaseAdapter<BPA_GOODS,LocalGoodsAdapter.GoodsViewHolder> {
private boolean isEdit = false;
private MyBitmapUtils myBitmapUtils = new MyBitmapUtils();
private CheckBox select;

public void setEdit(boolean isEdit){
this.isEdit = isEdit;
}

public void setAllSelect(boolean value){
if(select!=null){
select.setChecked(value);
}
}
@NonNull
@Override
public GoodsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@@ -40,6 +46,7 @@ public abstract class LocalGoodsAdapter extends BaseAdapter<BPA_GOODS,LocalGoods
@Override
public void onBindViewHolder(@NonNull GoodsViewHolder holder, @SuppressLint("RecyclerView") int position) {
try {

if(holder.binding.name.getTextSize()> 30 || holder.binding.name.getTextSize()< 28){
DisplayManager.scaleViewGroup(holder.binding.getRoot());
}
@@ -71,6 +78,17 @@ public abstract class LocalGoodsAdapter extends BaseAdapter<BPA_GOODS,LocalGoods
}else {
holder.binding.image.setImageResource(R.mipmap.loading123);
}

//多选框设置
holder.binding.image.setEnabled(goods.status>0?false:true);
holder.binding.upload.setEnabled(goods.status>0?false:true);
holder.binding.delete.setEnabled(goods.status>0?false:true);
holder.binding.SelectStatus.setVisibility(goods.status>0? View.VISIBLE:View.GONE);
holder.binding.SelectStatus.setChecked(goods.status==1?true:false);
holder.binding.SelectStatus.setOnCheckedChangeListener((view,value)->{
selectGoods(view,position,value);
});

//上传按钮点击
holder.binding.upload.setOnClickListener(new View.OnClickListener() {
@Override
@@ -120,6 +138,7 @@ public abstract class LocalGoodsAdapter extends BaseAdapter<BPA_GOODS,LocalGoods

protected abstract void uploadGoods(View v, int position);
protected abstract void deleteGoods(View v, int position);
protected abstract void selectGoods(View v, int position,boolean isSelect);
protected abstract void addGoods();
}



+ 91
- 7
app/src/main/java/com/bonait/bnframework/ui/fragment/goods/LocalGoodsFragment.java View File

@@ -7,8 +7,10 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -44,6 +46,7 @@ import com.bonait.bnframework.ui.dialog.AddGoodsDialog;
import com.bonait.bnframework.ui.dialog.EditGoodsDialog;
import com.bonait.bnframework.ui.util.DimensUtil;
import com.bonait.bnframework.ui.util.DisplayManager;
import com.bonait.bnframework.ui.viewmodel.UpdateAllDataService;
import com.bonait.bnframework.ui.viewmodel.UpdateDataService;
import com.bonait.bnframework.ui.widget.NewToastUtil;

@@ -52,7 +55,9 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author: liup
@@ -69,6 +74,7 @@ public class LocalGoodsFragment extends BaseFragment {
private Long FRESH_DELAY_TIME = 200L;
private AddGoodsDialog addGoodsDialog;
private EditGoodsDialog editGoodsDialog;
private boolean IsAllSelect=false;

/**
* 可编辑
@@ -111,16 +117,57 @@ public class LocalGoodsFragment extends BaseFragment {
EventBus.getDefault().register(this);
}

private void setSelectStatus(int value){
for(BPA_GOODS good:goodsList){
good.status=value;
}
goodsAdapter.notifyDataSetChanged();
}

@SuppressLint("NotifyDataSetChanged")
private void initView(){
DisplayManager.scaleViewGroup(viewBinding.getRoot());

viewBinding.allSelectTV.setVisibility(View.GONE);
viewBinding.allSelectTV.setOnClickListener(view->{
IsAllSelect=!IsAllSelect;
setSelectStatus(IsAllSelect?1:2);
viewBinding.allSelectTV.setText(IsAllSelect?"全不选":"全选");
});

viewBinding.CancelTV.setVisibility(View.GONE);
viewBinding.CancelTV.setOnClickListener(view->{
viewBinding.selectCB.setChecked(true);
});

viewBinding.selectCB.setVisibility(isEdit?View.VISIBLE:View.GONE);

viewBinding.selectCB.setOnCheckedChangeListener((view,value)->{
if(value){
viewBinding.selectCB.setVisibility(View.VISIBLE);
setSelectStatus(0);
viewBinding.allSelectTV.setText("全选");
viewBinding.allSelectTV.setVisibility(View.GONE);
viewBinding.CancelTV.setVisibility(View.GONE);
viewBinding.edit.setVisibility(View.GONE);
}else{
viewBinding.selectCB.setVisibility(View.GONE);
viewBinding.allSelectTV.setVisibility(View.VISIBLE);
viewBinding.CancelTV.setVisibility(View.VISIBLE);
viewBinding.edit.setVisibility(View.VISIBLE);
setSelectStatus(2);
}
viewBinding.edit.setEnabled(false);
viewBinding.edit.setAlpha(0.5f);
});

viewBinding.addClassify.setVisibility(isEdit?View.VISIBLE:View.GONE);
viewBinding.uploadAll.setOnClickListener(v->{
if(ConfigName.getInstance().isFast2Click()){
NewToastUtil.getInstance().showToast("点击过快!");
return;
List<BPA_GOODS> res = goodsList.stream().filter(p->p.status==1).collect(Collectors.toList());
if(res!=null) {
UpdateAllDataService.startUpLoadAll(res,getContext());
}
// UpdateAllDataService.startUpLoadAll(getContext());
viewBinding.selectCB.setChecked(true);//全部上传后隐藏多选内容
});

viewBinding.addClassify.setOnClickListener(view -> {
@@ -130,18 +177,32 @@ public class LocalGoodsFragment extends BaseFragment {
}
jumpClassify();
});
viewBinding.deleteAll.setVisibility(isEdit?View.VISIBLE:View.GONE);
viewBinding.deleteAll.setOnClickListener(v->{
AlertDialogUtils.showTipDialog((AppCompatActivity) getActivity(), "请确认", "确认删除所有商品信息?", new AlertDialogUtils.DialogClickListener() {
AlertDialogUtils.showTipDialog((AppCompatActivity) getActivity(), "请确认", "确认删除选择的所有商品信息?", new AlertDialogUtils.DialogClickListener() {
@Override
public void onConfirm() {
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("点击过快!");
return;
}
MainInit.clearGoodsInfo();
List<BPA_GOODS> res = goodsList.stream().filter(p->p.status==1).collect(Collectors.toList());
if(res!=null) {
res.forEach(bean->{
GoodsProcessDetailDBUtil.deleteByGoodsId(bean.id);
SubAttributeGroupDBUtil.deleteByGoodsId(bean.id);
if(GoodsDBUtil.delete(bean)){
NewToastUtil.getInstance().showToast("删除["+bean.name+"]成功!","Delete ["+bean.name+"] Success!");
goodsList.remove(bean);
goodsAdapter.notifyDataSetChanged();
RecordManager.getInstance().addLogRecord("角色操作日志","删除["+bean.name+"]菜品成功!");
}else {
NewToastUtil.getInstance().showToast("删除["+bean.name+"]失败!","Delete ["+bean.name+"] Fail!");
}
});
}
updateData();
RecordManager.getInstance().addLogRecord("角色操作日志","删除所有商品信息");
viewBinding.selectCB.setChecked(true);//全部删除后隐藏多选内容
}

@Override
@@ -241,6 +302,24 @@ public class LocalGoodsFragment extends BaseFragment {
});
}

@Override
protected void selectGoods(View v, int position,boolean isSelect){
mData.get(position).status=isSelect?1:2;
List<BPA_GOODS> res = goodsList.stream().filter(p->p.status==1).collect(Collectors.toList());
if(res!=null) {
if(res.size()==goodsList.size()){
viewBinding.allSelectTV.setText("全不选");
IsAllSelect=true;
}
else{
viewBinding.allSelectTV.setText("全选");
IsAllSelect=false;
}
viewBinding.edit.setEnabled(res.size()>0?true:false);
viewBinding.edit.setAlpha(res.size()>0?1.0f:0.5f);
}
}

@Override
protected void addGoods() {
if(!classifyList.isEmpty() && getActivity()!=null){
@@ -264,6 +343,10 @@ public class LocalGoodsFragment extends BaseFragment {
}
};
goodsAdapter.setEdit(isEdit);

ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)viewBinding.recyclerGoods.getLayoutParams();
params.topMargin=isEdit?83:10;
viewBinding.recyclerGoods.setLayoutParams(params);
viewBinding.recyclerGoods.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
@@ -277,6 +360,7 @@ public class LocalGoodsFragment extends BaseFragment {
classifyAdapter =new ClassifyAdapter() {
@Override
protected void onItemClick(View v, int position) {
viewBinding.selectCB.setChecked(true);//切换分类后隐藏多选内容
LogUtils.d("分类列表点击 position="+position+" name = "+mData.get(position).name);
RecordManager.getInstance().addLogRecord("角色操作日志","点击["+mData.get(position).name+"]分类");
handler.removeMessages(MSG_FRESH_GOODS);


+ 2
- 0
app/src/main/java/com/bonait/bnframework/ui/viewmodel/HomeGoodsViewModel.java View File

@@ -110,6 +110,8 @@ public class HomeGoodsViewModel extends ViewModel {
}
});
hasData = true;
}).OnFailed(e->{
WaitProcessUtil.getInstance().dismiss();
});
}



+ 450
- 543
app/src/main/java/com/bonait/bnframework/ui/viewmodel/UpdateAllDataService.java View File

@@ -1,544 +1,451 @@
//package com.bonait.bnframework.ui.viewmodel;
//
//import android.content.Context;
//
//import com.apkfuns.logutils.LogUtils;
//import com.bonait.bnframework.MainApplication;
//import com.bonait.bnframework.business.RecordManager;
//import com.bonait.bnframework.common.constant.ConfigName;
//import com.bonait.bnframework.common.db.QueryDB;
//import com.bonait.bnframework.common.db.file.DBHelper;
//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_MATERIAL;
//import com.bonait.bnframework.common.db.mode.BPA_PROCESS;
//import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel;
//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.MaterialUtil;
//import com.bonait.bnframework.common.db.util.ProcessModelUtil;
//import com.bonait.bnframework.common.db.util.SubAttributeDBUtil;
//import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil;
//import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback;
//import com.bonait.bnframework.common.model.upload.ProcessModelBean;
//import com.bonait.bnframework.common.model.upload.GoodsDataInfo;
//import com.bonait.bnframework.common.model.upload.GoodsProcessDetail;
//import com.bonait.bnframework.common.model.upload.MaterialDataInfo;
//import com.bonait.bnframework.common.model.upload.UpAttributeBean;
//import com.bonait.bnframework.common.model.upload.UpClassifyBean;
//import com.bonait.bnframework.common.model.upload.UpResData;
//import com.bonait.bnframework.common.model.upload.UploadRes;
//import com.bonait.bnframework.common.utils.NetworkUtils;
//import com.bonait.bnframework.ui.widget.NewToastUtil;
//import com.bonait.bnframework.ui.widget.WaitProcessUtil;
//import com.google.gson.Gson;
//import com.lzy.okgo.OkGo;
//import com.lzy.okgo.model.HttpHeaders;
//import com.lzy.okgo.model.Response;
//
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.LinkedHashMap;
//import java.util.List;
//
//import okhttp3.MediaType;
//import okhttp3.RequestBody;
//
///**
// * @author: liup
// * @description:
// * @date: 2024/7/25 14:55.
// */
//public class UpdateAllDataService {
// private static String path = UpdateDataService.path;
// private static String key = UpdateDataService.key;
//
// public static void startUpLoadAll(Context context){
// if(ConfigName.getInstance().isFast2Click()){
// NewToastUtil.getInstance().showToast("点击太快了");
// return;
// }
// if (NetworkUtils.checkNetworkAvailable(context)) {
// try{
// if(UpdateDataService.isDownProcessModel){
// upLoadMaterial(context);
// }else {
// downLoadProcessModel(context);
// }
// }catch (Exception e){
// NewToastUtil.getInstance().showToastError("异常 "+e.getMessage());
// }finally {
//
// }
// }else {
// NewToastUtil.getInstance().showToast("无网络,请先连接网络");
// }
// }
//
//
// /**
// * 下载云端工艺模型
// * @param context
// */
// private static void downLoadProcessModel( Context context){
// try{
// String url = "http://"+path+"/api/ExternalPlatform/Device/GetDeviceTechnology";
// WaitProcessUtil.getInstance().show(context,"匹配工艺模型","正在同步云端工艺模型...");
// HashMap<String,String> params = new HashMap<>();
// params.put("autokey",ConfigName.getInstance().DeviceAutoKey);
// String body = new Gson().toJson(params);
// HttpHeaders headers = new HttpHeaders();
// headers.put("key", key);
// OkGo.<ProcessModelBean>post(url)
// .tag(context)
// .upRequestBody(
// RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
// body))
// .headers(headers)
// .execute(new JsonDialogCallback<ProcessModelBean>(context) {
// @Override
// public void onSuccess(Response<ProcessModelBean> response) {
// LogUtils.d("下载工艺模型成功");
// RecordManager.getInstance().addLogRecord("数据接收", url+"-成功");
// List<BPA_PROCESS> processeList = new ArrayList<>();
// List<BPA_PROCESSModel> processModelList = new ArrayList<>();
//
// ProcessModelBean processModelBean = response.body();
// int pos = 1;
// if(processModelBean!=null && processModelBean.data!=null){
// for(ProcessModelBean.ProcessModelData processModelData:processModelBean.data){
// BPA_PROCESS process = new BPA_PROCESS();
// process.id = processModelData.id;
// process.name = processModelData.name;
// process.sort = pos;
// pos++;
// processeList.add(process);
// if(processModelData.actionList!=null){
// for(ProcessModelBean.ProcessModelData.ActionListBean actionListBean: processModelData.actionList){
// BPA_PROCESSModel processModel = new BPA_PROCESSModel();
// processModel.id = actionListBean.id;
// processModel.processid = processModelData.id;
// processModel.name = actionListBean.actionName;
// processModel.sort = actionListBean.sort;
// if(actionListBean.actionType!=null){
// switch (actionListBean.actionType){
// case "text":
// processModel.datatype = 1;
// break;
// case "select":
// processModel.datatype = 2;
// break;
// case "digit":
// processModel.datatype = 0;
// break;
// }
// }
// if(actionListBean.actionValue!=null && !actionListBean.actionValue.isEmpty()){
// List<String> actions = new ArrayList<>();
// try {
// JSONArray array = new JSONArray(actionListBean.actionValue);
// for (int i = 0; array != null && i < array.length(); i++){
// JSONObject jsonObject = array.getJSONObject(i);
// actions.add(jsonObject.optString("actionValueName"));
// }
// } catch (JSONException e) {
// throw new RuntimeException(e);
// }
// if(!actions.isEmpty()){
// processModel.data = actions.toString();
// }
// }
// processModelList.add(processModel);
// }
// }
// }
// }
// DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_PROCESS.class,null);
// DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_PROCESSModel.class,null);
// ProcessModelUtil.addProcessList(processeList);
// ProcessModelUtil.addProcessModelList(processModelList);
// upLoadMaterial(context);
// }
//
// @Override
// public void onError(Response<ProcessModelBean> response) {
// super.onError(response);
// WaitProcessUtil.getInstance().dismiss();
// NewToastUtil.getInstance().showToastError("下载工艺模型失败 "+response.message());
// LogUtils.d("下载工艺模型失败 "+response.message());
// RecordManager.getInstance().addLogRecord("数据接收", url+"-下载工艺模型失败");
// }
// });
// }catch (Exception e){
// LogUtils.d("网络请求异常"+e.getMessage());
// }
//
// }
//
// private static void upLoadMaterial(Context context){
// try {
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传物料信息,请耐心稍等...");
// List<BPA_MATERIAL> materials = MaterialUtil.GetMaterialALL();
//
// List<MaterialDataInfo> upMaterialBean = new ArrayList<>();
// for(BPA_MATERIAL material:materials){
// upMaterialBean.add(new MaterialDataInfo(material.id,material.name,"液体料",""));
// }
// String url = "http://"+path+"/api/ExternalPlatform/Material/AddMaterial";
// HttpHeaders headers = new HttpHeaders();
// headers.put("key", key);
// OkGo.<UploadRes<UpResData>>post(url)
// .tag(context)
// .upRequestBody(
// RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
// new Gson().toJson(upMaterialBean)))
// .headers(headers)
// .execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
// @Override
// public void onSuccess(Response<UploadRes<UpResData>> response) {
// LogUtils.d("上传物料信息成功");
// boolean isSuccess = true;
// List<String> names = new ArrayList<>();
// for(UpResData upResData:response.body().data){
// if (upResData.message.contains("重复数据")) {
// isSuccess = false;
// names.add(upResData.name);
// }
// }
// if(!isSuccess){
// NewToastUtil.getInstance().showToastError("批量物料上传失败:重复数据-"+names);
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传物料信息失败-重复数据-"+names);
// WaitProcessUtil.getInstance().dismiss();
// }else{
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传物料信息成功");
// NewToastUtil.getInstance().showToast("批量上传物料信息成功");
// upLoadClassifyInfo(context);
// }
// }
//
// @Override
// public void onError(Response<UploadRes<UpResData>> response) {
// super.onError(response);
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传物料信息失败");
// NewToastUtil.getInstance().showToastError("批量上传物料信息失败 "+response.message());
// WaitProcessUtil.getInstance().dismiss();
// }
// });
// }catch (Exception e){
// LogUtils.d("网络请求异常"+e.getMessage());
// }
//
// }
//
// private static void upLoadClassifyInfo(Context context){
// try {
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传所有分类信息,请耐心稍等...");
package com.bonait.bnframework.ui.viewmodel;

import android.content.Context;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.business.RecordManager;
import com.bonait.bnframework.common.Result.OperateResult;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.file.DBHelper;
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_MATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_PROCESS;
import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel;
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.MaterialUtil;
import com.bonait.bnframework.common.db.util.ProcessModelUtil;
import com.bonait.bnframework.common.db.util.SubAttributeDBUtil;
import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil;
import com.bonait.bnframework.common.helper.I.IRun;
import com.bonait.bnframework.common.helper.I.IRunT;
import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback;
import com.bonait.bnframework.common.model.upload.ProcessModelBean;
import com.bonait.bnframework.common.model.upload.GoodsDataInfo;
import com.bonait.bnframework.common.model.upload.GoodsProcessDetail;
import com.bonait.bnframework.common.model.upload.MaterialDataInfo;
import com.bonait.bnframework.common.model.upload.UpAttributeBean;
import com.bonait.bnframework.common.model.upload.UpClassifyBean;
import com.bonait.bnframework.common.model.upload.UpResData;
import com.bonait.bnframework.common.model.upload.UploadRes;
import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.ui.widget.NewToastUtil;
import com.bonait.bnframework.ui.widget.WaitProcessUtil;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.Response;

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
* @author: liup
* @description:
* @date: 2024/7/25 14:55.
*/
public class UpdateAllDataService {
private static String path = UpdateDataService.path;
private static String key = UpdateDataService.key;

public static void startUpLoadAll(List<BPA_GOODS> goods,Context context){
if(ConfigName.getInstance().isFast2Click()){
NewToastUtil.getInstance().showToast("点击太快了");
return;
}
if(goods==null) return;
if (NetworkUtils.checkNetworkAvailable(context)) {
try{
WaitProcessUtil.getInstance().Show(context,"商品上传","准备上传商品,请耐心稍等...");
if(UpdateDataService.isDownProcessModel){
upLoadMaterial(goods,context);
}else {
downLoadProcessModel(goods,context);
}
}catch (Exception e){
NewToastUtil.getInstance().showToastError("异常 "+e.getMessage());
}finally {

}
}else {
NewToastUtil.getInstance().showToast("无网络,请先连接网络");
}
}

/**
* 下载云端工艺模型
* @param context
*/
private static void downLoadProcessModel(List<BPA_GOODS> goods, Context context){
try{
String url = "http://"+path+"/api/ExternalPlatform/Device/GetDeviceTechnology";
WaitProcessUtil.getInstance().Show("正在同步云端工艺模型...");
HashMap<String,String> params = new HashMap<>();
params.put("autokey",ConfigName.getInstance().DeviceAutoKey);
String body = new Gson().toJson(params);
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
OkGo.<ProcessModelBean>post(url)
.tag(context)
.upRequestBody( RequestBody.create(MediaType.parse("application/json; charset=utf-8"),body))
.headers(headers)
.execute(new JsonDialogCallback<ProcessModelBean>(context) {
@Override
public void onSuccess(Response<ProcessModelBean> response) {
LogUtils.d("下载工艺模型成功");
RecordManager.getInstance().addLogRecord("数据接收", url+"-成功");
List<BPA_PROCESS> processeList = new ArrayList<>();
List<BPA_PROCESSModel> processModelList = new ArrayList<>();

ProcessModelBean processModelBean = response.body();
int pos = 1;
if(processModelBean!=null && processModelBean.data!=null){
for(ProcessModelBean.ProcessModelData processModelData:processModelBean.data){
BPA_PROCESS process = new BPA_PROCESS();
process.id = processModelData.id;
process.name = processModelData.name;
process.sort = pos;
pos++;
processeList.add(process);
if(processModelData.actionList!=null){
for(ProcessModelBean.ProcessModelData.ActionListBean actionListBean: processModelData.actionList){
BPA_PROCESSModel processModel = new BPA_PROCESSModel();
processModel.id = actionListBean.id;
processModel.processid = processModelData.id;
processModel.name = actionListBean.actionName;
processModel.sort = actionListBean.sort;
if(actionListBean.actionType!=null){
switch (actionListBean.actionType){
case "text":
processModel.datatype = 1;
break;
case "select":
processModel.datatype = 2;
break;
case "digit":
processModel.datatype = 0;
break;
}
}
if(actionListBean.actionValue!=null && !actionListBean.actionValue.isEmpty()){
List<String> actions = new ArrayList<>();
try {
JSONArray array = new JSONArray(actionListBean.actionValue);
for (int i = 0; array != null && i < array.length(); i++){
JSONObject jsonObject = array.getJSONObject(i);
actions.add(jsonObject.optString("actionValueName"));
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
if(!actions.isEmpty()){
processModel.data = actions.toString();
}
}
processModelList.add(processModel);
}
}
}
}
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_PROCESS.class,null);
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_PROCESSModel.class,null);
ProcessModelUtil.addProcessList(processeList);
ProcessModelUtil.addProcessModelList(processModelList);
upLoadMaterial(goods,context);
}

@Override
public void onError(Response<ProcessModelBean> response) {
super.onError(response);
WaitProcessUtil.getInstance().Dismiss();
NewToastUtil.getInstance().showToastError("下载工艺模型失败 "+response.message());
LogUtils.d("下载工艺模型失败 "+response.message());
RecordManager.getInstance().addLogRecord("数据接收", url+"-下载工艺模型失败");
}
});
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}

}

/**
* 接口请求数据的验证
* @param response 接口返回的消息体
* @param typeInfo 接口请求提示的消息类型
* @param url 接口请求的Url
* @return
*/
private static OperateResult Analysis(Context context,Response<UploadRes<UpResData>> response, String typeInfo, String url){
boolean isSuccess = true;
StringBuffer names = new StringBuffer();
String errorMsg ="";
for(UpResData upResData:response.body().data){
if (upResData.code>30000){
isSuccess = false;
names.append(upResData.name);
errorMsg=upResData.message;
}
}
if(!isSuccess){
NewToastUtil.getInstance().showToastError(errorMsg+"-"+names.toString());
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传"+typeInfo+"失败-重复数据-"+names);
WaitProcessUtil.getInstance().Dismiss(context,"上传"+typeInfo+"失败",errorMsg);
return OperateResult.CreateFailed("");
}else{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传"+typeInfo+"成功");
NewToastUtil.getInstance().showToast("上传物料信息成功");
return OperateResult.CreateSuccess();
}

}
private static void Post(String url, Context context, Object data, String typeInfo, IRunT<Response<UploadRes<UpResData>>> Success){
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
OkGo.<UploadRes<UpResData>>post(url)
.tag(context)
.upRequestBody(RequestBody.create(MediaType.parse("application/json; charset=utf-8"),new Gson().toJson(data)))
.headers(headers)
.execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
@Override
public void onSuccess(Response<UploadRes<UpResData>> response) {
if(Success!=null)Success.Run(response);
}
@Override
public void onError(Response<UploadRes<UpResData>> response) {
super.onError(response);
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传"+typeInfo+"失败");
NewToastUtil.getInstance().showToastError("上传"+typeInfo+"失败:"+response.message());
WaitProcessUtil.getInstance().Dismiss(context,"上传"+typeInfo+"失败",response.message());
}
});
}

private static void upLoadMaterial(List<BPA_GOODS> goods,Context context){
try {
WaitProcessUtil.getInstance().Show("正在上传物料信息,请耐心稍等...");
List<BPA_MATERIAL> materials = MaterialUtil.GetMaterialALL();

List<MaterialDataInfo> upMaterialBean = new ArrayList<>();
for(BPA_MATERIAL material:materials){
upMaterialBean.add(new MaterialDataInfo(material.id,material.name,"液体料","7b2aced3-db2a-469c-9b08-b85e3f3f1aa8"));
}
String url = "http://"+path+"/api/ExternalPlatform/Material/AddMaterial";
Post(url,context,upMaterialBean,"物料信息",(response->{
Analysis(context,response,"物料信息",url).OnSource(()->{
upLoadClassifyInfo(goods,context);
});
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}

}

private static void upLoadClassifyInfo(List<BPA_GOODS> goods,Context context){
try {
WaitProcessUtil.getInstance().Show("正在上传所有分类信息,请耐心稍等...");
List<UpClassifyBean> upClassifyBeans = new ArrayList<>();
goods.forEach(good->{
BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(good.classifyId);
if(classify!=null){
UpClassifyBean upClassifyBean = new UpClassifyBean();
upClassifyBean.id = classify.id;
upClassifyBean.name = classify.name;
upClassifyBean.sort = 0;
upClassifyBean.remark = "";
upClassifyBeans.add(upClassifyBean);
}
});
String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoodsType";
Post(url,context,upClassifyBeans,"分类信息",(response->{
Analysis(context,response,"分类信息",url).OnSource(()->{
upLoadAttribute(upClassifyBeans,goods,context);
});
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}

}

private static void upLoadAttribute(List<UpClassifyBean> upClassifyBeans,List<BPA_GOODS> goods,Context context){
try {
WaitProcessUtil.getInstance().Show("正在上传所有分类属性,请耐心稍等...");
// List<BPA_GOODS_CLASSIFY> classifys = GoodsClassifyDBUtil.getAll();
// if(classifys.isEmpty()){
// WaitProcessUtil.getInstance().dismiss();
// return;
// }
//
// List<UpClassifyBean> upClassifyBeans = new ArrayList<>();
//
// for(int i=0;i<classifys.size();i++){
// UpClassifyBean upClassifyBean = new UpClassifyBean();
// upClassifyBean.pid = "0";
// upClassifyBean.name = classifys.get(i).name;
// upClassifyBean.sort = 0;
// upClassifyBeans.add(upClassifyBean);
// }
//
// String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoodsType";
// HttpHeaders headers = new HttpHeaders();
// headers.put("key", key);
// OkGo.<UploadRes<UpResData>>post(url)
// .tag(context)
// .upRequestBody(
// RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
// new Gson().toJson(upClassifyBeans)))
// .headers(headers)
// .execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
// @Override
// public void onSuccess(Response<UploadRes<UpResData>> response) {
// boolean isSuccess = true;
// List<String> names = new ArrayList<>();
// for(UpResData upResData:response.body().data){
// if (upResData.message.contains("重复数据")) {
// isSuccess = false;
// names.add(upResData.name);
// }
// }
// if(!isSuccess){
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传分类信息失败-重复数据-"+names);
// NewToastUtil.getInstance().showToast("批量上传分类信息失败,云端有相同数据-"+names);
// WaitProcessUtil.getInstance().dismiss();
// }else{
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传分类信息成功");
// NewToastUtil.getInstance().showToast("批量上传分类信息成功");
// LogUtils.d("批量上传分类信息成功");
// upLoadAttribute(context);
// }
// }
//
// @Override
// public void onError(Response<UploadRes<UpResData>> response) {
// super.onError(response);
// WaitProcessUtil.getInstance().dismiss();
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传分类信息失败");
// NewToastUtil.getInstance().showToastError("批量上传分类信息失败 "+response.message());
// }
// });
// }catch (Exception e){
// LogUtils.d("网络请求异常"+e.getMessage());
// }
//
// }
//
// private static void upLoadAttribute(Context context){
// try {
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传所有分类属性,请耐心稍等...");
// List<BPA_GOODS_CLASSIFY> classifys = GoodsClassifyDBUtil.getAll();
// List<UpAttributeBean> upAttributeBeans = new ArrayList<>();
// for(BPA_GOODS_CLASSIFY classify1:classifys){
// List<BPA_ATTRIBUTE> attributes = AttributeDBUtil.getByClassify(classify1.id);
// for(BPA_ATTRIBUTE bean:attributes){
// UpAttributeBean upAttributeBean = new UpAttributeBean();
// upAttributeBean.setAttributeName(bean.name);
// upAttributeBean.setGoodsTypeName(classify1.name);
// List<BPA_SUBATTRIBUTE> subattributes = SubAttributeDBUtil.getByParentAttributeId(bean.id);
// for(BPA_SUBATTRIBUTE subattribute:subattributes){
// upAttributeBean.goodsAttributeValue.add(new UpAttributeBean.GoodsAttributeValueBean(subattribute.name,subattribute.sort));
// }
// upAttributeBeans.add(upAttributeBean);
// }
// }
// String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoodsAttribute";
// HttpHeaders headers = new HttpHeaders();
// headers.put("key", key);
// OkGo.<UploadRes<UpResData>>post(url)
// .tag(context)
// .upRequestBody(
// RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
// new Gson().toJson(upAttributeBeans)))
// .headers(headers)
// .execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
// @Override
// public void onSuccess(Response<UploadRes<UpResData>> response) {
// boolean isSuccess = true;
// List<String> names = new ArrayList<>();
// for(UpResData upResData:response.body().data){
// if (upResData.message.contains("重复数据")) {
// isSuccess = false;
// names.add(upResData.name);
// }
// }
// if(!isSuccess){
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传分类属性信息失败-重复数据-"+names);
// NewToastUtil.getInstance().showToast("批量上传分类属性信息失败,云端有相同数据-"+names);
// WaitProcessUtil.getInstance().dismiss();
// }else{
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传分类属性信息成功");
// LogUtils.d("批量上传分类属性信息成功 "+response.message());
// NewToastUtil.getInstance().showToast("批量上传分类属性信息成功");
// upLoadGoodsInfo(context);
// }
// }
//
// @Override
// public void onError(Response<UploadRes<UpResData>> response) {
// super.onError(response);
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传商品基础信息失败");
// NewToastUtil.getInstance().showToastError("批量上传分类属性信息失败 "+response.message());
// WaitProcessUtil.getInstance().dismiss();
// }
// });
// }catch (Exception e){
// LogUtils.d("网络请求异常"+e.getMessage());
// }
//
// }
//
// private static void upLoadGoodsInfo(Context context){
// try {
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传所有商品信息,请耐心稍等...");
// List<BPA_GOODS> goods = GoodsDBUtil.getAll();
// List<GoodsDataInfo> upMaterialBean = new ArrayList<>();
//
// for(BPA_GOODS good : goods){
// BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(good.classifyId);
// if(classify!=null){
// upMaterialBean.add(new GoodsDataInfo(good.id,good.name,"",good.url,0,false,good.classifyId,
// classify.name,"",""));
// }
// }
//
// String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoods";
// HttpHeaders headers = new HttpHeaders();
// headers.put("key", key);
// OkGo.<UploadRes<UpResData>>post(url)
// .tag(context)
// .upRequestBody(
// RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
// new Gson().toJson(upMaterialBean)))
// .headers(headers)
// .execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
// @Override
// public void onSuccess(Response<UploadRes<UpResData>> response) {
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传商品基础信息成功");
// NewToastUtil.getInstance().showToast("批量上传商品基础信息成功");
// upLoadDetailInfo(context);
// }
//
// @Override
// public void onError(Response<UploadRes<UpResData>> response) {
// super.onError(response);
// RecordManager.getInstance().addLogRecord("数据接收", url+"-批量上传商品基础信息失败");
// NewToastUtil.getInstance().showToastError("批量上传商品基础信息失败 "+response.message());
// WaitProcessUtil.getInstance().dismiss();
// }
// });
// }catch (Exception e){
// LogUtils.d("网络请求异常"+e.getMessage());
// }
//
// }
//
// private static void upLoadDetailInfo(Context context){
// try {
// List<GoodsProcessDetail> goodsProcessDetailList = new ArrayList<>();
//
//
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传工艺信息,请耐心稍等...");
//
// List<BPA_GOODS> goodsList = GoodsDBUtil.getAll();
// for(BPA_GOODS goods:goodsList){
// GoodsProcessDetail goodsProcessDetail = new GoodsProcessDetail();
// goodsProcessDetail.deviceId = ConfigName.getInstance().DeviceAutoKey;
// goodsProcessDetail.goodsId = goods.id;
// List<GoodsProcessDetail.TechnologyActionList> technologyActionLists = new ArrayList<>();
// BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(goods.classifyId);
// assert classify != null;
//
// List<BPA_GOODS_SUBATTRIBUTE_GROUP> groups = SubAttributeGroupDBUtil.getByGoodsId(goods.id);
// List<BPA_GOODS_PROCESS_DETAIL> goodsProcessDetails = new ArrayList<>();
// for(BPA_GOODS_SUBATTRIBUTE_GROUP group:groups){
// goodsProcessDetails.addAll(GoodsProcessDetailDBUtil.getByGroupId(group.id));
// }
//
// HashMap<String,String> processModel = new LinkedHashMap<>();
// List<BPA_PROCESSModel> processModelList = QueryDB.GetProcessModelALL();
// for(BPA_PROCESSModel bean : processModelList){
// processModel.put(bean.name,bean.id);
// }
//
// for(BPA_GOODS_PROCESS_DETAIL bean : goodsProcessDetails){
// GoodsProcessDetail.TechnologyActionList technologyActionList = new GoodsProcessDetail.TechnologyActionList();
// technologyActionList.sort = bean.sort+"";
// technologyActionList.stepName = bean.processname;
// BPA_PROCESS process = ProcessModelUtil.getProcessByName(bean.processname);
// if(process!=null){
// technologyActionList.chnologyId = process.id;
// BPA_GOODS_SUBATTRIBUTE_GROUP goodsSubattributeGroup = SubAttributeGroupDBUtil.getById(bean.goodsSubAttributeGroupId);
// if(goodsSubattributeGroup!=null){
// technologyActionList.goodsAttributeId = goodsSubattributeGroup.subAttributeIdList;
// }
//
// List<GoodsProcessDetail.TechnologyActionList.ActionJson> actionJson = new ArrayList<>();
// List<String> data = new ArrayList<>();
// if (bean.processvalue.contains("|")) {
// String[] res = bean.processvalue.split("[|]");
// data.addAll(Arrays.asList(res));
// } else {
// data.add(bean.processvalue);
// }
// int index = 0;
// for (String item : data) {
// if (item.contains(",")) {
// if(bean.processname.equals("液体料")){
// String[] wl = item.split("[,]");
// if (wl.length == 2) {
// //液体料单独处理
// String name = wl[0];
// String val = wl[1];
// BPA_PROCESSModel model = ProcessModelUtil.getProcessModelByName(process.id,"物料名称");
// if(model!=null){
// actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson("物料名称",name,model.id,index));
// index++;
// BPA_PROCESSModel model2 = ProcessModelUtil.getProcessModelByName(process.id,"重量");
// if(model2==null){
// model2 = ProcessModelUtil.getProcessModelByName(process.id,"物料重量");
// actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson("物料重量",val,model2.id,index));
// }else {
// actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson("重量",val,model2.id,index));
// }
// }else {
// NewToastUtil.getInstance().showToastError(name+"液体料工序上传失败");
// RecordManager.getInstance().addLogRecord("数据接收", name+"-液体料工序上传失败");
// }
// }
// }else{
// String[] wl = item.split("[,]");
// if (wl.length == 2) {
// String name = wl[0];
// String val = wl[1];
// BPA_PROCESSModel model = ProcessModelUtil.getProcessModelByName(process.id,name);
// actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson(name,val,model.id,index));
// index++;
// }
// }
//
// }
// }
//
// technologyActionList.actionJson = actionJson;
// technologyActionLists.add(technologyActionList);
// }
// }
// goodsProcessDetail.technologyActionList = technologyActionLists;
// goodsProcessDetailList.add(goodsProcessDetail);
// }
//
//
// String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoods";
// HttpHeaders headers = new HttpHeaders();
// headers.put("key", key);
// OkGo.<UploadRes<UpResData>>post(url)
// .tag(context)
// .upRequestBody(
// RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
// new Gson().toJson(goodsProcessDetailList)))
// .headers(headers)
// .execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
// @Override
// public void onSuccess(Response<UploadRes<UpResData>> response) {
// RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品工艺成功");
// NewToastUtil.getInstance().showToastError("上传商品工艺成功");
// WaitProcessUtil.getInstance().dismiss();
// }
//
// @Override
// public void onError(Response<UploadRes<UpResData>> response) {
// super.onError(response);
// RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品工艺失败");
// NewToastUtil.getInstance().showToastError("上传商品工艺失败 "+response.message());
// WaitProcessUtil.getInstance().dismiss();
// }
// });
// }catch (Exception e){
// LogUtils.d("网络请求异常"+e.getMessage());
// }
//
// }
//}

List<UpAttributeBean> upAttributeBeans = new ArrayList<>();
upClassifyBeans.forEach(ucb->{
List<BPA_ATTRIBUTE> attributes = AttributeDBUtil.getByClassify(ucb.id);
attributes.forEach(bean->{
UpAttributeBean upAttributeBean = new UpAttributeBean();
upAttributeBean.attributeName = (bean.name);
upAttributeBean.id = bean.id;
upAttributeBean.goodsTypeName = (ucb.name);
upAttributeBean.goodsTypeId = ucb.id;
upAttributeBean.sort = 1;

List<BPA_SUBATTRIBUTE> subattributes = SubAttributeDBUtil.getByParentAttributeId(bean.id);
for(BPA_SUBATTRIBUTE subattribute:subattributes){
upAttributeBean.goodsAttributeValueList.add(new UpAttributeBean.GoodsAttributeValueBean(subattribute.id,subattribute.name,subattribute.sort));
}
upAttributeBeans.add(upAttributeBean);
});
});
String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoodsAttribute";
Post(url,context,upAttributeBeans,"分类属性信息",(response->{
Analysis(context,response,"分类属性信息",url).OnSource(()->{
upLoadGoodsInfo(goods,context);
});
}));

}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}

}

private static void upLoadGoodsInfo(List<BPA_GOODS> goods,Context context){
try {
WaitProcessUtil.getInstance().Show("正在上传所有商品信息,请耐心稍等...");
List<GoodsDataInfo> upMaterialBean = new ArrayList<>();
for(BPA_GOODS good : goods){
BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(good.classifyId);
if(classify!=null){
upMaterialBean.add(new GoodsDataInfo(good.id,good.name,"",good.url,"0",false,good.classifyId,classify.name));
}
}
String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoods";
Post(url,context,upMaterialBean,"商品基础信息",(response->{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品基础信息成功");
NewToastUtil.getInstance().showToast("上传商品基础信息成功");
upLoadDetailInfo(goods,context);
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}

}

private static void upLoadDetailInfo(List<BPA_GOODS> goodsList,Context context){
try {
List<GoodsProcessDetail> goodsProcessDetailList = new ArrayList<>();
WaitProcessUtil.getInstance().Show("正在上传工艺信息,请耐心稍等...");
for(BPA_GOODS goods:goodsList){
GoodsProcessDetail goodsProcessDetail = new GoodsProcessDetail();
goodsProcessDetail.deviceId = ConfigName.getInstance().DeviceAutoKey;
goodsProcessDetail.goodsId = goods.id;
List<GoodsProcessDetail.TechnologyActionList> technologyActionLists = new ArrayList<>();
BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(goods.classifyId);
assert classify != null;

List<BPA_GOODS_SUBATTRIBUTE_GROUP> groups = SubAttributeGroupDBUtil.getByGoodsId(goods.id);
List<BPA_GOODS_PROCESS_DETAIL> goodsProcessDetails = new ArrayList<>();
for(BPA_GOODS_SUBATTRIBUTE_GROUP group:groups){
goodsProcessDetails.addAll(GoodsProcessDetailDBUtil.getByGroupId(group.id));
}

HashMap<String,String> processModel = new LinkedHashMap<>();
List<BPA_PROCESSModel> processModelList = QueryDB.GetProcessModelALL();
for(BPA_PROCESSModel bean : processModelList){
processModel.put(bean.name,bean.id);
}

for(BPA_GOODS_PROCESS_DETAIL bean : goodsProcessDetails){
GoodsProcessDetail.TechnologyActionList technologyActionList = new GoodsProcessDetail.TechnologyActionList();
technologyActionList.sort = bean.sort+"";
technologyActionList.stepName = bean.processname;
BPA_PROCESS process = ProcessModelUtil.getProcessByName(bean.processname);
if(process!=null){
technologyActionList.chnologyId = process.id;
BPA_GOODS_SUBATTRIBUTE_GROUP goodsSubattributeGroup = SubAttributeGroupDBUtil.getById(bean.goodsSubAttributeGroupId);
if(goodsSubattributeGroup!=null){
technologyActionList.goodsAttributeId = goodsSubattributeGroup.subAttributeIdList;
}

List<GoodsProcessDetail.TechnologyActionList.ActionJson> actionJson = new ArrayList<>();
List<String> data = new ArrayList<>();
if (bean.processvalue.contains("|")) {
String[] res = bean.processvalue.split("[|]");
data.addAll(Arrays.asList(res));
} else {
data.add(bean.processvalue);
}
int index = 0;
for (String item : data) {
if (item.contains(",")) {
if(bean.processname.equals("液体料")){
String[] wl = item.split("[,]");
if (wl.length == 2) {
//液体料单独处理
String name = wl[0];
String val = wl[1];
BPA_PROCESSModel model = ProcessModelUtil.getProcessModelByName(process.id,"物料名称");
if(model!=null){
actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson("物料名称",name,model.id,index));
index++;
BPA_PROCESSModel model2 = ProcessModelUtil.getProcessModelByName(process.id,"重量");
if(model2==null){
model2 = ProcessModelUtil.getProcessModelByName(process.id,"物料重量");
actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson("物料重量",val,model2.id,index));
}else {
actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson("重量",val,model2.id,index));
}
}else {
NewToastUtil.getInstance().showToastError(name+"液体料工序上传失败");
RecordManager.getInstance().addLogRecord("数据接收", name+"-液体料工序上传失败");
}
}
}else{
String[] wl = item.split("[,]");
if (wl.length == 2) {
String name = wl[0];
String val = wl[1];
BPA_PROCESSModel model = ProcessModelUtil.getProcessModelByName(process.id,name);
actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson(name,val,model.id,index));
index++;
}
}

}
}

technologyActionList.actionJson = actionJson;
technologyActionLists.add(technologyActionList);
}
}
goodsProcessDetail.technologyActionList = technologyActionLists;
goodsProcessDetailList.add(goodsProcessDetail);
}
String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoods";
Post(url,context,goodsProcessDetailList,"商品工艺",(response->{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品工艺成功");
NewToastUtil.getInstance().showToastError("上传商品工艺成功");
WaitProcessUtil.getInstance().Dismiss();
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
WaitProcessUtil.getInstance().Dismiss();
}

}
}

+ 106
- 207
app/src/main/java/com/bonait/bnframework/ui/viewmodel/UpdateDataService.java View File

@@ -8,6 +8,8 @@ import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.business.RecordManager;
import com.bonait.bnframework.common.API.APIHelper;
import com.bonait.bnframework.common.Result.OperateResult;
import com.bonait.bnframework.common.Result.OperateResultT;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.file.DBHelper;
import com.bonait.bnframework.common.db.mode.BPA_ATTRIBUTE;
@@ -27,6 +29,8 @@ import com.bonait.bnframework.common.db.util.MaterialUtil;
import com.bonait.bnframework.common.db.util.ProcessModelUtil;
import com.bonait.bnframework.common.db.util.SubAttributeDBUtil;
import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil;
import com.bonait.bnframework.common.helper.I.IRun;
import com.bonait.bnframework.common.helper.I.IRunT;
import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback;
import com.bonait.bnframework.common.model.upload.ProcessModelBean;
import com.bonait.bnframework.common.model.upload.GoodsDataInfo;
@@ -76,6 +80,7 @@ public class UpdateDataService {
if(good!=null){
//等待弹窗
try{
WaitProcessUtil.getInstance().Show(context,"商品上传","准备上传商品,请耐心稍等...");
if(isDownProcessModel){
upLoadMaterial(good.id,context,null);
}else {
@@ -101,7 +106,8 @@ public class UpdateDataService {
try{
String url = "http://"+path+"/api/ExternalPlatform/Device/GetDeviceTechnology";
if(context!=null){
WaitProcessUtil.getInstance().show(context,"匹配工艺模型","正在同步云端工艺模型...");
// WaitProcessUtil.getInstance().show(context,"匹配工艺模型","正在同步云端工艺模型...");
WaitProcessUtil.getInstance().Show("正在同步云端工艺模型...");
}
HashMap<String,String> params = new HashMap<>();
params.put("autokey",ConfigName.getInstance().DeviceAutoKey);
@@ -185,7 +191,7 @@ public class UpdateDataService {
isDownProcessModel = true;
EventBus.getDefault().post(new FreshSystemSeason());
if(context!=null){
WaitProcessUtil.getInstance().dismiss();
WaitProcessUtil.getInstance().Dismiss();
}
}

@@ -193,7 +199,7 @@ public class UpdateDataService {
public void onError(Response<ProcessModelBean> response) {
super.onError(response);
if(context!=null){
WaitProcessUtil.getInstance().dismiss();
WaitProcessUtil.getInstance().Dismiss();
}
NewToastUtil.getInstance().showToastError("下载工艺模型失败 "+response.message());
LogUtils.d("下载工艺模型失败 "+response.message());
@@ -206,6 +212,59 @@ public class UpdateDataService {

}

/**
* 接口请求数据的验证
* @param response 接口返回的消息体
* @param typeInfo 接口请求提示的消息类型
* @param url 接口请求的Url
* @return
*/
private static OperateResult Analysis(Context context,Response<UploadRes<UpResData>> response,String typeInfo,String url){
boolean isSuccess = true;
StringBuffer names = new StringBuffer();
String errorMsg ="";
for(UpResData upResData:response.body().data){
if (upResData.code>30000){
isSuccess = false;
names.append(upResData.name);
errorMsg=upResData.message;
}
}
if(!isSuccess){
NewToastUtil.getInstance().showToastError(errorMsg+"-"+names.toString());
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传"+typeInfo+"失败-重复数据-"+names);
WaitProcessUtil.getInstance().Dismiss(context,"上传"+typeInfo+"失败",errorMsg);
return OperateResult.CreateFailed("");
}else{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传"+typeInfo+"成功");
NewToastUtil.getInstance().showToast("上传物料信息成功");
return OperateResult.CreateSuccess();
}

}

private static void Post(String url, Context context, Object data, String typeInfo, IRunT<Response<UploadRes<UpResData>>> Success){
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
OkGo.<UploadRes<UpResData>>post(url)
.tag(context)
.upRequestBody(RequestBody.create(MediaType.parse("application/json; charset=utf-8"),new Gson().toJson(data)))
.headers(headers)
.execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
@Override
public void onSuccess(Response<UploadRes<UpResData>> response) {
if(Success!=null)Success.Run(response);
}
@Override
public void onError(Response<UploadRes<UpResData>> response) {
super.onError(response);
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传"+typeInfo+"失败");
NewToastUtil.getInstance().showToastError("上传"+typeInfo+"失败:"+response.message());
WaitProcessUtil.getInstance().Dismiss(context,"上传"+typeInfo+"失败",response.message());
}
});
}

/**
* 上传
* @param goodsId
@@ -213,7 +272,8 @@ public class UpdateDataService {
*/
private static void upLoadMaterial(String goodsId,Context context,List<MaterialDataInfo> upMaterialBean){
try{
WaitProcessUtil.getInstance().show(context,"数据上传","正在物料信息,请耐心稍等...");
// WaitProcessUtil.getInstance().show(context,"数据上传","正在物料信息,请耐心稍等...");
WaitProcessUtil.getInstance().Show("正在物料信息,请耐心稍等...");
List<BPA_MATERIAL> materials = MaterialUtil.GetMaterialALL();
if(upMaterialBean==null){
upMaterialBean = new ArrayList<>();
@@ -222,56 +282,17 @@ public class UpdateDataService {
upMaterialBean.add(new MaterialDataInfo(material.id,material.name,"液体料","7b2aced3-db2a-469c-9b08-b85e3f3f1aa8"));
}
String url = "http://"+path+"/api/ExternalPlatform/Material/AddMaterial";
String body = new Gson().toJson(upMaterialBean);
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
LogUtils.d("upLoadMaterial url="+url+" ;key="+key+";sign="+APIHelper.GetSign("",key)+";headers="+headers.toString());
LogUtils.d("upLoadMaterial body="+body);
OkGo.<UploadRes<UpResData>>post(url)
.tag(context)
.upRequestBody(
RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
body))
.headers(headers)
.execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
@Override
public void onSuccess(Response<UploadRes<UpResData>> response) {
LogUtils.d("上传物料信息成功");
boolean isSuccess = true;
List<String> names = new ArrayList<>();
for(UpResData upResData:response.body().data){
if (upResData.message.contains("重复数据")) {
isSuccess = false;
names.add(upResData.name);
}
}
if(!isSuccess){
NewToastUtil.getInstance().showToastError("物料上传失败:重复数据-"+names);
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传物料信息失败-重复数据-"+names);
WaitProcessUtil.getInstance().dismiss();
}else{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传物料信息成功");
NewToastUtil.getInstance().showToast("上传物料信息成功");
upLoadClassifyInfo(goodsId,context);
}
}

@Override
public void onError(Response<UploadRes<UpResData>> response) {
super.onError(response);
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传物料信息失败");
WaitProcessUtil.getInstance().dismiss();
NewToastUtil.getInstance().showToastError("上传物料信息失败 "+response.message());
LogUtils.d("上传物料信息失败 "+response.message());
}
});
Post(url,context,upMaterialBean,"物料信息",(response->{
Analysis(context,response,"物料信息",url).OnSource(()->{
upLoadClassifyInfo(goodsId,context);
});
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}

}


/**
* 商品分类
* @param goodsId
@@ -279,12 +300,12 @@ public class UpdateDataService {
*/
private static void upLoadClassifyInfo(String goodsId,Context context){
try{
WaitProcessUtil.getInstance().show(context,"数据上传","正在上传分类信息,请耐心稍等...");
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传分类信息,请耐心稍等...");
WaitProcessUtil.getInstance().Show("正在上传分类信息,请耐心稍等...");
BPA_GOODS goods = GoodsDBUtil.getById(goodsId);
assert goods != null;
BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(goods.classifyId);
assert classify != null;

List<UpClassifyBean> upClassifyBeans = new ArrayList<>();
UpClassifyBean upClassifyBean = new UpClassifyBean();
upClassifyBean.id = classify.id;
@@ -292,56 +313,17 @@ public class UpdateDataService {
upClassifyBean.sort = 0;
upClassifyBean.remark = "";
upClassifyBeans.add(upClassifyBean);

String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoodsType";
LogUtils.d("upLoadClassifyInfo url ="+url+" upClassifyBeans="+upClassifyBeans.toString());
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
OkGo.<UploadRes<UpResData>>post(url)
.tag(context)
.upRequestBody(
RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
new Gson().toJson(upClassifyBeans)))
.headers(headers)
.execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
@Override
public void onSuccess(Response<UploadRes<UpResData>> response) {
boolean isSuccess = true;
List<String> names = new ArrayList<>();
for(UpResData upResData:response.body().data){
if (upResData.message.contains("重复数据")) {
isSuccess = false;
names.add(upResData.name);
}
}
if(!isSuccess){
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传分类信息失败-重复数据-"+names);
NewToastUtil.getInstance().showToast("上传分类信息失败,云端有相同数据-"+names);
WaitProcessUtil.getInstance().dismiss();
}else{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传分类信息成功");
NewToastUtil.getInstance().showToast("上传分类信息成功");
LogUtils.d("上传分类信息成功");
List<BPA_ATTRIBUTE> attributes = AttributeDBUtil.getByClassify(classify.id);
if (!attributes.isEmpty()){
upLoadAttribute(attributes,goodsId,context);
}else {
upLoadGoodsInfo(goodsId,context);
}
}

}

@Override
public void onError(Response<UploadRes<UpResData>> response) {
super.onError(response);
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传分类信息失败");
NewToastUtil.getInstance().showToastError("上传分类信息失败 "+response.message());
LogUtils.d("上传分类信息失败 "+response.message());
WaitProcessUtil.getInstance().dismiss();

}
});
Post(url,context,upClassifyBeans,"分类信息",(response->{
Analysis(context,response,"分类信息",url).OnSource(()->{
List<BPA_ATTRIBUTE> attributes = AttributeDBUtil.getByClassify(classify.id);
if (!attributes.isEmpty()){
upLoadAttribute(attributes,goodsId,context);
}else {
upLoadGoodsInfo(goodsId,context);
}
});
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}
@@ -356,7 +338,8 @@ public class UpdateDataService {
*/
private static void upLoadAttribute(List<BPA_ATTRIBUTE> attributes,String goodsId,Context context){
try{
WaitProcessUtil.getInstance().show(context,"数据上传","正在上传分类属性信息,请耐心稍等...");
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传分类属性信息,请耐心稍等...");
WaitProcessUtil.getInstance().Show("正在上传分类属性信息,请耐心稍等...");
BPA_GOODS goods = GoodsDBUtil.getById(goodsId);
assert goods != null;
BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(goods.classifyId);
@@ -378,45 +361,11 @@ public class UpdateDataService {
}

String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoodsAttribute";
LogUtils.d("upLoadAttribute url ="+url+" upAttributeBeans="+upAttributeBeans.toString());
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
OkGo.<UploadRes<UpResData>>post(url)
.tag(context)
.upRequestBody(
RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
new Gson().toJson(upAttributeBeans)))
.headers(headers)
.execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
@Override
public void onSuccess(Response<UploadRes<UpResData>> response) {
boolean isSuccess = true;
List<String> names = new ArrayList<>();
for(UpResData upResData:response.body().data){
if (upResData.message.contains("重复数据")) {
isSuccess = false;
names.add(upResData.name);
}
}
if(!isSuccess){
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传分类属性信息失败-重复数据-"+names);
NewToastUtil.getInstance().showToast("上传分类属性信息失败,云端有相同数据-"+names);
WaitProcessUtil.getInstance().dismiss();
}else{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传分类属性信息成功");
LogUtils.d("上传分类属性信息成功 "+response.message());
upLoadGoodsInfo(goodsId,context);
}
}

@Override
public void onError(Response<UploadRes<UpResData>> response) {
super.onError(response);
LogUtils.d("上传分类属性信息失败 "+response.message());
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传分类属性信息失败");
NewToastUtil.getInstance().showToastError("上传分类属性信息失败 "+response.message());
}
});
Post(url,context,upAttributeBeans,"分类属性信息",(response->{
Analysis(context,response,"分类属性信息",url).OnSource(()->{
upLoadGoodsInfo(goodsId,context);
});
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}
@@ -430,7 +379,8 @@ public class UpdateDataService {
*/
private static void upLoadGoodsInfo(String goodsId,Context context){
try{
WaitProcessUtil.getInstance().show(context,"数据上传","正在上传商品信息,请耐心稍等...");
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传商品信息,请耐心稍等...");
WaitProcessUtil.getInstance().Show("正在上传商品信息,请耐心稍等...");
BPA_GOODS goods = GoodsDBUtil.getById(goodsId);
assert goods != null;
BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(goods.classifyId);
@@ -442,46 +392,12 @@ public class UpdateDataService {
classify.name));

String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoods";
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
OkGo.<UploadRes<UpResData>>post(url)
.tag(context)
.upRequestBody(
RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
new Gson().toJson(upMaterialBean)))
.headers(headers)
.execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
@Override
public void onSuccess(Response<UploadRes<UpResData>> response) {
boolean isSuccess = true;
List<String> names = new ArrayList<>();
for(UpResData upResData:response.body().data){
if (upResData.message.contains("重复数据")) {
isSuccess = false;
names.add(upResData.name);
}
}
if(!isSuccess){
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品基础信息失败-重复数据-"+names);
NewToastUtil.getInstance().showToast("上传商品基础信息失败,云端有相同数据-"+names);
WaitProcessUtil.getInstance().dismiss();
}else{
LogUtils.d("上传商品基础信息成功");
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品基础信息成功");
NewToastUtil.getInstance().showToast("上传商品基础信息成功");
upLoadDetailInfo(goodsId,context);
}
}

@Override
public void onError(Response<UploadRes<UpResData>> response) {
super.onError(response);
LogUtils.d("上传商品基础信息失败 "+response.message());
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品基础信息失败");
NewToastUtil.getInstance().showToastError("上传商品基础信息失败 "+response.message());
WaitProcessUtil.getInstance().dismiss();
}
});
Post(url,context,upMaterialBean,"商品基础信息",(response->{
Analysis(context,response,"商品基础信息",url).OnSource(()->{
upLoadDetailInfo(goodsId,context);
});
}));
}catch (Exception e){
LogUtils.d("网络请求异常"+e.getMessage());
}
@@ -495,7 +411,8 @@ public class UpdateDataService {
*/
private static void upLoadDetailInfo(String goodsId,Context context){
try{
WaitProcessUtil.getInstance().show(context,"数据上传","正在上传工艺信息,请耐心稍等...");
// WaitProcessUtil.getInstance().show(context,"数据上传","正在上传工艺信息,请耐心稍等...");
WaitProcessUtil.getInstance().Show("正在上传工艺信息,请耐心稍等...");
BPA_GOODS goods = GoodsDBUtil.getById(goodsId);
assert goods != null;
BPA_GOODS_CLASSIFY classify = GoodsClassifyDBUtil.getById(goods.classifyId);
@@ -570,7 +487,8 @@ public class UpdateDataService {
String name = wl[0];
String val = wl[1];
BPA_PROCESSModel model = ProcessModelUtil.getProcessModelByName(process.id,name);
actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson(name,val,model.id,index));
if(model!=null)
actionJson.add(new GoodsProcessDetail.TechnologyActionList.ActionJson(name,val,model.id,index));
index++;
}
}
@@ -586,36 +504,17 @@ public class UpdateDataService {
goodsProcessDetailList.add(goodsProcessDetail);

String url = "http://"+path+"/api/ExternalPlatform/Goods/AddGoodsTechnologyAction";
LogUtils.d(" upLoadDetailInfo url="+url+" goodsProcessDetailList="+goodsProcessDetailList.toString());
HttpHeaders headers = new HttpHeaders();
headers.put("key", key);
OkGo.<UploadRes<UpResData>>post(url)
.tag(context)
.upRequestBody(
RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
new Gson().toJson(goodsProcessDetailList)))
.headers(headers)
.execute(new JsonDialogCallback<UploadRes<UpResData>>(context) {
@Override
public void onSuccess(Response<UploadRes<UpResData>> response) {
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品工艺成功");
NewToastUtil.getInstance().showToastError("上传商品工艺成功");
WaitProcessUtil.getInstance().dismiss();
}

@Override
public void onError(Response<UploadRes<UpResData>> response) {
super.onError(response);
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品工艺失败");
NewToastUtil.getInstance().showToastError("上传商品工艺失败 "+response.message());
WaitProcessUtil.getInstance().dismiss();
}
});
Post(url,context,goodsProcessDetailList,"商品工艺",(response->{
RecordManager.getInstance().addLogRecord("数据接收", url+"-上传商品工艺成功");
NewToastUtil.getInstance().showToastError("上传商品工艺成功");
WaitProcessUtil.getInstance().Dismiss();
}));
}catch (Exception e){
e.printStackTrace();
LogUtils.d("网络请求异常"+e.getMessage());
WaitProcessUtil.getInstance().Dismiss();
}


}

}

+ 51
- 0
app/src/main/java/com/bonait/bnframework/ui/widget/WaitProcessUtil.java View File

@@ -1,8 +1,11 @@
package com.bonait.bnframework.ui.widget;

import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;

import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.ui.dialog.WaiteProgressDialog;

/**
@@ -44,4 +47,52 @@ public class WaitProcessUtil {
}
});
}

public void dismiss(Context context,String title,String info){
MainApplication.handler.post(()->{
if(progressDialog!=null){
progressDialog.dismiss();
progressDialog = null;
}
AlertDialogUtils.showDialog(context,title,info);
});
}

//region 等待弹框
ProgressDialog progressDialog1;
public void Show(Context context,String title, String message){
MainApplication.handler.post(() -> {
progressDialog1 = new ProgressDialog(context);
progressDialog1.setTitle(title);
progressDialog1.setCancelable(false);
progressDialog1.setMessage(message);
progressDialog1.show();
});
}
public void Show(String info){
if(progressDialog1==null) return;
MainApplication.handler.post(() -> {
progressDialog1.setMessage(info);
Log.i("WaitShow", "Show: "+info);
});
}
public void Dismiss(){
MainApplication.handler.post(() -> {
if(progressDialog1!=null){
progressDialog1.dismiss();
progressDialog1 = null;
}
});
}
public void Dismiss(Context context,String title,String info){
MainApplication.handler.post(()->{
if(progressDialog1!=null){
progressDialog1.dismiss();
progressDialog1 = null;
}
AlertDialogUtils.showDialog(context,title,info);
});
}
//endregion

}

+ 27
- 0
app/src/main/res/drawable/all_edit_btn.xml View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#7FEF5362"
android:radius="-1dp">

<item android:state_pressed="true">
<shape>
<solid android:color="#d4d4d4" />
<corners android:radius="10dp" />
</shape>
</item>

<item android:state_enabled="false">
<shape>
<solid android:color="#d4d4d4" />
<corners android:radius="10dp" />
</shape>
</item>


<item>
<shape>
<solid android:color="#d4d4d4" />
<corners android:radius="10dp" />
</shape>
</item>
</ripple>

+ 132
- 33
app/src/main/res/layout/fragment_local_goods.xml View File

@@ -36,69 +36,106 @@
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>

<!-- <TextView-->
<!-- android:id="@+id/upload_all"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:visibility="gone"-->
<!-- tools:visibility="visible"-->
<!-- android:layout_height="@dimen/dp_70"-->
<!-- android:paddingTop="10dp"-->
<!-- android:paddingBottom="10dp"-->
<!-- android:layout_marginEnd="300dp"-->
<!-- android:paddingStart="10dp"-->
<!-- android:paddingEnd="@dimen/dp_10"-->
<!-- android:layout_marginBottom="5dp"-->
<!-- android:layout_alignParentEnd="true"-->
<!-- android:ellipsize="middle"-->
<!-- android:textSize="@dimen/sp_32"-->
<!-- android:text="@string/btn_updateall"-->
<!-- android:textColor="#823E17"-->
<!-- android:gravity="center"-->
<!-- android:layout_alignParentTop="true"-->
<!-- android:background="@drawable/bg_round15_yellow_btn"/>-->

<!-- <TextView-->
<!-- android:id="@+id/delete_all"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:visibility="gone"-->
<!-- tools:visibility="visible"-->
<!-- android:layout_height="@dimen/dp_70"-->
<!-- android:paddingTop="10dp"-->
<!-- android:paddingBottom="10dp"-->
<!-- android:layout_marginEnd="60dp"-->
<!-- android:paddingStart="10dp"-->
<!-- android:paddingEnd="@dimen/dp_10"-->
<!-- android:layout_marginBottom="5dp"-->
<!-- android:layout_alignParentEnd="true"-->
<!-- android:ellipsize="middle"-->
<!-- android:textSize="@dimen/sp_32"-->
<!-- android:text="@string/btn_deleteall"-->
<!-- android:textColor="#823E17"-->
<!-- android:gravity="center"-->
<!-- android:layout_alignParentTop="true"-->
<!-- android:background="@drawable/bg_round15_yellow_btn"/>-->

<TextView
android:id="@+id/upload_all"
android:id="@+id/allSelectTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
android:layout_height="@dimen/dp_70"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginEnd="250dp"
android:paddingStart="10dp"
android:paddingEnd="@dimen/dp_10"
android:layout_marginBottom="5dp"
android:layout_alignParentEnd="true"
android:ellipsize="middle"
android:layout_marginLeft="20dp"
android:padding="10dp"
android:layout_toRightOf="@id/recycler_classify"
android:textSize="@dimen/sp_32"
android:text="@string/btn_updateall"
android:textColor="#823E17"
android:text="全选"
android:gravity="center"
android:layout_alignParentBottom="true"
android:background="@drawable/bg_round15_yellow_btn"/>
android:layout_alignParentTop="true"/>

<TextView
android:id="@+id/delete_all"
android:id="@+id/CancelTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
android:layout_height="@dimen/dp_70"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginEnd="10dp"
android:paddingStart="10dp"
android:paddingEnd="@dimen/dp_10"
android:layout_marginBottom="5dp"
android:layout_marginRight="20dp"
android:padding="10dp"
android:layout_alignParentEnd="true"
android:ellipsize="middle"
android:textSize="@dimen/sp_32"
android:text="@string/btn_deleteall"
android:textColor="#823E17"
android:text="取消"
android:gravity="center"
android:layout_alignParentBottom="true"
android:background="@drawable/bg_round15_yellow_btn"/>
android:layout_alignParentTop="true"/>

<CheckBox
android:id="@+id/selectCB"
android:layout_width="wrap_content"
android:layout_marginEnd="20dp"
android:buttonTint="@color/gray"
android:checked="true"
android:scaleX="2"
android:scaleY="2"
android:layout_height="@dimen/dp_70"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"/>

<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"
/>
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"
/>
android:background="@color/color3"/>

<androidx.recyclerview.widget.RecyclerView
android:layout_marginLeft="@dimen/dp_21"
android:layout_marginTop="@dimen/dp_3"
android:layout_marginTop="83dp"
android:id="@+id/recycler_goods"
android:layout_width="match_parent"
android:layout_marginBottom="@dimen/dp_85"
android:layout_toRightOf="@id/recycler_classify"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
@@ -106,6 +143,68 @@
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>

<LinearLayout
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:visibility="gone"
tools:visibility="visible"
android:layout_toRightOf="@id/recycler_classify"
android:background="@drawable/all_edit_btn"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp">
<RelativeLayout
android:id="@+id/upload_all"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_centerHorizontal="true">

<ImageView
android:id="@+id/img1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:src="@mipmap/ysc" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_update"
android:layout_toRightOf="@id/img1"
android:layout_centerVertical="true"
android:textColor="@color/black"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/delete_all"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_centerHorizontal="true">

<ImageView
android:id="@+id/img2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:src="@mipmap/ysc1" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_delete"
android:layout_toRightOf="@id/img2"
android:layout_centerVertical="true"
android:textColor="@color/black"
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>

</RelativeLayout>

</com.qmuiteam.qmui.widget.QMUIWindowInsetLayout>

+ 5
- 1
app/src/main/res/layout/item/layout/good_show.xml View File

@@ -39,7 +39,11 @@

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginBottom="0dp">

<RelativeLayout
android:layout_width="match_parent"


+ 29
- 19
app/src/main/res/layout/item/layout/item_local_goods.xml View File

@@ -101,8 +101,18 @@
</RelativeLayout>
</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<CheckBox
android:id="@+id/SelectStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/deep_purple_primary"
android:layout_alignParentRight="true"/>
</RelativeLayout>

<FrameLayout
android:id="@+id/add"
android:visibility="gone"
@@ -124,23 +134,23 @@
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

<!-- <TextView-->
<!-- android:id="@+id/Note_text"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginLeft="5dp"-->
<!-- android:text="时间:185秒"-->
<!-- android:textColor="@color/gray"-->
<!-- android:textSize="10dp"-->
<!-- android:visibility="gone"-->
<!-- tools:ignore="MissingConstraints" />-->
<!-- <TextView-->
<!-- android:id="@+id/Note_text"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginLeft="5dp"-->
<!-- android:text="时间:185秒"-->
<!-- android:textColor="@color/gray"-->
<!-- android:textSize="10dp"-->
<!-- android:visibility="gone"-->
<!-- tools:ignore="MissingConstraints" />-->

<!-- <ImageView-->
<!-- android:id="@+id/sc_image"-->
<!-- android:layout_width="40dp"-->
<!-- android:layout_height="40dp"-->
<!-- android:layout_alignParentRight="true"-->
<!-- android:layout_marginTop="5dp"-->
<!-- android:layout_marginRight="5dp"-->
<!-- android:src="@mipmap/sc_no1" />-->
<!-- <ImageView-->
<!-- android:id="@+id/sc_image"-->
<!-- android:layout_width="40dp"-->
<!-- android:layout_height="40dp"-->
<!-- android:layout_alignParentRight="true"-->
<!-- android:layout_marginTop="5dp"-->
<!-- android:layout_marginRight="5dp"-->
<!-- android:src="@mipmap/sc_no1" />-->
</RelativeLayout>

Loading…
Cancel
Save