修改 入库

idata
wanghao 7 months ago
parent 15779d6ef4
commit 548785eb48

@ -20,6 +20,7 @@ import com.example.beijing_daxing.base.MyRecultCall;
import com.example.beijing_daxing.base.MyResult;
import com.example.beijing_daxing.been.InStoreSelectBody;
import com.example.beijing_daxing.databinding.ActivityInBinding;
import com.example.beijing_daxing.uitls.HexAscii;
import com.example.beijing_daxing.uitls.SharedPreferencesUtils;
import com.example.beijing_daxing.vm.InStoreVM;
import com.lzy.okgo.OkGo;
@ -38,42 +39,54 @@ public class InActivity extends BaseActivity implements AdapterClickCall {
private List<String> epcList;
private ActivityInBinding binding;
private ObservableBoolean checkState;
private List<String> tagList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_in);
vm = new InStoreVM();
binding.setVm(vm);
checkState = new ObservableBoolean();
binding.setCheckState(checkState);
initRequest();
initAdapter();
}
// 初始化适配器
private void initAdapter() {
adapter = new InAdapter(this);
epcList = new ArrayList<>();
tagList = new ArrayList<>();
adapter.setList(epcList);
adapter.setAdapterClickCall(this);
binding.setAdapter(adapter);
checkState=new ObservableBoolean();
binding.setCheckState(checkState);
}
@Override
protected void onResume() {
super.onResume();
setPower(33);
rfidModel.initRFIDModel();
rfidModel.setPower(SharedPreferencesUtils.getInt("powerIn", 33));
}
@Override
protected void sanRfid(List<Reader.TAGINFO> epcs) {
// Log.e("TAG", "sanRfid:" + epcs);
epcs.stream().forEach(t -> {
var epc = Tools.Bytes2HexString(t.EpcId,t.EpcId.length);
@Override
public void epcData(List<Reader.TAGINFO> data) {
super.epcData(data);
data.stream().forEach(t -> {
var epc = Tools.Bytes2HexString(t.EpcId, t.EpcId.length);
if (!epc.substring(0, 8).equals("53574C44")) {
return;
}
if (!epcList.contains(epc)) {
if (!tagList.contains(epc)) {
Log.e("TAG", "sanRfid:" + epc);
if (epc.substring(0,8).equals("53574C44")){
epcList.add(epc);
}
}
tagList.add(epc);
epcList.add(HexAscii.hex2Str(epc));
});
vm.setSanLength(epcList.size());
adapter.notifyDataSetChanged();
@ -85,7 +98,6 @@ public class InActivity extends BaseActivity implements AdapterClickCall {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
// Log.e("TAG", "onSuccess:" + );response.body()
InStoreSelectBody inStoreSelectBody = gson.fromJson(response.body().getData().toString(), InStoreSelectBody.class);
vm.initSelect(inStoreSelectBody.getBaseLocationList(), inStoreSelectBody.getBaseManufacturerList());
}
@ -104,20 +116,18 @@ public class InActivity extends BaseActivity implements AdapterClickCall {
if (binchCode == null || epcList.isEmpty()) return;
vm.setEpcList(epcList);
vm.setSubmitUser(SharedPreferencesUtils.getstring("user", "test"));
OkGo.<MyResult>post(url + "/instore/submit")
.upRequestBody(RequestBody.create(JSON, gson.toJson(vm)))
.execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
Toast.makeText(InActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show();
if (response.body().getCode() == 0) {
finish();
}
}
});
OkGo.<MyResult>post(url + "/instore/submit").upRequestBody(RequestBody.create(JSON, gson.toJson(vm))).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
Toast.makeText(InActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show();
if (response.body().getCode() == 0) {
finish();
}
}
});
}
@ -131,12 +141,11 @@ public class InActivity extends BaseActivity implements AdapterClickCall {
private Runnable runnable = new Runnable() {
@Override
public void run() {
// Log.e("TAG", "发送广播读取RFID");
// sendBroadcast(broadcastIntent);
sanEpc();
rfidModel.sanRFID();
handler.postDelayed(runnable, 50);
}
};
public void instore_check(View view) {
var b = checkState.get();
if (b) {
@ -147,7 +156,7 @@ public class InActivity extends BaseActivity implements AdapterClickCall {
checkState.set(!b);
}
@Override
protected void onDestroy() {
super.onDestroy();

@ -1,9 +1,11 @@
package com.example.beijing_daxing;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.example.beijing_daxing.adapter.InAdapter;
import com.example.beijing_daxing.base.AdapterClickCall;
import com.example.beijing_daxing.base.BaseActivity;
@ -11,6 +13,7 @@ import com.example.beijing_daxing.base.MyRecultCall;
import com.example.beijing_daxing.base.MyResult;
import com.example.beijing_daxing.databinding.ActivityOutBinding;
import com.example.beijing_daxing.been.BaseLocation;
import com.example.beijing_daxing.uitls.HexAscii;
import com.example.beijing_daxing.uitls.SharedPreferencesUtils;
import com.example.beijing_daxing.vm.OutStoreVm;
import com.google.gson.reflect.TypeToken;
@ -28,34 +31,47 @@ public class OutActivity extends BaseActivity implements AdapterClickCall {
private InAdapter adapter;
private OutStoreVm outVm;
private List<String> epcList;
private List<String> tagList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityOutBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_out);
adapter=new InAdapter(this);
epcList=new ArrayList<>();
outVm = new OutStoreVm();
binding.setVm(outVm);
adapter = new InAdapter(this);
epcList = new ArrayList<>();
tagList = new ArrayList<>();
adapter.setList(epcList);
adapter.setAdapterClickCall(this);
binding.setAdapter(adapter);
outVm=new OutStoreVm();
binding.setVm(outVm);
initRequest();
}
@Override
protected void onResume() {
super.onResume();
setPower(17);
rfidModel.initRFIDModel();
rfidModel.setPower(SharedPreferencesUtils.getInt("powerOut", 17));
}
@Override
protected void sanRfid(List<Reader.TAGINFO> epcs) {
epcs.stream().forEach(t -> {
var epc = Tools.Bytes2HexString(t.EpcId,t.EpcId.length);
if (!epcList.contains(epc)) {
if (epc.substring(0,8).equals("53574C44")) {
epcList.add(epc);
}
public void epcData(List<Reader.TAGINFO> data) {
super.epcData(data);
data.stream().forEach(t -> {
var epc = Tools.Bytes2HexString(t.EpcId, t.EpcId.length);
if (!epc.substring(0, 8).equals("53574C44")) {
return;
}
if (tagList.contains(epc)) {
return;
}
tagList.add(epc);
epcList.add(HexAscii.hex2Str(epc));
});
adapter.notifyDataSetChanged();
}
@ -65,35 +81,36 @@ public class OutActivity extends BaseActivity implements AdapterClickCall {
epcList.remove(index);
adapter.notifyDataSetChanged();
}
private void initRequest() {
OkGo.<MyResult>post(url + "/outStore/select").tag(this).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
List<BaseLocation> baseLocationList=gson.fromJson(response.body().getData().toString(), new TypeToken<List<BaseLocation>>(){}.getType());
List<BaseLocation> baseLocationList = gson.fromJson(response.body().getData().toString(), new TypeToken<List<BaseLocation>>() {
}.getType());
outVm.setAreaList(baseLocationList);
}
});
}
public void out_submit(View view) {
String useUser = outVm.getUseUser();
if (useUser == null || epcList.isEmpty()) return;
outVm.setEpcList(epcList);
outVm.setSubmitUser(SharedPreferencesUtils.getstring("user","test"));
OkGo.<MyResult>post(url + "/outStore/submit")
.upRequestBody(RequestBody.create(JSON, gson.toJson(outVm)))
.execute(new MyRecultCall(dialog,this){
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
if (response.body().getCode()==0){
Toast.makeText(OutActivity.this, "提交成功", Toast.LENGTH_SHORT).show();
finish();
}else {
Toast.makeText(OutActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show();
}
}
});
outVm.setSubmitUser(SharedPreferencesUtils.getstring("user", "test"));
OkGo.<MyResult>post(url + "/outStore/submit").upRequestBody(RequestBody.create(JSON, gson.toJson(outVm))).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
if (response.body().getCode() == 0) {
Toast.makeText(OutActivity.this, "提交成功", Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(OutActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show();
}
}
});
}
}

@ -28,6 +28,8 @@ import androidx.core.content.FileProvider;
import com.example.beijing_daxing.R;
import com.example.beijing_daxing.rfid.RFID;
import com.example.beijing_daxing.rfid.impl.Device6109;
import com.google.gson.Gson;
import com.handheld.uhfr.*;
import com.uhf.api.cls.Reader;
@ -43,7 +45,7 @@ import java.util.List;
import okhttp3.MediaType;
public abstract class BaseActivity extends AppCompatActivity {
public abstract class BaseActivity extends AppCompatActivity implements Device6109.EpcDataInterface {
// public static String url = "http://192.168.0.102:8090/api";
// public static String url = "http://192.168.42.239:8090/api";
public static String url = "http://119.45.202.115:8090/api";
@ -53,45 +55,39 @@ public abstract class BaseActivity extends AppCompatActivity {
public UHFRManager uhfLongerManager;
private MediaPlayer mediaPlayer;
public MyReceiver myReceiver;
public Intent broadcastIntent;
@SuppressLint("UnspecifiedRegisterReceiverFlag")
public RFID rfidModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gson = new Gson();
initDialog();
initSan();
broadcastIntent = new Intent("android.rfid.FUN_KEY");
broadcastIntent.putExtra("keydown", false);
myReceiver = new MyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.rfid.FUN_KEY");
registerReceiver(myReceiver, intentFilter);
mediaPlayer = MediaPlayer.create(this, R.raw.msg);
rfidModel=new Device6109(this);
}
@Override
public void epcData(List<Reader.TAGINFO> data) {
}
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
var keydown = intent.getBooleanExtra("keydown", false);
Log.e("TAG", "接收到广播:" + keydown);
if (!keydown) {
// readTime = System.currentTimeMillis();
sanEpc();
rfidModel.sanRFID();
}
}
}
public void sanEpc() {
List<Reader.TAGINFO> strings = uhfLongerManager.tagInventoryRealTime();
// Log.e("TAG", "驱动" + (uhfLongerManager == null));
if (strings == null || strings.isEmpty()) {
return;
}
mediaPlayer.start();
sanRfid(strings);
}
private void initDialog() {
dialog = new ProgressDialog(this);
@ -101,27 +97,7 @@ public abstract class BaseActivity extends AppCompatActivity {
dialog.setMessage("请求网络...");
}
private void initSan() {
myReceiver = new MyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.rfid.FUN_KEY");
registerReceiver(myReceiver, intentFilter);
mediaPlayer = MediaPlayer.create(this, R.raw.msg);
}
public void setPower(int power) {
try {
Reader.READER_ERR readerErr = uhfLongerManager.setPower(power, power);
Log.e("TAG", "setPower:" + readerErr.name());
int[] power1 = uhfLongerManager.getPower();
Log.e("TAG", "readPower:" + power1[0] + "," + power1[1]);
} catch (Exception e) {
}
}
@Override
protected void onDestroy() {
@ -130,8 +106,6 @@ public abstract class BaseActivity extends AppCompatActivity {
}
protected abstract void sanRfid(List<Reader.TAGINFO> epcs);
public static final int CAMERA_PHOTO = 0X02;
public File outputImage;
public Uri img_uri;
@ -143,12 +117,9 @@ public abstract class BaseActivity extends AppCompatActivity {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
outputImage = new File(getExternalCacheDir(), "output_imgage" + format.format(new Date()) + ".jpg");
try {
outputImage.createNewFile();
} catch (IOException e) {
Log.e("TAG", "teke_photo:文件创建错误");
e.printStackTrace();
@ -180,30 +151,6 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
/*
try {
Bitmap bitmap;
InputStream inputStream = getContentResolver().openInputStream(img_uri);
if (inputStream!= null) {
bitmap = BitmapFactory.decodeStream(inputStream);
FileOutputStream outputStream = new FileOutputStream(outputImage);
if (bitmap!= null) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, outputStream);
takePhotoCall(outputImage, bitmap);
outputStream.close();
} else {
Log.e("Error", "Bitmap is null after decoding.");
}
} else {
Log.e("Error", "InputStream is null.");
}
} catch (IOException e) {
Log.e("Error", "Error reading or writing file.", e);
}
*/
Bitmap bitmap = null;
try {
Log.e("TAG", "onActivityResult:" + img_uri.getPath());

@ -3,5 +3,8 @@ package com.example.beijing_daxing.rfid;
public interface RFID {
void initRFIDModel();
void setPower(int power);
void sanRFID();
void close();
}

@ -1,23 +1,29 @@
package com.example.beijing_daxing.rfid.impl;
import android.content.IntentFilter;
import android.media.MediaPlayer;
import android.util.Log;
import com.example.beijing_daxing.R;
import com.example.beijing_daxing.base.BaseActivity;
import com.example.beijing_daxing.base.MyApplication;
import com.example.beijing_daxing.rfid.RFID;
import com.handheld.uhfr.UHFRManager;
import com.uhf.api.cls.Reader;
import java.util.List;
public class Device6109 implements RFID {
private UHFRManager uhfrManager;
private EpcDataInterface epcDataInterface;
public Device6109(EpcDataInterface epcDataInterface) {
this.epcDataInterface = epcDataInterface;
}
public Device6109() {
}
@Override
public void initRFIDModel() {
if (uhfrManager==null){
uhfrManager=UHFRManager.getInstance();
if (uhfrManager == null) {
uhfrManager = UHFRManager.getInstance();
}
uhfrManager.asyncStartReading();
}
@ -28,13 +34,27 @@ public class Device6109 implements RFID {
Log.e("TAG", "setPower:" + readerErr);
}
@Override
public void sanRFID() {
List<Reader.TAGINFO> data = uhfrManager.tagInventoryRealTime();
if (data == null || data.isEmpty()) {
return;
}
epcDataInterface.epcData(data);
}
@Override
public void close() {
if (uhfrManager==null){
return;
if (uhfrManager == null) {
return;
}
uhfrManager.asyncStopReading();
uhfrManager.close();
uhfrManager=null;
uhfrManager = null;
}
public interface EpcDataInterface {
void epcData(List<Reader.TAGINFO> data);
}
}

Loading…
Cancel
Save