Ver código fonte

完善日志显示,修复黑名单错误

shanmulinxi 2 anos atrás
pai
commit
60d7f2cc5c

+ 3 - 1
app/src/main/java/com/sunwin/visitorapp/db/DatabaseManager.java

@@ -154,7 +154,9 @@ public class DatabaseManager {
         return liteOrm.update(t);
     }
 
-
+    public <T> List<T> query(QueryBuilder<T> cla) {
+        return liteOrm.query(cla);
+    }
     /**
      * 查询 某字段 等于 Value的值
      */

+ 15 - 5
app/src/main/java/com/sunwin/visitorapp/db/LogModel.java

@@ -1,5 +1,6 @@
 package com.sunwin.visitorapp.db;
 
+import com.litesuits.orm.db.annotation.Column;
 import com.litesuits.orm.db.annotation.PrimaryKey;
 import com.litesuits.orm.db.enums.AssignType;
 import com.sunwin.visitorapp.manage.RunDataManage;
@@ -9,16 +10,25 @@ import java.util.Date;
 public class LogModel {
     public enum Type{
 
-        UserLoginIn,UserLoginOut,
-        UserSearch,UserEdit,UserDelete,
-        BlackListSearch,BlackListEdit,BlackListDelete,
-        RoleSearch,RoleEdit,RoleDelete,
+        UserLoginIn("登录"),UserLoginOut("登出"),
+        UserSearch("用户查询"),UserEdit("用户编辑"),UserDelete("用户删除"),
+        BlackListSearch("黑名单查询"),BlackListEdit("黑名单编辑"),BlackListDelete("黑名单删除"),
+        RoleSearch("角色查询"),RoleEdit("角色编辑"),RoleDelete("角色删除");
 
+        private String name;
+        Type(String name){
+            this.name = name;
+        }
+        public String getName() {
+            return name;
+        }
 
     }
     @PrimaryKey(AssignType.AUTO_INCREMENT)
     public long id;
 
+    public final static String Column_Name = "name";
+    @Column(Column_Name)
     public String name;
 
 
@@ -28,7 +38,7 @@ public class LogModel {
 
     public static void AddLog(Type type){
         LogModel model = new LogModel();
-        model.name = RunDataManage.GetLoginUser()!=null?RunDataManage.GetLoginUser().name:"位置";
+        model.name = RunDataManage.GetLoginUser()!=null?RunDataManage.GetLoginUser().name:"未知";
         model.time = new Date().getTime();
         model.type = type;
         DatabaseManager.getInstance().insertNew(model);

+ 2 - 0
app/src/main/java/com/sunwin/visitorapp/fragment/BlackListManageFr.java

@@ -143,6 +143,8 @@ public class BlackListManageFr extends Fragment {
             }
             model.name = editName.getText().toString().trim();
             model.id_card_code = editICCode.getText().toString().trim();
+
+            if(image_uri!=null)
             model.photo = FileUtil.copyToFilesDir(root.getContext(), image_uri);
             DatabaseManager.getInstance().insert(model);
             refreshData();

+ 53 - 0
app/src/main/java/com/sunwin/visitorapp/fragment/LogManageFr.java

@@ -1,25 +1,78 @@
 package com.sunwin.visitorapp.fragment;
 
+import android.annotation.SuppressLint;
+import android.content.Context;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.EditText;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
 import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
 
+import com.litesuits.orm.db.assit.QueryBuilder;
 import com.sunwin.visitorapp.R;
+import com.sunwin.visitorapp.adapter.BaseRecyclerAdapter;
+import com.sunwin.visitorapp.adapter.BaseViewHolder;
+import com.sunwin.visitorapp.db.DatabaseManager;
+import com.sunwin.visitorapp.db.LogModel;
+import com.sunwin.visitorapp.db.RoleModel;
+import com.sunwin.visitorapp.db.UserManagerModel;
+import com.sunwin.visitorapp.utils.TimeUtils;
 
 public class LogManageFr extends Fragment {
 
     private View root;
+    private Context context;
+    private BaseRecyclerAdapter<LogModel> adapter ;
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 
         if(root==null)root = inflater.inflate(R.layout.fr_log_manage,container,false);
+        context = root.getContext();
+        RecyclerView RecyclerBlackList = root.findViewById(R.id.RecyclerLogList);
+        adapter = new BaseRecyclerAdapter<LogModel>() {
+            @Override
+            protected View getLayoutView(ViewGroup parent, int viewType) {
+                return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_loglist,parent,false);
+            }
 
+            @SuppressLint("UseCompatLoadingForDrawables")
+            @Override
+            public void bind(int position, LogModel data, BaseViewHolder holder, int viewType) {
+
+                holder.setText(R.id.TextName,data.name);
+                holder.setText(R.id.TextType, data.type.getName());
+                holder.setText(R.id.TextTime, TimeUtils.stampToTime(data.time));
+
+
+            }
+        };
+        RecyclerBlackList.setAdapter(adapter);
+        RecyclerBlackList.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false));
+//        RecyclerBlackList.addItemDecoration(new RVLinearItemDecoration.Builder(root.getContext()).color(R.color.ColorGray).dashWidth(2).create());
+        refreshData();
+
+        EditText EditSearchKey = root.findViewById(R.id.EditSearchKey);
+        root.findViewById(R.id.ButtonSearch).setOnClickListener(v->{
+            search(EditSearchKey.getText().toString().trim());
+        });
         return root;
     }
