Min пре 9 месеци
родитељ
комит
4f285fe0bc

+ 18 - 34
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserWithBeisenController.java

@@ -179,6 +179,8 @@ public class UserWithBeisenController {
             msg.setError("当前员工在北森系统中不存在,请完成录入员工信息");
             return msg;
         }
+        //todo 获取指定日期的日报数据
+        JSONArray dailyReportList = BeiSenUtils.getDailyReportList(createDate, beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 100);
         //todo 获取到指定日期的考勤数据
         JSONObject item = BeiSenUtils.getAttendanceStatisticWithUser(createDate,withBeisen.get().getUserId(), beisenConfig.getAppKey(), beisenConfig.getAppSecret());
         //todo 获取到指定日期的加班数据
@@ -264,7 +266,6 @@ public class UserWithBeisenController {
               }
             }
             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()){
                 //todo:之前的逻辑
@@ -352,39 +353,22 @@ public class UserWithBeisenController {
                         }
                     }
                 }
-                //处理修改
-                List<JSONObject> lastVacationList = 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("DocumentType").equals("请假")
-                            &&  (a.getString("ApproveStatus").equals("通过") || a.getString("ApproveStatus").equals("审批中"))){
-                        return true;
-                    }
-                    return false;
-                }).collect(Collectors.toList());
-                if(lastVacationList.size()>0){
-                    for (int i = 0; i < lastVacationList.size(); i++) {
-                        JSONObject vacation = lastVacationList.get(i);
-                        String vacationStartDateTime = vacation.getString("VacationStartDateTime");
-                        String VacationStopDateTime = vacation.getString("VacationStopDateTime");
-                    }
-                    double vacationDuration = lastVacationList.stream().mapToDouble(i -> i.getDouble("VacationDuration")).sum();
-                    BigDecimal decimal = new BigDecimal(vacationDuration);
-                    decimal=decimal.divide(new BigDecimal(60),1,RoundingMode.HALF_DOWN);
-//                            //可能存在休假多天 只减去一天
-                    if(decimal.doubleValue()>=8){
-                        workTime= workTime-8;
-                    }else {
-                        workTime= workTime-decimal.doubleValue();
-                    }
-                }
+                //根据日报处理休假时长
+               Stream<JSONObject> dailyReportStream = dailyReportList.stream().map(elment -> (JSONObject) elment);
+               List<JSONObject> list = dailyReportStream.filter(d -> d.getString("StaffId").equals(beisen.get().getUserId())).collect(Collectors.toList());
+               if(list.size()>0){
+                   //年假
+                   double annualLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("AnnualLeaveHour")).sum();
+                   //事假
+                   double casualLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("CasualLeaveHour")).sum();
+                   //病假
+                   double sickLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("SickLeaveHour")).sum();
+                   //婚假
+                   double marriageLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("MarriageLeaveHour")).sum();
+                   //产假
+                   double maternityLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("MaternityLeaveHour")).sum();
+                   workTime=workTime-annualLeaveHour-casualLeaveHour-sickLeaveHour-marriageLeaveHour-maternityLeaveHour;
+               }
             }
             UserFvTime userFvTime=new UserFvTime();
             userFvTime.setWorkDate(LocalDate.parse(createDate,df));

+ 64 - 35
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserWithBeisenServiceImpl.java

@@ -17,8 +17,10 @@ import com.management.platform.util.BeiSenUtils;
 import com.management.platform.util.DateTimeUtil;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.WorkDayCalculateUtils;
+import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -44,13 +46,21 @@ import java.util.stream.Stream;
 @Service
 public class UserWithBeisenServiceImpl extends ServiceImpl<UserWithBeisenMapper, UserWithBeisen> implements UserWithBeisenService {
 
+    @Resource
     private UserFvTimeService userFvTimeService;
+    @Resource
     private UserMapper userMapper;
+    @Resource
     private TimeTypeMapper timeTypeMapper;
+    @Resource
     private HttpServletRequest request;
+    @Resource
     private UserWithBeisenService userWithBeisenService;
+    @Resource
     private BeisenConfigMapper beisenConfigMapper;
+    @Resource
     private HolidaySettingService holidaySettingService;
+    @Resource
     private LeaveSheetService leaveSheetService;
 
     @Override
@@ -77,6 +87,7 @@ public class UserWithBeisenServiceImpl extends ServiceImpl<UserWithBeisenMapper,
         List<LocalDate> workDaysListInRange = WorkDayCalculateUtils.getWorkDaysListInRange(startDate, endDate, 1);
         JSONArray allOverTimeList=new JSONArray();
         JSONArray allVacationList=new JSONArray();
+        JSONArray allDailyReportList=new JSONArray();
         List<LeaveSheet> leaveSheetList=new ArrayList<>();
         //同步休假数据到工时管家
         for (int i = 0; i < allVacationList.size(); i++) {
@@ -134,9 +145,11 @@ public class UserWithBeisenServiceImpl extends ServiceImpl<UserWithBeisenMapper,
             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);
+            JSONArray dailyReportList = BeiSenUtils.getDailyReportList(df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 100);
             allOverTimeList.addAll(overTimeList);
             attendanceStatistics.addAll(statisticList);
             allVacationList.addAll(vacationList);
+            allDailyReportList.addAll(dailyReportList);
         }
         for (LocalDate localDate : workDaysListInRange) {
             Stream<JSONObject> swipingCardsStream = attendanceStatistics.stream().map(item -> (JSONObject) item);
@@ -176,6 +189,7 @@ public class UserWithBeisenServiceImpl extends ServiceImpl<UserWithBeisenMapper,
                     }
                     Stream<JSONObject> overTimeStream = allOverTimeList.stream().map(elment -> (JSONObject) elment);
                     Stream<JSONObject> vacationStream = allVacationList.stream().map(elment -> (JSONObject) elment);
+                    Stream<JSONObject> dailyReportStream = allDailyReportList.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()){
                         //todo:之前的逻辑
@@ -261,44 +275,59 @@ public class UserWithBeisenServiceImpl extends ServiceImpl<UserWithBeisenMapper,
                                 }
                             }
                         }
-                        //处理修改
-                        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("DocumentType").equals("请假")
-                                    &&  (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_DOWN);
-//                            //可能存在休假多天 只减去一天
-                            if(decimal.doubleValue()>=8){
-                                workTime= workTime-8;
-                            }else {
-                                workTime= workTime-decimal.doubleValue();
-                            }
-                        }else {
-//                            //在工时管家已经同步到的请假数据中找到当前人员的所有请假数据
-//                            List<LeaveSheet> list = leaveSheetService.list(new LambdaQueryWrapper<LeaveSheet>().eq(LeaveSheet::getOwnerId, beisen.get().getUserId()));
-//                            //当前考勤日期在工时同步到的请假数据开始请假和结束日期区间的数据
-//                            List<LeaveSheet> sheets = list.stream().filter(l -> (l.getStartDate().isBefore(localDate) || l.getStartDate().isEqual(localDate)) && (l.getEndDate().isAfter(localDate) || l.getEndDate().isEqual(localDate))).collect(Collectors.toList());
-//                            double sum = sheets.stream().mapToDouble(LeaveSheet::getTimeHours).sum();
-//                            if(sum>=8){
+//                        //处理修改
+//                        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("DocumentType").equals("请假")
+//                                    &&  (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_DOWN);
+////                            //可能存在休假多天 只减去一天
+//                            if(decimal.doubleValue()>=8){
 //                                workTime= workTime-8;
 //                            }else {
-//                                workTime= workTime-sum;
+//                                workTime= workTime-decimal.doubleValue();
 //                            }
+//                        }else {
+////                            //在工时管家已经同步到的请假数据中找到当前人员的所有请假数据
+////                            List<LeaveSheet> list = leaveSheetService.list(new LambdaQueryWrapper<LeaveSheet>().eq(LeaveSheet::getOwnerId, beisen.get().getUserId()));
+////                            //当前考勤日期在工时同步到的请假数据开始请假和结束日期区间的数据
+////                            List<LeaveSheet> sheets = list.stream().filter(l -> (l.getStartDate().isBefore(localDate) || l.getStartDate().isEqual(localDate)) && (l.getEndDate().isAfter(localDate) || l.getEndDate().isEqual(localDate))).collect(Collectors.toList());
+////                            double sum = sheets.stream().mapToDouble(LeaveSheet::getTimeHours).sum();
+////                            if(sum>=8){
+////                                workTime= workTime-8;
+////                            }else {
+////                                workTime= workTime-sum;
+////                            }
+//                        }
+                        //根据日报处理休假时长
+                        List<JSONObject> list = dailyReportStream.filter(d -> d.getString("StaffId").equals(beisen.get().getUserId())&&d.getString("Date").equals(df.format(localDate))).collect(Collectors.toList());
+                        if(list.size()>0){
+                            //年假
+                            double annualLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("AnnualLeaveHour")).sum();
+                            //事假
+                            double casualLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("CasualLeaveHour")).sum();
+                            //病假
+                            double sickLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("SickLeaveHour")).sum();
+                            //婚假
+                            double marriageLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("MarriageLeaveHour")).sum();
+                            //产假
+                            double maternityLeaveHour = list.stream().mapToDouble(l -> l.getDoubleValue("MaternityLeaveHour")).sum();
+                            workTime=workTime-annualLeaveHour-casualLeaveHour-sickLeaveHour-marriageLeaveHour-maternityLeaveHour;
                         }
                     }
                     UserFvTime userFvTime=new UserFvTime();

+ 38 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/BeiSenUtils.java

@@ -364,4 +364,42 @@ public class BeiSenUtils {
         return lastJSONArray;
     }
 
+    /**
+     * 获取人员日报数据
+     * */
+    public static JSONArray getDailyReportList(String day,String appkey,String appSecret,Integer pageIndex,Integer pageSize){
+        String url = "https://openapi.italent.cn/AttendanceOpen/api/v1/DailyReport/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("DailyReportList");
+                lastJSONArray.addAll(target);
+                if (target.size()>0){
+                    pageIndex++;
+                    JSONArray dailyReportList = getDailyReportList(day, appkey, appSecret, pageIndex, pageSize);
+                    lastJSONArray.addAll(dailyReportList);
+                }
+            }
+        }
+        return lastJSONArray;
+    }
+
 }