|
@@ -4,20 +4,23 @@ package com.malk.fengkaili.controller;
|
|
* 错误抛出与拦截详见 CatchException
|
|
* 错误抛出与拦截详见 CatchException
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.malk.fengkaili.repository.entity.FKLDdContactPo;
|
|
|
|
+import com.malk.fengkaili.service.FKLService;
|
|
import com.malk.server.common.McR;
|
|
import com.malk.server.common.McR;
|
|
import com.malk.service.dingtalk.DDClient;
|
|
import com.malk.service.dingtalk.DDClient;
|
|
import com.malk.service.dingtalk.DDClient_Attendance;
|
|
import com.malk.service.dingtalk.DDClient_Attendance;
|
|
import com.malk.service.dingtalk.DDClient_Contacts;
|
|
import com.malk.service.dingtalk.DDClient_Contacts;
|
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
|
+import com.malk.utils.UtilNumber;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -34,31 +37,81 @@ public class FKLController {
|
|
@Autowired
|
|
@Autowired
|
|
private DDClient_Contacts ddClient_contacts;
|
|
private DDClient_Contacts ddClient_contacts;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FKLService fklService;
|
|
|
|
+
|
|
|
|
+ @PostMapping("test1")
|
|
|
|
+ McR test1() {
|
|
|
|
+
|
|
|
|
+ fklService.syncUserInfo();
|
|
|
|
+
|
|
|
|
+ return McR.success(Arrays.asList(1, 3, 2, 4).stream().reduce(Integer::sum).orElse(0));
|
|
|
|
+// return McR.success(ddClient_attendance.isOpenSmartReport(ddClient.getAccessToken()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// 累计月度汇总数字
|
|
|
|
+ private Object _reduceAttendance(Map column, String name, String keyList) {
|
|
|
|
+ Object value;
|
|
|
|
+ List<Map> vals = (List<Map>) column.get(keyList);
|
|
|
|
+ // 异常信息, 保留备注
|
|
|
|
+ if (name.equals("考勤结果")) {
|
|
|
|
+ value = String.join("\n", vals.stream().filter(item -> {
|
|
|
|
+ String content = UtilMap.getString(item, "value").replaceAll("正常", "").replaceAll("休息", "");
|
|
|
|
+ return StringUtils.isNotBlank(content);
|
|
|
|
+ }).map(item -> UtilMap.getString(item, "value")).collect(Collectors.toList()));
|
|
|
|
+ } else {
|
|
|
|
+ value = vals.stream().map(item -> UtilMap.getFloat(item, "value")).reduce((a, b) -> a + b).orElse(0f);
|
|
|
|
+ }
|
|
|
|
+ return value;
|
|
|
|
+ }
|
|
|
|
+
|
|
@PostMapping("test")
|
|
@PostMapping("test")
|
|
McR test() {
|
|
McR test() {
|
|
|
|
|
|
- List<String> columnNames = Arrays.asList("下班1打卡结果", "上班1打卡结果", "旷工天数", "出勤天数", "工作时长", "考勤结果", "出差时长", "迟到次数", "早退次数", "下班缺卡次数", "上班缺卡次数", "外出时长", "休息日加班", "工作日加班", "节假日加班", "严重迟到次数", "应出勤天数");
|
|
|
|
- List<String> leaveNames = new ArrayList<>();
|
|
|
|
|
|
+ // 考勤列, 假期信息定义
|
|
|
|
+ List<String> columnNames = Arrays.asList("旷工天数", "出勤天数", "工作时长", "考勤结果", "出差时长", "迟到次数", "早退次数", "下班缺卡次数", "上班缺卡次数", "外出时长", "休息日加班", "工作日加班", "节假日加班", "严重迟到次数", "应出勤天数");
|
|
List<Map> columns = ddClient_attendance.getAttColumns(ddClient.getAccessToken());
|
|
List<Map> columns = ddClient_attendance.getAttColumns(ddClient.getAccessToken());
|
|
- List<String> columnIds = columns.stream().filter(column -> {
|
|
|
|
-
|
|
|
|
- if (column.get("alias").equals("leave_")) {
|
|
|
|
- leaveNames.add(String.valueOf(column.get("name")));
|
|
|
|
|
|
+ Map columnIds = new HashMap();
|
|
|
|
+ // 假期单独返回, 钉钉产品规则
|
|
|
|
+ List<String> leaveNames = columns.stream().filter(column -> {
|
|
|
|
+ // 列类型储存id映射名称为map, 考勤数据返回仅保留列id
|
|
|
|
+ if (columnNames.contains(column.get("name"))) {
|
|
|
|
+ columnIds.put(column.get("id").toString(), column.get("name"));
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- return columnNames.contains(column.get("name"));
|
|
|
|
|
|
+ return column.get("alias").equals("leave_");
|
|
}
|
|
}
|
|
|
|
+ ).map(column -> String.valueOf(column.get("name"))).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
|
|
- ).map(column -> String.valueOf(column.get("id"))).collect(Collectors.toList());
|
|
|
|
|
|
+ String start = "2023-07-01 00:00:00";
|
|
|
|
+ String end = "2023-07-22 23:59:59";
|
|
|
|
+ // 基于用户分页
|
|
|
|
+ List<FKLDdContactPo> userInfos = fklService.queryUserInfos(1, 200, null, null).getContent();
|
|
|
|
|
|
-// ddClient_contacts.getDepartmentId_all(ddClient.getAccessToken(), true).forEach(deptId -> {
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-// });
|
|
|
|
|
|
+ List<Map> attendanceInfos = new ArrayList<>();
|
|
|
|
+ List<String> queryIds = new ArrayList<>(columnIds.keySet()); // 考勤列定义
|
|
|
|
+ userInfos.forEach(po -> {
|
|
|
|
+ Map attendanceInfo = UtilMap.map("员工ID, 员工姓名, 员工工号, 所属部门", po.getUserId(), po.getName(), po.getJobNumber(), po.getDeptName());
|
|
|
|
+ // 累计月度汇总
|
|
|
|
+ ddClient_attendance.getAttColumnVal(ddClient.getAccessToken(), po.getUserId(), queryIds, start, end).forEach(column -> {
|
|
|
|
+ String id = ((Map) column.get("column_vo")).get("id").toString();
|
|
|
|
+ String name = String.valueOf(columnIds.get(id)); // 接口仅返回列id, 通过map映射
|
|
|
|
+ attendanceInfo.put(name, _reduceAttendance(column, name, "column_vals"));
|
|
|
|
+ });
|
|
|
|
+ // 累计假期数据
|
|
|
|
+ for (Map column : ddClient_attendance.getLeaveTimeByNames(ddClient.getAccessToken(), po.getUserId(), leaveNames, start, end)) {
|
|
|
|
+ String name = ((Map) column.get("columnvo")).get("name").toString(); // 接口返回列名称
|
|
|
|
+ attendanceInfo.put(name, _reduceAttendance(column, name, "columnvals"));
|
|
|
|
+ }
|
|
|
|
+ // 数据处理
|
|
|
|
+ attendanceInfo.put("加班总时长", UtilNumber.formatPrecision(UtilMap.getFloat(attendanceInfo, "节假日加班") + UtilMap.getFloat(attendanceInfo, "节假日加班") + UtilMap.getFloat(attendanceInfo, "节假日加班")));
|
|
|
|
+ attendanceInfos.add(attendanceInfo);
|
|
|
|
+ });
|
|
|
|
+ log.info("xxx, {}", JSON.toJSONString(attendanceInfos));
|
|
|
|
|
|
|
|
+// log.info("xxx, {}", JSON.toJSONString(userInfo));
|
|
|
|
|
|
- ddClient_attendance.getAttColumnVal(ddClient.getAccessToken(), "01340563171287111,01386135062129166507", columnIds, "2023-07-01 00:00:00", "2023-07-22 23:59:59");
|
|
|
|
- ddClient_attendance.getLeaveTimeByNames(ddClient.getAccessToken(), "01340563171287111", leaveNames, "2023-07-01 00:00:00", "2023-07-22 23:59:59");
|
|
|
|
|
|
|
|
// getLeaveTimeByNames
|
|
// getLeaveTimeByNames
|
|
// ddClient_attendance.getAttColumns(ddClient.getAccessToken());
|
|
// ddClient_attendance.getAttColumns(ddClient.getAccessToken());
|