釘釘考勤接口調(diào)用與OA系統(tǒng)數(shù)據(jù)對接
公司由原來的指紋打卡更換為釘釘打卡,需要釘釘和現(xiàn)有的OA考勤數(shù)據(jù)對接(合并釘釘打卡數(shù)據(jù)和OA上的請假,外出,出差數(shù)據(jù)) 1.查看釘釘接口文檔 2.項目搭建引入釘釘開發(fā)SDK 3.獲取釘釘考勤數(shù)據(jù)存儲服務(wù)器數(shù)據(jù)庫(調(diào)整存儲格式) //測試 public static void main(String[] args) throws Exception { Date date = new Date(); DateFormat format_getHours = new SimpleDateFormat(“HH:mm:ss”); String currentDate = new SimpleDateFormat(“yyyy-MM-dd”).format(date); String yesterday = getPreDayOrAfterDay(currentDate, -1); String workDateFrom = yesterday + " " + “01:00:00”; String workDateTo = yesterday + " " + “23:00:00”; //新邏輯 List asList = Arrays.asList(“1”,“2”,“3”); List Attendances = new ArrayList(); for (int i = 0; i < asList.size(); i++) { Attendance Attendance = new Attendance(); Attendance.setUserId(asList.get(i)); JSONObject getuserinfo = getuserinfo(asList.get(i));//獲取用戶詳情 String name = getuserinfo.getString(“name”);//姓名 Attendance.setName(name); JSONArray departmentid = getuserinfo.getJSONArray(“department”);//部門id Attendance.setDepartment(getdepartment(departmentid.getString(0)));//獲取部門名稱 Attendance.setAttendanceTime(yesterday);//設(shè)置打卡時間 JSONObject Json = getattendance(asList.get(i),workDateFrom,workDateTo);//獲取打卡結(jié)果 JSONArray recordresult = Json.getJSONArray(“recordresult”); for (int j = 0; j < recordresult.size(); j++) { JSONObject record = recordresult.getJSONObject(j); String checkType = record.getString(“checkType”);//上下班 String locationResult = record.getString(“l(fā)ocationResult”);//位置結(jié)果 if (null!=locationResult) { switch (locationResult) { case “Normal”: locationResult=DingConstant.locationResult_Normal; break; case “Outside”: locationResult=DingConstant.locationResult_Outside; break; case “NotSigned”: locationResult=DingConstant.locationResult_NotSigned; break; } } String timeResult = record.getString("timeResult");//打卡結(jié)果 if (null!=timeResult) { switch (timeResult) { case "Normal": timeResult=DingConstant.timeResult_Normal; break; case "Early": timeResult=DingConstant.timeResult_Early; break; case "Late": timeResult=DingConstant.timeResult_Late; case "NotSigned": timeResult=DingConstant.timeResult_NotSigned; break; } } String userCheckTime = getHours(record.getString("userCheckTime"));//打卡時間 String onDuty1checkTime = Attendance.getOnDuty1checkTime(); String onDuty1checkResult = Attendance.getOnDuty1checkResult(); String offDuty1checkResult = Attendance.getOffDuty1checkResult(); String offDuty1checkTime = Attendance.getOffDuty1checkTime(); String offDuty2checkResult = Attendance.getOffDuty2checkResult(); String offDuty2checkTime = Attendance.getOffDuty2checkTime(); String onDuty2checkResult = Attendance.getOnDuty2checkResult(); String onDuty2checkTime = Attendance.getOnDuty2checkTime(); if (checkType!=null) { if (checkType.equals("OnDuty")) { if (null==onDuty1checkTime&&null==onDuty1checkResult) { Attendance.setOnDuty1checkTime(userCheckTime); if (null!=locationResult&&locationResult.equals(DingConstant.locationResult_Outside)) { Attendance.setOnDuty1checkResult(locationResult); }else { Attendance.setOnDuty1checkResult(timeResult); } continue; }else if (null==onDuty2checkTime&&null==onDuty2checkResult) { if (format_getHours.parse(userCheckTime).getTime()<format_getHours.parse(onDuty1checkTime).getTime()) { Attendance.setOnDuty2checkTime(onDuty1checkTime); Attendance.setOnDuty2checkResult(onDuty1checkResult); Attendance.setOnDuty1checkTime(userCheckTime); if (null!=locationResult&&locationResult.equals(DingConstant.locationResult_Outside)) { Attendance.setOnDuty1checkResult(locationResult); }else { Attendance.setOnDuty1checkResult(timeResult); } }else { Attendance.setOnDuty2checkTime(userCheckTime); if (null!=locationResult&&locationResult.equals(DingConstant.locationResult_Outside)) { Attendance.setOnDuty2checkResult(locationResult); }else { Attendance.setOnDuty2checkResult(timeResult); } } continue; } }else if (checkType.equals("OffDuty")) { if (null==offDuty1checkTime&&null==offDuty1checkResult) { Attendance.setOffDuty1checkTime(userCheckTime); if (null!=locationResult&&locationResult.equals(DingConstant.locationResult_Outside)) { Attendance.setOffDuty1checkResult(locationResult); }else { Attendance.setOffDuty1checkResult(timeResult); } continue; }else if (null==offDuty2checkTime&&null==offDuty2checkResult) { if (format_getHours.parse(userCheckTime).getTime()<format_getHours.parse(offDuty1checkTime).getTime()) { Attendance.setOffDuty2checkTime(offDuty1checkTime); Attendance.setOffDuty2checkResult(offDuty1checkResult); Attendance.setOffDuty1checkTime(userCheckTime); if (null!=locationResult&&locationResult.equals(DingConstant.locationResult_Outside)) { Attendance.setOffDuty1checkResult(locationResult); }else { Attendance.setOffDuty1checkResult(timeResult); } }else { Attendance.setOffDuty2checkTime(userCheckTime); if (null!=locationResult&&locationResult.equals(DingConstant.locationResult_Outside)) { Attendance.setOffDuty2checkResult(locationResult); }else { Attendance.setOffDuty2checkResult(timeResult); } } continue; } } } } System.out.println(Attendance.toString()); Attendances.add(Attendance); } } 4.合并OA數(shù)據(jù) public void run() { try { AttendanceService attendanceService = (AttendanceService) ApplicationContextUtil.getBean(“attendanceService”); OaLeaveService oaLeaveService = (OaLeaveService) ApplicationContextUtil.getBean(“oaLeaveService”); OaYearLeaveService oaYearLeaveService = (OaYearLeaveService) ApplicationContextUtil.getBean(“oaYearLeaveService”); OaBusinessService oaBusinessService = (OaBusinessService) ApplicationContextUtil.getBean(“oaBusinessService”); OaGooutService oaGooutService = (OaGooutService) ApplicationContextUtil.getBean(“oaGooutService”); UserService userService = (UserService) ApplicationContextUtil.getBean(“userService”); List<UserBean> list = userService.getuserlist(); String flow_data=null; //更新oa信息 for (int i = 0; i < list.size(); i++) { UserBean userBean = list.get(i); String oa_id = userBean.getUser_account();//OAID String ding_id = userBean.getDing_id();//dingdingID String user_name = userBean.getUser_name(); //判斷是否有OA賬號 if (null!=ding_id) { if (null==oa_id) { continue; }else { //取OA未記錄數(shù)據(jù) Map<String, Object> oaLeaveMap = oaLeaveService.getOaLeaveList("0",oa_id,"values", "", "", "flow_data_507", "批準", "''"+"2019-08-01"+"''", "", 1, 5); Map<String, Object> oaLeaveMap1 = oaLeaveService.getOaLeaveList("0",oa_id,"values", "", "", "flow_data_508", "批準", "''"+"2019-08-01"+"''", "", 1, 5); Map<String, Object> oaLeaveMap2 = oaLeaveService.getOaLeaveList("0",oa_id,"values", "", "", "flow_data_512", "批準", "''"+"2019-08-01"+"''", "", 1, 5); Map<String, Object> oaYearLeaveMap = oaYearLeaveService.getOaYearLeaveList("0",oa_id,"values", "", "", "flow_data_535", "批準", "''"+"2019-08-01"+"''", "", 1, 5); Map<String, Object> oaBusinessMap = oaBusinessService.getOaBusinessList("0",oa_id, "values", "", "", "flow_data_103", "批準", "''"+"2019-08-01"+"''", "", 1, 5); Map<String, Object> oaGooutMap = oaGooutService.getOaGooutList("0",oa_id, "values", "", "", "flow_data_85", "批準", "''"+"2019-08-01"+"''", "", 1, 5); List<OaLeave> oaLeaveList =(List<OaLeave>) oaLeaveMap.get("rows"); List<OaLeave> oaLeaveList1 =(List<OaLeave>) oaLeaveMap1.get("rows"); List<OaLeave> oaLeaveList2 =(List<OaLeave>) oaLeaveMap2.get("rows"); List<OaYearLeave> oaYearLeaveList =(List<OaYearLeave>) oaYearLeaveMap.get("rows"); List<OaBusiness> oaBusinessList = (List<OaBusiness>) oaBusinessMap.get("rows"); List<OaGoout> oaGooutList = (List<OaGoout>) oaGooutMap.get("rows"); //請假信息 if (oaLeaveList.isEmpty()&&oaLeaveList1.isEmpty()&&oaLeaveList2.isEmpty()&& oaYearLeaveList.isEmpty()&&oaBusinessList.isEmpty()&&oaGooutList.isEmpty()) { continue; }else { //構(gòu)造打卡信息 JSONObject getuserinfo = DingRecordSyncController.getuserinfo(ding_id); JSONArray departmentid = getuserinfo.getJSONArray("department");//部門id String department=null; if (null==departmentid) { continue; }else { department = DingRecordSyncController.getdepartment(departmentid.getString(0)); } //遍歷請假出差外出信息 if (!oaLeaveList.isEmpty()||!oaLeaveList1.isEmpty()||!oaLeaveList2.isEmpty()) { List<OaLeave> list2 = new ArrayList<OaLeave>(); if (!oaLeaveList.isEmpty()) { list2=oaLeaveList; flow_data="flow_data_507"; }else if (!oaLeaveList1.isEmpty()) { list2=oaLeaveList1; flow_data="flow_data_508"; }else if (!oaLeaveList2.isEmpty()) { list2=oaLeaveList2; flow_data="flow_data_512"; } for (int j = 0; j < list2.size(); j++) { OaLeave oaLeave = list2.get(j); String id = oaLeave.getId(); String begin_date_type = oaLeave.getBegin_date_type();//開始時間的上下午 String end_date_type = oaLeave.getEnd_date_type();//結(jié)束時間的上下午 String begin_date = oaLeave.getBegin_date();//開始日期 String end_date = oaLeave.getEnd_date();//結(jié)束日期 String leave_name = oaLeave.getLeave_name();//請假類別 String date_count = oaLeave.getDate_count();//請假時長 if (null!=date_count&&date_count.equals("半")) { date_count="0.5"; } if (null!=date_count&&date_count.equals("半天")) { date_count="0.5"; } float count = Float.parseFloat(date_count); if (begin_date_type.equals("上午")) { if (count==0.5) { Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2) { attendance2.setOnDuty1checkResult(leave_name); attendance2.setOffDuty1checkResult(leave_name); attendance2.setLeave_count(0.5f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,leave_name,null,leave_name,null,null,null,null,0.5f,null,null,null)); } if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; }else if (count==1) { Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2&&attendance2.getAttendanceTime()!=null) { attendance2.setOnDuty1checkResult(leave_name); attendance2.setOnDuty2checkResult(leave_name); attendance2.setOffDuty1checkResult(leave_name); attendance2.setOffDuty2checkResult(leave_name); attendance2.setLeave_count(1f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,leave_name,null,leave_name,null,leave_name,null,leave_name,1f,null,null,null)); } if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; }else if (count>1) { if (end_date_type.equals("上午")) { String nextDate = DateUtil.getNextDate(begin_date); Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2&&attendance2.getAttendanceTime()!=null) { attendance2.setOnDuty1checkResult(leave_name); attendance2.setOnDuty2checkResult(leave_name); attendance2.setOffDuty1checkResult(leave_name); attendance2.setOffDuty2checkResult(leave_name); attendance2.setLeave_count(1f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,leave_name,null,leave_name,null,leave_name,null,leave_name,1f,null,null,null)); } if (DateUtil.compateDate(end_date, nextDate)>0) { do { Attendance attendance3 = attendanceService.getAttendance(ding_id, nextDate); if (null!=attendance3&&attendance3.getAttendanceTime()!=null) { attendance3.setOnDuty1checkResult(leave_name); attendance3.setOnDuty2checkResult(leave_name); attendance3.setOffDuty1checkResult(leave_name); attendance3.setOffDuty2checkResult(leave_name); attendance3.setLeave_count(1f); attendanceService.updateAttendance(attendance3); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,nextDate,null,leave_name,null,leave_name,null,leave_name,null,leave_name,1f,null,null,null)); } nextDate=DateUtil.getNextDate(nextDate); } while (DateUtil.compateDate(end_date, nextDate)>0); } Attendance attendance4 = attendanceService.getAttendance(ding_id, end_date); if (null!=attendance4&&attendance4.getAttendanceTime()!=null) { attendance4.setOnDuty1checkResult(leave_name); attendance4.setOffDuty1checkResult(leave_name); attendance4.setLeave_count(0.5f); attendanceService.updateAttendance(attendance4); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,end_date,null,leave_name,null,leave_name,null,null,null,null,0.5f,null,null,null)); } if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; }else if (end_date_type.equals("下午")) { String nextDate = DateUtil.getNextDate(begin_date); Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2&&attendance2.getAttendanceTime()!=null) { attendance2.setOnDuty1checkResult(leave_name); attendance2.setOnDuty2checkResult(leave_name); attendance2.setOffDuty1checkResult(leave_name); attendance2.setOffDuty2checkResult(leave_name); attendance2.setLeave_count(1f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,leave_name,null,leave_name,null,leave_name,null,leave_name,1f,null,null,null)); } do { Attendance attendance3 = attendanceService.getAttendance(ding_id, nextDate); if (null!=attendance3&&attendance3.getAttendanceTime()!=null) { attendance3.setOnDuty1checkResult(leave_name); attendance3.setOnDuty2checkResult(leave_name); attendance3.setOffDuty1checkResult(leave_name); attendance3.setOffDuty2checkResult(leave_name); attendance3.setLeave_count(1f); attendanceService.updateAttendance(attendance3); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,nextDate,null,leave_name,null,leave_name,null,leave_name,null,leave_name,1f,null,null,null)); } nextDate=DateUtil.getNextDate(nextDate); } while (DateUtil.compateDate(end_date, nextDate)>=0); if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; } }//開始時間是上午 }else if (begin_date_type.equals("下午")) { if (count==0.5) { Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2) { attendance2.setOnDuty2checkResult(leave_name); attendance2.setOffDuty2checkResult(leave_name); attendance2.setLeave_count(0.5f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,null,null,null,null,leave_name,null,leave_name,0.5f,null,null,null)); } if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; }else if (count==1) { Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2&&attendance2.getAttendanceTime()!=null) { attendance2.setOnDuty2checkResult(leave_name); attendance2.setOffDuty2checkResult(leave_name); attendance2.setLeave_count(0.5f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,null,null,null,null,leave_name,null,leave_name,0.5f,null,null,null)); } Attendance attendance3 = attendanceService.getAttendance(ding_id, DateUtil.getNextDate(begin_date)); if (null!=attendance3&&attendance3.getAttendanceTime()!=null) { attendance3.setOnDuty1checkResult(leave_name); attendance3.setOffDuty1checkResult(leave_name); attendance3.setLeave_count(0.5f); attendanceService.updateAttendance(attendance3); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,DateUtil.getNextDate(begin_date),null,leave_name,null,leave_name,null,null,null,null,0.5f,null,null,null)); } if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; }else if (count>1) { if (end_date_type.equals("下午")) { String nextDate = DateUtil.getNextDate(begin_date); Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2&&attendance2.getAttendanceTime()!=null) { attendance2.setOnDuty2checkResult(leave_name); attendance2.setOffDuty2checkResult(leave_name); attendance2.setLeave_count(0.5f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,null,null,null,null,leave_name,null,leave_name,0.5f,null,null,null)); } do { Attendance attendance3 = attendanceService.getAttendance(ding_id, nextDate); if (null!=attendance3&&attendance3.getAttendanceTime()!=null) { attendance3.setOnDuty1checkResult(leave_name); attendance3.setOnDuty2checkResult(leave_name); attendance3.setOffDuty1checkResult(leave_name); attendance3.setOffDuty2checkResult(leave_name); attendance3.setLeave_count(1f); attendanceService.updateAttendance(attendance3); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,nextDate,null,leave_name,null,leave_name,null,leave_name,null,leave_name,1f,null,null,null)); } nextDate=DateUtil.getNextDate(nextDate); } while (DateUtil.compateDate(end_date, nextDate)>=0); if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; }else if (end_date_type.equals("上午")) { String nextDate = DateUtil.getNextDate(begin_date); Attendance attendance2 = attendanceService.getAttendance(ding_id, begin_date); if (null!=attendance2&&attendance2.getAttendanceTime()!=null) { attendance2.setOnDuty2checkResult(leave_name); attendance2.setOffDuty2checkResult(leave_name); attendance2.setLeave_count(0.5f); attendanceService.updateAttendance(attendance2); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,begin_date,null,null,null,null,null,leave_name,null,leave_name,0.5f,null,null,null)); } do { Attendance attendance3 = attendanceService.getAttendance(ding_id, nextDate); if (null!=attendance3&&attendance3.getAttendanceTime()!=null) { attendance3.setOnDuty1checkResult(leave_name); attendance3.setOnDuty2checkResult(leave_name); attendance3.setOffDuty1checkResult(leave_name); attendance3.setOffDuty2checkResult(leave_name); attendance3.setLeave_count(1f); attendanceService.updateAttendance(attendance3); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,nextDate,null,leave_name,null,leave_name,null,leave_name,null,leave_name,1f,null,null,null)); } nextDate=DateUtil.getNextDate(nextDate); } while (DateUtil.compateDate(end_date, nextDate)>0); Attendance attendance4 = attendanceService.getAttendance(ding_id, end_date); if (null!=attendance4&&attendance4.getAttendanceTime()!=null) { attendance4.setOnDuty1checkResult(leave_name); attendance4.setOffDuty1checkResult(leave_name); attendance4.setLeave_count(0.5f); attendanceService.updateAttendance(attendance4); }else { attendanceService.saveAttendance(new Attendance(ding_id,user_name,department,end_date,null,leave_name,null,leave_name,null,null,null,null,0.5f,null,null,null)); } if (flow_data.equals("flow_data_507")) { oaLeaveService.updateOaLeave(id,1); }else if (flow_data.equals("flow_data_508")) { oaLeaveService.updateOaLeave1(id,1); }else if (flow_data.equals("flow_data_512")) { oaLeaveService.updateOaLeave2(id,1); } continue; } }//開始時間是下午 } } } 5.添加定時任務(wù) public class TimerManager { private static final long PERIOD_DAY = 24 * 60 * 60 * 1000; public TimerManager() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 02); calendar.set(Calendar.MINUTE, 10); calendar.set(Calendar.SECOND, 00); Date date = calendar.getTime(); if (date.before(new Date())) { date = this.addDay(date, 1); } Timer timer = new Timer(); TimerTaskService task = new TimerTaskService(); timer.schedule(task, date, PERIOD_DAY); } private Date addDay(Date date, int num) { Calendar startDT = Calendar.getInstance(); startDT.setTime(date); startDT.add(Calendar.DAY_OF_MONTH, num); return startDT.getTime(); } } ———————————————— 版權(quán)聲明:本文為CSDN博主「kengso」的原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
該文章在 2020/4/27 17:45:11 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |