Преглед изворни кода

景昱 考勤同步调整 休假数据参与计算

Min пре 1 година
родитељ
комит
cbbc51d135

+ 83 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserWithBeisenController.java

@@ -24,6 +24,8 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -147,6 +149,7 @@ public class UserWithBeisenController {
         DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
         DateTimeFormatter df1=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         DateTimeFormatter df2=DateTimeFormatter.ofPattern("HH:mm");
+        DateTimeFormatter df3=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
         Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
         TimeType timeType = timeTypeMapper.selectById(companyId);
         List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
@@ -161,12 +164,15 @@ public class UserWithBeisenController {
         //todo 获取到指定日期的加班数据
         List<LocalDate> workDaysListInRange = WorkDayCalculateUtils.getWorkDaysListInRange(startDate, endDate, 1);
         JSONArray allOverTimeList=new JSONArray();
+        JSONArray allVacationList=new JSONArray();
         List<UserFvTime> userFvTimeList=new ArrayList<>();
         for (LocalDate localDate : workDaysListInRange) {
             JSONArray statisticList = BeiSenUtils.getAttendanceStatistics(df.format(localDate), df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 100);
             JSONArray overTimeList = BeiSenUtils.getOverTimeList(df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 100);
+            JSONArray vacationList = BeiSenUtils.getVacationList(df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(),1,100);
             allOverTimeList.addAll(overTimeList);
             attendanceStatistics.addAll(statisticList);
+            allVacationList.addAll(vacationList);
         }
         for (LocalDate localDate : workDaysListInRange) {
             Stream<JSONObject> swipingCardsStream = attendanceStatistics.stream().map(item -> (JSONObject) item);
@@ -183,15 +189,25 @@ public class UserWithBeisenController {
                 //获取最早上班打卡时间
                 List<LocalTime> minLocalTimeList = timeStream.filter(t -> t.getIntValue("Type") == 1).map(i -> LocalDateTime.parse(i.getString("ActualTime"),df1).toLocalTime()).collect(Collectors.toList());
                 Optional<LocalTime> min = minLocalTimeList.stream().min(LocalTime::compareTo);
-                //获取最早上班打卡时间
+                //获取最晚下班时间
                 List<LocalTime> maxLocalTimeList = timeStream1.filter(t -> t.getIntValue("Type") == 9).map(i -> LocalDateTime.parse(i.getString("ActualTime"),df1).toLocalTime()).collect(Collectors.toList());
                 Optional<LocalTime> max = maxLocalTimeList.stream().max(LocalTime::compareTo);
-                //获取最晚下班时间
                 if(first.isPresent()){
                     boolean workDay = WorkDayCalculateUtils.isWorkDay(localDate);
                     //todo:针对景昱 工作日默认以8小时工作制度加上加班时长 非工作日以加班时长为准
-                    Double workTime=8.0;
+                    Duration between = Duration.between(min.get(), max.get());
+                    Double workTime;
+                    if(between.toHours()>8){
+                        workTime=8.0;
+                    }else if(between.toHours()<0){
+                        workTime=0.0;
+                    }else {
+                        BigDecimal decimal = new BigDecimal(between.toMinutes());
+                        decimal=decimal.divide(new BigDecimal(60),1,RoundingMode.HALF_UP);
+                        workTime=decimal.doubleValue();
+                    }
                     Stream<JSONObject> overTimeStream = allOverTimeList.stream().map(elment -> (JSONObject) elment);
+                    Stream<JSONObject> vacationStream = allVacationList.stream().map(elment -> (JSONObject) elment);
                     Optional<UserWithBeisen> beisen = userWithBeisenList.stream().filter(u -> u.getJobNumber() != null && u.getJobNumber().equals(first.get().getJobNumber())).findFirst();
                     if(beisen.isPresent()){
                         //审核通过以及审批中都算
@@ -206,6 +222,35 @@ public class UserWithBeisenController {
                                 workTime= actualOverTimeDuration;
                             }
                         }
+                        //处理修改
+                        List<JSONObject> vacationList = vacationStream.filter(a ->{
+                            LocalDate vacationStartDate = LocalDateTime.parse(a.getString("VacationStartDateTime"), df3).toLocalDate();
+                            LocalDate vacationStopDate = LocalDateTime.parse(a.getString("VacationStopDateTime"), df3).toLocalDate();
+                            boolean b=false;
+                            if((localDate.isAfter(vacationStartDate)||localDate.isEqual(vacationStartDate))
+                                    &&(localDate.isBefore(vacationStopDate)||localDate.isEqual(vacationStopDate))){
+                                b=true;
+                            }
+                            if(a.getString("StaffId").equals(beisen.get().getUserId())
+                                    && b
+                                    &&  (a.getString("ApproveStatus").equals("通过") || a.getString("ApproveStatus").equals("审批中"))){
+                                return true;
+                            }
+                            return false;
+                        }).collect(Collectors.toList());
+                        if(vacationList.size()>0){
+                            double vacationDuration = vacationList.stream().mapToDouble(i -> i.getDouble("VacationDuration")).sum();
+                            BigDecimal decimal = new BigDecimal(vacationDuration);
+                            decimal=decimal.divide(new BigDecimal(60),1,RoundingMode.HALF_UP);
+                            //考勤打卡区间大于8小时 但是存在休假数据
+                            if(between.toHours()>8){
+                                if(decimal.doubleValue()>8){
+                                    workTime= workTime-8;
+                                }else {
+                                    workTime= workTime-decimal.doubleValue();
+                                }
+                            }
+                        }
                     }
                     UserFvTime userFvTime=new UserFvTime();
                     userFvTime.setWorkDate(localDate);
@@ -237,6 +282,7 @@ public class UserWithBeisenController {
         DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
         DateTimeFormatter df1=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         DateTimeFormatter df2=DateTimeFormatter.ofPattern("HH:mm");
+        DateTimeFormatter df3=DateTimeFormatter.ofPattern("HH:mm:ss");
         User user = userMapper.selectById(request.getHeader("token"));
         Integer companyId = user.getCompanyId();
         TimeType timeType = timeTypeMapper.selectById(companyId);
@@ -247,15 +293,17 @@ public class UserWithBeisenController {
             msg.setError("北森基础数据配置未完成,请联系服务商完成配置");
             return msg;
         }
-        //todo 获取到指定日期的考勤数据
-        //todo 获取到指定日期的加班数据
         Optional<UserWithBeisen> withBeisen = userWithBeisenList.stream().filter(u ->u.getJobNumber()!=null&& u.getJobNumber().equals(user.getJobNumber())).findFirst();
         if(!withBeisen.isPresent()){
             msg.setError("当前员工在北森系统中不存在,请完成录入员工信息");
             return msg;
         }
+        //todo 获取到指定日期的考勤数据
         JSONObject item = BeiSenUtils.getAttendanceStatisticWithUser(createDate,withBeisen.get().getUserId(), beisenConfig.getAppKey(), beisenConfig.getAppSecret());
+        //todo 获取到指定日期的加班数据
         JSONArray allOverTimeList = BeiSenUtils.getOverTimeList(createDate,beisenConfig.getAppKey(),beisenConfig.getAppSecret(),1,100);
+        //todo 获取到指定日期的休假数据
+        JSONArray vacationList = BeiSenUtils.getVacationList(createDate, beisenConfig.getAppKey(), beisenConfig.getAppSecret(),1,100);
         //获取当前数据下的人员工号对应到工时管家
         Optional<User> first = userList.stream().filter(f -> f.getJobNumber().equals(withBeisen.get().getJobNumber())).findFirst();
         System.out.println("考勤数据:"+item.toString());
@@ -266,8 +314,19 @@ public class UserWithBeisenController {
         if(first.isPresent()){
             boolean workDay = WorkDayCalculateUtils.isWorkDay(LocalDate.parse(createDate,df));
             //todo:针对景昱 工作日默认以8小时工作制度加上加班时长 非工作日以加班时长为准
-            Double workTime=8.0;
+            Double workTime;
+            Duration between = Duration.between(LocalTime.parse(firstCard, df3), LocalTime.parse(lastCard, df3));
+            if(between.toHours()>8){
+                workTime=8.0;
+            }else if(between.toHours()<0) {
+                workTime=0.0;
+            }else {
+                BigDecimal decimal = new BigDecimal(between.toMinutes());
+                decimal=decimal.divide(new BigDecimal(60),1,RoundingMode.HALF_UP);
+                workTime=decimal.doubleValue();
+            }
             Stream<JSONObject> overTimeStream = allOverTimeList.stream().map(elment -> (JSONObject) elment);
+            Stream<JSONObject> vacationStream = vacationList.stream().map(elment -> (JSONObject) elment);
             Optional<UserWithBeisen> beisen = userWithBeisenList.stream().filter(u -> u.getJobNumber() != null && u.getJobNumber().equals(first.get().getJobNumber())).findFirst();
             if(beisen.isPresent()){
                 List<JSONObject> overTimeList = overTimeStream.filter(a -> a.getString("StaffId").equals(beisen.get().getUserId())
@@ -280,11 +339,27 @@ public class UserWithBeisenController {
                         workTime= actualOverTimeDuration;
                     }
                 }
+                //计算休假
+                List<JSONObject> targetVacation = vacationStream.filter(a -> a.getString("StaffId").equals(beisen.get().getUserId())
+                        && (a.getString("ApproveStatus").equals("通过") || a.getString("ApproveStatus").equals("审批中"))).collect(Collectors.toList());
+                if(targetVacation.size()>0){
+                    double vacationDuration = targetVacation.stream().mapToDouble(i -> i.getDouble("VacationDuration")).sum();
+                    BigDecimal decimal = new BigDecimal(vacationDuration);
+                    decimal=decimal.divide(new BigDecimal(60),1,RoundingMode.HALF_UP);
+                    //考勤打卡区间大于8小时 但是存在休假数据
+                    if(between.toHours()>8){
+                        if(decimal.doubleValue()>8){
+                            workTime= workTime-8;
+                        }else {
+                            workTime= workTime-decimal.doubleValue();
+                        }
+                    }
+                }
             }
             UserFvTime userFvTime=new UserFvTime();
             userFvTime.setWorkDate(LocalDate.parse(createDate,df));
-            userFvTime.setStartTime(!StringUtils.isEmpty(firstCard)?firstCard:"08:30");
-            userFvTime.setEndTime(!StringUtils.isEmpty(lastCard)?lastCard:"17:30");
+            userFvTime.setStartTime(!StringUtils.isEmpty(firstCard)?firstCard:"08:30:00");
+            userFvTime.setEndTime(!StringUtils.isEmpty(lastCard)?lastCard:"17:30:00");
             userFvTime.setUserId(first.get().getId());
             userFvTime.setCompanyId(companyId);
             userFvTime.setWorkHours(workTime.floatValue());

+ 47 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/TimingTask.java

@@ -38,6 +38,7 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.security.SecureRandom;
 import java.sql.Time;
 import java.sql.Timestamp;
@@ -2069,6 +2070,7 @@ public class TimingTask {
         DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
         DateTimeFormatter df1=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         DateTimeFormatter df2=DateTimeFormatter.ofPattern("HH:mm");
+        DateTimeFormatter df3=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
         String startDate=LocalDate.now().minusDays(1).format(df);
         String endDate=LocalDate.now().plusDays(1).format(df);
         List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, 5978));
@@ -2082,13 +2084,16 @@ public class TimingTask {
         List<LocalDate> workDaysListInRange = WorkDayCalculateUtils.getWorkDaysListInRange(startDate, endDate, 1);
         JSONArray allOverTimeList=new JSONArray();
         JSONArray attendanceStatistics=new JSONArray();
+        JSONArray allVacationList=new JSONArray();
         List<UserFvTime> userFvTimeList=new ArrayList<>();
         for (LocalDate localDate : workDaysListInRange) {
             JSONArray overTimeList = BeiSenUtils.getOverTimeList(df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 100);
             //todo 获取到指定日期的考勤数据
             JSONArray attendanceStatisticList = BeiSenUtils.getAttendanceStatistics(df.format(localDate), df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 100);
+            JSONArray vacationList = BeiSenUtils.getVacationList(df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(),1,100);
             allOverTimeList.addAll(overTimeList);
             attendanceStatistics.addAll(attendanceStatisticList);
+            allVacationList.addAll(vacationList);
         }
         for (LocalDate localDate : workDaysListInRange) {
             Stream<JSONObject> swipingCardsStream = attendanceStatistics.stream().map(item -> (JSONObject) item);
@@ -2112,8 +2117,19 @@ public class TimingTask {
                 if(first.isPresent()){
                     boolean workDay = WorkDayCalculateUtils.isWorkDay(localDate);
                     //todo:针对景昱 工作日默认以8小时工作制度加上加班时长 非工作日以加班时长为准
-                    Double workTime=8.0;
+                    Duration between = Duration.between(min.get(), max.get());
+                    Double workTime;
+                    if(between.toHours()>8){
+                        workTime=8.0;
+                    }else if(between.toHours()<0){
+                        workTime=0.0;
+                    }else {
+                        BigDecimal decimal = new BigDecimal(between.toMinutes());
+                        decimal=decimal.divide(new BigDecimal(60),1, RoundingMode.HALF_UP);
+                        workTime=decimal.doubleValue();
+                    }
                     Stream<JSONObject> overTimeStream = allOverTimeList.stream().map(elment -> (JSONObject) elment);
+                    Stream<JSONObject> vacationStream = allVacationList.stream().map(elment -> (JSONObject) elment);
                     Optional<UserWithBeisen> beisen = userWithBeisenList.stream().filter(u -> u.getJobNumber() != null && u.getJobNumber().equals(first.get().getJobNumber())).findFirst();
                     if(beisen.isPresent()){
                         List<JSONObject> overTimeList = overTimeStream.filter(a -> a.getString("StaffId").equals(beisen.get().getUserId())
@@ -2127,11 +2143,39 @@ public class TimingTask {
                                 workTime= actualOverTimeDuration;
                             }
                         }
+                        List<JSONObject> vacationList = vacationStream.filter(a ->{
+                            LocalDate vacationStartDate = LocalDateTime.parse(a.getString("VacationStartDateTime"), df3).toLocalDate();
+                            LocalDate vacationStopDate = LocalDateTime.parse(a.getString("VacationStopDateTime"), df3).toLocalDate();
+                            boolean b=false;
+                            if((localDate.isAfter(vacationStartDate)||localDate.isEqual(vacationStartDate))
+                                    &&(localDate.isBefore(vacationStopDate)||localDate.isEqual(vacationStopDate))){
+                                b=true;
+                            }
+                            if(a.getString("StaffId").equals(beisen.get().getUserId())
+                                    && b
+                                    &&  (a.getString("ApproveStatus").equals("通过") || a.getString("ApproveStatus").equals("审批中"))){
+                                return true;
+                            }
+                            return false;
+                        }).collect(Collectors.toList());
+                        if(vacationList.size()>0){
+                            double vacationDuration = vacationList.stream().mapToDouble(i -> i.getDouble("VacationDuration")).sum();
+                            BigDecimal decimal = new BigDecimal(vacationDuration);
+                            decimal=decimal.divide(new BigDecimal(60),1,RoundingMode.HALF_UP);
+                            //考勤打卡区间大于8小时 但是存在休假数据
+                            if(between.toHours()>8){
+                                if(decimal.doubleValue()>8){
+                                    workTime= workTime-8;
+                                }else {
+                                    workTime= workTime-decimal.doubleValue();
+                                }
+                            }
+                        }
                     }
                     UserFvTime userFvTime=new UserFvTime();
                     userFvTime.setWorkDate(localDate);
-                    userFvTime.setStartTime(min.isPresent()?df2.format(min.get()):"08:30");
-                    userFvTime.setEndTime(max.isPresent()?df2.format(max.get()):"17:30");
+                    userFvTime.setStartTime(min.isPresent()?df2.format(min.get()):"08:30:00");
+                    userFvTime.setEndTime(max.isPresent()?df2.format(max.get()):"17:30:00");
                     userFvTime.setUserId(first.get().getId());
                     userFvTime.setCompanyId(5978);
                     userFvTime.setWorkHours(workTime.floatValue());

+ 54 - 21
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/BeiSenUtils.java

@@ -110,27 +110,22 @@ public class BeiSenUtils {
                 requestMap.put("columns",columns);
             }
         }
-        //针对威派格的参数
-        {
-            List<Integer> serviceType=new ArrayList<>();
-            serviceType.add(0);
-            serviceType.add(1);
-            List<String> employType=new ArrayList<>();
-            employType.add("0");
-            employType.add("2");
-            List<Integer> empStatus=new ArrayList<>();
-            empStatus.add(2);
-            empStatus.add(3);
-            empStatus.add(6);
-            empStatus.add(8);
-            if(companyId!=null && companyId==936){
-                requestMap.put("serviceType",serviceType);
-                requestMap.put("employType",employType);
-                requestMap.put("empStatus",empStatus);
-                requestMap.put("isWithDeleted",true);
-                requestMap.put("enableTranslate",true);
-            }
-        }
+        List<Integer> serviceType=new ArrayList<>();
+        serviceType.add(0);
+        serviceType.add(1);
+        List<String> employType=new ArrayList<>();
+        employType.add("0");
+        employType.add("2");
+        List<Integer> empStatus=new ArrayList<>();
+        empStatus.add(2);
+        empStatus.add(3);
+        empStatus.add(6);
+        empStatus.add(8);
+        requestMap.put("serviceType",serviceType);
+        requestMap.put("employType",employType);
+        requestMap.put("empStatus",empStatus);
+        requestMap.put("isWithDeleted",true);
+        requestMap.put("enableTranslate",true);
         System.out.println("--------headers请求头数据-------"+headers);
         if(!StringUtils.isEmpty(scrollId)){
             requestMap.put("scrollId",scrollId);
@@ -331,4 +326,42 @@ public class BeiSenUtils {
         return data;
     }
 
+    /**
+     * 获取人员休假数据
+     * */
+    public static JSONArray getVacationList(String day,String appkey,String appSecret,Integer pageIndex,Integer pageSize){
+        String url = "https://openapi.italent.cn/AttendanceOpen/api/v1/Vacation/GetList";
+        HttpHeaders headers = new HttpHeaders();
+        RestTemplate restTemplate = new RestTemplate();
+        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
+        headers.setContentType(type);
+        String accessToken = getToken(appkey,appSecret);
+        System.out.println("--------Bearer TOKEN--------"+accessToken);
+        headers.add("Authorization","Bearer "+accessToken);
+        JSONObject requestMap = new JSONObject();
+        requestMap.put("Day",day);
+        requestMap.put("PageIndex",pageIndex);
+        requestMap.put("PageSize",pageSize);
+        System.out.println("--------headers请求头数据-------"+headers);
+        System.out.println("--------requestMap请求参数-------"+requestMap);
+        HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
+        ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
+        JSONArray lastJSONArray=new JSONArray();
+        if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
+            String resp= ResponseEntity.getBody();
+            JSONObject respJson = JSONObject.parseObject(resp);
+            if(respJson.getIntValue("Code")==200){
+                JSONObject data = respJson.getJSONObject("Data");
+                JSONArray target = data.getJSONArray("VacationList");
+                lastJSONArray.addAll(target);
+                if (target.size()>0){
+                    pageIndex++;
+                    JSONArray overTimeList = getVacationList(day, appkey, appSecret, pageIndex, pageSize);
+                    lastJSONArray.addAll(overTimeList);
+                }
+            }
+        }
+        return lastJSONArray;
+    }
+
 }