欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

钉钉考勤接口调用与OA系统数据对接

程序员文章站 2022-03-31 08:08:38
...

钉钉考勤接口调用与OA系统数据对接

公司由原来的指纹打卡更换为钉钉打卡,需要钉钉和现有的OA考勤数据对接(合并钉钉打卡数据和OA上的请假,外出,出差数据)

1.查看钉钉接口文档
https://ding-doc.dingtalk.com/doc#/serverapi2/gh60vz
钉钉考勤接口调用与OA系统数据对接
2.项目搭建引入钉钉开发SDK
钉钉考勤接口调用与OA系统数据对接
3.获取钉钉考勤数据存储服务器数据库(调整存储格式)
//测试
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);//设置打卡时间
JSONObject Json = getattendance(asList.get(i),workDateFrom,workDateTo);//获取打卡结果
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(“locationResult”);//位置结果
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");//打卡结果
        	  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数据
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未记录数据
				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 {
					//构造打卡信息
					  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();//结束时间的上下午
							String begin_date = oaLeave.getBegin_date();//开始日期
							String end_date = oaLeave.getEnd_date();//结束日期
							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.添加定时任务
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();
}
}
Copyright © 2019 shaoyanbin All Rights Reserved

相关标签: 钉钉 OA 考勤