Browse Source

钉钉增加请假同步

QuYueTing 6 days ago
parent
commit
222382e9d9

+ 5 - 5
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/DingDingController.java

@@ -203,11 +203,11 @@ public class DingDingController {
     }
 
 //
-//    @RequestMapping("/syncLeaveTime")
-//    public HttpRespMsg syncLeaveTime(Integer companyId, String userId, String startDate, String endDate) {
-//        dingDingService.syncLeaveTime(companyId, userId, startDate, endDate);
-//        return new HttpRespMsg();
-//    }
+    @RequestMapping("/syncLeaveTime")
+    public HttpRespMsg syncLeaveTime(Integer companyId, String userId, String startDate, String endDate) {
+        dingDingService.syncLeaveTime(companyId, userId, startDate, endDate);
+        return new HttpRespMsg();
+    }
 
     @RequestMapping("/fixAttendance")
     public HttpRespMsg fixAttendance(Integer companyId) {

+ 50 - 41
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DingDingServiceImpl.java

@@ -1933,9 +1933,17 @@ public class DingDingServiceImpl implements DingDingService {
             //全部的
             List<TimeType> timeTypes = timeTypeMapper.selectList(new QueryWrapper<TimeType>().eq("sync_dingding", 1));
             List<Integer> companyIds = timeTypes.stream().map(TimeType::getCompanyId).collect(Collectors.toList());
-            List<CompanyDingding> dingdingList = companyDingdingMapper.selectList(new QueryWrapper<CompanyDingding>().in("company_id", companyIds));
-            for (CompanyDingding dingding : dingdingList) {
-                syncOneCompLeave(dingding, userId, startDate, endDate);
+            if (companyIds.size() == 0) {
+                return;
+            }
+            List<Company> companyList = companyMapper.selectList(new QueryWrapper<Company>().in("id", companyIds).ge("expiration_date", LocalDateTime.now()));
+            if (companyList.size() > 0) {
+                //缩小公司范围,只同步有效期内的公司
+                companyIds = companyList.stream().map(Company::getId).collect(Collectors.toList());
+                List<CompanyDingding> dingdingList = companyDingdingMapper.selectList(new QueryWrapper<CompanyDingding>().in("company_id", companyIds));
+                for (CompanyDingding dingding : dingdingList) {
+                    syncOneCompLeave(dingding, userId, startDate, endDate);
+                }
             }
         }
     }
@@ -1961,6 +1969,7 @@ public class DingDingServiceImpl implements DingDingService {
         }
     }
 
