#weaver-hansang-1# svn原始文件

main
shilei 2 years ago
parent a3b41d6e1e
commit bcadd75a08

@ -0,0 +1,979 @@
package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloudstore.dev.api.util.Util_DataMap;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.cmd.attendanceButton.ButtonStatusEnum;
import com.engine.kq.entity.KQShiftRuleEntity;
import com.engine.kq.entity.TimeScopeEntity;
import com.engine.kq.entity.TimeSignScopeEntity;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.enums.FlowReportTypeEnum;
import com.engine.kq.log.KQLog;
import com.engine.kq.util.UtilKQ;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.BatchRecordSet;
import weaver.conn.RecordSet;
import weaver.file.Prop;
import weaver.general.BaseBean;
import weaver.general.InitServer;
import weaver.general.Util;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*/
public class KQFormatData extends BaseBean {
private String today = DateUtil.getCurrentDate();
private KQLog kqLog = new KQLog();
private boolean writeLog = false;
private LinkedHashMap<String,Object> logInfo = new LinkedHashMap<>();
/***
*
* @param userId
* @param kqDate
* @return
*/
public Map<String, Object> formatKqDate(String userId, String kqDate) {
List<List<Object>> lsParam = new ArrayList<>();
//非工作日处理
List<Object> nonlsParam = null;
Map<String, Object> resultMap = new HashMap<>();
BatchRecordSet bRs = new BatchRecordSet();
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
RecordSet rs = new RecordSet();
String sql = "";
try {
kqLog.info("formatKqDate in userId=" + userId + "kqDate==" + kqDate);
if (DateUtil.timeInterval(kqDate, today) < 0) {//今天之后的无需处理
kqLog.info("今天之后的无需处理的数据resourceid=="+userId+"kqdate=="+kqDate+"today=="+today);
return resultMap;
}
String uuid = UUID.randomUUID().toString();
KQFormatFreeData kqFormatFreeData = new KQFormatFreeData();
KQWorkTime kqWorkTime = new KQWorkTime();
kqWorkTime.setIsFormat(true);
String kqDateNext = DateUtil.addDate(kqDate, 1);
KQFlowDataBiz kqFlowDataBiz = new KQFlowDataBiz.FlowDataParamBuilder().resourceidParam(userId).fromDateParam(kqDate).toDateParam(kqDateNext).build();
Map<String, Object> workFlowInfo = new HashMap<>();//userid|date--工作流程
kqFlowDataBiz.getAllFlowData(workFlowInfo,false);
WorkTimeEntity workTime = kqWorkTime.getWorkTime(userId, kqDate);
kqLog.info("userId:"+userId+":kqDate:"+kqDate+":formatKqDate workTime=" + JSONObject.toJSONString(workTime)+"::uuid::"+uuid);
kqLog.info("userId:"+userId+":kqDate:"+kqDate+":formatKqDate workFlowInfo=" + JSONObject.toJSONString(workFlowInfo)+"::uuid::"+uuid);
if(this.writeLog) {
logInfo.put("userId",userId);
logInfo.put("kqDate",kqDate);
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(16253,weaver.general.ThreadVarLanguage.getLang())+"",workTime);
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(126871,weaver.general.ThreadVarLanguage.getLang())+"",workFlowInfo);
}
new KQFormatBiz().delFormatData(userId, kqDate);
String excludecount = Util.null2String(kqGroupComInfo.getExcludecount(workTime.getGroupId()));//是否参与考勤报表统计
if (workTime.getIsExclude()) {//无需考勤人员没有异常状态
if(!excludecount.equals("1")){
kqLog.info("无需考勤人员没有异常状态 workTime.getIsExclude()="+workTime.getIsExclude()+"excludecount=="+excludecount);
return resultMap;
}
}
if( Util.null2String(workTime.getGroupId()).length()==0){
//没有考勤组不需格式化
return resultMap;
}
if (workTime == null || workTime.getWorkMins() == 0) {
kqLog.info("workTime == null || workTime.getWorkMins() == 0 插入空记录");
nonlsParam = new ArrayList<>();
formatNonWork(userId, kqDate,nonlsParam,workTime, workFlowInfo);
if(!nonlsParam.isEmpty()){
sql = " insert into kq_format_detail(resourceid,kqdate,groupid,serialnumber,signindate,signintime,signinid,signoutdate,signouttime,signoutid,leaveMins,leaveinfo,evectionMins,outMins)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
rs.executeUpdate(sql, nonlsParam);
sql = " insert into kq_format_total(resourceid,kqdate,subcompanyid,departmentid,jobtitle,groupid,serialid,workdays," +
" workmins,attendancedays,attendancemins,signdays,signmins,belate,belatemins,gravebelate,gravebelatemins,leaveeearly,leaveearlymins," +
" graveleaveearly,graveleaveearlymins,absenteeism,absenteeismmins,forgotcheck, forgotcheckMins,leaveMins,evectionMins,outMins)" +
" select a.resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid," +
" case when sum(workmins)>0 then 1 end as workdays, sum(workmins) as workmins," +
" 0 as attendancedays, sum(attendanceMins) as attendanceMins," +
" 0 as signdays, sum(signmins) as signmins," +
" sum(case when belatemins> 0 then 1 else 0 end) as belate,sum(belatemins) as belatemins," +
" sum(case when graveBeLateMins> 0 then 1 else 0 end) as graveBeLate,sum(graveBeLateMins) as graveBeLateMins," +
" sum(case when leaveearlymins> 0 then 1 else 0 end) as leaveearly,sum(leaveearlymins) as leaveearlymins," +
" sum(case when graveLeaveEarlyMins> 0 then 1 else 0 end) as graveLeaveEarly,sum(graveLeaveEarlyMins) as graveLeaveEarlyMins," +
" sum(case when absenteeismmins> 0 then 1 else 0 end) as absenteeism,sum(absenteeismmins) as absenteeismmins," +
" sum(case when forgotcheckmins> 0 then 1 else 0 end) as forgotcheck,sum(forgotcheckmins) as forgotcheckmins, " +
" sum(leaveMins) as leaveMins, sum(evectionMins) as evectionMins, sum(outMins) as outMins" +
" from kq_format_detail a, hrmresource b" +
" where a.resourceid = b.id and resourceid =? and kqdate=?" +
" group by resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid,workmins";
rs.executeUpdate(sql, userId, kqDate);
}
}else{
Map<String,Object> definedFieldInfo = new KQFormatBiz().getDefinedField();
String definedField = "";
String definedParam = "";
String definedParamSum = "";
if (workTime.getKQType().equals("3")) {//自由工时
lsParam.addAll(kqFormatFreeData.format(userId, kqDate, workFlowInfo));
} else {
definedField = Util.null2String(definedFieldInfo.get("definedField"));
definedParam = Util.null2String(definedFieldInfo.get("definedParam"));
definedParamSum = Util.null2String(definedFieldInfo.get("definedParamSum"));
lsParam.addAll(format(userId, kqDate, workTime, workFlowInfo,uuid));
}
if (lsParam.size() > 0) {
sql = " insert into kq_format_detail( " +
" resourceid,kqdate,groupid,serialid,serialnumber,workbegindate,workbegintime,workenddate,workendtime,workmins," +
" signindate,signintime,signinid,signoutdate,signouttime,signoutid,signMins," +
" attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins," +
" leaveMins,leaveinfo,evectionMins,outMins,forgotbeginworkcheckmins,otherinfo"+(definedField.length()>0?","+definedField+"":"")+") " +
" values(?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?"+(definedField.length()>0?","+definedParam+"":"")+")";
for (int i = 0; i < lsParam.size(); i++) {
List<Object> param = lsParam.get(i);
boolean isok = rs.executeUpdate(sql, param);
kqLog.info("插入记录:userId:"+userId+":kqDate:"+kqDate+":param:"+JSON.toJSONString(param)+":isok:"+isok+"::uuid::"+uuid);
}
sql = " insert into kq_format_total(resourceid,kqdate,subcompanyid,departmentid,jobtitle,groupid,serialid,workdays,workmins," +
" attendancedays,attendancemins,signdays,signmins,belate,belatemins,gravebelate,gravebelatemins,leaveeearly,leaveearlymins,graveleaveearly," +
" graveleaveearlymins,absenteeism,absenteeismmins,forgotcheck,forgotcheckmins," +
" leaveMins,evectionMins,outMins,forgotbeginworkcheck,forgotbeginworkcheckmins"+(definedField.length()>0?","+definedField+"":"")+") " +
" select a.resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid," +
" case when sum(workmins)>0 then 1 end as workdays, sum(workmins) as workmins," +
" cast(sum(attendanceMins)AS decimal(10, 2))/sum(workmins) as attendancedays, sum(attendanceMins) as attendanceMins," +
" cast(sum(signmins)AS decimal(10, 2))/sum(workmins) as signdays, sum(signmins) as signmins," +
" sum(case when belatemins> 0 then 1 else 0 end) as belate,sum(belatemins) as belatemins," +
" sum(case when graveBeLateMins> 0 then 1 else 0 end) as graveBeLate,sum(graveBeLateMins) as graveBeLateMins," +
" sum(case when leaveearlymins> 0 then 1 else 0 end) as leaveearly,sum(leaveearlymins) as leaveearlymins," +
" sum(case when graveLeaveEarlyMins> 0 then 1 else 0 end) as graveLeaveEarly,sum(graveLeaveEarlyMins) as graveLeaveEarlyMins, " +
" sum(case when absenteeismmins> 0 then 1 else 0 end) as absenteeism,sum(absenteeismmins) as absenteeismmins," +
" sum(case when forgotcheckmins> 0 then 1 else 0 end) as forgotcheck,sum(forgotcheckmins) as forgotcheckmins,sum(leaveMins) as leaveMins," +
" sum(evectionMins) as evectionMins,sum(outMins) as outMins, " +
" sum(case when forgotbeginworkcheckmins> 0 then 1 else 0 end) as forgotbeginworkcheck,sum(forgotbeginworkcheckmins) as forgotbeginworkcheckmins " +
(definedField.length()>0?","+definedParamSum+"":"")+
" from kq_format_detail a, hrmresource b" +
" where a.resourceid = b.id and resourceid = ? and kqdate=?" +
" group by resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid";
rs.executeUpdate(sql, userId, kqDate);
}
}
}catch (Exception e) {
kqLog.info("KQFormatData失败:userId:"+userId+":kqDate:"+kqDate);
sql = " insert into kq_format_pool (resourceid, kqdate) values (?,?)";
rs.executeUpdate(sql, userId, kqDate);
writeLog(e);
kqLog.info(e);
}
return resultMap;
}
public List<List<Object>> format(String userId, String kqDate, WorkTimeEntity workTime,
Map<String, Object> workFlowInfo, String uuid) {
List<List<Object>> lsParam = new ArrayList<>();
List<Object> params = null;
try {
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String nosign_is_absent = Util.null2String(kqSettingsComInfo.getMain_val("nosign_is_absent"),"1");
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
KQFormatShiftRule kqFormatShiftRule = new KQFormatShiftRule();
String preDate = DateUtil.addDate(kqDate, -1);//上一天日期
String nextDate = DateUtil.addDate(kqDate, 1);//下一天日期
String dateKey = userId + "|" + kqDate;
String nextDateKey = userId + "|" + nextDate;
ArrayList<String> hostIps = InitServer.getRealIp();
kqLog.info("format in >>>>>userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
boolean oneSign = false;
List<TimeScopeEntity> lsSignTime = new ArrayList<>();
List<TimeScopeEntity> lsWorkTime = new ArrayList<>();
List<TimeScopeEntity> lsRestTime = new ArrayList<>();
List<Object> workFlow = null;
if (workTime != null) {
lsSignTime = workTime.getSignTime();//允许打卡时间
lsWorkTime = workTime.getWorkTime();//工作时间
lsRestTime = workTime.getRestTime();//休息时段时间
oneSign = lsWorkTime!=null&&lsWorkTime.size()==1;
}
int[] dayMins = new int[2880];//一天所有分钟数
Arrays.fill(dayMins, -1);
for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) {
params = new ArrayList<>();
TimeScopeEntity signTimeScope = lsSignTime.get(i);
TimeScopeEntity workTimeScope = lsWorkTime.get(i);
TimeScopeEntity restTimeScope = lsRestTime.isEmpty()?null:lsRestTime.get(i);
String workBeginTime = Util.null2String(workTimeScope.getBeginTime());
String ori_workBeginTime = workBeginTime;
int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime);
boolean workBenginTimeAcross = workTimeScope.getBeginTimeAcross();
String workEndTime = Util.null2String(workTimeScope.getEndTime());
String ori_workEndTime = workEndTime;
int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime);
boolean workEndTimeAcross = workTimeScope.getEndTimeAcross();
int workMins = workTimeScope.getWorkMins();
String workBeginDate = workBenginTimeAcross ? nextDate : kqDate;
String workEndDate = workEndTimeAcross ? nextDate : kqDate;
Arrays.fill(dayMins, workBeginIdx, workEndIdx, 1);//工作时段标识 1
int beginIdx = 0;
int endIdx = 0;
int checkIn = 0;
int checkOut = 0;
String signInId = "";
String signInDate = "";
String signInTime = "";
String signOutId = "";
String signOutDate = "";
String signOutTime = "";
int earlyInMins = 0;//早到分钟数
int lateOutMins = 0;//晚走分钟数
int signMins = 0;//签到签退时长
int tmpAttendanceMins = 0;//出勤分钟数(流程抵扣来的)
int attendanceMins = 0;
int beLateMins = 0;
int graveBeLateMins = 0;
int leaveEarlyMins = 0;
int graveLeaveEarlyMins = 0;
int absenteeismMins = 0;
int leaveMins = 0;//请假时长
Map<String,Object> leaveInfo = new HashMap<>();//请假信息
Map<String,Object> otherinfo = new HashMap<>();//存一些用得到的信息
int evectionMins = 0;//出差时长
int outMins = 0;//公出时长
int otherMins = 0;//异常流程时长
int forgotCheckMins = 0;
int forgotBeginWorkCheckMins = 0;//上班漏签
int signInTimeIndx = -1;
int flowSignInTimeIndx = -1;
int signInTimeOutdx = -1;
//用来计算实际打卡时长用的
int signInTimeIndx4Sign = -1;
int signInTimeOutdx4Sign = -1;
String signBeginDateTime = signTimeScope.getBeginTimeAcross() ? nextDate : kqDate;
if(signTimeScope.isBeginTimePreAcross()){
signBeginDateTime = preDate;
}
signBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(signTimeScope.getBeginTime())+":00";
String signEndDateTime = signTimeScope.getEndTimeAcross() ? nextDate : kqDate;
signEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(signTimeScope.getEndTime())+":59";
String workBeginDateTime = workTimeScope.getBeginTimeAcross() ? nextDate : kqDate;
workBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime())+":00";
String workEndDateTime = workTimeScope.getEndTimeAcross() ? nextDate : kqDate;
workEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getEndTime())+":00";
kqLog.info("signBeginDateTime" + signBeginDateTime+"::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
kqLog.info("signEndDateTime" + signEndDateTime+"::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
kqLog.info("workBeginDateTime" + workBeginDateTime+"::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
kqLog.info("workEndDateTime" + workEndDateTime+"::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
Map<String, String> shifRuleMap = Maps.newHashMap();
if(oneSign){
//个性化设置只支持一天一次上下班
ShiftInfoBean shiftInfoBean = new ShiftInfoBean();
shiftInfoBean.setSplitDate(kqDate);
shiftInfoBean.setShiftRuleMap(workTime.getShiftRuleInfo());
shiftInfoBean.setSignTime(lsSignTime);
shiftInfoBean.setWorkTime(lsWorkTime);
List<String> logList = Lists.newArrayList();
KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean, userId, shifRuleMap,logList);
if(!shifRuleMap.isEmpty()){
if(!logList.isEmpty()){
otherinfo.put("logList", logList);
}
otherinfo.put("shiftRule", shifRuleMap);
if(shifRuleMap.containsKey("shift_beginworktime")){
String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime"));
if(shift_beginworktime.length() > 0){
workBeginTime = Util.null2String(shift_beginworktime);
workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime);
workTimeScope.setBeginTime(workBeginTime);
workTimeScope.setBeginTimeAcross(workBeginIdx>=1440?true:false);
}
}
if(shifRuleMap.containsKey("shift_endworktime")){
String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime"));
if(shift_endworktime.length() > 0){
workEndTime = Util.null2String(shift_endworktime);
workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime);
workTimeScope.setEndTime(workEndTime);
workTimeScope.setEndTimeAcross(workEndIdx>=1440?true:false);
}
}
}
kqLog.info("个性化之后 signBeginDateTime" + signBeginDateTime);
kqLog.info("个性化之后 signEndDateTime" + signEndDateTime);
kqLog.info("个性化之后 workBeginDateTime" + workBeginDateTime);
kqLog.info("个性化之后 workEndDateTime" + workEndDateTime);
}
List<Object> lsCheckInfo = new KQFormatSignData().getSignInfo(userId,signTimeScope,workTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo,hostIps,uuid);
kqLog.info("lsCheckInfo" + JSONObject.toJSONString(lsCheckInfo)+"::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
if(this.writeLog) {
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005297,weaver.general.ThreadVarLanguage.getLang())+"",signBeginDateTime);
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005298,weaver.general.ThreadVarLanguage.getLang())+"",signEndDateTime);
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(1940,weaver.general.ThreadVarLanguage.getLang())+"",workBeginDateTime);
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005299,weaver.general.ThreadVarLanguage.getLang())+"",workEndDateTime);
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005300,weaver.general.ThreadVarLanguage.getLang())+"",lsCheckInfo);
}
for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) {
Map<String, Object> checkInfo = (Map<String, Object>) lsCheckInfo.get(j);
String signStatus = Util.null2String(checkInfo.get("signStatus"));
String signId = Util.null2String(checkInfo.get("signId"));
String signDate = Util.null2String(checkInfo.get("signDate"));
String signTime = Util.null2String(checkInfo.get("signTime"));
String deduct_signintime = Util.null2String(checkInfo.get("deduct_signintime"));
String deduct_signofftime = Util.null2String(checkInfo.get("deduct_signofftime"));
String flow_signInTime = "";
String flow_signOutTime = "";
if(kqDate.compareTo(signDate) < 0)endIdx+=1440;
if (signTime.length() > 8) {
signTime = signTime.substring(0, 8);
}
if (checkInfo.get("signType").equals("1")) {//签到
checkIn++;
//如果流程抵扣存在,打卡时长也存在,那么相互比较得到出勤时长和打卡时长 暂不这样处理,还是按照漏签的逻辑来处理
if(signTime.length() > 0){
signInTimeIndx4Sign = kqTimesArrayComInfo.getArrayindexByTimes(signTime);
}
signInId = signId;
signInDate = signDate;
signInTime = signTime;
signInTimeIndx = kqTimesArrayComInfo.getArrayindexByTimes(signInTime);
if(deduct_signintime.length() > 0){
if(signTime.length() > 0){
if(deduct_signintime.compareTo(signTime) < 0){
flow_signInTime = deduct_signintime;
}
}else{
flow_signInTime = deduct_signintime;
}
}
if(flow_signInTime.length() > 0){
flowSignInTimeIndx = kqTimesArrayComInfo.getArrayindexByTimes(flow_signInTime);
}
if(kqDate.compareTo(signDate) < 0) {
signInTimeIndx += 1440;
flowSignInTimeIndx += 1440;
}else if(kqDate.compareTo(signDate) > 0){
signInTimeIndx -= 1440;
signInTimeIndx = signInTimeIndx < 0 ? 0 : signInTimeIndx;
flowSignInTimeIndx -= 1440;
flowSignInTimeIndx = flowSignInTimeIndx < 0 ? 0 : flowSignInTimeIndx;
}
if(oneSign){
if(workBeginIdx>signInTimeIndx) {
earlyInMins = workBeginIdx-signInTimeIndx;
}
}
} else if (checkInfo.get("signType").equals("2")) {//签退
checkOut++;
//如果流程抵扣存在,打卡时长也存在,那么相互比较得到出勤时长和打卡时长 暂不这样处理,还是按照漏签的逻辑来处理
if(signTime.length() > 0){
signInTimeOutdx4Sign = kqTimesArrayComInfo.getArrayindexByTimes(signTime);
}
signOutId = signId;
signOutDate = signDate;
signOutTime = signTime;
signInTimeOutdx = kqTimesArrayComInfo.getArrayindexByTimes(signOutTime);
if(deduct_signofftime.length() > 0){
if(signTime.length() > 0){
if(deduct_signofftime.compareTo(signTime) > 0){
flow_signOutTime = deduct_signofftime;
}
}else{
flow_signOutTime = deduct_signofftime;
}
}
if(flow_signOutTime.length() > 0){
signInTimeOutdx = kqTimesArrayComInfo.getArrayindexByTimes(flow_signOutTime);
}
if(kqDate.compareTo(signDate) < 0){
signInTimeOutdx+=1440;
}else if(kqDate.compareTo(signDate) > 0){
signInTimeOutdx -= 1440;
signInTimeOutdx = signInTimeOutdx < 0 ? 0 : signInTimeOutdx;
}
if(oneSign){
if(signInTimeOutdx>workEndIdx) {
lateOutMins = signInTimeOutdx-workEndIdx;
}
}
}
if (checkInfo.get("signType").equals("1")) {//签到
if(signTime.length() > 0){
String signMinTime = signTime.substring(0,5)+":00";
endIdx = kqTimesArrayComInfo.getArrayindexByTimes(signTime);
if(signTime.compareTo(signMinTime) > 0){
//如果签到时间是带秒的且是迟到,那么签到时间多一秒和多一分钟是一样的
endIdx += 1;
signInTimeIndx = signInTimeIndx + 1;//如果是带秒的打卡数据不应该影响流程抵扣的数据的下标
}
if(kqDate.compareTo(signDate) < 0){
endIdx+=1440;
}else if(kqDate.compareTo(signDate) > 0){
endIdx -= 1440;
endIdx = endIdx < 0 ? 0 : endIdx;
}
if (endIdx > workBeginIdx) {
if(flow_signInTime.length() > 0){
if(flowSignInTimeIndx > workBeginIdx){
//增加一个判断,流程抵扣打卡如果开启了并且有抵扣上班打卡,那么也就不是迟到了
Arrays.fill(dayMins, workBeginIdx, endIdx, 2);//迟到时段标识 2
}
}else{
Arrays.fill(dayMins, workBeginIdx, endIdx, 2);//迟到时段标识 2
}
}
}
} else if (checkInfo.get("signType").equals("2")) {//签退
if(signTime.length() > 0){
beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(signTime);
if(StringUtils.isNotBlank(signDate) && signDate.compareTo(kqDate) > 0){
beginIdx+=1440;
}else if(kqDate.compareTo(signDate) > 0){
beginIdx -= 1440;
beginIdx = beginIdx < 0 ? 0 : beginIdx;
}
if (workEndIdx > beginIdx) {
if(flow_signOutTime.length() > 0){
if (workEndIdx > signInTimeOutdx) {
//增加一个判断,流程抵扣打卡如果开启了并且有抵扣下班打卡,那么也就不是早退了
Arrays.fill(dayMins, beginIdx, workEndIdx, 3);//早退时段标识 3
}
}else{
Arrays.fill(dayMins, beginIdx, workEndIdx, 3);//早退时段标识 3
}
}
}
}
}
//打卡时长=签退时间-签到时间(有签到签退才计算)
if(checkIn==1&&checkOut==1){
if(signInTimeIndx4Sign > -1 && signInTimeOutdx4Sign > -1){
if(DateUtil.dayDiff(signInDate,signOutDate)==0){//同一天签到和签退
signMins=signInTimeOutdx4Sign - signInTimeIndx4Sign;
}else if(DateUtil.dayDiff(signInDate,signOutDate)==1) {//第一天签到,第二天签退
if(signInTimeOutdx4Sign<signInTimeIndx4Sign){
signMins = 1440 + signInTimeOutdx4Sign - signInTimeIndx4Sign;
}else{
signMins = signInTimeOutdx4Sign - signInTimeIndx4Sign;
}
}
}else{
signMins=0;
}
if(signMins<0){
signMins=0;
}
}
if (checkIn == 0 && checkOut == 0) {//旷工(无签到无签退)
if (workEndIdx > workBeginIdx) {
Arrays.fill(dayMins, workBeginIdx, workEndIdx, 4);//旷工时段标识 4
}
}
if (checkOut == 0 && checkIn > 0) {//漏签(有签到无签退)
if(signInTimeIndx > -1){
if (workEndIdx > signInTimeIndx) {
//漏签就是从本次时段内的打卡到下班点
//上班漏签应该是从签到到签到结束时间,不过这里可以不用管,只是一个次数
Arrays.fill(dayMins, signInTimeIndx, workEndIdx, 6);//上班漏签时段标识 6
} else {
//签到晚于本次时段结束时间,也算漏签
forgotCheckMins++;
}
}else if(flowSignInTimeIndx > -1){
if (workEndIdx > flowSignInTimeIndx) {
//漏签就是从本次时段内的打卡到下班点
//上班漏签应该是从签到到签到结束时间,不过这里可以不用管,只是一个次数
Arrays.fill(dayMins, flowSignInTimeIndx, workEndIdx, 6);//上班漏签时段标识 6
} else {
//签到晚于本次时段结束时间,也算漏签
forgotCheckMins++;
}
}
}
if (checkIn == 0 && checkOut > 0) {//漏签(有签退无签到)
if(signInTimeOutdx > 0){
if(workBeginIdx < signInTimeOutdx) {
//下班漏签应该是从签退到签退开始时间,不过这里可以不用管,只是一个次数
Arrays.fill(dayMins, workBeginIdx, signInTimeOutdx, 66);//下班漏签时段标识 6666呼应前面的漏签的6
}else{
//这种数据理论上不会存在,也记下吧
forgotBeginWorkCheckMins++;
}
}
}
if (workFlowInfo.get(dateKey) != null) {
workFlow = (List<Object>) workFlowInfo.get(dateKey);
}
for (int j = 0; workFlow != null && j < workFlow.size(); j++) {
Map<String, Object> data = (Map<String, Object>) workFlow.get(j);
String flowType = Util.null2String(data.get("flowtype"));
String newLeaveType = Util.null2String(data.get("newleavetype"));
String signtype = Util.null2String(data.get("signtype"));
String serial = Util.null2String(data.get("serial"));
String requestId = Util.null2String(data.get("requestId"));
beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("begintime")));
endIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("endtime")));
if (beginIdx >= endIdx) {
continue;
}
if(flowType.equals(FlowReportTypeEnum.EVECTION.getFlowType())){
Arrays.fill(dayMins, beginIdx, endIdx, 7);//出差抵扣时段标识 7
}else if(flowType.equals(FlowReportTypeEnum.OUT.getFlowType())){
Arrays.fill(dayMins, beginIdx, endIdx, 8);//公出抵扣时段标识 8
}else if(flowType.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())){
if (endIdx > beginIdx) {
Arrays.fill(dayMins, beginIdx, endIdx, 5);//流程抵扣时段标识 5
int tmpBeginIdx = beginIdx;
int tmpEndIdx = endIdx;
Integer val = 0;
if(leaveInfo.get(newLeaveType)==null){
leaveInfo.put(newLeaveType,val);
}else{
val = (Integer) leaveInfo.get(newLeaveType);
}
if(beginIdx<workBeginIdx)tmpBeginIdx=workBeginIdx;
if(endIdx>workEndIdx)tmpEndIdx=endIdx;
if(tmpEndIdx>tmpBeginIdx){
leaveInfo.put(newLeaveType,val+(tmpEndIdx-tmpBeginIdx));
}
}
}else{
if (endIdx > beginIdx) {
Arrays.fill(dayMins, beginIdx, endIdx, 99);//异常流程抵扣时段标识99
}
}
}
if (workEndTimeAcross && false) {//跨天需要加入一天的流程
workFlow = null;
if (workFlowInfo.get(nextDateKey) != null) {
workFlow = (List<Object>) workFlowInfo.get(nextDateKey);
}
for (int j = 0; workFlow != null && j < workFlow.size(); j++) {
Map<String, Object> data = (Map<String, Object>) workFlow.get(j);
String flowType = Util.null2String(data.get("flowtype"));
beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("begintime")))+1440;
endIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("endtime")))+1440;
if(endIdx>=2880){
endIdx = 2880;
}
if(flowType.equals(FlowReportTypeEnum.EVECTION.getFlowType())){
Arrays.fill(dayMins, beginIdx, endIdx, 7);//出差抵扣时段标识 7
}else if(flowType.equals(FlowReportTypeEnum.OUT.getFlowType())){
Arrays.fill(dayMins, beginIdx, endIdx, 8);//公出抵扣时段标识 8
}else if(flowType.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())){
if (endIdx > beginIdx) {
Arrays.fill(dayMins, beginIdx, endIdx, 5);//流程抵扣时段标识 5
}
}else{
if (endIdx > beginIdx) {
Arrays.fill(dayMins, beginIdx, endIdx, 99);//异常流程抵扣时段标识99
}
}
}
}
if (restTimeScope!=null) {
String restBeginTime = Util.null2String(restTimeScope.getBeginTime());
String restEndTime = Util.null2String(restTimeScope.getEndTime());
beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(restBeginTime);
endIdx = kqTimesArrayComInfo.getArrayindexByTimes(restEndTime);
if (endIdx > beginIdx) {
Arrays.fill(dayMins, beginIdx, endIdx, -1);//休息时间
workMins = workMins-(endIdx-beginIdx);
}
}
for (int j = workBeginIdx; j < workEndIdx; j++) {
switch (dayMins[j]) {
case 1:
tmpAttendanceMins++;
break;
case 2:
beLateMins++;
break;
case 3:
leaveEarlyMins++;
break;
case 4:
absenteeismMins++;
break;
case 5:
leaveMins++;
break;
case 6:
forgotCheckMins++;
break;
case 7:
evectionMins++;
break;
case 8:
outMins++;
break;
case 66:
forgotBeginWorkCheckMins++;
break;
case 99:
otherMins++;
break;
default:
break;
}
}
if(forgotCheckMins == 1 && beLateMins==0 && tmpAttendanceMins==0){//forgotCheckMins==1表示下班后漏签不是迟到流程已完全抵扣异常
forgotCheckMins = 0;
}
KQShiftRuleEntity kqShiftRuleEntity = new KQShiftRuleEntity();
kqShiftRuleEntity.setUserId(userId);
kqShiftRuleEntity.setKqDate(kqDate);
kqShiftRuleEntity.setBelatemins(beLateMins);
kqShiftRuleEntity.setLeaveearlymins(leaveEarlyMins);
kqShiftRuleEntity.setAbsenteeismmins(absenteeismMins);
kqShiftRuleEntity.setForgotcheckmins(forgotCheckMins);
kqShiftRuleEntity.setForgotBeginWorkCheckMins(forgotBeginWorkCheckMins);
kqShiftRuleEntity.setEarlyInMins(earlyInMins);
kqShiftRuleEntity.setLateOutMins(lateOutMins);
kqLog.info("人性化规则处理前数据" + JSONObject.toJSONString(kqShiftRuleEntity));
if(this.writeLog) {
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005301,weaver.general.ThreadVarLanguage.getLang())+"",kqShiftRuleEntity);
}
//人性化规则
kqShiftRuleEntity = kqFormatShiftRule.doShiftRule(workTime,kqShiftRuleEntity);
kqLog.info("人性化规则处理后数据" + JSONObject.toJSONString(kqShiftRuleEntity));
if(this.writeLog) {
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005302,weaver.general.ThreadVarLanguage.getLang())+"",kqShiftRuleEntity);
}
beLateMins = kqShiftRuleEntity.getBelatemins();
graveBeLateMins = kqShiftRuleEntity.getGravebelatemins();
leaveEarlyMins = kqShiftRuleEntity.getLeaveearlymins();
graveLeaveEarlyMins = kqShiftRuleEntity.getGraveleaveearlymins();
absenteeismMins = kqShiftRuleEntity.getAbsenteeismmins();
forgotCheckMins = kqShiftRuleEntity.getForgotcheckmins();
forgotBeginWorkCheckMins = kqShiftRuleEntity.getForgotBeginWorkCheckMins();
boolean beforeBegin = !new KQFormatBiz().needCal(workBeginDate,workBeginTime);
if(beforeBegin) {//还未到上班时间,不用计算任何状态
kqLog.writeLog("还未到上班时间,不用计算任何状态");
beLateMins = 0;
graveBeLateMins = 0;
leaveEarlyMins = 0;
graveLeaveEarlyMins = 0;
absenteeismMins = 0;
forgotCheckMins = 0;
forgotBeginWorkCheckMins = 0;
}else if(!new KQFormatBiz().needCal(workEndDate,workEndTime)) {//还未到下班时间
kqLog.writeLog("还未到上班时间");
leaveEarlyMins = 0;
graveLeaveEarlyMins = 0;
forgotCheckMins = 0;
}
if (workTime.getIsExclude()) {//无需考勤人员没有异常状态
beLateMins = 0;
graveBeLateMins = 0;
leaveEarlyMins = 0;
graveLeaveEarlyMins = 0;
absenteeismMins = 0;
forgotCheckMins = 0;
forgotBeginWorkCheckMins = 0;
}
//计算实际出勤时间(出差公出算出勤)=应出勤-旷工-请假-迟到-早退
attendanceMins = workMins - absenteeismMins-leaveMins-beLateMins-graveBeLateMins-leaveEarlyMins-graveLeaveEarlyMins;
// 如果没有开启"漏签是否算实际出勤"开关,则漏签不算实际出勤时长
if("0".equals(nosign_is_absent)) {
attendanceMins = attendanceMins-forgotCheckMins-forgotBeginWorkCheckMins;
}
if(beforeBegin || attendanceMins < 0) {//还未到上班时间,不用计算任何状体
attendanceMins = 0;
}
kqLog.info("实际出勤计算公式" + "实际出勤=应出勤- 旷工-请假-迟到-早退 userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
kqLog.info("实际出勤计算结果" + attendanceMins + "=" + workMins + "- " + absenteeismMins + "-" + leaveMins + "-" + (beLateMins + graveBeLateMins) + "-" + (leaveEarlyMins - graveLeaveEarlyMins)+" userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid);
if(this.writeLog) {
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005303,weaver.general.ThreadVarLanguage.getLang())+"",""+weaver.systeminfo.SystemEnv.getHtmlLabelName(130566,weaver.general.ThreadVarLanguage.getLang())+"="+weaver.systeminfo.SystemEnv.getHtmlLabelName(132056,weaver.general.ThreadVarLanguage.getLang())+"- "+weaver.systeminfo.SystemEnv.getHtmlLabelName(20085,weaver.general.ThreadVarLanguage.getLang())+"-"+weaver.systeminfo.SystemEnv.getHtmlLabelName(670,weaver.general.ThreadVarLanguage.getLang())+"-"+weaver.systeminfo.SystemEnv.getHtmlLabelName(20081,weaver.general.ThreadVarLanguage.getLang())+"-"+weaver.systeminfo.SystemEnv.getHtmlLabelName(20082,weaver.general.ThreadVarLanguage.getLang())+"");
logInfo.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005304,weaver.general.ThreadVarLanguage.getLang())+"",attendanceMins+"="+workMins+"- "+absenteeismMins+"-"+leaveMins+"-"+(beLateMins+graveBeLateMins)+"-"+(leaveEarlyMins-graveLeaveEarlyMins));
}
//判断当天考勤状态
// if (beLateMins > 0) {
// status = ButtonStatusEnum.BELATE.getStatusCode();
// } else if (leaveEarlyMins > 0) {
// status = ButtonStatusEnum.LEAVEERALY.getStatusCode();
// } else if (absenteeismMins > 0) {
// status = ButtonStatusEnum.ABSENT.getStatusCode();
// } else if (forgotCheckMins > 0) {
// status = ButtonStatusEnum.NOSIGN.getStatusCode();
// } else {
// status = ButtonStatusEnum.NORMAL.getStatusCode();
// }
String groupid = Util.null2String(workTime.getGroupId());
String serialid = Util.null2String(workTime.getSerialId());
params.add(userId);
params.add(kqDate);
params.add(groupid.length() == 0 ? null : groupid);
params.add(serialid.length() == 0 ? null : serialid);
params.add(i);
params.add(workBeginDate);
params.add(kqTimesArrayComInfo.turn48to24Time(ori_workBeginTime));
params.add(workEndDate);
params.add(kqTimesArrayComInfo.turn48to24Time(ori_workEndTime));
params.add(workMins);
params.add(signInDate);
params.add(signInTime);
params.add(signInId.length() == 0 ? null : signInId);
params.add(signOutDate);
params.add(signOutTime);
params.add(signOutId.length() == 0 ? null : signOutId);
kqLog.info("format in >>>>>userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid
+":signInDate:"+signInDate+":signInTime::"+signInTime+":signOutDate:"+signOutDate+":signOutTime::"+signOutTime);
params.add(signMins);
params.add(attendanceMins);
params.add(beLateMins);
params.add(graveBeLateMins);
params.add(leaveEarlyMins);
params.add(graveLeaveEarlyMins);
params.add(absenteeismMins);
params.add(forgotCheckMins);
params.add(leaveMins);
params.add(JSONObject.toJSONString(leaveInfo));
params.add(evectionMins);
params.add(outMins);
params.add(forgotBeginWorkCheckMins);
params.add(JSONObject.toJSONString(otherinfo));
Map<String,Object> definedFieldInfo = new KQFormatBiz().getDefinedField();
String[] definedFields = Util.splitString(Util.null2String(definedFieldInfo.get("definedField")),",");
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
for (int tmpIdx = 0; tmpIdx<definedFields.length; tmpIdx++) {
String fieldname = definedFields[tmpIdx];
// System.out.println("fieldname=="+fieldname);
String fieldid = KQReportFieldComInfo.field2Id.get(fieldname);
String formula = kqReportFieldComInfo.getFormula(fieldid);
if(formula.length()==0)continue;
String expression = formula;
Pattern pattern = Pattern.compile("\\$\\{[^}]+\\}");
Matcher matcher = pattern.matcher(expression);
Map<String, Object> env = new HashMap<>();
String keyname = "";
while (matcher.find()) {
String key = matcher.group(0);
keyname = key.substring(2, key.length() - 1).trim();
expression = matcher.replaceAll(keyname);
env.put(keyname, keyname.equals("beLateMins")?beLateMins:leaveEarlyMins);
}
Expression compiledExp = AviatorEvaluator.compile(expression,true);
String value = Util.null2String(compiledExp.execute(env));
params.add(value);
if(value.equals("1")) {
params.add(keyname.equals("beLateMins") ? beLateMins : leaveEarlyMins);
}else{
params.add("0");
}
}
kqLog.info("format in >>>>>userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid
+":params:"+JSON.toJSONString(params));
lsParam.add(params);
}
} catch (Exception e) {
writeLog(e);
kqLog.info(e);
}
return lsParam;
}
public void setWriteLog(boolean writeLog) {
this.writeLog = writeLog;
}
public Map<String,Object> getLogInfo() {
return logInfo;
}
public void formatDateByKQDate(String kqdate) {
KQFormatBiz kqFormatBiz = new KQFormatBiz();
kqFormatBiz.formatDateByKQDate(kqdate);
}
public void formatDateByGroupId(String groupid, String kqdate) {
KQFormatBiz kqFormatBiz = new KQFormatBiz();
kqFormatBiz.formatDateByGroupId(groupid, kqdate);
}
public void formatDate(String resourceid, String kqdate) {
KQFormatBiz kqFormatBiz = new KQFormatBiz();
kqFormatBiz.formatDate(resourceid, kqdate);
}
public void delFormatData(String resourceid, String kqdate) {
KQFormatBiz kqFormatBiz = new KQFormatBiz();
kqFormatBiz.delFormatData(resourceid, kqdate);
}
/**
*
* @param userId
* @param kqDate
* @param nonlsParam
* @param workTime
* @param workFlowInfo
*/
public void formatNonWork(String userId, String kqDate, List<Object> nonlsParam, WorkTimeEntity workTime, Map<String, Object> workFlowInfo) {
String signInId = "";
String signInDate = "";
String signInTime = "";
String signOutId = "";
String signOutDate = "";
String signOutTime = "";
int beginIdx = 0;
int endIdx = 0;
int leaveMins = 0;//请假时长
Map<String,Object> leaveInfo = new HashMap<>();//请假信息
int evectionMins = 0;//出差时长
int outMins = 0;//公出时长
int otherMins = 0;//异常流程时长
int[] dayMins = new int[2880];//一天所有分钟数
List<Object> workFlow = null;
String dateKey = userId + "|" + kqDate;
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
String preDate = DateUtil.addDate(kqDate, -1);//上一天日期
String nextDate = DateUtil.addDate(kqDate, 1);//下一天日期
WorkTimeEntity pre_workTime = new KQWorkTime().getWorkTime(userId, preDate);
List<TimeScopeEntity> pre_lsSignTime = new ArrayList<>();
if (pre_workTime != null) {
pre_lsSignTime = pre_workTime.getSignTime();//允许打卡时间
pre_lsSignTime = pre_lsSignTime != null ? pre_lsSignTime : new ArrayList<>();
}
WorkTimeEntity next_workTime = new KQWorkTime().getWorkTime(userId, nextDate);
List<TimeScopeEntity> next_lsSignTime = new ArrayList<>();
if (next_workTime != null) {
next_lsSignTime = next_workTime.getSignTime();//允许打卡时间
next_lsSignTime = next_lsSignTime != null ? next_lsSignTime : new ArrayList<>();
}
List<Object> lsCheckInfo = new KQFormatSignData().getNonWorkSignInfo(userId,preDate,kqDate,pre_lsSignTime,next_lsSignTime);
for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) {
Map<String, Object> checkInfo = (Map<String, Object>) lsCheckInfo.get(j);
String signStatus = Util.null2String(checkInfo.get("signStatus"));
String signId = Util.null2String(checkInfo.get("signId"));
String signDate = Util.null2String(checkInfo.get("signDate"));
String signTime = Util.null2String(checkInfo.get("signTime"));
if (checkInfo.get("signType").equals("1")) {//签到
signInId = signId;
signInDate = signDate;
signInTime = signTime;
} else if (checkInfo.get("signType").equals("2")) {//签退
signOutId = signId;
signOutDate = signDate;
signOutTime = signTime;
}
}
if (workFlowInfo.get(dateKey) != null) {
workFlow = (List<Object>) workFlowInfo.get(dateKey);
}
for (int j = 0; workFlow != null && j < workFlow.size(); j++) {
Map<String, Object> data = (Map<String, Object>) workFlow.get(j);
String flowType = Util.null2String(data.get("flowtype"));
String newLeaveType = Util.null2String(data.get("newleavetype"));
beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("begintime")));
endIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("endtime")));
if(flowType.equals(FlowReportTypeEnum.EVECTION.getFlowType())){
Arrays.fill(dayMins, beginIdx, endIdx, 7);//出差抵扣时段标识 7
}else if(flowType.equals(FlowReportTypeEnum.OUT.getFlowType())){
Arrays.fill(dayMins, beginIdx, endIdx, 8);//公出抵扣时段标识 8
}else if(flowType.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())){
if (endIdx > beginIdx) {
Arrays.fill(dayMins, beginIdx, endIdx, 5);//流程抵扣时段标识 5
int tmpBeginIdx = beginIdx;
int tmpEndIdx = endIdx;
Integer val = 0;
if(leaveInfo.get(newLeaveType)==null){
leaveInfo.put(newLeaveType,val);
}else{
val = (Integer) leaveInfo.get(newLeaveType);
}
if(tmpEndIdx>tmpBeginIdx){
leaveInfo.put(newLeaveType,val+(tmpEndIdx-tmpBeginIdx));
}
}
}else{
if (endIdx > beginIdx) {
Arrays.fill(dayMins, beginIdx, endIdx, 99);//异常流程抵扣时段标识99
}
}
}
for (int j = 0; j < 2880; j++) {
switch (dayMins[j]) {
case 5:
leaveMins++;
break;
case 7:
evectionMins++;
break;
case 8:
outMins++;
break;
case 99:
otherMins++;
break;
default:
break;
}
}
nonlsParam.add(userId);
nonlsParam.add(kqDate);
nonlsParam.add(workTime.getGroupId());
nonlsParam.add(0);
nonlsParam.add(signInDate);
nonlsParam.add(signInTime);
nonlsParam.add(signInId.length() == 0 ? null : signInId);
nonlsParam.add(signOutDate);
nonlsParam.add(signOutTime);
nonlsParam.add(signOutId.length() == 0 ? null : signOutId);
nonlsParam.add(leaveMins);
nonlsParam.add(JSONObject.toJSONString(leaveInfo));
nonlsParam.add(evectionMins);
nonlsParam.add(outMins);
}
}

