Browse Source

钉钉同步考勤人员错位问题

seyanew 2 days ago
parent
commit
e53b67616c

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

@@ -19,10 +19,12 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
@@ -191,6 +193,40 @@ public class DingDingController {
         return new HttpRespMsg();
     }
 
+    @RequestMapping("/syncCompCardAndLeaveTime")
+    public HttpRespMsg syncCompCardAndLeaveTime(Integer companyId, String startDate, String endDate) {
+        HttpRespMsg msg = new HttpRespMsg();
+        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate sDate = LocalDate.parse(startDate, dtf);
+        LocalDate eDate = LocalDate.parse(endDate, dtf);
+        //计算sDate和eDate之间的间隔天数
+
+        if (ChronoUnit.DAYS.between(sDate, eDate) > 31) {
+            msg.setError("日期间隔不得超过31天");
+            return msg;
+        }
+        //时间跨度超过7天需要分批执行
+        if (ChronoUnit.DAYS.between(sDate, eDate) > 6) {
+            LocalDate fromDate = sDate;
+            LocalDate toDate = null;
+            while (fromDate.isBefore(eDate)) {
+                toDate = fromDate.plusDays(6);
+                if (toDate.isAfter(eDate)) {
+                    toDate = eDate;
+                }
+                dingDingService.syncLeaveTime(companyId, null, dtf.format(fromDate), dtf.format(toDate));
+                dingDingService.syncCardTime(companyId, null, dtf.format(fromDate), dtf.format(toDate));
+                fromDate = toDate.plusDays(1);
+            }
+        } else {
+            dingDingService.syncLeaveTime(companyId, null, startDate, endDate);
+            dingDingService.syncCardTime(companyId, null, startDate, endDate);
+        }
+
+        return new HttpRespMsg();
+    }
+
+
     @RequestMapping("/refreshUserCardTime")
     public HttpRespMsg refreshUserCardTime(Integer companyId, String userId, String date) {
         //同步请假数据

+ 11 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DingDingServiceImpl.java

@@ -2246,6 +2246,15 @@ 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) {
@@ -2321,7 +2330,8 @@ public class DingDingServiceImpl implements DingDingService {
                             //如果没有上班数据,尝试查找invalidRecordType=Other, sourceType=APPROVE
                             for (int i=0;i<array.size(); i++) {
                                 JSONObject object = array.getJSONObject(i);
-                                if ("Other".equals(object.getString("invalidRecordType")) && "APPROVE".equals(object.getString("sourceType"))) {
+                                long workDateTime = object.getLong("workDate");
+                                if (object.getString("userId").equals(key) && d == workDateTime && "Other".equals(object.getString("invalidRecordType")) && "APPROVE".equals(object.getString("sourceType"))) {
                                     onDutyEarleast = JSONObject.toJavaObject(object, DdingCardTimeItem.class);
                                 }
                             }

+ 22 - 1
fhKeeper/formulahousekeeper/timesheet/src/views/settings/timetype.vue

@@ -381,6 +381,22 @@
             </el-date-picker>
             <el-button type="primary" :loading="attendanceSynchronizationLoading" @click="startSynchronizing()" size="small" :disabled="!attendanceSynchronizationDate.length">开始同步</el-button>
         </div>
+        <div class="yanjiu" v-if="user.timeType.showDdCardtime">
+            <p style="margin-left:10px;color:#666;">同步钉钉考勤</p>
+            <el-date-picker
+                v-model="attendanceSynchronizationDate"
+                type="daterange"
+                range-separator="至"
+                start-placeholder="开始日期"
+                end-placeholder="结束日期"
+                value-format="yyyy-MM-dd" 
+                size="small"
+                :picker-options="pickerOptions"
+                style="margin: 0 20px;">
+            </el-date-picker>
+            <el-button type="primary" :loading="attendanceSynchronizationLoading" @click="startSynchronizing()" size="small" :disabled="!attendanceSynchronizationDate.length">开始同步</el-button>
+        </div>
+        
         <div class="yanjiu">
             <p style="margin-left:10px;color:#666;">{{ $t('riBaoShenHeMoShi') }}</p><el-tag style="margin-left:10px;" type="plain">{{reportAuditTypeArray[timeType.reportAuditType]}}
                 <el-tooltip effect="dark" :content="$t('ruXuXiuGaiWeiQiTaShenHeMoShiQingLianXiKeFu')" placement="top-start">
@@ -1034,7 +1050,12 @@
          methods: {
             startSynchronizing() {
                 this.attendanceSynchronizationLoading = true;
-                this.http.post('/user-with-beisen/syncAttendanceFromBeisen',{
+                var url = '/user-with-beisen/syncAttendanceFromBeisen';
+                if (this.user.timeType.showDdCardtime) {
+                    url = "/dingding/syncCompCardAndLeaveTime";
+                }
+                this.http.post(url,{
+                    companyId: this.user.companyId,
                     startDate: this.attendanceSynchronizationDate[0],
                     endDate: this.attendanceSynchronizationDate[1],
                 },