|
|
@@ -2247,15 +2247,6 @@ public class DingDingServiceImpl implements DingDingService {
|
|
|
userList.add(userMapper.selectById(targetUserId));
|
|
|
} else {
|
|
|
userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", dingding.getCompanyId()).eq("is_active", 1));
|
|
|
-// for (User user : userList) {
|
|
|
-// if (user.getName().equals("杨云鑫")) {
|
|
|
-// System.out.println("杨云鑫。。。。" + user.getDingdingUserid());
|
|
|
-// List<User> nbewList = new ArrayList<>();
|
|
|
-// nbewList.add(user);
|
|
|
-// userList = nbewList;
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
String accessToken = getCorpAccessToken(dingding);
|
|
|
if (userList.size() > 50) {
|
|
|
@@ -2949,13 +2940,11 @@ public class DingDingServiceImpl implements DingDingService {
|
|
|
//第一天
|
|
|
long seconds = end.toEpochSecond(ZoneOffset.ofHours(8)) - start.toEpochSecond(ZoneOffset.ofHours(8));
|
|
|
double workHours = DateTimeUtil.getHoursFromDouble(DateTimeUtil.getHoursFromSeconds((int) seconds));
|
|
|
- System.out.println("出差时长=="+workHours);
|
|
|
userDingdingTime.setWorkHours((float)workHours);
|
|
|
} else if (endDateStr.equals(date)) {
|
|
|
//最后一天
|
|
|
long seconds = end.toEpochSecond(ZoneOffset.ofHours(8)) - start.toEpochSecond(ZoneOffset.ofHours(8));
|
|
|
double workHours = DateTimeUtil.getHoursFromDouble(DateTimeUtil.getHoursFromSeconds((int) seconds));
|
|
|
- System.out.println("出差时长=="+workHours);
|
|
|
userDingdingTime.setWorkHours((float)workHours);
|
|
|
} else {
|
|
|
//中间天,就是全天
|
|
|
@@ -2972,7 +2961,6 @@ public class DingDingServiceImpl implements DingDingService {
|
|
|
//就是当天,计算时长
|
|
|
long seconds = end.toEpochSecond(ZoneOffset.ofHours(8)) - start.toEpochSecond(ZoneOffset.ofHours(8));
|
|
|
double workHours = DateTimeUtil.getHoursFromDouble(DateTimeUtil.getHoursFromSeconds((int) seconds));
|
|
|
- System.out.println("出差时长=="+workHours);
|
|
|
userDingdingTime.setWorkHours((float)workHours);
|
|
|
}
|
|
|
if (userDingdingTime.getWorkHours() > 8.0) {
|
|
|
@@ -3009,4 +2997,114 @@ public class DingDingServiceImpl implements DingDingService {
|
|
|
}
|
|
|
return deptId;
|
|
|
}
|
|
|
+
|
|
|
+ private List<Long> getSchedulePlanIds(String accessToken, String workDate, String userId, long offset) {
|
|
|
+ List<Long> planIds = new ArrayList<>();
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/listschedule");
|
|
|
+ OapiAttendanceListscheduleRequest req = new OapiAttendanceListscheduleRequest();
|
|
|
+ req.setWorkDate(StringUtils.parseDateTime(workDate + " 11:11:11"));
|
|
|
+ req.setOffset(offset);
|
|
|
+ req.setSize(200L);
|
|
|
+ OapiAttendanceListscheduleResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, accessToken);
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
|
|
|
+ if (jsonObject.getInteger("errcode") == 0) {
|
|
|
+ JSONObject resultObj = jsonObject.getJSONObject("result");
|
|
|
+ Boolean hasMore = resultObj.getBoolean("has_more");
|
|
|
+ JSONArray jsonArray = resultObj.getJSONArray("schedules");
|
|
|
+ /**
|
|
|
+ *数据格式为 {
|
|
|
+ * "check_type": "OnDuty",
|
|
|
+ * "class_id": 677995086,
|
|
|
+ * "class_setting_id": 599315627,
|
|
|
+ * "group_id": 685935028,
|
|
|
+ * "plan_check_time": "2020-11-11 09:30:00",
|
|
|
+ * "plan_id": 157062792171,
|
|
|
+ * "userid": "user01"
|
|
|
+ * }
|
|
|
+ */
|
|
|
+
|
|
|
+ for (int i=0;i<jsonArray.size(); i++) {
|
|
|
+ JSONObject scheduleObj = jsonArray.getJSONObject(i);
|
|
|
+ String planId = scheduleObj.getString("plan_id");
|
|
|
+ String userIdStr = scheduleObj.getString("userid");
|
|
|
+ if (userIdStr.equals(userId)) {
|
|
|
+ planIds.add(Long.parseLong(planId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hasMore) {
|
|
|
+ List<Long> list = getSchedulePlanIds(accessToken, workDate, userId, offset+200);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ planIds.addAll(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (ApiException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return planIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取员工的考勤打卡记录
|
|
|
+ * 调用钉钉接口:https://oapi.dingtalk.com/topapi/attendance/schedule/result/listbyids
|
|
|
+ * 参考文档:https://open.dingtalk.com/document/development/query-the-results-of-a-batch-of-tasks
|
|
|
+ * @param companyId 公司ID
|
|
|
+ * @param userId 员工钉钉ID列表,多个用逗号分隔
|
|
|
+ * @param workDateFrom 开始日期 格式:yyyy-MM-dd
|
|
|
+ * @param workDateTo 结束日期 格式:yyyy-MM-dd
|
|
|
+ * @return 考勤打卡记录
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getAttendanceScheduleResult(Integer companyId, String userId, String workDateFrom, String workDateTo) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ // 获取公司钉钉配置信息
|
|
|
+ CompanyDingding dingding = companyDingdingMapper.selectOne(new QueryWrapper<CompanyDingding>().eq("company_id", companyId));
|
|
|
+ if (dingding == null) {
|
|
|
+ msg.setError("未找到公司钉钉配置信息");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取accessToken
|
|
|
+ String accessToken = getCorpAccessToken(dingding);
|
|
|
+ if (accessToken == null) {
|
|
|
+ msg.setError("获取accessToken失败");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> planIds = getSchedulePlanIds(accessToken, workDateFrom, userId, 0);
|
|
|
+ System.out.println("planIds===="+planIds);
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/schedule/result/listbyids");
|
|
|
+ OapiAttendanceScheduleResultListbyidsRequest req = new OapiAttendanceScheduleResultListbyidsRequest();
|
|
|
+ String oaManagerDid = dingding.getOaManagerDingid();
|
|
|
+ req.setOpUserId(oaManagerDid);
|
|
|
+ String planIdsString = planIds.stream().map(Object::toString).collect(Collectors.joining(","));
|
|
|
+ req.setScheduleIds(planIdsString);
|
|
|
+ OapiAttendanceScheduleResultListbyidsResponse rsp = client.execute(req, accessToken);
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
+ // 解析返回结果
|
|
|
+ JSONObject json = JSONObject.parseObject(rsp.getBody());
|
|
|
+ if (json.getInteger("errcode") == 0) {
|
|
|
+ // 成功获取数据
|
|
|
+ msg.data = json.getJSONObject("result");
|
|
|
+ System.out.println("成功获取考勤打卡记录,员工ID:" + userId + ",日期范围:" + workDateFrom + " 至 " + workDateTo);
|
|
|
+ } else {
|
|
|
+ // 接口返回错误
|
|
|
+ msg.setError("钉钉接口返回错误:" + json.getString("errmsg"));
|
|
|
+ System.err.println("获取考勤打卡记录失败:" + json.getString("errmsg"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("调用钉钉接口异常:" + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("获取考勤打卡记录异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|