@ -0,0 +1,709 @@
package com.engine.kq.biz;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.entity.KQOvertimeRulesDetailEntity;
import com.engine.kq.log.KQLog;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.wfset.bean.OvertimeBalanceTimeBean;
import com.engine.kq.wfset.bean.SplitBean;
import com.engine.kq.wfset.util.KQFlowUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.springframework.beans.BeanUtils;
import weaver.general.Util;
/**
*
*
*/
public class KQOverTimeFlowBiz {
private KQLog kqLog = new KQLog();
/**
*
*
*
* A-B A24A
* A-A24A
* -A0A
*
*
*
* @param splitBean
* @param splitBeans
*/
public void getSplitDurationBean_new(SplitBean splitBean,List<SplitBean> splitBeans) {
try{
long a = System.currentTimeMillis();
double oneDayHour = KQFlowUtil.getOneDayHour(splitBean.getDurationTypeEnum(),"");
int workmins = (int)(oneDayHour * 60);
String resourceid = splitBean.getResourceId();
String fromDate = splitBean.getFromdatedb();
String toDate = splitBean.getTodatedb();
String overtime_type = splitBean.getOvertime_type();
LocalDate localFromDate = LocalDate.parse(fromDate);
LocalDate localToDate = LocalDate.parse(toDate);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate preFromDate = localFromDate.minusDays(1);
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz();
KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz();
Map<String,Integer> changeTypeMap = Maps.newHashMap();
Map<String, KQOvertimeRulesDetailEntity> overRulesDetailMap = Maps.newHashMap();
Map<String,List<String[]>> restTimeMap = Maps.newHashMap();
Map<String,Integer> computingModeMap = Maps.newHashMap();
kqOverTimeRuleCalBiz.getOverTimeDataMap(resourceid, fromDate, toDate, dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap,computingModeMap);
if(overRulesDetailMap.isEmpty()){
return;
}
String fromTime = splitBean.getFromtimedb();
String toTime = splitBean.getTotimedb();
long betweenDays = localToDate.toEpochDay() - preFromDate.toEpochDay();
//默认是从加班开始日期的前一天开始计算 需要特殊处理的就三个情况i=0的时候i=1的时候就是加班流程开始日期那一天i=最后一天就是加班流程结束日期那一天
for (int i = 0; i <= betweenDays; i++) {
SplitBean overSplitBean = new SplitBean();
//然后把bean重新赋值下根据拆分后的时间
BeanUtils.copyProperties(splitBean, overSplitBean);
//从加班流程开始的前一天开始算归属
LocalDate curLocalDate = preFromDate.plusDays(i);
String splitDate = curLocalDate.format(dateFormatter);
String preSplitDate = LocalDate.parse(splitDate).minusDays(1).format(dateFormatter);
LocalDate nextLocalDate = curLocalDate.plusDays(1);
String nextSplitDate = nextLocalDate.format(dateFormatter);
String change_key = splitDate+"_"+resourceid;
String pre_change_key = preSplitDate+"_"+resourceid;
String next_change_key = nextSplitDate+"_"+resourceid;
int changeType = Util.getIntValue(""+changeTypeMap.get(change_key),-1);
int preChangeType = Util.getIntValue(""+changeTypeMap.get(pre_change_key),-1);
int next_changeType = Util.getIntValue(""+changeTypeMap.get(next_change_key),-1);
boolean shouldAcross = false;
String changeType_key = splitDate+"_"+changeType;
String preChangeType_key = preSplitDate+"_"+preChangeType;
String nextChangeType_key = nextSplitDate+"_"+next_changeType;
if(!computingModeMap.containsKey(changeType_key)){
continue;
}
int computingMode = computingModeMap.get(changeType_key);
if(computingMode == 3){
//如果是纯打卡为主的不生成加班
continue;
}
int[] initArrays = kqTimesArrayComInfo.getInitArr();
//当前日期的加班分割点 分割点都是次日的
String overtime_cut_point = "";
int before_startTime = 0;
int startTime = 0;
int curMins = 0 ;
//排除休息类型
int restTimeType = -1;
String next_beginwork_time = "";
String cur_beginwork_time = "";
String serialid = "";
//需要知道明日的类型:如果今天是工作日的话,那么今天的加班临界点可能和明日的上班时间冲突,需要知道明日的上班时间进行比较,
// 如果今天是休息日,那么明天如果是工作日的话,默认规则下,明天的上班前都是属于今天的加班区间
if(next_changeType == 2){
ShiftInfoBean next_shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, nextSplitDate, false);
if(next_shiftInfoBean != null){
List<int[]> workLongTimeIndex = next_shiftInfoBean.getWorkLongTimeIndex();
List<int[]> real_workLongTimeIndex = Lists.newArrayList();
get_real_workLongTimeIndex(workLongTimeIndex,real_workLongTimeIndex,next_shiftInfoBean,kqTimesArrayComInfo,splitBean);
if(real_workLongTimeIndex != null && !real_workLongTimeIndex.isEmpty()){
next_beginwork_time = kqTimesArrayComInfo.getTimesByArrayindex(real_workLongTimeIndex.get(0)[0]);
}
}
}
if(changeType == 2){
ShiftInfoBean cur_shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, splitDate, false);
if(cur_shiftInfoBean != null){
List<int[]> workLongTimeIndex = cur_shiftInfoBean.getWorkLongTimeIndex();
List<int[]> real_workLongTimeIndex = Lists.newArrayList();
get_real_workLongTimeIndex(workLongTimeIndex,real_workLongTimeIndex,cur_shiftInfoBean,kqTimesArrayComInfo,splitBean);
if(real_workLongTimeIndex != null && !real_workLongTimeIndex.isEmpty()){
cur_beginwork_time = kqTimesArrayComInfo.getTimesByArrayindex(real_workLongTimeIndex.get(0)[0]);
}
}
}
boolean needSplitByTime = false;
// 按照加班时长转调休的 时长设置
List<String> timepointList = null;
List<OvertimeBalanceTimeBean> overtimeBalanceTimeBeans = Lists.newArrayList();
KQOvertimeRulesDetailEntity curKqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key);
if(curKqOvertimeRulesDetailEntity != null){
int has_cut_point = curKqOvertimeRulesDetailEntity.getHas_cut_point();
before_startTime = curKqOvertimeRulesDetailEntity.getBefore_startTime();
int overtimeEnable = curKqOvertimeRulesDetailEntity.getOvertimeEnable();
if(overtimeEnable != 1){
continue;
}
if(has_cut_point != 1){
before_startTime = -1;
}
startTime = curKqOvertimeRulesDetailEntity.getStartTime();
restTimeType = curKqOvertimeRulesDetailEntity.getRestTimeType();
int paidLeaveEnable = kqOverTimeRuleCalBiz.getPaidLeaveEnable(curKqOvertimeRulesDetailEntity,overtime_type);
needSplitByTime = kqOverTimeRuleCalBiz.getNeedSplitByTime(curKqOvertimeRulesDetailEntity,paidLeaveEnable);
if(needSplitByTime){
int ruleDetailid = curKqOvertimeRulesDetailEntity.getId();
Map<String,List<String>> balanceTimethDetailMap = kqOvertimeRulesBiz.getBalanceTimeDetailMap(ruleDetailid);
if(balanceTimethDetailMap != null && !balanceTimethDetailMap.isEmpty()){
timepointList = balanceTimethDetailMap.get("timepointList");
}
}
if(has_cut_point == 0){
if(changeType == 2){
overtime_cut_point = cur_beginwork_time;
}else {
if(next_beginwork_time.length() > 0){
overtime_cut_point = next_beginwork_time;
}
}
}else{
overtime_cut_point = curKqOvertimeRulesDetailEntity.getCut_point();
if(next_beginwork_time.length() > 0){
int next_beginwork_time_index = kqTimesArrayComInfo.getArrayindexByTimes(next_beginwork_time);
int overtime_cut_point_index = kqTimesArrayComInfo.getArrayindexByTimes(overtime_cut_point);
if(overtime_cut_point_index > next_beginwork_time_index){
overtime_cut_point = next_beginwork_time;
}
}
}
if(overtime_cut_point.length() == 0){
overtime_cut_point = "00:00";
}
}else{
continue;
}
int fromTime_index = 0;
int toTime_index = 0;
if(i == 0){
//i=0就是加班开始日期的前一天只有当加班临界点超过了加班流程开始时间的话i=0才会有可能计算出时长
if(overtime_cut_point.compareTo(fromTime) > 0){
fromTime_index = kqTimesArrayComInfo.getArrayindexByTimes(kqTimesArrayComInfo.turn24to48Time(fromTime));
toTime_index = kqTimesArrayComInfo.getArrayindexByTimes(kqTimesArrayComInfo.turn24to48Time(overtime_cut_point));
if(fromDate.equalsIgnoreCase(toDate)){
//如果开始日期和结束日期是同一天,还需要比较流程的结束时间和归属点的大小
int oriTotime_index = kqTimesArrayComInfo.getArrayindexByTimes(kqTimesArrayComInfo.turn24to48Time(toTime));
if(toTime_index > oriTotime_index){
toTime_index = oriTotime_index;
}
}
Arrays.fill(initArrays, fromTime_index, toTime_index, 0);
// 1-节假日、2-工作日、3-休息日
if(changeType == 1){
handle_changeType_1(initArrays,overRulesDetailMap,nextChangeType_key,next_changeType,next_beginwork_time);
}else if(changeType == 2){
boolean isok = handle_changeType_2(initArrays, resourceid, splitDate, before_startTime, startTime, fromTime_index,kqTimesArrayComInfo,splitBean,
toTime_index);
serialid = splitBean.getSerialid();
if(!isok){
continue;
}
}else if(changeType == 3){
handle_changeType_3(initArrays,overRulesDetailMap,nextChangeType_key,next_changeType,next_beginwork_time);
}
if(restTimeType == 1){
//如果排除设置的休息时间
handle_resttime(restTimeMap,changeType_key,kqTimesArrayComInfo,shouldAcross,initArrays);
}
curMins = kqTimesArrayComInfo.getCnt(initArrays, fromTime_index,toTime_index,0);
if(restTimeType == 2){
//如果排除休息时间是扣除时长
curMins = handle_restlength(curMins,restTimeMap,changeType_key);
}
}else{
continue;
}
}else{
//除了i=0的情况其他的每一天都是要获取一下昨日的临界点的
String pre_overtime_cut_point = get_pre_overtime_cut_point(overRulesDetailMap,preChangeType_key,resourceid,preSplitDate,splitDate,preChangeType,kqTimesArrayComInfo,splitBean,changeType);
if(changeType == 2){
//如果今天是工作日,昨日的打卡归属会受到今日的上班前开始加班分钟数的影响
int cur_beginwork_time_index = kqTimesArrayComInfo.getArrayindexByTimes(cur_beginwork_time);
if(before_startTime > -1){
int pre_overtime_cut_point_index = kqTimesArrayComInfo.getArrayindexByTimes(pre_overtime_cut_point);
int before_cur_beginwork_time_index = cur_beginwork_time_index - before_startTime;
}
}
//计算区间加班开始日期和加班结束日期这两天都是要特殊处理的
fromTime_index = kqTimesArrayComInfo.getArrayindexByTimes(pre_overtime_cut_point);
if(i == 1){
if(fromTime.compareTo(pre_overtime_cut_point) > 0){
fromTime_index = kqTimesArrayComInfo.getArrayindexByTimes(fromTime);
}
}
if(i == betweenDays){
toTime_index = kqTimesArrayComInfo.getArrayindexByTimes(toTime);
}else{
toTime_index = kqTimesArrayComInfo.turn24to48TimeIndex(kqTimesArrayComInfo.getArrayindexByTimes(overtime_cut_point));
if(next_beginwork_time.length() > 0){
int overtime_cut_point_index = kqTimesArrayComInfo.getArrayindexByTimes(overtime_cut_point);
int next_beginwork_time_index = kqTimesArrayComInfo.getArrayindexByTimes(next_beginwork_time);
//如果临界点都已经超过第二天上班的开始时间了,要相应的缩短成第二天上班时间
if(overtime_cut_point_index > next_beginwork_time_index){
toTime_index = kqTimesArrayComInfo.turn24to48TimeIndex(next_beginwork_time_index);
}
}
if(i == betweenDays-1){
int ori_totime_index = kqTimesArrayComInfo.turn48to24TimeIndex(toTime_index);
int last_toTime_index = kqTimesArrayComInfo.getArrayindexByTimes(toTime);
if(ori_totime_index > last_toTime_index){
toTime_index = kqTimesArrayComInfo.turn24to48TimeIndex(last_toTime_index);
}
}
}
System.out.println(i+":betweenDays:"+betweenDays+":fromTime_index:"+fromTime_index+":toTime_index:"+toTime_index+":changeType:"+changeType);
if(fromTime_index > toTime_index){
continue;
}
Arrays.fill(initArrays, fromTime_index, toTime_index, 0);
if(changeType == 1){
handle_changeType_1(initArrays, overRulesDetailMap, nextChangeType_key, next_changeType,
next_beginwork_time);
}else if(changeType == 2){
serialid = splitBean.getSerialid();
boolean isok = handle_changeType_2(initArrays, resourceid, splitDate, before_startTime, startTime, fromTime_index,
kqTimesArrayComInfo, splitBean, toTime_index);
if(!isok){
continue;
}
}else if(changeType == 3){
handle_changeType_3(initArrays, overRulesDetailMap, nextChangeType_key, next_changeType,
overtime_cut_point);
}
if(restTimeType == 1) {
//如果排除设置的休息时间
handle_resttime(restTimeMap, changeType_key, kqTimesArrayComInfo, shouldAcross,initArrays);
}
curMins = kqTimesArrayComInfo.getCnt(initArrays, fromTime_index,toTime_index,0);
if(restTimeType == 2){
//如果排除休息时间是扣除时长
curMins = handle_restlength(curMins,restTimeMap,changeType_key);
}
}
int minimumUnit = curKqOvertimeRulesDetailEntity.getMinimumLen();
if(curMins < minimumUnit){
continue;
}
if(needSplitByTime){
kqOverTimeRuleCalBiz.get_overtimeBalanceTimeBeans(timepointList,overtimeBalanceTimeBeans,kqTimesArrayComInfo,initArrays,toTime_index,fromTime_index,0);
if(overtimeBalanceTimeBeans != null && !overtimeBalanceTimeBeans.isEmpty()){
String bean_cross_fromtime = kqTimesArrayComInfo.getTimesByArrayindex(fromTime_index);
String bean_cross_totime = kqTimesArrayComInfo.getTimesByArrayindex(toTime_index);
for(int timeIndex = 0 ; timeIndex < overtimeBalanceTimeBeans.size() ;timeIndex++) {
OvertimeBalanceTimeBean overtimeBalanceTimeBean = overtimeBalanceTimeBeans.get(timeIndex);
String timePointStart = overtimeBalanceTimeBean.getTimepoint_start();
String timePointEnd = overtimeBalanceTimeBean.getTimepoint_end();
boolean isNeedTX = overtimeBalanceTimeBean.isNeedTX();
int timePointStart_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointStart);
int timePointEnd_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointEnd);
if(timePointStart_index > fromTime_index){
bean_cross_fromtime = kqTimesArrayComInfo.getTimesByArrayindex(timePointStart_index);
}else{
bean_cross_fromtime = kqTimesArrayComInfo.getTimesByArrayindex(fromTime_index);
}
if(timePointEnd_index < toTime_index){
bean_cross_totime = kqTimesArrayComInfo.getTimesByArrayindex(timePointEnd_index);
}else{
bean_cross_totime = kqTimesArrayComInfo.getTimesByArrayindex(toTime_index);
}
int timepoint_mins = overtimeBalanceTimeBean.getTimepoint_mins();
if(isNeedTX){
if(timepoint_mins > 0){
overSplitBean = new SplitBean();
//然后把bean重新赋值下根据拆分后的时间
BeanUtils.copyProperties(splitBean, overSplitBean);
overSplitBean.setChangeType(changeType);
overSplitBean.setPreChangeType(preChangeType);
overSplitBean.setOneDayHour(oneDayHour);
overSplitBean.setWorkmins(workmins);
overSplitBean.setComputingMode(computingMode+"");
overSplitBean.setChangeType(changeType);
overSplitBean.setFromDate(splitDate);
overSplitBean.setFromTime(bean_cross_fromtime);
overSplitBean.setToDate(splitDate);
overSplitBean.setToTime(bean_cross_totime);
overSplitBean.setBelongDate(splitDate);
overSplitBean.setD_Mins(timepoint_mins);
overSplitBean.setOvertimeBalanceTimeBeans(overtimeBalanceTimeBeans);
overSplitBean.setSerialid(serialid);
getDurationByRule(overSplitBean);
splitBeans.add(overSplitBean);
}
}
}
}
}else{
curMins = (int) kqOverTimeRuleCalBiz.getD_MinsByUnit(curMins);
overSplitBean.setChangeType(changeType);
overSplitBean.setPreChangeType(preChangeType);
overSplitBean.setOneDayHour(oneDayHour);
overSplitBean.setWorkmins(workmins);
overSplitBean.setComputingMode(computingMode+"");
overSplitBean.setChangeType(changeType);
overSplitBean.setFromDate(splitDate);
overSplitBean.setFromTime(kqTimesArrayComInfo.getTimesByArrayindex(fromTime_index));
overSplitBean.setToDate(splitDate);
overSplitBean.setToTime(kqTimesArrayComInfo.getTimesByArrayindex(toTime_index));
overSplitBean.setBelongDate(splitDate);
overSplitBean.setD_Mins(curMins);
overSplitBean.setOvertimeBalanceTimeBeans(overtimeBalanceTimeBeans);
overSplitBean.setSerialid(serialid);
getDurationByRule(overSplitBean);
splitBeans.add(overSplitBean);
}
}
long b = System.currentTimeMillis();
System.out.println("::"+(b-a));
}catch (Exception e){
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
}
/**
*
* @param workLongTimeIndex
* @param real_workLongTimeIndex
* @param shiftInfoBean
* @param kqTimesArrayComInfo
* @param splitBean
*/
public void get_real_workLongTimeIndex(List<int[]> workLongTimeIndex,
List<int[]> real_workLongTimeIndex,
ShiftInfoBean shiftInfoBean, KQTimesArrayComInfo kqTimesArrayComInfo,
SplitBean splitBean) {
//list带数组这里要深拷贝
for(int[] tmp : workLongTimeIndex){
int[] real_tmp = new int[tmp.length];
System.arraycopy(tmp, 0, real_tmp, 0, tmp.length);
real_workLongTimeIndex.add(real_tmp);
}
if(real_workLongTimeIndex.size() == 1){
//个性化设置只支持一次打卡的
KQShiftRuleInfoBiz kqShiftRuleInfoBiz = new KQShiftRuleInfoBiz();
kqShiftRuleInfoBiz.rest_workLongTimeIndex(shiftInfoBean,splitBean,real_workLongTimeIndex,kqTimesArrayComInfo,null);
}
}
/**
*
* @param overRulesDetailMap
* @param preChangeType_key
* @param resourceid
* @param preSplitDate
* @param splitDate
* @param preChangeType
* @param kqTimesArrayComInfo
* @param splitBean
* @param changeType
* @return
*/
private String get_pre_overtime_cut_point(
Map<String, KQOvertimeRulesDetailEntity> overRulesDetailMap,
String preChangeType_key, String resourceid, String preSplitDate, String splitDate,
int preChangeType, KQTimesArrayComInfo kqTimesArrayComInfo,
SplitBean splitBean, int changeType) {
String pre_overtime_cut_point = "";
KQOvertimeRulesDetailEntity preKqOvertimeRulesDetailEntity = overRulesDetailMap.get(preChangeType_key);
if(preKqOvertimeRulesDetailEntity != null){
int has_cut_point = preKqOvertimeRulesDetailEntity.getHas_cut_point();
if(has_cut_point == 0){
if(preChangeType == 2){
ShiftInfoBean pre_shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, preSplitDate, false);
if(pre_shiftInfoBean != null){
List<int[]> workLongTimeIndex = pre_shiftInfoBean.getWorkLongTimeIndex();
List<int[]> real_workLongTimeIndex = Lists.newArrayList();
get_real_workLongTimeIndex(workLongTimeIndex,real_workLongTimeIndex,pre_shiftInfoBean,kqTimesArrayComInfo,splitBean);
if(real_workLongTimeIndex != null && !real_workLongTimeIndex.isEmpty()){
pre_overtime_cut_point = kqTimesArrayComInfo.getTimesByArrayindex(real_workLongTimeIndex.get(0)[0]);
}
}
}else {
String next_beginwork_time = "";
if(changeType == 2){
ShiftInfoBean next_shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, splitDate, false);
if(next_shiftInfoBean != null){
List<int[]> workLongTimeIndex = next_shiftInfoBean.getWorkLongTimeIndex();
List<int[]> real_workLongTimeIndex = Lists.newArrayList();
get_real_workLongTimeIndex(workLongTimeIndex,real_workLongTimeIndex,next_shiftInfoBean,kqTimesArrayComInfo,splitBean);
if(real_workLongTimeIndex != null && !real_workLongTimeIndex.isEmpty()){
next_beginwork_time = kqTimesArrayComInfo.getTimesByArrayindex(real_workLongTimeIndex.get(0)[0]);
}
}
}
if(next_beginwork_time.length() > 0){
pre_overtime_cut_point = next_beginwork_time;
}
}
}else{
pre_overtime_cut_point = preKqOvertimeRulesDetailEntity.getCut_point();
}
if(pre_overtime_cut_point.length() == 0){
pre_overtime_cut_point = "00:00";
}
}
return pre_overtime_cut_point;
}
/**
*
* @param initArrays
* @param overRulesDetailMap
* @param nextChangeType_key
* @param next_changeType
* @param next_beginwork_time
*/
public void handle_changeType_1(int[] initArrays,
Map<String, KQOvertimeRulesDetailEntity> overRulesDetailMap,
String nextChangeType_key, int next_changeType, String next_beginwork_time){
KQOvertimeRulesDetailEntity nextKqOvertimeRulesDetailEntity = overRulesDetailMap.get(nextChangeType_key);
// if(nextKqOvertimeRulesDetailEntity != null){
// if(next_changeType == 2){
// //如果明日是工作日 工作日如果设置了上班前分钟,会导致加班归属被设置的分钟数给切断,上班前某些部分属于今天不属于昨日
// int overtimeEnable = nextKqOvertimeRulesDetailEntity.getOvertimeEnable();
// if(overtimeEnable == 1){
// KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
// int before_startTime = nextKqOvertimeRulesDetailEntity.getBefore_startTime();
// int has_cut_point = nextKqOvertimeRulesDetailEntity.getHas_cut_point();
// if(has_cut_point != 1){
// before_startTime = -1;
// }
// int next_beginwork_time_index = kqTimesArrayComInfo.getArrayindexByTimes(next_beginwork_time);
// if(before_startTime > -1){
// int before_next_beginwork_time_index = next_beginwork_time_index - before_startTime;
// if(before_next_beginwork_time_index > 0 && before_next_beginwork_time_index < next_beginwork_time_index){
// before_next_beginwork_time_index = kqTimesArrayComInfo.turn24to48TimeIndex(before_next_beginwork_time_index);
// next_beginwork_time_index = kqTimesArrayComInfo.turn24to48TimeIndex(next_beginwork_time_index);
// Arrays.fill(initArrays, before_next_beginwork_time_index,next_beginwork_time_index,-1);
// }
// }
// }
// }
// }
}
/**
*
* @param restTimeMap
* @param changeType_key
* @param kqTimesArrayComInfo
* @param shouldAcross
* @param initArrays
*/
public void handle_resttime(Map<String, List<String[]>> restTimeMap, String changeType_key, KQTimesArrayComInfo kqTimesArrayComInfo, boolean shouldAcross, int[] initArrays) {
if(restTimeMap.containsKey(changeType_key)){
List<String[]> restTimeList = restTimeMap.get(changeType_key);
//再把休息时间填充上去
if(!restTimeList.isEmpty()){
for(int k =0 ; k < restTimeList.size() ; k++){
String[] restTimes = restTimeList.get(k);
if(restTimes.length == 2){
int restStart = kqTimesArrayComInfo.getArrayindexByTimes(restTimes[0]);
int restEnd = kqTimesArrayComInfo.getArrayindexByTimes(restTimes[1]);
if(shouldAcross && restEnd == 1439){
//针对跨天的休息时段单独处理排除掉23:59-00:00的时间
restEnd = 1440;
}
Arrays.fill(initArrays, restStart, restEnd, 1);
}
}
}
}
}
/**
*
* @param curMins
* @param restTimeMap
* @param changeType_key
* @return
*/
public int handle_restlength(int curMins, Map<String, List<String[]>> restTimeMap, String changeType_key) {
if(restTimeMap.containsKey(changeType_key)) {
List<String[]> restTimeList = restTimeMap.get(changeType_key);
//再把休息时间填充上去
if (!restTimeList.isEmpty()) {
for(int k = restTimeList.size()-1 ; k >= 0 ; k--) {
String[] restTimes = restTimeList.get(k);
if (restTimes.length == 2) {
//overlength 是满多少小时 cutlength是减去多少小时
double overlength = Util.getDoubleValue(restTimes[0],-1);
double cutlength = Util.getDoubleValue(restTimes[1],-1);
if(overlength > -1 && cutlength > -1){
double min_overlength = overlength * 60;
double min_cutlength = cutlength * 60;
if(curMins >= min_overlength){
curMins = (int) (curMins-min_cutlength);
break;
}
}
}
}
}
}
return curMins;
}
/**
*
* @param initArrays
* @param resourceid
* @param splitDate
* @param before_startTime
* @param startTime
* @param fromTime_index
* @param kqTimesArrayComInfo
* @param splitBean
* @param toTime_index
* @return
*/
public boolean handle_changeType_2(int[] initArrays, String resourceid, String splitDate,
int before_startTime, int startTime, int fromTime_index,
KQTimesArrayComInfo kqTimesArrayComInfo, SplitBean splitBean, int toTime_index){
boolean isok = true;
ShiftInfoBean cur_shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, splitDate, false);
if(cur_shiftInfoBean != null){
splitBean.setSerialid(cur_shiftInfoBean.getSerialid());
List<int[]> workLongTimeIndex = cur_shiftInfoBean.getWorkLongTimeIndex();
List<int[]> real_workLongTimeIndex = Lists.newArrayList();
get_real_workLongTimeIndex(workLongTimeIndex,real_workLongTimeIndex,cur_shiftInfoBean,kqTimesArrayComInfo,splitBean);
if(real_workLongTimeIndex != null && !real_workLongTimeIndex.isEmpty()){
int all_firstworktime = 0;
int all_lastworktime = 0;
boolean need_middle_time = false;
for(int k = 0 ; k < real_workLongTimeIndex.size() ; k++){
int workLongTimeStartIndex = real_workLongTimeIndex.get(k)[0];
int workLongTimeEndIndex = real_workLongTimeIndex.get(k)[1];
if(k == 0){
if(before_startTime > -1){
int before_workLongTimeStartIndex = workLongTimeStartIndex-before_startTime;
if(before_workLongTimeStartIndex > 0){
//从前一天的加班归属点到今天的上班前开始加班点,这段时间属于两不靠。需要排除
if(fromTime_index < before_workLongTimeStartIndex){
Arrays.fill(initArrays, fromTime_index,before_workLongTimeStartIndex,-1);
}
}
}
all_firstworktime = workLongTimeStartIndex;
}
if(k == real_workLongTimeIndex.size()-1){
if(startTime > -1){
int after_workLongTimeEndIndex = workLongTimeEndIndex+startTime;
if(workLongTimeEndIndex < after_workLongTimeEndIndex){
Arrays.fill(initArrays, workLongTimeEndIndex,after_workLongTimeEndIndex,-1);
}
}
all_lastworktime = workLongTimeEndIndex;
}
if(!need_middle_time){
//目前标准加班,一天多次打卡的话是不算中间时间的,只算上班前和下班后的加班
}else{
//这个里面是可以算一天多次打卡的话是中间时间的
Arrays.fill(initArrays, workLongTimeStartIndex,workLongTimeEndIndex,1);
}
}
if(!need_middle_time){
Arrays.fill(initArrays, all_firstworktime,all_lastworktime,1);
}
List<int[]> restLongTimeIndex = cur_shiftInfoBean.getRestLongTimeIndex();
if(restLongTimeIndex != null && !restLongTimeIndex.isEmpty()){
for (int k = 0; k < restLongTimeIndex.size(); k++) {
//休息时段填充2
Arrays.fill(initArrays, restLongTimeIndex.get(k)[0], restLongTimeIndex.get(k)[1], 2);
}
}
}else {
System.out.println("error");
isok = false;
}
}else {
System.out.println("error");
isok = false;
}
return isok;
}
/**
*
* @param restTimeMap
* @param initArrays
* @param overRulesDetailMap
* @param nextChangeType_key
* @param next_changeType
* @param next_beginwork_time
*/
public void handle_changeType_3(int[] initArrays,
Map<String, KQOvertimeRulesDetailEntity> overRulesDetailMap,
String nextChangeType_key, int next_changeType, String next_beginwork_time){
KQOvertimeRulesDetailEntity nextKqOvertimeRulesDetailEntity = overRulesDetailMap.get(nextChangeType_key);
// if(nextKqOvertimeRulesDetailEntity != null){
// if(next_changeType == 2){
// //如果明日是工作日 工作日如果设置了上班前分钟,会导致加班归属被设置的分钟数给切断,上班前某些部分属于今天不属于昨日
// int overtimeEnable = nextKqOvertimeRulesDetailEntity.getOvertimeEnable();
// if(overtimeEnable == 1){
// KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
// int before_startTime = nextKqOvertimeRulesDetailEntity.getBefore_startTime();
// int has_cut_point = nextKqOvertimeRulesDetailEntity.getHas_cut_point();
// if(has_cut_point != 1){
// before_startTime = -1;
// }
// int next_beginwork_time_index = kqTimesArrayComInfo.getArrayindexByTimes(next_beginwork_time);
// if(before_startTime > -1){
// int before_next_beginwork_time_index = next_beginwork_time_index - before_startTime;
// if(before_next_beginwork_time_index > 0 && before_next_beginwork_time_index < next_beginwork_time_index){
// before_next_beginwork_time_index = kqTimesArrayComInfo.turn24to48TimeIndex(before_next_beginwork_time_index);
// next_beginwork_time_index = kqTimesArrayComInfo.turn24to48TimeIndex(next_beginwork_time_index);
// Arrays.fill(initArrays, before_next_beginwork_time_index,next_beginwork_time_index,-1);
// }
// }
// }
// }
// }
}
public void getDurationByRule(SplitBean splitBean) {
double D_Mins = splitBean.getD_Mins();
int workmins = splitBean.getWorkmins();
String durationrule = splitBean.getDurationrule();
if("3".equalsIgnoreCase(durationrule) || "5".equalsIgnoreCase(durationrule)
|| "6".equalsIgnoreCase(durationrule)){
double d_hour = D_Mins/60.0;
splitBean.setDuration(KQDurationCalculatorUtil.getDurationRound5(""+d_hour));
}else if("1".equalsIgnoreCase(durationrule)){
double d_day = D_Mins/workmins;
splitBean.setDuration(KQDurationCalculatorUtil.getDurationRound5(""+d_day));
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,739 @@
package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.engine.kq.biz.chain.cominfo.HalfShiftComIndex;
import com.engine.kq.biz.chain.cominfo.RestShiftComIndex;
import com.engine.kq.biz.chain.cominfo.ShiftComIndex;
import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean;
import com.engine.kq.biz.chain.cominfo.WorkShiftComIndex;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.entity.TimeScopeEntity;
import com.engine.kq.log.KQLog;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.commons.lang.math.NumberUtils;
import weaver.cache.CacheBase;
import weaver.cache.CacheColumn;
import weaver.cache.CacheColumnType;
import weaver.cache.CacheItem;
import weaver.cache.CacheMap;
import weaver.cache.PKColumn;
import weaver.conn.RecordSet;
import weaver.general.Util;
/**
*
*/
public class KQShiftManagementComInfo extends CacheBase implements Serializable {
/*
* : initCache
*/
protected static String TABLE_NAME = "";
/*
* : initCache
* sqlwherewhere
*/
protected static String TABLE_WHERE = null;
/*
* : initCache sqlorder
* byorder by
*
*/
protected static String TABLE_ORDER = null;
@PKColumn(type = CacheColumnType.NUMBER)
protected static String PK_NAME = "id";
@CacheColumn
protected static int shiftbean;
@CacheColumn
protected static int color;
@CacheColumn
protected static int isoffdutyfreecheck;
@CacheColumn
protected static int shiftonoffworkcount;
@CacheColumn
protected static int serial;
@CacheColumn
protected static int isresttimeopen;
@CacheColumn
protected static int worktime;
@CacheColumn
protected static int punchsetting;
@CacheColumn
protected static int cardRemind;
@CacheColumn
protected static int cardRemOfSignIn;
@CacheColumn
protected static int minsBeforeSignIn;
@CacheColumn
protected static int cardRemOfSignOut;
@CacheColumn
protected static int minsAfterSignOut;
@CacheColumn
protected static int remindMode;
@CacheColumn
protected static int remindOnPC;
private KQLog kqLog = new KQLog();
@Override
public CacheItem initCache(String key) {
if (key == null || "".equals(key.trim())) {
return null;
}
CacheMap localData = createCacheMap();
String sql = "";
kqLog = new KQLog();
ConcurrentHashMap<String, Object> resourceKQGroups = new ConcurrentHashMap<>();
//考勤组优先级
try {
ConcurrentHashMap<String,Object> shiftInfoBeanMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> idMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> colorsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isoffdutyfreechecksMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> shiftonoffworkcountsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> serialsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isresttimeopensMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> worktimesMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> punchsettingsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemindMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsBeforeSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsAfterSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindModeMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindOnPCMap = new ConcurrentHashMap<>();
RecordSet rs = new RecordSet();
String getShiftInfo = "select * from kq_ShiftManagement where 1=1 and id="+key+" order by id ";
rs.execute(getShiftInfo);
while(rs.next()){
String serialid = rs.getString("id");
String isresttimeopen = rs.getString("isresttimeopen");
String color = rs.getString("color");
String shiftonoffworkcount = rs.getString("shiftonoffworkcount");
String worktime = rs.getString("worktime");
String serial = rs.getString("serial");
String punchsetting = "1";
String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck");
String cardRemind = rs.getString("cardRemind");
String cardRemOfSignIn = rs.getString("cardRemOfSignIn");
String minsBeforeSignIn = rs.getString("minsBeforeSignIn");
String cardRemOfSignOut = rs.getString("cardRemOfSignOut");
String minsAfterSignOut = rs.getString("minsAfterSignOut");
String remindMode = rs.getString("remindMode");
String remindOnPC = rs.getString("remindOnPC");
String halfcalrule = rs.getString("halfcalrule");
halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule;
String halfcalpoint = rs.getString("halfcalpoint");
String halfcalpoint2cross = rs.getString("halfcalpoint2cross");
getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross);
idMap.put(serialid, serialid);
colorsMap.put(serialid, color);
isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck);
shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount);
serialsMap.put(serialid, serial);
isresttimeopensMap.put(serialid, isresttimeopen);
worktimesMap.put(serialid, worktime);
punchsettingsMap.put(serialid, punchsetting);
cardRemindMap.put(serialid,cardRemind);
cardRemOfSignInMap.put(serialid,cardRemOfSignIn);
minsBeforeSignInMap.put(serialid,minsBeforeSignIn);
cardRemOfSignOutMap.put(serialid,cardRemOfSignOut);
minsAfterSignOutMap.put(serialid,minsAfterSignOut);
remindModeMap.put(serialid,remindMode);
remindOnPCMap.put(serialid,remindOnPC);
}
if(shiftInfoBeanMap.size()>0){
CacheItem cacheItem = createCacheItem();
Iterator<Entry<String, Object>> iterator = shiftInfoBeanMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> entry = iterator.next();
String id = entry.getKey();
Object value = entry.getValue();
cacheItem.set(PK_INDEX, id);
cacheItem.set(shiftbean, value);
cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id));
cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id));
cacheItem.set(serial, serialsMap.get(id));
cacheItem.set(isresttimeopen, isresttimeopensMap.get(id));
cacheItem.set(worktime, worktimesMap.get(id));
cacheItem.set(punchsetting, punchsettingsMap.get(id));
cacheItem.set(cardRemind,cardRemindMap.get(id));
cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id));
cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id));
cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id));
cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id));
cacheItem.set(remindMode,remindModeMap.get(id));
cacheItem.set(remindOnPC,remindOnPCMap.get(id));
modifyCacheItem(id, cacheItem);
}
return cacheItem;
}
} catch (Exception e) {
kqLog.info(e);
}
return null;
}
@Override
public CacheMap initCache() {
CacheMap localData = createCacheMap();
String sql = "";
kqLog = new KQLog();
ConcurrentHashMap<String, Object> resourceKQGroups = new ConcurrentHashMap<>();
//考勤组优先级
try {
ConcurrentHashMap<String,Object> shiftInfoBeanMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> idMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> colorsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isoffdutyfreechecksMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> shiftonoffworkcountsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> serialsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isresttimeopensMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> worktimesMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> punchsettingsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemindMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsBeforeSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsAfterSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindModeMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindOnPCMap = new ConcurrentHashMap<>();
RecordSet rs = new RecordSet();
String getShiftInfo = "select * from kq_ShiftManagement where 1=1 order by id ";
rs.execute(getShiftInfo);
while(rs.next()){
String serialid = rs.getString("id");
String isresttimeopen = rs.getString("isresttimeopen");
String color = rs.getString("color");
String shiftonoffworkcount = rs.getString("shiftonoffworkcount");
String worktime = rs.getString("worktime");
String serial = rs.getString("serial");
String punchsetting = "1";
String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck");
String cardRemind = rs.getString("cardRemind");
String cardRemOfSignIn = rs.getString("cardRemOfSignIn");
String minsBeforeSignIn = rs.getString("minsBeforeSignIn");
String cardRemOfSignOut = rs.getString("cardRemOfSignOut");
String minsAfterSignOut = rs.getString("minsAfterSignOut");
String remindMode = rs.getString("remindMode");
String remindOnPC = rs.getString("remindOnPC");
String halfcalrule = rs.getString("halfcalrule");
halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule;
String halfcalpoint = rs.getString("halfcalpoint");
String halfcalpoint2cross = rs.getString("halfcalpoint2cross");
getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross);
idMap.put(serialid, serialid);
colorsMap.put(serialid, color);
isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck);
shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount);
serialsMap.put(serialid, serial);
isresttimeopensMap.put(serialid, isresttimeopen);
worktimesMap.put(serialid, worktime);
punchsettingsMap.put(serialid, punchsetting);
cardRemindMap.put(serialid,cardRemind);
cardRemOfSignInMap.put(serialid,cardRemOfSignIn);
minsBeforeSignInMap.put(serialid,minsBeforeSignIn);
cardRemOfSignOutMap.put(serialid,cardRemOfSignOut);
minsAfterSignOutMap.put(serialid,minsAfterSignOut);
remindModeMap.put(serialid,remindMode);
remindOnPCMap.put(serialid,remindOnPC);
}
if(shiftInfoBeanMap.size()>0){
Iterator<Entry<String, Object>> iterator = shiftInfoBeanMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> entry = iterator.next();
String id = entry.getKey();
Object value = entry.getValue();
CacheItem cacheItem = createCacheItem();
cacheItem.set(PK_INDEX, id);
cacheItem.set(shiftbean, value);
cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id));
cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id));
cacheItem.set(serial, serialsMap.get(id));
cacheItem.set(isresttimeopen, isresttimeopensMap.get(id));
cacheItem.set(worktime, worktimesMap.get(id));
cacheItem.set(punchsetting, punchsettingsMap.get(id));
cacheItem.set(cardRemind,cardRemindMap.get(id));
cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id));
cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id));
cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id));
cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id));
cacheItem.set(remindMode,remindModeMap.get(id));
cacheItem.set(remindOnPC,remindOnPCMap.get(id));
modifyCacheItem(id, cacheItem);
localData.put(id, cacheItem);
}
}
} catch (Exception e) {
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
return localData;
}
public String getId(){
return (String)getRowValue(PK_INDEX);
}
public String getColor() { return (String)getRowValue(color); }
public String getColor(String key)
{
return (String)getValue(color,key);
}
public String getIsoffdutyfreecheck() { return (String)getRowValue(isoffdutyfreecheck); }
public String getIsoffdutyfreecheck(String key)
{
return (String)getValue(isoffdutyfreecheck,key);
}
public String getShiftonoffworkcounts() { return (String)getRowValue(shiftonoffworkcount); }
public String getShiftonoffworkcounts(String key)
{
return (String)getValue(shiftonoffworkcount,key);
}
public String getSerial() { return (String)getRowValue(serial); }
public String getSerial(String key)
{
return (String)getValue(serial,key);
}
public String getIsresttimeopen() { return (String)getRowValue(isresttimeopen); }
public String getIsresttimeopen(String key)
{
return (String)getValue(isresttimeopen,key);
}
public String getWorktime() { return (String)getRowValue(worktime); }
public String getWorktime(String key)
{
return (String)getValue(worktime,key);
}
public String getPunchsetting() {
return (String) getRowValue(punchsetting);
}
public String getPunchsetting(String key) {
return (String) getValue(punchsetting, key);
}
public String getCardRemind() {
return (String) getRowValue(cardRemind);
}
public String getCardRemind(String key) {
return (String) getValue(cardRemind,key);
}
public String getCardRemOfSignIn() {
return (String) getRowValue(cardRemOfSignIn);
}
public String getCardRemOfSignIn(String key) {
return (String) getValue(cardRemOfSignIn, key);
}
public String getMinsBeforeSignIn() {
return (String) getRowValue(minsBeforeSignIn);
}
public String getMinsBeforeSignIn(String key) {
return (String) getValue(minsBeforeSignIn, key);
}
public String getCardRemOfSignOut() {
return (String) getRowValue(cardRemOfSignOut);
}
public String getCardRemOfSignOut(String key) {
return (String) getValue(cardRemOfSignOut, key);
}
public String getMinsAfterSignOut() {
return (String) getRowValue(minsAfterSignOut);
}
public String getMinsAfterSignOut(String key) {
return (String) getValue(minsAfterSignOut, key);
}
public String getRemindMode() {
return (String) getRowValue(remindMode);
}
public String getRemindMode(String key) {
return (String) getValue(remindMode, key);
}
public String getRemindOnPC() {
return (String) getRowValue(remindOnPC);
}
public String getRemindOnPC(String key) {
return (String) getValue(remindOnPC, key);
}
private void getShiftInfoBean(String serialid, String isresttimeopen, String worktime,
String punchsettings,
ConcurrentHashMap<String, Object> serialMap,
String halfcalrule,String halfcalpoint,String halfcalpoint2cross) throws Exception {
Map<String,Object> workTimeMap = new HashMap<>();
int workmins = 0;
List<Object> workTimes = Collections.synchronizedList(new ArrayList<>());
List<Object> restTimes = Collections.synchronizedList(new ArrayList<>());
KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo();
KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo();
workTimes = kqShiftOnOffWorkSectionComInfo.getWorkSectionTimes(serialid);
if(workTimes != null && !workTimes.isEmpty()){
if("1".equalsIgnoreCase(isresttimeopen)) {
//如果开启了才去判断
restTimes = kqShiftRestTimeSectionComInfo.getRestSectionTimes(serialid);
}
if(NumberUtils.isNumber(worktime)){
if(worktime.indexOf('.') == -1){
workmins = Util.getIntValue(worktime,0);
}else {
worktime = worktime.substring(0,worktime.indexOf('.'));
workmins = Util.getIntValue(worktime,0);
}
}else{
workmins = 0;
kqLog.info("班次有问题serialid:"+serialid+"工作时长为:"+worktime);
}
workTimeMap.put("workTime", workTimes);
workTimeMap.put("restTime", restTimes);
workTimeMap.put("serialid", serialid);
//工作时长分钟数
workTimeMap.put("workmins", workmins+"");
workTimeMap.put("punchsettings", punchsettings);
workTimeMap.put("isresttimeopen", isresttimeopen);
workTimeMap.put("halfcalrule", halfcalrule);
workTimeMap.put("halfcalpoint", halfcalpoint);
workTimeMap.put("halfcalpoint2cross", halfcalpoint2cross);
ShiftInfoCominfoBean shiftInfoCominfoBean = setShiftInfoBean(workTimeMap);
serialMap.put(serialid, shiftInfoCominfoBean);
}
}
private ShiftInfoCominfoBean setShiftInfoBean(Map<String,Object> workTimeMap) throws Exception {
ShiftComIndex workComIndex = new WorkShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005306,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
ShiftComIndex restComIndex = new RestShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005307,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
ShiftComIndex halfComIndex = new HalfShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005308,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
//创建执行链
//前一天的都执行完了,去获取当天工作时段,再执行半天的规则
workComIndex.setDuration(restComIndex);
//执行完了半天的规则,再最后判断休息的时段
restComIndex.setDuration(halfComIndex);
ShiftInfoCominfoBean shiftInfoCominfoBean = new ShiftInfoCominfoBean();
workComIndex.handleDuration(shiftInfoCominfoBean);
return shiftInfoCominfoBean;
}
/**
*
* @param workdate
* @param serialidInfo
* @param containYesterday
* @return
*/
public Map<String,Object> getWorkButton(String workdate,Map<String,Object> serialidInfo, boolean containYesterday){
Map<String,Object> shiftMap = new HashMap<>();
//考勤按钮还是走缓存
KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis();
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
if(serialidInfo != null && !serialidInfo.isEmpty()){
LocalDate preLocalDate = LocalDate.parse(workdate);
String preSplitDate = "";
preLocalDate = preLocalDate.minusDays(1);
preSplitDate = preLocalDate.format(dateFormatter);
String serialid = Util.null2String(serialidInfo.get(workdate));
String preSerialid = Util.null2String(serialidInfo.get(preSplitDate));
if(containYesterday){
if(Util.getIntValue(preSerialid) > 0){
ShiftInfoCominfoBean pre_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(preSerialid);
List<Object> timelineList = pre_shiftInfoCominfoBean.getTimelineList();
if(timelineList!=null && !timelineList.isEmpty()){
shiftMap.put("pre_timelineList", timelineList);
}
shiftMap.put("pre_isAcross", pre_shiftInfoCominfoBean.getIsAcross());
shiftMap.put("pre_allWorkTime", pre_shiftInfoCominfoBean.getAllWorkTime());
shiftMap.put("pre_allAcrossWorkTime", pre_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftMap.put("pre_signTime", pre_shiftInfoCominfoBean.getSignWorkTime());
shiftMap.put("pre_restTime", pre_shiftInfoCominfoBean.getRestAcrossLongTime());
}
}
if(Util.getIntValue(serialid) > 0){
ShiftInfoCominfoBean cur_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(serialid);
Map<String,Object> shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false);
List<Object> timelineList = cur_shiftInfoCominfoBean.getTimelineList();
if(timelineList!=null && !timelineList.isEmpty()){
shiftMap.put("timelineList", timelineList);
}
shiftMap.put("isAcross", cur_shiftInfoCominfoBean.getIsAcross());
shiftMap.put("allWorkTime", cur_shiftInfoCominfoBean.getAllWorkTime());
shiftMap.put("allAcrossWorkTime", cur_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime());
shiftMap.put("restTime", cur_shiftInfoCominfoBean.getRestAcrossLongTime());
if(shiftRuleMap != null && !shiftRuleMap.isEmpty()){
shiftMap.put("shiftRuleMap", shiftRuleMap);
}
}
}
return shiftMap;
}
/**
*
* @param workdate
* @param serialidInfo
* @param containYesterday
* @return
* shiftInfoBean ,0-24
* shiftLongInfoBean 0-48
*/
public Map<String,Object> getWorkDuration(String workdate,Map<String,Object> serialidInfo,boolean containYesterday){
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Map<String,Object> dateWorkTimeMap = new HashMap<>();
LocalDate preLocalDate = LocalDate.parse(workdate);
String preSplitDate = "";
preLocalDate = preLocalDate.minusDays(1);
preSplitDate = preLocalDate.format(dateFormatter);
if(serialidInfo != null && !serialidInfo.isEmpty()){
String preSerialid = Util.null2String(serialidInfo.get(preSplitDate));
String serialid = Util.null2String(serialidInfo.get(workdate));
ShiftInfoBean shiftInfoBean = new ShiftInfoBean();
shiftInfoBean.setPreSplitDate(preSplitDate);
shiftInfoBean.setSplitDate(workdate);
shiftInfoBean.setD_Mins(0.0);
shiftInfoBean.setPreSerialid(preSerialid);
shiftInfoBean.setSerialid(serialid);
if(containYesterday){
if(Util.getIntValue(serialid) > 0 || Util.getIntValue(preSerialid) > 0){
fillShiftInfoBean(shiftInfoBean, preSerialid, serialid);
dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean);
}
}else{
if(Util.getIntValue(serialid) > 0){
fillShiftInfoBean(shiftInfoBean, preSerialid, serialid);
dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean);
}
}
}
return dateWorkTimeMap;
}
/**
* id+
* @param workdate
* @param serialidInfo
* @return
*/
public Map<String,Object> getWorkTimeMap(String workdate,Map<String,Object> serialidInfo){
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Map<String,Object> dateWorkTimeMap = new HashMap<>();
LocalDate preLocalDate = LocalDate.parse(workdate);
String preSplitDate = "";
preLocalDate = preLocalDate.minusDays(1);
preSplitDate = preLocalDate.format(dateFormatter);
if(serialidInfo != null && !serialidInfo.isEmpty()){
String preSerialid = Util.null2String(serialidInfo.get(preSplitDate));
String serialid = Util.null2String(serialidInfo.get(workdate));
getShiftInfoBeanMap(dateWorkTimeMap,preSerialid, serialid);
}
return dateWorkTimeMap;
}
/**
*
* @param dateWorkTimeMap
* @param preSerialid
* @param serialid
*/
private void getShiftInfoBeanMap(Map<String,Object> dateWorkTimeMap,String preSerialid, String serialid) {
ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid);
if(cur_shiftInfoCominfoBean != null){
dateWorkTimeMap.put("restTime",cur_shiftInfoCominfoBean.getRestAcrossLongTime());
dateWorkTimeMap.put("workTime",cur_shiftInfoCominfoBean.getWorkAcrossLongTime());
dateWorkTimeMap.put("workMins",cur_shiftInfoCominfoBean.getWorkmins());
dateWorkTimeMap.put("isAcross",cur_shiftInfoCominfoBean.getIsAcross());
dateWorkTimeMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime());
}
}
/**
*
* @param shiftInfoBean
* @param preSerialid
* @param serialid
*/
private void fillShiftInfoBean(ShiftInfoBean shiftInfoBean,String preSerialid,String serialid){
ShiftInfoCominfoBean pre_shiftInfoCominfoBean = getShiftInfoCominfoBean(preSerialid);
ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid);
Map<String,Object> pre_shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(preSerialid,false);
Map<String,Object> shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false);
//把前一个班次的填充好
if(pre_shiftInfoCominfoBean != null){
shiftInfoBean.setPreWorkIndex(pre_shiftInfoCominfoBean.getPreWorkTimeIndex());
shiftInfoBean.setPreWorkAcrossIndex(pre_shiftInfoCominfoBean.getWorkAcrossTimeIndex());
shiftInfoBean.setPreWorkMinsAcrossIndex(pre_shiftInfoCominfoBean.getWorkPunchMins());
shiftInfoBean.setPreRestIndex(pre_shiftInfoCominfoBean.getPreRestTimeIndex());
shiftInfoBean.setPreHalfWorkIndex(pre_shiftInfoCominfoBean.getHalfWorkIndex());
shiftInfoBean.setPreWorkmins(pre_shiftInfoCominfoBean.getWorkmins());
shiftInfoBean.setPreAllWorkTime(pre_shiftInfoCominfoBean.getAllWorkTime());
shiftInfoBean.setPreAllAcrossWorkTime(pre_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftInfoBean.setPreAllRestTime(pre_shiftInfoCominfoBean.getAllRestTime());
shiftInfoBean.setPreAllAcrossRestTime(pre_shiftInfoCominfoBean.getAllAcrossRestTime());
shiftInfoBean.setPreSerialid(preSerialid);
shiftInfoBean.setIsPreAcross(pre_shiftInfoCominfoBean.getIsAcross());
shiftInfoBean.setShiftRuleMap(pre_shiftRuleMap);
}
//把当前班次的填充好
if(cur_shiftInfoCominfoBean != null){
shiftInfoBean.setWorkIndex(cur_shiftInfoCominfoBean.getWorkTimeIndex());
shiftInfoBean.setWorkAcrossIndex(cur_shiftInfoCominfoBean.getWorkAcrossTimeIndex());
shiftInfoBean.setWorkMinsAcrossIndex(cur_shiftInfoCominfoBean.getWorkPunchMins());
shiftInfoBean.setRestIndex(cur_shiftInfoCominfoBean.getRestTimeIndex());
shiftInfoBean.setHalfWorkIndex(cur_shiftInfoCominfoBean.getHalfWorkIndex());
shiftInfoBean.setWorkmins(cur_shiftInfoCominfoBean.getWorkmins());
shiftInfoBean.setAllWorkTime(cur_shiftInfoCominfoBean.getAllWorkTime());
shiftInfoBean.setAllAcrossWorkTime(cur_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftInfoBean.setAllRestTime(cur_shiftInfoCominfoBean.getAllRestTime());
shiftInfoBean.setAllAcrossRestTime(cur_shiftInfoCominfoBean.getAllAcrossRestTime());
shiftInfoBean.setAllLongWorkTime(cur_shiftInfoCominfoBean.getAllLongWorkTime());
shiftInfoBean.setRestLongTimeIndex(cur_shiftInfoCominfoBean.getRestLongTimeIndex());
shiftInfoBean.setWorkLongTimeIndex(cur_shiftInfoCominfoBean.getWorkLongTimeIndex());
shiftInfoBean.setIsAcross(cur_shiftInfoCominfoBean.getIsAcross());
shiftInfoBean.setSerialid(serialid);
shiftInfoBean.setShiftRuleMap(shiftRuleMap);
if(cur_shiftInfoCominfoBean.getWorkAcrossLongTime() != null){
List<Object> workTime1 = cur_shiftInfoCominfoBean.getWorkAcrossLongTime().stream().collect(Collectors.toList());
List<TimeScopeEntity> lsWorkTime = new KQWorkTime().formatTimeScope(workTime1, false);
shiftInfoBean.setWorkTime(lsWorkTime);
}
if(cur_shiftInfoCominfoBean.getSignWorkTime() != null){
List<Object> signTime1 = cur_shiftInfoCominfoBean.getSignWorkTime().stream().collect(Collectors.toList());
List<TimeScopeEntity> lsSignTime = new KQWorkTime().formatTimeScope(signTime1, true);
shiftInfoBean.setSignTime(lsSignTime);
}
shiftInfoBean.setHalfcalrule(cur_shiftInfoCominfoBean.getHalfcalrule());
shiftInfoBean.setHalfcalpoint(cur_shiftInfoCominfoBean.getHalfcalpoint());
shiftInfoBean.setHalfcalpoint2cross(cur_shiftInfoCominfoBean.getHalfcalpoint2cross());
shiftInfoBean.setWorkAcrossTime(cur_shiftInfoCominfoBean.getWorkAcrossTime());
shiftInfoBean.setEachWorkMins(cur_shiftInfoCominfoBean.getEachWorkMins());
}
}
public void removeShiftManagementCache(){
KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo();
KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo();
kqShiftRestTimeSectionComInfo.removeShiftRestTimeSectionCache();
kqShiftOnOffWorkSectionComInfo.removeShiftWorkSectionCache();
super.removeCache();
//改用redis和staticobj的方式
KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis();
kqShiftManagementRedis.resetShiftValWithRedis();
}
/**
* shiftInfoCominfoBean
* @param serialid
* @return
*/
public ShiftInfoCominfoBean getShiftInfoCominfoBean(String serialid){
// Object object = getObjValue(shiftbean, serialid);
// if(object != null){
// return (ShiftInfoCominfoBean) object;
// }else{
// return null;
// }
//改用redis和staticobj的方式
KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis();
return kqShiftManagementRedis.getShiftInfoBeanMapBySql(serialid);
}
/**
* shiftInfoCominfoBean
* @param workdate
* @param serialidInfo
* @return
*/
public ShiftInfoCominfoBean getShiftInfoCominfoBean(String workdate,Map<String,Object> serialidInfo){
ShiftInfoCominfoBean shiftInfoCominfoBean = null;
if(serialidInfo != null && !serialidInfo.isEmpty()){
String serialid = Util.null2String(serialidInfo.get(workdate));
if(Util.getIntValue(serialid) > 0){
shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid);
}
}
return shiftInfoCominfoBean;
}
}

