You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-hostar/src/com/engine/kq/biz/KQFormatData.java

2201 lines
108 KiB
Java

package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloudstore.dev.api.util.Util_DataMap;
1 year ago
import com.engine.hostar.util.HostarUtil;
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;
1 year ago
import com.engine.kq.util.KQDurationCalculatorUtil;
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;
1 year ago
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
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;
1 year ago
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.InitServer;
1 year ago
import weaver.general.TimeUtil;
import weaver.general.Util;
1 year ago
import weaver.hrm.User;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*/
public class KQFormatData extends BaseBean {
BaseBean bb = new BaseBean();
private String today = DateUtil.getCurrentDate();
private KQLog kqLog = new KQLog();
private boolean writeLog = false;
private LinkedHashMap<String,Object> logInfo = new LinkedHashMap<>();
1 year ago
private final List<String> LIST = Arrays.asList("1", "8", "14","15");
private final static double PI = 3.14159265358979323; // 圆周率
private final static double R = 6371229; // 地球的半径
1 year ago
private static DecimalFormat df = new DecimalFormat("0.00");
private DecimalFormatSymbols symbols = new DecimalFormatSymbols();
/***
*
* @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 {
bb.writeLog("start to formatKqDate");
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));
}
bb.writeLog("lsParam: " + lsParam);
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,zeropoint"+(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,zeropoint"+(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,sum(zeropoint) as zeropoint " +
(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);
}
}
1 year ago
long startTime = System.currentTimeMillis();
// 获取考勤二开--夜班补助
String nightShiftSubsidy = getNightShiftSubsidy(userId, kqDate);
bb.writeLog("nightShiftSubsidy:" + nightShiftSubsidy);
if (StringUtils.isEmpty(nightShiftSubsidy)) {
nightShiftSubsidy = "0";
}
// 获取考勤二开--鸿仁驻点餐补
String otherStatAllowance = getOtherStatAllowance(userId, kqDate);
bb.writeLog("otherStatAllowance:" + otherStatAllowance);
if (StringUtils.isEmpty(otherStatAllowance)) {
otherStatAllowance = "0";
}
// 考勤二开--精密夜班餐补
String nightAllowance = getNightAllowance(userId, kqDate);
bb.writeLog("nightAllowance:" + nightAllowance);
if (StringUtils.isEmpty(nightAllowance)) {
nightAllowance = "0";
}
// 考勤二开--驻点餐补
String statAllowance = getStatAllowance(userId, kqDate);
bb.writeLog("statAllowance:" + statAllowance);
if (StringUtils.isEmpty(statAllowance)) {
statAllowance = "0";
}
// 考勤二开--出差餐补
String mealAllowance = getMealAllowance(userId, kqDate);
bb.writeLog("mealAllowance:" + mealAllowance);
if (StringUtils.isEmpty(mealAllowance)) {
mealAllowance = "0";
}
// 考勤二开--零点补助
String zeropoint = "0";
rs.executeQuery("select zeropoint from kq_format_total where resourceid = ? and kqdate = ?", userId, kqDate);
if (rs.next()) {
zeropoint = rs.getString("zeropoint");
}
if (StringUtils.isEmpty(zeropoint)) {
zeropoint = "0";
}
rs.executeQuery("select id from uf_cbxxjlb where xm = ? and rq = ?", userId, kqDate);
RecordSet rs1 = new RecordSet();
String cbxxjlModeId = rs1.getPropValue("hostar_zm_prop","cbxxjl_modeid");
if (rs.next()) {
int cbxxjlId = rs.getInt("id");
rs1.executeUpdate("update uf_cbxxjlb set hrzdcb = ?, jmybcb = ?, zdcb = ?, ybbz = ?, cccb = ?, ldbz = ? where id = ?",
otherStatAllowance, nightAllowance, statAllowance, nightShiftSubsidy, mealAllowance, zeropoint, cbxxjlId);
//权限重构
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare(1, Integer.parseInt(cbxxjlModeId), cbxxjlId);
} else {
String uuidT = UUID.randomUUID().toString();
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");//设置日期格式
String nowDate = sdfDate.format(new Date());
String nowTime = sdfTime.format(new Date());
String gh = null;
String bm = null;
rs1.executeQuery("SELECT workcode, departmentid from hrmresource where id = ?", userId);
if (rs1.next()) {
gh = rs1.getString("workcode");
bm = rs1.getString("departmentid");
}
rs1.executeUpdate("insert into uf_cbxxjlb (xm, rq, gh, bm, hrzdcb, jmybcb, zdcb, ybbz, cccb, ldbz, formmodeid, MODEUUID, " +
"modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,?)",
userId, kqDate, gh, bm ,otherStatAllowance, nightAllowance, statAllowance, nightShiftSubsidy, mealAllowance, zeropoint, cbxxjlModeId, uuidT, "1", "0", nowDate, nowTime);
1 year ago
RecordSet qxcgRs = new RecordSet();
qxcgRs.execute("select id from uf_cbxxjlb where MODEUUID = '" + uuidT + "'");
Integer idT = 0;
while (qxcgRs.next()) {
idT = qxcgRs.getInt("id");
}
//权限重构
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare(1, Integer.parseInt(cbxxjlModeId), idT);
}
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime; // 执行时间
bb.writeLog("getDailyMealAllowanceData执行时间" + elapsedTime/1000 + "秒");
}catch (Exception e) {
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;
1 year ago
RecordSet rt = new RecordSet();
try {
bb.writeLog("start to format");
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;
1 year ago
bb.writeLog("format.groupId:"+workTime.getGroupId()+"format.serialId:"+workTime.getSerialId());
if((workTime.getGroupId()!=null&&StringUtils.isNotBlank(workTime.getGroupId()))&&LIST.contains(workTime.getGroupId())&&(workTime.getSerialId()==null||StringUtils.isBlank(workTime.getSerialId()))){
bb.writeLog("start to Automatic shift alignment"+LIST);
bb.writeLog("format.userId:"+userId+"format.kqDate:"+kqDate+"format.workTime:"+workTime+"format.workFlowInfo:"+workFlowInfo+"format.uuid:"+uuid);
//责任制考勤组
//当天考勤标识
boolean kqFlag = false;
boolean xxFlag = false;
boolean ccFlag = false;
boolean wqdkFlag = false;
boolean qjFlag = false;
String showaddress = "";
String dybc = "";
//1.查询该员工当天考勤地点(名称)
String sql = "select a.id as id ,a.longitude,a.latitude,a.showaddress,b.id as resourceid, b.lastname," +
" signdate, signtime from hrmschedulesign a left join hrmresource b on b.id = a.userid" +
" left join hrmdepartment c on c.id = b.departmentid" +
" where a.isincom = 1 and b.id = ? and a.signdate = ? order by a.signdate desc";
rt.executeQuery(sql,userId,kqDate);
if(rt.next()){
kqFlag = true;
showaddress = Util.null2String(rt.getString("showaddress"));
}
bb.writeLog("sign showaddress:"+showaddress);
//2.查询指定打卡地点的经纬度及范围的list
List<Map<String,String>> list2 = new ArrayList<>();
//2.1查询出打卡地点经纬度建模list
String sql2 = "select kqdz,dybc from uf_jwdbj";
rt.execute(sql2);
while (rt.next()){
Map<String,String> map = new HashMap<>();
map.put("kqdz", Util.null2String(rt.getString("kqdz")));
map.put("dybc", Util.null2String(rt.getString("dybc")));
list2.add(map);
}
bb.writeLog("uf_jwdbj.list2:"+list2);
//3.计算两点之间的距离是否大于范围值,小于则自动对班(白班)
for (Map<String, String> map : list2) {
if(map.get("kqdz").equals(showaddress)){
dybc = map.get("dybc");
}
}
bb.writeLog("format.dybc:"+dybc);
// 4.休息日或节假日给休息班次
int changeType = KQOvertimeRulesBiz.getChangeType(userId, kqDate);
bb.writeLog("format.changeType:"+changeType);
//考勤当天是节假日或者休息日
if(changeType==1||changeType==3){
xxFlag = true;
}
bb.writeLog("format.xxFlag:"+xxFlag);
//5.外勤打卡(需要有打卡记录+对应的出差流程)
//5.1打卡记录查询
String wqSql = "select * from mobile_sign where operater = ? and operate_date = ? ";
rt.executeQuery(wqSql,userId,kqDate);
if(rt.next()){
wqdkFlag = true;
}
bb.writeLog("format.wqdkFlag:"+wqdkFlag);
//5.2出差记录查询
String ccSql = "select currentnodetype from workflow_requestbase where requestid in " +
" (select requestId from formtable_main_61 where sqr = ? and " +
" (ksrq +' '+ kssj) <=? " +
" and (yjjsrq+' '+yjjssj) >=? ";
rt.executeQuery(ccSql,userId,kqDate,kqDate);
if(rt.next()){
ccFlag = true;
}
bb.writeLog("format.ccFlag:"+ccFlag);
//6.查询该员工当天是否有已办结的请假流程(有:自动对班;否:不处理)
//6.1 查询当天是否有休假流程查询出流程requestid
String sql3 = "select currentnodetype from workflow_requestbase where requestid in (select requestid from kq_flow_split_leave where (fromdatedb +' '+ fromtimedb) <=? " +
"and (todatedb+' '+totimedb) >=?) and currentnodetype in ('1','3') ";
//6.2 查询这些requestid是否在当天前包含当天已批准
rt.executeQuery(sql3,kqDate,kqDate);
if(rt.next()){
qjFlag = true;
}
bb.writeLog("format.qjFlag:"+qjFlag);
//1.正常打卡给对应打卡地点对应班次
if(kqFlag){
//指定白班
workTime.setSerialId(dybc);
}
if(xxFlag){
//休息
workTime.setSerialId("-1");
}
if(wqdkFlag&&ccFlag){
//外勤打卡+出差流程
workTime.setSerialId("9");
}
if(qjFlag){
//请假流程指定白班
workTime.setSerialId("9");
}
bb.writeLog("format.serialIdLast:"+workTime.getSerialId());
}
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);
// 一天4次打卡单独做判断如果是上午下班打卡和下午上班打卡时间重叠那么上午的下班卡取最早的下午的上班卡取最晚的。用shiftCount是否等于-1判断-1就走标准不重叠。2就表示重叠走新的逻辑
int shiftCount = lsWorkTime == null ? 0 : lsWorkTime.size();
int shiftI = 0;
String signEndDateTimeZero = "";
for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) {
shiftI = i;
TimeScopeEntity signTimeScope = lsSignTime.get(i);
TimeScopeEntity workTimeScope = lsWorkTime.get(i);
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";
if (shiftCount == 2 && shiftI == 0) {
signEndDateTimeZero = signEndDateTime;
}
if (shiftCount == 2 && shiftI == 1) {
shiftCount = signBeginDateTime.compareTo(signEndDateTimeZero) <= 0 ? shiftCount : -1;
}
}
for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) {
shiftI = 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;
if (workTimeScope != null && workTimeScope.getEndTimeAcross() && signTimeScope.getEndTimeAcross() ) {
if(workTimeScope.getEndTime().compareTo(signTimeScope.getEndTime())>=0){
signEndDateTime = DateUtil.addDate(kqDate, 2);//下下一天日期;
}
}
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,shiftCount,shiftI);
bb.writeLog("kqformatdata lscheckinfo: " + lsCheckInfo);
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);
}
1 year ago
for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) {
Map<String, Object> checkInfo = (Map<String, Object>) lsCheckInfo.get(j);
bb.writeLog("kqformatdata checkInfo: " + checkInfo);
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{
bb.writeLog("1111-----");
bb.writeLog("dayMins: " + dayMins + ", beginIdx: " + beginIdx + ", workEndIdx: " + workEndIdx);
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 = 1440 + 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);
}
bb.writeLog("kqformatdata workFlow: " + workFlow);
for (int j = 0; workFlow != null && j < workFlow.size(); j++) {
Map<String, Object> data = (Map<String, Object>) workFlow.get(j);
bb.writeLog("kqformatdata workFlow data: " + workFlow);
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(beginIdx>=workEndIdx){
continue;
}
if(endIdx<=workBeginIdx){
continue;
}
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(lsRestTime != null && !lsRestTime.isEmpty()){
for(int k = 0 ; k < lsRestTime.size(); k++){
TimeScopeEntity restTimeScope = lsRestTime.get(k);
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, -11);//休息时间
}
}
}
int all_rest_cnt = kqTimesArrayComInfo.getCnt(dayMins, workBeginIdx, workEndIdx, -11);
if(all_rest_cnt >= 0){
workMins = workMins-(all_rest_cnt);
}
}
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));
bb.writeLog("人性化规则处理前数据: " + 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));
bb.writeLog("人性化规则处理后数据: " + 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 isondutyfreecheck =false;
boolean isoffdutyfreecheck =false;
Map<String, String> model_ShiftRule = kqFormatShiftRule.getModel_ShiftRule(i, workTime.getSerialId());
Iterator iter = model_ShiftRule.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String key = Util.null2String(entry.getKey());
String value = Util.null2String(entry.getValue());
if(key.equals("start")&&value.equals("1")){
isondutyfreecheck = true;
}
if(key.equals("end")&&value.equals("1")){
isoffdutyfreecheck = true;
}
}
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;
}
//允许下班不打卡 ,如果上班也没有打卡那么算上班旷工0.5天
if (isoffdutyfreecheck) {
if (checkIn == 0) {//(无签到),就会有上班漏签,如果有下班卡,那么上班漏签
if(forgotBeginWorkCheckMins==0&&absenteeismMins>0){
forgotBeginWorkCheckMins= absenteeismMins ;
}
}
absenteeismMins = 0;
forgotCheckMins = 0;
}
//允许上班不打卡,如果下班也没有打卡,那么算漏签
if(isondutyfreecheck){
if (checkOut == 0) {//(无签退)
if(forgotCheckMins==0&&absenteeismMins>0){
forgotCheckMins= absenteeismMins ;
}
}
absenteeismMins = 0;
forgotBeginWorkCheckMins = 0;
}
if(isondutyfreecheck&&isoffdutyfreecheck){
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);
bb.writeLog("实际出勤计算结果" + attendanceMins + "=" + workMins + "- " + absenteeismMins + "-" + leaveMins + "-" + (beLateMins + graveBeLateMins) + "-" + (leaveEarlyMins - graveLeaveEarlyMins)+" userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps);
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());
/*考勤二开--零点补助start*/
int zeroPointSub = 0;
RecordSet rs = new RecordSet();
Map<String, Object> groupMap = new HashMap<>();
String acqSql = "select kqgroup, grouptype from uf_ZeroPointSubSft";
rs.executeQuery(acqSql);
while (rs.next()) {
String kqgroup = Util.null2String(rs.getString("kqgroup"));
String grouptype = Util.null2String(rs.getString("grouptype"));
if (StringUtils.isNotBlank(kqgroup) && StringUtils.isNotBlank(grouptype)) {
groupMap.put(grouptype, kqgroup);
}
}
bb.writeLog("groupMap: " + groupMap);
bb.writeLog("groupid: " + groupid);
for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) {
Map<String, Object> checkInfo = (Map<String, Object>) lsCheckInfo.get(j);
if ("2".equals(checkInfo.get("signType"))) {//签退
String signDate = Util.null2String(checkInfo.get("signDate"));
String signTime = Util.null2String(checkInfo.get("signTime"));
bb.writeLog("signDate: " + signDate);
bb.writeLog("signTime: " + signTime);
if (groupMap != null && groupMap.size() > 0) {
for (String grouptype : groupMap.keySet()) {
bb.writeLog("grouptype: " + grouptype);
if ("0".equals(grouptype)) {//责任制--23点
String kqgroups = Util.null2String(groupMap.get(grouptype));
bb.writeLog("kqgroups: " + kqgroups);
List<String> groupList = Arrays.asList(kqgroups.split(","));
bb.writeLog("groupList: " + groupList);
if(groupList.contains(groupid)) {
//23:00
if (signTime.length() == 5) {
signTime = signTime + ":00";
}
String subsidyTime = kqDate + " 23:00:00";
bb.writeLog("subsidyTime: " + subsidyTime);
String outTime = signDate + " " + signTime;
bb.writeLog("outTime: " + outTime);
if (outTime.compareTo(subsidyTime) > 0 ) {
zeroPointSub = 1;
}
}
}
if ("1".equals(grouptype)) {//排班制--00点
String kqgroups = Util.null2String(groupMap.get(grouptype));
bb.writeLog("kqgroups: " + kqgroups);
List<String> groupList = Arrays.asList(kqgroups.split(","));
bb.writeLog("groupList: " + groupList);
if(groupList.contains(groupid)) {
//00:00
if (signTime.length() == 5) {
signTime = signTime + ":00";
}
LocalDate date = LocalDate.parse(kqDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDate localDate = date.plusDays(1);
String kqDateNew = localDate.toString();
String subsidyTime = kqDateNew + " 00:00:00";
bb.writeLog("subsidyTime: " + subsidyTime);
String outTime = signDate + " " + signTime;
bb.writeLog("outTime: " + outTime);
if (outTime.compareTo(subsidyTime) > 0 ) {
zeroPointSub = 1;
}
}
}
}
}
}
}
bb.writeLog("zeroPointSub: " + zeroPointSub);
/*考勤二开--零点补助end*/
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));
/*考勤二开--零点补助start*/
params.add(zeroPointSub);
/*考勤二开--零点补助end*/
bb.writeLog("params: " + params);
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);
}
1 year ago
public static double getDistance(double lng1, double lat1, double lng2,double lat2) {
double x, y, distance;
x = (lng2 - lng1) * PI * R
* Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
y = (lat2 - lat1) * PI * R / 180;
distance = Math.hypot(x, y);
return distance;
}
1 year ago
public String getNightShiftSubsidy(String userId, String kqDate) {
RecordSet rs = new RecordSet();
String value = "";
try {
//获取夜班班次
List<String> nightShiftList = new ArrayList<>();
String acqNightShiftSql = "select shift from uf_nightshiftmanage where isdelete is null or isdelete = 0";
rs.executeQuery(acqNightShiftSql);
while (rs.next()) {
String shift = Util.null2String(rs.getString("shift"));
if (StringUtils.isNotBlank(shift)) {
nightShiftList.add(shift);
}
}
if (nightShiftList != null & nightShiftList.size() > 0) {
HostarUtil houtil = new HostarUtil();
//先获取到出勤时长
Map<String, Double> attendanceMinsMap = new HashMap<>();
String acqAttenSql = " select resourceid, attendancemins, kqdate from kq_format_total where resourceid in (" + userId + ") and kqdate >='" + kqDate + "' and kqdate <='" + kqDate + "'";
rs.executeQuery(acqAttenSql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
Double attendancemins = Util.getDoubleValue(Util.null2String(rs.getString("attendancemins")));
String kqdate = Util.null2String(rs.getString("kqdate"));
if (attendancemins >= 0.00 ) {
attendanceMinsMap.put(resourceid+"|"+kqdate, attendancemins);
}
}
KQWorkTime kqWorkTime = new KQWorkTime();
//获取当天班次
Map<String, Object> serialInfo = kqWorkTime.getSerialInfo(userId, kqDate, false);
if (serialInfo != null && serialInfo.size() > 0) {
int serialid = Util.getIntValue(Util.null2String(serialInfo.get(kqDate)), 0);
if (serialid > 0) {
if ( !nightShiftList.contains(String.valueOf(serialid))) {
return "0";
}
}
}
Double attendanceMins = Util.getDoubleValue(Util.null2String(attendanceMinsMap.get(userId + "|" + kqDate)));
value = (( attendanceMins / 60) >= 8.00 ) ? "1" : "0";
}
} catch (Exception e) {
bb.writeLog("get NightShiftSubsidy error:" + e.getMessage());
}
return value;
}
public String getOtherStatAllowance(String userId, String kqDate) {
RecordSet rs = new RecordSet();
String value = "";
String sqlWhere = " ";
try {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
if(userId.length()>0){
sqlWhere +=" and a.id in("+userId+") ";
}
//获取加班时长
Map<String,Object> dailyFlowOverTimeData = getDailyFlowOverTimeDataAllowance(userId, kqDate);
String otherstatsub = Util.null2String(bb.getPropValue("project_hostar", "otherstatsubcompany"));
if (StringUtils.isNotBlank(otherstatsub)) {
//查询该分部下的人员
List<String> resIds = new ArrayList<>();
sqlWhere += " and a.subcompanyid1 in (" + otherstatsub + ") ";
String acqResSql = "select a.id from hrmresource a where a.status in (0,1,2,3) " + sqlWhere;
bb.writeLog("acqResSql: " + acqResSql);
rs.executeQuery(acqResSql);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
if (StringUtils.isNotBlank(id)) {
resIds.add(id);
}
}
bb.writeLog("resIds: " + resIds);
if (resIds != null && resIds.size() > 0 && StringUtils.isNotBlank(kqDate)) {
HostarUtil houtil = new HostarUtil();
//先获取到出勤时长
Map<String, Double> attendanceMinsMap = new HashMap<>();
String acqAttenSql = " select resourceid, attendancemins, kqdate from kq_format_total where resourceid in (" + String.join(",", resIds) + ") and kqdate >='" + kqDate + "' and kqdate <='" + kqDate + "'";
rs.executeQuery(acqAttenSql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
Double attendancemins = Util.getDoubleValue(Util.null2String(rs.getString("attendancemins")));
String kqdate = Util.null2String(rs.getString("kqdate"));
if (attendancemins >= 0.00) {
attendanceMinsMap.put(resourceid + "|" + kqdate, attendancemins);
}
}
List<String> removeRes = new ArrayList<>();
String acqNoOtherStatAllResSql = "select resourceid from uf_NoOtherStatAllRe where isdelete is null or isdelete = 0 ";
rs.executeQuery(acqNoOtherStatAllResSql);
while (rs.next()){
String resourceid = Util.null2String(rs.getString("resourceid"));
if (StringUtils.isNotBlank(resourceid) ) {
removeRes.add(resourceid);
}
}
if ( removeRes != null && removeRes.size() > 0 ) {
resIds.removeIf(removeRes::contains);
}
for (String res : resIds) {
//获取考勤打卡
Map<String, Object> otherinfo = new HashMap<>();//存一些用得到的信息
String uuid = UUID.randomUUID().toString();
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
ArrayList<String> hostIps = InitServer.getRealIp();//获取IP
boolean oneSign = false;//一天一段出勤时间段
List<TimeScopeEntity> lsSignTime = new ArrayList<>();
List<TimeScopeEntity> lsWorkTime = new ArrayList<>();
// List<TimeScopeEntity> lsRestTime = new ArrayList<>();
KQWorkTime kqWorkTime = new KQWorkTime();
kqWorkTime.setIsFormat(true);
WorkTimeEntity workTime = kqWorkTime.getWorkTime(res, kqDate);
String preDate = DateUtil.addDate(kqDate, -1);//上一天日期
String nextDate = DateUtil.addDate(kqDate, 1);//下一天日期
if (workTime != null) {
lsSignTime = workTime.getSignTime();//允许打卡时间
lsWorkTime = workTime.getWorkTime();//工作时间
// lsRestTime = workTime.getRestTime();//休息时段时间
oneSign = lsWorkTime != null && lsWorkTime.size() == 1;
}
int shiftCount = lsWorkTime == null ? 0 : lsWorkTime.size();
int shiftI = 0;
List<Object> lsCheckInfo = new ArrayList<>();
for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) {
shiftI = i;
TimeScopeEntity signTimeScope = lsSignTime.get(i);
TimeScopeEntity workTimeScope = lsWorkTime.get(i);
Map<String, String> shifRuleMap = Maps.newHashMap();
String workBeginTime = Util.null2String(workTimeScope.getBeginTime());
int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime);
String workEndTime = Util.null2String(workTimeScope.getEndTime());
int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime);
boolean workEndTimeAcross = workTimeScope.getEndTimeAcross();
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, res, 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);
}
}
}
}
lsCheckInfo = new KQFormatSignData().getSignInfo(res, signTimeScope, workTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo, hostIps, uuid, shiftCount, shiftI);
}
List<String> signIdList = new ArrayList<>();
for (int i = 0; i < lsCheckInfo.size(); i++) {
Object o = lsCheckInfo.get(i);
if ( o != null && o != "") {
Map<String, Object> temp = (Map<String, Object>) o;
String signId = Util.null2String(temp.get("signId"));
if (StringUtils.isNotBlank(signId)) {
signIdList.add(signId);
}
}
}
Integer signNumber = 0;
if (signIdList !=null && signIdList.size() > 0) {
String acqShowAddress = "select showaddress,addr from hrmschedulesign where id in (" + String.join(",", signIdList) + ") ";
// bb.writeLog("acqShowAddress: " + acqShowAddress);
rs.executeQuery(acqShowAddress);
while (rs.next()) {
String showaddress = Util.null2String(rs.getString("showaddress"));
String addr = Util.null2String(rs.getString("addr"));
if ("鸿仕达".equals(showaddress) || "hostar".equalsIgnoreCase(showaddress) || "鸿仕达".equals(addr) || "hostar".equalsIgnoreCase(addr)) {
signNumber = signNumber + 1;
}
}
}
if (signNumber == 0) {
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave;
double temp = workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave +
workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave;
// bb.writeLog("-=-temp:" + temp);
Double attendanceMins = Util.getDoubleValue(Util.null2String(attendanceMinsMap.get(res + "|" + kqDate)));
// bb.writeLog("-=-attendanceMins:" + attendanceMins);
double v = Math.round (((attendanceMins < 0.00) ? 0.00 : attendanceMins) + temp) / 60.00;
value = "0";
if (v >= 4.00 && v < 9.00) {
value = "1";
} else if (v >= 9.00) {
value = "2";
}
}
}
}
}
} catch (Exception e) {
bb.writeLog("get OtherStatAllowance error:" + e.getMessage());
}
return value;
}
public Map<String,Object> getDailyFlowOverTimeDataAllowance(String userId, String kqDate){
Map<String,Object> datas = new HashMap<>();;
RecordSet rs = new RecordSet();
String sql = "";
String sqlWhere = " ";
String valueRes = "";
try{
if(userId.length()>0){
sqlWhere +=" and a.id in("+userId+") ";
}
KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz();
int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位
double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系
String valueField = "";
if(uintType==3 || uintType== 5 || uintType== 6){//按小时计算
valueField = "sum( case when durationrule='3' then duration else duration*"+hoursToDay+" end) as val";
}else{//按天计算
valueField = "sum( case when durationrule='3' then duration/"+hoursToDay+" else duration end) as val";
}
sql = " select resourceid,changeType,belongdate,paidLeaveEnable, sum(cast(duration_min as decimal(18,4))) as val "+
" from hrmresource a, kq_flow_overtime b "+
" where a.id = b.resourceid and belongdate >='"+kqDate+"' and belongdate <='"+kqDate+"' " +sqlWhere+
" group by resourceid,changeType,paidLeaveEnable,belongdate ";
rs.execute(sql);
while (rs.next()) {
String resourceid = rs.getString("resourceid");
String belongdate = rs.getString("belongdate");
String paidLeaveEnable = rs.getString("paidLeaveEnable");
int changeType =rs.getInt("changeType");//1-节假日、2-工作日、3-休息日
double value = rs.getDouble("val")<0?0:rs.getDouble("val");
if(uintType==3 || uintType== 5 || uintType== 6){//按小时计算
value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value+""));
}else{//按天计算
value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value+""));
}
String flowType = "";
if(changeType==1){
flowType = "holidayOvertime";
}else if(changeType==2){
flowType = "workingDayOvertime";
}else if(changeType==3){
flowType = "restDayOvertime";
}
if("1".equalsIgnoreCase(paidLeaveEnable)){
//1表示关联调休
flowType += "_4leave";
}else{
//0表示不关联调休
flowType += "_nonleave";
}
//df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了
symbols.setDecimalSeparator('.');
df.setMaximumFractionDigits(5);
df.setDecimalFormatSymbols(symbols);
datas.put(resourceid+"|"+belongdate+"|"+flowType, df.format(value));
}
}catch (Exception e){
bb.writeLog("getDailyFlowOverTimeDataAllowance error:" + e.getMessage());
}
return datas;
}
public String getNightAllowance(String userId, String kqDate){
String value = "";
RecordSet rs = new RecordSet();
String sql = "";
String sqlWhere = " ";
try {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
if(userId.length()>0){
sqlWhere +=" and a.id in("+userId+") ";
}
//获取加班时长
Map<String, Object> dailyFlowOverTimeData = getDailyFlowOverTimeDataAllowance(userId, kqDate);
//获取夜班班次
List<String> nightShiftList = new ArrayList<>();
String acqNightShiftSql = "select shift from uf_nightshiftmanage where isdelete is null or isdelete = 0";
rs.executeQuery(acqNightShiftSql);
while (rs.next()) {
String shift = Util.null2String(rs.getString("shift"));
if (StringUtils.isNotBlank(shift)) {
nightShiftList.add(shift);
}
}
if (nightShiftList != null & nightShiftList.size() > 0) {
String nightshiftsub = Util.null2String(bb.getPropValue("project_hostar", "nightshiftsubcompany"));
if (StringUtils.isNotBlank(nightshiftsub)) {
//查询该分部下的人员
List<String> resIds = new ArrayList<>();
sqlWhere += " and a.subcompanyid1 in (" + nightshiftsub + ") ";
String acqResSql = "select a.id from hrmresource a where a.status in (0,1,2,3) " + sqlWhere;
bb.writeLog("acqResSql: " + acqResSql);
rs.executeQuery(acqResSql);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
if (StringUtils.isNotBlank(id)) {
resIds.add(id);
}
}
bb.writeLog("resIds: " + resIds);
if (resIds != null && resIds.size() > 0) {
HostarUtil houtil = new HostarUtil();
//先获取到出勤时长
Map<String, Double> attendanceMinsMap = new HashMap<>();
String acqAttenSql = " select resourceid, attendancemins, kqdate from kq_format_total where resourceid in (" + String.join(",", resIds) + ") and kqdate >='" + kqDate + "' and kqdate <='" + kqDate + "'";
rs.executeQuery(acqAttenSql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
Double attendancemins = Util.getDoubleValue(Util.null2String(rs.getString("attendancemins")));
String kqdate = Util.null2String(rs.getString("kqdate"));
if (attendancemins >= 0.00) {
attendanceMinsMap.put(resourceid + "|" + kqdate, attendancemins);
}
}
KQWorkTime kqWorkTime = new KQWorkTime();
for (String res : resIds) {
//获取当天班次
Map<String, Object> serialInfo = kqWorkTime.getSerialInfo(res, kqDate, false);
if (serialInfo != null && serialInfo.size() > 0) {
int serialid = Util.getIntValue(Util.null2String(serialInfo.get(kqDate)), 0);
if (serialid > 0) {
if (!nightShiftList.contains(String.valueOf(serialid))) {
continue;
}
}
}
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave;
double temp = workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave +
workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave;
// bb.writeLog("-=-temp:" + temp);
Double attendanceMins = Util.getDoubleValue(Util.null2String(attendanceMinsMap.get(res + "|" + kqDate)));
// bb.writeLog("-=-attendanceMins:" + attendanceMins);
value = String.valueOf(Math.floor(((attendanceMins < 0.00 ? 0.00 : attendanceMins) + temp) / 300));
}
}
}
}
} catch (Exception e) {
bb.writeLog("get NightAllowance error:" + e.getMessage());
}
return value;
}
public String getStatAllowance(String userId, String kqDate) {
String value = "0";
RecordSet rs = new RecordSet();
String sql = "";
String sqlWhere = " ";
try {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
if(userId.length()>0){
sqlWhere +=" and a.id in("+userId+") ";
}
//获取加班时长
Map<String, Object> dailyFlowOverTimeData = getDailyFlowOverTimeDataAllowance(userId, kqDate);
//首先去除指定不享有的分部
List<String> subComoanyList = new ArrayList<>();
String acqNoStatAllSql = "select subcompany from uf_NoStatAllSubCom where isdelete = 0 or isdelete is null";
rs.executeQuery(acqNoStatAllSql);
while (rs.next()) {
String subcompany = Util.null2String(rs.getString("subcompany"));
if (StringUtils.isNotBlank(subcompany)) {
subComoanyList.add(subcompany);
}
}
String subComoanys = "";
if ( subComoanyList != null && subComoanyList.size() > 0) {
subComoanys = String.join(",", subComoanyList);
}
if (StringUtils.isNotBlank(subComoanys)) {
sqlWhere += " and a.subcompanyid1 not in ("+subComoanys+") ";
}
//指定人员不享受
List<String> noRes = new ArrayList<>();
String acqNoResSql = "select resourceid from uf_NoStatAllRes where isdelete = 0 or isdelete is null";
rs.executeQuery(acqNoResSql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
if (StringUtils.isNotBlank(resourceid)) {
noRes.add(resourceid);
}
}
if ( noRes !=null && noRes.size()>0) {
sqlWhere += " and a.id not in ("+String.join(",", noRes)+") ";
}
List<String> resIds = new ArrayList<>();
String acqResSql = "select a.id from hrmresource a where a.status in (0,1,2,3) " + sqlWhere;
bb.writeLog("acqResSql: " + acqResSql);
rs.executeQuery(acqResSql);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
if (StringUtils.isNotBlank(id)) {
resIds.add(id);
}
}
bb.writeLog("resIds: " + resIds);
if (resIds != null && resIds.size() > 0 && StringUtils.isNotBlank(kqDate)) {
HostarUtil houtil = new HostarUtil();
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
//先获取到出勤时长
Map<String, Double> attendanceMinsMap = new HashMap<>();
String acqAttenSql = " select resourceid, attendancemins, kqdate from kq_format_total where resourceid in (" + String.join(",",resIds) + ") and kqdate >='" + kqDate + "' and kqdate <='" + kqDate + "'";
rs.executeQuery(acqAttenSql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
Double attendancemins = Util.getDoubleValue(Util.null2String(rs.getString("attendancemins")));
String kqdate = Util.null2String(rs.getString("kqdate"));
if (attendancemins >= 0.00 ) {
attendanceMinsMap.put(resourceid+"|"+kqdate, attendancemins);
}
}
// 获取享受的考勤组
List<String> grouplist = new ArrayList<String>();
String acqGroupSql = "select kqgroup from uf_StatAlloKqGroup where isdelete is null or isdelete = 0 " ;
rs.executeQuery(acqGroupSql);
while (rs.next()) {
String kqgroup = Util.null2String(rs.getString("kqgroup"));
if (StringUtils.isNotBlank(kqgroup)) {
grouplist.add(kqgroup);
}
}
if ( grouplist != null && grouplist.size() == 0) {
return "0";
}
for (String res: resIds) {
//判断考勤组
/*获取考勤组的ID因为考勤组有有效期所以需要传入日期*/
String groupId = kqGroupMemberComInfo.getKQGroupId(userId, kqDate);
if ( !grouplist.contains(groupId)) {
continue;
}
//获取考勤打卡
Map<String,Object> otherinfo = new HashMap<>();//存一些用得到的信息
String uuid = UUID.randomUUID().toString();
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
ArrayList<String> hostIps = InitServer.getRealIp();//获取IP
boolean oneSign = false;//一天一段出勤时间段
List<TimeScopeEntity> lsSignTime = new ArrayList<>();
List<TimeScopeEntity> lsWorkTime = new ArrayList<>();
KQWorkTime kqWorkTime = new KQWorkTime();
kqWorkTime.setIsFormat(true);
WorkTimeEntity workTime = kqWorkTime.getWorkTime(res, kqDate);
String preDate = DateUtil.addDate(kqDate, -1);//上一天日期
String nextDate = DateUtil.addDate(kqDate, 1);//下一天日期
if (workTime != null) {
lsSignTime = workTime.getSignTime();//允许打卡时间
lsWorkTime = workTime.getWorkTime();//工作时间
oneSign = lsWorkTime!=null&&lsWorkTime.size()==1;
}
int shiftCount = lsWorkTime == null ? 0 : lsWorkTime.size();
int shiftI = 0;
List<Object> lsCheckInfo = new ArrayList<>();
for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) {
shiftI = i;
TimeScopeEntity signTimeScope = lsSignTime.get(i);
TimeScopeEntity workTimeScope = lsWorkTime.get(i);
Map<String, String> shifRuleMap = Maps.newHashMap();
String workBeginTime = Util.null2String(workTimeScope.getBeginTime());
int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime);
String workEndTime = Util.null2String(workTimeScope.getEndTime());
int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime);
boolean workEndTimeAcross = workTimeScope.getEndTimeAcross();
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, res, 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);
}
}
}
}
lsCheckInfo = new KQFormatSignData().getSignInfo(res,signTimeScope,workTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo,hostIps,uuid,shiftCount,shiftI);
}
List<String> signIdList = new ArrayList<>();
for (int i = 0; i < lsCheckInfo.size(); i++) {
Object o = lsCheckInfo.get(i);
if ( o != null && o != "") {
Map<String, Object> temp = (Map<String, Object>) o;
String signId = Util.null2String(temp.get("signId"));
if (StringUtils.isNotBlank(signId)) {
signIdList.add(signId);
}
}
}
bb.writeLog("signIdList " + signIdList);
Integer signNumber = 0;
if (signIdList !=null && signIdList.size() > 0) {
String acqShowAddress = "select showaddress,addr from hrmschedulesign where id in (" + String.join(",", signIdList) + ") ";
bb.writeLog("acqShowAddress: " + acqShowAddress);
rs.executeQuery(acqShowAddress);
while (rs.next()) {
String showaddress = Util.null2String(rs.getString("showaddress"));
String addr = Util.null2String(rs.getString("addr"));
if ("鸿仕达".equals(showaddress) || "hostar".equalsIgnoreCase(showaddress) || "鸿仕达".equals(addr) || "hostar".equalsIgnoreCase(addr)) {
signNumber = signNumber + 1;
}
}
}
if (signNumber == 0 ) {
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(dailyFlowOverTimeData.get(res + "|" + kqDate + "|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave;
double temp = workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave +
workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave;
Double attendanceMins = Util.getDoubleValue(Util.null2String(attendanceMinsMap.get(res + "|" + kqDate)));
value = String.valueOf(Math.floor( ((attendanceMins < 0.00 ? 0.00 : attendanceMins) + temp) / 300));
}
}
}
} catch (Exception e) {
bb.writeLog("get StatAllowance error:" + e.getMessage());
}
return value;
}
public String getMealAllowance(String id, String kqDateA) {
String value = "0";
RecordSet rs = new RecordSet();
String sql = "";
String sqlWhere = " ";
try {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
if(id.length()>0){
sqlWhere +=" and b.id in("+id+") ";
}
// 首先获取出差公出流程信息
Map<String, Object> evectionMap = new HashMap<>();
String evectionTableName = Util.null2String(bb.getPropValue("project_hostar","evectionTableName"));
sql = " select d.resourceid, d.belongdate, d.longitude, d.latitude from ( " +
" select a.belongdate, b.id as resourceid, b.subcompanyid1, b.departmentid, b.managerstr, b.managerid, b.loginid, c.jd as longitude, c.wd as latitude from kq_flow_split_evection a " +
" left join hrmresource b " +
" on b.id = a.resourceid " +
" left join " + evectionTableName + " c " +
" on c.requestid = a.requestid " +
" where a.belongdate >='"+kqDateA+"' and a.belongdate <='"+kqDateA+"' " + sqlWhere +
" ) d " +
" where 1=1 " ;
bb.writeLog("sql: " + sql);
rs.execute(sql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
String belongdate = Util.null2String(rs.getString("belongdate"));
String longitude = Util.null2String(rs.getString("longitude"));
String latitude = Util.null2String(rs.getString("latitude"));
evectionMap.put( belongdate + "|" + resourceid, longitude + "|" + latitude );
}
bb.writeLog("evectionMap: " + evectionMap);
//获取外勤打卡数据
KQWorkTime kqWorkTime = new KQWorkTime();
kqWorkTime.setIsFormat(true);
Map< String, Map<String, Object>> lsCheckInfo = new HashMap<>();
for ( String key: evectionMap.keySet()) {
String[] split = key.split("\\|");
String kqDate = split[0];
String userId = split[1];
WorkTimeEntity workTime = kqWorkTime.getWorkTime(userId, kqDate);
List<TimeScopeEntity> lsSignTime = new ArrayList<>();
List<TimeScopeEntity> lsWorkTime = new ArrayList<>();
if (workTime != null) {
lsSignTime = workTime.getSignTime();//允许打卡时间
lsWorkTime = workTime.getWorkTime();//工作时间
}
//只支持一天一次上下班
if (lsWorkTime != null && lsWorkTime.size()==1 ) {
TimeScopeEntity signTimeScope = lsSignTime.get(0);
TimeScopeEntity workTimeScope = lsWorkTime.get(0);
List<Map<String, Object>> legWorkInfos = new ArrayList<>();
//获取允许打卡时间
String signBeginTime = signTimeScope.getBeginTime();
if (StringUtils.isNotBlank(signBeginTime)) {
signBeginTime = signBeginTime + ":00";
}
//获取上班时间
String workBeginTime = workTimeScope.getBeginTime();
if (StringUtils.isNotBlank(workBeginTime)) {
workBeginTime = workBeginTime + ":00";
}
String acqLegWorkSignSql = "select operate_time, longitude, latitude from mobile_sign where operater = ? and operate_date = '" + kqDate + "' and operate_time >='" + signBeginTime + "' order by operate_time asc ";
rs.executeQuery(acqLegWorkSignSql, userId);
while ( rs.next()) {
String operateTime = Util.null2String(rs.getString("operate_time"));
String longitude = Util.null2String(rs.getString("longitude"));
String latitude = Util.null2String(rs.getString("latitude"));
if ( StringUtils.isNotBlank(operateTime) && StringUtils.isNotBlank(longitude) && StringUtils.isNotBlank(latitude) ) {
Map<String, Object> temp = new HashMap<>();
temp.put("operateTime", operateTime);
temp.put("longitude", longitude);
temp.put("latitude", latitude);
legWorkInfos.add(temp);
}
}
if (legWorkInfos != null && legWorkInfos.size() > 0 ) {
String tempSignIn = "";
String tempSignInLatitude = "";
String tempSignInLongitude = "";
String tempSignOutLatitude = "";
String tempSignOutLongitude = "";
String tempSignOut = "";
Map<String, Object> checkInfo = new HashMap<>();
if ( legWorkInfos.size() == 1) {//只有一笔外勤卡直接算上班
Map<String, Object> temp = legWorkInfos.get(0);
String operateTime = Util.null2String(temp.get("operateTime"));
String longitude = Util.null2String(temp.get("longitude"));
String latitude = Util.null2String(temp.get("latitude"));
checkInfo.put("signDate", kqDate);//签到签退日期
checkInfo.put("signInTime", operateTime);//签到时间
checkInfo.put("signInLatitude", latitude);//签到纬度
checkInfo.put("signInLongitude", longitude);//签到经度
lsCheckInfo.put(userId + "|" + kqDate, checkInfo);
} else {
for ( Map<String, Object> temp : legWorkInfos) {
String operateTime = Util.null2String(temp.get("operateTime"));
String longitude = Util.null2String(temp.get("longitude"));
String latitude = Util.null2String(temp.get("latitude"));
if (operateTime.compareTo(workBeginTime) < 0) {//获取上班时间点之前最早的一笔卡
if (StringUtils.isBlank(tempSignIn)) {
tempSignIn = operateTime;
tempSignInLatitude = latitude;
tempSignInLongitude = longitude;
} else {
if ( operateTime.compareTo(tempSignIn) < 0 ) {
tempSignIn = operateTime;
tempSignInLatitude = latitude;
tempSignInLongitude = longitude;
}
}
}
if ( operateTime.compareTo(workBeginTime) > 0) {//下班卡取最晚的一笔
if (StringUtils.isBlank(tempSignIn)) {
tempSignOut = operateTime;
tempSignOutLatitude = latitude;
tempSignOutLongitude = longitude;
} else {
if ( operateTime.compareTo(tempSignOut) > 0 ) {
tempSignOut = operateTime;
tempSignOutLatitude = latitude;
tempSignOutLongitude = longitude;
}
}
}
}
checkInfo.put("signDate", kqDate);//签到签退日期
checkInfo.put("signInTime", tempSignIn);//签到时间
checkInfo.put("signInLatitude", tempSignInLatitude);//签到纬度
checkInfo.put("signInLongitude", tempSignInLongitude);//签到经度
checkInfo.put("signOutTime", tempSignOut);//签退时间
checkInfo.put("signOutLatitude", tempSignOutLatitude);//签退纬度
checkInfo.put("signOutLongitude", tempSignOutLongitude);//签退经度
lsCheckInfo.put(userId + "|" + kqDate, checkInfo);
}
}
}
}
HostarUtil hostarUtil = new HostarUtil();
String MealAlloTableName = Util.null2String(bb.getPropValue("project_hostar", "MealAllowanceTableName"));
if (StringUtils.isNotBlank(MealAlloTableName)) {
//获取餐补判断时间
List<Map<String, String>> MealMap = new ArrayList<>();
String acqTimeSql = "select startTime, endTime from " + MealAlloTableName + " where (isDelete is null or isDelete = 0)";
// bb.writeLog("acqTimeSql: " + acqTimeSql);
rs.executeQuery(acqTimeSql);
while (rs.next()) {
String startTime = Util.null2String(rs.getString("startTime"));
String endTime = Util.null2String(rs.getString("endTime"));
Map<String, String> temp = new HashMap<>();
temp.put("startTime",startTime);
temp.put("endTime",endTime);
MealMap.add(temp);
}
// bb.writeLog("MealMap: " + MealMap);
//根据外勤打卡数据计算餐补数据
for (String key: lsCheckInfo.keySet()) {
String[] split = key.split("\\|");
String userId = split[0];
String kqDate = split[1];
Map<String, Object> temp = lsCheckInfo.get(key);
String signInTime = Util.null2String(temp.get("signInTime"));
String signOutTime = Util.null2String(temp.get("signOutTime"));
if (StringUtils.isNotBlank(signInTime) && StringUtils.isNotBlank(signOutTime) ) {
for (Map<String, String> me: MealMap) {
String startTime = me.get("startTime");
String endTime = me.get("endTime");
if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
startTime = startTime + ":00";
endTime = endTime + ":00";
}
if ( (signInTime.compareTo(startTime) <= 0) && (signOutTime.compareTo(endTime) >= 0) ) {
if (StringUtils.isEmpty(value) || StringUtils.equals(value, "0")) {
value = "1";
} else {
value = String.valueOf(Integer.parseInt(value));
}
}
}
}
}
}
} catch (Exception e) {
bb.writeLog("get MealAllowance error:" + e.getMessage());
}
return value;
}
}