diff --git a/src/com/api/attendance/allowance/AllowanceActionApi.java b/src/com/api/attendance/allowance/AllowanceActionApi.java new file mode 100644 index 0000000..d16832c --- /dev/null +++ b/src/com/api/attendance/allowance/AllowanceActionApi.java @@ -0,0 +1,14 @@ +package com.api.attendance.allowance; + +import com.engine.attendance.workflow.web.AllowanceApi; + +import javax.ws.rs.Path; + +/** + * @Author: sy + * @Description: 出勤津贴 + * @Date: 2024/4/9 + **/ +@Path("/attendance/allowance") +public class AllowanceActionApi extends AllowanceApi { +} diff --git a/src/com/engine/attendance/workflow/service/AllowanceService.java b/src/com/engine/attendance/workflow/service/AllowanceService.java new file mode 100644 index 0000000..da0a6da --- /dev/null +++ b/src/com/engine/attendance/workflow/service/AllowanceService.java @@ -0,0 +1,8 @@ +package com.engine.attendance.workflow.service; + +import java.util.Map; + +public interface AllowanceService { + + Map addAllowanceRecords(Map params); +} diff --git a/src/com/engine/attendance/workflow/service/impl/AllowanceServiceImpl.java b/src/com/engine/attendance/workflow/service/impl/AllowanceServiceImpl.java new file mode 100644 index 0000000..8674da2 --- /dev/null +++ b/src/com/engine/attendance/workflow/service/impl/AllowanceServiceImpl.java @@ -0,0 +1,563 @@ +package com.engine.attendance.workflow.service.impl; + +import com.engine.attendance.enums.AccountingUnitEnum; +import com.engine.attendance.enums.AttendanceItemTypeEnum; +import com.engine.attendance.workflow.service.AllowanceService; +import com.engine.common.util.CommonUtil; +import com.engine.common.util.DbTools; +import com.engine.common.util.Utils; +import com.engine.core.impl.Service; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; + +import java.time.Duration; +import java.time.LocalTime; +import java.util.*; + +/** + * @Author: sy + * @Description: 出勤津贴 + * @Date: 2024/4/2 + **/ +public class AllowanceServiceImpl extends Service implements AllowanceService { + BaseBean bs = new BaseBean(); + @Override + public Map addAllowanceRecords(Map params) { + try { + //获取modeId,考勤方案的modeId + Map formmodeIdMap = Utils.getFormmodeIdMap(); + String modeId = formmodeIdMap.get("uf_jcl_kq_kqfa"); + //查询考勤方案 + String sql = "select * from uf_jcl_kq_kqfa where zt = 0"; + List> data = DbTools.getSqlToList(sql); + //获取人员和津贴类型考勤项目信息,构建映射关系 + Map> empIdWithAllowanceInfo = new HashMap<>(); + List targetEmpIdList = new ArrayList<>(); + List targetAllowanceIdList = new ArrayList<>(); + List targetBcIdList = new ArrayList<>(); + for (Map map : data) { + String dataId = map.get("id").toString(); + //获取方案适用的人员id列表 + List empIdList = CommonUtil.getEmpIds(dataId, modeId); + bs.writeLog("dataId : " + dataId); + bs.writeLog("modeId : " + modeId); + bs.writeLog("empIdList : " + empIdList); + //获取津贴类型的考勤项目 + String dtSql = "select * from uf_jcl_kq_kqfa_dt1 a left join uf_jcl_kq_kqxm b on b.id = a.kqxm where a.mainid = " + dataId + + " and b.xmlx = " + AttendanceItemTypeEnum.ALLOWANCE.getKey(); + List> dtData = DbTools.getSqlToList(dtSql); + List allowanceIdList = new ArrayList<>(); + dtData.forEach(f -> allowanceIdList.add(f.get("kqxm").toString())); + if (allowanceIdList.size() > 0 && empIdList.size() > 0) { + targetEmpIdList.addAll(empIdList); + targetAllowanceIdList.addAll(allowanceIdList); + //构建映射 + empIdList.forEach(f -> { + if (empIdWithAllowanceInfo.get(f) == null) { + empIdWithAllowanceInfo.put(f, allowanceIdList); + } else { + empIdWithAllowanceInfo.get(f).addAll(allowanceIdList); + } + }); + } + } + //构建班次和津贴映射关系 + Map> allowanceIdWithKqxmInfo = new HashMap<>(); + String bcSql = "select * from uf_jcl_kq_kqxm where id in ("+String.join(",",targetAllowanceIdList) + ") and sydbc is not null "; + List> bcData = DbTools.getSqlToList(bcSql); + Map> bcWithAllowanceInfo = new HashMap<>(); + for (Map map : bcData) { + String bcArr = map.get("sydbc").toString(); + String allowanceId = map.get("id").toString(); + allowanceIdWithKqxmInfo.put(allowanceId, map); + List bcList = Arrays.asList(bcArr.split(",")); + targetBcIdList.addAll(bcList); + bcList.forEach(f -> { + List values = new ArrayList<>(); + if (bcWithAllowanceInfo.get(f) == null) { + values.add(allowanceId); + bcWithAllowanceInfo.put(f, values); + } else { + bcWithAllowanceInfo.get(f).add(allowanceId); + } + }); + } + //获取出勤结果,遍历处理津贴信息 + String startDate = Util.null2String(params.get("startDate")); + String endDate = Util.null2String(params.get("endDate")); + String cqSql = "select * from uf_jcl_kq_cqjg where ygid in ("+String.join(",",targetEmpIdList) + ") and rq >= '" + startDate +"'" + " and rq <= '" + endDate +"'" + + " and bc in ("+String.join(",",targetBcIdList) + ")"; + List> cqData = DbTools.getSqlToList(cqSql); + bs.writeLog("cqData_size : " + cqData.size()); + bs.writeLog("empIdWithAllowanceInfo : " + empIdWithAllowanceInfo); + bs.writeLog("bcWithAllowanceInfo : " + bcWithAllowanceInfo); + bs.writeLog("allowanceIdWithKqxmInfo : " + allowanceIdWithKqxmInfo); + //获取待新增的津贴数据 + List> allowanceInfoList = createAllowanceInfo(cqData, empIdWithAllowanceInfo, bcWithAllowanceInfo, allowanceIdWithKqxmInfo); + bs.writeLog("allowanceInfoList_size : " + allowanceInfoList.size()); + //新增津贴数据,先删后加 + String delSql = "delete from uf_jcl_kq_cqjt where rq >= '" + startDate +"'" + " and rq <= '" + endDate +"'" + + " and yg in (" + String.join(",",targetEmpIdList) + ") and bc in (" + String.join(",",targetBcIdList) + ")"; + boolean delSign = DbTools.update(delSql); + bs.writeLog("delSign : " + delSign + ", delSql : " + delSql); + //插入津贴数据 + List dataList = new ArrayList<>(); + String insertSql = " insert into uf_jcl_kq_cqjt(szjg,yg,rq,bc,jtlx,sc) values(?,?,?,?,?,?)"; + for (Map map : allowanceInfoList) { + List list = new ArrayList<>(); + list.add(map.get("szjg")); + list.add(map.get("yg")); + list.add(map.get("rq")); + list.add(map.get("bc")); + list.add(map.get("jtlx")); + list.add(map.get("sc")); + + dataList.add(list); + } + bs.writeLog("dataList_size : " + dataList.size()); + if(dataList.size() > 0){ + RecordSet rs = new RecordSet(); + bs.writeLog("津贴数据记录入库开始---"); + boolean insertSign =rs.executeBatchSql(insertSql,dataList); + bs.writeLog("insertSign : " + insertSign); + } + } catch (Exception e) { + bs.errorLog("catch error :{}",e); + } + return null; + } + + private List> createAllowanceInfo(List> cqData, Map> empIdWithAllowanceInfo, Map> bcWithAllowanceInfo, Map> allowanceIdWithKqxmInfo) { + List> allowanceInfoList = new ArrayList<>(); + Map allowanceInfoItem; + //获取加班类型的考勤项目,并构建项目id和核算单位映射关系 + Map jbKqxmUnitInfo = collectKqxmUnitInfo(AttendanceItemTypeEnum.WORK_OVERTIME.getKey()); + bs.writeLog("jbKqxmUnitInfo : " + jbKqxmUnitInfo); + //获取津贴类型的考勤项目,并构建项目id和核算单位映射关系 + Map jtKqxmUnitInfo = collectKqxmUnitInfo(AttendanceItemTypeEnum.ALLOWANCE.getKey()); + bs.writeLog("jtKqxmUnitInfo : " + jtKqxmUnitInfo); + //获取津贴类型的考勤项目,并构建项目id和核算量映射关系 + Map jtKqxmCountScaleInfo = collectKqxmCountScaleInfo(AttendanceItemTypeEnum.ALLOWANCE.getKey()); + bs.writeLog("jtKqxmCountScaleInfo : " + jtKqxmCountScaleInfo); + //遍历出勤结果 + for (Map map : cqData) { + String empId = map.get("ygid").toString(); + String bc = Util.null2String(map.get("bc")); + //判断该班次是否存在津贴 + List allowanceIdsByBc = bcWithAllowanceInfo.get(bc); + //判断该人员是否有相关的津贴 + List allowanceIdsByEmp = empIdWithAllowanceInfo.get(empId); + //处理该人员在该班次可生效的津贴 + if(allowanceIdsByBc != null && allowanceIdsByEmp != null && allowanceIdsByBc.retainAll(allowanceIdsByEmp)) { + //收集下出勤结果中项目1-8存在的项目id + List kqxmIdsWithCq = collectKqxmIdsByCq(map); + bs.writeLog("kqxmIdsWithCq : " + kqxmIdsWithCq); + //收集下出勤结果中进出时间,仅收集进出两个时间点都有的数据 + List> jcInfoList = collectJcInfoByCq(map); + bs.writeLog("jcInfoList : " + jcInfoList); + //收集下出勤结果中,项目1-8中累积的加班时长,处理成分钟数 + Integer overtimeMinutes = collectOvertimeMinutes(map, jbKqxmUnitInfo); + bs.writeLog("overtimeMinutes : " + overtimeMinutes); + //最终核算分钟数 + double countMinutes = 0; + //出勤时长 + double cqsc = Util.null2String(map.get("cqsc")).equals("") ? 0 : Double.parseDouble(map.get("cqsc").toString()); + //获取班次班段时间范围 + List> bcTimeRangeList = collectBcTimeRangeInfo(Util.null2String(map.get("bcbdxx"))); + bs.writeLog("bcTimeRangeList : " + bcTimeRangeList); + //遍历该出勤结果中班次、人员都关联的津贴项目 + for(String allowanceId : allowanceIdsByBc) { + Map allowanceInfo = allowanceIdWithKqxmInfo.get(allowanceId); + bs.writeLog("allowanceInfo : " + allowanceInfo); + //项目1-8中出现以下考勤项目时,津贴失效 + String banKqxm = Util.null2String(allowanceInfo.get("bxsdxm")); + List banKqxmList = new ArrayList<>(); + if (!banKqxm.equals("")) { + banKqxmList = Arrays.asList(banKqxm.split(",")); + } + //正常工作时长计入核算量_标识,0-否,1-是 + String includeDailyWorkHours = Util.null2String(allowanceInfo.get("ljbcngzsj")); + //检查特定时间点是否在岗_标识,0-否,1-是 + String checkOneTimeOnDuty = Util.null2String(allowanceInfo.get("xysjd")); + //特定在岗时间点 + String onDutyTime = Util.null2String(allowanceInfo.get("sjd")); + //时间点之前的时长也计入核算量_标识,0-否,1-是 + String includeHoursBeforeDutyTime = Util.null2String(allowanceInfo.get("jljxysjdzqdsc")); + //起算分钟数(不包含) + String startMinutes = Util.null2String(allowanceInfo.get("jtqsfzs")); + //最大核算分钟数(包含) + String maxMinutes = Util.null2String(allowanceInfo.get("zdhsfzs")); + //超出起算时长的单次累加分钟数 + String oneTimeAddMinutes = Util.null2String(allowanceInfo.get("cchsfzs")); + bs.writeLog("includeDailyWorkHours : " + includeDailyWorkHours + ",checkOneTimeOnDuty : " + checkOneTimeOnDuty + + ",onDutyTime : " + onDutyTime + ",includeHoursBeforeDutyTime : " + includeHoursBeforeDutyTime + + ",startMinutes : " + startMinutes,"maxMinutes : " + maxMinutes + ",oneTimeAddMinutes : " + oneTimeAddMinutes); + //逐一判断是否满足津贴时长计入规则 + //1-此为考勤项目的多选,如果员工当天出勤中的项目1~项目8存在不核算此津贴的项目,则员工不能获得此津贴 + if (kqxmIdsWithCq.size() > 0 && banKqxmList.size() > 0 && banKqxmList.retainAll(kqxmIdsWithCq)) { + continue; + } + //2-如果勾选“检查特定时间点是否在岗”,则需要判断员工当天“须要在岗的时间点”所设置的时间员工是否在岗 + if (checkOneTimeOnDuty.equals("1") && !onDutyTime.equals("")) { + boolean onDuty = false; + for (Map jcInfo : jcInfoList) { + if (onDutyTime.compareTo(jcInfo.get("signIn")) >= 0 && onDutyTime.compareTo(jcInfo.get("signOut")) <= 0) { + onDuty = true; + break; + } + } + //不在岗,直接处理下一个津贴 + if (!onDuty) { + continue; + } + //3-如果时长大于“起算分钟数(不包含)”小于等于“最大核算分钟数(包含)”,则员工或获得此津贴 + //a-时长默认为取当天所有项目1~项目8中的各加班类型的考勤项目对应的时长 + //b-如果勾选“工作时长也计入核算量”,则还需要累加当天的“出勤时长”字段值 + //c-一旦勾选了“检查特定时间点是否在岗”,且只取“时间点”之后的分钟数时长 + //d-如果勾选了“时间点之前的时长也计入核算量”则上一点不需要做 + + if (includeHoursBeforeDutyTime.equals("1")) { + countMinutes = overtimeMinutes; + if (includeDailyWorkHours.equals("1")) { + countMinutes = countMinutes + cqsc * 60; + } + } else { + countMinutes = getMinutesWithAfterPointTime(bcTimeRangeList, jcInfoList, overtimeMinutes, onDutyTime, includeDailyWorkHours); + } + } else { + //未勾选“检查特定时间点是否在岗” + countMinutes = overtimeMinutes; + if (includeDailyWorkHours.equals("1")) { + countMinutes = countMinutes + cqsc * 60; + } + } + //4-津贴时长计算规则 + //a-起算分钟数 + 超出起算时长的单次累加分钟数 * N <= 最大核算分钟数 + //b-由a点获取到分钟数后,要根据津贴项目的核算量+核算单位来获取最终津贴时长,例如分钟数170分钟,核算量为0.5,核算单位为小时,则最终核算时长为2.5小时 + double allowanceMinutes = 0; + bs.writeLog("countMinutes : " + countMinutes); + if (countMinutes > Double.parseDouble(startMinutes)) { + if (!oneTimeAddMinutes.equals("") && !oneTimeAddMinutes.equals("0")) { + double multiple = (countMinutes - Double.parseDouble(startMinutes)) / Double.parseDouble(oneTimeAddMinutes); + allowanceMinutes = Double.parseDouble(startMinutes) + Double.parseDouble(oneTimeAddMinutes) * Math.floor(multiple); + } else { + allowanceMinutes = Double.parseDouble(startMinutes); + } + if (allowanceMinutes > Double.parseDouble(maxMinutes)) { + allowanceMinutes = Double.parseDouble(maxMinutes); + } + bs.writeLog("allowanceMinutes : " + allowanceMinutes); + //津贴时长 + String allowanceUnit = Util.null2String(jtKqxmUnitInfo.get(allowanceId)); + String countScale = Util.null2String(jtKqxmCountScaleInfo.get(allowanceId)); + if (!countScale.equals("")) { + double sc = 0; + if (allowanceUnit.equals(AccountingUnitEnum.DAY.getKey())) { + sc = (allowanceMinutes - allowanceMinutes % (1440 * Double.parseDouble(countScale))) / 1440; + } else if (allowanceUnit.equals(AccountingUnitEnum.HOUR.getKey())) { + sc = (allowanceMinutes - allowanceMinutes % (60 * Double.parseDouble(countScale))) / 60; + } else if (allowanceUnit.equals(AccountingUnitEnum.MINUTES.getKey())) { + sc = allowanceMinutes - allowanceMinutes % Double.parseDouble(countScale); + } + bs.writeLog("sc : " + sc); + //记录待新增的津贴记录 + allowanceInfoItem = new HashMap<>(); + allowanceInfoItem.put("szjg", Util.null2String(map.get("szjg"))); + allowanceInfoItem.put("yg", Util.null2String(map.get("ygid"))); + allowanceInfoItem.put("rq", Util.null2String(map.get("rq"))); + allowanceInfoItem.put("bc", Util.null2String(map.get("bc"))); + allowanceInfoItem.put("jtlx", allowanceId); + if (!allowanceUnit.equals(AccountingUnitEnum.ONCE.getKey())) { + allowanceInfoItem.put("sc", String.format("%.2f", sc)); + } else { + allowanceInfoItem.put("sc", "0"); + } + allowanceInfoList.add(allowanceInfoItem); + } + } + } + } + } + return allowanceInfoList; + } + + /** + * 获取考虑特殊在岗时间点情况下的考核时长分钟数 + * 勾选在岗时间点时, + * 1-处于班次工作时间段时,结合进出时间和班次班段判断班段时间内实际工作分钟数 + * 2-处于加班时间段内,结合进出时间记录,累加 + * @param overtimeMinutes + * @param onDutyTime + * @return + */ + private double getMinutesWithAfterPointTime(List> bcTimeRangeList, List> jcInfoList, + Integer overtimeMinutes, String onDutyTime, String includeDailyWorkHours) { + double bcOnDutyMinutes = 0; + double realOverWorkMinutes = 0; + if (includeDailyWorkHours.equals("1")) { + //判断在岗时间点和班次班段的关系,存在包含关系,则计算出班次时间内需要累计的时间 + //首先获取班次班段设置和实际进出交集的时间段 + List> bcRealOnDutyTimeRange = new ArrayList<>(); + Map realItemMap; + for (Map bcTime : bcTimeRangeList) { + String realStartTime = ""; + String realEndTime = ""; + String startTime = bcTime.get("startTime"); + String endTime = bcTime.get("endTime"); + for (Map jcTime : jcInfoList) { + String signInTime = jcTime.get("signIn"); + String signOutTime = jcTime.get("signOut"); + if (startTime.compareTo(signInTime) >= 0 && startTime.compareTo(signOutTime) <= 0) { + realStartTime = startTime; + } + if (endTime.compareTo(signInTime) >= 0 && endTime.compareTo(signOutTime) <= 0) { + realEndTime = endTime; + } + if (startTime.compareTo(signInTime) < 0 && endTime.compareTo(signOutTime) > 0) { + realStartTime = signInTime; + realEndTime = signOutTime; + } + if (realStartTime.equals("") && !realEndTime.equals("")) { + realStartTime = signInTime; + } + if (!realStartTime.equals("") && realEndTime.equals("")) { + realEndTime = signOutTime; + } + if (!realStartTime.equals("") && !realEndTime.equals("")) { + realItemMap = new HashMap<>(); + realItemMap.put("startTime", realStartTime); + realItemMap.put("endTime", realEndTime); + bcRealOnDutyTimeRange.add(realItemMap); + } + } + } + //遍历获取班次班段时间内的累计时长(某一在岗时间点之后的时间) + for (Map bcRealTimeInfo : bcRealOnDutyTimeRange) { + if (onDutyTime.compareTo(bcRealTimeInfo.get("startTime")) <= 0) { + bcOnDutyMinutes = bcOnDutyMinutes + getMinutesByTwo(bcRealTimeInfo.get("startTime"), bcRealTimeInfo.get("endTime")); + } else if (onDutyTime.compareTo(bcRealTimeInfo.get("startTime")) >= 0 && onDutyTime.compareTo(bcRealTimeInfo.get("endTime")) <= 0) { + bcOnDutyMinutes = bcOnDutyMinutes + getMinutesByTwo(onDutyTime, bcRealTimeInfo.get("endTime")); + } + } + } + //判断在岗时间点和加班时间区间的关系,即进出打卡记录是否与在岗时间点有包含关系,分情况累计时间 + for (Map jcInfo : jcInfoList) { + if (onDutyTime.compareTo(jcInfo.get("signIn")) <= 0) { + realOverWorkMinutes = realOverWorkMinutes + getMinutesByTwo(jcInfo.get("signIn"), jcInfo.get("signOut")); + } else if (onDutyTime.compareTo(jcInfo.get("signIn")) >= 0 && onDutyTime.compareTo(jcInfo.get("signOut")) <= 0) { + realOverWorkMinutes = realOverWorkMinutes + getMinutesByTwo(onDutyTime, jcInfo.get("signOut")); + } + } + //实际加班时长累计的核算分钟数,不可以超过项目1-8累计的加班时长分钟数 + if (realOverWorkMinutes > overtimeMinutes) { + realOverWorkMinutes = overtimeMinutes; + } + return realOverWorkMinutes + bcOnDutyMinutes; + } + + private double getMinutesByTwo(String startTime, String endTime) { + LocalTime time1 = LocalTime.of(Integer.parseInt(startTime.split(":")[0]), Integer.parseInt(startTime.split(":")[1])); + LocalTime time2 = LocalTime.of(Integer.parseInt(endTime.split(":")[0]), Integer.parseInt(endTime.split(":")[1])); + Duration duration = Duration.between(time1, time2); + // 获取分钟数 + return duration.toMinutes(); + } + + private List> collectBcTimeRangeInfo(String bcbdxx) { + List> timeRangeInfo = new ArrayList<>(); + if (!bcbdxx.equals("")) { + List rangeList = Arrays.asList(bcbdxx.split("\\|")); + Map itemMap; + for (String range : rangeList) { + String[] timeInfo = range.split("-"); + itemMap = new HashMap<>(); + itemMap.put("startTime", timeInfo[0]); + itemMap.put("endTime", timeInfo[1]); + timeRangeInfo.add(itemMap); + } + } + return timeRangeInfo; + } + + private Map collectKqxmUnitInfo(String kqxmType) { + Map unitInfo = new HashMap<>(); + String sql = "select * from uf_jcl_kq_kqxm where xmlx = " + kqxmType; + List> data = DbTools.getSqlToList(sql); + for (Map map : data) { + unitInfo.put(map.get("id").toString(), Util.null2String(map.get("hsdw"))); + } + return unitInfo; + } + + private Map collectKqxmCountScaleInfo(String kqxmType) { + Map unitInfo = new HashMap<>(); + String sql = "select * from uf_jcl_kq_kqxm where xmlx = " + kqxmType; + List> data = DbTools.getSqlToList(sql); + for (Map map : data) { + unitInfo.put(map.get("id").toString(), Util.null2String(map.get("hsl"))); + } + return unitInfo; + } + + private Integer collectOvertimeMinutes(Map cqMap, Map jbKqxmUnitInfo) { + Integer minutes = 0; + String xm = ""; + String sc = ""; + String unit = ""; + Map unitToMinutes = new HashMap<>(); + unitToMinutes.put(AccountingUnitEnum.DAY.getKey(), 1440); + unitToMinutes.put(AccountingUnitEnum.HOUR.getKey(), 60); + unitToMinutes.put(AccountingUnitEnum.MINUTES.getKey(), 1); + unitToMinutes.put(AccountingUnitEnum.ONCE.getKey(), 0); + for (int i = 1; i <= 8; i++) { + xm = Util.null2String(cqMap.get("xm" + i)); + sc = Util.null2String(cqMap.get("sc" + i)); + unit = Util.null2String(jbKqxmUnitInfo.get(xm)); + if (!xm.equals("") && !sc.equals("") && !unit.equals("")) { + minutes = minutes + Integer.parseInt(sc) * unitToMinutes.get(unit); + } + } + return minutes; + } + + private List> collectJcInfoByCq(Map cqMap) { + List> jcInfoList = new ArrayList<>(); + String j1 = Util.null2String(cqMap.get("j1")); + String j2 = Util.null2String(cqMap.get("j2")); + String j3 = Util.null2String(cqMap.get("j3")); + String j4 = Util.null2String(cqMap.get("j4")); + String j5 = Util.null2String(cqMap.get("j5")); + String j6 = Util.null2String(cqMap.get("j6")); + String j7 = Util.null2String(cqMap.get("j7")); + String j8 = Util.null2String(cqMap.get("j8")); + String c1 = Util.null2String(cqMap.get("c1")); + String c2 = Util.null2String(cqMap.get("c2")); + String c3 = Util.null2String(cqMap.get("c3")); + String c4 = Util.null2String(cqMap.get("c4")); + String c5 = Util.null2String(cqMap.get("c5")); + String c6 = Util.null2String(cqMap.get("c6")); + String c7 = Util.null2String(cqMap.get("c7")); + String c8 = Util.null2String(cqMap.get("c8")); + Map itemMap; + if (!j1.equals("") && !c1.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j1.substring(0, 5)); + itemMap.put("signOut", c1.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + if (!j2.equals("") && !c2.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j2.substring(0, 5)); + itemMap.put("signOut", c2.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + if (!j3.equals("") && !c3.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j3.substring(0, 5)); + itemMap.put("signOut", c3.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + if (!j4.equals("") && !c4.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j4.substring(0, 5)); + itemMap.put("signOut", c4.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + if (!j5.equals("") && !c5.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j5.substring(0, 5)); + itemMap.put("signOut", c5.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + if (!j6.equals("") && !c6.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j6.substring(0, 5)); + itemMap.put("signOut", c6.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + if (!j7.equals("") && !c7.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j7.substring(0, 5)); + itemMap.put("signOut", c7.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + if (!j8.equals("") && !c8.equals("")) { + itemMap = new HashMap<>(); + itemMap.put("signIn", j8.substring(0, 5)); + itemMap.put("signOut", c8.substring(0, 5)); + jcInfoList.add(itemMap); + } else { + return jcInfoList; + } + return jcInfoList; + } + + private List collectKqxmIdsByCq(Map cqMap) { + List kqxmIdsWithCq = new ArrayList<>(); + String xm1 = Util.null2String(cqMap.get("xm1")); + String xm2 = Util.null2String(cqMap.get("xm2")); + String xm3 = Util.null2String(cqMap.get("xm3")); + String xm4 = Util.null2String(cqMap.get("xm4")); + String xm5 = Util.null2String(cqMap.get("xm5")); + String xm6 = Util.null2String(cqMap.get("xm6")); + String xm7 = Util.null2String(cqMap.get("xm7")); + String xm8 = Util.null2String(cqMap.get("xm8")); + if (!xm1.equals("")) { + kqxmIdsWithCq.add(xm1); + } else { + return kqxmIdsWithCq; + } + if (!xm2.equals("")) { + kqxmIdsWithCq.add(xm2); + } else { + return kqxmIdsWithCq; + } + if (!xm3.equals("")) { + kqxmIdsWithCq.add(xm3); + } else { + return kqxmIdsWithCq; + } + if (!xm4.equals("")) { + kqxmIdsWithCq.add(xm4); + } else { + return kqxmIdsWithCq; + } + if (!xm5.equals("")) { + kqxmIdsWithCq.add(xm5); + } else { + return kqxmIdsWithCq; + } + if (!xm6.equals("")) { + kqxmIdsWithCq.add(xm6); + } else { + return kqxmIdsWithCq; + } + if (!xm7.equals("")) { + kqxmIdsWithCq.add(xm7); + } else { + return kqxmIdsWithCq; + } + if (!xm8.equals("")) { + kqxmIdsWithCq.add(xm8); + } else { + return kqxmIdsWithCq; + } + return kqxmIdsWithCq; + } +} diff --git a/src/com/engine/attendance/workflow/web/AllowanceApi.java b/src/com/engine/attendance/workflow/web/AllowanceApi.java new file mode 100644 index 0000000..7a7f39a --- /dev/null +++ b/src/com/engine/attendance/workflow/web/AllowanceApi.java @@ -0,0 +1,47 @@ +package com.engine.attendance.workflow.web; + +import com.alibaba.fastjson.JSONObject; +import com.engine.attendance.workflow.service.AllowanceService; +import com.engine.attendance.workflow.service.impl.AllowanceServiceImpl; +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: sy + * @Description: 出勤津贴 + * @Date: 2024/4/9 + **/ +public class AllowanceApi { + + private AllowanceService getAllowanceService(User user) { + return ServiceUtil.getService(AllowanceServiceImpl.class,user); + } + + /** + * 生成出勤津贴数据 + * @param request + * @param response + * @return + */ + @POST + @Path("/addAllowanceRecords") + @Produces(MediaType.TEXT_PLAIN) + public String addAllowanceRecords(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap(); + User user = HrmUserVarify.getUser(request, response); + apidatas = getAllowanceService(user).addAllowanceRecords(ParamUtil.request2Map(request)); + return JSONObject.toJSONString(apidatas); + } +} diff --git a/src/com/engine/common/util/CommonUtil.java b/src/com/engine/common/util/CommonUtil.java index 4b2b0f0..071b4e6 100644 --- a/src/com/engine/common/util/CommonUtil.java +++ b/src/com/engine/common/util/CommonUtil.java @@ -1,6 +1,8 @@ package com.engine.common.util; import com.engine.attendance.component.persongroup.commonutil.PersongroupCommonUtil; +import com.engine.attendance.enums.ApplicableOrganizationEnum; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; import lombok.extern.slf4j.Slf4j; import weaver.general.Util; @@ -185,4 +187,177 @@ public class CommonUtil { } return list; } + + /** + * 获取适用范围对应的人员id列表,适用范围由dataId和modeId获得 + * @param dataId + * @param modeId + * @return + */ + public static List getEmpIds(String dataId,String modeId) { + List empIdList = new ArrayList<>(); + String sql = "select dxlx,aqjb,dx from uf_jcl_syzz where modeid=? and dataid = ?"; + //适用组织所有值集合 + List> organzationList = DbTools.getSqlToList(sql,modeId, dataId); + //分组 + List> empIdInfos = new ArrayList<>(); + List> empGroupIdInfos = new ArrayList<>(); + List> depIdInfos = new ArrayList<>(); + List> subCompanyIdInfos = new ArrayList<>(); + for (Map organzation:organzationList){ + String id = Util.null2String(organzation.get("dx")).split("-")[0]; + String securityLevel = Util.null2String(organzation.get("aqjb")); + String[] securityLevelArr = securityLevel.split("-"); + String minSecurityLevel = securityLevel.substring(0, 1).equals("-") ? "" : securityLevelArr[0]; + String maxSecurityLevel = ""; + if (securityLevelArr.length == 1 && !securityLevelArr[0].equals(minSecurityLevel)) { + maxSecurityLevel = securityLevelArr[0]; + } else if (securityLevelArr.length == 2) { + maxSecurityLevel = securityLevelArr[1]; + } + if (ApplicableOrganizationEnum.PERSONNEL.getKey().equals(organzation.get("dxlx"))){ + Map infoItem = new HashMap<>(); + infoItem.put("id", id); + infoItem.put("minSecurityLevel", minSecurityLevel); + infoItem.put("maxSecurityLevel", maxSecurityLevel); + empIdInfos.add(infoItem); + }else if (ApplicableOrganizationEnum.PERSONNEL_GROUP.getKey().equals(organzation.get("dxlx"))){ + Map infoItem = new HashMap<>(); + infoItem.put("id", id); + infoItem.put("minSecurityLevel", minSecurityLevel); + infoItem.put("maxSecurityLevel", maxSecurityLevel); + empGroupIdInfos.add(infoItem); + }else if (ApplicableOrganizationEnum.DEPARTMENT.getKey().equals(organzation.get("dxlx"))){ + Map infoItem = new HashMap<>(); + infoItem.put("id", id); + infoItem.put("minSecurityLevel", minSecurityLevel); + infoItem.put("maxSecurityLevel", maxSecurityLevel); + depIdInfos.add(infoItem); + }else if (ApplicableOrganizationEnum.SUBCOMPANY.getKey().equals(organzation.get("dxlx"))){ + Map infoItem = new HashMap<>(); + infoItem.put("id", id); + infoItem.put("minSecurityLevel", minSecurityLevel); + infoItem.put("maxSecurityLevel", maxSecurityLevel); + subCompanyIdInfos.add(infoItem); + } + } + //人员类型 + for (Map map : empIdInfos) { + String id = map.get("id"); + String minSecurityLevel = map.get("minSecurityLevel"); + String maxSecurityLevel = map.get("maxSecurityLevel"); + //查询目标人员信息 + String querySql = "select * from hrmresouorce where id = " + id; + if (!minSecurityLevel.equals("")) { + querySql = querySql + " and seclevel >= " +minSecurityLevel; + } + if (!maxSecurityLevel.equals("")) { + querySql = querySql + " and seclevel <= " +maxSecurityLevel; + } + Map data = DbTools.getSqlToMap(querySql); + if (data.size() > 0) { + empIdList.add(id); + } + } + //人员分组类型 + for (Map map : empGroupIdInfos) { + String id = map.get("id"); + String minSecurityLevel = map.get("minSecurityLevel"); + String maxSecurityLevel = map.get("maxSecurityLevel"); + //获取分组包含人员id + List empIdsByGroup = getEmpGroupUserIds(id); + //查询目标人员信息 + String querySql = "select * from hrmresouorce where id = in ("+String.join(",",empIdsByGroup)+")"; + if (!minSecurityLevel.equals("")) { + querySql = querySql + " and seclevel >= " +minSecurityLevel; + } + if (!maxSecurityLevel.equals("")) { + querySql = querySql + " and seclevel <= " +maxSecurityLevel; + } + List> datas = DbTools.getSqlToList(querySql); + if (datas.size() > 0) { + datas.forEach(f -> empIdList.add(f.get("id").toString())); + } + } + //部门类型 + for (Map map : depIdInfos) { + String id = map.get("id"); + String minSecurityLevel = map.get("minSecurityLevel"); + String maxSecurityLevel = map.get("maxSecurityLevel"); + //查询目标人员信息 + String querySql = "select * from hrmresouorce where departmentid = " + id; + if (!minSecurityLevel.equals("")) { + querySql = querySql + " and seclevel >= " +minSecurityLevel; + } + if (!maxSecurityLevel.equals("")) { + querySql = querySql + " and seclevel <= " +maxSecurityLevel; + } + List> datas = DbTools.getSqlToList(querySql); + if (datas.size() > 0) { + datas.forEach(f -> empIdList.add(f.get("id").toString())); + } + } + //分部类型 + for (Map map : subCompanyIdInfos) { + String id = map.get("id"); + String minSecurityLevel = map.get("minSecurityLevel"); + String maxSecurityLevel = map.get("maxSecurityLevel"); + //查询目标人员信息 + String querySql = "select * from hrmresouorce where subcompanyid1 = " + id; + if (!minSecurityLevel.equals("")) { + querySql = querySql + " and seclevel >= " +minSecurityLevel; + } + if (!maxSecurityLevel.equals("")) { + querySql = querySql + " and seclevel <= " +maxSecurityLevel; + } + List> datas = DbTools.getSqlToList(querySql); + if (datas.size() > 0) { + datas.forEach(f -> empIdList.add(f.get("id").toString())); + } + } + + return empIdList; + } + + /** + * 获得人员分组下面的人员集合 + * @param empGroupId + * @return 人员id集合 + */ + public static List getEmpGroupUserIds(String empGroupId){ + String sql = "select b.mainid,b.empid,b.filters,b.bdate,b.edate,a.list_type from uf_ryqz a left join uf_ryqz_dt1 b on a.id=b.mainid where mainid = " + empGroupId; + + List> personGroupDataList = DbTools.getSqlToList(sql); + + List empIdList = new ArrayList<>(); + for (Map personGroupData :personGroupDataList){ + String id = Util.null2String(personGroupData.get("mainid")); + String empid = Util.null2String(personGroupData.get("empid")); + String filters = Util.null2String(personGroupData.get("filters")); + String list_type = Util.null2String(personGroupData.get("list_type")); + + if ("0".equals(list_type) && !"".equals(empid)){ + //人员清单 + empIdList.add(empid); + }else if ("1".equals(list_type) && !"".equals(filters)){ + //条件清单 + sql = "select id,seclevel from hrmresource where 1=1 "; + if (filters.contains("field")){ + sql = "select a.id,a.seclevel from hrmresource a left join cus_fielddata b on a.id=b.id where scope='HrmCustomFieldByInfoType' and scopeid=-1 and "+filters; + }else { + filters = filters.replace("and","and"); + filters = filters.replace("or","or"); + sql = sql+ " and "+filters; + } + log.info("getPersonnelGroupingByPerson filter sql : {}",sql); + List> dataList = DbTools.getSqlToList(sql); + for (Map dataMap :dataList){ + String hrmId = Util.null2String(dataMap.get("id")); + String seclevel = Util.null2String(dataMap.get("seclevel")); + empIdList.add(hrmId); + } + } + } + return empIdList; + } }