Compare commits

...

13 Commits

@ -0,0 +1,36 @@
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.engine.kq.biz.KQFormatData" %>
<%@ page import="weaver.general.Util" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%
RecordSet rs1 = new RecordSet();
rs1.writeLog("begin do FormatDingTalkSignTime invoke ...");
try {
// 当前日期
String today = DateUtil.getCurrentDate();
String startDate = "2024-03-01";
// 格式化期间的考勤时间
rs1.writeLog("开始处理时间格式,处理范围【" + startDate + "到" + today + "】");
rs1.executeUpdate("update hrmschedulesign set signtime = left(signtime, 5) + ':00' where belongdate >= '" + startDate + "' and belongdate <= '" + today + "'");
rs1.writeLog("结束处理时间格式,处理范围【" + startDate + "到" + today + "】");
// 处理当前日期到2024-03-01的考勤数据
for (String date = startDate; DateUtil.timeInterval(date, today) >= 0; date = DateUtil.addDate(date, 1)) {
String sql = "select id from hrmresource where status in (0,1,2,3)";
rs1.execute(sql);
while (rs1.next()) {
String resourceId = Util.null2String(rs1.getString("id"));
rs1.writeLog("KQFormatData当前人员Id==" + resourceId);
for (int i = 0; i < 22; i++) {
new KQFormatData().formatKqDate(resourceId, DateUtil.addDate(date, i));
}
}
}
rs1.writeLog("end do FormatDingTalkSignTime invoke ...");
} catch (Exception e) {
rs1.writeLog("考勤格式化异常", e);
}
out.println("数据处理完成...");
%>

@ -0,0 +1,340 @@
package com.engine.hrm.cmd.emmanager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQGroupMemberComInfo;
import com.engine.kq.entity.KQGroupEntity;
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 weaver.common.DateUtil;
import weaver.conn.BatchRecordSet;
import weaver.conn.RecordSet;
import weaver.general.Util;
import com.engine.kq.biz.KQFormatData;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* EM
*
* @author lvyi
*/
public class SynKqData4EMCmd extends AbstractCommonCommand<Map<String, Object>> {
private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public SynKqData4EMCmd(Map<String, Object> params) {
this.params = params;
}
// "checkindata": [{
// "userid" : "100",
// "checkin_type" : 1,
// "checkin_time" : "1492617610",
// "location" : "四川省成都市武侯区益州大道中段784号附近",
// "longitude" : "116.486888",
// "latitude" : "39.999946",
// "wifiname" : "办公一区",
// "wifimac" : "3c:46:d8:0c:7a:70",
// "notes" : "路上堵车迟到了5分钟"
// },{
// "userid" : "101",
// "checkin_type" : 3,
// "checkin_time" : "1492617620",
// "location" : "重庆市渝北区金渝大道101号金渝大道",
// "longitude" : "116.486888",
// "latitude" : "39.999946",
// "wifiname" : "办公室二区",
// "wifimac" : "3c:46:d8:0c:7a:71",
// "notes" : ""
// }]
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
String sql = "";
RecordSet rs = new RecordSet();
BatchRecordSet bRs = new BatchRecordSet();
List<List<Object>> lsParam = new ArrayList<>();
List<List<Object>> lsParam_out = new ArrayList<>();
List<Object> param = null;
List<Object> param_out = null;
List<List<Object>> lsDelParams = new ArrayList<>();
List<List<Object>> lsDelParams_out = new ArrayList<>();
List<Object> delParams = null;
List<String> lsFormatData = new ArrayList<>();
List<String> lsFormatData_out = new ArrayList<>();
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = null;
try {
String checkindata = Util.null2String(params.get("checkindata"));
String cptype = Util.null2String(params.get("cptype"));
writeLog("执行考勤数据同步=="+JSONObject.toJSONString(params));
JSONArray datas = JSONArray.parseArray(checkindata);
for (int i = 0; datas != null && i < datas.size(); i++) {
JSONObject data = datas.getJSONObject(i);
String userid = Util.null2String(data.getString("userid"));
//将checkin_time放在前面是用于userid为空的时候日志的打印便于定位云桥推送的问题数据因为刚刚肉眼看了1w+的数据量,乏了
String checkin_time = Util.null2String(data.getString("checkin_time"));
if(userid.length()==0){
writeLog("userid为空或者云桥推送数据有问题:checkin_time=="+checkin_time);
continue;
}
String signtype = Util.null2String(data.getString("checkin_type"));
boolean isOutSide = false; //是否是外勤打卡数据
String outsidesign = ""; //人员所在考勤组是否开启外勤签到转考勤
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
KQGroupEntity kqGroupEntity = kqGroupMemberComInfo.getUserKQGroupInfo(userid);
if (kqGroupEntity != null) {
outsidesign = kqGroupEntity.getOutsidesign();
}
if(checkin_time.length()==0)continue;
String[] tmpDateTime = Util.splitString(DateUtil.getFullDate(new Date(new Long(checkin_time)* 1000L))," ");
String signdate = tmpDateTime[0].trim();
String signtime = tmpDateTime[1].trim();
// 将钉钉上同步过来的打卡数据去掉后面的秒数显示解决统计迟到时长
signtime = DateUtil.formatTime(signtime)+":00";
writeLog("处理钉钉考勤时间格式化完成userid==" + userid + ",signdate==" + signdate + ",signtime==" + signtime);
String addr = Util.null2String(data.getString("location"));
String longitude = Util.null2String(data.getString("longitude"));
String latitude = Util.null2String(data.getString("latitude"));
String wifiname = Util.null2String(data.getString("wifiname"));
String wifimac = Util.null2String(data.getString("wifimac"));
String notes = Util.null2String(data.getString("notes"));
String deviceId = Util.null2String(data.getString("deviceId"));
String deviceInfo = "";
if(!"".equals(deviceId)){
Map<String, Object> tmpdate = new HashMap<String, Object>();
tmpdate.put("deviceId",deviceId);
deviceInfo = JSONObject.toJSONString(tmpdate);
}
String exception_type = Util.null2String(data.getString("exception_type"));
String timeResult = Util.null2String(data.getString("timeResult"));
String locationResult = Util.null2String(data.getString("locationResult"));
String memo = "";//最近一直有云桥的同步报错的问题,先干掉;"wifiname:"+wifiname+"#wifimac:"+wifimac+"#notes:"+notes;
if("1".equals(cptype)){
//企业微信打卡
if(signtype.equalsIgnoreCase("3")) isOutSide = true;
//过滤异常数据
if(exception_type.length()>0&&(exception_type.indexOf("未打卡")>=0 || exception_type.indexOf("地点异常")>=0 || exception_type.indexOf("wifi异常")>=0)){
// continue;
}
}else if("2".equals(cptype)){
//钉钉打卡
// 有一个isLegal 字段是否合法如果timeResult和locationResult都是空则不合法无效打卡数据。
// 如果是不合法打卡数据不传给OA
boolean notLegal = "".equalsIgnoreCase(timeResult) && "".equals(locationResult);
if(notLegal) {
// continue;
}
if("Outside".equals(locationResult)) isOutSide = true;
//过滤异常数据
if("NotSigned".equals(timeResult)) continue;
}
//允许外勤签到转考勤
if("1".equalsIgnoreCase(outsidesign)){
param = new ArrayList<>();
param_out = new ArrayList<>();
param.add(userid);
param.add("1");
param.add(signtype);
param.add(signdate);
param.add(signtime);
if(isOutSide){
param.add("EMSyn_out");
}else{
param.add("EMSyn");
}
param.add("1");
param.add(addr);
param.add(longitude);
param.add(latitude);
param.add(memo);
param.add(deviceInfo);
lsParam.add(param);
String formatData = userid+"|"+signdate+"|"+signtime;
if(!lsFormatData.contains(formatData)){
lsFormatData.add(formatData);
}
//外勤数据
if(isOutSide) {
param_out.add(userid);
param_out.add("e9_mobile_out");
param_out.add(signdate);
param_out.add(signtime);
param_out.add(longitude);
param_out.add(latitude);
param_out.add(addr);
param_out.add(notes);
param_out.add("1");
lsParam_out.add(param_out);
String formatData_out = userid+"|"+signdate+"|"+signtime;
if(!lsFormatData_out.contains(formatData_out)){
lsFormatData_out.add(formatData_out);
}
}
}else{
//不允许外勤数据转考勤
param = new ArrayList<>();
param_out = new ArrayList<>();
//外勤打卡数据
if(isOutSide){
param_out.add(userid);
param_out.add("e9_mobile_out");
param_out.add(signdate);
param_out.add(signtime);
param_out.add(longitude);
param_out.add(latitude);
param_out.add(addr);
param_out.add(notes);
param_out.add("1");
lsParam_out.add(param_out);
String formatData_out = userid+"|"+signdate+"|"+signtime;
if(!lsFormatData_out.contains(formatData_out)){
lsFormatData_out.add(formatData_out);
}
}else{
//人事打卡数据
param.add(userid);
param.add("1");
param.add(signtype);
param.add(signdate);
param.add(signtime);
param.add("EMSyn");
param.add("1");
param.add(addr);
param.add(longitude);
param.add(latitude);
param.add(memo);
param.add(deviceInfo);
lsParam.add(param);
String formatData = userid+"|"+signdate+"|"+signtime;
if(!lsFormatData.contains(formatData)){
lsFormatData.add(formatData);
}
}
}
}
Map<String,List<String>> overtimeMap = Maps.newHashMap();
List<String> overtimeList = Lists.newArrayList();
//刷新报表数据
for(int i=0;lsFormatData!=null&&i<lsFormatData.size();i++){
formatParams = new ArrayList<>();
String[] formatData = Util.splitString(lsFormatData.get(i),"|");
String date_1 = 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);
}
}
for(int i=0;lsFormatData_out!=null&&i<lsFormatData_out.size();i++){
String[] formatData = Util.splitString(lsFormatData_out.get(i),"|");
delParams = new ArrayList<>();
delParams.add(formatData[0]);
delParams.add(formatData[1]);
delParams.add(formatData[2]);
lsDelParams_out.add(delParams);
//使用executeBatchSql删除不了暂时用这种方法
sql = " delete from mobile_sign where isImport='1' and operater ='"+formatData[0]+"' and operate_date = '"+formatData[1]+"' and operate_time='"+formatData[2]+"'";
rs.executeUpdate(sql);
}
//删除本次同步数据
sql = " delete from hrmschedulesign where (signfrom='EMSyn' or signfrom = 'EMSyn_out') and userid =? and signdate = ? and signtime=? ";
bRs.executeBatchSql(sql, lsDelParams);
//插入同步数据
sql = " insert into hrmschedulesign (userid,userType,signtype,signdate,signtime,signfrom,isincom,addr,longitude,latitude,memo,deviceInfo) " +
" values(?,?,?,?,?,?,?,?,?,?,?,?)";
bRs.executeBatchSql(sql, lsParam);
//插入外勤同步数据
sql = " insert into mobile_sign (operater,operate_type,operate_date,operate_time,longitude,latitude,address,remark,isImport) " +
" values(?,?,?,?,?,?,?,?,?)";
bRs.executeBatchSql(sql, lsParam_out);
//格式化报表数据
String resourceid = "";
String kqdate = "";
List<Object> params = null;
for (int i = 0; lsFormatParams != null && i < lsFormatParams.size(); i++) {
params = lsFormatParams.get(i);
resourceid = Util.null2String(params.get(0));
kqdate = Util.null2String(params.get(1));
new KQFormatData().formatKqDate(resourceid, kqdate);
}
//处理加班生成
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);
}
retmap.put("errcode", 0);
retmap.put("errmsg", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(387135,weaver.general.ThreadVarLanguage.getLang())+"");
} catch (Exception e) {
retmap.put("status", 1);
retmap.put("error", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005249,weaver.general.ThreadVarLanguage.getLang())+"" + e.getMessage());
writeLog(e);
}
return retmap;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,173 @@
package com.engine.kq.cmd.schedulesignimport;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQFormatBiz;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.common.StringUtil;
import weaver.conn.BatchRecordSet;
import weaver.conn.RecordSet;
import weaver.file.Prop;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiAttendanceListRequest;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiAttendanceListResponse;
import com.dingtalk.api.response.OapiGettokenResponse;
import weaver.general.Util;
public class SynDingTalkDataCmd extends AbstractCommonCommand<Map<String, Object>> {
private SimpleBizLogger logger;
public SynDingTalkDataCmd(Map<String, Object> params) {
this.params = params;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
try{
String fromDate = Util.null2String(params.get("fromDate"));
String toDate = Util.null2String(params.get("toDate"));
String sql = "";
RecordSet rs = new RecordSet();
BatchRecordSet bRs = new BatchRecordSet();
RecordSet rs1 = new RecordSet();
List<String> lsFormatData = new ArrayList<>();
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = null;
rs.executeUpdate("delete HrmScheduleSign where isimport=1 and signdate>='"+fromDate+"' and signdate<='"+toDate+"'");
Map<String, String> resourceIdMap = new HashMap<String, String>();
rs.executeQuery("select id,workcode from hrmresource where workcode is not null and workcode<>''");
while(rs.next()){
resourceIdMap.put(Util.formatMultiLang(rs.getString("workcode")), StringUtil.vString(rs.getString("id")));
}
String corpId = StringUtil.vString(Prop.getInstance().getPropValue("HrmSynDDInfo", "corpId"));
String corpSecret = StringUtil.vString(Prop.getInstance().getPropValue("HrmSynDDInfo", "corpSecret"));
if(corpId.length()==0||corpSecret.length()==0){
writeLog("获取钉钉考勤数据失败corpId=="+corpId+" corpSecret=="+corpSecret);
retmap.put("status", "-1");
retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005341,weaver.general.ThreadVarLanguage.getLang())+"corpId=="+corpId+" corpSecret=="+corpSecret);
return retmap;
}
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
OapiGettokenRequest request1 = new OapiGettokenRequest();
request1.setAppkey(corpId);
request1.setAppsecret(corpSecret);
request1.setHttpMethod("GET");
OapiGettokenResponse response1 = client.execute(request1);
String accessToken = response1.getAccessToken();
client = new DefaultDingTalkClient("https://oapi.dingtalk.com/attendance/list");
OapiAttendanceListRequest request = new OapiAttendanceListRequest();
request.setWorkDateFrom(fromDate+" 00:00:00");
request.setWorkDateTo(toDate+" 23:59:59");
request.setOffset(0L);
request.setLimit(50L);
List<String> resourceList = new ArrayList<String>();
int ni = 0;
rs.executeQuery("select workcode from hrmresource where workcode is not null and workcode<>''");
while(rs.next()){
ni++;
resourceList.add(Util.formatMultiLang(rs.getString("workcode")));
if(ni%10==0 || ni==rs.getCounts()){
try {
request.setUserIdList(resourceList);
OapiAttendanceListResponse response = client.execute(request, accessToken);
JSONObject jsonData = JSONObject.fromObject(response);
if(!"0".equals(StringUtil.vString(jsonData.get("errcode")))){
writeLog("获取钉钉考勤数据失败:"+jsonData.get("errmsg"));
retmap.put("status", "-1");
retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005341,weaver.general.ThreadVarLanguage.getLang())+""+jsonData.get("errmsg"));
return retmap;
}
Calendar calendar = Calendar.getInstance();
DateFormat formatterDate = new SimpleDateFormat("yyyy-MM-dd");
// 将钉钉上同步过来的打卡数据去掉后面的秒数显示解决统计迟到时长
DateFormat formatterTime = new SimpleDateFormat("HH:mm:00");
JSONArray jsonList = JSONArray.fromObject(jsonData.get("recordresult"));
for(int i=0;i<jsonList.size();i++){
JSONObject data = jsonList.getJSONObject(i);
String locationResult = StringUtil.vString(data.get("locationResult"));
if("NotSigned".equals(locationResult)){
continue;
}
String userId = StringUtil.vString(data.get("userId"));
String oaUserId = StringUtil.vString(resourceIdMap.get(userId));
if("".equals(oaUserId)){
writeLog("通过工号("+userId+"无法在OA找到对应人员请维护人员信息");
continue;
}
JSONObject jsonCheckTime = JSONObject.fromObject(data.get("userCheckTime"));
if("".equals(StringUtil.vString(jsonCheckTime.get("time")))){
writeLog("获取实际打卡时间失败userId="+userId);
continue;
}
long userCheckTime = StringUtil.parseToLong(jsonCheckTime.get("time"));
calendar.setTimeInMillis(userCheckTime);
String signDate = formatterDate.format(calendar.getTime());
String signTime = formatterTime.format(calendar.getTime());
writeLog("处理钉钉考勤时间格式化完成userId==" + oaUserId + ",signDate==" + signDate + ",signTime==" + signTime);
String checkType = StringUtil.vString(data.get("checkType"));
String signType = "";
if("OnDuty".equals(checkType)){
signType = "1";
}else if("OffDuty".equals(checkType)){
signType = "2";
}else{
writeLog("获取考勤类型失败userId="+userId);
continue;
}
writeLog("获取考勤数据oaUserId="+oaUserId+",userId="+userId+",userCheckTime="+userCheckTime+",locationResult="+locationResult+",checkType="+checkType+",signDate="+signDate+",signTime="+signTime);
rs1.executeUpdate("insert into hrmScheduleSign(userid,userType,signType,signDate,signTime,isInCom,isImport,signFrom) values("+oaUserId+",'1','"+signType+"','"+signDate+"','"+signTime+"','1',1,'DingTalk')");
String formatData = oaUserId+"|"+signDate;
if(!lsFormatData.contains(formatData)){
lsFormatData.add(formatData);
}
}
resourceList = new ArrayList<String>();
} catch (Exception e) {
writeLog(this.getClass().getName(),e);
}
}
}
//刷新报表数据
for(int i=0;lsFormatData!=null&&i<lsFormatData.size();i++){
formatParams = new ArrayList<>();
String[] formatData = Util.splitString(lsFormatData.get(i),"|");
formatParams.add(formatData[0]);
formatParams.add(formatData[1]);
lsFormatParams.add(formatParams);
}
new KQFormatBiz().format(lsFormatParams);
} catch (Exception e) {
writeLog("同步钉钉考勤数据:" + e);
retmap.put("status", "-1");
}
return retmap;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public List<BizLogContext> getLogContexts() {
return logger.getBizLogContexts();
}
}

@ -1,8 +1,12 @@
package com.engine.kq.job; package com.engine.kq.job;
import com.engine.kq.biz.KQReportBiz;
import com.engine.kq.biz.KQTimesArrayComInfo;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import weaver.general.TimeUtil; import weaver.general.TimeUtil;
import weaver.general.Util; import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.schedule.BaseCronJob; import weaver.interfaces.schedule.BaseCronJob;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -28,7 +32,9 @@ public class SynClockInTimeJob extends BaseCronJob {
String lastdatetime = lastdate+" "+currenttime; String lastdatetime = lastdate+" "+currenttime;
try{ try{
RecordSet rs1 = new RecordSet(); RecordSet rs1 = new RecordSet();
rs.executeQuery("select * from uf_jbtz where ksrq>=? and jsrq<=?",lastdate,currentdate); //只查询 来源 是 导入的
// rs.executeQuery("select * from uf_jbtz where ly=1 and ksrq>=? and jsrq<=?",lastdate,currentdate);
rs.executeQuery("select * from uf_jbtz where ksrq>=? and jsrq<=?",lastdate,currentdate);
while(rs.next()){ while(rs.next()){
String mainid = Util.null2String(rs.getString("id")); String mainid = Util.null2String(rs.getString("id"));
String userid = Util.null2String(rs.getString("jbr")); String userid = Util.null2String(rs.getString("jbr"));
@ -36,19 +42,39 @@ public class SynClockInTimeJob extends BaseCronJob {
String kssj = Util.null2String(rs.getString("kssj")); String kssj = Util.null2String(rs.getString("kssj"));
String jsrq = Util.null2String(rs.getString("jsrq")); String jsrq = Util.null2String(rs.getString("jsrq"));
String jssj = Util.null2String(rs.getString("jssj")); String jssj = Util.null2String(rs.getString("jssj"));
String gzrq = Util.null2String(rs.getString("gzrq"));
String starttime = ksrq+" "+kssj+":00"; String starttime = ksrq+" "+kssj+":00";
String endtime = jsrq+" "+jssj+":00"; String endtime = jsrq+" "+jssj+":00";
User user = new User(Integer.parseInt(userid));
String beforetwohours_starttime = addDateHour(starttime,-2); String beforetwohours_starttime = addDateHour(starttime,-2);
String aftertwohours_endtime = addDateHour(endtime,2); String aftertwohours_endtime = addDateHour(endtime,2);
String earlystarttime = getEarlyStartTime(beforetwohours_starttime,starttime,ksrq,userid); // String earlystarttime = getEarlyStartTime(beforetwohours_starttime,starttime,ksrq,userid);
String afterendtime = getAfterEndTime(endtime,aftertwohours_endtime,jsrq,userid); // String afterendtime = getAfterEndTime(endtime,aftertwohours_endtime,jsrq,userid);
String earlystarttime = getEarlyStartTime(gzrq,userid,user);
String afterendtime = "";
if(checkIsNightSerial(userid,gzrq)){
afterendtime = getAfterEndTime(gzrq,userid,user);
}else{
afterendtime = getAfterEndTime(jsrq,userid,user);
}
boolean bool = rs1.executeUpdate("update uf_jbtz set zzdksj=?,zwdkrq=? where id=?",earlystarttime,afterendtime,mainid); boolean bool = rs1.executeUpdate("update uf_jbtz set zzdksj=?,zwdkrq=? where id=?",earlystarttime,afterendtime,mainid);
if(bool){ if(bool){
rs.writeLog(userid+ " ------------ "+ kssj +" ------------ "+ jsrq +" ---------- "+ bool); rs.writeLog(userid+ " ------------ "+ kssj +" ------------ "+ jsrq +" ---------- "+ bool);
// 计算有效时长
rs.writeLog("计算有效时长开始");
rs.writeLog("earlystarttime===" + earlystarttime + ",afterendtime===" + afterendtime + ",gzrq===" + gzrq);
// 来源为导入,且最早、最晚打卡时间,归属日期不为空的数据
if (StringUtils.isNoneBlank(earlystarttime, afterendtime, gzrq)) {
UpdateEffectiveDuration.execute(mainid, userid, gzrq, earlystarttime, afterendtime,starttime,endtime);
}
rs.writeLog("计算有效时长结束");
} }
} }
}catch(Exception e){ }catch(Exception e){
@ -58,6 +84,182 @@ public class SynClockInTimeJob extends BaseCronJob {
rs.writeLog("---------- end to syn overtime work card time ----------"); rs.writeLog("---------- end to syn overtime work card time ----------");
} }
public static String getEarlyStartTime(String kqDate,String resourceId,User user){
String result = "";
Map<String, Object> data = null;
Map<String, Object> signStatusInfo = null;
RecordSet rs = new RecordSet();
try {
String sql = " select kqdate, resourceid,groupid,serialid,serialnumber,workbegindate,workbegintime, " +
" workenddate,workendtime,workmins,signindate,signintime,signinid,signoutdate,signouttime,signoutid, " +
" attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins," +
" forgotcheckmins,forgotBeginWorkCheckMins,leaveMins,leaveInfo,evectionMins,outMins,otherinfo " +
" from kq_format_detail b " +
" where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' " +
" order by serialnumber ";
rs.execute(sql);
while (rs.next()) {
String serialid = Util.null2String(rs.getString("serialid"));
String workbegindate = Util.null2String(rs.getString("workbegindate")).trim();
String workbegintime = Util.null2String(rs.getString("workbegintime")).trim();
String signinid = Util.null2String(rs.getString("signinid")).trim();
String signintime = Util.null2String(rs.getString("signintime")).trim();
String beLateMins = Util.null2String(rs.getString("beLateMins")).trim();
String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim();
String absenteeismMins = Util.null2String(rs.getString("absenteeismMins")).trim();
String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim();
int leaveMins = rs.getInt("leaveMins");
String leaveInfo = Util.null2String(rs.getString("leaveInfo"));
int evectionMins = rs.getInt("evectionMins");
int outMins = rs.getInt("outMins");
if (serialid.length() > 0) {
if (workbegintime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate", workbegindate);
signStatusInfo.put("worktime", workbegintime);
signStatusInfo.put("signtime", signintime);
signStatusInfo.put("beLateMins", beLateMins);
signStatusInfo.put("forgotBeginWorkCheckMins", forgotBeginWorkCheckMins);
signStatusInfo.put("graveBeLateMins", graveBeLateMins);
signStatusInfo.put("absenteeismMins", absenteeismMins);
signStatusInfo.put("leaveMins", leaveMins);
signStatusInfo.put("leaveInfo", leaveInfo);
signStatusInfo.put("evectionMins", evectionMins);
signStatusInfo.put("outMins", outMins);
data = new HashMap<>();
data.put("workTime", workbegintime);
data.put("signTime", signintime.length() == 0 ? "" : signintime);
data.put("signStatus", KQReportBiz.getSignStatus(signStatusInfo, user, "on"));
Map<String, Object> signDetailInfo = getSignDetailInfo(signinid);
data.put("addr", Util.null2String(signDetailInfo.get("addr")));
}
} else {
signStatusInfo = new HashMap();
signStatusInfo.put("leaveMins", leaveMins);
signStatusInfo.put("leaveInfo", leaveInfo);
signStatusInfo.put("evectionMins", evectionMins);
signStatusInfo.put("outMins", outMins);
if (signinid.length() > 0) {
data = new HashMap<>();
data.put("signStatus", KQReportBiz.getSignStatus(signStatusInfo, user, ""));
data.put("signTime", signintime.length() == 0 ? "" : signintime);
Map<String, Object> signDetailInfo = getSignDetailInfo(signinid);
data.put("addr", Util.null2String(signDetailInfo.get("addr")));
} else {
data = new HashMap<>();
data.put("signStatus", KQReportBiz.getSignStatus(signStatusInfo, user, ""));
}
}
}
if(data.containsKey("signTime")){
String signTime = data.get("signTime").toString();
if(signTime != null && !"".equals(signTime)){
result = kqDate + " " + signTime;
}
}
}catch (Exception e) {
rs.writeLog(e);
}
return result;
}
public static String getAfterEndTime(String kqDate,String resourceId,User user){
String result = "";
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
Map<String, Object> data = null;
Map<String, Object> signStatusInfo = null;
RecordSet rs = new RecordSet();
try {
String sql = " select kqdate, resourceid,groupid,serialid,serialnumber,workbegindate,workbegintime, " +
" workenddate,workendtime,workmins,signindate,signintime,signinid,signoutdate,signouttime,signoutid, " +
" attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins," +
" forgotcheckmins,forgotBeginWorkCheckMins,leaveMins,leaveInfo,evectionMins,outMins,otherinfo " +
" from kq_format_detail b " +
" where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' " +
" order by serialnumber ";
rs.execute(sql);
while (rs.next()) {
String serialid = Util.null2String(rs.getString("serialid"));
String workenddate = Util.null2String(rs.getString("workenddate")).trim();
String workendtime = Util.null2String(rs.getString("workendtime")).trim();
String signoutid = Util.null2String(rs.getString("signoutid")).trim();
String signouttime = Util.null2String(rs.getString("signouttime")).trim();
String leaveEarlyMins = Util.null2String(rs.getString("leaveEarlyMins")).trim();
String graveLeaveEarlyMins = Util.null2String(rs.getString("graveLeaveEarlyMins")).trim();
String absenteeismMins = Util.null2String(rs.getString("absenteeismMins")).trim();
String forgotCheckMins = Util.null2String(rs.getString("forgotCheckMins")).trim();
int leaveMins = rs.getInt("leaveMins");
String leaveInfo = Util.null2String(rs.getString("leaveInfo"));
int evectionMins = rs.getInt("evectionMins");
int outMins = rs.getInt("outMins");
if (serialid.length() > 0) {
if (workendtime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate", workenddate);
signStatusInfo.put("worktime", kqTimesArrayComInfo.turn48to24Time(workendtime));
signStatusInfo.put("signtime", signouttime);
signStatusInfo.put("leaveEarlyMins", leaveEarlyMins);
signStatusInfo.put("graveLeaveEarlyMins", graveLeaveEarlyMins);
signStatusInfo.put("forgotCheckMins", forgotCheckMins);
signStatusInfo.put("absenteeismMins", absenteeismMins);
signStatusInfo.put("leaveMins", leaveMins);
signStatusInfo.put("leaveInfo", leaveInfo);
signStatusInfo.put("evectionMins", evectionMins);
signStatusInfo.put("outMins", outMins);
data = new HashMap<>();
data.put("workTime", kqTimesArrayComInfo.turn48to24Time(workendtime));
data.put("signTime", signouttime.length() == 0 ? "" : signouttime);
data.put("signStatus", KQReportBiz.getSignStatus(signStatusInfo, user, "off"));
Map<String, Object> signDetailInfo = getSignDetailInfo(signoutid);
data.put("addr", Util.null2String(signDetailInfo.get("addr")));
}
} else {
signStatusInfo = new HashMap();
signStatusInfo.put("leaveMins", leaveMins);
signStatusInfo.put("leaveInfo", leaveInfo);
signStatusInfo.put("evectionMins", evectionMins);
signStatusInfo.put("outMins", outMins);
if (signoutid.length() > 0) {
data = new HashMap<>();
data.put("signStatus", KQReportBiz.getSignStatus(signStatusInfo, user, ""));
data.put("signTime", signouttime.length() == 0 ? "" : signouttime);
Map<String, Object> signDetailInfo = getSignDetailInfo(signoutid);
data.put("addr", Util.null2String(signDetailInfo.get("addr")));
} else {
data = new HashMap<>();
data.put("signStatus", KQReportBiz.getSignStatus(signStatusInfo, user, ""));
}
}
}
if(data.containsKey("signTime")){
String signTime = data.get("signTime").toString();
if(signTime != null && !"".equals(signTime)){
result = kqDate + " " + signTime;
}
}
}catch (Exception e) {
rs.writeLog(e);
}
return result;
}
public static Map<String,Object> getSignDetailInfo(String id){
Map<String,Object> resultMap = new HashMap<>();
RecordSet rs = new RecordSet();
String sql = "";
try{
sql = " select addr from hrmschedulesign where id = ? ";
rs.executeQuery(sql,id);
if(rs.next()){
resultMap.put("addr",Util.null2String(rs.getString("addr")));
}
}catch (Exception e){
rs.writeLog(e);
}
return resultMap;
}
/** /**
* *
* @param beforetwohours_starttime * @param beforetwohours_starttime
@ -88,10 +290,10 @@ public class SynClockInTimeJob extends BaseCronJob {
String signTime = Util.null2String(rs.getString("signTime")); String signTime = Util.null2String(rs.getString("signTime"));
String signdatetime = signDate + " " + signTime; String signdatetime = signDate + " " + signTime;
boolean bool = belongCalendar(signdatetime, beforetwohours_starttime, starttime); // boolean bool = belongCalendar(signdatetime, beforetwohours_starttime, starttime);
if (bool) { // if (bool) {
list.add(format.parse(signdatetime)); list.add(format.parse(signdatetime));
} // }
} }
if(list.size()>0){ if(list.size()>0){
if(list.size()>1){ if(list.size()>1){
@ -127,7 +329,7 @@ public class SynClockInTimeJob extends BaseCronJob {
" and (signDate is not null and signDate>='"+ jsrq +"') " + " and (signDate is not null and signDate>='"+ jsrq +"') " +
" and (signDate is not null and signDate<='"+ jsrq +"') " + " and (signDate is not null and signDate<='"+ jsrq +"') " +
" and (loginId is not null and loginId<>'') " + " and (loginId is not null and loginId<>'') " +
" and signType=1 "+ " and signType=2 "+
" and (b.status = 0 or b.status = 1 or b.status = 2 or b.status = 3)" + " and (b.status = 0 or b.status = 1 or b.status = 2 or b.status = 3)" +
" and userId in ("+ userid +")" + " and userId in ("+ userid +")" +
" order by signDate,signTime"); " order by signDate,signTime");
@ -137,10 +339,10 @@ public class SynClockInTimeJob extends BaseCronJob {
String signTime = Util.null2String(rs.getString("signTime")); String signTime = Util.null2String(rs.getString("signTime"));
String signdatetime = signDate + " " + signTime; String signdatetime = signDate + " " + signTime;
boolean bool = belongCalendar(signdatetime, endtime, aftertwohours_endtime); // boolean bool = belongCalendar(signdatetime, endtime, aftertwohours_endtime);
if (bool) { // if (bool) {
list.add(format.parse(signdatetime)); list.add(format.parse(signdatetime));
} // }
} }
if(list.size()>0){ if(list.size()>0){
if(list.size()>1){ if(list.size()>1){
@ -167,17 +369,23 @@ public class SynClockInTimeJob extends BaseCronJob {
boolean b = false; boolean b = false;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try { try {
Date nowTime = format.parse(nowString); if(nowString.equals(beginString)){
Calendar date = Calendar.getInstance(); b = true;
date.setTime(nowTime); }else if(nowString.equals(endString)){
Date beginTime = format.parse(beginString);
Calendar begin = Calendar.getInstance();
begin.setTime(beginTime);
Date endTime = format.parse(endString);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.after(begin) && date.before(end)) {//在时间段内
b = true; b = true;
}else {
Date nowTime = format.parse(nowString);
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Date beginTime = format.parse(beginString);
Calendar begin = Calendar.getInstance();
begin.setTime(beginTime);
Date endTime = format.parse(endString);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.after(begin) && date.before(end)) {//在时间段内
b = true;
}
} }
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
@ -237,4 +445,24 @@ public class SynClockInTimeJob extends BaseCronJob {
return ""; return "";
} }
/**
*
* @param userid
* @param date
* @return
*/
public static boolean checkIsNightSerial(String userid,String date){
boolean bool = false;
RecordSet rs = new RecordSet();
String night_serialids = rs.getPropValue("nbjh_ygdjblc","night_serialids");
rs.executeQuery("select * from kq_format_detail where resourceid = ? and kqdate = ? ",userid,date);
while(rs.next()){
String serialid = Util.null2String(rs.getString("serialid"));
if((","+night_serialids+",").contains((","+serialid+","))){
bool = true;
}
}
return bool;
}
} }

@ -0,0 +1,387 @@
package com.engine.kq.job;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.engine.kq.biz.KQShiftManagementComInfo;
import com.engine.kq.biz.KQShiftRestTimeSectionComInfo;
import com.engine.kq.biz.KQWorkTime;
import com.engine.kq.entity.WorkTimeEntity;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
/**
* @author:dxfeng
* @createTime: 2024/03/29
* @version: 1.0
*/
public class UpdateEffectiveDuration {
/**
*
*/
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/**
*
* 1==
* 2=
* 1
* 2
* 3=-
*
* @param mainId
* @param userId
* @param gzrq
* @param earlyStartTime
* @param afterEndTime
* @param startTime
* @param endTime
*/
public static void execute(String mainId, String userId, String gzrq, String earlyStartTime, String afterEndTime, String startTime, String endTime) {
RecordSet recordSet = new RecordSet();
try {
LocalDateTime startSignTime = LocalDateTime.parse(earlyStartTime, DATE_TIME_FORMATTER);
LocalDateTime endSignTime = LocalDateTime.parse(afterEndTime, DATE_TIME_FORMATTER);
LocalDateTime startWorkTime = LocalDateTime.parse(startTime, DATE_TIME_FORMATTER);
LocalDateTime endWorkTime = LocalDateTime.parse(endTime, DATE_TIME_FORMATTER);
// 最早、最晚打卡时间,与开始时间、结束时间,是否存在交集
boolean hasIntersection = startSignTime.isBefore(endWorkTime) && endSignTime.isAfter(startWorkTime);
recordSet.executeQuery("select gjsc,ly from uf_jbtz where id = ?", mainId);
double gjscHours = 0.0;
String ly = "";
if (recordSet.next()) {
gjscHours = recordSet.getDouble("gjsc");
ly = recordSet.getString("ly");
}
if (gjscHours < 0) {
throw new Exception("mainId===" + mainId + ",共计时长小于0");
}
// 只处理来源为导入的数据
if ("1".equals(ly) && hasIntersection) {
int totalMinutes = 0;
if (startSignTime.isAfter(startWorkTime)) {
int startDifference = (int) (startWorkTime.until(startSignTime, ChronoUnit.MINUTES));
recordSet.execute("mainId=" + mainId + ",userId=" + userId + ",gzrq=" + gzrq + ",startDifference=" + startDifference);
totalMinutes += startDifference;
}
if (endSignTime.isBefore(endWorkTime)) {
int endDifference = (int) (endSignTime.until(endWorkTime, ChronoUnit.MINUTES));
recordSet.execute("mainId=" + mainId + ",userId=" + userId + ",gzrq=" + gzrq + ",endDifference=" + endDifference);
totalMinutes += endDifference;
}
// 总计相差时间,按照半小时,向上取整
double totalHours = (double) totalMinutes / 60;
double timeDifference = gjscHours - totalHours;
// 将小时数按照0.5小时的单位向下取整
double roundedHours = (int) Math.floor(timeDifference / 0.5) * 0.5;
recordSet.writeLog("userId==" + userId + ",totalMinutes===" + totalMinutes + ",gjscHours===" + gjscHours + ",totalHours==" + totalHours + ",roundedHours==" + roundedHours);
recordSet.executeUpdate("update uf_jbtz set yxsc=? where id=? ", roundedHours, mainId);
} else {
// 最早、最晚打卡时间,与开始时间、结束时间没有交集=》有效时长=共计时长
recordSet.executeUpdate("update uf_jbtz set yxsc=? where id=? ", gjscHours, mainId);
}
} catch (Exception e) {
recordSet.writeLog(e);
}
}
/**
*
* <p/>
* <p></p>
*
* @param mainId ID
* @param userId ID
* @param gzrq
* @param earlyStartTime
* @param afterEndTime
*/
public static void execute1(String mainId, String userId, String gzrq, String earlyStartTime, String afterEndTime, String startTime, String endTime) {
RecordSet recordSet = new RecordSet();
try {
KQWorkTime kqWorkTime = new KQWorkTime();
WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(userId, gzrq);
String serialId = workTimeEntity.getSerialId();
recordSet.writeLog("serialId===" + serialId);
if (StringUtils.isBlank(serialId) || "-1".equals(serialId)) {
kqWorkTime.setIsFormat(true);
workTimeEntity = kqWorkTime.getWorkTime(userId, gzrq);
serialId = workTimeEntity.getSerialId();
}
recordSet.writeLog("userId==" + userId + ",serialId===" + JSON.toJSONString(serialId) + ",workTimeEntity===" + JSON.toJSONString(workTimeEntity));
// 转换所有的工作时间
List<Map<String, String>> workTimeList = new ArrayList<>();
Map<String, String> workMap = new HashMap<>();
workMap.put("startTimes", startTime);
workMap.put("endTimes", endTime);
workTimeList.add(workMap);
recordSet.writeLog("userId==" + userId + ",workTimeList===" + JSON.toJSONString(workTimeList));
// 转换所有的休息时间
List<Map<String, String>> restTimeList = new ArrayList<>();
KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo();
String isRestTimeOpen = kqShiftManagementComInfo.getIsresttimeopen(serialId);
// 排除休息时间是否开启 1表示开启
recordSet.writeLog("isRestTimeOpen===" + isRestTimeOpen);
if ("1".equals(isRestTimeOpen)) {
List<Object> restSectionTimes = new KQShiftRestTimeSectionComInfo().getRestSectionTimes(serialId);
recordSet.writeLog("userId==" + userId + ",restSectionTimes===" + JSON.toJSONString(restSectionTimes));
if (CollectionUtils.isNotEmpty(restSectionTimes)) {
//convertDateTime(gzrq, restSectionTimes, restTimeList);
convertDateTime2(gzrq, restSectionTimes, restTimeList);
recordSet.writeLog("userId==" + userId + ",restTimeList===" + JSON.toJSONString(restTimeList));
}
}
// 所有的有效时间区间
recordSet.writeLog("userId==" + userId + ",earlyStartTime===" + earlyStartTime + ",afterEndTime===" + afterEndTime);
List<String> effectiveTime = getEffectiveTime(earlyStartTime, afterEndTime, startTime, endTime, restTimeList);
recordSet.writeLog("userId==" + userId + ",effectiveTime===" + JSON.toJSONString(effectiveTime));
// 有效区间总计分钟数
long totalMinutes = effectiveTime.stream()
.mapToInt(interval -> {
String[] parts = interval.split(",");
LocalDateTime start = LocalDateTime.parse(parts[0], DATE_TIME_FORMATTER);
LocalDateTime end = LocalDateTime.parse(parts[1], DATE_TIME_FORMATTER);
return (int) (start.until(end, ChronoUnit.MINUTES));
})
.sum();
double totalHours = (double) totalMinutes / 60;
// 将小时数按照0.5小时的单位向下取整
double roundedHours = (int) Math.floor(totalHours / 0.5) * 0.5;
recordSet.writeLog("userId==" + userId + ",totalMinutes===" + totalMinutes + ",totalHours==" + totalHours + ",roundedHours==" + roundedHours);
// 更新当前数据的有效时长
recordSet.executeUpdate("update uf_jbtz set yxsc=? where id=? ", roundedHours, mainId);
} catch (Exception e) {
recordSet.writeLog(e);
}
}
/**
*
*/
private static List<String> getEffectiveTime(String earlyStartTime, String afterEndTime, String startTime, String endTime, List<Map<String, String>> restTimeList) {
// 打卡时间区间,去除所有的休息时间
List<String> effectiveTimeList = new ArrayList<>();
LocalDateTime startSignTime = LocalDateTime.parse(earlyStartTime, DATE_TIME_FORMATTER);
LocalDateTime endSignTime = LocalDateTime.parse(afterEndTime, DATE_TIME_FORMATTER);
LocalDateTime startWorkTime = LocalDateTime.parse(startTime, DATE_TIME_FORMATTER);
LocalDateTime endWorkTime = LocalDateTime.parse(endTime, DATE_TIME_FORMATTER);
// 计算交集
LocalDateTime intersectionStart = startSignTime.isAfter(startWorkTime) ? startSignTime : startWorkTime;
LocalDateTime intersectionEnd = endSignTime.isBefore(endWorkTime) ? endSignTime : endWorkTime;
List<TimeInterval> restIntervals = new ArrayList<>();
for (Map<String, String> restTimeMap : restTimeList) {
restIntervals.add(new TimeInterval(
LocalDateTime.parse(restTimeMap.get("startTimes"), DATE_TIME_FORMATTER),
LocalDateTime.parse(restTimeMap.get("endTimes"), DATE_TIME_FORMATTER)
));
}
// 休息时间区间排序
restIntervals.sort(Comparator.comparing(TimeInterval::getStart));
// 实际的工作开始时间、结束时间
List<TimeInterval> workIntervals = calculateWorkIntervals(intersectionStart, intersectionEnd, restIntervals);
//new BaseBean().writeLog("workIntervals===" + JSON.toJSONString(workIntervals));
for (TimeInterval workInterval : workIntervals) {
effectiveTimeList.add(workInterval.getStart().format(DATE_TIME_FORMATTER) + "," + workInterval.getEnd().format(DATE_TIME_FORMATTER));
}
long totalMinutes = calculateTotalWorkMinutes(workIntervals);
//new BaseBean().writeLog("totalMinutes==="+totalMinutes);
//if (intersectionStart.isBefore(intersectionEnd)) {
// // 去除休息时间
// for (Map<String, String> restTimeMap : restTimeList) {
// LocalDateTime startRestTime = LocalDateTime.parse(restTimeMap.get("startTimes"), DATE_TIME_FORMATTER);
// LocalDateTime endRestTime = LocalDateTime.parse(restTimeMap.get("endTimes"), DATE_TIME_FORMATTER);
//
// if (!intersectionEnd.isBefore(startRestTime) && !intersectionStart.isAfter(endRestTime)) {
// if (intersectionStart.isBefore(startRestTime)) {
// // 交集在休息时间之前
// intersectionEnd = intersectionEnd.isBefore(startRestTime) ? intersectionEnd : startRestTime;
// } else if (intersectionEnd.isAfter(endRestTime)) {
// // 交集在休息时间之后
// intersectionStart = intersectionStart.isAfter(endRestTime) ? intersectionStart : endRestTime;
// } else {
// // 休息时间在交集中间
// intersectionStart = startRestTime;
// intersectionEnd = endRestTime;
// }
// }
// }
// effectiveTimeList.add(intersectionStart.format(DATE_TIME_FORMATTER) + "," + intersectionEnd.format(DATE_TIME_FORMATTER));
//}
return effectiveTimeList;
}
/**
*
*
* @param gzrq
* @param sectionTimes
* @param timeList
*/
private static void convertDateTime(String gzrq, List<Object> sectionTimes, List<Map<String, String>> timeList) {
String currentDate = gzrq;
String preTime = "";
for (Object sectionTime : sectionTimes) {
List<Map<String, String>> sectionTime1 = (List) sectionTime;
if (sectionTime1.size() != 2) {
break;
}
// 获取当前的打卡时间
Map<String, String> startMap = sectionTime1.get(0);
String startTimes = startMap.get("times");
Map<String, String> map = new HashMap<>();
currentDate = getDateStr(currentDate, preTime, startTimes);
map.put("startTimes", currentDate + " " + startTimes + ":00");
Map<String, String> endMap = sectionTime1.get(1);
String endTimes = endMap.get("times");
currentDate = getDateStr(currentDate, startTimes, endTimes);
map.put("endTimes", currentDate + " " + endTimes + ":00");
preTime = endTimes;
timeList.add(map);
}
}
private static void convertDateTime2(String gzrq, List<Object> sectionTimes, List<Map<String, String>> timeList) {
String currentDate = gzrq;
String preTime = "";
for (Object sectionTime : sectionTimes) {
List<Map<String, String>> sectionTime1 = (List) sectionTime;
if (sectionTime1.size() != 2) {
break;
}
// 获取当前的打卡时间
Map<String, String> startMap = sectionTime1.get(0);
String startTimes = startMap.get("times");
String startAcross = startMap.get("across");
Map<String, String> map = new HashMap<>();
//currentDate = getDateStr(currentDate, preTime, startTimes);
if ("1".equals(startAcross)) {
map.put("startTimes", DateUtil.addDate(currentDate, 1) + " " + startTimes + ":00");
} else {
map.put("startTimes", currentDate + " " + startTimes + ":00");
}
Map<String, String> endMap = sectionTime1.get(1);
String endTimes = endMap.get("times");
String endAcross = endMap.get("across");
//currentDate = getDateStr(currentDate, startTimes, endTimes);
if ("1".equals(endAcross)) {
map.put("endTimes", DateUtil.addDate(currentDate, 1) + " " + endTimes + ":00");
} else {
map.put("endTimes", currentDate + " " + endTimes + ":00");
}
preTime = endTimes;
timeList.add(map);
}
}
/**
*
*
* @param currentDate
* @param preTime
* @param currentTime
* @return
*/
private static String getDateStr(String currentDate, String preTime, String currentTime) {
// 前一个时间为空,返回当前日期+当前时间
if (StringUtils.isBlank(preTime)) {
return currentDate;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime localPreTime = LocalTime.parse(preTime, formatter);
LocalTime localCurrentTime = LocalTime.parse(currentTime, formatter);
if (localPreTime.isAfter(localCurrentTime)) {
return DateUtil.addDate(currentDate, 1);
} else {
return currentDate;
}
}
public static List<TimeInterval> calculateWorkIntervals(LocalDateTime startWork, LocalDateTime endWork,
List<TimeInterval> restIntervals) {
List<TimeInterval> workIntervals = new ArrayList<>();
LocalDateTime currentStart = startWork;
for (TimeInterval restInterval : restIntervals) {
LocalDateTime restStart = restInterval.getStart();
LocalDateTime restEnd = restInterval.getEnd();
// 如果休息时间与工作时间重合,则调整工作时间段
if (currentStart.isBefore(restEnd) && endWork.isAfter(restStart)) {
if (currentStart.isBefore(restStart)) {
workIntervals.add(new TimeInterval(currentStart, restStart));
}
currentStart = restEnd;
}
}
// 添加剩余的工作时间段
if (currentStart.isBefore(endWork)) {
workIntervals.add(new TimeInterval(currentStart, endWork));
}
return workIntervals;
}
public static long calculateTotalWorkMinutes(List<TimeInterval> workIntervals) {
long totalMinutes = 0;
for (TimeInterval interval : workIntervals) {
totalMinutes += Duration.between(interval.getStart(), interval.getEnd()).toMinutes();
}
return totalMinutes;
}
static class TimeInterval {
private LocalDateTime start;
private LocalDateTime end;
public TimeInterval(LocalDateTime start, LocalDateTime end) {
this.start = start;
this.end = end;
}
public LocalDateTime getStart() {
return start;
}
public LocalDateTime getEnd() {
return end;
}
}
}

@ -0,0 +1,429 @@
package weaver.interfaces.nbjh.action;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.*;
import java.util.*;
public class UpdateResourceAction implements Action {
@Override
public String execute(RequestInfo requestInfo) {
User user = requestInfo.getRequestManager().getUser();
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
Property[] properties = mainTableInfo.getProperty();
// 流程主表数据
Map<String, String> mainData = new HashMap<>();
for (Property property : properties) {
mainData.put(property.getName(), property.getValue());
}
// 获取身份证号
String sfzh = mainData.get("sfzh");
// 姓名
String xm = mainData.get("xm");
RecordSet rs = new RecordSet();
// 根据身份证号/姓名获取获取员工ID
String resourceId = "";
if (StringUtils.isNotBlank(sfzh)) {
rs.executeQuery("select id from hrmresource where certificatenum = ?", sfzh);
if (rs.next()) {
resourceId = rs.getString("id");
}
if (StringUtils.isBlank(resourceId)) {
requestInfo.getRequestManager().setMessagecontent("当前身份证号未匹配到员工信息,请确认信息填写是否正确");
return FAILURE_AND_CONTINUE;
}
} else {
rs.executeQuery("select id from hrmresource where lastname = ?", xm);
if (rs.next()) {
resourceId = rs.getString("id");
}
if (StringUtils.isBlank(resourceId)) {
requestInfo.getRequestManager().setMessagecontent("当前姓名未匹配到人员信息,请确认信息填写是否正确");
return FAILURE_AND_CONTINUE;
}
}
BaseBean baseBean = new BaseBean();
baseBean.writeLog("UpdateResourceAction,开始更新主表照片字段人员ID===" + resourceId);
// 更新主表照片字段
String zp1 = mainData.get("zp1");
baseBean.writeLog("zp1====" + zp1);
String imageFileId = null;
if (StringUtils.isNotBlank(zp1)) {
String docId = zp1.split(",")[0];
baseBean.writeLog("docId====" + docId);
rs.executeQuery("select imagefileid from docimagefile where docid = ? ", docId);
if (rs.next()) {
imageFileId = rs.getString("imagefileid");
}
}
baseBean.writeLog("imageFileId====" + imageFileId);
if (StringUtils.isNotBlank(imageFileId)) {
rs.executeUpdate("update hrmresource set resourceimageid = ? where id = ? ", imageFileId, resourceId);
} else {
// 更新照片为null
rs.executeUpdate("update hrmresource set resourceimageid = null where id = ? ", resourceId);
}
baseBean.writeLog("UpdateResourceAction,更新主表照片字段结束");
String resourceimageid;
rs.executeQuery("select resourceimageid from hrmresource where id = ? ", resourceId);
if (rs.next()) {
resourceimageid = rs.getString("resourceimageid");
baseBean.writeLog("resourceimageid====" + resourceimageid);
} else {
baseBean.writeLog("resourceimageid,未查询到数据");
}
DetailTableInfo detailTableInfo = requestInfo.getDetailTableInfo();
// 学习履历
List<Map<String, String>> eduDetailDataList = getDetailDataList(detailTableInfo, 0);
// 工作履历
List<Map<String, String>> workDetailDataList = getDetailDataList(detailTableInfo, 1);
// 家庭主要成员
List<Map<String, String>> familyDetailDataList = getDetailDataList(detailTableInfo, 2);
// 插入明细表数据,插入前先删除原有数据
String formModeId = getModeIdByTableName("uf_xxll");
if (StringUtils.isNotBlank(formModeId)) {
rs.executeUpdate("delete from uf_xxll where xm = ? ", resourceId);
for (Map<String, String> detailMap : eduDetailDataList) {
Map<String, String> dataMap = new HashMap<>();
String uuid = UUID.randomUUID().toString();
dataMap.put("modeuuid", uuid);
dataMap.put("formmodeid", formModeId);
buildModeInsertFields(dataMap, user.getUID());
dataMap.put("xm", resourceId);
dataMap.put("xx", detailMap.get("xx"));
dataMap.put("zy", detailMap.get("zy"));
dataMap.put("ksrq", detailMap.get("ksrq"));
dataMap.put("jsrq", detailMap.get("jsrq"));
dataMap.put("bz", detailMap.get("bz"));
insertDetailData(dataMap, "uf_xxll");
refreshRight(uuid, "uf_xxll", formModeId, user.getUID());
}
}
formModeId = getModeIdByTableName("uf_gzll");
if (StringUtils.isNotBlank(formModeId)) {
rs.executeUpdate("delete from uf_gzll where xm = ? ", resourceId);
for (Map<String, String> detailMap : workDetailDataList) {
Map<String, String> dataMap = new HashMap<>();
String uuid = UUID.randomUUID().toString();
dataMap.put("modeuuid", uuid);
dataMap.put("formmodeid", formModeId);
buildModeInsertFields(dataMap, user.getUID());
dataMap.put("xm", resourceId);
dataMap.put("gzdw", detailMap.get("gzdw"));
dataMap.put("ksrq", detailMap.get("ksrq"));
dataMap.put("jsrq", detailMap.get("jsrq"));
dataMap.put("zw", detailMap.get("zw"));
dataMap.put("lzyy", detailMap.get("lzyy"));
dataMap.put("zmr", detailMap.get("zmr"));
insertDetailData(dataMap, "uf_gzll");
refreshRight(uuid, "uf_gzll", formModeId, user.getUID());
}
}
formModeId = getModeIdByTableName("uf_jtzycy");
if (StringUtils.isNotBlank(formModeId)) {
rs.executeUpdate("delete from uf_jtzycy where ygxm = ? ", resourceId);
for (Map<String, String> detailMap : familyDetailDataList) {
Map<String, String> dataMap = new HashMap<>();
String uuid = UUID.randomUUID().toString();
dataMap.put("modeuuid", uuid);
dataMap.put("formmodeid", formModeId);
buildModeInsertFields(dataMap, user.getUID());
dataMap.put("ygxm", resourceId);
dataMap.put("xm", detailMap.get("xm"));
dataMap.put("nl", detailMap.get("nl"));
dataMap.put("ybrgx", detailMap.get("ybrgx"));
dataMap.put("zy", detailMap.get("zy"));
dataMap.put("zz", detailMap.get("zz"));
insertDetailData(dataMap, "uf_jtzycy");
refreshRight(uuid, "uf_jtzycy", formModeId, user.getUID());
}
}
return SUCCESS;
}
/**
*
*
* @param mainData
* @return
*/
private Map<String, String> buildResourceMap(Map<String, String> mainData) {
Map<String, String> resourceMap = new HashMap<>();
// 申请职位
resourceMap.put("jobtitle", mainData.get("sqzw"));
// 姓名
resourceMap.put("lastname", mainData.get("xm"));
// 性别
resourceMap.put("sex", mainData.get("xb"));
// 出生日期
resourceMap.put("birthday", mainData.get("csrq"));
// 身份证号
resourceMap.put("certificatenum", mainData.get("sfzh"));
// 民族
resourceMap.put("folk", mainData.get("mz"));
// 籍贯
resourceMap.put("nativeplace", mainData.get("jg"));
// 联系电话
resourceMap.put("mobile", mainData.get("lxdh"));
// 政治面貌
resourceMap.put("policy", mainData.get("zzmm"));
// 参加工作时间
resourceMap.put("workstartdate", mainData.get("cjgzsj"));
// 部门
String bm = mainData.get("bm");
resourceMap.put("departmentid", bm);
// 分部
String subcompanyid1 = new DepartmentComInfo().getSubcompanyid1(bm);
resourceMap.put("subcompanyid1", subcompanyid1);
// 入职日期
resourceMap.put("companystartdate", mainData.get("rzrq"));
// 照片
resourceMap.put("resourceimageid", mainData.get("zp"));
// 学历
resourceMap.put("educationlevel", mainData.get("xl"));
// 婚姻状况
resourceMap.put("maritalstatus", mainData.get("hyzk"));
// 办公地点
resourceMap.put("workroom", mainData.get("bgdd"));
// 状态
resourceMap.put("status", mainData.get("zt"));
// 试用期结束日期
resourceMap.put("probationenddate", mainData.get("syqjsrq"));
return resourceMap;
}
private Map<String, Map<String, String>> buildCustomMap(Map<String, String> mainData, String status) {
Map<String, Map<String, String>> dataMap = new HashMap<>();
// 1
Map<String, String> custom1Map = new HashMap<>();
// 3
Map<String, String> custom3Map = new HashMap<>();
// 毕业院校
custom1Map.put("field7", mainData.get("byyx"));
// 专业
custom1Map.put("field8", mainData.get("zy"));
// 户口类型
custom1Map.put("field9", mainData.get("hklx"));
// 职称
custom1Map.put("field10", mainData.get("zc"));
// 特长
custom1Map.put("field11", mainData.get("tc"));
// 出生地
custom1Map.put("field17", mainData.get("csd"));
// 现户口所在地
custom1Map.put("field13", mainData.get("xhkszd"));
// 现联系地址
custom1Map.put("field15", mainData.get("xlxdz"));
// 试用期限
custom3Map.put("field20", mainData.get("syqx"));
// 血型
custom1Map.put("field22", mainData.get("xx"));
// 准驾车险
custom1Map.put("field23", mainData.get("zjcx"));
// 紧急联系人电话
custom1Map.put("field16", mainData.get("jjlxrdh"));
// 身高
custom1Map.put("field14", mainData.get("sg"));
if ("0".equals(status)) {
// 试用职等档次
custom3Map.put("field21", mainData.get("syzddc"));
} else if ("1".equals(status)) {
// 正式职等档次
custom3Map.put("field21", mainData.get("zszddc"));
}
dataMap.put("1", custom1Map);
dataMap.put("3", custom3Map);
return dataMap;
}
/**
*
*
* @param detailTableInfo
* @param detailIndex
* @return
*/
private List<Map<String, String>> getDetailDataList(DetailTableInfo detailTableInfo, int detailIndex) {
List<Map<String, String>> detailDataList = new ArrayList<>();
DetailTable detailTable = detailTableInfo.getDetailTable(detailIndex);
Row[] rows = detailTable.getRow();
for (Row row : rows) {
Map<String, String> detailDataMap = new HashMap<>();
Cell[] cells = row.getCell();
for (Cell cell : cells) {
detailDataMap.put(cell.getName(), cell.getValue());
}
detailDataList.add(detailDataMap);
}
return detailDataList;
}
/**
*
*
* @param dataMap
*/
public static void updateHrmDataById(Map<String, String> dataMap, String id) {
List<String> fieldList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
dataMap.forEach((key, value) -> {
fieldList.add(key + " = ? ");
if (StringUtils.isBlank(value)) {
dataList.add(null);
} else {
dataList.add(value);
}
});
dataList.add(id);
String updateSql = "update hrmresource set " + StringUtils.join(fieldList, ",") + " where id = ? ";
RecordSet rs = new RecordSet();
rs.executeUpdate(updateSql, dataList);
if (StringUtils.isNotBlank(rs.getExceptionMsg())) {
throw new RuntimeException(rs.getExceptionMsg());
}
}
/**
*
*
* @param dataMap
* @param id
* @param scopeId
*/
public static void updateCusDataById(Map<String, String> dataMap, String id, String scopeId) {
List<String> fieldList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
dataMap.forEach((key, value) -> {
fieldList.add(key + " = ? ");
// 兼容SqlServer数据库Text字段类型不为null
if (StringUtils.isBlank(value) && !"field21".equals(key)) {
dataList.add(null);
} else {
dataList.add(value);
}
});
dataList.add(id);
dataList.add(scopeId);
String updateSql = "update cus_fielddata set " + StringUtils.join(fieldList, ",") + " where id = ? and scope ='HrmCustomFieldByInfoType' and scopeid = ? ";
RecordSet rs = new RecordSet();
rs.executeUpdate(updateSql, dataList);
if (StringUtils.isNotBlank(rs.getExceptionMsg())) {
throw new RuntimeException(rs.getExceptionMsg());
}
}
/**
*
*
* @param dataMap
* @param tableName
*/
public static void insertDetailData(Map<String, String> dataMap, String tableName) {
List<String> fieldList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
List<String> paramList = new ArrayList<>();
dataMap.forEach((key, value) -> {
if (StringUtils.isNotBlank(value)) {
fieldList.add(key);
dataList.add(value);
paramList.add("?");
}
});
String insertSql = " insert into " + tableName + "(" + StringUtils.join(fieldList, ",") + ") values (" + StringUtils.join(paramList, ",") + ")";
RecordSet rs = new RecordSet();
rs.executeUpdate(insertSql, dataList);
if (StringUtils.isNotBlank(rs.getExceptionMsg())) {
throw new RuntimeException(rs.getExceptionMsg());
}
}
/**
*
*
* @param uuid
* @param modeTable
* @param formModeId
*/
private String refreshRight(String uuid, String modeTable, String formModeId, int creator) {
RecordSet rs = new RecordSet();
rs.executeQuery("select id from " + modeTable + " where modeuuid='" + uuid + "'");
if (rs.next()) {
//建模数据的id
int bid = Util.getIntValue(rs.getString("id"));
ModeRightInfo modeRightInfo = new ModeRightInfo();
modeRightInfo.setNewRight(true);
//新建的时候添加共享
modeRightInfo.editModeDataShare(creator, Integer.parseInt(formModeId), bid);
return String.valueOf(bid);
}
return "";
}
/**
*
*
* @param mainDataMap
*/
private void buildModeInsertFields(Map<String, String> mainDataMap, int userId) {
String dateTime = DateUtil.getFullDate();
String[] dateSplit = dateTime.split(" ");
mainDataMap.put("modedatacreater", String.valueOf(userId));
mainDataMap.put("modedatacreatedate", dateSplit[0]);
mainDataMap.put("modedatacreatetime", dateSplit[1]);
mainDataMap.put("modedatacreatertype", "0");
}
/**
* ,ID
*
* @param modeTable
* @return
*/
private String getModeIdByTableName(String modeTable) {
String formModeId = "-1";
RecordSet rs = new RecordSet();
rs.executeQuery("select id from modeinfo where formid =( select id from workflow_bill where tablename = ? ) order by id", modeTable);
if (rs.next()) {
formModeId = rs.getString("id");
}
return formModeId;
}
}
Loading…
Cancel
Save