seyanew 2 giorni fa
parent
commit
38525e085c

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserCorpwxTimeController.java

@@ -832,7 +832,7 @@ public class UserCorpwxTimeController {
     public HttpRespMsg importZhengBeiAttendance(Integer companyId, @RequestParam("multipartFile") MultipartFile file) throws IOException {
         WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
         HttpRespMsg msg = new HttpRespMsg();
-        List<UserCorpwxTime> list = excelParserService.parseAttendanceExcel(file);
+        List<UserCorpwxTime> list = excelParserService.parseAttendanceExcel(file, companyId == 8268);
         list.forEach(l->{
             l.setCompanyId(companyId);
             l.setWxCorpid(wxCorpInfo.getCorpid());

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/DdingCardTimeItem.java

@@ -9,5 +9,7 @@ public class DdingCardTimeItem {
     private String userId;
     private Long userCheckTime;
     private String corpId;
+    private String invalidRecordType;
+    private String sourceType;
 
 }

+ 21 - 12
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ExcelParserService.java

@@ -9,6 +9,7 @@ import org.springframework.util.StringUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
@@ -18,7 +19,7 @@ import java.util.List;
 @Service
 public class ExcelParserService {
 
-    public List<UserCorpwxTime> parseAttendanceExcel(MultipartFile file) throws IOException {
+    public List<UserCorpwxTime> parseAttendanceExcel(MultipartFile file, boolean onlyReduceRestTime) throws IOException {
         List<UserCorpwxTime> attendanceList = new ArrayList<>();
 
         try (Workbook workbook = new XSSFWorkbook(file.getInputStream())) {
@@ -115,7 +116,7 @@ public class ExcelParserService {
                     // 计算工作时长(这里简化处理,实际需要更精确的计算)
                     if (startTime != null && endTime != null) {
                         try {
-                            double workHours = calculateZhengBeiWorkHours(startTime, endTime);
+                            double workHours = calculateZhengBeiWorkHours(startTime, endTime, false);
                             attendance.setWorkHours(workHours);
                         } catch (Exception e) {
                             // 时间格式不正确时忽略
@@ -163,21 +164,23 @@ public class ExcelParserService {
     }
 
     public static void main(String[] args) {
-        String startTime = "08:25";
+        String startTime = "08:20";
         String endTime = "12:30";
-        double workHours = calculateZhengBeiWorkHours(startTime, endTime);
+        double workHours = calculateZhengBeiWorkHours(startTime, endTime, true);
 
         System.out.println("工作时长:" + workHours + "小时");
     }
 
-    public static double calculateZhengBeiWorkHours(String startTime, String endTime) {
+
+
+    public static double calculateZhengBeiWorkHours(String startTime, String endTime, boolean onlyReduceRestTime) {
         // 简单计算工作时长(小时)
         if (startTime.compareTo("08:30") < 0 && endTime.compareTo("08:30") < 0) {
             //上下班都是八点半之前,忽略掉
             return 0;
         }
         // 实际应用中需要更精确的计算,考虑午休时间等
-        if (startTime.compareTo("08:30") < 0) {
+        if (!onlyReduceRestTime && startTime.compareTo("08:30") < 0) {
             startTime = "08:30";
         }
         // 12:00-13:00为午休,中间来的得从下午上班时间开始算
@@ -216,14 +219,20 @@ public class ExcelParserService {
         }
         double minPart = hours - (int)hours;
 
-        if (minPart > 0 && minPart < 0.5) {
-            minPart = 0;
-        } else if (minPart > 0.5) {
-            minPart = 0.5;
+        //按0.5小时对齐
+        if (!onlyReduceRestTime) {
+            if (minPart > 0 && minPart < 0.5) {
+                minPart = 0;
+            } else if (minPart > 0.5) {
+                minPart = 0.5;
+            }
         }
-        hours = (int)hours + minPart;
 
-        return hours;
+        hours = (int)hours + minPart;
+        //四舍五入到小数点后一位
+        BigDecimal bigDecimal = new BigDecimal(hours);
+        bigDecimal = bigDecimal.setScale(1, BigDecimal.ROUND_HALF_UP);
+        return bigDecimal.doubleValue();
     }
 
     private int convertWeekDay(String weekDayTxt) {

+ 13 - 10
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DingDingServiceImpl.java

@@ -2328,14 +2328,17 @@ public class DingDingServiceImpl implements DingDingService {
                             onDutyEarleast = find.get();
                         } else {
                             //如果没有上班数据,尝试查找invalidRecordType=Other, sourceType=APPROVE
-                            for (int i=0;i<array.size(); i++) {
-                                JSONObject object = array.getJSONObject(i);
-                                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);
-                                }
-                            }
-                            if (onDutyEarleast == null) {
+//                            for (int i=0;i<array.size(); i++) {
+//                                JSONObject object = array.getJSONObject(i);
+//                                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);
+//                                }
+//                            }
+                            Optional<DdingCardTimeItem> findApproveItem = oneDayTimes.stream().filter(item->"Other".equals(item.getInvalidRecordType()) && "APPROVE".equals(item.getCheckType())).findFirst();
+                            if (findApproveItem.isPresent()) {
+                                onDutyEarleast = findApproveItem.get();
+                            } else {
                                 //再尝试获取最早的下班打卡,作为上班时间,但是要在15:00之前
                                 find = oneDayTimes.stream().filter(p->"OffDuty".equals(p.getCheckType())).min(comparator);
                                 if (find.isPresent()) {
@@ -2386,8 +2389,8 @@ public class DingDingServiceImpl implements DingDingService {
                                 onDutyEarleast.setUserCheckTime(timeInSeconds*1000);
                             }
                             if (SysConstant.ZhengBeiCompIds.contains(dingding.getCompanyId())) {
-                                //休息时间段:苏州正北-午休12:00-13:00, 晚修:17:30-18:00
-                                double workHours = ExcelParserService.calculateZhengBeiWorkHours(timeItem.getStartTime(), timeItem.getEndTime());
+                                //休息时间段:苏州正北-午休12:00-13:00, 晚修:17:30-18:00;正北液金不做0.5小时的对齐
+                                double workHours = ExcelParserService.calculateZhengBeiWorkHours(timeItem.getStartTime(), timeItem.getEndTime(), dingding.getCompanyId() == 8268);
                                 //如果工作时长大于8小时,需要检查是否有当天的请假,有的话得减去请假的时长
                                 if (workHours >= 8.0) {
                                     List<LeaveSheet> leaveSheets = leaveSheetMapper.selectList(new QueryWrapper<LeaveSheet>()