+
+    private void refreshData(){
+        adapter.setList(DatabaseManager.getInstance().getQueryAll(LogModel.class));
+    }
+
+    private void search(String key){
+        QueryBuilder<LogModel> q =new QueryBuilder<>(LogModel.class);
+        q.whereEquals(LogModel.Column_Name,key);
+        adapter.setList(DatabaseManager.getInstance().query(q));
+    }
 }

+ 1 - 1
app/src/main/java/com/sunwin/visitorapp/manage/RunDataManage.java

@@ -8,7 +8,7 @@ import com.sunwin.visitorapp.utils.GsonUtil;
 import com.sunwin.visitorapp.utils.SharePrefenceUtils;
 
 public class RunDataManage {
-    private static  String Key_loginUser = "Key_loginUser";
+    private static final String Key_loginUser = "Key_loginUser";
     private static UserManagerModel loginUser;
     private static RoleModel roleModel;
 

+ 33 - 0
app/src/main/res/layout/fr_log_manage.xml

@@ -31,11 +31,13 @@
             android:gravity="center_vertical"
             android:layout_height="wrap_content">
             <EditText
+                android:id="@+id/EditSearchKey"
                 android:layout_width="230dp"
                 android:hint="用户名、IP、行为等"
                 style="@style/StyleInputContent"
                 android:layout_height="wrap_content"/>
             <EditText
+                android:id="@+id/EditSearchStartTime"
                 android:layout_width="150dp"
                 android:hint="开始时间"
                 style="@style/StyleInputContent"
@@ -46,6 +48,7 @@
                 android:text="至"
                 />
             <EditText
+                android:id="@+id/EditSearchEndTime"
                 android:layout_width="150dp"
                 android:hint="结束时间"
                 style="@style/StyleInputContent"
@@ -60,7 +63,37 @@
         </LinearLayout>
     </androidx.constraintlayout.widget.ConstraintLayout>
 
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center_vertical"
+        android:layout_margin="1dp"
+        android:padding="10dp">
+
+        <TextView
+            style="@style/StyleTextContent"
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            android:text="用户名称"
+            />
+        <TextView
+            style="@style/StyleTextContent"
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            android:text="操作类型"
+            />
+        <TextView
+            style="@style/StyleTextContent"
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            android:text="操作时间"
+            />
+
+
+    </LinearLayout>
     <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/RecyclerLogList"
         android:layout_marginVertical="10dp"
         android:layout_width="match_parent"
         android:layout_height="0dp"

+ 34 - 0
app/src/main/res/layout/item_loglist.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:orientation="horizontal"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="center_vertical"
+    android:background="@drawable/border_gary"
+    android:layout_margin="1dp"
+    android:padding="10dp">
+
+    <TextView
+        android:id="@+id/TextName"
+        style="@style/StyleTextContent"
+        android:layout_width="0dp"
+        android:layout_weight="1"
+
+        />
+    <TextView
+        android:id="@+id/TextType"
+        style="@style/StyleTextContent"
+        android:layout_width="0dp"
+        android:layout_weight="1"
+
+        />
+    <TextView
+        android:id="@+id/TextTime"
+        style="@style/StyleTextContent"
+        android:layout_width="0dp"
+        android:layout_weight="1"
+
+        />
+
+</LinearLayout>