package com.engine.sskj.service.impl; import com.engine.core.impl.Service; import com.engine.kq.biz.KQTimesArrayComInfo; import com.engine.kq.util.KQDurationCalculatorUtil; import com.engine.sskj.service.KqWorkflowService; import com.engine.sskj.util.SskjUtil; import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; import weaver.general.BaseBean; import weaver.general.Util; import java.util.*; public class KqWorkflowServiceImpl extends Service implements KqWorkflowService { BaseBean bb = new BaseBean(); @Override public Map calWorkTime(Map params) { Map result = new HashMap<>(); String startTime = Util.null2String(params.get("starttime")); bb.writeLog("startTime: " + startTime); String endTime = Util.null2String(params.get("endtime")); bb.writeLog("endTime: " + endTime); if (StringUtils.isBlank(startTime) || StringUtils.isBlank(endTime)) { result.put("code",500); result.put("msg", "开始时间或结束时间为空"); return result; } if (startTime.length() == 16) { startTime = startTime + ":00"; } if (endTime.length() == 16) { endTime = endTime + ":00"; } SskjUtil sskjUtil = new SskjUtil(); long time = sskjUtil.getTime(startTime, endTime); bb.writeLog("time: " + time); String betweenHours = KQDurationCalculatorUtil.getDurationRound(String.valueOf(Util.getDoubleValue(time+"")/60.0)); bb.writeLog("betweenHours: " + betweenHours); result.put("code",200); result.put("data",betweenHours); return result; } @Override public Map checkConOverTime(Map params) { Map result = new HashMap<>(); bb.writeLog("checkConOverTime start"); try { RecordSet rs = new RecordSet(); KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); String overTimeInfo = Util.null2String(params.get("overtimeinfo")); bb.writeLog("overTimeInfo: " + overTimeInfo); if (StringUtils.isBlank(overTimeInfo)) { result.put("code", 500); result.put("msg", "请传入加班明细数据"); return result; } //resourceId=10_fromDate=2023-11-24_fromTime=12:00_toDate=2023-11-24_toTime=13:00|resourceId=10_fromDate=2023-11-24_fromTime=12:00_toDate=2023-11-24_toTime=13:00 String[] overTimeInfos = overTimeInfo.split("\\|"); /*同条流程间校验*/ if (overTimeInfos.length > 1) { Map resToOvInMap = new HashMap<>(); for (String oti : overTimeInfos) { String resourceId = ""; String fromDate = ""; String fromTime = ""; String toDate = ""; String toTime = ""; String[] otiArray = oti.split("_"); for (String ot : otiArray) { String[] split = ot.split("="); if ("resourceId".equals(split[0])) { resourceId = split[1]; } if ("fromDate".equals(split[0])) { fromDate = split[1]; } if ("fromTime".equals(split[0])) { fromTime = split[1]; } if ("toDate".equals(split[0])) { toDate = split[1]; } if ("toTime".equals(split[0])) { toTime = split[1]; } bb.writeLog("ot: " + ot); } if (resToOvInMap.containsKey(resourceId)) { bb.writeLog("containsKey" ); int[] dayMins = resToOvInMap.get(resourceId); int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime); bb.writeLog("fromTimeIdx: " + fromTimeIdx ); int toTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(toTime); bb.writeLog("toTimeIdx: " + toTimeIdx ); if (fromDate.compareTo(toDate) < 0 ) { toTimeIdx = toTimeIdx + 1440; } //先判断是否已经存在了 boolean isExist = false; for (int i = fromTimeIdx; i <= toTimeIdx; i++) { if (dayMins[i] == 1) { isExist = true; } } bb.writeLog("isExist: " + isExist ); if (!isExist) { Arrays.fill(dayMins, fromTimeIdx, toTimeIdx, 1);//加班时段标识 1 } else { String lastname = ""; String acqResLastNameSql = "select lastname from hrmresource where id = ? "; rs.executeQuery(acqResLastNameSql, resourceId); while (rs.next()) { lastname = Util.null2String(rs.getString("lastname")); } bb.writeLog("lastname: " + lastname ); result.put("code", 500); result.put("msg", "加班人员:" + lastname + " 的" + fromDate + " " + fromTime + "--" + toDate + " " + toTime + "在明细表中存在重复部分,请调整!"); return result; } resToOvInMap.put(resourceId, dayMins); } else { int[] dayMins = new int[2880];//一天所有分钟数 bb.writeLog("fromTime: " + fromTime ); int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime); bb.writeLog("fromTimeIdx: " + fromTimeIdx ); bb.writeLog("toTime: " + toTime ); int toTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(toTime); bb.writeLog("toTimeIdx: " + toTimeIdx ); if (fromDate.compareTo(toDate) < 0 ) { toTimeIdx = toTimeIdx + 1440; } Arrays.fill(dayMins, fromTimeIdx, toTimeIdx, 1);//加班时段标识 1 resToOvInMap.put(resourceId, dayMins); } } } /*与历史数据校验*/ for (String oti : overTimeInfos) { String[] otiArray = oti.split("_"); String resourceId = ""; String fromDate = ""; String fromTime = ""; String toDate = ""; String toTime = ""; //取出加班数据 for (String ot : otiArray) { String[] split = ot.split("="); if ("resourceId".equals(split[0])) { resourceId = split[1]; } if ("fromDate".equals(split[0])) { fromDate = split[1]; } if ("fromTime".equals(split[0])) { fromTime = split[1]; } if ("toDate".equals(split[0])) { toDate = split[1]; } if ("toTime".equals(split[0])) { toTime = split[1]; } } //获取已有的连班加班的数据--(此处连班加班指班次的休息时间) //设置一个时间轴数组,长度为一天的分钟数 int[] dayMins = new int[2880];//一天所有分钟数 Arrays.fill(dayMins, 0); String acqConOverTimeSql = "select fromDate, fromTime, toDate, toTime from uf_conOvertime where resourceId = ? and fromDate = ? and toDate = ?"; rs.executeQuery(acqConOverTimeSql, resourceId, fromDate, toDate); while (rs.next()) { String fTime = Util.null2String(rs.getString("fromTime")); String fDate = Util.null2String(rs.getString("fromDate")); String tTime = Util.null2String(rs.getString("toTime")); String tDate = Util.null2String(rs.getString("toDate")); //将时间转成时间轴上对应的点 int fTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fTime); int tTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(tTime); if (fDate.compareTo(tDate) < 0) { tTimeIdx = tTimeIdx +1440; } Arrays.fill(dayMins, fTimeIdx, tTimeIdx, 1);//加班时段标识 1 } int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime); int toTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(toTime); //确认fromTimeIdx-toTimeIdx在时间轴上是否有1 boolean isExist = false; for (int i = fromTimeIdx; i <= toTimeIdx; i++) { if (dayMins[i] == 1) { isExist = true; } } if (isExist) { String lastname = ""; String acqResLastNameSql = "select lastname from hrmresource where id = ? "; rs.executeQuery(acqResLastNameSql, resourceId); while (rs.next()) { lastname = Util.null2String(rs.getString("lastname")); } result.put("code", 500); result.put("msg", "加班人员:" + lastname + " 的" + fromDate + " " + fromTime + "--" + toDate + " " + toTime + "已经申请过连班加班,不可重复申请!"); return result; } } } catch (Exception e) { bb.writeLog("checkConOverTime exception: " + e); result.put("code",500); result.put("msg","加班数据校验异常"); return result; } result.put("code",200); result.put("msg","加班数据没有重复"); return result; } @Override public Map importOverTime(Map params) { bb.writeLog("importOverTime start"); String coiledWf = Util.null2String(bb.getPropValue("project_sskj", "coiledOverTimeWorkflow")); if (StringUtils.isNotBlank(coiledWf)) { RecordSet rs = new RecordSet(); //流程明细表中获取没有加班时长的数据 List< Map< String, Object>> overtimeInfos = new ArrayList<>(); String acqSql = "select id, ksrq, kssj, jsrq, jssj from " + coiledWf + " where jbsch is null "; rs.executeQuery(acqSql); while (rs.next()) { String id = Util.null2String(rs.getString("id")); String ksrq = Util.null2String(rs.getString("ksrq")); String kssj = Util.null2String(rs.getString("kssj")); String jsrq = Util.null2String(rs.getString("jsrq")); String jssj = Util.null2String(rs.getString("jssj")); Map< String, Object> overtimeInfo = new HashMap<>(); overtimeInfo.put("id", id); overtimeInfo.put("starttime", ksrq + " " + kssj); overtimeInfo.put("endtime", jsrq + " " + jssj); overtimeInfos.add(overtimeInfo); } String syncSql = "update " + coiledWf + " set jbsch = ? where id = ?"; for (Map< String, Object> overtimeInfo : overtimeInfos) { String id = Util.null2String(overtimeInfo.get("id")); Map stringObjectMap = this.calWorkTime(overtimeInfo); if (Util.null2String(stringObjectMap.get("code")).equals("200")) { rs.executeUpdate(syncSql, Util.null2String(stringObjectMap.get("data")), id); } } } return null; } @Override public Map getEntryType(Map params) { Map result = new HashMap<>(); bb.writeLog("getEntryType start "); String resourceId = Util.null2String(params.get("resourceid")); bb.writeLog("resourceId: " + resourceId); if (StringUtils.isBlank(resourceId) ) { result.put("code",500); result.put("msg", "请先选择请假人"); return result; } String entryTypeField = Util.null2String(bb.getPropValue("project_sskj", "entryTypeField")); bb.writeLog("entryTypeField: " + entryTypeField); String entryTypeFieldValue = ""; String acqEntryTypeSql = "select " + entryTypeField + " from cus_fielddata where scopeid = 3 and id = ? "; bb.writeLog("acqEntryTypeSql: " + acqEntryTypeSql); RecordSet rs = new RecordSet(); rs.executeQuery(acqEntryTypeSql, resourceId); if (rs.next()) { String temp = Util.null2String(rs.getString(1)); bb.writeLog("temp: " + temp); if (StringUtils.isNotBlank(temp)) { entryTypeFieldValue = temp; } } result.put("code",200); result.put("data",entryTypeFieldValue); return result; } }