添加MQTT接收
This commit is contained in:
parent
6df7e26e28
commit
964760e69d
|
|
@ -74,7 +74,7 @@ public class UpdateBasicData {
|
||||||
int personNum = 0;
|
int personNum = 0;
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put(UPDATE_TIME, "");
|
// json.put(UPDATE_TIME, "");
|
||||||
json.put("type", type);
|
json.put("type", type);
|
||||||
json.put("userId", userId);
|
json.put("userId", userId);
|
||||||
String jsonString = json.toString();
|
String jsonString = json.toString();
|
||||||
|
|
@ -124,7 +124,7 @@ public class UpdateBasicData {
|
||||||
Log.i(TAG, "getFacePhoto: " + time);
|
Log.i(TAG, "getFacePhoto: " + time);
|
||||||
personFaceNum = 0;
|
personFaceNum = 0;
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put(UPDATE_TIME, "");
|
// json.put(UPDATE_TIME, "");
|
||||||
json.put("userId", userId);
|
json.put("userId", userId);
|
||||||
String jsonString = json.toString();
|
String jsonString = json.toString();
|
||||||
Log.i(TAG, "getFacePhoto jsonString: " + jsonString);
|
Log.i(TAG, "getFacePhoto jsonString: " + jsonString);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,21 @@
|
||||||
package com.bonus.canteen.utils.rabbitmq;
|
package com.bonus.canteen.utils.rabbitmq;
|
||||||
|
|
||||||
|
import static com.xuexiang.xutil.XUtil.runOnUiThread;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bonus.canteen.db.AppDatabase;
|
||||||
|
import com.bonus.canteen.db.beans.base.CustPhotoFulInfo;
|
||||||
|
import com.bonus.canteen.db.entity.base.UserInfo;
|
||||||
|
import com.bonus.canteen.face.util.FaceServer;
|
||||||
|
import com.bonus.canteen.service.data.GetBasicDataService;
|
||||||
|
import com.bonus.canteen.service.data.impl.GetBasicDataServiceImp;
|
||||||
|
import com.bonus.canteen.utils.ThreadPoolManager;
|
||||||
import com.bonus.canteen.utils.WorkConfig;
|
import com.bonus.canteen.utils.WorkConfig;
|
||||||
|
|
||||||
import org.eclipse.paho.android.service.MqttAndroidClient;
|
import org.eclipse.paho.android.service.MqttAndroidClient;
|
||||||
|
|
@ -68,10 +79,7 @@ public class RabbitMqMqttHelper {
|
||||||
public void messageArrived(String topic, MqttMessage message) {
|
public void messageArrived(String topic, MqttMessage message) {
|
||||||
String payload = new String(message.getPayload());
|
String payload = new String(message.getPayload());
|
||||||
Log.d(TAG, "Received message: " + payload);
|
Log.d(TAG, "Received message: " + payload);
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
new Handler(Looper.getMainLooper()).postDelayed(() -> handleIncomingMessage(topic, payload), 5000);
|
||||||
// TODO 在主线程中处理消息
|
|
||||||
Log.d(TAG, "Processing message on main thread: " + payload)
|
|
||||||
, 5000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -80,7 +88,54 @@ public class RabbitMqMqttHelper {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
private void handleIncomingMessage(String topic, String payload) {
|
||||||
|
JSONObject jsonObject = JSON.parseObject(payload);
|
||||||
|
if (topic.contains("morning-inspection-device-update-person-config-v4")) {
|
||||||
|
handlePersonConfigUpdate(jsonObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 处理人员配置更新(包含子操作)
|
||||||
|
*/
|
||||||
|
private void handlePersonConfigUpdate(JSONObject json) {
|
||||||
|
checkAndLogUpdate(json, UPDATE_PERSON_PHOTO, "人员信息");
|
||||||
|
checkAndLogUpdate(json, UPDATE_PERSON_PHOTO, "人员照片");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 通用更新检查方法
|
||||||
|
*/
|
||||||
|
private void checkAndLogUpdate(JSONObject json, String field, String desc) {
|
||||||
|
try {
|
||||||
|
if (json.getIntValue(field) > 0 && desc.equals("人员照片")) {
|
||||||
|
ThreadPoolManager.getExecutor().execute(() -> {
|
||||||
|
if (json.getString("type").equals("del")) {
|
||||||
|
int userId = json.getIntValue(field);
|
||||||
|
Log.d(TAG, "userId: " + userId);
|
||||||
|
AppDatabase.getDatabase(context).userDao().delete(new UserInfo(Long.parseLong(String.valueOf(userId))));
|
||||||
|
AppDatabase.getDatabase(context).custPhotoFulDao().delete(new CustPhotoFulInfo(Long.parseLong(String.valueOf(userId))));
|
||||||
|
} else {
|
||||||
|
GetBasicDataService service = new GetBasicDataServiceImp();
|
||||||
|
service.getFacePhoto(json.getString("currentTime"), json.getIntValue(UPDATE_PERSON));
|
||||||
|
}
|
||||||
|
runOnUiThread(() -> FaceServer.getInstance().loadFace(context));
|
||||||
|
});
|
||||||
|
} else if (json.getIntValue(field) > 0 && desc.equals("人员信息")) {
|
||||||
|
ThreadPoolManager.getExecutor().execute(() -> {
|
||||||
|
if (json.getString("type").equals("del")) {
|
||||||
|
int userId = json.getIntValue(field);
|
||||||
|
Log.d(TAG, "userId: " + userId);
|
||||||
|
AppDatabase.getDatabase(context).userDao().delete(new UserInfo(Long.parseLong(String.valueOf(userId))));
|
||||||
|
AppDatabase.getDatabase(context).custPhotoFulDao().delete(new CustPhotoFulInfo(Long.parseLong(String.valueOf(userId))));
|
||||||
|
} else {
|
||||||
|
GetBasicDataService service = new GetBasicDataServiceImp();
|
||||||
|
service.getPersonInfo(json.getString("currentTime"), "user", json.getIntValue(UPDATE_PERSON));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d(TAG, "处理人员配置更新异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
private MqttTraceHandler createMqttTraceHandler() {
|
private MqttTraceHandler createMqttTraceHandler() {
|
||||||
return new MqttTraceHandler() {
|
return new MqttTraceHandler() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -130,7 +185,7 @@ public class RabbitMqMqttHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
subscriptionTopics = new String[]{
|
subscriptionTopics = new String[]{
|
||||||
"device-update-person-config-v4." + tenantId,
|
"morning-inspection-device-update-person-config-v4." + tenantId,
|
||||||
"device-update-info-v4." + tenantId + "." + sn,
|
"device-update-info-v4." + tenantId + "." + sn,
|
||||||
"time-calibration-v4." + tenantId + "." + sn };
|
"time-calibration-v4." + tenantId + "." + sn };
|
||||||
mqttAndroidClient.subscribe(subscriptionTopics, new int[]{1, 1, 1}, null, new IMqttActionListener() {
|
mqttAndroidClient.subscribe(subscriptionTopics, new int[]{1, 1, 1}, null, new IMqttActionListener() {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
android:drawableStart="@drawable/ic_password"
|
android:drawableStart="@drawable/ic_password"
|
||||||
android:paddingStart="0dp"
|
android:paddingStart="0dp"
|
||||||
android:hint="请输入密码"
|
android:hint="请输入密码"
|
||||||
android:text="Bonus$2031"
|
android:text="Bonus$2027"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
tools:ignore="RtlSymmetry" />
|
tools:ignore="RtlSymmetry" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue