|
|
|
@ -0,0 +1,273 @@
|
|
|
|
|
package weaver.interfaces.sskj.job;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.engine.kq.biz.KQFormatBiz;
|
|
|
|
|
import com.engine.kq.timer.KQQueue;
|
|
|
|
|
import com.engine.kq.timer.KQTaskBean;
|
|
|
|
|
import com.engine.kq.wfset.util.SplitActionUtil;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import com.jayway.jsonpath.Configuration;
|
|
|
|
|
import com.jayway.jsonpath.JsonPath;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import weaver.conn.RecordSet;
|
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
|
|
|
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import static weaver.interfaces.sskj.util.HttpsUtil.doPostJsonRequest;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created with IntelliJ IDEA.
|
|
|
|
|
* 获取中控的考勤数据同步至OA
|
|
|
|
|
* @Auther: chenwnj
|
|
|
|
|
* @Date: 2023/02/27/14:03
|
|
|
|
|
* @Description:
|
|
|
|
|
*/
|
|
|
|
|
public class SyncZkAllDayKqDataJob extends BaseCronJob {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
|
|
|
|
new BaseBean();
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
bb.writeLog("获取中控的考勤数据同步至OA!!!");
|
|
|
|
|
Instant startDoTime = Instant.now();
|
|
|
|
|
try {
|
|
|
|
|
//获取所有在职人员的id和workcode
|
|
|
|
|
Map<String, String> idWorkcodeMap = new HashMap<>();
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
String acqResSql = "SELECT id,workcode FROM HRMRESOURCE WHERE status in (0,1,2,3)";
|
|
|
|
|
rs.executeQuery(acqResSql);
|
|
|
|
|
while (rs.next()){
|
|
|
|
|
String userId = Util.null2String(rs.getString("id"));
|
|
|
|
|
String workcode = Util.null2String(rs.getString("workcode"));
|
|
|
|
|
if ( StringUtils.isNotBlank(userId) && StringUtils.isNotBlank(workcode)) {
|
|
|
|
|
idWorkcodeMap.put(workcode,userId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取开始时间结束时间
|
|
|
|
|
String startTime = "";
|
|
|
|
|
String endTime = "";
|
|
|
|
|
bb.writeLog("startTime = " + startTime);
|
|
|
|
|
bb.writeLog("endTime = " + endTime);
|
|
|
|
|
if (StringUtils.isBlank(startTime) && StringUtils.isBlank(endTime)) {
|
|
|
|
|
String format = DateUtil.format(new Date(), "yyyy-MM-dd");
|
|
|
|
|
DateTime yesterday = DateUtil.yesterday();
|
|
|
|
|
String format1 = DateUtil.format(yesterday, "yyyy-MM-dd");
|
|
|
|
|
startTime = format1 + " " + "00:00:00";
|
|
|
|
|
endTime = format + " " + "00:00:00";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bb.writeLog("startTime:"+startTime);
|
|
|
|
|
bb.writeLog("endTime:"+endTime);
|
|
|
|
|
String url = bb.getPropValue("project_sskj", "zkKqUrl");
|
|
|
|
|
//获取日志表建模模块ID
|
|
|
|
|
String kqSyncLogModeId = bb.getPropValue("project_sskj","kqSyncLogModeId");
|
|
|
|
|
bb.writeLog("url:"+url);
|
|
|
|
|
Map<String, String> heads = new HashMap<String, String>();
|
|
|
|
|
Map<String,Object> dataMap = new HashMap<String,Object>();
|
|
|
|
|
dataMap.put("starttime",startTime);
|
|
|
|
|
dataMap.put("endtime",endTime);
|
|
|
|
|
bb.writeLog("获取中控的考勤数据入参dataMap:"+JSONObject.toJSONString(dataMap));
|
|
|
|
|
String back = doPostJsonRequest(url,heads, JSON.toJSONString(dataMap));
|
|
|
|
|
bb.writeLog("urlBack:"+back);
|
|
|
|
|
bb.writeLog("获取中控的考勤数据--response:"+back);
|
|
|
|
|
List<List> logParams = new ArrayList<>();
|
|
|
|
|
List<List> lsParams = new ArrayList<>();
|
|
|
|
|
List<String> lsFormatData = new ArrayList<>();
|
|
|
|
|
Object tempBack = Configuration.defaultConfiguration().jsonProvider().parse(back);
|
|
|
|
|
Integer ret = JsonPath.read(tempBack, "$.ret");
|
|
|
|
|
if ( ret == 0) {
|
|
|
|
|
Integer count = Util.getIntValue(Util.null2String(JsonPath.read(tempBack, "$.data.count").toString()));
|
|
|
|
|
if ( count > 0 ) {
|
|
|
|
|
List<Map<String, Object>> items = JsonPath.read(tempBack, "$.data.items[*]");
|
|
|
|
|
for (Map<String, Object> item : items) {
|
|
|
|
|
String pin = Util.null2String(item.get("pin"));
|
|
|
|
|
String checktime = Util.null2String(item.get("checktime"));
|
|
|
|
|
String alias = Util.null2String(item.get("alias"));
|
|
|
|
|
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Date date = df.parse(checktime);
|
|
|
|
|
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
DateFormat df3 = new SimpleDateFormat("HH:mm:ss");
|
|
|
|
|
Integer isimport = 1;
|
|
|
|
|
String userid = Util.null2String(idWorkcodeMap.get(pin));
|
|
|
|
|
Integer usertype = 1;
|
|
|
|
|
String signDate = df2.format(date);
|
|
|
|
|
String signTime = df3.format(date);
|
|
|
|
|
Integer isincom = 1;
|
|
|
|
|
String signfrom = "OutDataSourceSyn";
|
|
|
|
|
if (StringUtils.isBlank(alias)) {
|
|
|
|
|
bb.writeLog("--item:"+item);
|
|
|
|
|
}
|
|
|
|
|
String addr = alias;
|
|
|
|
|
List params = new ArrayList<>();
|
|
|
|
|
if (StringUtils.isBlank(userid)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
params.add(userid);
|
|
|
|
|
params.add(usertype);
|
|
|
|
|
params.add(signDate);
|
|
|
|
|
params.add(signTime);
|
|
|
|
|
params.add("");
|
|
|
|
|
params.add(isincom);
|
|
|
|
|
params.add(isimport);
|
|
|
|
|
params.add(signfrom);
|
|
|
|
|
params.add("");
|
|
|
|
|
params.add("");
|
|
|
|
|
params.add(addr);
|
|
|
|
|
params.add("中控考勤机");
|
|
|
|
|
lsParams.add(params);
|
|
|
|
|
String formatData = userid + "|" + signDate + "|" + signTime;
|
|
|
|
|
if (!lsFormatData.contains(formatData)) {
|
|
|
|
|
lsFormatData.add(formatData);
|
|
|
|
|
}
|
|
|
|
|
//日志表
|
|
|
|
|
List<String> logPa = new ArrayList<>();
|
|
|
|
|
logPa.add(signDate);
|
|
|
|
|
logPa.add(userid);
|
|
|
|
|
logPa.add(signDate);
|
|
|
|
|
logPa.add(signTime);
|
|
|
|
|
logPa.add(addr);
|
|
|
|
|
logPa.add(kqSyncLogModeId);
|
|
|
|
|
logPa.add("1");
|
|
|
|
|
logPa.add("0");
|
|
|
|
|
logPa.add(signDate);
|
|
|
|
|
logPa.add(endTime.substring(10,16));
|
|
|
|
|
logParams.add(logPa);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bb.writeLog("lsParams:"+JSON.toJSONString(lsParams));
|
|
|
|
|
bb.writeLog("lsFormatData:"+JSON.toJSONString(lsFormatData));
|
|
|
|
|
|
|
|
|
|
Map<String,List<String>> overtimeMap = Maps.newHashMap();
|
|
|
|
|
List<String> overtimeList = Lists.newArrayList();
|
|
|
|
|
List<Object> formatParams = null;
|
|
|
|
|
List<List<Object>> lsFormatParams = new ArrayList<>();
|
|
|
|
|
List delParams = null;
|
|
|
|
|
List<List> lsDelParams = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
bb.writeLog("准备刷新报表数据");
|
|
|
|
|
//刷新报表数据
|
|
|
|
|
for(int i=0;lsFormatData!=null&&i<lsFormatData.size();i++){
|
|
|
|
|
formatParams = new ArrayList<>();
|
|
|
|
|
String[] formatData = Util.splitString(lsFormatData.get(i),"|");
|
|
|
|
|
String date_1 = weaver.common.DateUtil.addDate(formatData[1], -1);
|
|
|
|
|
formatParams.add(formatData[0]);
|
|
|
|
|
formatParams.add(date_1);
|
|
|
|
|
lsFormatParams.add(formatParams);
|
|
|
|
|
|
|
|
|
|
formatParams = new ArrayList<>();
|
|
|
|
|
formatParams.add(formatData[0]);
|
|
|
|
|
formatParams.add(formatData[1]);
|
|
|
|
|
lsFormatParams.add(formatParams);
|
|
|
|
|
|
|
|
|
|
delParams = new ArrayList<>();
|
|
|
|
|
delParams.add(formatData[0]);
|
|
|
|
|
delParams.add(formatData[1]);
|
|
|
|
|
delParams.add(formatData[2]);
|
|
|
|
|
lsDelParams.add(delParams);
|
|
|
|
|
|
|
|
|
|
String resourceId = formatData[0];
|
|
|
|
|
String kqdate = formatData[1];
|
|
|
|
|
if(overtimeMap.containsKey(resourceId)){
|
|
|
|
|
List<String> tmp_overtimeList = overtimeMap.get(resourceId);
|
|
|
|
|
if(!tmp_overtimeList.contains(kqdate)){
|
|
|
|
|
tmp_overtimeList.add(kqdate);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if(!overtimeList.contains(kqdate)){
|
|
|
|
|
overtimeList.add(kqdate);
|
|
|
|
|
}
|
|
|
|
|
overtimeMap.put(resourceId, overtimeList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String sql = "";
|
|
|
|
|
RecordSet rsB = new RecordSet();
|
|
|
|
|
bb.writeLog("开始同步数据");
|
|
|
|
|
|
|
|
|
|
//记录日志
|
|
|
|
|
//获取插入前最大的ID
|
|
|
|
|
Integer maxId = -1;
|
|
|
|
|
String acqMaxId = "select MAX(id) as id from uf_kqsynclog order by id desc";
|
|
|
|
|
rsB.executeQuery(acqMaxId);
|
|
|
|
|
while (rsB.next()) {
|
|
|
|
|
maxId = Util.getIntValue(Util.null2String(rsB.getString("id")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String addLogSql = "insert into uf_kqsynclog (syncdate, resourceid, kqdate, kqtime, kqalias, " +
|
|
|
|
|
" formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime) " +
|
|
|
|
|
" values (?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
|
boolean bLog = rsB.executeBatchSql(addLogSql, logParams);
|
|
|
|
|
bb.writeLog("bLog: " + bLog);
|
|
|
|
|
// if (bLog) {
|
|
|
|
|
// List<Integer> billids = new ArrayList<>();
|
|
|
|
|
// Map<Integer,Integer> billid_creator = new HashMap<>();
|
|
|
|
|
// String acqBillidsSql = "select id from uf_kqsynclog where id > ?";
|
|
|
|
|
// rsB.executeQuery(acqBillidsSql, maxId);
|
|
|
|
|
// while (rsB.next()) {
|
|
|
|
|
// Integer id = Util.getIntValue(Util.null2String(rsB.getString("id")));
|
|
|
|
|
// billids.add(id);
|
|
|
|
|
// billid_creator.put(id, 1);
|
|
|
|
|
// }
|
|
|
|
|
// if (billids != null && billids.size() > 0) {
|
|
|
|
|
// SskjUtil ssutil = new SskjUtil();
|
|
|
|
|
// ssutil.modePerReconBatch(billid_creator, kqSyncLogModeId, billids);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//删除本次同步数据
|
|
|
|
|
bb.writeLog("lsDelParams: " + lsDelParams);
|
|
|
|
|
sql = " delete from hrmschedulesign where signfrom='OutDataSourceSyn' and userid =? and signdate = ? and signtime = ? ";
|
|
|
|
|
boolean b1 = rsB.executeBatchSql(sql, lsDelParams);
|
|
|
|
|
bb.writeLog("b1: " + b1);
|
|
|
|
|
|
|
|
|
|
sql = " insert into HrmScheduleSign (userid, usertype, signdate, signtime, clientaddress, isincom, isimport, signfrom, longitude, latitude, addr,memo) "
|
|
|
|
|
+ " values(?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
|
boolean b2 = rsB.executeBatchSql(sql, lsParams);
|
|
|
|
|
bb.writeLog("b2: " + b2);
|
|
|
|
|
|
|
|
|
|
bb.writeLog("lsFormatParams:"+JSON.toJSONString(lsFormatParams));
|
|
|
|
|
bb.writeLog("lsFormatParams.size:"+lsFormatParams.size());
|
|
|
|
|
new KQFormatBiz().format(lsFormatParams);
|
|
|
|
|
|
|
|
|
|
bb.writeLog("开始处理加班生成");
|
|
|
|
|
//处理加班生成
|
|
|
|
|
List<KQTaskBean> tasks = new ArrayList<>();
|
|
|
|
|
for(Map.Entry<String, List<String>> mme: overtimeMap.entrySet()){
|
|
|
|
|
String resid = mme.getKey();
|
|
|
|
|
List<String> overList = mme.getValue();
|
|
|
|
|
for(String date : overList){
|
|
|
|
|
SplitActionUtil.pushOverTimeTasks(date,date,resid,tasks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!tasks.isEmpty()){
|
|
|
|
|
KQQueue.writeTasks(tasks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
bb.writeLog(e);
|
|
|
|
|
bb.writeLog("获取中控的考勤数据同步至OA--error"+e.getMessage());
|
|
|
|
|
}finally {
|
|
|
|
|
Instant endDoTime = Instant.now();
|
|
|
|
|
|
|
|
|
|
Duration timeElapsed = Duration.between(startDoTime, endDoTime);
|
|
|
|
|
bb.writeLog("中控考勤数据同步代码执行时间: " + timeElapsed.toMillis() + " 毫秒");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|