From 48c3b9619d9b20d9da964115d73503615f0e6b63 Mon Sep 17 00:00:00 2001 From: wangh <123456> Date: Wed, 22 Nov 2023 17:45:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20-=20PDA=20mac=20=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/aucma_mes/CheckActivity.java | 52 ++++++++++++------- .../com/example/aucma_mes/MainActivity.java | 36 ++++++++++++- .../example/aucma_mes/entity/RegisterPda.java | 45 ++++++++++++++++ 3 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/com/example/aucma_mes/entity/RegisterPda.java diff --git a/app/src/main/java/com/example/aucma_mes/CheckActivity.java b/app/src/main/java/com/example/aucma_mes/CheckActivity.java index dfa359e..81a8a30 100644 --- a/app/src/main/java/com/example/aucma_mes/CheckActivity.java +++ b/app/src/main/java/com/example/aucma_mes/CheckActivity.java @@ -57,7 +57,7 @@ public class CheckActivity extends BaseActivity implements CheckAdapter.CheckIte listPopupWindow.setAnchorView(binding.selectDefect); listPopupWindow.setOnItemClickListener(this); String stationCode = getIntent().getStringExtra("stationCode"); - /* OkGo.get(url + "/base/qualityInspectionItem/getQualityDefects/" + stationCode).tag(this).headers("Authorization", SharedPreferencesUtils.getstring("token", "")).execute(new MyRecultCall(dialog, this) { + OkGo.get(url + "/base/qualityInspectionItem/getQualityDefects/" + stationCode).tag(this).headers("Authorization", SharedPreferencesUtils.getstring("token", "")).execute(new MyRecultCall(dialog, this) { @Override public void onSuccess(Response response) { super.onSuccess(response); @@ -77,20 +77,21 @@ public class CheckActivity extends BaseActivity implements CheckAdapter.CheckIte } }); - */ OkGo.get(url + "/system/dict/data/type/treatment_measures").tag(this) + OkGo.get(url + "/system/dict/data/type/treatment_measures").tag(this) .headers("Authorization", SharedPreferencesUtils.getstring("token", "")) .execute(new MyRecultCall(dialog, this) { - @Override - public void onSuccess(Response response) { - super.onSuccess(response); - Result body = response.body(); - List dictBeenList = gson.fromJson(gson.toJson(body.getData()), - new TypeToken>() {}.getType()); - - checkViewModel.setDictBeenList(dictBeenList); - } - - }); + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + Result body = response.body(); + List dictBeenList = gson.fromJson(gson.toJson(body.getData()), + new TypeToken>() { + }.getType()); + + checkViewModel.setDictBeenList(dictBeenList); + } + + }); } @Override @@ -112,13 +113,24 @@ public class CheckActivity extends BaseActivity implements CheckAdapter.CheckIte checkViewModel.setOffline(s1); checkViewModel.setList(submitList); checkViewModel.setUserName(SharedPreferencesUtils.getstring("userName", "pda01")); - OkGo.post(url + "/api/checkSubmit").tag(this).headers("Authorization", SharedPreferencesUtils.getstring("token", "")).upRequestBody(RequestBody.create(JSON, gson.toJson(checkViewModel))).execute(new MyRecultCall(dialog, this) { - @Override - public void onSuccess(Response response) { - super.onSuccess(response); - - } - }); + OkGo.post(url + "/api/checkSubmit").tag(this) + .headers("Authorization", SharedPreferencesUtils.getstring("token", "")) + .upRequestBody(RequestBody.create(JSON, gson.toJson(checkViewModel))) + .execute(new MyRecultCall(dialog, this) { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + Result result = response.body(); + if (result.getCode() == 200) { + Toast.makeText(CheckActivity.this, "提交成功", Toast.LENGTH_SHORT).show(); + checkViewModel.setCode(null); + submitList.clear(); + checkAdapter.notifyDataSetChanged(); + } else { + Toast.makeText(CheckActivity.this, result.getMsg(), Toast.LENGTH_SHORT).show(); + } + } + }); } @Override diff --git a/app/src/main/java/com/example/aucma_mes/MainActivity.java b/app/src/main/java/com/example/aucma_mes/MainActivity.java index 833384c..776b062 100644 --- a/app/src/main/java/com/example/aucma_mes/MainActivity.java +++ b/app/src/main/java/com/example/aucma_mes/MainActivity.java @@ -17,9 +17,13 @@ import android.widget.Toast; import com.example.aucma_mes.base.BaseActivity; import com.example.aucma_mes.databinding.ActivityMainBinding; import com.example.aucma_mes.entity.LoginBack; +import com.example.aucma_mes.entity.RegisterPda; +import com.example.aucma_mes.entity.Result; +import com.example.aucma_mes.utils.MyRecultCall; import com.example.aucma_mes.utils.SharedPreferencesUtils; import com.example.aucma_mes.vm.User; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.lzy.okgo.OkGo; import com.lzy.okgo.callback.StringCallback; import com.lzy.okgo.model.Response; @@ -34,7 +38,7 @@ import okhttp3.RequestBody; public class MainActivity extends BaseActivity { private User user; - +private boolean loginState=false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -45,6 +49,31 @@ public class MainActivity extends BaseActivity { getSupportActionBar().hide(); // 隐藏原生标题栏 binding.setUser(user); Toast.makeText(this, getMacAddress()+"可以使用", Toast.LENGTH_SHORT).show(); + OkGo.get(url + "/system/dict/data/type/treatment_measures").tag(this) + .headers("Authorization", SharedPreferencesUtils.getstring("token", "")) + .execute(new MyRecultCall(dialog, this) { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + Result result = response.body(); + if (result.getCode()==200){ + List pdaList=gson.fromJson(gson.toJson( result.getData()),new TypeToken< List>(){}.getType()); + RegisterPda registerPda=new RegisterPda(); + registerPda.setSerialCode(getMacAddress()); + int index = pdaList.indexOf(registerPda); + loginState= index >-1; + if (loginState){ + SharedPreferencesUtils.putstring("pdaName",pdaList.get(index).getPdaName()); + } + + }else { + Toast.makeText(MainActivity.this, result.getMsg(), Toast.LENGTH_SHORT).show(); + } + + } + }); + + } @Override @@ -76,6 +105,11 @@ public class MainActivity extends BaseActivity { return "02:00:00:00:00:00"; // 如果无法获取到有效的MAC地址,返回一个默认值 } public void login(View view) { + if (!loginState) { + Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show(); + return; + } + dialog.show(); MediaType JSON = MediaType.parse("application/json; charset=utf-8"); RequestBody body = RequestBody.create(JSON,gson.toJson(user) ); diff --git a/app/src/main/java/com/example/aucma_mes/entity/RegisterPda.java b/app/src/main/java/com/example/aucma_mes/entity/RegisterPda.java new file mode 100644 index 0000000..ac7e8ee --- /dev/null +++ b/app/src/main/java/com/example/aucma_mes/entity/RegisterPda.java @@ -0,0 +1,45 @@ +package com.example.aucma_mes.entity; + +import java.util.Objects; + +/** + * @author wanghao + * @date 2023/11/22 17:36 + */ +public class RegisterPda { +/* "pdaName": "质检PDA02", + "serialCode": "4c:11:54:36:b7:91",*/ + private String pdaName; + private String serialCode; + + public String getPdaName() { + return pdaName; + } + + public void setPdaName(String pdaName) { + this.pdaName = pdaName; + } + + public String getSerialCode() { + return serialCode; + } + + public void setSerialCode(String serialCode) { + this.serialCode = serialCode; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RegisterPda that = (RegisterPda) o; + + return Objects.equals(serialCode, that.serialCode); + } + + @Override + public int hashCode() { + return serialCode != null ? serialCode.hashCode() : 0; + } +}