|
@@ -15,6 +15,7 @@ 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;
|
|
|
|
|
@@ -67,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());
|
|
@@ -81,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;
|
|
|
}
|
|
@@ -120,7 +125,7 @@ public class UserWithBeisenController {
|
|
|
@RequestMapping("/getSwipingCardsTest")
|
|
|
public HttpRespMsg getSwipingCardsTest(String createDate){
|
|
|
HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- JSONArray swipingCards = BeiSenUtils.getSwipingCards(createDate,"70FD83474FB946E5A6A122BB2989E8D9","F494856D0BCC49D18C63429D4F2CB42EDE9480D5C075449E9C97E7AEA5C7D9E1",1,300);
|
|
|
+ JSONArray swipingCards = BeiSenUtils.getSwipingCards(createDate,"97BF1F7DF8314F268D91E09C12772CAD","D52BE666683C408087063B422275C289DE09488E28D64B7FB4E5190C43F8AA66",1,300);
|
|
|
System.out.println("获取到的打卡数据====>"+swipingCards.toJSONString());
|
|
|
httpRespMsg.setData(swipingCards);
|
|
|
return httpRespMsg;
|
|
@@ -129,7 +134,7 @@ public class UserWithBeisenController {
|
|
|
@RequestMapping("/getOverTimeListTest")
|
|
|
public HttpRespMsg getOverTimeListTest(String createDate){
|
|
|
HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- JSONArray swipingCards = BeiSenUtils.getOverTimeList(createDate,"70FD83474FB946E5A6A122BB2989E8D9","F494856D0BCC49D18C63429D4F2CB42EDE9480D5C075449E9C97E7AEA5C7D9E1",1,300);
|
|
|
+ JSONArray swipingCards = BeiSenUtils.getOverTimeList(createDate,"97BF1F7DF8314F268D91E09C12772CAD","D52BE666683C408087063B422275C289DE09488E28D64B7FB4E5190C43F8AA66",1,100);
|
|
|
System.out.println("获取到的加班那数据====>"+swipingCards.toJSONString());
|
|
|
httpRespMsg.setData(swipingCards);
|
|
|
return httpRespMsg;
|
|
@@ -138,40 +143,43 @@ public class UserWithBeisenController {
|
|
|
@RequestMapping("/getAttendanceStatisticsTest")
|
|
|
public HttpRespMsg getAttendanceStatisticsTest(String startDate,String endDate){
|
|
|
HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- JSONArray swipingCards = BeiSenUtils.getAttendanceStatistics(startDate,endDate,"70FD83474FB946E5A6A122BB2989E8D9","F494856D0BCC49D18C63429D4F2CB42EDE9480D5C075449E9C97E7AEA5C7D9E1",1,300);
|
|
|
+ JSONArray swipingCards = BeiSenUtils.getAttendanceStatistics(startDate,endDate,"97BF1F7DF8314F268D91E09C12772CAD","D52BE666683C408087063B422275C289DE09488E28D64B7FB4E5190C43F8AA66",1,100);
|
|
|
System.out.println("获取到的考勤数据====>"+swipingCards.toJSONString());
|
|
|
httpRespMsg.setData(swipingCards);
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
|
|
|
- @RequestMapping("syncAttendanceFromBeisen")
|
|
|
+ @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("HH:mm");
|
|
|
+ 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, 300);
|
|
|
+ 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, 300);
|
|
|
+ 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 -> LocalDate.parse(i.getString("SwipingCardDate")).equals(localDate)).collect(Collectors.toList());
|
|
|
+ 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");
|
|
@@ -179,50 +187,50 @@ public class UserWithBeisenController {
|
|
|
//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 -> LocalTime.parse(i.getString("ActualTime"))).collect(Collectors.toList());
|
|
|
+ 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 = timeStream.filter(t -> t.getIntValue("Type") == 9).map(i -> LocalTime.parse(i.getString("ActualTime"))).collect(Collectors.toList());
|
|
|
+ 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);
|
|
|
- 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 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(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);
|
|
|
}
|
|
|
+ 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;
|
|
|
}
|
|
|
|