ソースを参照

同步提示修改

鸿鹄中学一拖二
pry 3ヶ月前
コミット
f1110f67fc
4個のファイルの変更131行の追加84行の削除
  1. +7
    -0
      app/src/main/java/com/bonait/bnframework/HBL/APICallback.java
  2. +77
    -0
      app/src/main/java/com/bonait/bnframework/HBL/APIHelper.java
  3. +44
    -81
      app/src/main/java/com/bonait/bnframework/business/ConfigData.java
  4. +3
    -3
      app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java

+ 7
- 0
app/src/main/java/com/bonait/bnframework/HBL/APICallback.java ファイルの表示

@@ -0,0 +1,7 @@
package com.bonait.bnframework.HBL;

public interface APICallback {
void onSuccess(String val);

void onFailure(String ErrorMsg);
}

+ 77
- 0
app/src/main/java/com/bonait/bnframework/HBL/APIHelper.java ファイルの表示

@@ -0,0 +1,77 @@
package com.bonait.bnframework.HBL;
import com.bonait.bnframework.common.helper.I.IRun;
import com.bonait.bnframework.common.helper.I.IRunT;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicReference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import okhttp3.Response;

public class APIHelper {
public static void Post(String url, String par, APICallback callback){
HttpURLConnection connection = null;
InputStream inputStream = null;
BufferedReader reader = null;
// StringBuffer buffer = new StringBuffer();
try {
URL requestUrl = new URL(url);
connection = (HttpURLConnection) requestUrl.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler"
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Charset", "UTF-8");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setDoOutput(true);
connection.setDoInput(true);

// 发送请求参数
byte[] outputInBytes = par.getBytes("UTF-8");
OutputStream os = connection.getOutputStream();
os.write(outputInBytes);
os.close();

// 获取响应结果
int statusCode = connection.getResponseCode();

if (statusCode == HttpURLConnection.HTTP_OK) {
inputStream = connection.getInputStream();
String value = new Scanner(inputStream).useDelimiter("\\A").next();
inputStream.close();
if(callback!=null)callback.onSuccess(value);
} else {
if(callback!=null)callback.onFailure("服务器返回错误,状态码:" + statusCode);
}
}catch (Exception e){
if(callback!=null)callback.onFailure("POST 请求异常:"+e.toString());
}finally {
if (connection != null) {
connection.disconnect();
}
}
}

}

+ 44
- 81
app/src/main/java/com/bonait/bnframework/business/ConfigData.java ファイルの表示

@@ -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());
}
});
}


+ 3
- 3
app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java ファイルの表示

@@ -86,7 +86,7 @@ public class BottomNavigationMainActivity extends BaseActivity {

@BindView(R.id.viewpager)
QMUIViewPager viewPager;
Context context;
Context context;
Activity activity;
HttpServer hs;

@@ -174,8 +174,8 @@ Context context;
DialogHelper.showInfo(this,"餐盆到位,请出餐!", AlertDialogButton.OK,null);
PeripheralData.PutBlowComplete=false;
Task.Run(()->{
Task.Delay(3000);
YJDeviceHelper.getInstance().ConveyorLineControl(false);
Task.Delay(3000);
YJDeviceHelper.getInstance().ConveyorLineControl(false);
});
}
};


読み込み中…
キャンセル
保存