diff --git a/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java b/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java index f1bec85..aab9a1c 100644 --- a/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java +++ b/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java @@ -24,6 +24,8 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; import weaver.common.DateUtil; import weaver.conn.RecordSet; import weaver.formmode.setup.ModeRightInfo; @@ -106,6 +108,8 @@ public class KQOverTimeRuleCalBiz { computingModeMap,kqTimesArrayComInfo,uuid,singleRs); } } + fromDate=preFromDate.format(dateFormatter); + updateTiaoXiu(resourceid, fromDate, toDate); }catch (Exception e){ kqLog.info("加班生成数据报错:KQOverTimeRuleCalBiz:"); StringWriter errorsWriter = new StringWriter(); @@ -114,6 +118,116 @@ public class KQOverTimeRuleCalBiz { } } + + /** + * 更新调休 + * @param resourceid + * @param fromDate + * @param toDate + */ + public void updateTiaoXiu(String resourceid, String fromDate, String toDate){ + //假期类型的缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + //[调休]的假期类型的ID + String leaveRulesId = ""; + //找到[调休]的假期类型ID + rulesComInfo.setTofirstRow(); + while (rulesComInfo.next()) { + if (KQLeaveRulesBiz.isTiaoXiu(rulesComInfo.getId())) { + if("1".equals(rulesComInfo.getIsEnable())){ + leaveRulesId = rulesComInfo.getId(); + break; + } + } + } + RecordSet recordSet = new RecordSet(); + String sql = " select * from kq_balanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceid + + " and leaveRulesId=" + leaveRulesId + + " and effectiveDate>='" + fromDate + "' and effectiveDate<='" +toDate+"'"+ + " order by belongYear asc,effectiveDate asc,id asc "; + recordSet.executeQuery(sql); + String all_tiaoxiuids = ""; + BigDecimal duration = new BigDecimal("0"); + while (recordSet.next()) { + //额外 + BigDecimal extraAmount = new BigDecimal(Util.null2s(recordSet.getString("extraAmount"), "0")); + //加班生成调休 + BigDecimal tiaoxiuAmount = new BigDecimal(Util.null2s(recordSet.getString("tiaoxiuamount"), "0")); + //已休 + BigDecimal usedAmount = new BigDecimal(Util.null2s(recordSet.getString("usedAmount"), "0")); + + if (extraAmount.add(tiaoxiuAmount).subtract(usedAmount).doubleValue() >= 0) { + continue; + } + String id = recordSet.getString("id"); + if(id.length() > 0 && Util.getIntValue(id) > 0){ + all_tiaoxiuids += ","+id; + duration =duration.add(extraAmount).add(tiaoxiuAmount).subtract(usedAmount); + } + } + duration = duration.abs(); + List updateList = new ArrayList(); + sql = " select * from kq_balanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceid + + " and leaveRulesId=" + leaveRulesId + + " and effectiveDate>='" + fromDate + "'"+ + " order by belongYear asc,effectiveDate asc,id asc "; + recordSet.executeQuery(sql); + int total = recordSet.getCounts(); + int index = 0; + while (recordSet.next()) { + index++; + String id = recordSet.getString("id"); + //额外 + BigDecimal extraAmount = new BigDecimal(Util.null2s(recordSet.getString("extraAmount"), "0")); + //加班生成调休 + BigDecimal tiaoxiuAmount = new BigDecimal(Util.null2s(recordSet.getString("tiaoxiuamount"), "0")); + //已休 + BigDecimal usedAmount = new BigDecimal(Util.null2s(recordSet.getString("usedAmount"), "0")); + + if (extraAmount.add(tiaoxiuAmount).subtract(usedAmount).doubleValue() <= 0) { + continue; + } + BigDecimal temp = extraAmount.add(tiaoxiuAmount).subtract(usedAmount).subtract(duration); + /*该假期剩余假期余额不足以扣减,记录错误日志,退出方法*/ + if (index == total && temp.doubleValue() < 0) { + kqLog.info("该人员的该假期所有的剩余假期余额都不足以扣减。" + + "resourceId=" + resourceid + ",date=" + fromDate + ",ruleId=" + leaveRulesId + ",duration=" + duration + ",extraAmount=" + extraAmount.doubleValue() + ",usedAmount=" + usedAmount.doubleValue()); + String newUsedAmount = usedAmount.add(duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + " where id=" + id; + updateList.add(updateSql); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount = usedAmount.add(duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + " where id=" + id; + updateList.add(updateSql); + break; + } else { + duration = duration.add(usedAmount).subtract(extraAmount).subtract(tiaoxiuAmount); + String newUsedAmount = extraAmount.add(tiaoxiuAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + " where id=" + id; + updateList.add(updateSql); + continue; + } + } + if(all_tiaoxiuids.length() > 0) { + all_tiaoxiuids = all_tiaoxiuids.substring(1); + updateList.add("update kq_balanceOfLeave set isDelete=1 where id in (" +all_tiaoxiuids+")"); + } + kqLog.info("updateList:"+updateList); + /*SQL操作批处理*/ + for (int i = 0; i < updateList.size(); i++) { + boolean flag = recordSet.executeUpdate(updateList.get(i)); + if (!flag) { + kqLog.info("刷新加班流程数据失败:数据库更新失败" ); + return; + } + } + + } + /** * 需审批,以打卡为准,取流程和打卡的交集 * @param resourceid @@ -584,6 +698,40 @@ public class KQOverTimeRuleCalBiz { String overtimeid = get_overtime_uuid(overtime_uuid); kqEventLogBiz.updateOvertimeId(uuid, overtimeid); + + new BaseBean().writeLog("tiaoxiuId---2:"+tiaoxiuId); + if(StringUtils.isNotBlank(tiaoxiuId)){ + if (isRestSerial(searIdFrom,rs)) { + + Double sc = divide(String.valueOf(across_mins),"60"); + + new BaseBean().writeLog("更新kq_balanceOfLeave的sc:"+across_mins); + sc = recalculateOverTime(sc,searIdFrom, fromdatedb, fromtimedb, todatedb, totimedb, rs, singleRs); + new BaseBean().writeLog("重新计算后的sc:"+sc); + String sql = " select * from kq_balanceOfLeave where id = "+tiaoxiuId ; + rs.executeQuery(sql); + if(rs.next()){ + String tiaoxiuamount = Util.null2String(rs.getString("tiaoxiuamount")); + new BaseBean().writeLog("系统计算的调休是:"+tiaoxiuamount); + } + sql = "update kq_balanceOfLeave set tiaoxiuamount="+sc+" where id = "+tiaoxiuId ; + new BaseBean().writeLog("重新计算sql:"+sql); + boolean isTrue = rs.executeUpdate(sql); + new BaseBean().writeLog("重新计算更新:"+isTrue); + new BaseBean().writeLog("overtime_uuid:"+overtime_uuid); + +// if(StringUtils.isNotBlank(overtime_uuid)){ +// int duration_min = (int)sc.doubleValue()*60; +// sql = " update kq_flow_overtime set duration_min='"+duration_min+"' where uuid='"+overtime_uuid+"'" ; +// new BaseBean().writeLog("重新计算kq_flow_overtime的sql:"+sql); +// isTrue = rs.executeUpdate(sql); +// new BaseBean().writeLog("kq_flow_overtime重新计算更新:"+isTrue); +// } + + + } + } + } } }else{ @@ -906,8 +1054,39 @@ public class KQOverTimeRuleCalBiz { String overtimeid = get_overtime_uuid(overtime_uuid); kqEventLogBiz.updateOvertimeId(uuid, overtimeid); - } + + new BaseBean().writeLog("tiaoxiuId---:"+tiaoxiuId); + if(StringUtils.isNotBlank(tiaoxiuId)) { + if (isRestSerial(searIdFrom, rs)) { + + Double sc = divide(String.valueOf(mins), "60"); + + new BaseBean().writeLog("更新kq_balanceOfLeave的sc:" + mins); + sc = recalculateOverTime(sc, searIdFrom, signinDate, signinTime, signoutDate, signoutTime, rs, singleRs); + new BaseBean().writeLog("重新计算后的sc:" + sc); + String sql = " select * from kq_balanceOfLeave where id = " + tiaoxiuId; + rs.executeQuery(sql); + if (rs.next()) { + String tiaoxiuamount = Util.null2String(rs.getString("tiaoxiuamount")); + new BaseBean().writeLog("系统计算的调休是:" + tiaoxiuamount); + } + sql = "update kq_balanceOfLeave set tiaoxiuamount=" + sc + " where id = " + tiaoxiuId; + new BaseBean().writeLog("重新计算sql:" + sql); + boolean isTrue = rs.executeUpdate(sql); + new BaseBean().writeLog("重新计算更新:" + isTrue); + new BaseBean().writeLog("overtime_uuid:" + overtime_uuid); + +// if(StringUtils.isNotBlank(overtime_uuid)){ +// int duration_min = (int)sc.doubleValue()*60; +// sql = " update kq_flow_overtime set duration_min='"+duration_min+"' where uuid='"+overtime_uuid+"'" ; +// new BaseBean().writeLog("重新计算kq_flow_overtime的sql:"+sql); +// isTrue = rs.executeUpdate(sql); +// new BaseBean().writeLog("kq_flow_overtime重新计算更新:"+isTrue); +// } + } + } + } } }else{ logOvertimeMap(overtimeLogMap, "打卡区间不正确|"+flow_cross_key, mapKey+"|"+"打卡区间,得到打卡时长|over_count");