From cf38cce77259d1a92f4a7d1292671c23b9573ac7 Mon Sep 17 00:00:00 2001 From: wangh <123456> Date: Tue, 8 Aug 2023 18:22:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E7=89=88=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 11 +- .../java/com/example/pulit/BaseActivity.java | 19 ++ .../java/com/example/pulit/MainActivity.java | 17 +- .../java/com/example/pulit/MyApplication.java | 15 +- .../com/example/pulit/SolventActivity.java | 201 ++++++++++++ .../java/com/example/pulit/X1Activity.java | 179 ++++++++++- .../java/com/example/pulit/X2Activity.java | 189 +++++++++++ .../example/pulit/adapter/ItemAdapter.java | 106 +++++++ .../com/example/pulit/dialog/TipDialog.java | 24 +- .../java/com/example/pulit/entity/Item.java | 83 +++++ .../com/example/pulit/entity/PlanView.java | 297 ++++++++++++++++++ .../java/com/example/pulit/entity/X1.java | 66 ++++ .../com/example/pulit/entity/X1Submit.java | 70 +++++ .../example/pulit/util/MyOkGoCallback.java | 34 ++ .../java/com/example/pulit/util/Resust.java | 59 ++++ app/src/main/res/layout/activity_main.xml | 6 +- app/src/main/res/layout/activity_solvent.xml | 168 ++++++++++ app/src/main/res/layout/activity_x1.xml | 60 ++-- app/src/main/res/layout/activity_x2.xml | 184 +++++++++++ app/src/main/res/layout/dialog_layout.xml | 10 +- app/src/main/res/layout/item_layout.xml | 57 ++++ app/src/main/res/values/styles.xml | 12 +- 23 files changed, 1814 insertions(+), 55 deletions(-) create mode 100644 app/src/main/java/com/example/pulit/SolventActivity.java create mode 100644 app/src/main/java/com/example/pulit/X2Activity.java create mode 100644 app/src/main/java/com/example/pulit/adapter/ItemAdapter.java create mode 100644 app/src/main/java/com/example/pulit/entity/Item.java create mode 100644 app/src/main/java/com/example/pulit/entity/PlanView.java create mode 100644 app/src/main/java/com/example/pulit/entity/X1.java create mode 100644 app/src/main/java/com/example/pulit/entity/X1Submit.java create mode 100644 app/src/main/java/com/example/pulit/util/MyOkGoCallback.java create mode 100644 app/src/main/java/com/example/pulit/util/Resust.java create mode 100644 app/src/main/res/layout/activity_solvent.xml create mode 100644 app/src/main/res/layout/activity_x2.xml create mode 100644 app/src/main/res/layout/item_layout.xml diff --git a/app/build.gradle b/app/build.gradle index 159dc6d..bc54a42 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,6 +43,8 @@ dependencies { // https://mvnrepository.com/artifact/com.android.volley/volley implementation 'com.android.volley:volley:1.2.1' + implementation 'com.lzy.net:okgo:3.0.4' + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 56cc9af..93981a9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,10 @@ + + + + - + android:theme="@style/Theme.PuLiT" + android:usesCleartextTraffic="true"> + + + diff --git a/app/src/main/java/com/example/pulit/BaseActivity.java b/app/src/main/java/com/example/pulit/BaseActivity.java index ab182e0..1840e6f 100644 --- a/app/src/main/java/com/example/pulit/BaseActivity.java +++ b/app/src/main/java/com/example/pulit/BaseActivity.java @@ -1,19 +1,38 @@ package com.example.pulit; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import android.Manifest; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; +import com.android.volley.RequestQueue; +import com.android.volley.toolbox.Volley; +import com.example.pulit.dialog.MyDialog; +import com.example.pulit.dialog.TipDialog; + +import java.text.DecimalFormat; + public abstract class BaseActivity extends AppCompatActivity { private ScanBroadcastReceiver scanBroadcastReceiver; + public RequestQueue mQueue; + public MyDialog dialog; + public DecimalFormat decimalFormat = new DecimalFormat("#.000"); + public TipDialog tipDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); scanBroadcastReceiver = new ScanBroadcastReceiver(); +// mQueue = Volley.newRequestQueue(this); + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_NETWORK_STATE,Manifest.permission.INTERNET}, + 100); + dialog=new MyDialog(this); + tipDialog=new TipDialog(this); } @Override diff --git a/app/src/main/java/com/example/pulit/MainActivity.java b/app/src/main/java/com/example/pulit/MainActivity.java index f318ced..2479eb9 100644 --- a/app/src/main/java/com/example/pulit/MainActivity.java +++ b/app/src/main/java/com/example/pulit/MainActivity.java @@ -17,33 +17,38 @@ import butterknife.OnClick; public class MainActivity extends AppCompatActivity { private SettingIPDialog textDialog; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); - textDialog=new SettingIPDialog(this); + textDialog = new SettingIPDialog(this); String ip = SharedPreferencesUtils.getstring("ip", null); - if (ip==null||ip.isEmpty()){ + if (ip == null || ip.isEmpty()) { Toast.makeText(this, "先设置ip", Toast.LENGTH_SHORT).show(); textDialog.show(); } } - @OnClick({R.id.home_xl_b, R.id.home_xl_t, R.id.home_rj_c, R.id.home_rj_t, R.id.home_setting, R.id.home_back}) public void onClick(View view) { - Intent intent=null; + Intent intent = null; switch (view.getId()) { case R.id.home_xl_b: - intent=new Intent(this,X1Activity.class); + intent = new Intent(this, X2Activity.class); break; case R.id.home_xl_t: + intent = new Intent(this, X1Activity.class); break; case R.id.home_rj_c: + intent = new Intent(this, SolventActivity.class); + intent.putExtra("type", true); break; case R.id.home_rj_t: + intent = new Intent(this, SolventActivity.class); + intent.putExtra("type", false); break; case R.id.home_setting: textDialog.setIpAddress(SharedPreferencesUtils.getstring("ip", null)); @@ -53,7 +58,7 @@ public class MainActivity extends AppCompatActivity { finish(); break; } - if (intent!=null){ + if (intent != null) { startActivity(intent); } } diff --git a/app/src/main/java/com/example/pulit/MyApplication.java b/app/src/main/java/com/example/pulit/MyApplication.java index 7abc431..478c5df 100644 --- a/app/src/main/java/com/example/pulit/MyApplication.java +++ b/app/src/main/java/com/example/pulit/MyApplication.java @@ -4,10 +4,19 @@ import android.app.Application; import com.example.pulit.util.SharedPreferencesUtils; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.cache.CacheEntity; +import com.lzy.okgo.cache.CacheMode; +import com.lzy.okgo.cookie.CookieJarImpl; +import com.lzy.okgo.cookie.store.MemoryCookieStore; +import com.lzy.okgo.https.HttpsUtils; +import com.lzy.okgo.interceptor.HttpLoggingInterceptor; import java.util.concurrent.TimeUnit; import java.util.logging.Level; +import okhttp3.OkHttpClient; + /** * @author: wangh @@ -34,7 +43,7 @@ public class MyApplication extends Application { //OKGO 初始化 private void okGoBase() { - /* OkHttpClient.Builder builder = new OkHttpClient.Builder(); + OkHttpClient.Builder builder = new OkHttpClient.Builder(); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("OkGo"); //log打印级别,决定了log显示的详细程度 loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY); @@ -56,6 +65,8 @@ public class MyApplication extends Application { OkGo.getInstance().init(this).setOkHttpClient(builder.build()) //建议设置OkHttpClient,不设置将使用默认的 .setCacheMode(CacheMode.NO_CACHE) //全局统一缓存模式,默认不使用缓存,可以不传 .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE) //全局统一缓存时间,默认永不过期,可以不传 - .setRetryCount(3);*/ + .setRetryCount(3); + + } } diff --git a/app/src/main/java/com/example/pulit/SolventActivity.java b/app/src/main/java/com/example/pulit/SolventActivity.java new file mode 100644 index 0000000..9d6c427 --- /dev/null +++ b/app/src/main/java/com/example/pulit/SolventActivity.java @@ -0,0 +1,201 @@ +package com.example.pulit; + +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.alibaba.fastjson2.JSONObject; +import com.example.pulit.entity.PlanView; +import com.example.pulit.util.MyOkGoCallback; +import com.example.pulit.util.Resust; +import com.example.pulit.util.SharedPreferencesUtils; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.Response; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import okhttp3.MediaType; +import okhttp3.RequestBody; + +public class SolventActivity extends BaseActivity { + + @BindView(R.id.solvent_title) + TextView solventTitle; + @BindView(R.id.solvent_frist_name) + TextView solventFristName; + @BindView(R.id.solvent_code) + TextView solventCode; + @BindView(R.id.solvent_title_name) + TextView solventTitleName; + @BindView(R.id.solvent_goods_code) + TextView solventGoodsCode; + @BindView(R.id.solvent_goodsName) + TextView solventGoodsName; + @BindView(R.id.solvent_goods) + TextView solventGoods; + @BindView(R.id.solvent_wc) + TextView solventWc; + +// @BindView(R.id.solvent_submit) +// Button solventSubmit; + + private boolean type; + private boolean sanType; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_solvent); + ButterKnife.bind(this); + sanType = true; + type = getIntent().getBooleanExtra("type", true); + if (type) { + solventTitle.setText("物料称重"); + solventFristName.setText("扫描拉缸条码"); + } else { + solventTitle.setText("溶剂投料"); + solventFristName.setText("扫描泵位条码"); + solventTitleName.setText("扫描容器条码"); + } + } + + private PlanView planView; + + @Override + public void scanInfo(String info) { + + if (sanType) { + dialog.show(); + solventCode.setText(info); + selectSup(info); + } else { + try { + checkGoods(info); + } catch (Exception e) { + e.printStackTrace(); + Toast.makeText(this, "条码格式错误", Toast.LENGTH_SHORT).show(); + } + + } + } + + @OnClick({R.id.info_title_back, R.id.solvent_scan, R.id.solvent_submit}) + public void onClick(View view) { + switch (view.getId()) { + case R.id.info_title_back: + finish(); + break; + case R.id.solvent_scan: + super.sanCode(); + break; + case R.id.solvent_submit: + if (planView == null) return; + dialog.show(); + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;"), + JSONObject.toJSONString(planView)); + OkGo.post("http://" + SharedPreferencesUtils.getstring("ip", null) + "/api/Warehouse/ExecPlcState") + .upRequestBody(requestBody) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + dialog.dismiss(); + Toast.makeText(SolventActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show(); + if (response.body().isSuccess()) { + finish(); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + Toast.makeText(SolventActivity.this, "网络请求失败", Toast.LENGTH_SHORT).show(); + } + }); + break; + } + } + + private void selectSup(String info) { + String uri = type ? "/api/Solvent/GetByCylinderCode" : "/api/Solvent/GetByPumpCode"; + OkGo.get("http://" + SharedPreferencesUtils.getstring("ip", null) + uri) + .params("code", info) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + dialog.dismiss(); + if (response.body().isSuccess()) { + planView = JSONObject.parseObject(response.body().getData(), PlanView.class); +// Log.e("TAG", "onSuccess:" + planView.toString()); + solventWc.setText(planView.getSet_Error()+""); + Toast.makeText(SolventActivity.this, "扫描成功", Toast.LENGTH_SHORT).show(); + sanType = false; + } else { + Toast.makeText(SolventActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + } + }); + } + + private void checkGoods(String scanInfo) { + { + solventGoodsCode.setText(scanInfo); + //物料编码 + String goodsCode = scanInfo.substring(0, scanInfo.indexOf("-")); + Log.e("TAG", "scanInfo:" + goodsCode); + planView.setCode(goodsCode); + //品名 + int index = scanInfo.indexOf("-", scanInfo.indexOf("-", scanInfo.indexOf("-") + 1) + 1) + 1; + int endIndex = scanInfo.indexOf("|"); + String goodsName = scanInfo.substring(index, endIndex); + Log.e("TAG", "scanInfo:" + goodsName); + planView.setMaterialName(goodsName); + solventGoodsName.setText(goodsName); + //重量 + String format = decimalFormat.format( + Double.parseDouble( + scanInfo.substring(scanInfo.indexOf("|") + 1, scanInfo.indexOf("kg")) + )); + solventGoods.setText(format); + double weight = Double.parseDouble(format); + + planView.setMaterialWeight(weight); + planView.setWholeMaterial(scanInfo); + double set_weight = planView.getSet_Weight(); + double set_error = planView.getSet_Error(); + if (type) { + //称量只验证重量 + +// double set_weight = planView.getSet_Weight(); +// double set_error = planView.getSet_Error(); + if (set_weight+set_error >= weight && set_weight-set_error <= weight) { + planView.setState(1); + tipDialog.showState(true); + } else { + planView.setState(0); + tipDialog.showState(false); + } + } else { + if (planView.getMaterial_code() .equals(goodsCode) && set_weight+set_error >= weight && set_weight-set_error <= weight) { + planView.setState(1); + tipDialog.showState(true); + } else { + planView.setState(0); + tipDialog.showState(false); + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/pulit/X1Activity.java b/app/src/main/java/com/example/pulit/X1Activity.java index 8e36529..f3c2358 100644 --- a/app/src/main/java/com/example/pulit/X1Activity.java +++ b/app/src/main/java/com/example/pulit/X1Activity.java @@ -1,38 +1,98 @@ package com.example.pulit; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.Toast; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.alibaba.fastjson2.JSONObject; +import com.example.pulit.adapter.ItemAdapter; +import com.example.pulit.entity.Item; +import com.example.pulit.entity.X1; +import com.example.pulit.entity.X1Submit; +import com.example.pulit.util.MyOkGoCallback; +import com.example.pulit.util.Resust; +import com.example.pulit.util.SharedPreferencesUtils; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.Response; + +import java.util.List; + import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import okhttp3.MediaType; +import okhttp3.RequestBody; public class X1Activity extends BaseActivity { @BindView(R.id.x1_code) TextView x1Code; - @BindView(R.id.x1_plan_name) - TextView x1PlanName; + @BindView(R.id.x1_recycler_view) + RecyclerView x1RecyclerView; + + + @BindView(R.id.x1_tong) + TextView x1Tong; @BindView(R.id.x1_goods_code) TextView x1GoodsCode; - @BindView(R.id.x1_goods_name) - TextView x1GoodsName; + @BindView(R.id.x1_goods_Weight) + TextView x1GoodsWeight; + + + private boolean scanStates; + private List items; + private ItemAdapter adapter; + private X1Submit entrySubmit; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_x1); ButterKnife.bind(this); + scanStates = true; + x1RecyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapter = new ItemAdapter(this); } @Override public void scanInfo(String info) { - Toast.makeText(this, info, Toast.LENGTH_SHORT).show(); + Log.e("TAG", "scanInfo:" + info); + if (scanStates) { + x1Code.setText(info); + dialog.show(); + //反应釜查询 + getF(info); + + } else { + x1Tong.setText(info); + if (info.contains("kg")) { + //整包 截取 物料编码 + String goodsCode = info.substring(0, info.indexOf("-")); + + //格式化重量 + String stringFormatWeight = decimalFormat.format( + Double.parseDouble(info.substring(info.indexOf("|") + 1, info.indexOf("kg")))); + + double goodsWeight = Double.parseDouble(stringFormatWeight); + checkItem(goodsCode, goodsWeight, "整包", info); + } else { + //散装、查询接口 + selectGoods(info); + } + + } + + } + @OnClick({R.id.info_title_back, R.id.x1_scan, R.id.x1_submit}) public void onClick(View view) { switch (view.getId()) { @@ -43,7 +103,116 @@ public class X1Activity extends BaseActivity { super.sanCode(); break; case R.id.x1_submit: + if (entrySubmit == null) return; + dialog.show(); + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;"), + JSONObject.toJSONString(entrySubmit)); + OkGo.post("http://" + SharedPreferencesUtils.getstring("ip", null) + "/api/Warehouse/ExecPlcState") + .upRequestBody(requestBody) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + dialog.dismiss(); + Toast.makeText(X1Activity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show(); + if (response.body().isSuccess()) { + finish(); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + } + }); + break; } } + + private String kcode; + private int station; +//查询 釜 + private void getF(String info) { + OkGo.get("http://" + SharedPreferencesUtils.getstring("ip", null) + "/api/Warehouse/GetByCode") + .params("code", info) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + dialog.dismiss(); + if (response.body().isSuccess()) { + X1 x1 = JSONObject.parseObject(response.body().getData(), X1.class); + station = x1.getID();// + kcode = x1.getBarCode();// + items = x1.getChildren(); + adapter.setList(items); + x1RecyclerView.setAdapter(adapter); + scanStates = false;//扫描 + } else { + Toast.makeText(X1Activity.this, "请求失败,条码不正确", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + Toast.makeText(X1Activity.this, "网络请求失败", Toast.LENGTH_SHORT).show(); + } + } + ); + } +//查询散装 + private void selectGoods(String info) { + OkGo.get("http://" + SharedPreferencesUtils.getstring("ip", null) + "/api/Warehouse/GetByBarrelInfo") + .params("code", info) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + if (response.body().isSuccess()) { + JSONObject obj = response.body().getDateObj(); + double goodsWeight = obj.getDoubleValue("Weight"); + String goodsCode = obj.getString("MaterialID"); + checkItem(goodsCode, goodsWeight, "散装", info); + } else { + Toast.makeText(X1Activity.this, "查询失败,条码不正确", Toast.LENGTH_SHORT).show(); + x1GoodsCode.setText(null); + x1GoodsWeight.setText(null); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + } + }); + } + //比对 + private void checkItem(String goodsCode, double goodsWeight, String matType, String info) { + x1GoodsCode.setText(goodsCode); + x1GoodsWeight.setText(goodsWeight + ""); + entrySubmit = new X1Submit(); + Item item = new Item(); + item.setMaterial_Code(goodsCode); + item.setSetWeight(goodsWeight); + if (items.contains(item)) { + entrySubmit.setState(1); + tipDialog.showState(true); + + } else { + tipDialog.showState(false); + entrySubmit.setState(2); + } + entrySubmit.setkCode(kcode); + entrySubmit.setStation(station); + entrySubmit.setMatWeight(goodsWeight); + entrySubmit.setMatCode(goodsCode); + entrySubmit.setMatType(matType); + entrySubmit.setWholePackage(info); + + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/pulit/X2Activity.java b/app/src/main/java/com/example/pulit/X2Activity.java new file mode 100644 index 0000000..3c6551c --- /dev/null +++ b/app/src/main/java/com/example/pulit/X2Activity.java @@ -0,0 +1,189 @@ +package com.example.pulit; + +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +import com.alibaba.fastjson2.JSONObject; +import com.example.pulit.util.MyOkGoCallback; +import com.example.pulit.util.Resust; +import com.example.pulit.util.SharedPreferencesUtils; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.Response; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import okhttp3.MediaType; +import okhttp3.RequestBody; + +public class X2Activity extends BaseActivity { + + @BindView(R.id.x2_code) + TextView x2Code; + @BindView(R.id.x2_plan_code) + TextView x2PlanCode; + @BindView(R.id.x2_goods) + TextView x2Goods; + @BindView(R.id.x2_goods_code) + TextView x2GoodsCode; + @BindView(R.id.x2_plan_name) + TextView x2PlanName; + @BindView(R.id.x2_goods_name) + TextView x2GoodsName; + private boolean sanType; + private int state = 0; + private int Bin_Serial; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_x2); + ButterKnife.bind(this); + sanType = true; + } + + @Override + public void scanInfo(String info) { + if (sanType) { + x2Code.setText(info); + selectSup(info); + } else { + x2Goods.setText(info); + if (info.contains("kg")) { + //整包 截取 + String goodsCode = info.substring(0, info.indexOf("-")); + checkItem(goodsCode); + x2GoodsCode.setText(goodsCode); + int index = info.indexOf("-", info.indexOf("-", info.indexOf("-") + 1) + 1) + 1; + int endIndex = info.indexOf("|"); + String goodsName = info.substring(index, endIndex); + x2GoodsName.setText(goodsName); + } else { + selectGoodsInfo(info); + + } + } + + + } + + private void checkItem(String goodsCode) { + String planCode = x2PlanCode.getText().toString(); + if (planCode.equals(goodsCode)) { + tipDialog.showState(true); + state = 1; + } else { + tipDialog.showState(false); + state = 2; + } + + } + + + @OnClick({R.id.info_title_back, R.id.x2_scan, R.id.x2_submit}) + public void onClick(View view) { + switch (view.getId()) { + case R.id.info_title_back: + finish(); + break; + case R.id.x2_scan: + super.sanCode(); + break; + case R.id.x2_submit: + if (state == 0) return; + dialog.show(); + + OkGo.post("http://" + SharedPreferencesUtils.getstring("ip", null) + "/api/xl_material/ExecPlcCode") + .params("code",Bin_Serial) + .params("state",state) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + dialog.dismiss(); + Toast.makeText(X2Activity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show(); + if (response.body().isSuccess()){ + finish(); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + } + }); + break; + } + } + + private void selectSup(String info) { + dialog.show(); + OkGo.get("http://" + SharedPreferencesUtils.getstring("ip", null) + "/api/xl_material/GetByBinCode") + .params("code", info) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + dialog.dismiss(); + if (response.body().isSuccess()) { + JSONObject obj = response.body().getDateObj(); + x2PlanCode.setText(obj.getString("Material_code")); + Bin_Serial=obj.getInteger("Bin_Serial"); + x2PlanName.setText(obj.getString("Material_Name")); + sanType=false; + } else { + Toast.makeText(X2Activity.this, "请求失败,条码不正确", Toast.LENGTH_SHORT).show(); + x2PlanCode.setText(null); + x2PlanName.setText(null); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + Toast.makeText(X2Activity.this, "网络请求失败", Toast.LENGTH_SHORT).show(); + } + } + ); + + } + + + private void selectGoodsInfo(String info) { + dialog.show(); + OkGo.get("http://" + SharedPreferencesUtils.getstring("ip", null) + "/api/xl_material/GetByMaterialCode") + .params("code", info) + .execute(new MyOkGoCallback() { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + dialog.dismiss(); + if (response.body().isSuccess()) { + JSONObject obj = response.body().getDateObj(); + String material_code = obj.getString("Material_code"); + x2GoodsCode.setText(material_code); + x2GoodsName.setText(obj.getString("Material_name")); + checkItem(material_code); + } else { + Toast.makeText(X2Activity.this, "请求失败,条码不正确", Toast.LENGTH_SHORT).show(); + x2GoodsCode.setText(null); + x2GoodsCode.setText(null); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + dialog.dismiss(); + Toast.makeText(X2Activity.this, "网络请求失败", Toast.LENGTH_SHORT).show(); + } + } + ); + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/pulit/adapter/ItemAdapter.java b/app/src/main/java/com/example/pulit/adapter/ItemAdapter.java new file mode 100644 index 0000000..6bf216d --- /dev/null +++ b/app/src/main/java/com/example/pulit/adapter/ItemAdapter.java @@ -0,0 +1,106 @@ +package com.example.pulit.adapter; + +import android.content.Context; +import android.os.Build; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.pulit.R; +import com.example.pulit.entity.Item; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * @author: wangh + * @description: + * @date: 2019/08/06-08:36 + */ +public class ItemAdapter extends RecyclerView.Adapter { + + + private List list; + private Context mContext; + private LayoutInflater inflater; + + public void setList(List list) { + this.list = list; + } + + public ItemAdapter(Context mContext) { + this.mContext = mContext; + inflater = LayoutInflater.from(mContext); + } + + //创建 + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = inflater.inflate(R.layout.item_layout, parent, false); + return new MyViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + Item been = list.get(position); + holder.index.setText(position+1+""); + holder.code.setText(been.getMaterial_Code()); + holder.name.setText(been.getMaterialName()); + holder.number.setText(been.getSetWeight()+""); + } + + + //没用 + @RequiresApi(api = Build.VERSION_CODES.N) + @Override + public int getItemCount() { + return Optional.ofNullable(list).map(u -> list.size()).orElse(0); + } + + + + + + //刷新 + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull List payloads) { + super.onBindViewHolder(holder, position, payloads); + if (payloads.isEmpty()) { + onBindViewHolder(holder, position); //绑定数据 + } else {//刷新倒计时所在的View + Log.e("test", "刷新倒计时所在的View"); + } + } + + //如果要点击变色必须要写,用来固定view + class MyViewHolder extends RecyclerView.ViewHolder { + + TextView index; + TextView code; + TextView name; + TextView number; + + + public MyViewHolder(View view) { + super(view); + index=view.findViewById(R.id.item_index); + code=view.findViewById(R.id.item_code); + name=view.findViewById(R.id.item_name); + number=view.findViewById(R.id.item_weight); + + } + } + + public interface ItemClikeLitener{ + public void onItemClick(int tag); + } +} diff --git a/app/src/main/java/com/example/pulit/dialog/TipDialog.java b/app/src/main/java/com/example/pulit/dialog/TipDialog.java index 00caa51..42447c6 100644 --- a/app/src/main/java/com/example/pulit/dialog/TipDialog.java +++ b/app/src/main/java/com/example/pulit/dialog/TipDialog.java @@ -3,6 +3,7 @@ package com.example.pulit.dialog; import android.app.Dialog; import android.content.Context; import android.os.Bundle; +import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -11,6 +12,7 @@ import androidx.annotation.NonNull; import com.example.pulit.R; import butterknife.BindView; +import butterknife.ButterKnife; import butterknife.OnClick; @@ -21,12 +23,11 @@ import butterknife.OnClick; */ public class TipDialog extends Dialog { + @BindView(R.id.tip1_state) ImageView tip1State; @BindView(R.id.tip1_info) TextView tip1Info; - private boolean state; - public TipDialog(@NonNull Context context) { super(context, R.style.CustomDialog); @@ -36,10 +37,29 @@ public class TipDialog extends Dialog { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_layout); + ButterKnife.bind(this); + setCanceledOnTouchOutside(false); } @OnClick(R.id.tip1_button) public void onClick() { + dismiss(); + } + + + public void showState(boolean state) { + super.show(); + tip1State.setImageResource(state ? R.mipmap.dialog_yes : R.mipmap.dialog_jingg); + tip1Info.setText(state ? "匹配成功" : "匹配失败"); } + + private void showMsg(boolean state, String msg) { + super.show(); + tip1State.setImageResource(state ? R.mipmap.dialog_yes : R.mipmap.dialog_jingg); + tip1Info.setText(msg); + + } + + } diff --git a/app/src/main/java/com/example/pulit/entity/Item.java b/app/src/main/java/com/example/pulit/entity/Item.java new file mode 100644 index 0000000..c08127a --- /dev/null +++ b/app/src/main/java/com/example/pulit/entity/Item.java @@ -0,0 +1,83 @@ +package com.example.pulit.entity; + +/** + * @author wanghao + * @date 2023/8/7 15:42 + */ +public class Item { + private int ID; + private String MainId; + private String MaterialID; + private String MaterialName; + private String Material_Code; + private double SetWeight; + + public int getID() { + return ID; + } + + public void setID(int ID) { + this.ID = ID; + } + + public String getMainId() { + return MainId; + } + + public void setMainId(String mainId) { + MainId = mainId; + } + + public String getMaterialID() { + return MaterialID; + } + + public void setMaterialID(String materialID) { + MaterialID = materialID; + } + + public String getMaterialName() { + return MaterialName; + } + + public void setMaterialName(String materialName) { + MaterialName = materialName; + } + + public String getMaterial_Code() { + return Material_Code; + } + + public void setMaterial_Code(String material_Code) { + Material_Code = material_Code; + } + + public double getSetWeight() { + return SetWeight; + } + + public void setSetWeight(double setWeight) { + SetWeight = setWeight; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Item item = (Item) o; + + if (Double.compare(item.SetWeight, SetWeight) != 0) return false; + return Material_Code != null ? Material_Code.equals(item.Material_Code) : item.Material_Code == null; + } + + @Override + public int hashCode() { + int result; + long temp; + result = Material_Code != null ? Material_Code.hashCode() : 0; + temp = Double.doubleToLongBits(SetWeight); + result = 31 * result + (int) (temp ^ (temp >>> 32)); + return result; + } +} diff --git a/app/src/main/java/com/example/pulit/entity/PlanView.java b/app/src/main/java/com/example/pulit/entity/PlanView.java new file mode 100644 index 0000000..964d83b --- /dev/null +++ b/app/src/main/java/com/example/pulit/entity/PlanView.java @@ -0,0 +1,297 @@ +package com.example.pulit.entity; + +/** + * @author wanghao + * @date 2023/8/8 13:54 + */ +public class PlanView { + private int Mid;//物料下发排序ID + private String Plan_Id; //计划ID + private int Plan_Num;//计划执行数量 + private int Real_Num;//实际执行数量 + private int Plan_Serial;//计划序号,我拿来传给PLC作为了唯一值 + private String Plan_Date;//计划执行时间 + private int Plan_State;// 计划执行状态 + private String Plan_StateText;//中文状态标识 + private double Plan_TotalError;//合计误差 + private double Plan_TotalWeight;//合计重量 + private String RecipeID;//配方ID + private String Recipe_Serial;//配方序列 + private String Recipe_Name;//配方名称 + private String Version;//版本 + private String Recipe_Verify;//否是在计划中展示 + private double Total_Weight;//配方重量 + private double Total_Error;//配方误差 + private String MaterialID;//物料ID + private String Material_name;//;物料 + private double Set_Weight;//设置重量 + private double Set_Error;//设置误差 + private String Material_code; + private int RMatCode;//物料编码 + + private String Code;//匹配物料编码 + + private String MaterialName;//匹配物料名称 + + private double MaterialWeight;//匹配物料重量 + + private String WholeMaterial; + private int State; + + public int getMid() { + return Mid; + } + + public String getMaterial_code() { + return Material_code; + } + + public void setMaterial_code(String material_code) { + Material_code = material_code; + } + + public void setMid(int mid) { + Mid = mid; + } + + public String getPlan_Id() { + return Plan_Id; + } + + public void setPlan_Id(String plan_Id) { + Plan_Id = plan_Id; + } + + public int getPlan_Num() { + return Plan_Num; + } + + public void setPlan_Num(int plan_Num) { + Plan_Num = plan_Num; + } + + public int getReal_Num() { + return Real_Num; + } + + public void setReal_Num(int real_Num) { + Real_Num = real_Num; + } + + public int getPlan_Serial() { + return Plan_Serial; + } + + public void setPlan_Serial(int plan_Serial) { + Plan_Serial = plan_Serial; + } + + public String getPlan_Date() { + return Plan_Date; + } + + public void setPlan_Date(String plan_Date) { + Plan_Date = plan_Date; + } + + public int getPlan_State() { + return Plan_State; + } + + public void setPlan_State(int plan_State) { + Plan_State = plan_State; + } + + public String getPlan_StateText() { + return Plan_StateText; + } + + public void setPlan_StateText(String plan_StateText) { + Plan_StateText = plan_StateText; + } + + public double getPlan_TotalError() { + return Plan_TotalError; + } + + public void setPlan_TotalError(double plan_TotalError) { + Plan_TotalError = plan_TotalError; + } + + public double getPlan_TotalWeight() { + return Plan_TotalWeight; + } + + public void setPlan_TotalWeight(double plan_TotalWeight) { + Plan_TotalWeight = plan_TotalWeight; + } + + public String getRecipeID() { + return RecipeID; + } + + public void setRecipeID(String recipeID) { + RecipeID = recipeID; + } + + public String getRecipe_Serial() { + return Recipe_Serial; + } + + public void setRecipe_Serial(String recipe_Serial) { + Recipe_Serial = recipe_Serial; + } + + public String getRecipe_Name() { + return Recipe_Name; + } + + public void setRecipe_Name(String recipe_Name) { + Recipe_Name = recipe_Name; + } + + public String getVersion() { + return Version; + } + + public void setVersion(String version) { + Version = version; + } + + public String getRecipe_Verify() { + return Recipe_Verify; + } + + public void setRecipe_Verify(String recipe_Verify) { + Recipe_Verify = recipe_Verify; + } + + public double getTotal_Weight() { + return Total_Weight; + } + + public void setTotal_Weight(double total_Weight) { + Total_Weight = total_Weight; + } + + public double getTotal_Error() { + return Total_Error; + } + + public void setTotal_Error(double total_Error) { + Total_Error = total_Error; + } + + public String getMaterialID() { + return MaterialID; + } + + public void setMaterialID(String materialID) { + MaterialID = materialID; + } + + public String getMaterial_name() { + return Material_name; + } + + public void setMaterial_name(String material_name) { + Material_name = material_name; + } + + public double getSet_Weight() { + return Set_Weight; + } + + public void setSet_Weight(double set_Weight) { + Set_Weight = set_Weight; + } + + public double getSet_Error() { + return Set_Error; + } + + public void setSet_Error(double set_Error) { + Set_Error = set_Error; + } + + public int getRMatCode() { + return RMatCode; + } + + public void setRMatCode(int RMatCode) { + this.RMatCode = RMatCode; + } + + public String getCode() { + return Code; + } + + public void setCode(String code) { + Code = code; + } + + public String getMaterialName() { + return MaterialName; + } + + public void setMaterialName(String materialName) { + MaterialName = materialName; + } + + public double getMaterialWeight() { + return MaterialWeight; + } + + public void setMaterialWeight(double materialWeight) { + MaterialWeight = materialWeight; + } + + public String getWholeMaterial() { + return WholeMaterial; + } + + public void setWholeMaterial(String wholeMaterial) { + WholeMaterial = wholeMaterial; + } + + public int getState() { + return State; + } + + public void setState(int state) { + State = state; + } + + @Override + public String toString() { + return "PlanView{" + + "Mid=" + Mid + + ", Plan_Id='" + Plan_Id + '\'' + + ", Plan_Num=" + Plan_Num + + ", Real_Num=" + Real_Num + + ", Plan_Serial=" + Plan_Serial + + ", Plan_Date='" + Plan_Date + '\'' + + ", Plan_State=" + Plan_State + + ", Plan_StateText='" + Plan_StateText + '\'' + + ", Plan_TotalError=" + Plan_TotalError + + ", Plan_TotalWeight=" + Plan_TotalWeight + + ", RecipeID='" + RecipeID + '\'' + + ", Recipe_Serial='" + Recipe_Serial + '\'' + + ", Recipe_Name='" + Recipe_Name + '\'' + + ", Version='" + Version + '\'' + + ", Recipe_Verify='" + Recipe_Verify + '\'' + + ", Total_Weight=" + Total_Weight + + ", Total_Error=" + Total_Error + + ", MaterialID='" + MaterialID + '\'' + + ", Material_name='" + Material_name + '\'' + + ", Set_Weight=" + Set_Weight + + ", Set_Error=" + Set_Error + + ", RMatCode=" + RMatCode + + ", Code='" + Code + '\'' + + ", MaterialName='" + MaterialName + '\'' + + ", MaterialWeight=" + MaterialWeight + + ", WholeMaterial='" + WholeMaterial + '\'' + + ", State=" + State + + '}'; + } +} diff --git a/app/src/main/java/com/example/pulit/entity/X1.java b/app/src/main/java/com/example/pulit/entity/X1.java new file mode 100644 index 0000000..102fde6 --- /dev/null +++ b/app/src/main/java/com/example/pulit/entity/X1.java @@ -0,0 +1,66 @@ +package com.example.pulit.entity; + +import java.util.List; + +/** + * @author wanghao + * @date 2023/8/7 15:39 + */ +public class X1 { + private int ID; + private String Name; + private String BarCode; + private String CreateTime; + private List Children; + + public int getID() { + return ID; + } + + public void setID(int ID) { + this.ID = ID; + } + + public String getName() { + return Name; + } + + public void setName(String name) { + Name = name; + } + + public String getBarCode() { + return BarCode; + } + + public void setBarCode(String barCode) { + BarCode = barCode; + } + + public String getCreateTime() { + return CreateTime; + } + + public void setCreateTime(String createTime) { + CreateTime = createTime; + } + + public List getChildren() { + return Children; + } + + public void setChildren(List children) { + Children = children; + } + + @Override + public String toString() { + return "X1{" + + "ID=" + ID + + ", Name='" + Name + '\'' + + ", BarCode='" + BarCode + '\'' + + ", CreateTime='" + CreateTime + '\'' + + ", Children=" + Children + + '}'; + } +} diff --git a/app/src/main/java/com/example/pulit/entity/X1Submit.java b/app/src/main/java/com/example/pulit/entity/X1Submit.java new file mode 100644 index 0000000..09a5342 --- /dev/null +++ b/app/src/main/java/com/example/pulit/entity/X1Submit.java @@ -0,0 +1,70 @@ +package com.example.pulit.entity; + +/** + * @author wanghao + * @date 2023/8/8 11:20 + */ +public class X1Submit { + private int station;// 釜工位——主键 + private String kCode;// 投料釜条码 + private String matCode;// 物料条码 + private double matWeight;//物料重量 + private String matType;// 物料类型:整包、散装 + private int state;//状态 0:未扫描 1:匹配 2:报警 +private String wholePackage; + public int getStation() { + return station; + } + + public void setStation(int station) { + this.station = station; + } + + public String getkCode() { + return kCode; + } + + public void setkCode(String kCode) { + this.kCode = kCode; + } + + public String getMatCode() { + return matCode; + } + + public void setMatCode(String matCode) { + this.matCode = matCode; + } + + public double getMatWeight() { + return matWeight; + } + + public void setMatWeight(double matWeight) { + this.matWeight = matWeight; + } + + public String getMatType() { + return matType; + } + + public void setMatType(String matType) { + this.matType = matType; + } + + public int getState() { + return state; + } + + public String getWholePackage() { + return wholePackage; + } + + public void setWholePackage(String wholePackage) { + this.wholePackage = wholePackage; + } + + public void setState(int state) { + this.state = state; + } +} diff --git a/app/src/main/java/com/example/pulit/util/MyOkGoCallback.java b/app/src/main/java/com/example/pulit/util/MyOkGoCallback.java new file mode 100644 index 0000000..77f189a --- /dev/null +++ b/app/src/main/java/com/example/pulit/util/MyOkGoCallback.java @@ -0,0 +1,34 @@ +package com.example.pulit.util; + +import com.alibaba.fastjson2.JSONObject; +import com.lzy.okgo.callback.AbsCallback; +import com.lzy.okgo.model.Response; + +import okhttp3.ResponseBody; + + +/** + * @author wanghao + * @date 2022/9/20 17:26 + */ +public class MyOkGoCallback extends AbsCallback { + + @Override + public void onSuccess(Response response) { + + } + + + + @Override + public Resust convertResponse(okhttp3.Response response) throws Throwable { + ResponseBody body = response.body(); + if (body == null) return null; + + Resust resust = JSONObject.parseObject(body.string(), Resust.class); + + return resust; + } + + +} diff --git a/app/src/main/java/com/example/pulit/util/Resust.java b/app/src/main/java/com/example/pulit/util/Resust.java new file mode 100644 index 0000000..5c0fb96 --- /dev/null +++ b/app/src/main/java/com/example/pulit/util/Resust.java @@ -0,0 +1,59 @@ +package com.example.pulit.util; + + +import com.alibaba.fastjson2.JSONObject; + +/** + * @author wanghao + * @date 2022/9/20 17:22 + */ +public class Resust { + private int status; + private boolean success; + private Object data; + private String msg; + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getData() { + return data.toString(); + } + public JSONObject getDateObj(){ + return (JSONObject)data; + } + + public void setData(Object data) { + this.data = data; + } + + @Override + public String toString() { + return "Resust{" + + "status=" + status + + ", success=" + success + + ", data=" + data + + '}'; + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 637306e..9d619e4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,13 +34,13 @@ android:id="@+id/home_xl_b" style="@style/TabRadioButton" android:drawableTop="@mipmap/home_xl" - android:text="小料补料" /> + android:text="料仓补料" /> + android:text="粉体投料" /> @@ -59,7 +59,7 @@ android:id="@+id/home_rj_c" style="@style/TabRadioButton" android:drawableTop="@mipmap/home_rj" - android:text="溶剂称量" /> + android:text="物料称重" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +