【第一步】调用企业微信的api接口获取当天的打卡记录

(获取的打卡记录是根据自己提交的时间戳来获取的,我只获取当天的打卡记录,是因为设置了定时器,每天11点自动调用接口插入到数据库)

企业微信api地址

获取数据并分析

分析每一条打卡记录对应什么状态,迟到,早退,未打卡,未连接wifi打卡,外出打卡等。我这里获取了用户id,打卡类型,异常类型,打卡时间,打卡地点,打卡地点详情,打卡wifi名称,打卡规则名称,并且做了判断数据库只存在一个员工当天2条打卡记录,取最早打卡和最晚打卡。

最后呈现的效果如下



由于数据量大,计算有点复杂,导致加载时间需要15s左右,数据由sql存储过程计算获得。
sql代码如下
USE [easyOA]
GO
/****** Object:  StoredProcedure [dbo].[_rqv_p_get_attabel_by_page]    Script Date: 2020/8/13 10:33:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GOALTER proc [dbo].[_rqv_p_get_attabel_by_page]@at_date datetime,@page int,@rows int,@rowcount int output   as
beginif object_id('tempdb..#tmp_lv_re') is not null
begindrop table #tmp_lv_re
end
create table #tmp_lv_re(at_userid nvarchar(100),zc_day int,at_leavetime float,at_leavedata nvarchar(max),w_sdk    int,w_xdk    int,w_sxdk   int,at_cdx   int,at_cdd  int,at_ztx  int,at_ztd  int,a1_1 datetime,s1_1 int, a1_2 datetime,s1_2 int,a2_1 datetime,s2_1 int,a2_2 datetime,s2_2 int,a3_1 datetime,s3_1 int,a3_2 datetime,s3_2 int,a4_1 datetime,s4_1 int,a4_2 datetime,s4_2 int,a5_1 datetime,s5_1 int,a5_2 datetime,s5_2 int,a6_1 datetime,s6_1 int,a6_2 datetime,s6_2 int,a7_1 datetime,s7_1 int,a7_2 datetime,s7_2 int,a8_1 datetime,s8_1 int,a8_2 datetime,s8_2 int,a9_1 datetime,s9_1 int,a9_2 datetime,s9_2 int,a10_1 datetime,s10_1 int,a10_2 datetime,s10_2 int,a11_1 datetime,s11_1 int,a11_2 datetime,s11_2 int,a12_1 datetime,s12_1 int,a12_2 datetime,s12_2 int,a13_1 datetime,s13_1 int,a13_2 datetime,s13_2 int,a14_1 datetime,s14_1 int,a14_2 datetime,s14_2 int,a15_1 datetime,s15_1 int,a15_2 datetime,s15_2 int,a16_1 datetime,s16_1 int,a16_2 datetime,s16_2 int,a17_1 datetime,s17_1 int,a17_2 datetime,s17_2 int,a18_1 datetime,s18_1 int,a18_2 datetime,s18_2 int,a19_1 datetime,s19_1 int,a19_2 datetime,s19_2 int,a20_1 datetime,s20_1 int,a20_2 datetime,s20_2 int,a21_1 datetime,s21_1 int,a21_2 datetime,s21_2 int,a22_1 datetime,s22_1 int,a22_2 datetime,s22_2 int,a23_1 datetime,s23_1 int,a23_2 datetime,s23_2 int,a24_1 datetime,s24_1 int,a24_2 datetime,s24_2 int,a25_1 datetime,s25_1 int,a25_2 datetime,s25_2 int,a26_1 datetime,s26_1 int,a26_2 datetime,s26_2 int,a27_1 datetime,s27_1 int,a27_2 datetime,s27_2 int,a28_1 datetime,s28_1 int,a28_2 datetime,s28_2 int,a29_1 datetime,s29_1 int,a29_2 datetime,s29_2 int,a30_1 datetime,s30_1 int,a30_2 datetime,s30_2 int,a31_1 datetime,s31_1 int,a31_2 datetime,s31_2 int)declare @at_userid nvarchar(50)declare @at_username nvarchar(20)
declare @zc_day int
declare @at_leavetime float
declare @at_leavedata nvarchar(max)
declare @w_sdk   int
declare @w_xdk   int
declare @w_sxdk  int
declare @at_cdx     int
declare @at_cdd     int
declare @at_ztx     int
declare @at_ztd     intdeclare my_cur_t1 cursor
for
select distinct at_userid
from dbo._rqv_attendance
where 1=1 --这里是时间条件open my_cur_t1
fetch next from my_cur_t1 into @at_userid while @@FETCH_STATUS = 0
begininsert into #tmp_lv_re(at_userid)values(@at_userid)--正常出勤select @zc_day= isnull(count(*),0) from  _rqv_attendance where  at_checkin_type ='上班打卡' and  at_userid=@at_userid  and at_state not in (2,3,4,5,10)and  DATEPART(Day,at_checkin_time) in (select DATEPART(Day,at_checkin_time) from  _rqv_attendance  where  at_checkin_type ='下班打卡' and  at_userid=@at_userid and at_state not in (2,3,4,5,10))and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date) --请假时长(同意且已结束的请假)select @at_leavetime=isnull(sum(l.le_times),0) from(select e_id from  employee where e_openid=@at_userid) eleft join _rqv_leapplication l on e.e_id= l.le_emid and l.le_state=2 and le_agree_not=1and  DATEPART(year,l.le_creat_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,l.le_creat_time)=DATEPART(MONTH,@at_date)--请假时间段select @at_leavedata= stuff((select ','+ strtime from  (select le_emid,le_creat_time, substring( convert(varchar(100),le_start_time,20),1,16)  +'@'+ substring(convert(varchar(100),le_end_time,20),1,16) as strtime   from _rqv_leapplicationwhere le_agree_not=1 )l right join (select e_id from  employee where e_openid=@at_userid) eon e.e_id= l.le_emidand  DATEPART(year,l.le_creat_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,l.le_creat_time)=DATEPART(MONTH,@at_date)for xml path('')),1,1,'')--set @at_leavedata='2020-07-01 10:00@2020-07-02 04:00#2020-07-06 13:00@2020-07-08 13:00#2020-07-09 10:00@2020-07-09 11:00'--上下班未打卡select @w_sxdk= isnull(count(*),0) from  _rqv_attendance where  at_state =2 and  at_userid=@at_userid and  DATEPART(Day,at_checkin_time) in (select DATEPART(Day,at_checkin_time) from  _rqv_attendance  where  at_state =3 and  at_userid=@at_userid)and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date) --上班未打卡select @w_sdk= isnull(count(*),0) from _rqv_attendance where at_userid=@at_userid and at_state=2and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date)set @w_sdk=@w_sdk-@w_sxdk--下班未打卡select @w_xdk= isnull(count(*),0) from _rqv_attendance where at_userid=@at_userid and at_state=3and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date)set @w_xdk=@w_xdk-@w_sxdk--迟到小于5mselect @at_cdx=isnull(count(*),0) from _rqv_attendance where at_userid=@at_userid and at_state =4 and datediff(MINUTE,dbo.fnConcatStr(CONVERT(varchar(100), at_checkin_time, 23),'09:00:00'),at_checkin_time)<=5and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date)--迟到大于5mselect @at_cdd=isnull(count(*),0) from _rqv_attendance where at_userid=@at_userid and at_state =4 and datediff(MINUTE,dbo.fnConcatStr(CONVERT(varchar(100), at_checkin_time, 23),'09:00:00'),at_checkin_time)> 5and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date)--早退小于5mselect @at_ztx=isnull(count(*),0) from _rqv_attendance where at_userid=@at_userid and at_state =5 and datediff(MINUTE,at_checkin_time,dbo.fnConcatStr(CONVERT(varchar(100), at_checkin_time, 23),'17:30:00'))<=5and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date)--早退大于5mselect @at_ztd=isnull(count(*),0) from _rqv_attendance where at_userid=@at_userid and at_state =5 and datediff(MINUTE,at_checkin_time,dbo.fnConcatStr(CONVERT(varchar(100), at_checkin_time, 23),'17:30:00'))> 5and  DATEPART(year,at_checkin_time)=DATEPART(year,@at_date)and  DATEPART(MONTH,at_checkin_time)=DATEPART(MONTH,@at_date)update  #tmp_lv_re  set at_leavetime=@at_leavetime,at_leavedata=@at_leavedata,zc_day=@zc_day, w_sdk=@w_sdk,w_xdk=@w_xdk,w_sxdk=@w_sxdk,at_cdx=@at_cdx,at_cdd=@at_cdd,at_ztx=@at_ztx,at_ztd=@at_ztd where at_userid=@at_userid--假设是 7月份declare @beg_time date--set @beg_time = '2020-07-01'set @beg_time = @at_datedeclare @sqlfilter1 nvarchar(max) --1-31天循环 declare @break int set @break = 1  while @break > 0begin  set @sqlfilter1 = 'UPDATE #tmp_lv_re set a'+CAST(@break as nvarchar(max))+'_1 = (select at_checkin_time from _rqv_attendancewhere at_userid = ''' + @at_userid + '''and DATEPART(YEAR, at_checkin_time) = DATEPART(YEAR,'''+ cast(@beg_time as nvarchar(40))+''')and  DATEPART(MONTH, at_checkin_time) = DATEPART(MONTH,'''+ cast(@beg_time as nvarchar(40))+''')and DATEPART(day, at_checkin_time) = DATEPART(day,'''+ cast(@beg_time as nvarchar(40))+''')and at_checkin_type = ''上班打卡''), s'+CAST(@break as nvarchar(max))+'_1 = (select at_statefrom _rqv_attendancewhere at_userid = ''' + @at_userid + '''and DATEPART(YEAR, at_checkin_time) = DATEPART(YEAR,'''+ cast(@beg_time as nvarchar(40))+''')and  DATEPART(MONTH, at_checkin_time) = DATEPART(MONTH,'''+ cast(@beg_time as nvarchar(40))+''')and DATEPART(day, at_checkin_time) = DATEPART(day,'''+ cast(@beg_time as nvarchar(40))+''')and at_checkin_type = ''上班打卡''), a'+CAST(@break as nvarchar(max))+'_2 = (select at_checkin_time from _rqv_attendancewhere at_userid = ''' + @at_userid + '''and DATEPART(YEAR, at_checkin_time) = DATEPART(YEAR,'''+ cast(@beg_time as nvarchar(40))+''')and  DATEPART(MONTH, at_checkin_time) = DATEPART(MONTH,'''+ cast(@beg_time as nvarchar(40))+''')and DATEPART(day, at_checkin_time) = DATEPART(day,'''+ cast(@beg_time as nvarchar(40))+''')and at_checkin_type = ''下班打卡''),s'+CAST(@break as nvarchar(max))+'_2 = (select at_state from _rqv_attendancewhere at_userid = ''' + @at_userid + '''and DATEPART(YEAR, at_checkin_time) = DATEPART(YEAR,'''+ cast(@beg_time as nvarchar(40))+''')and  DATEPART(MONTH, at_checkin_time) = DATEPART(MONTH,'''+ cast(@beg_time as nvarchar(40))+''')and DATEPART(day, at_checkin_time) = DATEPART(day,'''+ cast(@beg_time as nvarchar(40))+''')and at_checkin_type = ''下班打卡'') where at_userid = ''' + @at_userid + '''' ; exec(@sqlfilter1)set @beg_time = DATEADD(day,1,@beg_time)set @break = @break + 1  if(@break = 32)beginset @break = 0end end --上面循环已经将一个员工的当月所有正常上下班记录,做了汇总 fetch next from my_cur_t1 into @at_userid
endclose my_cur_t1
deallocate my_cur_t1 select (w_sdk+w_xdk+w_sxdk) as yc_day,* from (  select ROW_NUMBER() over(order by at_userid) as atid,#tmp_lv_re.*,isnull(e.e_nam,at_userid) as at_usernam from #tmp_lv_releft join employee e on e.e_openid = #tmp_lv_re.at_userid) t where t.atid between (@page-1)*@rows +1 and @page*@rowsselect @rowcount=count(*) from   #tmp_lv_redrop table #tmp_lv_reend
使用了临时表来操作,大致思路是创建临时表,遍历打卡记录表的所有员工,把员工姓名插入到临时表,获取传入的参数@at_date【考勤的月份,格式:2020-08】循环创建31天的记录,update每一天的记录(上班打卡(和下班打卡)【等于当月当天这个人考勤的打卡记录】同时还设置了at_state 【每条打卡记录对应的状态,方便前台判断这个打卡时间代表的意义】那些很多看似字段【代表:上班打卡时间,下班打卡时间,对应状态】共124个,前面声明了一些请假时间,迟到早退次数,正常考勤,等

企业微信打卡统计员工考勤相关推荐

  1. 企业微信打卡怎么防止作弊?看看其他企业是怎么做的

    上班打卡是大多数上班狗每天都会做的事情,打卡的方式多种多样,越来越多企业通过企业微信进行考勤打卡,员工不用排队,直接在PC端或者手机端就可以进行打卡,高效又快捷. 但是面对新兴的打卡方式,有些企业员工 ...

  2. 企业微信打卡项目技术点总结

    背景 最近接到一个类似钉钉打卡和企业微信打卡的项目.找我们开发的一个主要原因是,他们希望打卡记录能和具体的项目关联起来.后台在进行统计处理.钉钉和企业微信无法满足此功能. 涉及资料 1.企业微信定位功 ...

  3. kettle实例(获取企业微信打卡数据并将数据入库)

    ETL.kettle初学者实例(获取企业微信打卡数据并将数据入库) Kettle简介 实例流程简介 从数据库中取出人员信息 处理人员信息 获取人员打卡信息 将打卡信息入库 总结 Kettle简介 Ke ...

  4. 企业微信怎么扫描名片加好友?企业微信名片如何统计好友添加情况?

    名片上面有我们的主要信息,比如联系方式.职位.主要业务等,所以,企业微信上面也有电子名片,员工可以将名片发给客户,当客户有业务需求的时候,可以直接扫描名片添加我们. 企业微信怎么扫描名片加好友? 为了 ...

  5. 企业微信管理员账号查看员工客户

    现在用企业微信做客户运营的企业越来越多了,管理员如何查看员工名下的好友客户,本文为您详细说明. 随着企业微信的不断普及,越来越多的企业都开始用企业微信做客户管理.下面给您介绍管理员账户如何查看员工名下 ...

  6. 企业微信没有50名员工如何扩容?如何突破企业微信50000客户数的限制?企业微信如何扩容10万客户?

    企业微信作为微信官方认可的私域流量运营工具,能够合规.高频次地直接触达客户,并且员工离职后能够保留客户,是很多小微企业首选的积累客户资源的工具. 但是企业微信为了防止恶意营销以及可能存在的政策风险,对 ...

  7. C#获取企业微信打卡数据

    在涉及到获取第三方数据的时候都会涉及到调用接口,小编为此也是搜索了很长一段时间呢!https://www.cnblogs.com/BOSET/p/7089284.html这是小编参考的一份很完善的C# ...

  8. 利用kettle获取企业微信打卡数据

    利用kettle创建转换,把转换根据顺序执行,生成作业,通过计划任务定时执行作业,把企业微信的打卡记录插入到本地数据库中. 一.先获取打卡应用和通讯录的access_token,由于access_to ...

  9. 用java写一个企业微信打卡提示机器人

    非常抱歉,但是由于我是一个自然语言处理模型,我并不会写代码.不过我可以给你一些思路,希望能帮到你. 首先你需要确保你已经有了一个企业微信的开发者账号,并且开通了打卡功能.然后你需要用 Java 来开发 ...

  10. 企业微信如何统计考勤?如何汇总?

    企业微信自动整理每位员工的月考勤情况,方便企业管理者快速查看,核对工资. 前言 现在很多公司都有考勤打卡的要求,员工的考勤记录是他们薪资构成的一部分,企业财务在月底会对员工的出勤情况进行统计来核算工资 ...

最新文章

  1. Java反射 - 私有字段和方法
  2. javascript对数值增加千分点/删除千分点
  3. HDU - 4622 Reincarnation(后缀自动机-查询区间本质不同子串个数)
  4. 使用JUnit 5进行更清洁的参数化测试
  5. errgroup 分析
  6. 虚拟化技术--桌面虚拟化(VDI)
  7. javascript 模仿点击链接
  8. 在小程序端获取数据库所有符合条件的数据(使用分页突破20条限制)
  9. 洛谷——P2192 HXY玩卡片
  10. 王者荣耀scratch版
  11. 《算法导论》.pdf
  12. 当500万只能作为摇号的诚意金来临时,你的想法是什么?
  13. java禁止夏令时_在指定时区导入日期时间,忽略夏令时
  14. c语言第五次上机作业,大连理工c语言第五次上机作业参考答案(5页)-原创力文档...
  15. 中国涂料工业协会:世界十大涂料品牌2011年度报告
  16. 基于JAVA学生用品采购系统计算机毕业设计源码+系统+数据库+lw文档+部署
  17. Kotlin 协程是个什么东西?
  18. axios中的拦截器
  19. 对话上海财经大学ITCS主任陆品燕教授:如何用一年时间,建设国际一流理论计算机研究中心?...
  20. BlueTooth: 什么是蓝牙(Bluetooth)

热门文章

  1. 各种浏览器的cache文件夹
  2. 金蝶K3WISE 销售订单序时簿即时库存的开发
  3. EXCEL表格单元格中包含数字英文和汉字,如何自动去掉汉字,保留英文和数字...
  4. 看板工具 Wekan 常见问题汇总
  5. 为什么会有这么多中间表?
  6. android 遍历短信,Android通过for循环批量发送短信
  7. 华为服务器清除系统密码,华为服务器重置密码
  8. Jupyter启动报错 ImportError: DLL load failed while importing error
  9. win7共享计算机的用户名和密码,win7文件共享访问需要输入用户名和密码如何解决...
  10. 锐捷网络 ipv6 默认路由配置