|
@@ -4,14 +4,17 @@ package com.management.platform.controller;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.management.platform.entity.BeisenConfig;
|
|
|
-import com.management.platform.entity.UserWithBeisen;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.management.platform.entity.*;
|
|
|
import com.management.platform.mapper.BeisenConfigMapper;
|
|
|
+import com.management.platform.mapper.TimeTypeMapper;
|
|
|
import com.management.platform.mapper.UserMapper;
|
|
|
import com.management.platform.mapper.UserWithBeisenMapper;
|
|
|
+import com.management.platform.service.UserFvTimeService;
|
|
|
import com.management.platform.service.UserWithBeisenService;
|
|
|
import com.management.platform.util.BeiSenUtils;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.management.platform.util.WorkDayCalculateUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
@@ -19,9 +22,16 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -43,6 +53,10 @@ public class UserWithBeisenController {
|
|
|
private UserWithBeisenService userWithBeisenService;
|
|
|
@Resource
|
|
|
private BeisenConfigMapper beisenConfigMapper;
|
|
|
+ @Resource
|
|
|
+ private UserFvTimeService userFvTimeService;
|
|
|
+ @Resource
|
|
|
+ private TimeTypeMapper timeTypeMapper;
|
|
|
|
|
|
@RequestMapping("/getByTimeWindow")
|
|
|
public HttpRespMsg getByTimeWindow(String startTime,String stopTime){
|
|
@@ -130,5 +144,87 @@ public class UserWithBeisenController {
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @RequestMapping("syncAttendanceFromBeisen")
|
|
|
+ public HttpRespMsg syncAttendanceFromBeisen(String startDate,String endDate){
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ DateTimeFormatter df1=DateTimeFormatter.ofPattern("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));
|
|
|
+ BeisenConfig beisenConfig = beisenConfigMapper.selectById(companyId);
|
|
|
+ if(beisenConfig==null){
|
|
|
+ msg.setError("北森基础数据配置未完成,请联系服务商完成配置");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ //todo 获取到指定日期的考勤数据
|
|
|
+ JSONArray attendanceStatistics = BeiSenUtils.getAttendanceStatistics(startDate, endDate, beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 300);
|
|
|
+ //todo 获取到指定日期的加班数据
|
|
|
+ List<LocalDate> workDaysListInRange = WorkDayCalculateUtils.getWorkDaysListInRange(startDate, endDate, 1);
|
|
|
+ JSONArray allOverTimeList=new JSONArray();
|
|
|
+ List<UserFvTime> userFvTimeList=new ArrayList<>();
|
|
|
+ for (LocalDate localDate : workDaysListInRange) {
|
|
|
+ JSONArray overTimeList = BeiSenUtils.getOverTimeList(df.format(localDate), beisenConfig.getAppKey(), beisenConfig.getAppSecret(), 1, 300);
|
|
|
+ allOverTimeList.addAll(overTimeList);
|
|
|
+ }
|
|
|
+ for (LocalDate localDate : workDaysListInRange) {
|
|
|
+ Stream<JSONObject> swipingCardsStream = attendanceStatistics.stream().map(item -> (JSONObject) item);
|
|
|
+ //todo: 获取当天的考勤数据
|
|
|
+ List<JSONObject> swipingCardDateList = swipingCardsStream.filter(i -> LocalDate.parse(i.getString("SwipingCardDate")).equals(localDate)).collect(Collectors.toList());
|
|
|
+ for (JSONObject item : swipingCardDateList) {
|
|
|
+ //获取当前数据下的人员工号对应到工时管家
|
|
|
+ String cardNumber = item.getString("CardNumber");
|
|
|
+ Optional<User> first = userList.stream().filter(f -> f.getJobNumber().equals(cardNumber)).findFirst();
|
|
|
+ //todo: 获取考勤打卡时间集合
|
|
|
+ JSONArray times = item.getJSONArray("Times");
|
|
|
+ Stream<JSONObject> timeStream = times.stream().map(time -> (JSONObject) time);
|
|
|
+ //获取最早上班打卡时间
|
|
|
+ List<LocalTime> minLocalTimeList = timeStream.filter(t -> t.getIntValue("Type") == 1).map(i -> LocalTime.parse(i.getString("ActualTime"))).collect(Collectors.toList());
|
|
|
+ Optional<LocalTime> min = minLocalTimeList.stream().min(LocalTime::compareTo);
|
|
|
+ //获取最早上班打卡时间
|
|
|
+ List<LocalTime> maxLocalTimeList = timeStream.filter(t -> t.getIntValue("Type") == 9).map(i -> LocalTime.parse(i.getString("ActualTime"))).collect(Collectors.toList());
|
|
|
+ Optional<LocalTime> max = maxLocalTimeList.stream().max(LocalTime::compareTo);
|
|
|
+ LocalTime maxTime=LocalTime.parse("18:00",df1);
|
|
|
+ if(max.isPresent()){
|
|
|
+ maxTime=max.get();
|
|
|
+ }
|
|
|
+ //获取最晚下班时间
|
|
|
+ if(first.isPresent()){
|
|
|
+ boolean workDay = WorkDayCalculateUtils.isWorkDay(localDate);
|
|
|
+ //todo:针对景昱 工作日默认以8小时工作制度加上加班时长 非工作日以加班时长为准
|
|
|
+ if(companyId==5978){
|
|
|
+ Double workTime=8.0;
|
|
|
+ Stream<JSONObject> overTimeStream = allOverTimeList.stream().map(elment -> (JSONObject) elment);
|
|
|
+ List<JSONObject> overTimeList = overTimeStream.filter(a -> LocalDate.parse(a.getString("StartDate"), df).equals(localDate)
|
|
|
+ && a.getIntValue("ApproveStatus") == 2).collect(Collectors.toList());
|
|
|
+ double actualOverTimeDuration = overTimeList.stream().mapToDouble(i -> i.getDouble("ActualOverTimeDuration")).sum();
|
|
|
+ //存在加班的情况在下班打卡时间后面加上对应的时间
|
|
|
+ if(actualOverTimeDuration>0){
|
|
|
+ String[] split = String.valueOf(actualOverTimeDuration).split("\\.");
|
|
|
+ maxTime=maxTime.plusHours(Integer.valueOf(split[0])).plusMinutes(Long.valueOf("0."+split[1])*60);
|
|
|
+ }
|
|
|
+ if(workDay){
|
|
|
+ workTime= workTime+actualOverTimeDuration;
|
|
|
+ }else {
|
|
|
+ workTime= actualOverTimeDuration;
|
|
|
+ }
|
|
|
+ UserFvTime userFvTime=new UserFvTime();
|
|
|
+ userFvTime.setWorkDate(localDate);
|
|
|
+ userFvTime.setStartTime(min.isPresent()?df1.format(min.get()):"09:00");
|
|
|
+ userFvTime.setEndTime(df1.format(maxTime));
|
|
|
+ userFvTime.setUserId(first.get().getId());
|
|
|
+ userFvTime.setCompanyId(companyId);
|
|
|
+ userFvTime.setWorkHours(workTime.floatValue());
|
|
|
+ }else {
|
|
|
+ UserFvTime userFvTime=new UserFvTime();
|
|
|
+ userFvTime.setWorkDate(localDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|