diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 203d567..1f2e856 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -100,6 +100,10 @@
+
{
+ public final OkHttpService service = new OkHttpService();
+
+ @Override
+ protected ActivityLoginBinding viewBindingInflate(LayoutInflater inflater) {
+ return ActivityLoginBinding.inflate(inflater);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ XUI.initTheme(this);
+ super.onCreate(savedInstanceState);
+ setupImmersiveMode();
+ initView();
+ }
+ private void setupImmersiveMode() {
+ View decorView = getWindow().getDecorView();
+ int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+ }
+ decorView.setSystemUiVisibility(flags);
+ }
+ public void initView() {
+ initListener();
+ }
+
+ public void initListener() {
+ findViewById(R.id.btn_login).setOnClickListener(v -> {
+ String userName = binding.etUsername.getText().toString();
+ String password = binding.etPassword.getText().toString();
+ checkParameters(userName,password);
+ login(userName, password);
+ });
+ binding.tvForgetPassword.setOnClickListener(view -> XToastUtils.warning("请在后台管理端重置密码!"));
+ }
+
+ private void login(String userName, String password) {
+ ThreadPoolManager.getExecutor().execute(() -> {
+ try {
+ String url = WorkConfig.getPrefixesUrl() + "/auth/login";
+ org.json.JSONObject json = new org.json.JSONObject();
+ json.put("username", userName);
+ json.put("password", password);
+ json.put("verificationCode", "");
+ json.put("code", "");
+ json.put("phoneUuid", "");
+ json.put("uuid", "");
+ json.put("loginType", "USERNAME_PASSWORD");
+ String jsonString = json.toString();
+ Log.i("getPersonMessage jsonString", jsonString);
+ // 定义 JSON 的 MediaType
+ MediaType mediaType = MediaType.parse(AppConstants.MEDIA_TYPE);
+ // 创建 RequestBody
+ RequestBody body = RequestBody.create(mediaType, jsonString);
+ String result = service.httpLoginPost(url, body, this);
+ if (result != null && !result.isEmpty()) {
+ JSONObject jsonObject = JSONObject.parseObject(result);
+ if (jsonObject.getIntValue("code") == 500){
+ runOnUiThread(() -> XToastUtils.error(jsonObject.getString("msg")));
+ return;
+ }
+ runOnUiThread(() -> XToastUtils.success("登录成功"));
+ String data = jsonObject.getString("data");
+ JSONObject dataJson = JSONObject.parseObject(data);
+ AppDatabase.getDatabase(this).loginInfoDao().deleteAll();
+ LoginInfo loginInfo = new LoginInfo();
+ loginInfo.setUserName(userName);
+ loginInfo.setUserPwd(password);
+ loginInfo.setUserId("-1"); // 假设用户ID为1,实际应用中应从服务器获取
+ loginInfo.setPhone("-1"); // 假设手机号为1234567890,实际应用中应从服务器获取
+ loginInfo.setToken(dataJson.getString("access_token")); // 假设令牌为sample_token,实际应用中应从服务器获取
+ AppDatabase.getDatabase(this).loginInfoDao().insert(loginInfo);
+ startActivity(new Intent(this, InitializationActivity.class));
+ finish();
+ } else {
+ XToastUtils.error("登录失败,请检查用户名和密码");
+ }
+ } catch (Exception e) {
+ Log.e("LoginActivity", "Login error: ", e);
+ XToastUtils.error("登录异常,请稍后再试");
+ }
+ });
+ }
+
+ private void checkParameters(String userName, String password) {
+ if (userName.isEmpty()) {
+ XToastUtils.warning("用户名不能为空");
+ return;
+ }
+ if (password.isEmpty()) {
+ XToastUtils.warning("登录密码不能为空");
+ return;
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent ev) {
+ if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+ View v = getCurrentFocus();
+ if (v instanceof EditText) {
+ int[] location = new int[2];
+ v.getLocationOnScreen(location);
+ float x = ev.getRawX() + v.getLeft() - location[0];
+ float y = ev.getRawY() + v.getTop() - location[1];
+ if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) {
+ hideKeyboard(v);
+ }
+ }
+ }
+ return super.dispatchTouchEvent(ev);
+ }
+ private void hideKeyboard(View view) {
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ }
+ }
+}
diff --git a/app/src/main/java/com/bonus/canteen/activity/OperationActivity.java b/app/src/main/java/com/bonus/canteen/activity/OperationActivity.java
index 87c3f54..3800bd6 100644
--- a/app/src/main/java/com/bonus/canteen/activity/OperationActivity.java
+++ b/app/src/main/java/com/bonus/canteen/activity/OperationActivity.java
@@ -1041,6 +1041,10 @@ public class OperationActivity extends BaseActivity {
+ // 在这里执行UI操作,如创建并显示AlertDialog
+ // 使用JSON解析库解析主体内容
+ JSONObject jsonResponse = null;
+ try {
+ String responseBody = response.body().string();
+ jsonResponse = new JSONObject(responseBody);
+ String message = jsonResponse.getString("message");
+ if (message.contains("过期")){
+ XToastUtils.warning("登录过期,请重新登录");
+ Intent intent = new Intent(context, LoginActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ context.startActivity(intent);
+ }
+ } catch (JSONException | IOException e) {
+ e.printStackTrace();
+ }
+ });
} else {
return "";
}
@@ -257,14 +128,61 @@ public class OkHttpService {
}
public String httpPost(String url, RequestBody body, Context context) {
+ try {
+
+ OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
+ .readTimeout(60000, TimeUnit.MILLISECONDS)
+ .build();
+
+ Request request = new Request.Builder().url(url)
+ .addHeader("machine-sn", Objects.requireNonNull(AppUtil.getSn(context)))
+ .addHeader("Authorization", AppDatabase.getDatabase(context).loginInfoDao().getLoginInfoOne().getToken())
+ .post(body).build();
+ Response response = client.newCall(request).execute();
+
+ int statueCode = response.code();
+ Log.e(TAG, statueCode + "");
+ if (statueCode == 200) {
+ String json = response.body().string();
+ Log.e(TAG, "json=" + response.toString());
+ if (!StringHelper.isEmpty(json) && json.contains("OK")) {
+ return json;
+ }
+ return json;
+ }else if (statueCode==401){
+ ThreadPoolManager.executeInUIThread(() -> {
+ // 在这里执行UI操作,如创建并显示AlertDialog
+ // 使用JSON解析库解析主体内容
+ JSONObject jsonResponse = null;
+ try {
+ String responseBody = response.body().string();
+ jsonResponse = new JSONObject(responseBody);
+ String message = jsonResponse.getString("message");
+ if (message.contains("过期")){
+ XToastUtils.warning("登录过期,请重新登录");
+ Intent intent = new Intent(context, LoginActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ context.startActivity(intent);
+ }
+ } catch (JSONException | IOException e) {
+ e.printStackTrace();
+ }
+ });
+ } else {
+ return "";
+ }
+ } catch (Exception e) {
+ Log.i(TAG, e.toString());
+ }
+ return "";
+ }
+ public String httpLoginPost(String url, RequestBody body, Context context) {
try {
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
.readTimeout(60000, TimeUnit.MILLISECONDS)
.build();
Request request = new Request.Builder().url(url)
- .addHeader("Authorization", token)
- .addHeader("machine-sn","2AD2428001118585")
.post(body).build();
Response response = client.newCall(request).execute();
@@ -304,132 +222,6 @@ public class OkHttpService {
}
return "";
}
- public String httpPost(String url, FormBody body) {
- try {
- OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
- .readTimeout(60000, TimeUnit.MILLISECONDS)
- .build();
-
- Request request = new Request.Builder().url(url)
- .post(body).build();
- Response response = client.newCall(request).execute();
-
- int statueCode = response.code();
- Log.e(TAG, statueCode + "");
- if (statueCode == 200) {
- String json = response.body().string();
- Log.e(TAG, "json=" + response.toString());
- if (!StringHelper.isEmpty(json) && json.contains("OK")) {
- return json;
- }
- return json;
- } else {
- return "";
- }
- } catch (Exception e) {
- Log.i(TAG, e.toString());
- }
- return "";
- }
- public String httpPostNoToken(String url, FormBody body) {
- try {
- OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
- .readTimeout(60000, TimeUnit.MILLISECONDS)
- .build();
-
- Request request = new Request.Builder().url(url)
- .post(body).build();
- Response response = client.newCall(request).execute();
-
- int statueCode = response.code();
- Log.e(TAG, statueCode + "");
- if (statueCode == 200) {
- String json = response.body().string();
- Log.e(TAG, "json=" + response.toString());
- if (!StringHelper.isEmpty(json) && json.contains("OK")) {
- return json;
- }
- return json;
- } else {
- return "";
- }
- } catch (Exception e) {
- Log.i(TAG, e.toString());
- }
- return "";
- }
-
- public String httpFilePost(String url, MultipartBody body) {
- try {
- OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
- .readTimeout(60000, TimeUnit.MILLISECONDS)
- .build();
-
- Request request = new Request.Builder().url(url)
- .addHeader("token",token)
- .post(body).build();
- Response response = client.newCall(request).execute();
-
- int statueCode = response.code();
- Log.e(TAG, "statueCode=" + statueCode);
- if (statueCode == 200) {
- String json = response.body().string();
- Log.e(TAG, "json=" + response.toString());
- if (!StringHelper.isEmpty(json) && json.contains("OK")) {
- return json;
- }
- return json;
- } else {
- return "";
- }
- } catch (Exception e) {
- Log.i(TAG, e.toString());
- }
- return "";
- }
-
- public String httpFilePostNoToken(String url, MultipartBody body) {
- try {
- OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
- .readTimeout(60000, TimeUnit.MILLISECONDS)
- .build();
-
- Request request = new Request.Builder().url(url)
- .post(body).build();
- Response response = client.newCall(request).execute();
-
- int statueCode = response.code();
- Log.e(TAG, "statueCode=" + statueCode);
- if (statueCode == 200) {
- String json = response.body().string();
- Log.e(TAG, "json=" + response.toString());
- if (!StringHelper.isEmpty(json) && json.contains("OK")) {
- return json;
- }
- return json;
- } else {
- return "";
- }
- } catch (Exception e) {
- Log.i(TAG, e.toString());
- }
- return "";
- }
-
- public String syncPost(String url, String json) {
- RequestBody body = RequestBody.create(JSON, json);
- Request request = new Request.Builder()
- .url(url)
- .post(body)
-// .addHeader("key", "SonBianDian")
- .build();
- try {
- Response response = getInstance().newCall(request).execute();
- return response.body().string();
- } catch (Exception e) {
- return e.toString();
- }
- }
private OkHttpClient getInstance() {
if (client == null) {
diff --git a/app/src/main/java/com/bonus/canteen/utils/WorkConfig.java b/app/src/main/java/com/bonus/canteen/utils/WorkConfig.java
index 1a7e763..68860d2 100644
--- a/app/src/main/java/com/bonus/canteen/utils/WorkConfig.java
+++ b/app/src/main/java/com/bonus/canteen/utils/WorkConfig.java
@@ -27,7 +27,7 @@ public class WorkConfig {
//本地
// protected static String baseUrl = "http://192.168.0.34:48380/smart-canteen";
// protected static String prefixesUrl = "http://192.168.0.34:48380";
- protected static String baseUrl = "http://192.168.0.244:48380/smart-canteen";
+ protected static String baseUrl = "http://192.168.0.34:48380/smart-canteen";
protected static String prefixesUrl = "http://192.168.0.34:48380";
protected static String fileUrl = "http://192.168.0.244:48380/lnyst/";
protected static String updateUrl = "https://www.baidu.com";
diff --git a/app/src/main/java/com/bonus/canteen/utils/rabbitmq/RabbitMqMqttHelper.java b/app/src/main/java/com/bonus/canteen/utils/rabbitmq/RabbitMqMqttHelper.java
index 9ccd0be..b7c4b37 100644
--- a/app/src/main/java/com/bonus/canteen/utils/rabbitmq/RabbitMqMqttHelper.java
+++ b/app/src/main/java/com/bonus/canteen/utils/rabbitmq/RabbitMqMqttHelper.java
@@ -349,7 +349,7 @@ public class RabbitMqMqttHelper {
.orderDetailsDao().getOrderInfoListByOrderId(orderId, dishesId);
if (orderDetailsInfo != null) {
BigDecimal price = new BigDecimal(orderDetailsInfo.getPrice());
- BigDecimal money = price.multiply(BigDecimal.valueOf(refundNum)).setScale(2, RoundingMode.HALF_UP);
+ BigDecimal money = price.multiply(BigDecimal.valueOf(refundNum)).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
refundMoney = refundMoney.add(money);
// 更新订单详情状态
AppDatabase.getDatabase(context).orderDetailsDao()
diff --git a/app/src/main/res/drawable/edit_text_bg.xml b/app/src/main/res/drawable/edit_text_bg.xml
new file mode 100644
index 0000000..49e6c4c
--- /dev/null
+++ b/app/src/main/res/drawable/edit_text_bg.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_canteen_operation.xml b/app/src/main/res/layout/activity_canteen_operation.xml
index 83d7a75..5ec859c 100644
--- a/app/src/main/res/layout/activity_canteen_operation.xml
+++ b/app/src/main/res/layout/activity_canteen_operation.xml
@@ -411,6 +411,7 @@
diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml
new file mode 100644
index 0000000..69d865f
--- /dev/null
+++ b/app/src/main/res/layout/activity_login.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7a34ccb..5e82214 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -175,4 +175,9 @@
等待支付
+ 请输入用户名
+ 图标
+ 请输入登录密码
+ 忘记密码?
+ 登录