|
@@ -17,6 +17,7 @@ import org.json.HTTP;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.core.io.FileSystemResource;
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
|
+import org.springframework.format.annotation.DateTimeFormat;
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -590,7 +591,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
int toIndex = (i + 1) * batchSize;
|
|
int toIndex = (i + 1) * batchSize;
|
|
if (toIndex > totalLength) toIndex = totalLength;
|
|
if (toIndex > totalLength) toIndex = totalLength;
|
|
Object[] objects = corpwxUserIds.subList(fromIndex, toIndex).toArray(new String[0]);
|
|
Object[] objects = corpwxUserIds.subList(fromIndex, toIndex).toArray(new String[0]);
|
|
- reqPunchRecord(corpInfo, startTime, endTime, objects, showLog,userId,date);
|
|
|
|
|
|
+ reqPunchRecord(corpInfo, startTime, endTime, objects, showLog,date);
|
|
}
|
|
}
|
|
} catch (Exception exception) {
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
exception.printStackTrace();
|
|
@@ -728,6 +729,64 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg fixPunchRecord(Integer companyId, LocalDateTime startDateTime, LocalDateTime endDateTime, boolean showLog) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ WxCorpInfo corpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
|
+ if (corpInfo == null) {
|
|
|
|
+ //msg.setError("该企业未对接企业微信");
|
|
|
|
+ msg.setError(MessageUtils.message("wx.dockError"));
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ String url = null;
|
|
|
|
+ try {
|
|
|
|
+ LocalDate date=startDateTime.toLocalDate();
|
|
|
|
+ //获取企业下的活跃员工
|
|
|
|
+ List<User> users = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId).isNotNull("corpwx_userid").eq("is_active", 1));
|
|
|
|
+ List<UserCorpwxTime> corpwxTimes = userCorpwxTimeMapper.selectList(new QueryWrapper<UserCorpwxTime>().eq("company_id", companyId).between("create_date", startDateTime.toLocalDate(), endDateTime.toLocalDate()));
|
|
|
|
+ LocalDate endLocalDate = endDateTime.toLocalDate();
|
|
|
|
+ int i=0;
|
|
|
|
+ DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+ while (true) {
|
|
|
|
+ LocalDate day = date.plusDays(i);
|
|
|
|
+ if (WorkDayCalculateUtils.isWorkDay(day)) {
|
|
|
|
+ System.out.println("============="+dateTimeFormat.format(day)+"==============");
|
|
|
|
+ List<String> missRecordUserCorpIds = new ArrayList<>();
|
|
|
|
+ List<User> filterusers = new ArrayList<>();
|
|
|
|
+ for (User u : users) {
|
|
|
|
+ //找到有效的打卡记录
|
|
|
|
+ boolean find = corpwxTimes.stream().anyMatch(corp->corp.getCorpwxUserid().equals(u.getCorpwxUserid()) && corp.getCreateDate().isEqual(day)
|
|
|
|
+ && (corp.getWorkHours() > 0 || corp.getCardTime() >= 1.0 || corp.getAskLeaveTime() > 0 || corp.getOutdoorTime() > 0));
|
|
|
|
+ if (!find) {
|
|
|
|
+ missRecordUserCorpIds.add(u.getCorpwxUserid());
|
|
|
|
+ filterusers.add(u);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (missRecordUserCorpIds.size() > 0) {
|
|
|
|
+ LocalDateTime sDate = day.atStartOfDay();
|
|
|
|
+// sDate = sDate.withHour(0).withMinute(0).withSecond(0).withNano(0);
|
|
|
|
+ long startTime = sDate.toEpochSecond(ZoneOffset.of("+8"));
|
|
|
|
+
|
|
|
|
+ LocalDateTime eDate = day.atTime(23, 59,0,0);
|
|
|
|
+ long endTime = eDate.toEpochSecond(ZoneOffset.of("+8"));
|
|
|
|
+ System.out.println("获取用户:"+filterusers.stream().map(User::getName).collect(Collectors.joining(",")));
|
|
|
|
+ Object[] objects = missRecordUserCorpIds.toArray(new String[0]);
|
|
|
|
+ reqPunchRecord(corpInfo, startTime, endTime, objects, showLog,day);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (day.isEqual(endLocalDate)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception exception) {
|
|
|
|
+ exception.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public synchronized User generateUserInfo(Integer companyId, String corpwxOpenId) {
|
|
public synchronized User generateUserInfo(Integer companyId, String corpwxOpenId) {
|
|
User find = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", corpwxOpenId));
|
|
User find = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", corpwxOpenId));
|
|
@@ -773,7 +832,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void reqPunchRecord(WxCorpInfo corpInfo, long startTime, long endTime, Object[] objects, boolean showLog,String userId,LocalDate date)throws Exception {
|
|
|
|
|
|
+ public void reqPunchRecord(WxCorpInfo corpInfo, long startTime, long endTime, Object[] objects, boolean showLog,LocalDate date)throws Exception {
|
|
DateTimeFormatter mdFormat = DateTimeFormatter.ofPattern("yyyy/M/d");
|
|
DateTimeFormatter mdFormat = DateTimeFormatter.ofPattern("yyyy/M/d");
|
|
LocalDateTime needDataTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
|
|
LocalDateTime needDataTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
|
|
long dataTime = needDataTime.toEpochSecond(ZoneOffset.of("+8"));
|
|
long dataTime = needDataTime.toEpochSecond(ZoneOffset.of("+8"));
|
|
@@ -848,13 +907,15 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
userCorpwxTime.setStartTime(LocalTime.parse(minTime,df).plusHours(8).format(df));
|
|
userCorpwxTime.setStartTime(LocalTime.parse(minTime,df).plusHours(8).format(df));
|
|
userCorpwxTime.setEndTime(LocalTime.parse(maxTime,df).plusHours(8).format(df));
|
|
userCorpwxTime.setEndTime(LocalTime.parse(maxTime,df).plusHours(8).format(df));
|
|
userCorpwxTime.setWxCorpid(corpInfo.getCorpid());
|
|
userCorpwxTime.setWxCorpid(corpInfo.getCorpid());
|
|
- if(userId!=null){
|
|
|
|
- userCorpwxTime.setCreateDate(date);
|
|
|
|
- userCorpwxTime.setWeekDay(date.getDayOfWeek().getValue());
|
|
|
|
- }else {
|
|
|
|
- userCorpwxTime.setCreateDate(LocalDate.now());
|
|
|
|
- userCorpwxTime.setWeekDay(LocalDate.now().getDayOfWeek().getValue());
|
|
|
|
- }
|
|
|
|
|
|
+// if(userId!=null){
|
|
|
|
+// userCorpwxTime.setCreateDate(date);
|
|
|
|
+// userCorpwxTime.setWeekDay(date.getDayOfWeek().getValue());
|
|
|
|
+// }else {
|
|
|
|
+// userCorpwxTime.setCreateDate(LocalDate.now());
|
|
|
|
+// userCorpwxTime.setWeekDay(LocalDate.now().getDayOfWeek().getValue());
|
|
|
|
+// }
|
|
|
|
+ userCorpwxTime.setCreateDate(date);
|
|
|
|
+ userCorpwxTime.setWeekDay(date.getDayOfWeek().getValue());
|
|
userCorpwxTime.setWeekDayTxt(DateTimeUtil.getWeekDayTxt(userCorpwxTime.getWeekDay()));
|
|
userCorpwxTime.setWeekDayTxt(DateTimeUtil.getWeekDayTxt(userCorpwxTime.getWeekDay()));
|
|
BigDecimal bigDecimal=new BigDecimal(Duration.between(LocalTime.parse(minTime,df).plusHours(8),LocalTime.parse(maxTime,df).plusHours(8)).toMinutes());
|
|
BigDecimal bigDecimal=new BigDecimal(Duration.between(LocalTime.parse(minTime,df).plusHours(8),LocalTime.parse(maxTime,df).plusHours(8)).toMinutes());
|
|
bigDecimal=bigDecimal.divide(BigDecimal.valueOf(60),0,BigDecimal.ROUND_HALF_UP).subtract(new BigDecimal(restTime));
|
|
bigDecimal=bigDecimal.divide(BigDecimal.valueOf(60),0,BigDecimal.ROUND_HALF_UP).subtract(new BigDecimal(restTime));
|
|
@@ -864,14 +925,15 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
}
|
|
}
|
|
userCorpwxTime.setWorkHours(time);
|
|
userCorpwxTime.setWorkHours(time);
|
|
System.out.println(userCorpwxTime);
|
|
System.out.println(userCorpwxTime);
|
|
- UserCorpwxTime item;
|
|
|
|
- if(userId!=null){
|
|
|
|
- item= userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", (String) objects[i])
|
|
|
|
- .eq("create_date", date));
|
|
|
|
- }else {
|
|
|
|
- item= userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", (String) objects[i])
|
|
|
|
- .eq("create_date", LocalDate.now()));
|
|
|
|
- }
|
|
|
|
|
|
+ UserCorpwxTime item = userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", (String) objects[i])
|
|
|
|
+ .eq("create_date", date));
|
|
|
|
+// if(userId!=null){
|
|
|
|
+// item= userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", (String) objects[i])
|
|
|
|
+// .eq("create_date", date));
|
|
|
|
+// }else {
|
|
|
|
+// item= userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", (String) objects[i])
|
|
|
|
+// .eq("create_date", LocalDate.now()));
|
|
|
|
+// }
|
|
if (item != null) {
|
|
if (item != null) {
|
|
userCorpwxTime.setId(item.getId());
|
|
userCorpwxTime.setId(item.getId());
|
|
//已存在记录,进行更新
|
|
//已存在记录,进行更新
|
|
@@ -1397,16 +1459,18 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
|
|
|
UserCorpwxTime item = userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", curUserid)
|
|
UserCorpwxTime item = userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", curUserid)
|
|
.eq("create_date", localDate));
|
|
.eq("create_date", localDate));
|
|
|
|
+ //有工作时长或者打卡时长或者请假时长,外出时长,都算有效时间
|
|
|
|
+ boolean hasTimeRecord = ct.getWorkHours() > 0 || ct.getCardTime() >= 1.0 || ct.getAskLeaveTime() > 0 || ct.getOutdoorTime() > 0;
|
|
if (item != null) {
|
|
if (item != null) {
|
|
ct.setId(item.getId());
|
|
ct.setId(item.getId());
|
|
- //已存在记录,但是如果老记录有工作时长,新记录无工作时长,也没有请假外出和打卡时长,说明新的记录是没有取到考勤的。 老记录是通过当天打卡数据获取到的,包含外出的时间
|
|
|
|
- if (item.getWorkHours() > 0 && ct.getWorkHours() == 0 && ct.getCardTime() >= 1.0 && ct.getAskLeaveTime() == 0 && ct.getOutdoorTime() == 0) {
|
|
|
|
- //不处理
|
|
|
|
- } else {
|
|
|
|
|
|
+ //之前有的时长不合法,或者新的有打卡时长
|
|
|
|
+ if (item.getWorkHours() <= 0 || hasTimeRecord) {
|
|
userCorpwxTimeMapper.updateById(ct);
|
|
userCorpwxTimeMapper.updateById(ct);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- userCorpwxTimeMapper.insert(ct);
|
|
|
|
|
|
+ if (hasTimeRecord) {
|
|
|
|
+ userCorpwxTimeMapper.insert(ct);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|