我希望以这样的方式存储员工的出勤率,以便我可以使用firebase数据库 - Android获得每月出勤率

时间:2018-03-19 17:10:33

标签: android firebase firebase-realtime-database

Johnson's algorithm

我是新来的,我也不知道如何发帖,但不好解释我的要求

将数据存储在firebase数据库中 我想以两种方式获取数据 日期和月度

1 个答案:

答案 0 :(得分:0)

如果我的问题正确,您可以检索每天关于员工的数据,但您想知道员工每月在场的天数。也许是这样的:

     DatabaseReference employees_ref=FirebaseDatabase.getInstance().getReference().child("EmployeesAttendance").child(Employee_uid).child("2018").child("March");

     employees_Ref.addListenerForSingleValueEvent(new Value....{

        onDataChanged(DataSnapshot datasnapshot){

          //get the number of days that employees where present in march
          int number_days_present_march=datasnapshot.getChildrenCount();



         }  


      }); 

修改

我想你现在想要的是知道员工x何时出现以及他/她何时离开(或缺席)。

为此,当他/她在这里以及他们离开时,你必须得到你想要的每一天。

  • 例如:

让我说我想知道员工x何时来,他什么时候离开2018年/ 3月/ 18:

   //get a reference of employee x during 2018/march/18
   Databasereference employee_presence= FirebaseDatabase.getInstance().getReference().child("EmployeesAttendance").child(EmployeeX_uid).child("2018").child("march").child("18");

  //use the reference to know when he was in and when he was out

   employee_presence.addListenerForSingleValueEvent(new Value.....{

    onDatachange(DataSnapshot datasnapshot){

     //if you stored your date as number (long)
     //get the presence like this:

     long time_in=datasnapshot.child("in_time").getValue(long.class);

     long time_out=datasnapshot.child("out_time").getValue(long.class);

     //show a message

     Toast.makeText(getApplicationContext(), "Employee X was in at"+ String.Valueof(time_in) + "and was out at" + String.Valueof(time_out) ).show();


     //if you stored your date as a string
     //get the presence like this:

     String time_in= datasnapshot.child("time_in").getValue().toString();

     String time_out= datasnapshot.child("time_out").getValue().toString();


      //show a message
     Toast.makeText(getApplicationContext(), "Employee x was in at" +  time_in + "and was out at" + time_out).show();



    }

   });