|
@@ -7,12 +7,23 @@ import com.dingtalk.api.response.*;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
|
import com.jeeplus.test.dingding.dto.DeptDTO;
|
|
|
+import com.jeeplus.test.dingding.dto.DdUserDTO;
|
|
|
+import com.jeeplus.utils.StringUtils;
|
|
|
import com.taobao.api.ApiException;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/test/addressBook")
|
|
|
public class DingdingAddressBookController {
|
|
@@ -23,6 +34,8 @@ public class DingdingAddressBookController {
|
|
|
@Value("NWFAu2fcfKlW3GxlvrGEwMjvJ7jyCPq0Q70XzptUsxE5PYs9cx5wTBWL0wjxKBtf")
|
|
|
private String appSecret;
|
|
|
|
|
|
+ private DingdingController dingdingController;
|
|
|
+
|
|
|
/**
|
|
|
* 获取token
|
|
|
*/
|
|
@@ -49,8 +62,10 @@ public class DingdingAddressBookController {
|
|
|
@ApiLog("获取用户列表")
|
|
|
@ApiOperation(value = "获取用户列表")
|
|
|
@GetMapping("list")
|
|
|
- public ResponseEntity list(Long deptId) {
|
|
|
+ public ResponseEntity list(Long deptId,String dateFrom,String dateTo) {
|
|
|
try {
|
|
|
+ ArrayList<DdUserDTO> userDTOS = new ArrayList<>();
|
|
|
+
|
|
|
String token = getToken();
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
|
|
|
OapiV2UserListRequest req = new OapiV2UserListRequest();
|
|
@@ -60,8 +75,68 @@ public class DingdingAddressBookController {
|
|
|
req.setCursor(0L); // 起始点
|
|
|
req.setSize(50L); // 每页返回数量,建议不要超过 50
|
|
|
OapiV2UserListResponse rsp = client.execute(req, token);
|
|
|
+ List<OapiV2UserListResponse.ListUserResponse> list = rsp.getResult().getList();
|
|
|
+
|
|
|
+ //获取考勤信息列
|
|
|
+ DingTalkClient client1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getattcolumns");
|
|
|
+ OapiAttendanceGetattcolumnsRequest req1 = new OapiAttendanceGetattcolumnsRequest();
|
|
|
+ OapiAttendanceGetattcolumnsResponse rsp1 = client1.execute(req1, token);
|
|
|
+ ArrayList<OapiAttendanceGetattcolumnsResponse.ColumnForTopVo> arrayList = new ArrayList<>();
|
|
|
+ for (OapiAttendanceGetattcolumnsResponse.ColumnForTopVo column : rsp1.getResult().getColumns()) {
|
|
|
+ if (column.getName().equals("应出勤天数") || column.getName().equals("出勤天数") || column.getName().equals("休息天数")){
|
|
|
+ arrayList.add(column);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String typeIds = arrayList.stream().map(column -> String.valueOf(column.getId())).collect(Collectors.joining(","));
|
|
|
+ //获取用户考勤信息
|
|
|
+ for (OapiV2UserListResponse.ListUserResponse user : list) {
|
|
|
+ DdUserDTO ddUserDTO = new DdUserDTO();
|
|
|
+ ddUserDTO.setUserid(user.getUserid());
|
|
|
+ ddUserDTO.setMobile(user.getMobile());
|
|
|
+ ddUserDTO.setName(user.getName());
|
|
|
+ String requiredAttDays ="";//应出勤天数
|
|
|
+ String attDays = "";//出勤天数
|
|
|
+ String restDays = "";//休息天数
|
|
|
+ OapiAttendanceGetcolumnvalResponse attRsp = getAttById(user.getUserid(), typeIds, dateFrom, dateTo);
|
|
|
+ //根据考勤信息列获取里面的数据
|
|
|
+ for (OapiAttendanceGetcolumnvalResponse.ColumnValForTopVo columnVal : attRsp.getResult().getColumnVals()) {
|
|
|
+ for (OapiAttendanceGetattcolumnsResponse.ColumnForTopVo columnForTopVo : arrayList) {
|
|
|
+ //对考勤信息列进行汇总
|
|
|
+ if (columnForTopVo.getId().equals(columnVal.getColumnVo().getId()) && columnForTopVo.getName().equals("应出勤天数")){
|
|
|
+ double days = 0;
|
|
|
+ for (OapiAttendanceGetcolumnvalResponse.ColumnDayAndVal val : columnVal.getColumnVals()) {
|
|
|
+ double v = Double.parseDouble(val.getValue());
|
|
|
+ days += v;
|
|
|
+ }
|
|
|
+ requiredAttDays = String.valueOf(days);
|
|
|
+ }
|
|
|
+ if (columnForTopVo.getId().equals(columnVal.getColumnVo().getId()) && columnForTopVo.getName().equals("出勤天数")){
|
|
|
+ double days = 0;
|
|
|
+ for (OapiAttendanceGetcolumnvalResponse.ColumnDayAndVal val : columnVal.getColumnVals()) {
|
|
|
+ double v = Double.parseDouble(val.getValue());
|
|
|
+ days += v;
|
|
|
+ }
|
|
|
+ attDays = String.valueOf(days);
|
|
|
+ }
|
|
|
+ if (columnForTopVo.getId().equals(columnVal.getColumnVo().getId()) && columnForTopVo.getName().equals("休息天数")){
|
|
|
+ double days = 0;
|
|
|
+ for (OapiAttendanceGetcolumnvalResponse.ColumnDayAndVal val : columnVal.getColumnVals()) {
|
|
|
+ double v = Double.parseDouble(val.getValue());
|
|
|
+ days += v;
|
|
|
+ }
|
|
|
+ restDays = String.valueOf(days);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ddUserDTO.setAttDays(attDays);
|
|
|
+ ddUserDTO.setRequiredAttDays(requiredAttDays);
|
|
|
+ ddUserDTO.setRestDays(restDays);
|
|
|
+
|
|
|
+ userDTOS.add(ddUserDTO);
|
|
|
+ }
|
|
|
+
|
|
|
// 返回 JSON 响应
|
|
|
- return ResponseEntity.ok(rsp);
|
|
|
+ return ResponseEntity.ok(userDTOS);
|
|
|
} catch (ApiException e) {
|
|
|
e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
|
return ResponseEntity.badRequest ( ).body ( "接口异常,请重试!" );
|
|
@@ -71,6 +146,44 @@ public class DingdingAddressBookController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public OapiAttendanceGetcolumnvalResponse getAttById(String userId,String leaveTypes,String dateFrom,String dateTo) throws ApiException, ParseException {
|
|
|
+ String access_token = getToken();
|
|
|
+
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getcolumnval");
|
|
|
+ OapiAttendanceGetcolumnvalRequest req = new OapiAttendanceGetcolumnvalRequest();
|
|
|
+ req.setUserid(userId);
|
|
|
+ req.setColumnIdList(leaveTypes);
|
|
|
+ Date from;
|
|
|
+ Date to;
|
|
|
+ //日期必须传,当没有日期的时候获取当前的日期
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(dateFrom) && StringUtils.isBlank(dateTo)){
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate firstDayOfMonth = today.withDayOfMonth(1);
|
|
|
+ // 将 LocalDate 转换为 Date 对象
|
|
|
+ Date date = Date.from(today.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date fromDate = Date.from(firstDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ // 使用 SimpleDateFormat 格式化 Date 对象
|
|
|
+ String toattedDate = sdf.format(date);
|
|
|
+ String formattedDate = sdf.format(fromDate);
|
|
|
+ from = sdf.parse(formattedDate);
|
|
|
+ to = sdf.parse(toattedDate);
|
|
|
+ }else {
|
|
|
+ from = sdf.parse(dateFrom);
|
|
|
+ to = sdf.parse(dateTo);
|
|
|
+ }
|
|
|
+ req.setFromDate(from);
|
|
|
+ req.setToDate(to);
|
|
|
+ OapiAttendanceGetcolumnvalResponse rsp = client.execute(req, access_token);
|
|
|
+
|
|
|
+
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取部门列表
|
|
|
*/
|