|
|
@@ -8,6 +8,8 @@ import android.os.Handler; |
|
|
|
import android.os.Message; |
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
import com.bonait.bnframework.HBL.APICallback; |
|
|
|
import com.bonait.bnframework.HBL.APIHelper; |
|
|
|
import com.bonait.bnframework.HBL.Dialog.WaitDialog; |
|
|
|
import com.bonait.bnframework.HBL.Task; |
|
|
|
import com.bonait.bnframework.R; |
|
|
@@ -66,6 +68,7 @@ import com.google.gson.Gson; |
|
|
|
import com.lzy.okgo.OkGo; |
|
|
|
import com.lzy.okgo.callback.StringCallback; |
|
|
|
import com.lzy.okgo.model.HttpHeaders; |
|
|
|
import com.lzy.okgo.model.HttpParams; |
|
|
|
import com.lzy.okgo.model.Response; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
@@ -75,6 +78,7 @@ import java.util.Comparator; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
|
|
@@ -258,99 +262,58 @@ public class ConfigData { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
IRun run1; |
|
|
|
IRun run2; |
|
|
|
|
|
|
|
/** |
|
|
|
* 同步商品数据到设备屏幕 |
|
|
|
*/ |
|
|
|
public void DownDataToDevice(Context context, Activity activity){ |
|
|
|
// AtomicBoolean one =new AtomicBoolean(false); |
|
|
|
// AtomicBoolean two = new AtomicBoolean(false); |
|
|
|
// WaitDialog.Show("商品下发","开始下发商品到一号炒锅",context,activity); |
|
|
|
AtomicBoolean one =new AtomicBoolean(false); |
|
|
|
AtomicBoolean two = new AtomicBoolean(false); |
|
|
|
WaitDialog.Show("商品下发","开始下发商品到一号炒锅",context,activity); |
|
|
|
Task.Run(()->{ |
|
|
|
try{ |
|
|
|
// run1=()->{ |
|
|
|
// WaitDialog.AddText("开始下发商品到二号炒锅"); |
|
|
|
// String url1 = "http://" + ConfigName.getInstance().F2HMIAddress+":36000/api/DownGoodsData"; |
|
|
|
// OkGo.<String>post(url1).upJson(new Gson().toJson(new SendData())).tag(this).execute(new StringCallback() { |
|
|
|
// @Override |
|
|
|
// public void onSuccess(Response<String> response) { |
|
|
|
// ToastUtils.info("下发数据到二号设备成功!"); |
|
|
|
// WaitDialog.AddText("下发商品到二号炒锅成功"); |
|
|
|
// two.set(true); |
|
|
|
// if(run2!=null)run2.Run(); |
|
|
|
// } |
|
|
|
// @Override |
|
|
|
// public void onError(Response<String> val){ |
|
|
|
// ToastUtils.info("下发数据到二号设备失败!"); |
|
|
|
// WaitDialog.AddText("下发商品到二号炒锅失败"); |
|
|
|
// Task.Delay(1000); |
|
|
|
// if(run2!=null)run2.Run(); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// |
|
|
|
// }; |
|
|
|
|
|
|
|
// run2=()->{ |
|
|
|
// ConfigName.getInstance().IsChangeGoods=false; |
|
|
|
// if(!one.get()&&!two.get()){ |
|
|
|
// WaitDialog.TimeOut("商品同步到一号、二号炒锅失败!"); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// if(!one.get()){ |
|
|
|
// WaitDialog.TimeOut("商品同步到一号炒锅失败!"); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// if(!two.get()){ |
|
|
|
// WaitDialog.TimeOut("商品同步到二号炒锅失败!"); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// WaitDialog.Dismiss(); |
|
|
|
// }; |
|
|
|
|
|
|
|
String url = "http://" + ConfigName.getInstance().F1HMIAddress+":36000/api/DownGoodsData"; |
|
|
|
OkGo.<String>post(url).upJson(new Gson().toJson(new SendData())).tag(this).execute(new StringCallback() { |
|
|
|
@Override |
|
|
|
public void onSuccess(Response<String> response) { |
|
|
|
ToastUtils.info("下发商品到一号设备成功!"); |
|
|
|
// WaitDialog.AddText("下发商品到一号炒锅成功"); |
|
|
|
// one.set(true); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Response<String> val){ |
|
|
|
ToastUtils.info("下发商品到一号设备失败!"); |
|
|
|
// WaitDialog.AddText("下发商品到一号炒锅失败"); |
|
|
|
// Task.Delay(1000); |
|
|
|
} |
|
|
|
}); |
|
|
|
MediaType JSON = MediaType.parse("application/json; charset=utf-8"); |
|
|
|
RequestBody body = RequestBody.create(JSON, new Gson().toJson(new SendData())); |
|
|
|
okhttp3.Response res = OkGo.<String>post(url).upRequestBody(body).tag(this).execute(); |
|
|
|
if (res.isSuccessful()){ |
|
|
|
WaitDialog.AddText("下发商品到一号设备成功"); |
|
|
|
one.set(true); |
|
|
|
Task.Delay(1000); |
|
|
|
}else{ |
|
|
|
WaitDialog.AddText("下发商品到一号设备失败"); |
|
|
|
Task.Delay(1000); |
|
|
|
} |
|
|
|
|
|
|
|
WaitDialog.AddText("开始下发商品到二号炒锅"); |
|
|
|
Task.Delay(1000); |
|
|
|
String url1 = "http://" + ConfigName.getInstance().F2HMIAddress+":36000/api/DownGoodsData"; |
|
|
|
OkGo.<String>post(url1).upJson(new Gson().toJson(new SendData())).tag(this).execute(new StringCallback() { |
|
|
|
@Override |
|
|
|
public void onSuccess(Response<String> response) { |
|
|
|
Task.Delay(1500); |
|
|
|
ToastUtils.info("下发数据到二号设备成功!"); |
|
|
|
// WaitDialog.AddText("下发商品到二号炒锅成功"); |
|
|
|
// two.set(true); |
|
|
|
// if(run2!=null)run2.Run(); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void onError(Response<String> val){ |
|
|
|
Log.d("DownGoodsData", "onError: "+val.message()+val.code()+val.message()); |
|
|
|
Task.Delay(1500); |
|
|
|
// ToastUtils.info("下发数据到二号设备失败!"); |
|
|
|
// WaitDialog.AddText("下发商品到二号炒锅失败"); |
|
|
|
// if(run2!=null)run2.Run(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
okhttp3.Response res1 = OkGo.<String>post(url1).upRequestBody(body).tag(this).execute(); |
|
|
|
if (res1.isSuccessful()){ |
|
|
|
WaitDialog.AddText("下发商品到二号炒锅成功"); |
|
|
|
two.set(true); |
|
|
|
Task.Delay(1000); |
|
|
|
}else{ |
|
|
|
WaitDialog.AddText("下发商品到二号设备失败"); |
|
|
|
Task.Delay(1000); |
|
|
|
} |
|
|
|
|
|
|
|
if(!one.get() && !two.get()){ |
|
|
|
WaitDialog.TimeOut("下发商品到一号、二号炒锅失败!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(!one.get()){ |
|
|
|
WaitDialog.TimeOut("下发商品到一号炒锅失败"); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(!two.get()){ |
|
|
|
WaitDialog.TimeOut("下发商品到二号炒锅失败"); |
|
|
|
return; |
|
|
|
} |
|
|
|
WaitDialog.Dismiss(); |
|
|
|
}catch (Exception e){ |
|
|
|
// MessageLog.ShowError("下发商品失败!"+e.getMessage()); |
|
|
|
// WaitDialog.TimeOut("下发商品失败"); |
|
|
|
ToastUtils.error("下发商品失败!"+e.getMessage()); |
|
|
|
WaitDialog.TimeOut("下发商品失败"); |
|
|
|
MessageLog.ShowError("下发商品失败,失败信息:"+e.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|