@ -0,0 +1,289 @@
package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloudstore.dev.api.util.Util_DataCache;
import com.engine.kq.biz.chain.cominfo.HalfShiftComIndex;
import com.engine.kq.biz.chain.cominfo.RestShiftComIndex;
import com.engine.kq.biz.chain.cominfo.ShiftComIndex;
import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean;
import com.engine.kq.biz.chain.cominfo.WorkShiftComIndex;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.entity.TimeScopeEntity;
import com.engine.kq.log.KQLog;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.commons.lang.math.NumberUtils;
import weaver.cache.CacheBase;
import weaver.cache.CacheColumn;
import weaver.cache.CacheColumnType;
import weaver.cache.CacheItem;
import weaver.cache.CacheMap;
import weaver.cache.PKColumn;
import weaver.cluster.CacheManager;
import weaver.cluster.CacheMessage;
import weaver.conn.RecordSet;
import weaver.email.MailReciveStatusUtils;
import weaver.email.domain.AccountStautsBean;
import weaver.general.BaseBean;
import weaver.general.StaticObj;
import weaver.general.Util;
/**
* redis
*/
public class KQShiftManagementRedis {
public static final String KQ_SHIFT_COMINFO_STATUS = "KQ_SHIFT_COMINFO_STATUS";
private static final BaseBean baseBean = new BaseBean();
/**
* E9 radisfalseradistrue使radis
*/
public static boolean isNewSession = false;
/**
* 线
*/
public static ConcurrentHashMap<String, Object> KQ_SHIFT_COMINFO_STATUS_MAP = new ConcurrentHashMap<String, Object>();
// 初始化执行
static {
useNewSessionMode();
}
/**
* redis
*/
public static void useNewSessionMode() {
String status = Util.null2String(baseBean.getPropValue("weaver_new_session", "status")).trim();
isNewSession = "1".equals(status);
}
private KQLog kqLog = new KQLog();
public void getShiftInfoBean(String serialid, String isresttimeopen, String worktime,
String punchsettings,
ConcurrentHashMap<String, ShiftInfoCominfoBean> shiftInfoBeanMap,
String halfcalrule,String halfcalpoint,String halfcalpoint2cross) throws Exception {
Map<String,Object> workTimeMap = new HashMap<>();
int workmins = 0;
List<Object> workTimes = Collections.synchronizedList(new ArrayList<>());
List<Object> restTimes = Collections.synchronizedList(new ArrayList<>());
KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo();
KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo();
workTimes = kqShiftOnOffWorkSectionComInfo.getWorkSectionTimes(serialid);
if(workTimes != null && !workTimes.isEmpty()){
if("1".equalsIgnoreCase(isresttimeopen)) {
//如果开启了才去判断
restTimes = kqShiftRestTimeSectionComInfo.getRestSectionTimes(serialid);
}
if(NumberUtils.isNumber(worktime)){
if(worktime.indexOf('.') == -1){
workmins = Util.getIntValue(worktime,0);
}else {
worktime = worktime.substring(0,worktime.indexOf('.'));
workmins = Util.getIntValue(worktime,0);
}
}else{
workmins = 0;
kqLog.info("班次有问题serialid:"+serialid+"工作时长为:"+worktime);
}
workTimeMap.put("workTime", workTimes);
workTimeMap.put("restTime", restTimes);
workTimeMap.put("serialid", serialid);
//工作时长分钟数
workTimeMap.put("workmins", workmins+"");
workTimeMap.put("punchsettings", punchsettings);
workTimeMap.put("isresttimeopen", isresttimeopen);
workTimeMap.put("halfcalrule", halfcalrule);
workTimeMap.put("halfcalpoint", halfcalpoint);
workTimeMap.put("halfcalpoint2cross", halfcalpoint2cross);
ShiftInfoCominfoBean shiftInfoCominfoBean = setShiftInfoBean(workTimeMap);
shiftInfoBeanMap.put(serialid, shiftInfoCominfoBean);
}
}
public ShiftInfoCominfoBean setShiftInfoBean(Map<String,Object> workTimeMap) throws Exception {
ShiftComIndex workComIndex = new WorkShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005306,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
ShiftComIndex restComIndex = new RestShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005307,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
ShiftComIndex halfComIndex = new HalfShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005308,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
//创建执行链
//前一天的都执行完了,去获取当天工作时段,再执行半天的规则
workComIndex.setDuration(restComIndex);
//执行完了半天的规则,再最后判断休息的时段
restComIndex.setDuration(halfComIndex);
ShiftInfoCominfoBean shiftInfoCominfoBean = new ShiftInfoCominfoBean();
workComIndex.handleDuration(shiftInfoCominfoBean);
return shiftInfoCominfoBean;
}
public ConcurrentHashMap<String,ShiftInfoCominfoBean> getShiftInfoBeanMap() {
ConcurrentHashMap<String,ShiftInfoCominfoBean> shiftInfoBeanMap = new ConcurrentHashMap<>();
kqLog = new KQLog();
try {
RecordSet rs = new RecordSet();
String getShiftInfo = "select * from kq_ShiftManagement where 1=1 order by id ";
rs.executeQuery(getShiftInfo);
while(rs.next()){
String serialid = rs.getString("id");
try {
String isresttimeopen = rs.getString("isresttimeopen");
String worktime = rs.getString("worktime");
String punchsetting = "1";
String halfcalrule = rs.getString("halfcalrule");
halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule;
String halfcalpoint = rs.getString("halfcalpoint");
String halfcalpoint2cross = rs.getString("halfcalpoint2cross");
getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross);
} catch (Exception e) {
kqLog.info("班次缓存报错:getShiftInfoBeanMap:serialid:"+serialid);
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
}
} catch (Exception e) {
kqLog.info("班次缓存报错:getShiftInfoBeanMap:");
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
return shiftInfoBeanMap;
}
public ShiftInfoCominfoBean getShiftInfoBeanMapBySql(String serialid) {
ConcurrentHashMap<String,ShiftInfoCominfoBean> shiftInfoBeanMap = new ConcurrentHashMap<>();
kqLog = new KQLog();
try {
RecordSet rs = new RecordSet();
String getShiftInfo = "select * from kq_ShiftManagement where 1=1 and id=? order by id ";
rs.executeQuery(getShiftInfo,serialid);
if(rs.next()){
String isresttimeopen = rs.getString("isresttimeopen");
String worktime = rs.getString("worktime");
String punchsetting = "1";
String halfcalrule = rs.getString("halfcalrule");
halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule;
String halfcalpoint = rs.getString("halfcalpoint");
String halfcalpoint2cross = rs.getString("halfcalpoint2cross");
getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross);
}
if(shiftInfoBeanMap.containsKey(serialid)){
return shiftInfoBeanMap.get(serialid);
}
} catch (Exception e) {
kqLog.info("班次缓存报错:getShiftInfoBeanMapBySql:");
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
return null;
}
/**
* redis staticobj map
*
*/
public void resetShiftValWithRedis(){
boolean isCluster = StaticObj.getInstance().isCluster();
Map<String, ShiftInfoCominfoBean> shiftInfoBeanMap = getShiftInfoBeanMap();
if(isCluster) {
if(isNewSession) {
try {
Util_DataCache.setObjValWithRedis(KQ_SHIFT_COMINFO_STATUS, shiftInfoBeanMap);
} catch (IOException e) {
baseBean.writeLog(e);
StaticObj staticObj = StaticObj.getInstance();
staticObj.putObject(KQ_SHIFT_COMINFO_STATUS, shiftInfoBeanMap);
sendNotificationToCache(CacheManager.ACTION_UPDATE, KQ_SHIFT_COMINFO_STATUS);
}
}else{
StaticObj staticObj = StaticObj.getInstance();
staticObj.putObject(KQ_SHIFT_COMINFO_STATUS, shiftInfoBeanMap);
sendNotificationToCache(CacheManager.ACTION_UPDATE, KQ_SHIFT_COMINFO_STATUS);
}
} else {
KQ_SHIFT_COMINFO_STATUS_MAP.put(KQ_SHIFT_COMINFO_STATUS, shiftInfoBeanMap);
}
}
public ShiftInfoCominfoBean getShiftInfoBean(String serialid){
ShiftInfoCominfoBean shiftInfoCominfoBean = null;
Map<String, ShiftInfoCominfoBean> shiftInfoBeanMap = getShiftBeanMapValWithRedis();
if(shiftInfoBeanMap == null){
resetShiftValWithRedis();
shiftInfoBeanMap = getShiftBeanMapValWithRedis();
}
if(shiftInfoBeanMap != null && shiftInfoBeanMap.containsKey(serialid)){
shiftInfoCominfoBean = shiftInfoBeanMap.get(serialid);
}
return shiftInfoCominfoBean;
}
public Map<String, ShiftInfoCominfoBean> getShiftBeanMapValWithRedis() {
Map<String, ShiftInfoCominfoBean> shiftInfoBeanMap = null;
boolean isCluster = StaticObj.getInstance().isCluster();
if(isCluster) { // 判断是否是集群环境。true 是集群false非集群
if(isNewSession){
try {
if(Util_DataCache.containsKeyWithRedis(KQ_SHIFT_COMINFO_STATUS)) {
shiftInfoBeanMap = (Map<String, ShiftInfoCominfoBean>) Util_DataCache.getObjValWithRedis(KQ_SHIFT_COMINFO_STATUS);
}
}catch (Exception e){
StaticObj staticObj = StaticObj.getInstance();
shiftInfoBeanMap = (Map<String, ShiftInfoCominfoBean>) staticObj.getObject(KQ_SHIFT_COMINFO_STATUS);
}
}else{
StaticObj staticObj = StaticObj.getInstance();
shiftInfoBeanMap = (Map<String, ShiftInfoCominfoBean>) staticObj.getObject(KQ_SHIFT_COMINFO_STATUS);
}
} else {
shiftInfoBeanMap = (Map<String, ShiftInfoCominfoBean>) KQ_SHIFT_COMINFO_STATUS_MAP.get(KQ_SHIFT_COMINFO_STATUS);
}
return shiftInfoBeanMap;
}
/**
* .
* @param optType
* @param cacheKey
*/
public static void sendNotificationToCache(String optType, String cacheKey) {
StaticObj staticObj = StaticObj.getInstance();
if(staticObj.isCluster()) {
CacheMessage msg = new CacheMessage();
msg.setAction(optType);
msg.setCacheType(cacheKey);
staticObj.sendNotification(msg);
}
}
}

@ -0,0 +1,402 @@
package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.entity.KQGroupEntity;
import com.engine.kq.entity.TimeScopeEntity;
import com.engine.kq.entity.TimeSignScopeEntity;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.log.KQLog;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;
import java.util.*;
public class KQWorkTime extends BaseBean {
private KQLog kqLog = new KQLog();
private boolean isFormat = false;
public WorkTimeEntity getWorkTime(String userId) {
return getWorkTime(userId, null);
}
/**
*
* @param userId
* @param workdate
* @return
*/
public boolean isWorkDay(String userId, String workdate) {
boolean isWorkDay = false;
if(!KQHolidaySetBiz.isHoliday(userId,workdate)) {//不是节假日,且有班次
Map<String, Object> serialInfo = getSerialInfo( userId, workdate, false);
if(!serialInfo.isEmpty()){
if(Util.null2String(serialInfo.get("kqType")).equals("3")){
Map<String, Object> result = (Map<String, Object>) serialInfo.get(workdate);
if(result!=null && result.size()>0 && Util.null2String(result.get("signStart")).length()>0 && Util.null2String(result.get("workMins")).length()>0){
isWorkDay = true;
}
}else{
isWorkDay = Util.getIntValue(Util.null2String(serialInfo.get(workdate)))>0;
}
}
}
return isWorkDay;
}
public Map<String, Object> getWorkButton(String userId, String workdate, boolean containYesterday) {
Map<String, Object> result = new HashMap<>();
try {
KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo();
Map<String,Object> serialInfo = getSerialInfo(userId, workdate, containYesterday);
kqLog.info("考勤组获取成员所在的班次 getWorkButton:serialInfo:"+ serialInfo);
String kqType = Util.null2String(serialInfo.get("kqType"));
if(serialInfo!=null&&serialInfo.size()>0){
if("3".equalsIgnoreCase(kqType)){
//自由班制的单独处理
result = (Map<String, Object>) serialInfo.get(workdate);
if(result != null && !result.isEmpty()){
result.put("isfree", "1");
}else{
result = new HashMap<>();
}
}else{
result = kQShiftManagementComInfo.getWorkButton(workdate,serialInfo,containYesterday);
kqLog.info("考勤组获取成员所在的班次 getWorkButton:result:"+ JSON.toJSONString(result));
}
}
} catch (Exception e) {
writeLog(e);
}
return result;
}
/**
*
*
* @param userId
* @param workdate
* @param containYesterday
* @param isLog
* @return
*/
public Map<String, Object> getWorkDuration(String userId, String workdate,boolean containYesterday,boolean isLog) {
Map<String, Object> result = new HashMap<>();
try {
Map<String,Object> workTimeMap = null;
KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo();
Map<String,Object> serialInfo = getSerialInfo(userId, workdate, true);
if(isLog){
//kqLog.info("考勤组获取成员所在的班次 getWorkDuration:"+serialInfo);
}
if(serialInfo!=null&&serialInfo.size()>0){
String kqType = Util.null2String(serialInfo.get("kqType"));
if("3".equalsIgnoreCase(kqType)){
//自由班制的单独处理
result = (Map<String, Object>) serialInfo.get(workdate);
if(result != null && !result.isEmpty()){
result.put("isfree", "1");
}else{
result = new HashMap<>();
}
}else{
workTimeMap = kQShiftManagementComInfo.getWorkDuration(workdate,serialInfo,containYesterday);
if(workTimeMap!=null){
if(isLog) {
//kqLog.info(
// "考勤组获取成员所在的班次 getWorkDuration:workTimeMap:" + JSON.toJSONString(workTimeMap));
}
result.put("shiftInfoBean",workTimeMap.get("shiftInfoBean"));
}
}
}
} catch (Exception e) {
writeLog(e);
}
return result;
}
/**
*
* @param userId
* @param workdate
* @param containYesterday
* @return
*/
public Map<String, Object> getWorkDuration(String userId, String workdate,boolean containYesterday) {
return getWorkDuration(userId,workdate,containYesterday,true);
}
/**
*
* @param userId
* @param workdate
* @return
*/
public ShiftInfoCominfoBean getShiftInfoCominfoBean(String userId, String workdate) {
ShiftInfoCominfoBean shiftInfoCominfoBean = null;
try {
Map<String,Object> workTimeMap = null;
KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo();
Map<String,Object> serialInfo = getSerialInfo(userId, workdate, false);
if(serialInfo!=null&&serialInfo.size()>0){
shiftInfoCominfoBean = kQShiftManagementComInfo.getShiftInfoCominfoBean(workdate,serialInfo);
}
} catch (Exception e) {
writeLog(e);
}
return shiftInfoCominfoBean;
}
/**
*
* @param userId
* @param workdate
* @return
*/
public WorkTimeEntity getWorkTime(String userId, String workdate) {
WorkTimeEntity workTimeEntity = new WorkTimeEntity();
try {
KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo();
ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit();
Map<String,Object> serialInfo = getSerialInfo(userId, workdate, false);
workTimeEntity.setIsExclude(Util.null2String(serialInfo.get("isExclude")).equals("1"));
workTimeEntity.setGroupId(Util.null2String(serialInfo.get("groupId")));
if(serialInfo!=null&&serialInfo.size()>0) {
String kqType = Util.null2String(serialInfo.get("kqType"));
if(kqType.equals("3")){
Map<String,Object> map = (Map<String,Object>)serialInfo.get(workdate);
workTimeEntity.setGroupId(Util.null2String(serialInfo.get("groupId")));
workTimeEntity.setGroupName(Util.null2String(serialInfo.get("groupName")));
workTimeEntity.setKQType(Util.null2String(kqType));
workTimeEntity.setIsExclude(Util.null2String(serialInfo.get("isExclude")).equals("1"));
if(map!=null) {
workTimeEntity.setSignStart(Util.null2String(map.get("signStart")));
workTimeEntity.setWorkMins(Util.getIntValue(Util.null2String(map.get("workMins"))));
workTimeEntity.setCalmethod(Util.null2String(map.get("calmethod")));
}
}else{
int serialid = Util.getIntValue(Util.null2String(serialInfo.get(workdate)), 0);
if (serialid > 0){
Map<String,Object> dateWorkTimeMap = kQShiftManagementComInfo.getWorkTimeMap(workdate, serialInfo);
workTimeEntity.setGroupId(Util.null2String(serialInfo.get("groupId")));
workTimeEntity.setGroupName(Util.null2String(serialInfo.get("groupName")));
workTimeEntity.setKQType(kqType);
workTimeEntity.setSerialId(""+serialid);
workTimeEntity.setShiftRuleInfo(ShiftManagementToolKit.getShiftRuleInfo(""+serialid,true));
workTimeEntity.setSignTime(formatTimeScope((List<Object>)dateWorkTimeMap.get("signTime"),false));
workTimeEntity.setWorkTime(formatTimeScope((List<Object>)dateWorkTimeMap.get("workTime"),true));
workTimeEntity.setRestTime(formatTimeScope((List<Object>)dateWorkTimeMap.get("restTime"),false));
workTimeEntity.setWorkMins(Util.getIntValue(Util.null2String(dateWorkTimeMap.get("workMins"))));
workTimeEntity.setIsAcross(Util.null2String(dateWorkTimeMap.get("isAcross")));
}
}
}
} catch (Exception e) {
writeLog(e);
}
return workTimeEntity;
}
public List<TimeScopeEntity> formatTimeScope(List<Object> timeScope, boolean needWorkMins){
List<TimeScopeEntity> timeScopes = new ArrayList<>();
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
TimeScopeEntity timeScopeEntity = null;
for(int i=0;timeScope!=null && i<timeScope.size();i++){
Map<String,Object> obj = (Map<String,Object>)timeScope.get(i);
String bengintime_end = Util.null2String(obj.get("bengintime_end"));
String bengintime_end_across = Util.null2String(obj.get("bengintime_end_across"));
String endtime_start = Util.null2String(obj.get("endtime_start"));
String endtime_start_across = Util.null2String(obj.get("endtime_start_across"));
String bengintime_pre_across = Util.null2String(obj.get("bengintime_pre_across"));
timeScopeEntity = new TimeScopeEntity();
timeScopeEntity.setBeginTime(Util.null2String(obj.get("bengintime")));
timeScopeEntity.setBeginTimeAcross(Util.null2String(obj.get("bengintime_across")).equals("1"));//标记是否跨天
timeScopeEntity.setEndTime(Util.null2String(obj.get("endtime")));
timeScopeEntity.setEndTimeAcross(Util.null2String(obj.get("endtime_across")).equals("1"));//标记是否跨天
timeScopeEntity.setBeginTimePreAcross("1".equalsIgnoreCase(bengintime_pre_across));
if(needWorkMins) {
int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(timeScopeEntity.getBeginTime());
int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(timeScopeEntity.getEndTime());
timeScopeEntity.setWorkMins(workEndIdx - workBeginIdx);
}
if((bengintime_end != null && bengintime_end.length() >0) || (endtime_start != null && endtime_start.length() > 0)){
TimeSignScopeEntity timeSignScopeEntity = new TimeSignScopeEntity();
timeSignScopeEntity.setBeginTimeEnd(bengintime_end);
timeSignScopeEntity.setBeginTimeEndAcross("1".equalsIgnoreCase(bengintime_end_across));
timeSignScopeEntity.setEndTimeStart(endtime_start);
timeSignScopeEntity.setEndTimeStartAcross("1".equalsIgnoreCase(endtime_start_across));
timeSignScopeEntity.setBeginTimePreAcross("1".equalsIgnoreCase(bengintime_pre_across));
timeScopeEntity.setTimeSignScopeEntity(timeSignScopeEntity);
}
timeScopes.add(timeScopeEntity);
}
return timeScopes;
}
/**
*
* @param userId
* @param workdate
* @return
*/
public String getSerialIds(String userId, String workdate) {
Map<String, Object> serialInfo = getSerialInfo( userId, workdate, false);
return serialInfo!=null?Util.null2String(serialInfo.get(workdate)):"";
}
/**
*
* @param userId
* @param workdate
* @param containYesterday
* @return
*/
public Map<String,Object> getSerialInfo(String userId, String workdate, boolean containYesterday) {
Map<String, Object> serialInfo = new HashMap<>();
String preworkdate = "";
try {
KQGroupMemberComInfo groupMemberComInfo = new KQGroupMemberComInfo();
groupMemberComInfo.setIsFormat(this.isFormat);
KQFixedSchedulceComInfo kqFixedSchedulceComInfo = new KQFixedSchedulceComInfo();
kqFixedSchedulceComInfo.setFormat(this.isFormat);
KQShiftScheduleComInfo kqShiftScheduleComInfo = new KQShiftScheduleComInfo();
kqShiftScheduleComInfo.setFormat(this.isFormat);
KQGroupEntity kqGroupEntity = groupMemberComInfo.getUserKQGroupInfo(userId,workdate);
ResourceComInfo resourceComInfo = new ResourceComInfo();
preworkdate = DateUtil.addDate(workdate,-1);
if(containYesterday){
Map<String, Object> pre_serialInfo = getSerialInfo(userId, preworkdate, false);
if(pre_serialInfo != null && !pre_serialInfo.isEmpty()){
if(pre_serialInfo.containsKey(preworkdate)){
serialInfo.put(preworkdate,pre_serialInfo.get(preworkdate));//获取前一天的班次
}
}
}
if(kqGroupEntity==null){//不在考勤组内
return serialInfo;
}
//无需考勤人员需要计算考勤时间,但不计算异常状态
// if (("," + kqGroupEntity.getExcludeid() + ",").indexOf("," + userId + ",")>-1) {//排除人员无需计算考勤时间
// return serialInfo;
// }
if (("," + kqGroupEntity.getExcludeid() + ",").indexOf("," + userId + ",")>-1) {//排除人员无需计算考勤时间
serialInfo.put("isExclude","1");
}
String begindate = Util.null2String(resourceComInfo.getCreatedate(userId)).trim();
String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(userId)).trim();
if(companyStartDate.length()!=10){
companyStartDate = "";
}
if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){
begindate=companyStartDate;
}
if(begindate.length()>0 && DateUtil.compDate(begindate,workdate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准
// kqLog.writeLog("getSerialInfo 入职日期不满足条件:userId:"+userId+":workdate:"+workdate+":companyStartDate:"+companyStartDate+":begindate:"+begindate+":DateUtil.compDate(begindate,workdate):"+DateUtil.compDate(begindate,workdate));
return serialInfo;
}
String endDate = Util.null2String(resourceComInfo.getEndDate(userId));
String status = Util.null2String(resourceComInfo.getStatus(userId));
if(status.equals("0")||status.equals("1")||status.equals("2")||status.equals("3")){
//在职
}else{
//其他状态
if(endDate.length()>0 && DateUtil.compDate(endDate,workdate)>0){//人员合同结束日期无需计算考勤
// kqLog.writeLog("getSerialInfo 人员合同结束日期不满足条件:userId:"+userId+":workdate:"+workdate+":endDate:"+endDate+":status:"+status+":DateUtil.compDate(endDate,workdate):"+DateUtil.compDate(endDate,workdate));
return serialInfo;
}
}
String groupid = kqGroupEntity.getId();
String groupname = kqGroupEntity.getGroupname();
String kqtype = kqGroupEntity.getKqtype();
int dayOfweek = DateUtil.getWeek(workdate)-1;
int preDayOfweek = DateUtil.getWeek(preworkdate)-1;
boolean preDayIsHoliday = KQHolidaySetBiz.isHoliday(userId,preworkdate);
boolean isHoliday = KQHolidaySetBiz.isHoliday(userId,workdate);
String serialid = "";
if(!kqtype.equals("2")){//处理调配工作日(除排班外)
if(KQHolidaySetBiz.getChangeType(groupid,preworkdate)==2){
preDayOfweek = KQHolidaySetBiz.getRelatedDay(userId,preworkdate);
}
if(KQHolidaySetBiz.getChangeType(groupid,workdate)==2){
dayOfweek = KQHolidaySetBiz.getRelatedDay(userId,workdate);
}
}
serialInfo.put("groupId",groupid);
serialInfo.put("groupName",groupname);
serialInfo.put("kqType",kqtype);
serialInfo.put("isHoliday",isHoliday);
if (kqtype.equals("1")) {//固定班
// if(containYesterday && !serialInfo.containsKey(preworkdate)) {
// serialid = Util.null2String(kqFixedSchedulceComInfo.getSerialid(groupid,preDayOfweek));
// if(!preDayIsHoliday&&serialid.length()>0 && Util.getIntValue(serialid) > 0){
// serialInfo.put(preworkdate,serialid);//获取前一天的班次
// }
// }
if(!serialInfo.containsKey(workdate)){
serialid = Util.null2String(kqFixedSchedulceComInfo.getSerialid(groupid,dayOfweek));
if( !isHoliday&&serialid.length()>0 && Util.getIntValue(serialid) > 0){
serialInfo.put(workdate, serialid);//获取当天的班次
}
}
} else if (kqtype.equals("2")) {//排班
//先取排班设置里的班次
// serialid = Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,preworkdate));
// if(containYesterday && serialid.length()>0 && !preDayIsHoliday && Util.getIntValue(serialid) > 0){
// serialInfo.put(preworkdate,Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,preworkdate)));//获取前一天的班次
// }
serialid = Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,workdate));
if(serialid.length()>0 && !isHoliday && Util.getIntValue(serialid) > 0){
serialInfo.put(workdate,Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,workdate)));//获取当天的班次
}
} else if (kqtype.equals("3")) {//自由班
List weekDay = Util.splitString2List(kqGroupEntity.getWeekday(), ",");
String signStart = Util.null2String(kqGroupEntity.getSignstart());//签到开始时间
int workMins = Util.getIntValue(Util.getIntValues(""+Util.getDoubleValue(Util.null2String(kqGroupEntity.getWorkhour()))*60));//工作时长
if(signStart.length()>0 && workMins>0) {
String calmethod = Util.null2s(kqGroupEntity.getCalmethod(),"1");
Map<String, Object> map = null;
if (weekDay.contains(""+preDayOfweek) && !preDayIsHoliday) {//前一天
map = new HashMap<>();
map.put("signStart", signStart);
map.put("workMins", workMins);
map.put("calmethod", calmethod);
serialInfo.put(preworkdate, map);
}
if (weekDay.contains(""+dayOfweek) && !isHoliday) {//当前天
map = new HashMap<>();
map.put("signStart", signStart);
map.put("workMins", workMins);
map.put("calmethod", calmethod);
serialInfo.put(workdate, map);
}
}
}
} catch (Exception e) {
writeLog(e);
}
return serialInfo;
}
public void setIsFormat(boolean isFormat){
this.isFormat = isFormat;
}
}

