出差流程没有外勤打卡不计算考勤

dev
chenwei 1 year ago
parent 137ea3ee8e
commit add2b096db

File diff suppressed because it is too large Load Diff

@ -19,7 +19,7 @@ public interface KqWorkflowService {
Map<String, Object> importOverTime(Map<String, Object> params);
/**
*
*
*/
Map<String, Object> getEntryType(Map<String, Object> params);

@ -1,5 +1,6 @@
package com.engine.sskj.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.engine.core.impl.Service;
import com.engine.kq.biz.KQTimesArrayComInfo;
import com.engine.kq.util.KQDurationCalculatorUtil;
@ -10,6 +11,8 @@ import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class KqWorkflowServiceImpl extends Service implements KqWorkflowService {
@ -73,6 +76,46 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
String[] overTimeInfos = overTimeInfo.split("\\|");
/*同条流程间校验*/
if (overTimeInfos.length > 1) {
// String minDate = "";
// String maxDate = "";
// for (String oti : overTimeInfos) {
//
// String resourceId = "";
// String fromDate = "";
// String fromTime = "";
// String toDate = "";
// String toTime = "";
//
// String[] otiArray = oti.split("_");
// for (String ot : otiArray) {
// String[] split = ot.split("=");
// if ("fromDate".equals(split[0])) {
// fromDate = split[1];
// if ( minDate.compareTo(fromDate) > 0 ) {
// minDate = fromDate;
// }
// }
//
// if ("toDate".equals(split[0])) {
// toDate = split[1];
// if ( maxDate.compareTo(toDate) > 0 ) {
// maxDate = toDate;
// }
// }
// }
// }
// List<String> allDays = new ArrayList<>();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//
// LocalDate start = LocalDate.parse(minDate, formatter);
// LocalDate end = LocalDate.parse(maxDate, formatter);
//
// while (!start.isAfter(end)) {
// allDays.add(start.format(formatter));
// start = start.plusDays(1);
// }
Map<String, int[]> resToOvInMap = new HashMap<>();
for (String oti : overTimeInfos) {
@ -107,6 +150,8 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
bb.writeLog("containsKey" );
int[] dayMins = resToOvInMap.get(resourceId);
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins) );
int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime);
bb.writeLog("fromTimeIdx: " + fromTimeIdx );
@ -127,10 +172,18 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
bb.writeLog("isExist: " + isExist );
if (!isExist) {
bb.writeLog("!isExist to do " );
bb.writeLog("fromTimeIdx: " + fromTimeIdx );
bb.writeLog("toTimeIdx: " + toTimeIdx );
bb.writeLog("dayMins: " + dayMins.length );
Arrays.fill(dayMins, fromTimeIdx, toTimeIdx, 1);//加班时段标识 1
} else {
bb.writeLog("!isExist else " );
String lastname = "";
String acqResLastNameSql = "select lastname from hrmresource where id = ? ";
rs.executeQuery(acqResLastNameSql, resourceId);
while (rs.next()) {
lastname = Util.null2String(rs.getString("lastname"));
@ -144,6 +197,12 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
resToOvInMap.put(resourceId, dayMins);
} else {
bb.writeLog("containsKey else" );
// int[] dayMins =new int[2880];
// if (allDays != null && allDays.size() > 0) {
// dayMins = new int[1440 * (allDays.size())];
// }
int[] dayMins = new int[2880];//一天所有分钟数
bb.writeLog("fromTime: " + fromTime );
@ -157,17 +216,20 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
if (fromDate.compareTo(toDate) < 0 ) {
toTimeIdx = toTimeIdx + 1440;
}
bb.writeLog("toTimeIdx: " + toTimeIdx );
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins) );
Arrays.fill(dayMins, fromTimeIdx, toTimeIdx, 1);//加班时段标识 1
resToOvInMap.put(resourceId, dayMins);
resToOvInMap.put(resourceId + "_" + fromDate, dayMins);
}
}
}
/*与历史数据校验*/
bb.writeLog("历史数据校验 " );
for (String oti : overTimeInfos) {
String[] otiArray = oti.split("_");
bb.writeLog("otiArray: " + otiArray.toString() );
String resourceId = "";
String fromDate = "";
@ -199,6 +261,7 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
//设置一个时间轴数组,长度为一天的分钟数
int[] dayMins = new int[2880];//一天所有分钟数
Arrays.fill(dayMins, 0);
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins));
String acqConOverTimeSql = "select fromDate, fromTime, toDate, toTime from uf_conOvertime where resourceId = ? and fromDate = ? and toDate = ?";
rs.executeQuery(acqConOverTimeSql, resourceId, fromDate, toDate);
while (rs.next()) {
@ -212,11 +275,17 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
if (fDate.compareTo(tDate) < 0) {
tTimeIdx = tTimeIdx +1440;
}
bb.writeLog("fTimeIdx: " + fTimeIdx);
bb.writeLog("tTimeIdx: " + tTimeIdx);
Arrays.fill(dayMins, fTimeIdx, tTimeIdx, 1);//加班时段标识 1
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins));
}
int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime);
int toTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(toTime);
bb.writeLog("fromTimeIdx: " + fromTimeIdx);
bb.writeLog("toTimeIdx: " + toTimeIdx);
//确认fromTimeIdx-toTimeIdx在时间轴上是否有1
boolean isExist = false;
for (int i = fromTimeIdx; i <= toTimeIdx; i++) {
@ -307,9 +376,23 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
String entryTypeField = Util.null2String(bb.getPropValue("project_sskj", "entryTypeField"));
bb.writeLog("entryTypeField: " + entryTypeField);
String entryTypeValue = Util.null2String(bb.getPropValue("project_sskj", "entryTypeValue"));
bb.writeLog("entryTypeValue: " + entryTypeValue);
if (StringUtils.isBlank(entryTypeField)) {
result.put("code",500);
result.put("msg", "请先配置劳务工类型字段");
return result;
}
if (StringUtils.isBlank(entryTypeValue)) {
result.put("code",500);
result.put("msg", "请先配置劳务工类型值");
return result;
}
String entryTypeFieldValue = "";
String acqEntryTypeSql = "select " + entryTypeField + " from cus_fielddata where scopeid = 3 and id = ? ";
boolean entryTypeFieldValue = false;
String acqEntryTypeSql = "select " + entryTypeField + " from cus_fielddata where scopeid = -1 and id = ? ";
bb.writeLog("acqEntryTypeSql: " + acqEntryTypeSql);
RecordSet rs = new RecordSet();
rs.executeQuery(acqEntryTypeSql, resourceId);
@ -317,8 +400,8 @@ public class KqWorkflowServiceImpl extends Service implements KqWorkflowService
String temp = Util.null2String(rs.getString(1));
bb.writeLog("temp: " + temp);
if (StringUtils.isNotBlank(temp)) {
entryTypeFieldValue = temp;
if(temp.equals(entryTypeValue)) {
entryTypeFieldValue = true;
}
}

@ -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() + " 毫秒");
}
}
}
Loading…
Cancel
Save