|
@@ -32,11 +32,18 @@ import com.kingdee.eas.utils.ExpiringMapCache;
|
|
|
import com.kingdee.util.StringUtils;
|
|
|
import okhttp3.*;
|
|
|
import org.apache.log4j.Logger;
|
|
|
+
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.sql.*;
|
|
|
import java.sql.Connection;
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.OffsetDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.Date;
|
|
|
|
|
@@ -45,6 +52,7 @@ public class SyncTranForMJFacadeControllerBean extends AbstractSyncTranForMJFaca
|
|
|
private Properties propt = new Properties();
|
|
|
private static ExpiringMapCache<String, String> cache = new ExpiringMapCache();
|
|
|
private long durationInMillis = 84600000;
|
|
|
+ private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
public SyncTranForMJFacadeControllerBean() throws BOSException {
|
|
|
String syncOAConfigPath = System.getProperty("EAS_HOME") + "/server/properties/scy/syncMJConfig.properties";
|
|
@@ -69,70 +77,53 @@ public class SyncTranForMJFacadeControllerBean extends AbstractSyncTranForMJFaca
|
|
|
@Override
|
|
|
protected void _syncAccessRecord(Context ctx, String startDate, String endDate) throws BOSException {
|
|
|
logger.error("_syncAccessRecord------");
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
Properties properties = new Properties();
|
|
|
properties.put("version", propt.getProperty("version"));
|
|
|
properties.put("tenantCode", propt.getProperty("tenantCode"));//租户编号,平台提供
|
|
|
properties.put("language", propt.getProperty("language"));//语言
|
|
|
properties.put("tenantSecret", propt.getProperty("tenantSecret"));//密钥
|
|
|
properties.put("account", propt.getProperty("account"));//接口账号
|
|
|
- properties.put("password", propt.getProperty("password"));//接口账号密码
|
|
|
+ properties.put("password", propt.getProperty("passwordMj"));//接口账号密码
|
|
|
properties.put("getTokenPath", propt.getProperty("getTokenPath"));//获取token接口地址
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
-
|
|
|
+ int pageIndex = 1;
|
|
|
try {
|
|
|
- JSONObject params = new JSONObject();
|
|
|
- params.put("count", "100");
|
|
|
- //获取前三天数据
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.add(Calendar.DAY_OF_YEAR, -3);
|
|
|
- Date threeDaysAgoDate = calendar.getTime();
|
|
|
- if(StringUtils.isEmpty(startDate)){
|
|
|
- //Date parse = sdf.parse("2022-01-01");
|
|
|
- params.put("rowTimeStamp", threeDaysAgoDate.getTime());
|
|
|
- }else{
|
|
|
- Date parse = sdf.parse(startDate);
|
|
|
- params.put("rowTimeStamp", parse.getTime());
|
|
|
- }
|
|
|
- String payload = params.toJSONString();
|
|
|
- Map<String, String> headers = getHeader(payload, false);
|
|
|
+ while (true) {
|
|
|
+ // 获取前三天的时间
|
|
|
+ JSONObject params = buildRequestParams(pageIndex, startDate, endDate);
|
|
|
+ String payload = params.toJSONString();
|
|
|
+ Map<String, String> headers = getHeader(payload, false);
|
|
|
+
|
|
|
+ OkHttpClient client = new OkHttpClient.Builder().build();
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
+ RequestBody body = RequestBody.create(mediaType, payload);
|
|
|
+ Request.Builder requestBuilder = new Request.Builder()
|
|
|
+ .url(propt.getProperty("getMJPath"))
|
|
|
+ .method("POST", body)
|
|
|
+ .addHeader("Content-Type", "application/json");
|
|
|
+ // 批量添加请求头
|
|
|
+ for (Map.Entry<String, String> header : headers.entrySet()) {
|
|
|
+ requestBuilder.header(header.getKey(), header.getValue());
|
|
|
+ }
|
|
|
+ Response response = client.newCall(requestBuilder.build()).execute();
|
|
|
+ logger.error("response----" + response.isSuccessful());
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ //重置token,每次调用接口后刷新token
|
|
|
+ resetToken();
|
|
|
+ String resultBody = response.body().string();
|
|
|
+ logger.error("resultBody----" + resultBody);
|
|
|
+ JSONObject result = JSONObject.parseObject(resultBody);
|
|
|
+ logger.error("respMap----" + result);
|
|
|
+
|
|
|
+ if (result.get("code").equals("0") || Integer.parseInt(result.get("code").toString()) == 0) {
|
|
|
+ JSONArray data = result.getJSONArray("data");
|
|
|
+ int pageCount = result.getInteger("pageCount");
|
|
|
+ jsonArray.add(data);
|
|
|
+ if (pageIndex >= pageCount) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ pageIndex++;
|
|
|
|
|
|
- OkHttpClient client = new OkHttpClient.Builder().build();
|
|
|
- MediaType mediaType = MediaType.parse("application/json");
|
|
|
- RequestBody body = RequestBody.create(mediaType, payload);
|
|
|
- Request.Builder requestBuilder = new Request.Builder()
|
|
|
- .url(propt.getProperty("getMJPath"))
|
|
|
- .method("POST", body)
|
|
|
- .addHeader("Content-Type", "application/json");
|
|
|
- // 批量添加请求头
|
|
|
- for (Map.Entry<String, String> header : headers.entrySet()) {
|
|
|
- requestBuilder.header(header.getKey(), header.getValue());
|
|
|
- }
|
|
|
- Response response = client.newCall(requestBuilder.build()).execute();
|
|
|
- logger.error("response----" + response.isSuccessful());
|
|
|
- if (response.isSuccessful()) {
|
|
|
- //重置token,每次调用接口后刷新token
|
|
|
- resetToken();
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- String resultBody = response.body().string();
|
|
|
- logger.error("resultBody----" + resultBody);
|
|
|
- JSONObject result = JSONObject.parseObject(resultBody);
|
|
|
- logger.error("respMap----" + result);
|
|
|
- if (result.get("code").equals("0") || Integer.parseInt(result.get("code").toString()) == 0) {
|
|
|
- String data = result.get("data").toString();
|
|
|
- JSONArray jsonArray = JSONArray.parseArray(data);
|
|
|
- logger.error("jsonArray---" + jsonArray.toString());
|
|
|
- logger.error("jsonArray---" + jsonArray.size());
|
|
|
- IPerson iPerson = PersonFactory.getLocalInstance(ctx);
|
|
|
- PersonCollection personCollection = iPerson.getPersonCollection("select number ");
|
|
|
- Set set = new HashSet();
|
|
|
- for (int i = 0; i < personCollection.size(); i++) {
|
|
|
- PersonInfo personInfo = personCollection.get(i);
|
|
|
- set.add(personInfo.getNumber().toString());
|
|
|
- }
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JSONObject resultData = jsonArray.getJSONObject(i);
|
|
|
- //保存门禁打卡记录
|
|
|
- saveMJPunchCardData(ctx, resultData, set);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -140,18 +131,81 @@ public class SyncTranForMJFacadeControllerBean extends AbstractSyncTranForMJFaca
|
|
|
e.printStackTrace();
|
|
|
throw new BOSException(e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONArray resultData = jsonArray.getJSONArray(i);
|
|
|
+
|
|
|
+ //保存门禁打卡记录
|
|
|
+ saveMJPunchCardData(ctx, resultData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期格式装换
|
|
|
+ *
|
|
|
+ * @param date
|
|
|
+ */
|
|
|
+ private String dateFormatConversion(String date) {
|
|
|
+ // 定义输入日期时间字符串的格式
|
|
|
+ DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ // 解析输入的字符串为 LocalDateTime 对象
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.parse(date, inputFormatter);
|
|
|
+ // 将 LocalDateTime 对象转换为 OffsetDateTime 对象,并指定时区偏移为 +08:00
|
|
|
+ OffsetDateTime offsetDateTime = localDateTime.atOffset(ZoneOffset.of("+08:00"));
|
|
|
+ // 定义输出的日期时间格式,即 ISO 8601 格式
|
|
|
+ DateTimeFormatter outputFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
+ // 将 OffsetDateTime 对象格式化为目标字符串
|
|
|
+ String outputDateStr = offsetDateTime.format(outputFormatter);
|
|
|
+ return outputDateStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取前三天的时间
|
|
|
+ *
|
|
|
+ * @param startDate
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ private JSONObject buildRequestParams(int pageIndex, String startDate, String endDate) {
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("pageIndex", pageIndex);
|
|
|
+ params.put("pageSize", propt.getProperty("pageSize"));
|
|
|
+ params.put("eventResult", 1);
|
|
|
+ String array = propt.getProperty("array");
|
|
|
+ String array2 = propt.getProperty("array2");
|
|
|
+ Set<String> set = AtsUtil.toSet(array + array2);
|
|
|
+ params.put("pointCodes", set);//门点编号
|
|
|
+ // 获取当前时间,并设置为 UTC+8 时区
|
|
|
+ ZonedDateTime now = ZonedDateTime.now(ZoneOffset.ofHours(8));
|
|
|
+ // 获取前两天的日期时间
|
|
|
+ ZonedDateTime twoDaysAgo = now.minusDays(2);
|
|
|
+ ZonedDateTime plusDays = now.plusDays(1);
|
|
|
+ // 定义目标格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
|
+ // 格式化时间 当前时间前两天
|
|
|
+ String formattedTime = twoDaysAgo.format(formatter);
|
|
|
+ String plusDaysTime = plusDays.format(formatter);
|
|
|
+ // 输出结果
|
|
|
+ if (!StringUtils.isEmpty(startDate) && !StringUtils.isEmpty(endDate)) {
|
|
|
+ params.put("minEventTime", dateFormatConversion(startDate));
|
|
|
+ params.put("maxEventTime", dateFormatConversion(endDate));
|
|
|
+ } else {
|
|
|
+ params.put("minEventTime", formattedTime);
|
|
|
+ params.put("maxEventTime", plusDaysTime);
|
|
|
+ }
|
|
|
+ return params;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 保存门禁打卡记录
|
|
|
*
|
|
|
* @param ctx
|
|
|
- * @param resultData
|
|
|
+ * @param jsonArray
|
|
|
*/
|
|
|
- public void saveMJPunchCardData(Context ctx, JSONObject resultData, Set set) {
|
|
|
+ public void saveMJPunchCardData(Context ctx, JSONArray jsonArray) {
|
|
|
logger.error("saveMJPunchCardData----");
|
|
|
try {
|
|
|
-
|
|
|
int success = 0;
|
|
|
int error = 0;
|
|
|
Set<String> setCardId = new HashSet();
|
|
@@ -166,71 +220,83 @@ public class SyncTranForMJFacadeControllerBean extends AbstractSyncTranForMJFaca
|
|
|
//存储考勤日期为空的数据
|
|
|
JSONArray notExistRecords = new JSONArray();
|
|
|
JSONArray seccussArray = new JSONArray();
|
|
|
- ++success;
|
|
|
- String personNumber = resultData.getString("empCode");//员工编码
|
|
|
- String punchCardDate = resultData.getString("checkTime"); //打卡时间
|
|
|
- String RecDate = punchCardDate.substring(0, 10);// 考勤日期
|
|
|
- String RecTime = punchCardDate.substring(11, 19);// 考勤时间
|
|
|
- //String locationDetail = resultSet.getString("name"); //打卡地点
|
|
|
- //String EquNo = resultSet.getString("EquNo"); //考勤机编码
|
|
|
- //String exceptionType = resultSet.getString("EquNo"); // 打卡/异常类型
|
|
|
- //Date punchDate = HRTimeWebUtils.stringToShortDate(RecDate, true);
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
|
- SimpleDateFormat sdfymd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- Date date = sdf.parse(punchCardDate);
|
|
|
- String format = sdfymd.format(date);
|
|
|
- Date punchDate = com.kingdee.eas.custom.synctask.utils.HRTimeWebUtils.stringToShortDate(RecDate, true);
|
|
|
- Timestamp punchCardTime = com.kingdee.eas.custom.synctask.utils.HRTimeWebUtils.stringToTimestamp(format ,true);
|
|
|
- // 处理数据
|
|
|
- if (punchCardDate != null && punchCardTime != null) {
|
|
|
- PunchCardRecordInfo cardInfo = new PunchCardRecordInfo();
|
|
|
- //考勤机编码
|
|
|
- cardInfo.setEquipmentNum("001");
|
|
|
- //考勤编码
|
|
|
- cardInfo.setAttendanceNum(personNumber);
|
|
|
- //打卡日期
|
|
|
- cardInfo.setPunchCardDate(punchDate);
|
|
|
- //打卡时间
|
|
|
- cardInfo.setPunchCardTime(punchCardTime);
|
|
|
- // 打卡来源
|
|
|
- cardInfo.setPunchCardSource(PunchCardSourceEnum.attenceMachine);
|
|
|
- // 打卡位置
|
|
|
- cardInfo.setPunchCardPlace((String) resultData.get("checkLocation"));
|
|
|
- // 有效
|
|
|
- PunchCardStateEnum punchCardStateEnum;
|
|
|
- if ((boolean) resultData.get("isActive")) {
|
|
|
+ //获取员工编码
|
|
|
+ IPerson iPerson = PersonFactory.getLocalInstance(ctx);
|
|
|
+ PersonCollection personCollection = iPerson.getPersonCollection("select number ");
|
|
|
+ Set set = new HashSet();
|
|
|
+ for (int i = 0; i < personCollection.size(); i++) {
|
|
|
+ PersonInfo personInfo = personCollection.get(i);
|
|
|
+ set.add(personInfo.getNumber().toString());
|
|
|
+ }
|
|
|
+ for (int j = 0; j < jsonArray.size(); j++) {
|
|
|
+ JSONObject resultData = jsonArray.getJSONObject(j);
|
|
|
+ ++success;
|
|
|
+ String personNumber = resultData.getString("empCode");//员工编码
|
|
|
+ String punchCardDate = resultData.getString("eventTime"); //打卡时间
|
|
|
+ //String punchCardDate = resultData.getString("checkTime"); //打卡时间
|
|
|
+ String RecDate = punchCardDate.substring(0, 10);// 考勤日期
|
|
|
+ String RecTime = punchCardDate.substring(11, 19);// 考勤时间
|
|
|
+ //String locationDetail = resultSet.getString("name"); //打卡地点
|
|
|
+ //String EquNo = resultSet.getString("EquNo"); //考勤机编码
|
|
|
+ //String exceptionType = resultSet.getString("EquNo"); // 打卡/异常类型
|
|
|
+ //Date punchDate = HRTimeWebUtils.stringToShortDate(RecDate, true);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
|
+ SimpleDateFormat sdfymd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date date = sdf.parse(punchCardDate);
|
|
|
+ String format = sdfymd.format(date);
|
|
|
+ Date punchDate = com.kingdee.eas.custom.synctask.utils.HRTimeWebUtils.stringToShortDate(RecDate, true);
|
|
|
+ Timestamp punchCardTime = com.kingdee.eas.custom.synctask.utils.HRTimeWebUtils.stringToTimestamp(format, true);
|
|
|
+ // 处理数据
|
|
|
+ if (punchCardDate != null && punchCardTime != null) {
|
|
|
+ PunchCardRecordInfo cardInfo = new PunchCardRecordInfo();
|
|
|
+ //考勤机编码
|
|
|
+ cardInfo.setEquipmentNum("001");
|
|
|
+ //考勤编码
|
|
|
+ cardInfo.setAttendanceNum(personNumber);
|
|
|
+ //打卡日期
|
|
|
+ cardInfo.setPunchCardDate(punchDate);
|
|
|
+ //打卡时间
|
|
|
+ cardInfo.setPunchCardTime(punchCardTime);
|
|
|
+ // 打卡来源
|
|
|
+ cardInfo.setPunchCardSource(PunchCardSourceEnum.attenceMachine);
|
|
|
+ // 打卡位置
|
|
|
+ cardInfo.setPunchCardPlace((String) resultData.get("pointName"));
|
|
|
+ // 有效
|
|
|
+ PunchCardStateEnum punchCardStateEnum;
|
|
|
+ //if ((boolean) resultData.get("isActive")) {
|
|
|
+ // punchCardStateEnum = PunchCardStateEnum.normal;
|
|
|
+ //} else {
|
|
|
+ // punchCardStateEnum = PunchCardStateEnum.cancelled;
|
|
|
+ //}
|
|
|
punchCardStateEnum = PunchCardStateEnum.normal;
|
|
|
- } else {
|
|
|
- punchCardStateEnum = PunchCardStateEnum.cancelled;
|
|
|
- }
|
|
|
- cardInfo.setPunchCardState(punchCardStateEnum);
|
|
|
- ////简称
|
|
|
- //cardInfo.setSimpleName(exceptionType);
|
|
|
- //描述
|
|
|
- cardInfo.setDescription("门禁打卡机");
|
|
|
-
|
|
|
- EquNoSet.add("001");
|
|
|
- if (!StringUtils.isEmpty(personNumber)) {
|
|
|
- if (!set.contains(personNumber)) {
|
|
|
- return;
|
|
|
+ cardInfo.setPunchCardState(punchCardStateEnum);
|
|
|
+ ////简称
|
|
|
+ //cardInfo.setSimpleName(exceptionType);
|
|
|
+ //描述
|
|
|
+ cardInfo.setDescription("门禁打卡机");
|
|
|
+ EquNoSet.add("001");
|
|
|
+ if (!StringUtils.isEmpty(personNumber)) {
|
|
|
+ if (!set.contains(personNumber)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ setCardId.add(personNumber);
|
|
|
+ cardColl.add(cardInfo);
|
|
|
}
|
|
|
- setCardId.add(personNumber);
|
|
|
- cardColl.add(cardInfo);
|
|
|
- }
|
|
|
|
|
|
- if (minDateTime != null && maxDateTime != null) {
|
|
|
- if (punchCardTime.getTime() < minDateTime.getTime()) {
|
|
|
+ if (minDateTime != null && maxDateTime != null) {
|
|
|
+ if (punchCardTime.getTime() < minDateTime.getTime()) {
|
|
|
+ minDateTime = punchCardTime;
|
|
|
+ } else if (punchCardTime.getTime() > maxDateTime.getTime()) {
|
|
|
+ maxDateTime = punchCardTime;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
minDateTime = punchCardTime;
|
|
|
- } else if (punchCardTime.getTime() > maxDateTime.getTime()) {
|
|
|
maxDateTime = punchCardTime;
|
|
|
}
|
|
|
+
|
|
|
} else {
|
|
|
- minDateTime = punchCardTime;
|
|
|
- maxDateTime = punchCardTime;
|
|
|
+ formatErrorRecords.add(resultData);
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- formatErrorRecords.add(resultData);
|
|
|
}
|
|
|
// 考勤档案
|
|
|
Map<String, AttendanceFileInfo> attendanceFileMap = AttendanceFileFactory.getLocalInstance(ctx).getPersonByAttendanceNum(setCardId);
|
|
@@ -287,13 +353,15 @@ public class SyncTranForMJFacadeControllerBean extends AbstractSyncTranForMJFaca
|
|
|
logger.error("notExistRecords-----" + notExistRecords.size());
|
|
|
logger.error("seccussArray--Size-----" + seccussArray.size());
|
|
|
logger.error("seccussArray-----" + seccussArray);
|
|
|
+ if(cardCollFinally.size()>=0){
|
|
|
IObjectPK[] iObjectPKS = PunchCardRecordFactory.getLocalInstance(ctx).saveBatchData(cardCollFinally);
|
|
|
- logger.error("iObjectPKS----" + iObjectPKS.length);
|
|
|
- } catch (
|
|
|
- Exception e) {
|
|
|
+ logger.error("iObjectPKS----" + iObjectPKS.length);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 重置token,每次调用接口后刷新token
|
|
|
*/
|
|
@@ -352,7 +420,7 @@ public class SyncTranForMJFacadeControllerBean extends AbstractSyncTranForMJFaca
|
|
|
try {
|
|
|
com.alibaba.fastjson.JSONObject params = new com.alibaba.fastjson.JSONObject();
|
|
|
params.put("account", propt.getProperty("account"));
|
|
|
- String password = propt.getProperty("password");
|
|
|
+ String password = propt.getProperty("passwordMj");
|
|
|
params.put("password", EncryptUtils.sha256(password, false));
|
|
|
String payload = params.toJSONString();
|
|
|
String getTokenPath = propt.getProperty("getTokenPath");
|