|
@@ -4,14 +4,18 @@ 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.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
@@ -19,9 +23,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 +54,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){
|
|
@@ -53,6 +68,10 @@ public class UserWithBeisenController {
|
|
|
httpRespMsg.setError("北森基础数据配置未完成,请联系服务商完成配置");
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+// if(companyId==5978){
|
|
|
+// beisenConfig.setAppKey("70FD83474FB946E5A6A122BB2989E8D9");
|
|
|
+// beisenConfig.setAppSecret("F494856D0BCC49D18C63429D4F2CB42EDE9480D5C075449E9C97E7AEA5C7D9E1");
|
|
|
+// }
|
|
|
List<UserWithBeisen> allBeisenList = userWithBeisenService.list(new LambdaQueryWrapper<UserWithBeisen>().eq(UserWithBeisen::getCompanyId, companyId));
|
|
|
List<UserWithBeisen> userWithBeisenList=new ArrayList<>();
|
|
|
List<JSONArray> byTimeWindow = BeiSenUtils.getByTimeWindow("",startTime,stopTime,beisenConfig.getAppKey(),beisenConfig.getAppSecret());
|
|
@@ -67,11 +86,11 @@ public class UserWithBeisenController {
|
|
|
userWithBeisen.setMobilePhone(employeeInfo.getString("mobilePhone"));
|
|
|
userWithBeisen.setName(employeeInfo.getString("name"));
|
|
|
userWithBeisen.setUserId(employeeInfo.getString("userID"));
|
|
|
- Optional<UserWithBeisen> first = allBeisenList.stream().filter(a -> a.getUserId().equals(employeeInfo.getString("userID"))).findFirst();
|
|
|
+ Optional<UserWithBeisen> first = allBeisenList.stream().filter(a ->a.getJobNumber()!=null&& a.getJobNumber().equals(recordInfo.getString("jobNumber"))).findFirst();
|
|
|
if(first.isPresent()){
|
|
|
userWithBeisen.setId(first.get().getId());
|
|
|
}
|
|
|
- boolean anyMatch = userWithBeisenList.stream().anyMatch(u -> u.getUserId().equals(userWithBeisen.getUserId()));
|
|
|
+ boolean anyMatch = userWithBeisenList.stream().anyMatch(u ->u.getJobNumber()!=null&&u.getJobNumber().equals(userWithBeisen.getJobNumber()));
|
|
|
if(anyMatch){
|
|
|
continue;
|
|
|
}
|
|
@@ -98,7 +117,7 @@ public class UserWithBeisenController {
|
|
|
}
|
|
|
List<UserWithBeisen> allBeisenList = userWithBeisenService.list(new LambdaQueryWrapper<UserWithBeisen>().eq(UserWithBeisen::getCompanyId, companyId));
|
|
|
List<UserWithBeisen> userWithBeisenList=new ArrayList<>();
|
|
|
- JSONArray swipingCards = BeiSenUtils.getSwipingCards(createDate,beisenConfig.getAppKey(),beisenConfig.getAppSecret());
|
|
|
+ JSONArray swipingCards = BeiSenUtils.getSwipingCards(createDate,beisenConfig.getAppKey(),beisenConfig.getAppSecret(),1,300);
|
|
|
httpRespMsg.setData(swipingCards);
|
|
|
return httpRespMsg;
|
|
|
}
|
|
@@ -106,12 +125,114 @@ public class UserWithBeisenController {
|
|
|
@RequestMapping("/getSwipingCardsTest")
|
|
|
public HttpRespMsg getSwipingCardsTest(String createDate){
|
|
|
HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
- JSONArray swipingCards = BeiSenUtils.getSwipingCards(createDate,"70FD83474FB946E5A6A122BB2989E8D9","F494856D0BCC49D18C63429D4F2CB42EDE9480D5C075449E9C97E7AEA5C7D9E1");
|
|
|
+ JSONArray swipingCards = BeiSenUtils.getSwipingCards(createDate,"97BF1F7DF8314F268D91E09C12772CAD","D52BE666683C408087063B422275C289DE09488E28D64B7FB4E5190C43F8AA66",1,300);
|
|
|
System.out.println("获取到的打卡数据====>"+swipingCards.toJSONString());
|
|
|
httpRespMsg.setData(swipingCards);
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping("/getOverTimeListTest")
|
|
|
+ public HttpRespMsg getOverTimeListTest(String createDate){
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
+ JSONArray swipingCards = BeiSenUtils.getOverTimeList(createDate,"97BF1F7DF8314F268D91E09C12772CAD","D52BE666683C408087063B422275C289DE09488E28D64B7FB4E5190C43F8AA66",1,100);
|
|
|
+ System.out.println("获取到的加班那数据====>"+swipingCards.toJSONString());
|
|
|
+ httpRespMsg.setData(swipingCards);
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/getAttendanceStatisticsTest")
|
|
|
+ public HttpRespMsg getAttendanceStatisticsTest(String startDate,String endDate){
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
+ JSONArray swipingCards = BeiSenUtils.getAttendanceStatistics(startDate,endDate,"97BF1F7DF8314F268D91E09C12772CAD","D52BE666683C408087063B422275C289DE09488E28D64B7FB4E5190C43F8AA66",1,100);
|
|
|
+ System.out.println("获取到的考勤数据====>"+swipingCards.toJSONString());
|
|
|
+ httpRespMsg.setData(swipingCards);
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/syncAttendanceFromBeisen")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpRespMsg syncAttendanceFromBeisen(String startDate,String endDate){
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ DateTimeFormatter df1=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ DateTimeFormatter df2=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));
|
|
|
+ List<UserWithBeisen> userWithBeisenList = userWithBeisenService.list(new LambdaQueryWrapper<UserWithBeisen>().eq(UserWithBeisen::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, 100);
|
|
|
+ //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, 100);
|
|
|
+ allOverTimeList.addAll(overTimeList);
|
|
|
+ }
|
|
|
+ for (LocalDate localDate : workDaysListInRange) {
|
|
|
+ Stream<JSONObject> swipingCardsStream = attendanceStatistics.stream().map(item -> (JSONObject) item);
|
|
|
+ //todo: 获取当天的考勤数据
|
|
|
+ List<JSONObject> swipingCardDateList = swipingCardsStream.filter(i -> LocalDateTime.parse(i.getString("SwipingCardDate"),df1).toLocalDate().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);
|
|
|
+ Stream<JSONObject> timeStream1 = times.stream().map(time -> (JSONObject) time);
|
|
|
+ //获取最早上班打卡时间
|
|
|
+ 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;
|
|
|
+ Stream<JSONObject> overTimeStream = allOverTimeList.stream().map(elment -> (JSONObject) elment);
|
|
|
+ Optional<UserWithBeisen> beisen = userWithBeisenList.stream().filter(u -> u.getJobNumber() != null && u.getJobNumber().equals(first.get().getJobNumber())).findFirst();
|
|
|
+ List<JSONObject> overTimeList = overTimeStream.filter(a -> a.getString("StaffId").equals(beisen.get().getUserId())
|
|
|
+ && a.getIntValue("ApproveStatus") == 2).collect(Collectors.toList());
|
|
|
+ if(overTimeList.size()>0){
|
|
|
+ double actualOverTimeDuration = overTimeList.stream().mapToDouble(i -> i.getDouble("ActualOverTimeDuration")).sum();
|
|
|
+ if(workDay){
|
|
|
+ workTime= workTime+actualOverTimeDuration;
|
|
|
+ }else {
|
|
|
+ workTime= actualOverTimeDuration;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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.setUserId(first.get().getId());
|
|
|
+ userFvTime.setCompanyId(companyId);
|
|
|
+ userFvTime.setWorkHours(workTime.floatValue());
|
|
|
+ UserFvTime one = userFvTimeService.getOne(new LambdaQueryWrapper<UserFvTime>().eq(UserFvTime::getCompanyId, companyId).eq(UserFvTime::getUserId, first.get().getId()).eq(UserFvTime::getWorkDate, localDate));
|
|
|
+ if(one!=null){
|
|
|
+ userFvTime.setId(one.getId());
|
|
|
+ }
|
|
|
+ userFvTimeList.add(userFvTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(userFvTimeList.size()>0){
|
|
|
+ if(!userFvTimeService.saveOrUpdateBatch(userFvTimeList)){
|
|
|
+ msg.setError("同步验证失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|