|
@@ -1,6 +1,8 @@
|
|
|
package com.usoftchina.uas.office.qywx.task;
|
|
|
|
|
|
import com.usoftchina.qywx.sdk.OaSdk;
|
|
|
+import com.usoftchina.qywx.sdk.dto.GetCheckinByDevDataReq;
|
|
|
+import com.usoftchina.qywx.sdk.dto.GetCheckinByDevDataResp;
|
|
|
import com.usoftchina.qywx.sdk.dto.GetCheckinDataReq;
|
|
|
import com.usoftchina.qywx.sdk.dto.GetCheckinDataResp;
|
|
|
import com.usoftchina.uas.office.entity.DataCenter;
|
|
@@ -10,6 +12,7 @@ import com.usoftchina.uas.office.qywx.entity.Employee;
|
|
|
import com.usoftchina.uas.office.qywx.entity.OutSign;
|
|
|
import com.usoftchina.uas.office.qywx.manage.service.QywxSettingService;
|
|
|
import com.usoftchina.uas.office.qywx.service.UasCardLogService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasConfigsService;
|
|
|
import com.usoftchina.uas.office.qywx.service.UasEmployeeService;
|
|
|
import com.usoftchina.uas.office.qywx.service.UasOutSignService;
|
|
|
import org.slf4j.Logger;
|
|
@@ -20,11 +23,15 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -49,6 +56,8 @@ public class QywxCheckinTask {
|
|
|
|
|
|
@Autowired
|
|
|
private UasOutSignService outSignService;
|
|
|
+ @Autowired
|
|
|
+ private UasConfigsService uasConfigsService;
|
|
|
|
|
|
/**
|
|
|
* 每次最多条数据
|
|
@@ -77,23 +86,51 @@ public class QywxCheckinTask {
|
|
|
Long lastTime = settingService.getCheckinTime();
|
|
|
if (lastTime == null) {
|
|
|
lastTime = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
|
|
+ } else {
|
|
|
+ //@wuyx 默认记录上次对接打卡的最后一次时间,且时间跨度超过1个月的自动更新为当前时间
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.add(Calendar.MONTH, -1);
|
|
|
+ long oneMonthAgo = cal.getTimeInMillis();
|
|
|
+ if (lastTime < oneMonthAgo) {
|
|
|
+ lastTime = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
|
|
+ }
|
|
|
}
|
|
|
+ logger.debug("get checkin lastTime {}", lastTime);
|
|
|
+// lastTime = 1725120000000L;
|
|
|
Date now = new Date();
|
|
|
//@update 反馈:2021040337 每次往上+1秒 偶尔会导致系统漏获取一条数据
|
|
|
- long unixStartTime = lastTime / 1000 ;
|
|
|
+ long unixStartTime = lastTime / 1000;
|
|
|
long unixEndTime = now.getTime() / 1000;
|
|
|
- logger.debug("get checkin unixStartTime {} enable", lastTime);
|
|
|
+ logger.debug("get checkin unixStartTime {} unixEndTime {} enable", unixStartTime,unixEndTime);
|
|
|
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ AtomicReference<Long> endTime = new AtomicReference<>(lastTime / 1000);
|
|
|
Stream.iterate(0, n -> n + 1)
|
|
|
.limit((int) Math.ceil((double) employees.size() / maxSeed)).forEach(page -> {
|
|
|
- GetCheckinDataReq req = new GetCheckinDataReq(GetCheckinDataReq.CheckinType.ALL,
|
|
|
- unixStartTime, unixEndTime,
|
|
|
- employees.stream().skip(page * maxSeed).limit(maxSeed).map(Employee::getEm_qywx).collect(Collectors.toList()));
|
|
|
- logger.debug("get checkin employeeCount {} ",employees.stream().skip(page * maxSeed).limit(maxSeed).map(Employee::getEm_qywx).count() );
|
|
|
- List<GetCheckinDataResp.CheckinData> dataList = oaSdk.getCheckinData(req);
|
|
|
- logger.debug("get checkin dataSize {} ", dataList.size());
|
|
|
- saveCheckinData(employeeMap, dataList);
|
|
|
+ List<String> userList = employees.stream().skip(page * maxSeed).limit(maxSeed).map(Employee::getEm_qywx).collect(Collectors.toList());
|
|
|
+ logger.debug("get checkin employeeCount {} ", userList.size());
|
|
|
+ String configData = uasConfigsService.getDBSetting("CardLog","getCheckinDataType");
|
|
|
+ //联戎: 根据企业微信打卡方式获取打卡记录 0 仅企业微信打卡 1: 仅设备对接打卡 2:企业微信打卡和设备打卡
|
|
|
+ if(configData == null || !"1".equals(configData)){
|
|
|
+ //企业微信打卡记录
|
|
|
+ GetCheckinDataReq req = new GetCheckinDataReq(GetCheckinDataReq.CheckinType.ALL,
|
|
|
+ unixStartTime, unixEndTime,userList
|
|
|
+ );
|
|
|
+ List<GetCheckinDataResp.CheckinData> dataList = oaSdk.getCheckinData(req);
|
|
|
+ logger.debug("get checkin dataSize {} ", dataList.size());
|
|
|
+ endTime.set(saveCheckinData(endTime.get(), employeeMap, dataList));
|
|
|
+ logger.debug("get checkin setCheckinTime-1 {} ", format.format(new Date((endTime.get() * 1000))));
|
|
|
+ }
|
|
|
+ //设备对接 联戎
|
|
|
+ if(configData!=null&&!"0".equals(configData)){
|
|
|
+ GetCheckinByDevDataReq reqByDev = new GetCheckinByDevDataReq(GetCheckinByDevDataReq.CheckinType.BYUPLOAD,
|
|
|
+ unixStartTime, unixEndTime,userList);
|
|
|
+ List<GetCheckinByDevDataResp.CheckinData> dataListByDev = oaSdk.getCheckinDataByDev(reqByDev);
|
|
|
+ logger.debug("get checkin ByDev dataSize {} ", dataListByDev.size());
|
|
|
+ endTime.set(saveCheckinByDevData(endTime.get(), employeeMap, dataListByDev));
|
|
|
+ logger.debug("get checkin setCheckinTime-2 {} ", format.format(new Date((endTime.get() * 1000))));
|
|
|
+ }
|
|
|
});
|
|
|
- settingService.setCheckinTime(now);
|
|
|
+ settingService.setCheckinTime(new Date((endTime.get() * 1000)));
|
|
|
}
|
|
|
} finally {
|
|
|
DataSourceHolder.clear();
|
|
@@ -102,21 +139,39 @@ public class QywxCheckinTask {
|
|
|
logger.debug("get checkin data === end ===");
|
|
|
}
|
|
|
|
|
|
- private void saveCheckinData(Map<String, Employee> employeeMap, List<GetCheckinDataResp.CheckinData> dataList) {
|
|
|
- dataList.forEach(data -> {
|
|
|
+ private Long saveCheckinData(Long endTime, Map<String, Employee> employeeMap, List<GetCheckinDataResp.CheckinData> dataList) {
|
|
|
+ for (GetCheckinDataResp.CheckinData data : dataList) {
|
|
|
if (!data.getException_type().equals("未打卡")) {
|
|
|
Employee employee = employeeMap.get(data.getUserid());
|
|
|
logger.debug("get checkin data, user {}, type {}", employee.getEm_name(), data.getCheckin_type());
|
|
|
- if ("外出打卡".equals(data.getCheckin_type())) {
|
|
|
+ if (endTime < data.getCheckin_time()) {
|
|
|
+ endTime = data.getCheckin_time();
|
|
|
+ }
|
|
|
+ if ("外出打卡".equals(data.getCheckin_type())) {
|
|
|
// 外勤签到 插入外勤打卡记录
|
|
|
outSignService.save(new OutSign(employee, data));
|
|
|
} else {
|
|
|
// 在企业微信设置了考勤打卡规则的,才同步到uas
|
|
|
if (!StringUtils.isEmpty(data.getGroupname())) {
|
|
|
- cardLogService.save(new CardLog(employee, data));
|
|
|
+ cardLogService.saveWhenNotExist(new CardLog(employee, data));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ return endTime;
|
|
|
+ }
|
|
|
+ private Long saveCheckinByDevData(Long endTime, Map<String, Employee> employeeMap, List<GetCheckinByDevDataResp.CheckinData> dataList) {
|
|
|
+ for (GetCheckinByDevDataResp.CheckinData data : dataList) {
|
|
|
+ Employee employee = employeeMap.get(data.getUserid());
|
|
|
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ logger.debug("get checkin ByDev data, user {}, type {}, checkinTime {}", employee.getEm_name(), data.getDevice_name()
|
|
|
+ , format.format(new Date((data.getCheckin_time() * 1000))));
|
|
|
+ cardLogService.saveWhenNotExist(new CardLog(employee, data));
|
|
|
+ if (endTime < data.getCheckin_time()) {
|
|
|
+ endTime = data.getCheckin_time();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return endTime;
|
|
|
}
|
|
|
}
|