|
@@ -1,25 +1,119 @@
|
|
package com.sunwin.visitorapp.fragment;
|
|
package com.sunwin.visitorapp.fragment;
|
|
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
|
+import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
+import android.os.Environment;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
|
+import android.widget.EditText;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.Nullable;
|
|
|
|
+import androidx.appcompat.app.AlertDialog;
|
|
import androidx.fragment.app.Fragment;
|
|
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.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.ExcelUtil;
|
|
|
|
+import com.sunwin.visitorapp.utils.TimeUtils;
|
|
|
|
+import com.sunwin.visitorapp.utils.ToastUtils;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.Date;
|
|
|
|
|
|
public class LogManageFr extends Fragment {
|
|
public class LogManageFr extends Fragment {
|
|
|
|
|
|
private View root;
|
|
private View root;
|
|
|
|
+ private Context context;
|
|
|
|
+ private BaseRecyclerAdapter<LogModel> adapter ;
|
|
@Nullable
|
|
@Nullable
|
|
@Override
|
|
@Override
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
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);
|
|
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);
|
|
|
|
+ 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());
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ root.findViewById(R.id.ButtonExcelOut).setOnClickListener(v->{
|
|
|
|
+ File sdcard = Environment.getExternalStorageDirectory();
|
|
|
|
+ String path = new File(sdcard.getAbsolutePath()+"/VisitorAppLog").getAbsolutePath();
|
|
|
|
+ String excelFileName = "/日志记录"+TimeUtils.stampToTime(new Date().getTime())+".xls";
|
|
|
|
+ new AlertDialog.Builder(context).setTitle("提示").setMessage("确定导出吗?将"+adapter.getList().size()+"条数据导出到\n"+path+excelFileName).setPositiveButton("确定", (dialog, which) -> {
|
|
|
|
+ OntExcel(path,excelFileName);
|
|
|
|
+ }).setNegativeButton("取消",null).create().show();
|
|
|
|
+
|
|
|
|
+ });
|
|
return root;
|
|
return root;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void OntExcel(String path,String fileName) {
|
|
|
|
+
|
|
|
|
+ new Thread(() -> {
|
|
|
|
+ try {
|
|
|
|
+ File file = new File(path);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ String[] title = {"用户名称", "操作类型", "操作时间"};
|
|
|
|
+ String sheetName = "日志记录";
|
|
|
|
+ String filePaths = file.getAbsolutePath() + fileName;
|
|
|
|
+ ExcelUtil.initExcel(filePaths, sheetName, title);
|
|
|
|
+ ExcelUtil.writeObjListToExcel(adapter.getList(), filePaths, LogManageFr.this.requireActivity());
|
|
|
|
+ LogManageFr.this.requireActivity().runOnUiThread(() -> ToastUtils.showToast("导出成功"));
|
|
|
|
+ return;
|
|
|
|
+ }catch (Exception ig){
|
|
|
|
+ LogManageFr.this.requireActivity().runOnUiThread(() -> ToastUtils.showToast("导出失败"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }).start();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ private void refreshData(){
|
|
|
|
+ adapter.setList(DatabaseManager.getInstance().getQueryAll(LogModel.class));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void search(String key){
|
|
|
|
+ QueryBuilder<LogModel> q =new QueryBuilder<>(LogModel.class);
|
|
|
|
+ q.where(LogModel.Column_Name + " like ?","%"+key+"%")
|
|
|
|
+ .whereAppendOr().where(LogModel.Column_Type+ " like ?","%"+key+"%");
|
|
|
|
+
|
|
|
|
+ adapter.setList(DatabaseManager.getInstance().query(q));
|
|
|
|
+ }
|
|
}
|
|
}
|