@ -0,0 +1,508 @@
package com.engine.kq.biz.chain.cominfo;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
*/
public class ShiftInfoCominfoBean implements Serializable {
private static final long serialVersionUID = -1735765502081116461L;
/**
*
*/
private List<String[]> preWorkTime;
/**
* 0-24
*/
private List<String[]> workTime;
/**
* 0-24
*/
private List<String[]> workAcrossTime;
/**
*
*/
private List<int[]> preWorkTimeIndex;
/**
* 0-24
*/
private List<int[]> workTimeIndex;
/**
* 0-48
*/
private List<int[]> workLongTimeIndex;
/**
* 0-48
*/
private List<int[]> restLongTimeIndex;
/**
* 48
*/
private List<String> allLongWorkTime;
/**
* 0-24
*/
private List<int[]> workAcrossTimeIndex;
/**
* 48
*/
private List<Map<String,String>> workAcrossLongTime;
/**
* 退
*/
private List<String[][]> workPunchMins;
/**
*
*/
private List<String[]> preRestTime;
/**
* 0-24
*/
private List<String[]> restTime;
/**
* r0-24
*/
private List<String[]> restAcrossTime;
/**
*
*/
private List<int[]> preRestTimeIndex;
/**
* 0-24
*/
private List<int[]> restTimeIndex;
/**
* r0-24
*/
private List<int[]> restAcrossTimeIndex;
/**
* 48
*/
private List<Map<String,String>> restAcrossLongTime;
/**
*
*
*/
private List<String> halfWorkTime;
/**
*
*
*/
private List<int[]> halfWorkIndex;
/**
*
*/
private List<String> allWorkTime;
/**
*
*/
private List<String> allAcrossWorkTime;
/**
*
*/
private List<String> allRestTime;
/**
*
*/
private List<String> allAcrossRestTime;
/**
*
*/
private List<Integer> eachWorkMins;
/**
*
*/
private int workmins;
/**
*
*/
private String serialid;
/**
*
*/
private String isAcross;
/**
*
*/
private String halfcalrule;
/**
*
*/
private String halfcalpoint;
private String halfcalpoint2cross;
private List<Object> timelineList;
/**
* 退
*/
private List<Map<String,String>> signWorkTime;
/**
* allWorkTime
*/
private List<String> allWorkTimeisAcross;
private String uuid = "";
public ShiftInfoCominfoBean() {
this.preWorkTime = new ArrayList<>();
this.workTime = new ArrayList<>();
this.workAcrossTime = new ArrayList<>();
this.preWorkTimeIndex = new ArrayList<>();
this.workTimeIndex = new ArrayList<>();
this.workAcrossTimeIndex = new ArrayList<>();
this.workAcrossLongTime = new ArrayList<>();
this.workPunchMins = new ArrayList<>();
this.preRestTime = new ArrayList<>();
this.restTime = new ArrayList<>();
this.restAcrossTime = new ArrayList<>();
this.preRestTimeIndex = new ArrayList<>();
this.restTimeIndex = new ArrayList<>();
this.restAcrossTimeIndex = new ArrayList<>();
this.restAcrossLongTime = new ArrayList<>();
this.halfWorkTime = new ArrayList<>();
this.allWorkTime = new ArrayList<>();
this.allAcrossWorkTime = new ArrayList<>();
this.allRestTime = new ArrayList<>();
this.allAcrossRestTime = new ArrayList<>();
this.eachWorkMins = new ArrayList<>();
this.workmins = 0;
this.serialid = "";
this.isAcross = "0";
this.halfcalrule = "0";
this.halfWorkIndex = new ArrayList<>();
this.timelineList = new ArrayList<>();
this.workLongTimeIndex = new ArrayList<>();
this.restLongTimeIndex = new ArrayList<>();
this.allLongWorkTime = new ArrayList<>();
this.signWorkTime = new ArrayList<>();
this.allWorkTimeisAcross = new ArrayList<>();
this.uuid = UUID.randomUUID().toString();
this.halfcalpoint = "0";
this.halfcalpoint2cross = "0";
}
public List<String[]> getPreWorkTime() {
return preWorkTime;
}
public void setPreWorkTime(List<String[]> preWorkTime) {
this.preWorkTime = preWorkTime;
}
public List<String[]> getWorkTime() {
return workTime;
}
public void setWorkTime(List<String[]> workTime) {
this.workTime = workTime;
}
public List<String[]> getWorkAcrossTime() {
return workAcrossTime;
}
public void setWorkAcrossTime(List<String[]> workAcrossTime) {
this.workAcrossTime = workAcrossTime;
}
public List<Map<String, String>> getWorkAcrossLongTime() {
return workAcrossLongTime;
}
public void setWorkAcrossLongTime(
List<Map<String, String>> workAcrossLongTime) {
this.workAcrossLongTime = workAcrossLongTime;
}
public List<String[][]> getWorkPunchMins() {
return workPunchMins;
}
public void setWorkPunchMins(List<String[][]> workPunchMins) {
this.workPunchMins = workPunchMins;
}
public List<String> getHalfWorkTime() {
return halfWorkTime;
}
public void setHalfWorkTime(List<String> halfWorkTime) {
this.halfWorkTime = halfWorkTime;
}
public int getWorkmins() {
return workmins;
}
public void setWorkmins(int workmins) {
this.workmins = workmins;
}
public String getSerialid() {
return serialid;
}
public void setSerialid(String serialid) {
this.serialid = serialid;
}
public List<String> getAllWorkTime() {
return allWorkTime;
}
public void setAllWorkTime(List<String> allWorkTime) {
this.allWorkTime = allWorkTime;
}
public List<String> getAllAcrossWorkTime() {
return allAcrossWorkTime;
}
public void setAllAcrossWorkTime(List<String> allAcrossWorkTime) {
this.allAcrossWorkTime = allAcrossWorkTime;
}
public List<String[]> getRestTime() {
return restTime;
}
public void setRestTime(List<String[]> restTime) {
this.restTime = restTime;
}
public String getIsAcross() {
return isAcross;
}
public void setIsAcross(String isAcross) {
this.isAcross = isAcross;
}
public List<String[]> getPreRestTime() {
return preRestTime;
}
public void setPreRestTime(List<String[]> preRestTime) {
this.preRestTime = preRestTime;
}
public List<String[]> getRestAcrossTime() {
return restAcrossTime;
}
public void setRestAcrossTime(List<String[]> restAcrossTime) {
this.restAcrossTime = restAcrossTime;
}
public List<Map<String, String>> getRestAcrossLongTime() {
return restAcrossLongTime;
}
public void setRestAcrossLongTime(
List<Map<String, String>> restAcrossLongTime) {
this.restAcrossLongTime = restAcrossLongTime;
}
public List<String> getAllRestTime() {
return allRestTime;
}
public void setAllRestTime(List<String> allRestTime) {
this.allRestTime = allRestTime;
}
public List<String> getAllAcrossRestTime() {
return allAcrossRestTime;
}
public void setAllAcrossRestTime(List<String> allAcrossRestTime) {
this.allAcrossRestTime = allAcrossRestTime;
}
public List<Integer> getEachWorkMins() {
return eachWorkMins;
}
public void setEachWorkMins(List<Integer> eachWorkMins) {
this.eachWorkMins = eachWorkMins;
}
public List<int[]> getPreWorkTimeIndex() {
return preWorkTimeIndex;
}
public void setPreWorkTimeIndex(List<int[]> preWorkTimeIndex) {
this.preWorkTimeIndex = preWorkTimeIndex;
}
public List<int[]> getWorkTimeIndex() {
return workTimeIndex;
}
public void setWorkTimeIndex(List<int[]> workTimeIndex) {
this.workTimeIndex = workTimeIndex;
}
public List<int[]> getWorkAcrossTimeIndex() {
return workAcrossTimeIndex;
}
public void setWorkAcrossTimeIndex(List<int[]> workAcrossTimeIndex) {
this.workAcrossTimeIndex = workAcrossTimeIndex;
}
public List<int[]> getPreRestTimeIndex() {
return preRestTimeIndex;
}
public void setPreRestTimeIndex(List<int[]> preRestTimeIndex) {
this.preRestTimeIndex = preRestTimeIndex;
}
public List<int[]> getRestTimeIndex() {
return restTimeIndex;
}
public void setRestTimeIndex(List<int[]> restTimeIndex) {
this.restTimeIndex = restTimeIndex;
}
public List<int[]> getRestAcrossTimeIndex() {
return restAcrossTimeIndex;
}
public void setRestAcrossTimeIndex(List<int[]> restAcrossTimeIndex) {
this.restAcrossTimeIndex = restAcrossTimeIndex;
}
public List<int[]> getHalfWorkIndex() {
return halfWorkIndex;
}
public void setHalfWorkIndex(List<int[]> halfWorkIndex) {
this.halfWorkIndex = halfWorkIndex;
}
public List<Object> getTimelineList() {
return timelineList;
}
public void setTimelineList(List<Object> timelineList) {
this.timelineList = timelineList;
}
public List<int[]> getWorkLongTimeIndex() {
return workLongTimeIndex;
}
public void setWorkLongTimeIndex(List<int[]> workLongTimeIndex) {
this.workLongTimeIndex = workLongTimeIndex;
}
public List<int[]> getRestLongTimeIndex() {
return restLongTimeIndex;
}
public void setRestLongTimeIndex(List<int[]> restLongTimeIndex) {
this.restLongTimeIndex = restLongTimeIndex;
}
public List<String> getAllLongWorkTime() {
return allLongWorkTime;
}
public void setAllLongWorkTime(List<String> allLongWorkTime) {
this.allLongWorkTime = allLongWorkTime;
}
public List<Map<String, String>> getSignWorkTime() {
return signWorkTime;
}
public void setSignWorkTime(
List<Map<String, String>> signWorkTime) {
this.signWorkTime = signWorkTime;
}
public List<String> getAllWorkTimeisAcross() {
return allWorkTimeisAcross;
}
public void setAllWorkTimeisAcross(List<String> allWorkTimeisAcross) {
this.allWorkTimeisAcross = allWorkTimeisAcross;
}
public String getHalfcalrule() {
return halfcalrule;
}
public void setHalfcalrule(String halfcalrule) {
this.halfcalrule = halfcalrule;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getHalfcalpoint() {
return halfcalpoint;
}
public void setHalfcalpoint(String halfcalpoint) {
this.halfcalpoint = halfcalpoint;
}
public String getHalfcalpoint2cross() {
return halfcalpoint2cross;
}
public void setHalfcalpoint2cross(String halfcalpoint2cross) {
this.halfcalpoint2cross = halfcalpoint2cross;
}
}

@ -0,0 +1,35 @@
package com.engine.kq.biz.chain.cominfo;
import com.engine.kq.biz.KQTimesArrayComInfo;
import java.util.List;
import java.util.Map;
import weaver.general.Util;
/**
*
*/
public class WorkShiftComIndex extends ShiftComIndex {
public WorkShiftComIndex(String name,Map<String,Object> workTimeMap){
super(name,workTimeMap);
}
@Override
public void handleDuration(ShiftInfoCominfoBean shiftInfoCominfoBean) throws Exception {
handleWorkTime(shiftInfoCominfoBean);
this.success.handleDuration(shiftInfoCominfoBean);
}
private void handleWorkTime(ShiftInfoCominfoBean shiftInfoCominfoBean) throws Exception {
List<Object> workTimes = (List<Object>)workTimeMap.get("workTime");
int workmins = Util.getIntValue(Util.null2String(workTimeMap.get("workmins")));
shiftInfoCominfoBean.setWorkmins(workmins);
String serialid = Util.null2String(workTimeMap.get("serialid"));
shiftInfoCominfoBean.setSerialid(serialid);
setWorkDuration(workTimes, shiftInfoCominfoBean);
}
}

@ -0,0 +1,608 @@
package com.engine.kq.cmd.attendanceButton;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloudstore.dev.api.util.EMManager;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQCardLogBiz;
import com.engine.kq.biz.KQFormatBiz;
import com.engine.kq.biz.KQGroupBiz;
import com.engine.kq.biz.KQGroupMemberComInfo;
import com.engine.kq.biz.KQLoactionComInfo;
import com.engine.kq.biz.KQShiftRuleInfoBiz;
import com.engine.kq.biz.KQTimesArrayComInfo;
import com.engine.kq.biz.KQWorkTime;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.entity.KQGroupEntity;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.log.KQLog;
import com.engine.kq.timer.KQQueue;
import com.engine.kq.timer.KQTaskBean;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.wfset.util.SplitActionUtil;
import com.google.common.collect.Maps;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.dateformat.DateTransformer;
import weaver.dateformat.TimeZoneVar;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
/**
* 退
*/
public class PunchButtonCmd extends AbstractCommonCommand<Map<String, Object>> {
public KQLog kqLog = new KQLog();
private HttpServletRequest request;
private Map<String,Object> logMap = Maps.newHashMap();
private Map<String,Object> workTimeEntityLogMap = Maps.newHashMap();
public PunchButtonCmd(HttpServletRequest request,Map<String, Object> params, User user) {
this.request = request;
this.user = user;
this.params = params;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
try{
insertSign(retmap);
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
kqLog.info(user.getLastname()+":PunchButtonCmd:retmap:"+retmap);
KQCardLogBiz.logCardInfo(user.getUID()+"", logMap, workTimeEntityLogMap, "punchButton");
return retmap;
}
/**
* ip
* @param ismobile
*/
private boolean checkIsInIp(String ismobile) {
// if("1".equalsIgnoreCase(ismobile)){
// return true;
// }
KQGroupBiz kqGroupBiz = new KQGroupBiz();
String clientAddress = Util.getIpAddr(request);
kqLog.info("PunchButtonCmd:clientAddress:"+clientAddress);
return kqGroupBiz.getIsInScopeV4V6(user.getUID()+"", clientAddress,ismobile);
}
public void insertSign(Map<String, Object> retmap) throws Exception{
logMap.put("lastname", user.getLastname());
logMap.put("params", params);
kqLog.info(user.getLastname()+":PunchButtonCmd:params:"+params);
RecordSet rs = new RecordSet();
String deviceInfo = Util.null2String(params.get("deviceInfo"));
JSONObject jsonObject = null;
if(deviceInfo.length() > 0){
jsonObject = JSON.parseObject(deviceInfo);
JSONObject jsonObject1 = new JSONObject();
Set<Entry<String, Object>> jsonSet = jsonObject.entrySet();
for(Entry<String, Object> js : jsonSet){
String key = js.getKey();
String value = Util.null2String(js.getValue());
jsonObject1.put(key, value);
}
if(!jsonObject1.isEmpty()){
deviceInfo = jsonObject1.toJSONString();
}
}
//应上班 工作时间点
String time = Util.null2String(params.get("time"));
//应上班 工作时间 带日期
String datetime = Util.null2String(params.get("datetime"));
//允许打卡时段 带日期
String signSectionTime = Util.null2String(params.get("signSectionTime"));
//上传照片
String attachment = Util.null2String(params.get("fileids"));
//打卡所属worksection的对应的点
String type = Util.null2String(params.get("type"));
//所属打卡日期
String belongdate = Util.null2String(params.get("belongdate"));
belongdate = belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate;
String islastsign = Util.null2String(params.get("islastsign"));
String isfirstsign = Util.null2String(params.get("isfirstsign"));
String workmins = Util.null2String(params.get("workmins"));
//针对非工作时段 签退的时候记录的签到数据 用于计算加班
String signInTime4Out = Util.null2String(params.get("signInTime4Out"));
//允许打卡的范围
String signsection = Util.null2String(params.get("signSection"));
//手机打卡部分
String longitude = Util.null2String(params.get("longitude"));
String latitude = Util.null2String(params.get("latitude"));
double d_longitude = Util.getDoubleValue(longitude);
double d_latitude = Util.getDoubleValue(latitude);
if(d_latitude <= 0){
latitude = "";
}
if(d_longitude <= 0){
longitude = "";
}
//wifi用的
String mac = Util.null2String(params.get("mac"));
String sid = Util.null2String(params.get("sid"));
String addr = Util.null2String(params.get("position"));
String ismobile = Util.null2String(params.get("ismobile"));
//区分是来自于钉钉还是EM7
String browser = Util.null2String(params.get("browser"));
//自由班制处理
String isfree = Util.null2String(Util.null2String(params.get("isfree")),"0");
//上班打卡 允许最晚打卡时间
String signSectionEndTime = Util.null2String(params.get("signSectionEndTime"));
//下班打卡 允许最早打卡时间
String signSectionBeginTime = Util.null2String(params.get("signSectionBeginTime"));
String locationshowaddress = Util.null2String(params.get("locationshowaddress"));
if(locationshowaddress.equals("1")){//记录统一地址
String locationid = Util.null2String(params.get("locationid"));//办公地点id
if(locationid.length()>0){//如果开启统一显示,就用配置的地址
KQLoactionComInfo kqLoactionComInfo = new KQLoactionComInfo();
addr = kqLoactionComInfo.getLocationname(locationid);
}
}
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime localTime = LocalTime.now();
String signTime =localTime.format(dateTimeFormatter);
String signDate = LocalDate.now().format(dateFormatter);
String timeZone = Util.null2String(TimeZoneVar.getTimeZone(),"");
//处理多时区
String timeZoneConversion = Util.null2String(new weaver.general.BaseBean().getPropValue("weaver_timezone_conversion","timeZoneConversion")).trim();
logMap.put("timeZoneConversion", timeZoneConversion);
if("1".equals(timeZoneConversion)) {
DateTransformer dateTransformer=new DateTransformer();
String[] zone_localTime = dateTransformer.getLocaleDateAndTime(signDate,signTime);
kqLog.info(user.getLastname()+":TimeZoneVar.getTimeZone():"+TimeZoneVar.getTimeZone()+":zone_localTime:"+JSON.toJSONString(zone_localTime));
if(zone_localTime != null && zone_localTime.length == 2){
signDate = zone_localTime[0];
signTime = zone_localTime[1];
}
}
int userId = user.getUID();
String userType = user.getLogintype();
String signType = "on".equalsIgnoreCase(type) ? "1" : "2";
String clientAddress = Util.getIpAddr(request);
boolean isInIp = checkIsInIp(ismobile);
logMap.put("clientAddress", clientAddress);
if(!isInIp){
retmap.put("message", SystemEnv.getHtmlLabelName(20157,user.getLanguage()));
retmap.put("isInIp", "0");
}
String isInCom = isInIp ? "1" : "0";
//是否是考勤例外人员
boolean isExclude = false;
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
KQWorkTime kqWorkTime = new KQWorkTime();
WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(user.getUID()+"", signDate);
String userinfo = "#userid#"+user.getUID()+"#getUserSubCompany1#"+user.getUserSubCompany1()+"#getUserSubCompany1#"+user.getUserDepartment()
+"#getJobtitle#"+user.getJobtitle();
workTimeEntityLogMap.put("resourceid", userinfo);
workTimeEntityLogMap.put("splitDate", signDate);
workTimeEntityLogMap.put("workTimeEntity", workTimeEntity);
String groupid = workTimeEntity.getGroupId();
logMap.put("groupid", groupid);
KQGroupEntity kqGroupEntity = kqGroupMemberComInfo.getUserKQGroupInfo(user.getUID()+"");
String kqGroupEntityInfo = kqGroupEntity != null ? JSON.toJSONString(kqGroupEntity): "";
logMap.put("kqGroupEntityInfo", kqGroupEntityInfo);
if (kqGroupEntity != null && ("," + kqGroupEntity.getExcludeid() + ",").indexOf("," + user.getUID() + ",")>-1) {//排除人员无需计算考勤时间
isExclude = true;
}
String[] signsections = signsection.split("#");
if(!"1".equalsIgnoreCase(isfree)){
if(signsections != null && signsections.length == 2){
//判断是未签到直接签退
String signedMsg = signedMsg(userId+"", signType, user,signsections,signSectionBeginTime,signSectionEndTime);
if(signedMsg.length() > 0){
retmap.put("status", "1");
retmap.put("message", signedMsg);
isInCom = "0";
}
}
}
String datetime_timezone = signDate+" "+signTime;
LocalDateTime nowDateTime = LocalDateTime.parse(datetime_timezone,fullFormatter);
kqLog.info("timeZone:"+timeZone+":signDate:"+signDate+":signTime:"+signTime+":nowDateTime:"+nowDateTime);
if("1".equalsIgnoreCase(signType) && signSectionTime.length() > 0 ){
LocalDateTime startWorkDateTime = LocalDateTime.parse(signSectionTime,fullFormatter);
if(nowDateTime.isBefore(startWorkDateTime)){
Duration duration = Duration.between(nowDateTime, startWorkDateTime);
retmap.put("status", "1");
retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005326,weaver.general.ThreadVarLanguage.getLang())+""+duration.toMinutes()+""+weaver.systeminfo.SystemEnv.getHtmlLabelName(15049,weaver.general.ThreadVarLanguage.getLang())+"");
isInCom = "0";
}
}else if("2".equalsIgnoreCase(signType) && signSectionTime.length() > 0 ){
LocalDateTime endWorkDateTime = LocalDateTime.parse(signSectionTime,fullFormatter);
if(nowDateTime.isAfter(endWorkDateTime)){
Duration duration = Duration.between(endWorkDateTime, nowDateTime);
retmap.put("status", "1");
retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005327,weaver.general.ThreadVarLanguage.getLang())+""+duration.toMinutes()+""+weaver.systeminfo.SystemEnv.getHtmlLabelName(15049,weaver.general.ThreadVarLanguage.getLang())+"");
isInCom = "0";
}
}
//记录下是来自于E9的pc端签到
String signfrom = "e9pc";
if("1".equalsIgnoreCase(ismobile)){
signfrom = "e9mobile";
boolean needLocationRange = false;
boolean needWifiRange = false;
boolean isLocationRange = false;
boolean isWifiRange = false;
KQGroupBiz kqGroupBiz = new KQGroupBiz();
Map<String,Object> locationMap = kqGroupBiz.checkLocationScope(userId+"",longitude,latitude);
logMap.put("locationMap", locationMap);
String locationNeedCheck = Util.null2String(locationMap.get("needCheck"));
boolean locationInScope = Boolean.parseBoolean(Util.null2String(locationMap.get("inScope")));
if("1".equalsIgnoreCase(locationNeedCheck)){
needLocationRange = true;
if(locationInScope){
isLocationRange = true;
}
}
String wifiNeedCheck = "";
Map<String,Object> wifiMap = kqGroupBiz.checkWifiScope(userId+"", sid, mac);
logMap.put("wifiMap", wifiMap);
wifiNeedCheck = Util.null2String(wifiMap.get("needCheck"));
boolean wifiInScope = Boolean.parseBoolean(Util.null2String(wifiMap.get("inScope")));
if("1".equalsIgnoreCase(wifiNeedCheck)){
needWifiRange = true;
if(wifiInScope){
isWifiRange = true;
}
}
if(needLocationRange){
if(isLocationRange){
}else{
if(needWifiRange){
if(isWifiRange){
}else{
//地理位置开启而且不在范围内且开启wifi验证,不在范围内
retmap.put("message", SystemEnv.getHtmlLabelName(507524, user.getLanguage()));
isInCom = "0";
}
}else {
//地理位置开启而且不在范围内且未开启wifi验证
retmap.put("message", SystemEnv.getHtmlLabelName(500510, user.getLanguage()));
isInCom = "0";
}
}
}else{
if(needWifiRange) {
if (isWifiRange) {
} else {
//地理位置未开启且开启wifi验证,不在范围内
retmap.put("message", SystemEnv.getHtmlLabelName(507524, user.getLanguage()));
isInCom = "0";
}
}
}
if("DingTalk".equalsIgnoreCase(browser)){
signfrom = "DingTalk";
}else if("Wechat".equalsIgnoreCase(browser)){
signfrom = "Wechat";
String weChat_deviceid = Util.null2String(request.getSession().getAttribute(EMManager.DeviceId));
logMap.put("weChat_deviceid", weChat_deviceid);
kqLog.info("EMManager.DeviceId:"+EMManager.DeviceId+":weChat_deviceid:"+weChat_deviceid);
if(weChat_deviceid.length() > 0){
//微信打卡的设备号需要单独处理
if(jsonObject != null){
jsonObject.put("deviceId", weChat_deviceid);
}else{
jsonObject = new JSONObject();
jsonObject.put("deviceId", weChat_deviceid);
}
if(!jsonObject.isEmpty()){
deviceInfo = jsonObject.toJSONString();
}
}
}
}
String signStatus = "";
if(!"1".equalsIgnoreCase(isfree) && datetime.length() > 0){
signStatus = getSignStatus(signType,datetime,user.getUID()+"",belongdate,nowDateTime);
logMap.put("signStatus", signStatus);
}
if(isExclude){
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
String punchSql = "insert into HrmScheduleSign(userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo) "+
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
boolean isOk = rs.executeUpdate(punchSql,userId,userType,signType,signDate,signTime,clientAddress,isInCom,
timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo);
if(!isOk){
retmap.put("status", "1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
return ;
}
logMap.put("punchSql", punchSql);
logMap.put("punchSql_isOk", isOk);
kqLog.info(user.getLastname()+":PunchButtonCmd:punchSql:"+punchSql+":isOk:"+isOk);
//打卡提醒处理
String remindSql = "insert into hrmschedulesign_remind(userId,signType,signDate,signTime,belongdate) values(?,?,?,?,?)";
isOk = rs.executeUpdate(remindSql, userId,signType,signDate,signTime,belongdate);
kqLog.info(user.getLastname()+":PunchButtonCmd:remindSql:"+remindSql+":isOk:"+isOk);
//同步更新考勤数据到考勤报表
new KQFormatBiz().formatDate(""+userId,(belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
//点击签退的时候,可能存在加班数据生成的情况
if("2".equalsIgnoreCase(signType)){
if("1".equalsIgnoreCase(islastsign)){
List<KQTaskBean> tasks = new ArrayList<>();
List<KQTaskBean> after_tasks = new ArrayList<>();
SplitActionUtil.pushOverTimeTasks(belongdate, belongdate, ""+userId,tasks);
if(!tasks.isEmpty()){
for(KQTaskBean kqTaskBean : tasks){
after_tasks.add(kqTaskBean);
}
}
logMap.put("after_tasks", after_tasks);
if(!after_tasks.isEmpty()){
KQQueue.writeTasks(after_tasks);
}
}
}
if("1".equalsIgnoreCase(signType)){
if("1".equalsIgnoreCase(isfirstsign)){
List<KQTaskBean> tasks = new ArrayList<>();
List<KQTaskBean> before_tasks = new ArrayList<>();
SplitActionUtil.pushOverTimeTasks(belongdate, belongdate, ""+userId,tasks);
if(!tasks.isEmpty()){
for(KQTaskBean kqTaskBean : tasks){
kqTaskBean.setTasktype("punchcard");
before_tasks.add(kqTaskBean);
}
}
logMap.put("before_tasks", before_tasks);
if(!before_tasks.isEmpty()){
KQQueue.writeTasks(before_tasks);
}
}
}
String reSignStatus = reSignStatus(user.getUID()+"",signType,nowDateTime,belongdate);
if(Util.null2String(reSignStatus,"").length() > 0){
signStatus = reSignStatus;
}
retmap.put("status", "1");
retmap.put("signdate", signDate);
retmap.put("signtime", signTime);
retmap.put("kqstatus", signStatus);
if(!"1".equalsIgnoreCase(signStatus) && !"2".equalsIgnoreCase(signStatus)){
if("".equalsIgnoreCase(Util.null2String(retmap.get("message")))){
retmap.put("success", "1");
retmap.put("message", SystemEnv.getHtmlLabelName(512596,weaver.general.Util.getIntValue(user.getLanguage())));
}
}
logMap.put("retmap", retmap);
}
public String reSignStatus(String userid, String signType, LocalDateTime nowDateTime,
String workdate) {
String signStatus = "";
String shift_begindateworktime = "";
String shift_enddateworktime = "";
ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(userid, workdate,false);
if(shiftInfoBean == null){
return signStatus;
}
Map<String,String> shifRuleMap = Maps.newHashMap();
KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean,userid,shifRuleMap);
KQTimesArrayComInfo arrayComInfo = new KQTimesArrayComInfo();
if(!shifRuleMap.isEmpty()) {
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String datetime = "";
if (shifRuleMap.containsKey("shift_beginworktime")) {
String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime"));
if (shift_beginworktime.length() > 0) {
int shift_beginworktime_index = -1;
shift_beginworktime_index = arrayComInfo.getArrayindexByTimes(shift_beginworktime);
datetime = workdate+" "+shift_beginworktime+":00";
if(shift_beginworktime_index >= 1440){
//跨天了
datetime = DateUtil.addDate(workdate, 1)+" "+arrayComInfo.turn48to24Time(shift_beginworktime)+":00";
}
}
}
if (shifRuleMap.containsKey("shift_endworktime")) {
String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime"));
if (shift_endworktime.length() > 0) {
int shift_endworktime_index = -1;
shift_endworktime_index = arrayComInfo.getArrayindexByTimes(shift_endworktime);
datetime = workdate+" "+shift_endworktime+":00";
if(shift_endworktime_index >= 1440) {
//跨天了
datetime = DateUtil.addDate(workdate, 1)+" "+arrayComInfo.turn48to24Time(shift_endworktime)+":00";
}
}
}
if (datetime.length() > 0) {
if("1".equalsIgnoreCase(signType)) {
LocalDateTime startWorkDateTime = LocalDateTime.parse(datetime, fullFormatter);
//打卡时间比上班时间晚,迟到了
if (nowDateTime.isAfter(startWorkDateTime)) {
signStatus = ButtonStatusEnum.BELATE.getStatusCode();
} else {
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
} else if ("2".equalsIgnoreCase(signType)) {
LocalDateTime endWorkDateTime = LocalDateTime.parse(datetime, fullFormatter);
//签退的话
if (nowDateTime.isBefore(endWorkDateTime)) {
signStatus = ButtonStatusEnum.LEAVEERALY.getStatusCode();
} else {
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
} else {
writeLog(user.getLastname() + nowDateTime + ":竟然没有传:" + signType);
return "";
}
}
}
return signStatus;
}
/**
*
* @param resourceid
* @param pre_splitDate
* @param signtime
* @param pre_bengintime
* @param signdate
*/
public void doBeforeAcrossOvertime(String resourceid,String pre_splitDate,String signtime,String pre_bengintime,String signdate) {
KQTaskBean kqTaskBean = new KQTaskBean();
kqTaskBean.setResourceId(resourceid);
kqTaskBean.setTaskDate(pre_splitDate);
kqTaskBean.setLastWorkTime(signtime);
if(pre_bengintime.length() == 5){
kqTaskBean.setTaskSignTime(pre_bengintime+":00");
}else{
kqTaskBean.setTaskSignTime(pre_bengintime);
}
kqTaskBean.setSignDate(signdate);
kqTaskBean.setSignEndDate(signdate);
kqTaskBean.setTimesource("before");
KQQueue.writeTask(kqTaskBean);
}
/**
*
* @param userid
* @param signtype
* @param curUser
* @param signsections
* @param signSectionBeginTime
* @param signSectionEndTime
* @return
*/
public String signedMsg(String userid, String signtype, User curUser, String[] signsections,
String signSectionBeginTime, String signSectionEndTime) throws Exception{
String signedMsg = "";
RecordSet rs = new RecordSet();
boolean hasSigned = false;
String onSignSectionTime = signsections[0];
String offSignSectionTime = signsections[1];
if(onSignSectionTime.length() > 0 && offSignSectionTime.length() > 0){
String hasSign = "select 1 from hrmschedulesign where 1 = 1 and isInCom = '1' and userid = ? ";
StringBuffer sql = new StringBuffer();
if(rs.getDBType().equals("oracle")||rs.getDBType().equals("postgresql")){
sql.append(" AND signDate||' '||signTime>=? ");
sql.append(" AND signDate||' '||signTime<=? ");
}else if(rs.getDBType().equals("mysql")){
sql.append(" AND concat(signDate,' ',signTime)>=? ");
sql.append(" AND concat(signDate,' ',signTime)<=? ");
}else{
sql.append(" AND signDate+' '+signTime>=? ");
sql.append(" AND signDate+' '+signTime<=? ");
}
hasSign += sql.toString();
rs.executeQuery(hasSign, userid,onSignSectionTime,offSignSectionTime);
if(rs.next()){
hasSigned = true;
}
if("1".equalsIgnoreCase(signtype)){
if(signSectionBeginTime.length() > 0 || signSectionEndTime.length() > 0){
}else{
if(hasSigned){
signedMsg = SystemEnv.getHtmlLabelName(129706, curUser.getLanguage());
}
}
}else if("2".equalsIgnoreCase(signtype)){
if(signSectionBeginTime.length() > 0 || signSectionEndTime.length() > 0){
}else{
if(!hasSigned){
signedMsg = SystemEnv.getHtmlLabelName(501301, curUser.getLanguage());
}
}
}
}
return signedMsg;
}
/**
* 退
* 退
* @return
*/
public String getSignStatus(String signType, String datetime, String userid, String workdate,
LocalDateTime nowDateTime) {
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String signStatus = "";
//签到的话
if("1".equalsIgnoreCase(signType)){
LocalDateTime startWorkDateTime = LocalDateTime.parse(datetime,fullFormatter);
//打卡时间比上班时间晚,迟到了
if(nowDateTime.isAfter(startWorkDateTime)){
signStatus = ButtonStatusEnum.BELATE.getStatusCode();
}else{
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
}else if("2".equalsIgnoreCase(signType)){
LocalDateTime endWorkDateTime = LocalDateTime.parse(datetime,fullFormatter);
//签退的话
if(nowDateTime.isBefore(endWorkDateTime)){
signStatus = ButtonStatusEnum.LEAVEERALY.getStatusCode();
}else{
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
}else{
writeLog(user.getLastname()+nowDateTime+":竟然没有传:"+signType);
return "";
}
return signStatus;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,127 @@
package com.engine.kq.entity;
import java.util.List;
import java.util.Map;
/***
*
*/
public class WorkTimeEntity {
private String groupId;//所属考勤组
private String groupName;//所属考勤组
private String kqType;//考勤类型
private String serialId;//班次
private Map<String,Object> shiftRuleInfo;//班次人性化规则
private List<TimeScopeEntity> signTime;//允许打卡时间
private List<TimeScopeEntity> workTime;//工作时间
private List<TimeScopeEntity> restTime;//休息时间
private int workMins;//工作时长
private String isAcross;//是否跨天
private String signstart;//自由工时开始打卡时间
private boolean isExclude;//无需考勤人员
private String calmethod;//自由班制计算方式
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getKQType() {
return kqType;
}
public void setKQType(String kqType) {
this.kqType = kqType;
}
public String getSerialId() {
return serialId;
}
public void setSerialId(String serialId) {
this.serialId = serialId;
}
public Map<String, Object> getShiftRuleInfo() {
return shiftRuleInfo;
}
public void setShiftRuleInfo(Map<String, Object> shiftRuleInfo) {
this.shiftRuleInfo = shiftRuleInfo;
}
public List<TimeScopeEntity> getWorkTime() {
return workTime;
}
public void setWorkTime(List<TimeScopeEntity> workTime) {
this.workTime = workTime;
}
public List<TimeScopeEntity> getRestTime() {
return restTime;
}
public void setRestTime(List<TimeScopeEntity> restTime) {
this.restTime = restTime;
}
public int getWorkMins() {
return workMins;
}
public void setWorkMins(int workMins) {
this.workMins = workMins;
}
public String getIsAcross() {
return isAcross;
}
public void setIsAcross(String isAcross) {
this.isAcross = isAcross;
}
public String getSignStart() {
return signstart;
}
public void setSignStart(String signstart) {
this.signstart = signstart;
}
public List<TimeScopeEntity> getSignTime() {
return signTime;
}
public void setSignTime(List<TimeScopeEntity> signTime) {
this.signTime = signTime;
}
public boolean getIsExclude() {
return isExclude;
}
public void setIsExclude(boolean isExclude) {
this.isExclude = isExclude;
}
public String getCalmethod() {
return calmethod;
}
public void setCalmethod(String calmethod) {
this.calmethod = calmethod;
}
}

@ -0,0 +1,608 @@
package com.engine.kq.util;
import com.engine.kq.biz.KQLeaveRulesBiz;
import com.engine.kq.biz.KQLeaveRulesComInfo;
import com.engine.kq.biz.KQWorkTime;
import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean;
import com.engine.kq.biz.chain.duration.NonDayUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonHalfUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonHourUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonWholeUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonWorkDurationChain;
import com.engine.kq.biz.chain.duration.WorkDayUnitSplitChain;
import com.engine.kq.biz.chain.duration.WorkDurationChain;
import com.engine.kq.biz.chain.duration.WorkHalfUnitSplitChain;
import com.engine.kq.biz.chain.duration.WorkHourUnitSplitChain;
import com.engine.kq.biz.chain.duration.WorkWholeUnitSplitChain;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.enums.DurationTypeEnum;
import com.engine.kq.log.KQLog;
import com.engine.kq.wfset.bean.SplitBean;
import com.engine.kq.wfset.util.KQFlowUtil;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.report.schedulediff.HrmScheduleDiffUtil;
public class KQDurationCalculatorUtil extends BaseBean {
private KQLog kqLog = new KQLog();
private final String resourceid;
private String fromDate;
private String toDate;
private String fromTime;
private String toTime;
private String newLeaveType;
/**
*
* 1-
* 2-
* 3-
* 4-
*/
private String durationrule;
/**
* 1-
* 2-
*/
private String computingMode;
/**
*
*/
private String overtime_type;
private DurationTypeEnum durationTypeEnum;
//外部类的构造函数
private KQDurationCalculatorUtil(DurationParamBuilder build){
this.resourceid = build.resourceid;
this.fromDate = build.fromDate;
this.toDate = build.toDate;
this.fromTime = build.fromTime;
this.toTime = build.toTime;
this.newLeaveType = build.newLeaveType;
this.durationrule = build.durationrule;
this.computingMode = build.computingMode;
this.durationTypeEnum = build.durationTypeEnum;
this.overtime_type = build.overtime_type;
}
/**
*
* @param resourceid
* @param date
* @param containYesterday
* @return
*/
public static ShiftInfoBean getWorkTime(String resourceid, String date,boolean containYesterday){
User user = User.getUser(Util.getIntValue(resourceid), 0);
if(user == null){
return null;
}
return getWorkTime(user, date,containYesterday);
}
/**
*
* @param resourceid
* @param date
* @param containYesterday
* @param isLog
* @return
*/
public static ShiftInfoBean getWorkTime(String resourceid, String date,boolean containYesterday,boolean isLog){
User user = User.getUser(Util.getIntValue(resourceid), 0);
if(user == null){
return null;
}
return getWorkTime(user, date,containYesterday,isLog);
}
public static ShiftInfoCominfoBean getShiftInfoCominfoBean(String resourceid, String date){
KQWorkTime kqWorkTime = new KQWorkTime();
Map<String, Object> kqWorkTimeMap = new HashMap<>();
ShiftInfoCominfoBean shiftInfoCominfoBean = kqWorkTime.getShiftInfoCominfoBean(resourceid, date);
return shiftInfoCominfoBean;
}
/**
* user
* @param user
* @param date
* @param containYesterday
* @param isLog
* @return
*/
public static ShiftInfoBean getWorkTime(User user, String date,boolean containYesterday,boolean isLog){
KQWorkTime kqWorkTime = new KQWorkTime();
Map<String, Object> kqWorkTimeMap = new HashMap<>();
kqWorkTimeMap = kqWorkTime.getWorkDuration(""+user.getUID(), date,containYesterday,isLog);
boolean isfree = "1".equalsIgnoreCase(Util.null2String(kqWorkTimeMap.get("isfree")));
if(isfree){
ShiftInfoBean shiftInfoBean = new ShiftInfoBean();
shiftInfoBean.setIsfree(true);
String signStart = Util.null2String(kqWorkTimeMap.get("signStart"));
String workMins = Util.null2String(kqWorkTimeMap.get("workMins"));
shiftInfoBean.setFreeSignStart(signStart);
shiftInfoBean.setFreeWorkMins(workMins);
shiftInfoBean.setSplitDate(date);
if(signStart.length() > 0 && workMins.length() > 0){
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime signLocalTime = LocalTime.parse(signStart, dateTimeFormatter);
shiftInfoBean.setFreeSignEnd(signLocalTime.plusMinutes(Util.getIntValue(workMins)).format(dateTimeFormatter));
shiftInfoBean.setFreeSignMiddle(signLocalTime.plusMinutes(Util.getIntValue(workMins)/2).format(dateTimeFormatter));
}
return shiftInfoBean;
}else{
if(kqWorkTimeMap.get("shiftInfoBean") != null){
ShiftInfoBean shiftInfoBean = (ShiftInfoBean)kqWorkTimeMap.get("shiftInfoBean");
return shiftInfoBean;
}else{
return null;
}
}
}
/**
* user
* @param user
* @param date
* @param containYesterday
* @return
*/
public static ShiftInfoBean getWorkTime(User user, String date,boolean containYesterday){
return getWorkTime(user, date, containYesterday, true);
}
public static Map<String, Object> getWorkButton(String resourceid, String date, boolean containYesterday){
User user = User.getUser(Util.getIntValue(resourceid), 0);
return getWorkButton(user,date,containYesterday);
}
public static Map<String, Object> getWorkButton(User user, String date, boolean containYesterday){
KQWorkTime kqWorkTime = new KQWorkTime();
Map<String, Object> kqWorkTimeMap = new HashMap<>();
kqWorkTimeMap = kqWorkTime.getWorkButton(""+user.getUID(), date,containYesterday);
return kqWorkTimeMap;
}
/**
*
* @return
*/
public Map<String,Object> getNonWorkDuration(){
Map<String,Object> durationMap = new HashMap<>();
try{
double D_Duration = 0.0;
double Min_Duration = 0.0;
//公众假日加班时长
double D_Pub_Duration = 0.0;
double D_Pub_Mins = 0.0;
//工作日加班时长
double D_Work_Duration = 0.0;
double D_Work_Mins = 0.0;
//休息日加班时长
double D_Rest_Duration = 0.0;
double D_Rest_Mins = 0.0;
SplitBean splitBean = new SplitBean();
splitBean.setFromDate(fromDate);
splitBean.setFromTime(fromTime);
splitBean.setToDate(toDate);
splitBean.setToTime(toTime);
splitBean.setResourceId(resourceid);
splitBean.setFromdatedb(fromDate);
splitBean.setTodatedb(toDate);
splitBean.setFromtimedb(fromTime);
splitBean.setTotimedb(toTime);
splitBean.setDurationrule(durationrule);
splitBean.setComputingMode(computingMode);
splitBean.setDurationTypeEnum(DurationTypeEnum.OVERTIME);
splitBean.setOvertime_type(overtime_type);
List<SplitBean> splitBeans = new ArrayList<>();
NonWorkDurationChain hourUnitSplitChain = new NonHourUnitSplitChain(splitBeans);
NonWorkDurationChain dayUnitSplitChain = new NonDayUnitSplitChain(splitBeans);
NonWorkDurationChain halfUnitSplitChain = new NonHalfUnitSplitChain(splitBeans);
NonWorkDurationChain wholeUnitSplitChain = new NonWholeUnitSplitChain(splitBeans);
//设置执行链
hourUnitSplitChain.setDurationChain(dayUnitSplitChain);
dayUnitSplitChain.setDurationChain(halfUnitSplitChain);
halfUnitSplitChain.setDurationChain(wholeUnitSplitChain);
//把初始数据设置进去
hourUnitSplitChain.handleDuration(splitBean);
//每一天的流程时长都在这里了,搞吧
for(SplitBean sb : splitBeans){
// * 1-公众假日、2-工作日、3-休息日
int changeType = sb.getChangeType();
double durations = Util.getDoubleValue(sb.getDuration(), 0.0);
double durationMins = sb.getD_Mins();
if(1 == changeType){
D_Pub_Duration += durations;
D_Pub_Mins += durationMins;
}
if(2 == changeType){
D_Work_Duration += durations;
D_Work_Mins += durationMins;
}
if(3 == changeType){
D_Rest_Duration += durations;
D_Rest_Mins += durationMins;
}
}
Min_Duration = D_Pub_Mins+D_Work_Mins+D_Rest_Mins;
if("3".equalsIgnoreCase(durationrule) || "5".equalsIgnoreCase(durationrule) || "6".equalsIgnoreCase(durationrule)){
double d_hour = Min_Duration/60.0;
durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound(""+d_hour));
}else {
double oneDayHour = KQFlowUtil.getOneDayHour(DurationTypeEnum.OVERTIME,"");
double d_day = Min_Duration/(oneDayHour * 60);
durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound(""+d_day));
}
durationMap.put("min_duration", KQDurationCalculatorUtil.getDurationRound(""+Min_Duration));
}catch (Exception e){
e.printStackTrace();
}
return durationMap;
}
/**
*
* @return
*/
public Map<String,Object> getWorkDuration(){
Map<String,Object> durationMap = new HashMap<>();
try{
if(!isValidate(fromDate,toDate,fromTime,toTime)){
durationMap.put("duration", "0.0");
return durationMap;
}
if(durationTypeEnum != DurationTypeEnum.COMMON_CAL){
kqLog.info("getWorkDuration:"+durationTypeEnum.getDurationType()+":fromDate:"+fromDate+":toDate:"+toDate+":fromTime:"+fromTime+":toTime:"+toTime+":durationrule:"+durationrule+":computingMode:"+computingMode);
}
//如果是加班
if(durationTypeEnum ==DurationTypeEnum.OVERTIME){
return getNonWorkDuration();
}
//时长
double D_Duration = 0.0;
//分钟数
double Min_Duration = 0.0;
SplitBean splitBean = new SplitBean();
splitBean.setFromDate(fromDate);
splitBean.setFromTime(fromTime);
splitBean.setToDate(toDate);
splitBean.setToTime(toTime);
splitBean.setResourceId(resourceid);
splitBean.setFromdatedb(fromDate);
splitBean.setTodatedb(toDate);
splitBean.setFromtimedb(fromTime);
splitBean.setTotimedb(toTime);
splitBean.setDurationrule(durationrule);
splitBean.setDurationTypeEnum(durationTypeEnum);
splitBean.setComputingMode(computingMode);
splitBean.setNewLeaveType(newLeaveType);
if("2".equalsIgnoreCase(computingMode)){
double oneDayHour = KQFlowUtil.getOneDayHour(durationTypeEnum,newLeaveType);
splitBean.setOneDayHour(oneDayHour);
if(durationTypeEnum == DurationTypeEnum.LEAVE){
//只有自然日 请假才有这个排除节假日、休息日的功能
splitBean.setFilterholidays(KQLeaveRulesBiz.getFilterHolidays(splitBean.getNewLeaveType()));
}
}
if(durationTypeEnum ==DurationTypeEnum.LEAVE || durationTypeEnum ==DurationTypeEnum.LEAVEBACK){
if(newLeaveType.length() > 0){
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
String conversion = kqLeaveRulesComInfo.getConversion(newLeaveType);
splitBean.setConversion(conversion);
}
}
List<SplitBean> splitBeans = new ArrayList<>();
WorkDurationChain hourUnitSplitChain = new WorkHourUnitSplitChain(splitBeans);
WorkDurationChain dayUnitSplitChain = new WorkDayUnitSplitChain(splitBeans);
WorkDurationChain halfUnitSplitChain = new WorkHalfUnitSplitChain(splitBeans);
WorkDurationChain wholeUnitSplitChain = new WorkWholeUnitSplitChain(splitBeans);
//设置执行链
hourUnitSplitChain.setDurationChain(dayUnitSplitChain);
dayUnitSplitChain.setDurationChain(halfUnitSplitChain);
halfUnitSplitChain.setDurationChain(wholeUnitSplitChain);
//把初始数据设置进去
hourUnitSplitChain.handleDuration(splitBean);
//每一天的流程时长都在这里了,搞吧
for(SplitBean sb : splitBeans){
double durations = Util.getDoubleValue(sb.getDuration(), 0.0);
double min_durations = sb.getD_Mins();
D_Duration += durations;
Min_Duration += min_durations;
}
durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound(""+D_Duration));
durationMap.put("min_duration", KQDurationCalculatorUtil.getDurationRound(""+Min_Duration));
}catch (Exception e){
e.printStackTrace();
}
return durationMap;
}
/**
*
* @return false
*/
private boolean isValidate(String fromDate,String toDate,String fromTime,String toTime) {
if(fromDate.length() == 0 || toDate.length() == 0){
return false;
}
if(fromTime.length() == 0 || toTime.length() == 0){
return false;
}
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String fromDateTime = fromDate+" "+fromTime+":00";
String toDateTime = toDate+" "+toTime+":00";
LocalDateTime localFromDateTime = LocalDateTime.parse(fromDateTime,fullFormatter);
LocalDateTime localToDateTime = LocalDateTime.parse(toDateTime,fullFormatter);
if(localFromDateTime.isAfter(localToDateTime) || localFromDateTime.isEqual(localToDateTime)){
return false;
}
return true;
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public Map<String,Object> getTotalWorkingDurations(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
KQDurationCalculatorUtil kqDurationCalculatorUtil =new KQDurationCalculatorUtil.DurationParamBuilder(resourceid).
fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).durationRuleParam("1")
.computingModeParam("1").durationTypeEnumParam(DurationTypeEnum.COMMON_CAL).build();
Map<String,Object> durationMap = kqDurationCalculatorUtil.getWorkDuration();
return durationMap;
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalWorkingDays(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
Map<String,Object> durationMap = getTotalWorkingDurations(fromDate,fromTime,toDate,toTime,resourceid);
String duration4day = Util.null2s(Util.null2String(durationMap.get("duration")),"0");
return KQDurationCalculatorUtil.getDurationRound(duration4day);
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalWorkingHours(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
Map<String,Object> durationMap = getTotalWorkingDurations(fromDate,fromTime,toDate,toTime,resourceid);
String duration4min = Util.null2s(Util.null2String(durationMap.get("min_duration")),"0");
double duration4hour = Util.getDoubleValue(duration4min)/60.0;
return KQDurationCalculatorUtil.getDurationRound(duration4hour+"");
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalWorkingMins(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
Map<String,Object> durationMap = getTotalWorkingDurations(fromDate,fromTime,toDate,toTime,resourceid);
String duration4min = Util.null2s(Util.null2String(durationMap.get("min_duration")),"0");
return KQDurationCalculatorUtil.getDurationRound(duration4min+"");
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalNonWorkingDays(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
KQDurationCalculatorUtil kqDurationCalculatorUtil =new KQDurationCalculatorUtil.DurationParamBuilder(resourceid).
fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).computingModeParam("1").
durationRuleParam("1").durationTypeEnumParam(DurationTypeEnum.OVERTIME).build();
Map<String,Object> durationMap = kqDurationCalculatorUtil.getNonWorkDuration();
String duration = Util.null2String(durationMap.get("duration"));
return KQDurationCalculatorUtil.getDurationRound(duration);
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalNonWorkingHours(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
KQDurationCalculatorUtil kqDurationCalculatorUtil =new KQDurationCalculatorUtil.DurationParamBuilder(resourceid).
fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).computingModeParam("1").
durationRuleParam("3").durationTypeEnumParam(DurationTypeEnum.OVERTIME).build();
Map<String,Object> durationMap = kqDurationCalculatorUtil.getNonWorkDuration();
String duration = Util.null2String(durationMap.get("duration"));
return KQDurationCalculatorUtil.getDurationRound(duration);
}
/**
* 2
* @param duration
* @return
*/
public static String getDurationRound(String duration){
if(HrmScheduleDiffUtil.isFromFlow()){
return Util.round(duration,5) ;
}
return Util.round(duration, 2);
}
/**
* 5
* @param duration
* @return
*/
public static String getDurationRound5(String duration){
return Util.round(duration, 5);
}
/**
* Builder
*/
public static class DurationParamBuilder {
//必选变量 人员看怎么都是需要的
private final String resourceid;
//可选变量
private String fromDate = "";
private String toDate = "";
private String fromTime = "";
private String toTime = "";
/**
*
*/
private String newLeaveType = "";
/**
*
* 1-
* 2-
* 3-
* 4-
*/
private String durationrule = "";
/**
*
* 1-
* 2-
*/
private String computingMode = "";
/**
*
*/
private String overtime_type = "";
/**
*
*/
private DurationTypeEnum durationTypeEnum;
public DurationParamBuilder(String resourceid) {
this.resourceid = resourceid;
//初始化的时候需要把其他参数先清空下
this.fromDate = "";
this.toDate = "";
this.fromTime = "";
this.toTime = "";
this.newLeaveType = "";
this.durationrule = "";
this.computingMode = "";
this.overtime_type = "";
}
//成员方法返回其自身,所以可以链式调用
public DurationParamBuilder fromDateParam(final String fromDate) {
this.fromDate = fromDate;
return this;
}
public DurationParamBuilder toDateParam(final String toDate) {
this.toDate = toDate;
return this;
}
public DurationParamBuilder fromTimeParam(final String fromTime) {
this.fromTime = fromTime;
return this;
}
public DurationParamBuilder toTimeParam(final String toTime) {
this.toTime = toTime;
return this;
}
public DurationParamBuilder newLeaveTypeParam(final String newLeaveType) {
this.newLeaveType = newLeaveType;
return this;
}
public DurationParamBuilder durationRuleParam(final String durationrule) {
this.durationrule = durationrule;
return this;
}
public DurationParamBuilder computingModeParam(final String computingMode) {
this.computingMode = computingMode;
return this;
}
public DurationParamBuilder overtime_typeParam(final String overtime_type) {
this.overtime_type = overtime_type;
return this;
}
public DurationParamBuilder durationTypeEnumParam(final DurationTypeEnum durationTypeEnum) {
this.durationTypeEnum = durationTypeEnum;
return this;
}
//Builder的build方法返回外部类的实例
public KQDurationCalculatorUtil build() {
return new KQDurationCalculatorUtil(this);
}
}
}
Loading…
Cancel
Save