Commit 67bf33ea by 张富康

fix(attendance): 优化考勤数据处理及打卡位置获取

- 注释Dubbo配置中无效的URL调用,保留相关版本和超时配置
- 将多线程处理开关默认设为关闭,避免并发风险
- 添加详细日志,记录员工考勤数据及策略执行过程,方便排查
- 修正策略二判断打卡时间范围参数,保证考勤时间检验准确
- 同步企微打卡数据时启用多线程,提高数据处理效率
- 当打卡位置详情存在时,调用百度地图API获取精确经纬度坐标
- 新增LocationResponse辅助类解析百度地图返回的地理位置信息
- 优化考勤数据经纬度字段赋值逻辑,增强异常处理和日志记录
- 更新测试坐标用于验证距离计算功能
1 parent 95d419b6
......@@ -87,7 +87,7 @@ public class AttendanceDataCleansingService {
// 失败记录最大容量(防止内存溢出)
Integer MAX_FAILURE_RECORDS = OrePropertyConfigurer.getProperty("MAX_FAILURE_RECORDS", Integer.class, 1000);
// 是否开启多线程处理(1-不使用,2-使用)
Integer USE_MULTITHREAD = OrePropertyConfigurer.getProperty("USE_MULTITHREAD", Integer.class, 2);
Integer USE_MULTITHREAD = OrePropertyConfigurer.getProperty("USE_MULTITHREAD", Integer.class, 1);
// 允许的最近商户距离(公里)
Double JUDGE_DISTANCE = OrePropertyConfigurer.getProperty("judgeDistance", Double.class, 0.1);
// 考勤打卡门店清单
......@@ -302,6 +302,11 @@ public class AttendanceDataCleansingService {
// 1. 遍历每个考勤记录
for (StaffQwClockClean clockInfo : staffQwClockCleans) {
log.info("处理员工 {} ({}) 考勤数据-打卡日期:{},\n上班打卡时间:{},下班打卡时间:{},\n上班打卡经纬度:{},{},下班打卡经纬度:{},{}",
employee.getStaffName(), employee.getStaffPhone(),
clockInfo.getClockInDate(),
clockInfo.getClockInTimeStart(), clockInfo.getClockOutTimeEnd(),
clockInfo.getClockInAddrLng(), clockInfo.getClockInAddrLat(), clockInfo.getClockOutAddrLng(), clockInfo.getClockOutAddrLat());
try {
// 2. 处理每条考勤记录
// 判断该打卡日期是否在离职直接之后,如果在离职日期之后则不计算
......@@ -378,16 +383,19 @@ public class AttendanceDataCleansingService {
if (ObjectUtil.isNotEmpty(clockInfo.getClockInTimeStart())
&& StrUtil.isNotBlank(clockInfo.getClockInAddrLng())
&& StrUtil.isNotBlank(clockInfo.getClockInAddrLat())) {
log.info("采用策略一");
return new ClockInStrategyOne();
}
// 2. 下班打卡时间不为空 下班打卡经纬度不为空 - 策略二
if (ObjectUtil.isNotEmpty(clockInfo.getClockOutTimeEnd())
&& StrUtil.isNotBlank(clockInfo.getClockOutAddrLng())
&& StrUtil.isNotBlank(clockInfo.getClockOutAddrLat())) {
log.info("采用策略二");
return new ClockInStrategyTwo();
}
// 4. 没有经纬度,使用默认策略
log.info("采用默认策略");
return new DefaultClockInStrategy();
}
......@@ -751,11 +759,14 @@ public class AttendanceDataCleansingService {
public ClockInResult process(StaffQwClockClean clockInfo, DateTime lastMonthYMD, StaffBeisenBaseInfo employee) {
// 1. 获取最近的商户
MerchantAttendanceList merchant = findNearestMerchant(clockInfo.getClockInAddrLng(), clockInfo.getClockInAddrLat());
if (ObjectUtil.isEmpty(merchant)) {
// 如果没有找到最近的商户,使用默认策略
log.info("策略一-没有找到最近的商户,使用默认策略");
return new DefaultClockInStrategy().process(clockInfo, lastMonthYMD, employee);
}
log.info("已找到最近的商户: {}-{},上下班打卡时间:{}-{},经纬度:{},{}", merchant.getId(), merchant.getMerchantName(),
clockInfo.getClockInTimeStart(), clockInfo.getClockOutTimeEnd(),
merchant.getAddressLng(), merchant.getAddressLat());
// 2. 处理打卡时间
return processWithMerchant(clockInfo, merchant, employee);
......@@ -764,6 +775,8 @@ public class AttendanceDataCleansingService {
private ClockInResult processWithMerchant(StaffQwClockClean clockInfo, MerchantAttendanceList merchant, StaffBeisenBaseInfo employee) {
log.info("策略一:处理打卡时间:{}-{},经纬度:{},{}", clockInfo.getClockInTimeStart(), clockInfo.getClockOutTimeEnd(),
merchant.getAddressLng(), merchant.getAddressLat());
String clockInDate = clockInfo.getClockInDate();
String officialDate = employee.getOfficialDate();
// yyyy-MM-dd 比较clockInDate officialDate 日期大小 该打卡日期是否转正后
......@@ -895,6 +908,7 @@ public class AttendanceDataCleansingService {
if (ObjectUtil.isEmpty(merchant)) {
// 如果没有找到最近的商户,使用默认策略
log.info("策略二-没有找到最近的商户,使用默认策略");
return new DefaultClockInStrategy().process(clockInfo, lastMonthYMD, employee);
}
......@@ -903,6 +917,7 @@ public class AttendanceDataCleansingService {
}
private ClockInResult processWithTwo(StaffQwClockClean clockInfo, MerchantAttendanceList merchant, StaffBeisenBaseInfo employee) {
log.info("采用策略二: clockInfo:{}", clockInfo);
String clockInDate = clockInfo.getClockInDate();
String officialDate = employee.getOfficialDate();
BigDecimal totalWorkHours = BigDecimal.ZERO;
......@@ -1037,7 +1052,7 @@ public class AttendanceDataCleansingService {
if (ObjectUtil.isNotEmpty(clockInfo.getClockOutTimeEnd())) {
// 使用默认考勤时间
JudgeResult timeRangeResult = TimeRangeChecker.getReasonForNotInRange(
clockInfo.getClockInTimeStart(), DEFAULT_CLOCK_OUT_TIME, LATEST_CLOCK_OUT_TIME, 1);
clockInfo.getClockOutTimeEnd(), DEFAULT_CLOCK_OUT_TIME, LATEST_CLOCK_OUT_TIME, 1);
if (timeRangeResult.getInRangeType() == 1) {
// 在打卡时间范围内
normalClockCount++;
......
......@@ -6,6 +6,7 @@ import cn.com.glsx.dj.staff.mapper.perfSalary.StaffQwClockInInfoMapper;
import cn.com.glsx.dj.staff.model.perfSalary.StaffQwClockClean;
import cn.com.glsx.dj.staff.model.perfSalary.StaffQwClockInInfo;
import cn.com.glsx.dj.staff.util.HttpUtil;
import cn.com.glsx.dj.staff.util.LocationResponse;
import cn.com.glsx.scrm.wechat.dto.workwechat.checkin.request.GetWorkWechatUserCheckInDataRequestDTO;
import cn.com.glsx.scrm.wechat.dto.workwechat.checkin.response.WorkWechatUserCheckInDataResponseDTO;
import cn.hutool.core.collection.CollUtil;
......@@ -14,6 +15,7 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
......@@ -38,6 +40,10 @@ public class ClockInCompleteAnalysisStaffService {
@Resource
private StaffQwClockCleanMapper staffQwClockCleanMapper;
// 测试 pbKP9T69inAX0GVwS9uar2l1Yz6OLyyg
// 线上 j140gfsl1LTZeUYH8hEUrfXVqOUcRH1C
String baiduAk = OrePropertyConfigurer.getProperty("baidu.ak", String.class, "j140gfsl1LTZeUYH8hEUrfXVqOUcRH1C");
public void syncQwClockInDetailData(String clockInDateStr) {
Integer merchantId = OrePropertyConfigurer.getProperty("syncQwClockInData.build.merchantId", Integer.class, 44202977);
// 查询企微打卡表指定日期所有人员
......@@ -80,7 +86,7 @@ public class ClockInCompleteAnalysisStaffService {
int batchCount = (int) Math.ceil((double) totalUserCount / 100);
log.info("开始同步企微打卡数据:总用户数={},分{}个批次处理", totalUserCount, batchCount);
for (List<String> userIdList : partition(new ArrayList<>(userIdSet), 100)) {
handlerData(userIdList, requestDTO, userIdStaffPhoneMap);
taskExecutor.execute(() -> handlerData(userIdList, requestDTO, userIdStaffPhoneMap));
}
}
......@@ -153,11 +159,21 @@ public class ClockInCompleteAnalysisStaffService {
.min(Comparator.comparingLong(CheckInRecordDTO::getCheckinTime));
// 如果当前记录中没有打卡照片或者打卡状态为0,且找到了上班打卡记录 保存经纬度信息
if (checkIn.isPresent()) {
Integer lng = checkIn.get().getLng();
Integer lat = checkIn.get().getLat();
record.setClockInAddrLng(ObjectUtil.isEmpty(lng) ? null : ((double) lng / 1000000) + "");
record.setClockInAddrLat(ObjectUtil.isEmpty(lat) ? null : ((double) lat / 1000000) + "");
record.setClockInAddrInfo(checkIn.get().getLocationDetail());
String locationDetail = checkIn.get().getLocationDetail();
if (StrUtil.isNotBlank(locationDetail)) {
String url = "https://api.map.baidu.com/geocoding/v3/?address=" + locationDetail + "&output=json&ak=" + baiduAk + "&ret_coordtype=gcj02ll";
String s = cn.hutool.http.HttpUtil.get(url);
LocationResponse bean = JSONUtil.toBean(s, LocationResponse.class);
if (ObjectUtil.equals(bean.getStatus(), 0)) {
String lng = bean.getResult().getLocation().getLng();
String lat = bean.getResult().getLocation().getLat();
record.setClockInAddrLng(StrUtil.isBlank(lng) ? null : lng);
record.setClockInAddrLat(StrUtil.isBlank(lat) ? null : lat);
} else {
log.error("百度地图接口异常:{}", s);
}
}
record.setClockInAddrInfo(locationDetail);
record.setClockInTimeStart(DateUtil.date(checkIn.get().getCheckinTime() * 1000));
}
// 查找下班打卡记录(最晚的一次,且有照片媒体文件)
......@@ -169,10 +185,20 @@ public class ClockInCompleteAnalysisStaffService {
.max(Comparator.comparingLong(CheckInRecordDTO::getCheckinTime));
// 如果当前记录中没有下班打卡照片,且找到了下班打卡记录 保存经纬度信息
if (checkOut.isPresent()) {
Integer lng = checkOut.get().getLng();
Integer lat = checkOut.get().getLat();
record.setClockOutAddrLng(ObjectUtil.isEmpty(lng) ? null : ((double) lng / 1000000) + "");
record.setClockOutAddrLat(ObjectUtil.isEmpty(lat) ? null : ((double) lat / 1000000) + "");
String locationDetail = checkOut.get().getLocationDetail();
if (StrUtil.isNotBlank(locationDetail)) {
String url = "https://api.map.baidu.com/geocoding/v3/?address=" + locationDetail + "&output=json&ak=" + baiduAk + "&ret_coordtype=gcj02ll";
String s = cn.hutool.http.HttpUtil.get(url);
LocationResponse bean = JSONUtil.toBean(s, LocationResponse.class);
if (ObjectUtil.equals(bean.getStatus(), 0)) {
String lng = bean.getResult().getLocation().getLng();
String lat = bean.getResult().getLocation().getLat();
record.setClockOutAddrLng(StrUtil.isBlank(lng) ? null : lng);
record.setClockOutAddrLat(StrUtil.isBlank(lat) ? null : lat);
} else {
log.error("百度地图接口异常:{}", s);
}
}
record.setClockOutAddrInfo(checkOut.get().getLocationDetail());
record.setClockOutTimeEnd(DateUtil.date(checkOut.get().getCheckinTime() * 1000));
}
......
......@@ -34,10 +34,15 @@ public class DistanceTest {
//(116.368904, 39.923423) (116.387271, 39.772501)
public static void main(String[] args) {
double lon1 = 116.368904;
double lat1 = 39.923423;
double lon2 = 116.387271;
double lat2 = 39.772501;
// double lon1 = 116.368904;
// double lat1 = 39.923423;
// double lon2 = 116.387271;
// double lat2 = 39.772501;
double lon1 = 108.2803613945588;
double lat1 = 22.77437977665505;
double lon2 = 108.2803613945588;
double lat2 = 22.77437977665505;
double dist = GetDistance(lat1, lon1, lat2, lon2);
System.out.println("输出结果:" + dist * 1000 + "m");
......
package cn.com.glsx.dj.staff.util;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class LocationResponse {
private int status;
private Result result;
@Data
@Builder
public static class Result {
private Location location;
private int precise;
private int confidence;
private int comprehension;
private String level;
}
@Data
@Builder
public static class Location {
private String lng;
private String lat;
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!