+    //仅适用于钉钉企业内部应用
     private void sycUserOneDayWorkData(CompanyDingding dingding, String userId, String workDate, boolean showLog, boolean onlySyncAttendance) {
         List<User> userList = null;
         if (StringUtils.isEmpty(userId)) {
@@ -2172,44 +2181,44 @@ public class DingDingServiceImpl implements DingDingService {
                 OapiAttendanceGetleavetimebynamesResponse rsp = null;
                 try {
                     rsp = client.execute(req, accessToken);
-                    System.out.println(rsp.getBody());
-//                    JSONArray array = JSONObject.parseObject(rsp.getBody()).getJSONObject("result").getJSONArray("columns");
-//                    for (int i=0;i<array.size(); i++) {
-//                        JSONObject item = array.getJSONObject(i);
-//                        String leaveTypeName = item.getJSONObject("columnvo").getString("name");
-//                        int typeIndex = 0;
-//                        for (int index=0;index < Constant.LEAVE_TYPES.length; index++) {
-//                            if (Constant.LEAVE_TYPES[index].equals(leaveTypeName)) {
-//                                typeIndex = index;
-//                                break;
-//                            }
-//                        }
-//                        //获取请假的数据
-//                        JSONArray valArray = item.getJSONArray("columnvals");
-//                        for (int j=0;j<valArray.size(); j++) {
-//                            Float val = valArray.getJSONObject(j).getFloat("value");
-//                            String date = valArray.getJSONObject(j).getString("date");
-//                            LocalDate localDate = LocalDateTime.parse(date, dtf).toLocalDate();
-//                            if (val != null && val > 0.0) {
-//                                //存在请假时长
-//                                LeaveSheet sheet = new LeaveSheet();
-//                                sheet.setCompanyId(dingding.getCompanyId());
-//                                sheet.setOwnerId(u.getId());
-//                                sheet.setOwnerName(u.getName());
-//                                sheet.setLeaveType(typeIndex);
-//                                sheet.setTimeHours(val);
-//                                sheet.setStartDate(localDate);
-//                                sheet.setEndDate(localDate);
-//                                if (val >= timeType.getAllday()) {
-//                                    sheet.setTimeType(0);
-//                                    sheet.setTimeDays(1.0f);
-//                                } else {
-//                                    sheet.setTimeType(1);//按小时
-//                                }
-//                                sheetList.add(sheet);
-//                            }
-//                        }
-//                    }
+//                    System.out.println(rsp.getBody());
+                    JSONArray array = JSONObject.parseObject(rsp.getBody()).getJSONObject("result").getJSONArray("columns");
+                    for (int i=0;i<array.size(); i++) {
+                        JSONObject item = array.getJSONObject(i);
+                        String leaveTypeName = item.getJSONObject("columnvo").getString("name");
+                        int typeIndex = 0;
+                        for (int index=0;index < Constant.LEAVE_TYPES.length; index++) {
+                            if (Constant.LEAVE_TYPES[index].equals(leaveTypeName)) {
+                                typeIndex = index;
+                                break;
+                            }
+                        }
+                        //获取请假的数据
+                        JSONArray valArray = item.getJSONArray("columnvals");
+                        for (int j=0;j<valArray.size(); j++) {
+                            Float val = valArray.getJSONObject(j).getFloat("value");
+                            String date = valArray.getJSONObject(j).getString("date");
+                            LocalDate localDate = LocalDateTime.parse(date, dtf).toLocalDate();
+                            if (val != null && val > 0.0) {
+                                //存在请假时长
+                                LeaveSheet sheet = new LeaveSheet();
+                                sheet.setCompanyId(dingding.getCompanyId());
+                                sheet.setOwnerId(u.getId());
+                                sheet.setOwnerName(u.getName());
+                                sheet.setLeaveType(typeIndex);
+                                sheet.setTimeHours(val);
+                                sheet.setStartDate(localDate);
+                                sheet.setEndDate(localDate);
+                                if (val >= timeType.getAllday()) {
+                                    sheet.setTimeType(0);
+                                    sheet.setTimeDays(1.0f);
+                                } else {
+                                    sheet.setTimeType(1);//按小时
+                                }
+                                sheetList.add(sheet);
+                            }
+                        }
+                    }
                 } catch (ApiException e) {
                     e.printStackTrace();
                 }

+ 17 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/TimingTask.java

@@ -61,6 +61,8 @@ public class TimingTask {
     //是否是开发环境
     @Value("${configEnv.isDev}")
     boolean isDev;
+    @Value("${configEnv.isSaasProd}")
+    private boolean isSaasProd;
     @Value("${privateDeployURL.pcUrl}")
     private String pcUrl;
     //是否是私有化部署
@@ -252,8 +254,11 @@ public class TimingTask {
         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         String yesStr = dateTimeFormatter.format(yestoday);
         List<TimeType> typeList = timeTypeMapper.selectList(new QueryWrapper<TimeType>().eq("sync_dingding", 1));
-        for (TimeType type : typeList) {
-            Integer companyId = type.getCompanyId();
+        List<Integer> compIds = typeList.stream().map(TimeType::getCompanyId).collect(Collectors.toList());
+        if (compIds.size() == 0) return;
+        List<Company> companyList = companyMapper.selectList(new QueryWrapper<Company>().in("id", compIds).ge("expiration_date", LocalDateTime.now()));
+        for (Company company : companyList) {
+            Integer companyId = company.getId();
             System.out.println("钉钉同步:companyId="+companyId);
             dingDingService.syncCardTime(companyId, null, yesStr, yesStr);
         }
@@ -285,6 +290,10 @@ public class TimingTask {
     @Scheduled(cron = "0 11 2 ? * *")
     private void synDingDingWorkData() {
         if (isDev) return;
+        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDateTime yestoday = LocalDateTime.now().minusDays(2);
+        String startDate = dtf.format(yestoday);
+        String endDate = dtf.format(yestoday.plusDays(32));
         List<TimeType> timeTypeList = timeTypeMapper.selectList(new QueryWrapper<TimeType>().eq("sync_dingding", 1));
         if (timeTypeList.size() > 0) {
             List<Integer> compIds = timeTypeList.stream().map(TimeType::getCompanyId).collect(Collectors.toList());
@@ -293,10 +302,7 @@ public class TimingTask {
                     .isNotNull("inner_appkey"));
             System.out.println("==========获取钉钉内部应用的数量是:"+dingdingList.size());
             if (dingdingList.size() > 0) {
-                DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-                LocalDateTime yestoday = LocalDateTime.now().minusDays(2);
-                String startDate = dtf.format(yestoday);
-                String endDate = dtf.format(yestoday.plusDays(32));
+
                 for (int i=0;i<dingdingList.size(); i++) {
                     System.out.println("钉钉公司:"+dingdingList.get(i).getCorpName());
                     long t1 = System.currentTimeMillis();
@@ -306,8 +312,13 @@ public class TimingTask {
                 }
             }
         }
+        if (isSaasProd) {
+            dingDingService.syncLeaveTime(null, null, startDate, endDate);
+        }
     }
 
+
+
     //每个月五号一点推送上月日报信息
     @Scheduled(cron = "0 0 1 5 * ?")
     private void pushReportListByToken(){