diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 45f78a2..388ebd9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,8 @@
+
+
+
+
+ android:exported="false" />
diff --git a/app/src/main/java/com/example/aucma_mes/ChangeActivity.java b/app/src/main/java/com/example/aucma_mes/ChangeActivity.java
index b6a0113..9584046 100644
--- a/app/src/main/java/com/example/aucma_mes/ChangeActivity.java
+++ b/app/src/main/java/com/example/aucma_mes/ChangeActivity.java
@@ -7,6 +7,7 @@ import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
+import android.widget.TextView;
import android.widget.Toast;
import com.example.aucma_mes.base.BaseActivity;
@@ -21,20 +22,25 @@ import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class ChangeActivity extends BaseActivity {
private List list;
public List tagList;
-
+ private TextView barCodeView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityChangeBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_change);
tagList = new ArrayList<>();
binding.setVm(this);
- OkGo.get(url + "/base/productLine/findProductLineList?productLineType=2&stationType=2").tag(this)
- .headers("Authorization", SharedPreferencesUtils.getstring("token", "")).execute(new MyRecultCall(dialog, this) {
+ getSupportActionBar().hide();
+ var tilte = getIntent().getStringExtra("title");
+ binding.setTitle(tilte);
+ barCodeView=binding.changeBoxCode;
+ OkGo.get(url + "/base/productLine/findProductLineList?productLineType=2&stationType=2").tag(this).headers("Authorization", SharedPreferencesUtils.getstring("token", "")).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response response) {
var body = response.body();
@@ -52,19 +58,42 @@ public class ChangeActivity extends BaseActivity {
@Override
protected void sanInfo(String code) {
-
+ barCodeView.setText(code);
}
- private String tag;
+
+
+ private String tag;
+
public void onItemClick(AdapterView> parent, View view, int position, long id) {
tag = tagList.get(position);
productLineCode = list.get(position).getProductLineCode();
Log.e("TAG", "选中工位:" + tag);
}
- private String productLineCode;
- public void changeSubmit(View view){
- SharedPreferencesUtils.putstring("stationName",tag);
- SharedPreferencesUtils.putstring("stationCode",productLineCode);
+
+ private String productLineCode;
+
+ public void changeSubmit(View view) {
+ SharedPreferencesUtils.putstring("stationName", tag);
+ SharedPreferencesUtils.putstring("stationCode", productLineCode);
finish();
}
+
+ public void changeOrderSubmit(View view) {
+ OkGo.post(url + "/api/switchOrders").tag(this)
+ .params("barCode", barCodeView.getText().toString().trim())
+ .params("stationCode", productLineCode)
+ .execute(new MyRecultCall(dialog, this) {
+ @Override
+ public void onSuccess(Response response) {
+ super.onSuccess(response);
+ Result result = response.body();
+ if (result.getCode()==200){
+ barCodeView.setText(null);
+ }
+ Toast.makeText(ChangeActivity.this, result.getMsg(), Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/aucma_mes/HomePageActivity.java b/app/src/main/java/com/example/aucma_mes/HomePageActivity.java
index 60fdfc7..f3dc35f 100644
--- a/app/src/main/java/com/example/aucma_mes/HomePageActivity.java
+++ b/app/src/main/java/com/example/aucma_mes/HomePageActivity.java
@@ -1,22 +1,20 @@
package com.example.aucma_mes;
-import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
-import android.view.View;
import android.widget.Toast;
import com.example.aucma_mes.databinding.ActivityHomePageBinding;
import com.example.aucma_mes.dialog.InfoDialog;
import com.example.aucma_mes.entity.LoginInfoBeen;
+import com.example.aucma_mes.service.MyService;
import com.example.aucma_mes.utils.SharedPreferencesUtils;
import com.example.aucma_mes.vm.User;
import com.google.gson.Gson;
-import com.google.gson.JsonObject;
import java.util.ArrayList;
@@ -25,6 +23,7 @@ public class HomePageActivity extends AppCompatActivity {
private Intent intent;
private ArrayList roles;
private User user;
+ private Intent serviceIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -37,6 +36,7 @@ public class HomePageActivity extends AppCompatActivity {
String json = intent1.getStringExtra("info");
LoginInfoBeen infoBeen = new Gson().fromJson(json, LoginInfoBeen.class);
InfoDialog infoDialog = new InfoDialog(this);
+
try {
user = infoBeen.getUser();
@@ -87,11 +87,13 @@ public class HomePageActivity extends AppCompatActivity {
startActivity(intent);
});
binding.homeButton6.setOnClickListener(v -> {
+ // 切换工位
if (!roles.contains("switch_station")) {
Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show();
return;
}
intent = new Intent(this, ChangeActivity.class);
+ intent.putExtra("title","工位切换");
startActivity(intent);
});
binding.homeButton5.setOnClickListener(v -> {
@@ -104,17 +106,27 @@ public class HomePageActivity extends AppCompatActivity {
return;
}
intent = new Intent(this, UnbindActivity.class);
- intent.putExtra("type",false);
+ intent.putExtra("type", false);
startActivity(intent);
});
binding.homeButton8.setOnClickListener(v -> {
- //sn解绑
+ // sn解绑
if (!roles.contains("unbinding_barCode")) {
Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show();
return;
}
intent = new Intent(this, UnbindActivity.class);
- intent.putExtra("type",true);
+ intent.putExtra("type", true);
+ startActivity(intent);
+ });
+ binding.homeButton9.setOnClickListener(v -> {
+ // 切换订单
+ // if (!roles.contains("switch_order")) {
+ // Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show();
+ // return;
+ // }
+ intent = new Intent(this, ChangeActivity.class);
+ intent.putExtra("title","切换订单");
startActivity(intent);
});
@@ -122,6 +134,10 @@ public class HomePageActivity extends AppCompatActivity {
Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
+
+ serviceIntent = new Intent(this, MyService.class);
+ startService(serviceIntent);
+
}
private String stationName;
@@ -130,7 +146,6 @@ public class HomePageActivity extends AppCompatActivity {
@Override
protected void onResume() {
super.onResume();
-
stationName = SharedPreferencesUtils.getstring("stationName", user.getStationName());
stationCode = SharedPreferencesUtils.getstring("stationCode", user.getStationCode());
@@ -139,7 +154,9 @@ public class HomePageActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
+ // 重置保存数据
SharedPreferencesUtils.putstring("stationName", null);
SharedPreferencesUtils.putstring("stationCode", null);
+ stopService(serviceIntent);// 停止服务
}
}
\ No newline at end of file
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 79b7564..84f1c17 100644
--- a/app/src/main/java/com/example/aucma_mes/MainActivity.java
+++ b/app/src/main/java/com/example/aucma_mes/MainActivity.java
@@ -51,7 +51,6 @@ public class MainActivity extends BaseActivity {
user.setPassword("123456");
getSupportActionBar().hide(); // 隐藏原生标题栏
binding.setUser(user);
-
OkGo.get(url + "/base/teamMembers/getTeamMemberList").tag(this)
.execute(new MyRecultCall(dialog, this) {
@Override
@@ -131,10 +130,10 @@ public class MainActivity extends BaseActivity {
// 登录
public void login(View view) {
- if (!loginState) {
- Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show();
- return;
- }
+ // if (!loginState) {
+ // Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show();
+ // return;
+ // }
String teamCode = user.getTeamCode();
if (teamCode==null||teamCode.isEmpty()) return;
dialog.show();
diff --git a/app/src/main/java/com/example/aucma_mes/base/BaseActivity.java b/app/src/main/java/com/example/aucma_mes/base/BaseActivity.java
index 7f72f5f..7b7c823 100644
--- a/app/src/main/java/com/example/aucma_mes/base/BaseActivity.java
+++ b/app/src/main/java/com/example/aucma_mes/base/BaseActivity.java
@@ -26,8 +26,8 @@ import okhttp3.MediaType;
public abstract class BaseActivity extends AppCompatActivity {
private MyBroad receiver;
- // public static String url="http://192.168.137.1:8080";
- public static String url="http://10.100.72.10:8080";
+ public static String url="http://192.168.137.1:8080";
+ // public static String url="http://10.100.72.10:8080";
public ProgressDialog dialog;
public Gson gson;
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
diff --git a/app/src/main/java/com/example/aucma_mes/service/MyService.java b/app/src/main/java/com/example/aucma_mes/service/MyService.java
new file mode 100644
index 0000000..f5ef9c6
--- /dev/null
+++ b/app/src/main/java/com/example/aucma_mes/service/MyService.java
@@ -0,0 +1,108 @@
+package com.example.aucma_mes.service;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.os.IBinder;
+import android.util.Log;
+
+import androidx.core.app.NotificationCompat;
+
+import com.example.aucma_mes.R;
+import com.example.aucma_mes.base.BaseActivity;
+import com.example.aucma_mes.entity.Result;
+import com.example.aucma_mes.utils.SharedPreferencesUtils;
+import com.google.gson.Gson;
+import com.lzy.okgo.OkGo;
+import com.lzy.okgo.callback.StringCallback;
+import com.lzy.okgo.model.Response;
+
+public class MyService extends Service {
+
+
+ private boolean isRunning = true;
+ private static final int NOTIFICATION_ID = 1;
+ private Gson gson;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ gson=new Gson();
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.e("TAG", "服务启动");
+ startQuery();
+
+ return START_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ Log.e("TAG", "服务停止");
+ isRunning = false;
+ }
+
+ private void startQuery() {
+ Thread queryThread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (isRunning) {
+ // 如果查询结果不为空,则发送通知进行提醒
+
+ OkGo.post(BaseActivity.url+"/api/messageNotifications")
+ .params("userName", SharedPreferencesUtils.getstring("loginName",""))
+ .execute(new StringCallback() {
+ @Override
+ public void onSuccess(Response response) {
+ Result result= gson.fromJson(response.body(), Result.class);
+ if (result.getCode()==200){
+ showNotification(result.getMsg(),null);
+ }
+ }
+ });
+ try {
+ Thread.sleep(180000); // 设置查询间隔
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+ queryThread.start();
+ }
+
+
+ private void showNotification(String title, String content) {
+ NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+
+ // 创建通知渠道(适用于Android 8.0及以上版本)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel channel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT);
+ notificationManager.createNotificationChannel(channel);
+ }
+
+ // 创建通知
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
+ .setSmallIcon(R.mipmap.logo2)
+ .setContentTitle(title)
+ .setContentText(content)
+ // .setStyle(new NotificationCompat.BigTextStyle()
+ // .bigText("这里是非常长的文本内容,可以显示多行文本。"))
+ .setAutoCancel(true);
+
+ // 发送通知
+ notificationManager.notify((int) System.currentTimeMillis(), builder.build());
+ }
+
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_change.xml b/app/src/main/res/layout/activity_change.xml
index f4dea29..e4ab3bc 100644
--- a/app/src/main/res/layout/activity_change.xml
+++ b/app/src/main/res/layout/activity_change.xml
@@ -4,27 +4,67 @@
xmlns:tools="http://schemas.android.com/tools">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:layout_marginEnd="4dp"
+ android:background="@color/white">
+ android:onItemSelected="@{vm.onItemClick}"
+ android:textAlignment="center" />
@@ -52,6 +92,18 @@
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:onClick="changeSubmit"
- android:text="提交"/>
+ android:text="提交"
+ android:visibility='@{title.equals("切换订单")?View.GONE:View.VISIBLE}' />
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_home_page.xml b/app/src/main/res/layout/activity_home_page.xml
index a6d41b3..78c0a6e 100644
--- a/app/src/main/res/layout/activity_home_page.xml
+++ b/app/src/main/res/layout/activity_home_page.xml
@@ -98,6 +98,14 @@
app:layout_columnWeight="1" />
+
+
+