diff --git a/src/com/engine/kq/biz/KQBalanceOfLeaveBiz.java b/src/com/engine/kq/biz/KQBalanceOfLeaveBiz.java new file mode 100644 index 0000000..017bee8 --- /dev/null +++ b/src/com/engine/kq/biz/KQBalanceOfLeaveBiz.java @@ -0,0 +1,4894 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSONObject; +import com.engine.kq.bean.KQChildrenBean; +import com.engine.kq.entity.KQBalanceOfLeaveEntity; +import com.engine.kq.entity.KQOvertimeRulesDetailEntity; +import com.engine.kq.entity.KQUsageHistoryEntity; +import com.engine.kq.jucailin.util.KQDateUtil; +import com.engine.kq.log.KQLog; +import com.engine.kq.wfset.bean.OvertimeBalanceTimeBean; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.moduledetach.ManageDetachComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 假期余额相关接口 + */ +public class KQBalanceOfLeaveBiz { + + private static KQLog logger = new KQLog();//用于记录日志信息 + + public static String getBalanceOfLeave(String resourceId, String ruleId, String date) { + return getBalanceOfLeave(resourceId, ruleId, date, true); + } + + public static String getBalanceOfLeave(String resourceId, String ruleId, String date, boolean isAll) { + return getBalanceOfLeave(resourceId, ruleId, date, false, isAll); + } + + public static String getBalanceOfLeave(String resourceId, String ruleId, String searchDate, boolean calcByCurrentDate, boolean isAll) { + return getRestAmount(resourceId, ruleId, searchDate, calcByCurrentDate, isAll); + } + + /** + * 获取指定人员的指定假期的有效的假期余额 + * + * @param resourceId 指定的人员ID + * @param ruleId 指定的假期类型的ID(表kq_leaveRules的主键ID) + * @param date 请假日期(根据此日期计算释放规则以及判断员工假期余额是否失效) + * @return 如果传入的指定假期类型没有开启假期余额,则返回0.00 + */ + public static String getRestAmount(String resourceId, String ruleId, String date) { + return getRestAmount(resourceId, ruleId, date, true); + } + + /** + * 获取指定人员的指定假期的有效的假期余额 + * + * @param resourceId 指定的人员ID + * @param ruleId 指定的假期类型的ID(表kq_leaveRules的主键ID) + * @param date 请假日期(根据此日期计算释放规则以及判断员工假期余额是否失效) + * @param isAll true--查询所有年份加起来的总有效余额、false--仅仅查询指定请假日期那一年的有效余额 + * @return 如果传入的指定假期没有开启假期余额,则返回0.00 + */ + public static String getRestAmount(String resourceId, String ruleId, String date, boolean isAll) { + return getRestAmount(resourceId, ruleId, date, false, isAll); + } + + /** + * 获取指定人员的指定假期的有效的假期余额 + * + * @param resourceId 指定的人员ID + * @param ruleId 指定的假期类型的ID(表kq_leaveRules的主键ID) + * @param searchDate 请假日期(不可为空) + * @param calcByCurrentDate true--根据当前日期计算释放规则以及判断员工假期余额是否失效、false--根据请假日期来计算释放规则以及判断员工假期余额是否失效 + * @param isAll true--查询所有年份加起来的总有效余额、false--仅仅查询指定请假日期那一年的有效余额 + * @return 如果传入的指定假期没有开启假期余额,则返回0.00 + */ + public static String getRestAmount(String resourceId, String ruleId, String searchDate, boolean calcByCurrentDate, boolean isAll) { + //员工的假期余额 + String balanceOfLeave = "0"; + Map params = new HashMap<>(); + params.put("resourceId",resourceId); + params.put("ruleId",ruleId); + params.put("searchDate",searchDate); + params.put("calcByCurrentDate",calcByCurrentDate); + params.put("isAll",isAll); + try { + BigDecimal restAmount = new BigDecimal("0"); + //获取当前日期 + Calendar today = Calendar.getInstance(); + //当前日期 + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + //所属年份 + String searchYear = searchDate.substring(0, 4); + + /**********************************************************************************************************/ + + //假期类型缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + //是否启用假期余额:0-未开启、1-开启 + int balanceEnable = Util.getIntValue(rulesComInfo.getBalanceEnable(ruleId), 0); + + /**********************************************************************************************************/ + + //人员缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //分部ID + String subCompanyId = resourceComInfo.getSubCompanyID(resourceId); + //部门ID + String departmentId = resourceComInfo.getDepartmentID(resourceId); + /**********************************************************************************************************/ + + //假期规则缓存类 + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //余额发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按司龄+工龄自动发放 + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subCompanyId, departmentId, resourceId), 1); + // + int decimalDigit = Util.getIntValue(detailComInfo.getDecimalDigit(ruleId, subCompanyId, departmentId, resourceId), 2); + + /**********************************************************************************************************/ + + //该假期没有启用假期余额,记录错误日志,返回假期余额0 + if (balanceEnable != 1) { + logger.info("获取员工假期余额失败,此假期类型没有开启假期余额。params=" + JSONObject.toJSONString(params)); + return "0"; + } + //传入的请假日期为空,记录错误日期,返回假期余额0 + if (searchDate.equals("")) { + logger.info("获取员工假期余额失败,传入的请假日期为空。params=" + JSONObject.toJSONString(params)); + return "0"; + } + //传入的指定日期格式不对,记录错误日期,返回假期余额0 + Pattern pattern = Pattern.compile("^\\d{4}\\-\\d{2}\\-\\d{2}$"); + Matcher matcher = pattern.matcher(searchDate); + if (!matcher.matches()) { + logger.info("获取员工假期余额失败,传入的请假日期格式不对。params=" + JSONObject.toJSONString(params)); + return "0"; + } + //根据指定日期(或者根据当前日期)判断假期是否已经过了有效期 + String date = calcByCurrentDate ? currentDate : searchDate; + + //如果是调休,获取假期余额的逻辑会不太一样 + if (distributionMode == 5) { + restAmount = getRestAmountByDis5(ruleId, resourceId, searchDate, calcByCurrentDate, isAll); + return restAmount.setScale(decimalDigit, RoundingMode.HALF_UP).toPlainString(); + } + if (distributionMode == 8) { + restAmount = getRestAmountByDis8(ruleId, resourceId, searchDate, calcByCurrentDate, isAll); + return restAmount.setScale(decimalDigit, RoundingMode.HALF_UP).toPlainString(); + } + + //计算员工假期余额总和 + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_BalanceOfLeave where resourceId=? and leaveRulesId=? and (isDelete is null or isDelete<>1) "; + //是查询所有有效的假期余额还是仅仅查询指定日期当年的 + if(KQSettingsBiz.is_balanceofleave()){//开启开关 + if (!isAll) { + sql += " and belongYear='" + searchYear + "'"; + }else{ + sql += " and belongYear<='" + searchYear + "'"; + } + }else{ + if (!isAll) { + sql += " and belongYear='" + searchYear + "'"; + } + } + recordSet.executeQuery(sql, resourceId, ruleId); + while (recordSet.next()) { + //所属年份 + String belongYear = recordSet.getString("belongYear"); + //生效日期 + String effectiveDate = recordSet.getString("effectiveDate"); + //失效日期 + String expirationDate = recordSet.getString("expirationDate"); + //是否失效 + boolean status = getBalanceStatus(ruleId, resourceId, belongYear, date, effectiveDate, expirationDate); + if (!status) { + continue; + } + + if (distributionMode == 6) { + BigDecimal baseAmount = new BigDecimal(Util.null2s(recordSet.getString("baseAmount"), "0"));//混合模式下的法定年假基数 + BigDecimal usedAmount = new BigDecimal(Util.null2s(recordSet.getString("usedAmount"), "0"));//混合模式下的已休法定年假数 + BigDecimal extraAmount = new BigDecimal(Util.null2s(recordSet.getString("extraAmount"), "0"));//混合模式下的额外法定年假数 + //根据释放规则获取已释放的天数/小时数 + baseAmount = getCanUseAmount(resourceId, ruleId, belongYear, baseAmount, "legal", date); + + BigDecimal baseAmount2 = new BigDecimal(Util.null2s(recordSet.getString("baseAmount2"), "0"));//混合模式下的福利年假基数 + BigDecimal usedAmount2 = new BigDecimal(Util.null2s(recordSet.getString("usedAmount2"), "0"));//混合模式下的已休福利年假数 + BigDecimal extraAmount2 = new BigDecimal(Util.null2s(recordSet.getString("extraAmount2"), "0"));//混合模式下的额外福利年假数 + //根据释放规则获取已释放的天数/小时数 + baseAmount2 = getCanUseAmount(resourceId, ruleId, belongYear, baseAmount2, "welfare", date); + //剩余=已释放+额外-已休 + restAmount = restAmount.add(baseAmount.add(extraAmount).subtract(usedAmount).add(baseAmount2).add(extraAmount2).subtract(usedAmount2)); + } else { + BigDecimal baseAmount = new BigDecimal(Util.null2s(recordSet.getString("baseAmount"), "0"));//假期余额基数 + BigDecimal usedAmount = new BigDecimal(Util.null2s(recordSet.getString("usedAmount"), "0"));//已休的假期时长 + BigDecimal extraAmount = new BigDecimal(Util.null2s(recordSet.getString("extraAmount"), "0"));//额外的假期时长 + //根据释放规则获取已释放的天数/小时数 + baseAmount = getCanUseAmount(resourceId, ruleId, belongYear, baseAmount, "", date); + //剩余=已释放+额外-已休 + restAmount = restAmount.add(baseAmount.add(extraAmount).subtract(usedAmount)); + } + } + balanceOfLeave = restAmount.setScale(decimalDigit, RoundingMode.HALF_UP).toPlainString(); + } catch (Exception e) { + logger.info(e.getMessage()); + logger.info("获取员工假期余额失败。params=" + JSONObject.toJSONString(params)); + } + return balanceOfLeave; + } + + /** + * 获取指定人员的指定假期类型的指定年份在指定日期的可用余额(假期基数*释放比例) + * + * @param resourceId 指定的人员ID + * @param ruleId 指定的假期类型ID(对应于数据库表kq_leaveRules的主键ID) + * @param belongYear 指定的所属年份(格式yyyy) + * @param baseAmount 假期基数 + * @param legalOrWelfare 是计算[法定年假]还是计算[福利年假]:legal-法定年假、welfare-福利年假 + * @param date 指定日期(获取的就是此日期的假期可用余额) + * @return + */ + public static BigDecimal getCanUseAmount(String resourceId, String ruleId, String belongYear, BigDecimal baseAmount, String legalOrWelfare, String date) { + BigDecimal canUseAmount = new BigDecimal("0"); + try { + //人员缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //分部ID + String subCompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + //创建日期 + String createDate = resourceComInfo.getCreatedate(resourceId); + //入职日期 + String companyStartDate = resourceComInfo.getCompanyStartDate(resourceId); + //没有维护入职日期时取创建日期 + companyStartDate = companyStartDate.equals("") ? createDate : companyStartDate; + //参加工作日期 + String workStartDate = resourceComInfo.getWorkStartDate(resourceId); + //没有维护参加工作日期时取创建日期 + workStartDate = workStartDate.equals("") ? createDate : workStartDate; + + /*********************************************************************************/ + + //指定日期--用于计算已释放天数的日期 + Calendar searchDate = DateUtil.getCalendar(date); + //指定日期的年份 + String searchYear = Util.add0(searchDate.get(Calendar.YEAR), 4); + //指定日期那年一共多少天 + BigDecimal actualMaximum = new BigDecimal("" + searchDate.getActualMaximum(Calendar.DAY_OF_YEAR)); + //指定日期是那年的第几天 + BigDecimal dayOfYear = new BigDecimal("" + searchDate.get(Calendar.DAY_OF_YEAR)); + //指定日期是那年的第几月 + BigDecimal monthOfYear = new BigDecimal("" + (searchDate.get(Calendar.MONTH) + 1)); + + /*********************************************************************************/ + + //如果人员已离职--根据合同结束日期计算年假天数 + String resourcestatus = Util.null2String(resourceComInfo.getStatus(resourceId)); + if(resourcestatus.equals("5")){ + try{ + String enddate = Util.null2String(resourceComInfo.getEndDate(resourceId));//合同结束日期 + Calendar calenddate = DateUtil.getCalendar(enddate); + //指定日期是那年的第几天 + dayOfYear = new BigDecimal("" + calenddate.get(Calendar.DAY_OF_YEAR)); + //指定日期是那年的第几月 + monthOfYear = new BigDecimal("" + (calenddate.get(Calendar.MONTH) + 1)); + }catch (Exception e){ + e.printStackTrace(); + } + } + /*********************************************************************************/ + //获取此假期类型下,该人员所在分部对应的假期规则 + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //余额发放方式 + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subCompanyId, departmentId, resourceId), 1); + //释放规则:0-不限制、1-按天释放、2-按月释放 + int releaseRule = Util.getIntValue(detailComInfo.getReleaseRule(ruleId, subCompanyId, departmentId, resourceId), 0); + //小数位数 + int decimalDigit = Util.getIntValue(detailComInfo.getDecimalDigit(ruleId, subCompanyId, departmentId, resourceId), 2); + + /*********************************************************************************/ + + //这几种发放方式不支持释放规则 + if (distributionMode == 5 || distributionMode == 7|| distributionMode == 8) { + return baseAmount; + } + + //指定日期小于入职日期时,释放出来的假期余额应为0(无人提出此要求,暂时不加此限制) + + /*********************************************************************************/ + + //这一年什么时候开始想有假期的 + Calendar calendar = null; + + //如果指定日期的年份大于假期余额的所属年份,则代表假期基数已经全部释放 + if (searchYear.compareTo(belongYear) > 0) { + return baseAmount; + } else if (searchYear.compareTo(belongYear) < 0) { + //如果指定日期的年份小于假期余额的所属年份,则代表假期基数还没有开始释放 + if (releaseRule != 0) { + return new BigDecimal("0"); + } + } else if (searchYear.compareTo(belongYear) == 0) { + } + if (distributionMode == 6) { + calendar = getReleaseDateByDis6(resourceId, ruleId, belongYear, legalOrWelfare); + } else { + calendar = getReleaseDate(resourceId, ruleId, belongYear); + } + + /****************************************************************************************/ + + /* 释放规则 start */ + if (releaseRule == 0) { + canUseAmount = baseAmount; + } else if (releaseRule == 1) { + BigDecimal dateIndex = new BigDecimal("" + (calendar.get(Calendar.DAY_OF_YEAR) - 1)); + canUseAmount = baseAmount.multiply(dayOfYear.subtract(dateIndex)).divide(actualMaximum.subtract(dateIndex), decimalDigit, RoundingMode.HALF_UP); + } else if (releaseRule == 2) { + BigDecimal monthIndex = new BigDecimal("" + calendar.get(Calendar.MONTH)); + canUseAmount = baseAmount.multiply(monthOfYear.subtract(monthIndex)).divide(new BigDecimal("12").subtract(monthIndex), decimalDigit, RoundingMode.HALF_UP); + } + /* 释放规则 end */ + //如果释放为负数,就修改为0 + int i=canUseAmount.compareTo(BigDecimal.ZERO); + if(i < 0){ + canUseAmount = new BigDecimal("0"); + } + } catch (Exception e) { + e.printStackTrace(); + } + return canUseAmount; + } + + /** + * 获取失效日期 + * + * @param ruleId 指定的假期类型ID(对应于数据库表kq_leaveRules的主键ID) + * @param resourceId 指定的人员ID + * @param belongYear 指定的所属年份(格式yyyy) + * @param effectiveDate 生效日期 + * @param expirationDate 失效日期(待计算返回的) + * @return + */ + public static String getExpirationDate(String ruleId, String resourceId, String belongYear, String effectiveDate, String expirationDate) { + try { + //人力资源缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //入职日期 + String companyStartDate = resourceComInfo.getCompanyStartDate(resourceId); + //创建日期 + String createDate = resourceComInfo.getCreatedate(resourceId); + //如果入职日期为空,默认取创建日期 + companyStartDate = companyStartDate.equals("") ? createDate : companyStartDate; + //分部ID + String subcompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + + + //假期规则缓存类 + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //有效期规则:0-不限制、1-按自然年失效、2-按入职日期起12个月、3-自定义次年失效日期、4-按天数失效、5-按季度失效、6-按月数失效 + int validityRule = Util.getIntValue(detailComInfo.getValidityRule(ruleId, subcompanyId, departmentId, resourceId), 0); + //自定义有效天数([validityRule=4]时有效) + int effectiveDays = Util.getIntValue(detailComInfo.getEffectiveDays(ruleId, subcompanyId, departmentId, resourceId), 0); + //自定义有效月数([validityRule=6]时有效) + int effectiveMonths = Util.getIntValue(detailComInfo.getEffectiveMonths(ruleId, subcompanyId, departmentId, resourceId), 0); + //自定义次年失效的月份([validityRule=3]时有效) + String expirationMonth = detailComInfo.getExpirationMonth(ruleId, subcompanyId, departmentId, resourceId); + //自定义次年失效的日期([validityRule=3]时有效) + String expirationDay = detailComInfo.getExpirationDay(ruleId, subcompanyId, departmentId, resourceId); + //允许延长有效期:0--不允许、1--允许 + int extensionEnable = Util.getIntValue(detailComInfo.getExtensionEnable(ruleId, subcompanyId, departmentId, resourceId), 0); + //允许延长的有效天数 + int extendedDays = Util.getIntValue(detailComInfo.getExtendedDays(ruleId, subcompanyId, departmentId, resourceId)); + //获取当前日期 + String currentDate = DateUtil.getCurrentDate(); + //如果生效日期为空,默认取当前日期 + effectiveDate = effectiveDate.equals("") ? currentDate : effectiveDate; + + if (validityRule == 0) { + //不限制有效期,默认永久有效(永久有效时有效日期默认为2222-12-31) + expirationDate = "2222-12-31"; + } else if (validityRule == 1) { + //按自然年(1月1日-12月31日) + if (extensionEnable == 1) { + //允许延长有效期 + expirationDate = DateUtil.addDate(belongYear + "-12-31", extendedDays); + } else { + expirationDate = belongYear + "-12-31"; + } + } else if (validityRule == 2) { + //按入职日期起12个月 + if (companyStartDate.equals("")) { + expirationDate = effectiveDate; + } else if (extensionEnable == 1) { + /*允许延长有效期*/ + expirationDate = DateUtil.addDate((Util.getIntValue(belongYear) + 1) + companyStartDate.substring(4), extendedDays); + } else { + expirationDate = (Util.getIntValue(belongYear) + 1) + companyStartDate.substring(4); + } + } else if (validityRule == 3) { + /*自定义次年失效日期*/ + if (extensionEnable == 1) { + /*允许延长有效期*/ + expirationDate = DateUtil.addDate((Util.getIntValue(belongYear) + 1) + "-" + expirationMonth + "-" + expirationDay, extendedDays); + } else { + expirationDate = (Util.getIntValue(belongYear) + 1) + "-" + expirationMonth + "-" + expirationDay; + } + } else if (validityRule == 4) { + //按天数失效 + if(expirationDate.length() > 0){ + + }else{ + expirationDate = DateUtil.addDate(effectiveDate, effectiveDays); + } + } else if (validityRule == 5) { + //按季度失效 + expirationDate = DateUtil.getLastDayOfQuarter(effectiveDate); + if (extensionEnable == 1) { + /*允许延长有效期*/ + expirationDate = DateUtil.addDate(expirationDate, extendedDays); + } + } else if (validityRule == 6){ + Calendar calendar = DateUtil.addMonth(DateUtil.getCalendar(effectiveDate), effectiveMonths - 1); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String dateStr = sdf.format(calendar.getTime()); + //按月数失效 + expirationDate = DateUtil.getLastDayOfMonth(dateStr); + if (extensionEnable == 1) { + /*允许延长有效期*/ + expirationDate = DateUtil.addDate(expirationDate, extendedDays); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return expirationDate; + } + /** + * 获取育儿家失效日期 + * + * @param ruleId 指定的假期类型ID(对应于数据库表kq_leaveRules的主键ID) + * @param resourceId 指定的人员ID + * @param belongYear 指定的所属年份(格式yyyy) + * @param effectiveDate 生效日期 + * @param searchDate 查询搜索日期 + * @return + */ + public static boolean getParentalExpirationDate(String ruleId, String resourceId, String belongYear, String effectiveDate, String searchDate) { + boolean status = false; + try { + //人力资源缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //分部ID + String subcompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + //假期规则缓存类 + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //有效期规则:0-不限制、1-按自然年失效、2-按入职日期起12个月、3-自定义次年失效日期、4-按天数失效、5-按季度失效、6-按月数失效 + String rulesDetailId = detailComInfo.getId(ruleId, subcompanyId, departmentId, resourceId); + int validityRule = Util.getIntValue(detailComInfo.getValidityRule(ruleId, subcompanyId, departmentId, resourceId), 0); + int yearsOld = StringUtil.parseToInt(detailComInfo.getYearsOld(ruleId, subcompanyId, departmentId, resourceId), 0); + String isprovince = Util.null2s(detailComInfo.getIsProvince(ruleId, subcompanyId, departmentId, resourceId), "1"); + if(isprovince.equals("2")){ + Map params = new HashMap<>(); + getChildrenProvinceId(rulesDetailId,resourceComInfo.getLocationid(resourceId),params); + yearsOld = Util.getIntValue(Util.null2String(params.get("yearsOld"))); + } + //自定义有效天数([validityRule=4]时有效) + if (validityRule == 0) { + //不限制有效期,默认永久有效(永久有效时有效日期默认为2222-12-31) + return true; + } else { + ArrayList listDates = getParentalLeaveDate(resourceId); + for (int i = 0; i < listDates.size(); i++) { + String dateOfBirth = listDates.get(i); + String baseAmountReleaseDate = belongYear + dateOfBirth.substring(4); + int ageLimit = getAgeLimit(dateOfBirth, baseAmountReleaseDate); + if (ageLimit >= 0 && ageLimit <= yearsOld-1) { + String expirationDate = (Util.getIntValue(belongYear) + 1) + dateOfBirth.substring(4); + if (expirationDate.compareTo(searchDate) > 0) { + status = true; + break; + } else { + status = false; + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return status; + } + + /** + * 判断假期余额是否有效 + * + * @param ruleId 指定的假期类型ID(对应于数据库表kq_leaveRules的主键ID) + * @param resourceId 指定的人员ID + * @param belongYear 指定的所属年份(格式yyyy) + * @param searchDate 指定日期(根据此日期判断假期余额是否有效) + * @param effectiveDate 数据库中存放的生效日期 + * @param expirationDate 数据库中存放的失效日期 + * @return + */ + public static boolean getBalanceStatus(String ruleId, String resourceId, String belongYear, String searchDate, String effectiveDate, String expirationDate) { + boolean status = true; + try { + //育儿假 + if (KQLeaveRulesBiz.isLeaveOfParental(ruleId)) { + return getParentalExpirationDate(ruleId, resourceId, belongYear, effectiveDate, searchDate); + } + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subCompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + if (!KQLeaveRulesBiz.isTiaoXiu(ruleId,subCompanyId,departmentId,resourceId)) { + expirationDate = getExpirationDate(ruleId, resourceId, belongYear, effectiveDate, expirationDate); + } + if (!expirationDate.equals("") && expirationDate.compareTo(searchDate)<0) { + status = false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return status; + } + + /** + * 保存加班时长转换成的调休时长,当加班时长的单位与调休单位不一致时根据【加班单位】中的日折算时长转换 + * + * @param resourceId 指定人员ID(根据人员ID判断属于哪个考勤组,根据考勤组获取加班规则ID) + * @param date 指定日期(根据指定日期判断是节假日还是工作日还是休息日、日期格式yyyy-MM-dd) + * @param durationOfOvertime 加班时长 + * @param type 加班时长单位:0-分钟、1-小时、2-天 + * 单位可为空(为空则默认取【加班单位】中设置的最小加班单位) + * @param hoursOfworkday 指定日期的工作时长(只有当指定日期为工作日的时候才有工作时长) + * 当最小加班单位与调休单位不一致时,且指定日期为工作日时使用此工作时长进行折算 + * @param requestId 加班流程的requestId(用于使用记录中可追溯至加班流程) + * @param fromCardOrFlow 是打卡数据还是审批数据:1--打卡、2--流程 + * @param fromDateDb 加班流程表单中的加班开始日期 + * @return + */ + public static boolean saveTimeOfLeave(String resourceId, String date, String durationOfOvertime, String type, String hoursOfworkday, String requestId, String fromCardOrFlow, String fromDateDb) { + //加班转调休是否成功 + boolean flag = true; + try { + String tiaoxiuId = addExtraAmountByDis5(resourceId,date,durationOfOvertime,type,hoursOfworkday,requestId,fromCardOrFlow,fromDateDb,null); + flag = Util.getIntValue(tiaoxiuId, -1) > 0; + } catch (Exception e) { + new BaseBean().writeLog(e); + } + return flag; + } + + /** + * 保存加班时长转换成的调休时长,当加班时长的单位与调休单位不一致时根据【加班单位】中的日折算时长转换 + * + * @param resourceId 指定人员ID(根据人员ID判断属于哪个考勤组,根据考勤组获取加班规则ID) + * @param date 指定日期(根据指定日期判断是节假日还是工作日还是休息日、日期格式yyyy-MM-dd) + * @param durationOfOvertime 加班时长 + * @param type 加班时长单位:0-分钟、1-小时、2-天 + * 单位可为空(为空则默认取【加班单位】中设置的最小加班单位) + * @param hoursOfworkday 指定日期的工作时长(只有当指定日期为工作日的时候才有工作时长) + * 当最小加班单位与调休单位不一致时,且指定日期为工作日时使用此工作时长进行折算 + * @param requestId 加班流程的requestId(用于使用记录中可追溯至加班流程) + * @param fromCardOrFlow 是打卡数据还是审批数据:1--打卡、2--流程 + * @param fromDateDb 加班流程表单中的加班开始日期 + * @return + */ + public static String addExtraAmountByDis5(String resourceId, String date, String durationOfOvertime, String type, String hoursOfworkday, String requestId, String fromCardOrFlow, String fromDateDb,Map otherParam) { + Map params = new HashMap(); + params.put("resourceId", resourceId); + params.put("date", date); + params.put("durationOfOvertime", durationOfOvertime); + params.put("type", type); + params.put("hoursOfworkday", hoursOfworkday); + params.put("requestId", requestId); + params.put("fromCardOrFlow", fromCardOrFlow); + params.put("fromDateDb", fromDateDb); + //加班转的调休明细ID(KQ_BalanceOfLeave的ID) + String tiaoxiuId = "-1"; + try { + String workflowid = "-1"; + RecordSet rs = new RecordSet(); + if(requestId.length() > 0 && Util.getIntValue(requestId) > 0){ + String workflow_sql = "select workflowid from workflow_requestbase where requestid = ? "; + rs.executeQuery(workflow_sql, requestId); + if(rs.next()){ + workflowid = Util.null2s(rs.getString("workflowid"),"-1"); + } + } + //加班转调休是否成功 + boolean flag = false; + //人员信息缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //创建日期 + String createDate = Util.null2String(resourceComInfo.getCompanyStartDate(resourceId)); + //入职日期 + String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(resourceId)); + //如果入职日期为空,则取创建日期 + companyStartDate = "".equals(companyStartDate) ? createDate : companyStartDate; + //分部ID + String subCompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + //日期类型:1-节假日、2-工作日、3-休息日(节假日设置的优先级高于考勤组中的设置) + int changeType = KQOvertimeRulesBiz.getChangeType(resourceId, date); + //获取当前日期,当前时间 + Calendar today = Calendar.getInstance(); + //当前日期 + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + //当前时间 + String currentTime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" + + Util.add0(today.get(Calendar.MINUTE), 2) + ":" + + Util.add0(today.get(Calendar.SECOND), 2); + + /****************************************************************************************************************/ + + //假期类型的缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //[调休]的假期类型的ID + //找到[调休]的假期类型ID + rs.writeLog("lxr2018>addExtraAmountByDis5开始"); + String leaveRulesId = KQLeaveRulesBiz.getTiaoXiu(subCompanyId, departmentId, resourceId)+""; + rulesComInfo.setTofirstRow(); + rs.writeLog("lxr2018>addExtraAmountByDis5="+leaveRulesId); + //[调休]的假期类型的最小请假单位:1-按天、2-按半天、3-按小时、4-按整天 + int minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(leaveRulesId), -1); + //假期规则的缓存类 +// KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //有效期规则:0-永久有效、1-按自然年(1月1日-12月31日)、2-按入职日期起12个月、3-自定义次年失效日期、4-按天数失效 + int validityRule = Util.getIntValue(detailComInfo.getValidityRule(leaveRulesId, subCompanyId,departmentId,resourceId)); + //保留几位小数 + int decimalDigit = Util.getIntValue(detailComInfo.getDecimalDigit(leaveRulesId, subCompanyId,departmentId,resourceId), 2); + + String order = getDeductOrder(""+changeType,detailComInfo.getId(leaveRulesId, subCompanyId,departmentId,resourceId)); + rs.writeLog("lxr2018>order="+order+",changeType="+changeType+",getId="+detailComInfo.getId(leaveRulesId, subCompanyId,departmentId,resourceId)); + + /*如果没有设置调休的假期类型,则直接退出方法*/ + if ("".equals(leaveRulesId)) { + logger.info("未设置调休的假期类型或未调休的假期类型下未设置改人员所在分部可用的假期规则。params=" + JSONObject.toJSONString(params)); + return "-1"; + } + /*【调休】的假期规则的最小请假单位有误时,记录错误日志,直接返回*/ + if (minimumUnit < 1 || minimumUnit > 6) { + logger.info("调休的请假规则的最小请假单位有误。params=" + JSONObject.toJSONString(params)); + return "-1"; + } + /*【调休】的假期规则的有效期规则有误时,记录错误日志,直接返回*/ + if (validityRule < 0 || validityRule > 6) { + logger.info("调休的请假规则的有效期规则有误。params=" + JSONObject.toJSONString(params)); + return "-1"; + } + + /****************************************************************************************************************/ + + //所属年份 + String belongYear = date.substring(0, 4); + //失效日期 + String expirationDate = ""; + //根据有效期规则获取有效日期 + expirationDate = getExpirationDate(leaveRulesId, resourceId, belongYear, date, expirationDate); + + /****************************************************************************************************************/ + + //最小加班单位:1-按天、2-按半天、3-按小时、4-按整天、5-按半小时加班、6-整小时 + int minimumUnitOfOvertime = -1; + //日折算时长 + double hoursToDay = -1.00; + + String sql = "select * from kq_OvertimeUnit where (isDelete is null or isDelete !=1) and id=1"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + if (recordSet.next()) { + minimumUnitOfOvertime = Util.getIntValue(recordSet.getString("minimumUnit"), -1); + hoursToDay = Util.getDoubleValue(recordSet.getString("hoursToDay"), 8.00); + } + /*【加班单位】的相关设置获取有误时,记录错误日志,直接返回*/ + if (minimumUnitOfOvertime == -1 || hoursToDay < 0) { + logger.info("获取到的加班单位的相关设置有误。params=" + JSONObject.toJSONString(params)); + return "-1"; + } + + /** + * 加班单位与调休单位不一致,实现转换 + */ + if (changeType == 2) { + if (hoursOfworkday.equals("")) { + logger.info("指定日期为工作日,但未传入工作日的工作时长。params=" + JSONObject.toJSONString(params)); + } + //当最小加班单位与调休单位不一致时,且指定日期为工作日时使用此工作时长进行折算 + hoursToDay = Util.getDoubleValue(hoursOfworkday, hoursToDay); + } + BigDecimal _hoursToDay = new BigDecimal("" + hoursToDay); + //把加班时长只按照分钟先处理一下 + BigDecimal min_durationOfOvertime = new BigDecimal(Util.null2s(durationOfOvertime, "0")); + if (type.equals("0")) { + } else if (type.equals("1")) { + //加班时长类型为小时---将加班分钟时长*60 + min_durationOfOvertime = min_durationOfOvertime.multiply(new BigDecimal("60")); + } else if (type.equals("2")) { + //加班时长类型为天----将加班分钟时长*一天加班小时数*60 + min_durationOfOvertime = min_durationOfOvertime.multiply(_hoursToDay).multiply(new BigDecimal("60")); + } else if (type.equals("")) { + } + BigDecimal _durationOfOvertime = new BigDecimal(Util.null2s(durationOfOvertime, "0")); + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {//调休单位为天 + if (type.equals("0")) { + //加班时长类型为分钟、调休单位为天----将加班时长转换为天 + _durationOfOvertime = _durationOfOvertime.divide(new BigDecimal("60").multiply(_hoursToDay), 5, RoundingMode.HALF_UP); + } else if (type.equals("1")) { + //加班时长类型为小时、调休单位为天----将加班时长转换为天 + _durationOfOvertime = _durationOfOvertime.divide(_hoursToDay, 5, RoundingMode.HALF_UP); + } else if (type.equals("2")) { + //加班时长类型为天、调休单位为天----不作转换 + } else if (type.equals("")) { + //加班时长类型为空,取【加班单位】中设置的最小加班单位 + if (minimumUnitOfOvertime == 3 || minimumUnitOfOvertime== 5 || minimumUnitOfOvertime== 6) { + //最小加班单位为小时、调休单位为天----将加班时长转换为天 + _durationOfOvertime = _durationOfOvertime.divide(_hoursToDay, 5, RoundingMode.HALF_UP); + } else { + //最小加班单位为天、调休单位为天----不作转换 + } + } + } else if (KQUnitBiz.isLeaveHour(minimumUnit+"")) {//调休单位为小时 + if (type.equals("0")) { + //加班时长类型为分钟、调休单位为小时----将加班时长转换为小时 + _durationOfOvertime = _durationOfOvertime.divide(new BigDecimal("60"), 5, RoundingMode.HALF_UP); + } else if (type.equals("1")) { + //加班时长类型为小时、调休单位为小时----不作转换 + } else if (type.equals("2")) { + //加班时长类型为天、调休单位为小时----将加班时长转换为小时 + _durationOfOvertime = _durationOfOvertime.multiply(_hoursToDay).setScale(5, RoundingMode.HALF_UP); + } else if (type.equals("")) { + //加班时长类型为空,取【加班单位】中设置的最小加班单位 + if (minimumUnitOfOvertime == 3 || minimumUnitOfOvertime== 5 || minimumUnitOfOvertime== 6) { + //最小加班单位为小时、调休单位为小时----不作转换 + } else { + //最小加班单位为天、调休单位为小时----将加班时长转换为小时 + _durationOfOvertime = _durationOfOvertime.multiply(_hoursToDay).setScale(5, RoundingMode.HALF_UP); + } + } + } + logger.info("记录一下【最小加班单位】和调休的【最小请假单位】。params=" + JSONObject.toJSONString(params)); + + /*员工假期余额变更记录*/ + KQUsageHistoryBiz usageHistoryBiz = new KQUsageHistoryBiz(); + KQUsageHistoryEntity usageHistoryEntity = new KQUsageHistoryEntity(); + List usageHistoryEntityList = new ArrayList(); + + Map changeTypeMap = Maps.newHashMap(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + Map overRulesDetailMap = Maps.newHashMap(); + Map> restTimeMap = Maps.newHashMap(); + Map computingModeMap = Maps.newHashMap(); + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + kqOverTimeRuleCalBiz.getOverTimeDataMap(resourceId, date, date, dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap,computingModeMap); + + Map overtimeLogMap = null; + if (otherParam != null && !otherParam.isEmpty()) { + if (otherParam.containsKey("overtimeLogMap")) { + overtimeLogMap = (Map) otherParam.get("overtimeLogMap"); + } + } + String changeType_key = date+"_"+changeType; + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + if(kqOvertimeRulesDetailEntity == null){ + logOvertimeMap(overtimeLogMap,changeType_key,"|加班规则为null|KQOvertimeRulesDetailEntity"); + logger.info("加班转调休记录日志保存失败。获取不到加班规则信息=" + JSONObject.toJSONString(changeType_key)); + return "-1"; + }else{ + logger.info("加班转调休记录。kqOvertimeRulesDetailEntity=" + JSONObject.toJSONString(kqOvertimeRulesDetailEntity)); + } + String timepoint_key = Util.null2String(otherParam.get("timepoint_key")); + /** + * 判断是否允许加班补偿,若未允许,则不累加调休时长,只记录记录使用记录 + * paidLeaveEnable:是否允许加班补偿:0-不允许、1-允许 + */ + String overtime_type = ""; + int paidLeaveEnable = kqOvertimeRulesDetailEntity.getPaidLeaveEnable(); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + if(2 == paidLeaveEnableType){ + if(otherParam != null && !otherParam.isEmpty()){ + if(otherParam.containsKey("overtime_type")){ + overtime_type = Util.null2String(otherParam.get("overtime_type")); + if("0".equalsIgnoreCase(overtime_type)){ + paidLeaveEnable = 1; + }else if("1".equalsIgnoreCase(overtime_type)){ + paidLeaveEnable = 0; + }else{ + paidLeaveEnable = -1; + } + } + } + } + logOvertimeMap(overtimeLogMap,params,timepoint_key+"|生成调休参数|params"); + logOvertimeMap(overtimeLogMap,paidLeaveEnable,timepoint_key+"|是否生成调休|paidLeaveEnable"); + + usageHistoryEntity = new KQUsageHistoryEntity(leaveRulesId,resourceId,requestId,resourceId,currentDate,currentTime,fromCardOrFlow.equals("1") ? "3" : "4",belongYear,"0","0","0","0","0" + ,"0","0","0","0","0","0","0",""+minimumUnit,""+minimumUnit,"","-1",workflowid); + + if (paidLeaveEnable != 1) { + logger.info("未开启加班转调休,记录使用日志。params=" + JSONObject.toJSONString(params)); + /*记录使用记录*/ + usageHistoryEntity.setInsertOrUpdate("PaidLeaveEnable"); + usageHistoryEntityList.add(usageHistoryEntity); + flag = usageHistoryBiz.save(usageHistoryEntityList); + if (!flag){ + logger.info("加班转调休记录日志保存失败。params=" + JSONObject.toJSONString(params)); + } + return "-1"; + }else { + String paidLeaveEnableInfo = "paidLeaveEnable:"+paidLeaveEnable+":paidLeaveEnableType:"+paidLeaveEnableType+":overtime_type:"+overtime_type; + logOvertimeMap(overtimeLogMap,paidLeaveEnableInfo,"|未开启调休|paidLeaveEnable"); + } + + Map paidMap = Maps.newHashMap(); + paidMap.put("changeType", String.valueOf(changeType)); + paidMap.put("order", order); + if(1 == paidLeaveEnableType){ +// 默认加班补偿规则 +// 1-按加班时长比例转调休时长、2-按加班时长范围设置转调休时长、3-按加班的时间段设置转调休时长 + int paidLeaveEnableDefaultType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableDefaultType(); + if(1 == paidLeaveEnableDefaultType){ + Map resultMap = save_paidLeaveEnableDefaultType1(kqOvertimeRulesDetailEntity,_durationOfOvertime,date,leaveRulesId, resourceId,belongYear,expirationDate,fromCardOrFlow,paidMap); + if(!resultMap.isEmpty()){ + return handleUsageHistory(resultMap,params,usageHistoryEntity); + } + }else if(2 == paidLeaveEnableDefaultType){ + int ruleDetailid = kqOvertimeRulesDetailEntity.getId(); + if(ruleDetailid > 0){ + Map resultMap = save_paidLeaveEnableDefaultType2(date,leaveRulesId, resourceId,belongYear,expirationDate,fromCardOrFlow,ruleDetailid,min_durationOfOvertime,minimumUnit,_hoursToDay,paidMap); + if(!resultMap.isEmpty()){ + return handleUsageHistory(resultMap,params,usageHistoryEntity); + } + } + }else if(3 == paidLeaveEnableDefaultType){ + int ruleDetailid = kqOvertimeRulesDetailEntity.getId(); + if(ruleDetailid > 0) { + if (otherParam != null && !otherParam.isEmpty()) { + if (otherParam.containsKey("OvertimeBalanceTimeBean")) { + OvertimeBalanceTimeBean overtimeBalanceTimeBean = (OvertimeBalanceTimeBean) otherParam.get("OvertimeBalanceTimeBean"); + if(overtimeBalanceTimeBean != null){ + int list_index = overtimeBalanceTimeBean.getList_index(); + if(list_index > -1) { + int timepoint_min = overtimeBalanceTimeBean.getTimepoint_mins(); + if(timepoint_min <= 0){ + logger.info("时间区间内加班生成为0。overtimeBalanceTimeBean=" + JSONObject.toJSONString(overtimeBalanceTimeBean)); + } + Map resultMap = save_paidLeaveEnableDefaultType3(date, + leaveRulesId, resourceId, belongYear, expirationDate, fromCardOrFlow, + ruleDetailid, overtimeBalanceTimeBean,list_index,minimumUnit,_hoursToDay,overtimeLogMap,timepoint_key,paidMap); + if(!resultMap.isEmpty()){ + return handleUsageHistory(resultMap,params,usageHistoryEntity); + } + }else{ + logger.info("时间区间内加班下标为-1,overtimeBalanceTimeBean=" + JSONObject.toJSONString(overtimeBalanceTimeBean)); + } + } + } + } + } + } + }else if(2 == paidLeaveEnableType){ + //根据员工在加班流程上选择的加班补偿类型进行补偿两种 +// 1-按加班时长比例转调休时长、2-按加班时长范围设置转调休时长、3-按加班的时间段设置转调休时长 + int paidLeaveEnableFlowType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableFlowType(); + if(1 == paidLeaveEnableFlowType){ + Map resultMap = save_paidLeaveEnableDefaultType1(kqOvertimeRulesDetailEntity,_durationOfOvertime,date,leaveRulesId, resourceId,belongYear,expirationDate,fromCardOrFlow,paidMap); + if(!resultMap.isEmpty()){ + return handleUsageHistory(resultMap,params,usageHistoryEntity); + } + }else if(2 == paidLeaveEnableFlowType){ + int ruleDetailid = kqOvertimeRulesDetailEntity.getId(); + if(ruleDetailid > 0){ + Map resultMap = save_paidLeaveEnableDefaultType2(date,leaveRulesId, resourceId,belongYear,expirationDate,fromCardOrFlow,ruleDetailid,min_durationOfOvertime, + minimumUnit, _hoursToDay,paidMap); + if(!resultMap.isEmpty()){ + return handleUsageHistory(resultMap,params,usageHistoryEntity); + } + } + }else if(3 == paidLeaveEnableFlowType){ + int ruleDetailid = kqOvertimeRulesDetailEntity.getId(); + if(ruleDetailid > 0) { + if (otherParam != null && !otherParam.isEmpty()) { + if (otherParam.containsKey("OvertimeBalanceTimeBean")) { + OvertimeBalanceTimeBean overtimeBalanceTimeBean = (OvertimeBalanceTimeBean) otherParam.get("OvertimeBalanceTimeBean"); + if(overtimeBalanceTimeBean != null){ + int list_index = overtimeBalanceTimeBean.getList_index(); + if(list_index > -1) { + int timepoint_min = overtimeBalanceTimeBean.getTimepoint_mins(); + if(timepoint_min <= 0){ + logger.info("时间区间内加班生成为0。overtimeBalanceTimeBean=" + JSONObject.toJSONString(overtimeBalanceTimeBean)); + } + Map resultMap = save_paidLeaveEnableDefaultType3(date, + leaveRulesId, resourceId, belongYear, expirationDate, fromCardOrFlow, + ruleDetailid, overtimeBalanceTimeBean,list_index, minimumUnit, + _hoursToDay, overtimeLogMap, timepoint_key,paidMap); + if(!resultMap.isEmpty()){ + return handleUsageHistory(resultMap,params,usageHistoryEntity); + } + }else{ + logger.info("时间区间内加班下标为-1,overtimeBalanceTimeBean=" + JSONObject.toJSONString(overtimeBalanceTimeBean)); + } + } + } + } + } + } + } + } catch (Exception e) { + logger.info("加班转调休出错。params=" + JSONObject.toJSONString(params)); + new BaseBean().writeLog(e); + } + return tiaoxiuId; + } + + + /** + * 输出日志并记录假期使用记录 + * @param resultMap + * @param params + * @param usageHistoryEntity + * @return + */ + private static String handleUsageHistory(Map resultMap, Map params, KQUsageHistoryEntity usageHistoryEntity) { + + boolean flag = false; + KQUsageHistoryBiz usageHistoryBiz = new KQUsageHistoryBiz(); + List usageHistoryEntityList = new ArrayList(); + + String result_status = Util.null2String(resultMap.get("status")); + String extraAmount = Util.null2s(Util.null2String(resultMap.get("extraAmount")),"0"); + String tiaoxiuId = Util.null2String(resultMap.get("tiaoxiuId")); + if("-1".equalsIgnoreCase(result_status)){ + logger.info("加班转调休余额为0,不产生调休明细,记录使用日志。params=" + JSONObject.toJSONString(params)); + usageHistoryEntity.setInsertOrUpdate("OnlyRecordLog"); + usageHistoryEntity.setNewExtraAmount("0"); + /*记录使用记录*/ + usageHistoryEntityList.add(usageHistoryEntity); + flag = usageHistoryBiz.save(usageHistoryEntityList); + if (!flag) { + logger.info("加班转调休记录日志保存失败。params=" + JSONObject.toJSONString(params)); + } + return "-1"; + } + if("-2".equalsIgnoreCase(result_status)){ + logger.info("加班转调休保存失败。params=" + JSONObject.toJSONString(params)); + return "-1"; + } + if("1".equalsIgnoreCase(result_status)){ + usageHistoryEntity.setInsertOrUpdate("insert"); + usageHistoryEntity.setNewExtraAmount(extraAmount); + usageHistoryEntity.setBalanceOfLeaveId(tiaoxiuId); + usageHistoryEntityList.add(usageHistoryEntity); + flag = usageHistoryBiz.save(usageHistoryEntityList); + if (!flag) { + logger.info("加班转调休记录日志保存失败。params=" + JSONObject.toJSONString(params)); + } + } + return tiaoxiuId; + } + + /** + * 按加班的时间段设置转调休时长 + */ + private static Map save_paidLeaveEnableDefaultType3(String date, + String leaveRulesId, String resourceId, String belongYear, String expirationDate, + String fromCardOrFlow, int ruleDetailid, OvertimeBalanceTimeBean overtimeBalanceTimeBean, + int list_index, int minimumUnit, BigDecimal _hoursToDay, + Map overtimeLogMap, String timepoint_key, + Map paidMap) { + int changeType = Util.getIntValue(Util.null2String(paidMap.get("changeType"))); + String order = Util.null2String(paidMap.get("order")); + if(Util.getIntValue(order) <= 0){ + order = ""; + } + Map resultMap = Maps.newHashMap(); + + String tiaoxiuId = "-1"; + boolean flag = false; + RecordSet recordSet = new RecordSet(); + String extraAmount = ""; + + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + Map> balanceLengthDetailMap = kqOvertimeRulesBiz.getBalanceTimeDetailMap(ruleDetailid); + + int timepoint_min = overtimeBalanceTimeBean.getTimepoint_mins(); + List lenOfOvertimeList = balanceLengthDetailMap.get("lenOfOvertimeList"); + List lenOfLeaveList = balanceLengthDetailMap.get("lenOfLeaveList"); + String lenOfOvertime = lenOfOvertimeList.get(list_index); + String lenOfLeave = lenOfLeaveList.get(list_index); + + BigDecimal _timepoint_min = new BigDecimal(Util.null2s(""+timepoint_min, "0")); + BigDecimal _lenOfLeave = new BigDecimal(lenOfLeave); + BigDecimal _lenOfOvertime = new BigDecimal(lenOfOvertime); + BigDecimal durationOfLeave = _timepoint_min.multiply(_lenOfLeave).divide(_lenOfOvertime, 5, RoundingMode.HALF_UP); + + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {//调休单位为天 + durationOfLeave = durationOfLeave.divide(new BigDecimal("60").multiply(_hoursToDay), 5, RoundingMode.HALF_UP); + + } else if (KQUnitBiz.isLeaveHour(minimumUnit+"")) {//调休单位为小时 + durationOfLeave = durationOfLeave.divide(new BigDecimal("60"), 5, RoundingMode.HALF_UP); + } + + extraAmount = durationOfLeave.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String paidLeaveEnableDefaultType3 = "minimumUnit:"+minimumUnit+":durationOfLeave:"+durationOfLeave + +":_lenOfLeave:"+_lenOfLeave+":_lenOfOvertime:"+_lenOfOvertime+":_timepoint_min:"+_timepoint_min+":_hoursToDay:"+_hoursToDay; + logOvertimeMap(overtimeLogMap,paidLeaveEnableDefaultType3,timepoint_key+"|生成调休|save_paidLeaveEnableDefaultType3"); + + if (Util.getDoubleValue(extraAmount) <= 0) { + resultMap.put("status", "-1"); + return resultMap; + } + java.sql.Timestamp date1 = KQDateUtil.getUpdateTimeStamp(); + /*插入调休时长*/ + String _belongYear = date.substring(0, 4); + String _belongMonth = date.substring(5, 7); + String sql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,belongMonth,baseAmount,tiaoxiuamount,usedAmount,baseAmount2,extraAmount2,usedAmount2,status,expirationDate,effectiveDate,overtimeType,isDelete,create_time,update_time,creator,changetype,deductorder) " + + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + if (recordSet.getDBType().equals("postgresql")) { + sql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,belongMonth,baseAmount,tiaoxiuamount,usedAmount,baseAmount2,extraAmount2,usedAmount2,status,expirationDate,effectiveDate,overtimeType,isDelete,create_time,update_time,creator,changetype,deductorder) " + + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?,?,?)"; + } + flag = recordSet.executeUpdate(sql, leaveRulesId, resourceId, _belongYear, _belongMonth, 0, extraAmount, 0, 0, 0, 0, 0, expirationDate, date, fromCardOrFlow.equals("0") ? "3" : "4", 0,date1,date1,Util.getIntValue(resourceId),changeType,order); + if (!flag) { + resultMap.put("status", "-2"); + return resultMap; + } + //获取刚才插入的调休明细的ID + sql = "select max(id) from kq_balanceOfLeave where leaveRulesId=? and resourceId=? and belongYear=?"; + recordSet.executeQuery(sql, leaveRulesId, resourceId, belongYear); + if (recordSet.next()) { + tiaoxiuId = recordSet.getString(1); + } + resultMap.put("status", "1"); + resultMap.put("tiaoxiuId", tiaoxiuId); + resultMap.put("extraAmount", extraAmount); + return resultMap; + } + + /** + * 按加班时长范围设置转调休时长 + */ + private static Map save_paidLeaveEnableDefaultType2( + String date, String leaveRulesId, String resourceId, + String belongYear, String expirationDate, String fromCardOrFlow, int ruleDetailid, + BigDecimal min_durationOfOvertime, int minimumUnit, BigDecimal _hoursToDay, + Map paidMap) { + int changeType = Util.getIntValue(Util.null2String(paidMap.get("changeType"))); + String order = Util.null2String(paidMap.get("order")); + if(Util.getIntValue(order) <= 0){ + order = ""; + } + Map resultMap = Maps.newHashMap(); + + String tiaoxiuId = "-1"; + boolean flag = false; + RecordSet recordSet = new RecordSet(); + String extraAmount = ""; + + int overtimelength_i = -1; + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + Map> balanceLengthDetailMap = kqOvertimeRulesBiz.getBalanceLengthDetailMap(ruleDetailid); + if(balanceLengthDetailMap != null && !balanceLengthDetailMap.isEmpty()){ + List overtimelengthList = balanceLengthDetailMap.get("overtimelengthList"); + for(int i = 0 ; i < overtimelengthList.size() ; i++){ + String overtimelength = Util.null2s(overtimelengthList.get(i),""); + if(overtimelength.length() == 0){ + continue; + } + BigDecimal b_60Mins = new BigDecimal(60); + BigDecimal b_overtimelength = new BigDecimal(overtimelength).multiply(b_60Mins); + if(min_durationOfOvertime.compareTo(b_overtimelength) >= 0){ + overtimelength_i = i; + break; + } + } + if(overtimelength_i > -1){ + List balancelengthList = balanceLengthDetailMap.get("balancelengthList"); + if(balancelengthList.size() > overtimelength_i){ + String balancelength = balancelengthList.get(overtimelength_i); + BigDecimal b_balancelength = new BigDecimal(balancelength); + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {//调休单位为天 + b_balancelength = b_balancelength.divide(_hoursToDay, 5, RoundingMode.HALF_UP); + + } else if (KQUnitBiz.isLeaveHour(minimumUnit+"")) {//调休单位为小时 + } + extraAmount = Util.null2s(b_balancelength.toPlainString(), "0"); + } + } + } + new KQLog().info("save_paidLeaveEnableDefaultType2 balanceLengthDetailMap:"+balanceLengthDetailMap + +":min_durationOfOvertime:"+min_durationOfOvertime+":extraAmount:"+extraAmount); + + if (Util.getDoubleValue(extraAmount) <= 0) { + extraAmount = "0.0"; + } + if(overtimelength_i < 0){ + extraAmount = "0.0"; + } + java.sql.Timestamp date1 = KQDateUtil.getUpdateTimeStamp(); + /*插入调休时长*/ + String _belongYear = date.substring(0, 4); + String _belongMonth = date.substring(5, 7); + String sql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,belongMonth,baseAmount,tiaoxiuamount,usedAmount,baseAmount2,extraAmount2,usedAmount2,status,expirationDate,effectiveDate,overtimeType,isDelete,create_time,update_time,creator,changetype,deductorder) " + + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + if (recordSet.getDBType().equals("postgresql")) { + sql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,belongMonth,baseAmount,tiaoxiuamount,usedAmount,baseAmount2,extraAmount2,usedAmount2,status,expirationDate,effectiveDate,overtimeType,isDelete,create_time,update_time,creator,changetype,deductorder) " + + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?,?,?)"; + } + flag = recordSet.executeUpdate(sql, leaveRulesId, resourceId, _belongYear, _belongMonth, 0, extraAmount, 0, 0, 0, 0, 0, expirationDate, date, fromCardOrFlow.equals("0") ? "3" : "4", 0,date1,date1,Util.getIntValue(resourceId),changeType,order); + if (!flag) { + resultMap.put("status", "-2"); + return resultMap; + } + //获取刚才插入的调休明细的ID + sql = "select max(id) from kq_balanceOfLeave where leaveRulesId=? and resourceId=? and belongYear=?"; + recordSet.executeQuery(sql, leaveRulesId, resourceId, belongYear); + if (recordSet.next()) { + tiaoxiuId = recordSet.getString(1); + } + resultMap.put("status", "1"); + resultMap.put("tiaoxiuId", tiaoxiuId); + resultMap.put("extraAmount", extraAmount); + return resultMap; + } + + /** + * 按加班时长比例转调休时长 + */ + private static Map save_paidLeaveEnableDefaultType1( + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity, + BigDecimal _durationOfOvertime, String date, String leaveRulesId, String resourceId, + String belongYear, String expirationDate, String fromCardOrFlow, + Map paidMap) { + int changeType = Util.getIntValue(Util.null2String(paidMap.get("changeType"))); + String order = Util.null2String(paidMap.get("order")); + if(Util.getIntValue(order) <= 0){ + order = ""; + } + Map resultMap = Maps.newHashMap(); + + String tiaoxiuId = "-1"; + boolean flag = false; + RecordSet recordSet = new RecordSet(); + String extraAmount = ""; + /** + * 计算调休时长并存入调休余额中 + */ + BigDecimal _lenOfLeave = new BigDecimal("" + kqOvertimeRulesDetailEntity.getLenOfLeave()); + BigDecimal _lenOfOvertime = new BigDecimal("" + kqOvertimeRulesDetailEntity.getLenOfOvertime()); + BigDecimal durationOfLeave = _durationOfOvertime.multiply(_lenOfLeave).divide(_lenOfOvertime, 5, RoundingMode.HALF_UP); + extraAmount = durationOfLeave.setScale(5, RoundingMode.HALF_UP).toPlainString(); + + if (durationOfLeave.doubleValue() <= 0) { + extraAmount = "0.0"; + } + java.sql.Timestamp date1 = KQDateUtil.getUpdateTimeStamp(); + /*插入调休时长*/ + String _belongYear = date.substring(0, 4); + String _belongMonth = date.substring(5, 7); + String sql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,belongMonth,baseAmount,tiaoxiuamount,usedAmount,baseAmount2,extraAmount2,usedAmount2,status,expirationDate,effectiveDate,overtimeType,isDelete,create_time,update_time,creator,changetype,deductorder) " + + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + if (recordSet.getDBType().equals("postgresql")) { + sql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,belongMonth,baseAmount,tiaoxiuamount,usedAmount,baseAmount2,extraAmount2,usedAmount2,status,expirationDate,effectiveDate,overtimeType,isDelete,create_time,update_time,creator,changetype,deductorder) " + + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?,?,?)"; + } + flag = recordSet.executeUpdate(sql, leaveRulesId, resourceId, _belongYear, _belongMonth, 0, extraAmount, 0, 0, 0, 0, 0, expirationDate, date, fromCardOrFlow.equals("0") ? "3" : "4", 0,date1,date1,Util.getIntValue(resourceId),changeType,order); + if (!flag) { + resultMap.put("status", "-2"); + return resultMap; + } + //获取刚才插入的调休明细的ID + sql = "select max(id) from kq_balanceOfLeave where leaveRulesId=? and resourceId=? and belongYear=?"; + recordSet.executeQuery(sql, leaveRulesId, resourceId, belongYear); + if (recordSet.next()) { + tiaoxiuId = recordSet.getString(1); + } + resultMap.put("status", "1"); + resultMap.put("tiaoxiuId", tiaoxiuId); + resultMap.put("extraAmount", extraAmount); + return resultMap; + } + + /** + * 根据员工假期余额的ID + * + * @param balanceOfLeaveId 调休余额的ID + * @param durationOfOvertime 加班时长,默认为分钟 + * @return + */ + public static boolean updateExtraAmountByDis5(String balanceOfLeaveId, double durationOfOvertime, String requestId) { + boolean result = false; + try { + if (balanceOfLeaveId == null && !balanceOfLeaveId.equals("")) { + logger.info("传入的员工假期余额ID为空。"); + logger.info("balanceOfLeaveId=" + balanceOfLeaveId + ",newExtraAmount=" + durationOfOvertime + ",requestId=" + requestId); + return false; + } + String workflowid = "-1"; + RecordSet rs = new RecordSet(); + if(requestId.length() > 0 && Util.getIntValue(requestId) > 0){ + String workflow_sql = "select workflowid from workflow_requestbase where requestid = ? "; + rs.executeQuery(workflow_sql, requestId); + if(rs.next()){ + workflowid = Util.null2s(rs.getString("workflowid"),"-1"); + } + } + + //获取当前日期,当前时间 + Calendar today = Calendar.getInstance(); + //当前日期 + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + //当前时间 + String currentTime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" + + Util.add0(today.get(Calendar.MINUTE), 2) + ":" + + Util.add0(today.get(Calendar.SECOND), 2); + + //假期类型的缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + + //add + ResourceComInfo resourceComInfo1 = null; + String resourceId1 = ""; + try { + resourceComInfo1 = new ResourceComInfo(); + } catch (Exception e) { + e.printStackTrace(); + } + RecordSet rs1 = new RecordSet(); + String sql1 = "select * from KQ_BalanceOfLeave where id=?"; + rs1.executeQuery(sql1, balanceOfLeaveId); + if (rs1.next()) { + String id = rs1.getString("id"); + resourceId1 = rs1.getString("resourceId"); + } + //分部ID + String subCompanyId = resourceComInfo1.getSubCompanyID(resourceId1); + String departmentId = resourceComInfo1.getDepartmentID(resourceId1); + //[调休]的假期类型的ID + String leaveRulesId = ""; + //找到[调休]的假期类型ID + rulesComInfo.setTofirstRow(); + while (rulesComInfo.next()) { + if (KQLeaveRulesBiz.isTiaoXiu(rulesComInfo.getId(),subCompanyId,departmentId,resourceId1)) { + leaveRulesId = rulesComInfo.getId(); + break; + } + } + //[调休]的假期类型的最小请假单位:1-按天、2-按半天、3-按小时、4-按整天 + int minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(leaveRulesId), 3); + + /****************************************************************************************************************/ + + //加班单位中的日折算时长 + double hoursToDay = 8.00; + String overtimeSql = "select * from kq_OvertimeUnit where (isDelete is null or isDelete !=1) and id=1"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(overtimeSql); + if (recordSet.next()) { + hoursToDay = Util.getDoubleValue(recordSet.getString("hoursToDay"), 8.00); + } + + /****************************************************************************************************************/ + + BigDecimal _hoursToDay = new BigDecimal("" + hoursToDay); + BigDecimal _durationOfOvertime = new BigDecimal("" + durationOfOvertime); + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {//调休单位为天 + //加班时长类型为分钟、调休单位为天----将加班时长转换为天 + _durationOfOvertime = _durationOfOvertime.divide(new BigDecimal("60").multiply(_hoursToDay), 5, RoundingMode.HALF_UP); + } else if (KQUnitBiz.isLeaveHour(minimumUnit+"")) {//调休单位为小时 + //加班时长类型为分钟、调休单位为小时----将加班时长转换为小时 + _durationOfOvertime = _durationOfOvertime.divide(new BigDecimal("60"), 5, RoundingMode.HALF_UP); + } + logger.info("记录一下需要重新生成调休时长的调休时长。"); + logger.info("balanceOfLeaveId=" + balanceOfLeaveId + ",newExtraAmount=" + durationOfOvertime + ",requestId=" + requestId + ",_durationOfOvertime=" + _durationOfOvertime.doubleValue()); + + boolean flag = true; + KQUsageHistoryBiz kqUsageHistoryBiz = new KQUsageHistoryBiz(); + KQUsageHistoryEntity kqUsageHistoryEntity = new KQUsageHistoryEntity(); + List kqUsageHistoryEntities = new ArrayList<>(); + + String sql = "select * from KQ_BalanceOfLeave where id=?"; + recordSet.executeQuery(sql, balanceOfLeaveId); + if (recordSet.next()) { + String id = recordSet.getString("id"); + String resourceId = recordSet.getString("resourceId"); + String belongYear = recordSet.getString("belongYear"); + String belongMonth = recordSet.getString("belongMonth"); + String baseAmount = recordSet.getString("baseAmount"); + String extraAmount = recordSet.getString("extraAmount"); + String usedAmount = recordSet.getString("usedAmount"); + String effectiveDate = recordSet.getString("effectiveDate"); + String expirationDate = recordSet.getString("expirationDate"); + + //根据加班时长以及转换比例得出调休时长 + BigDecimal _lenOfLeave = new BigDecimal("" + KQOvertimeRulesBiz.getLenOfLeave(resourceId, effectiveDate)); + BigDecimal _lenOfOvertime = new BigDecimal("" + KQOvertimeRulesBiz.getLenOfOvertime(resourceId, effectiveDate)); + BigDecimal durationOfLeave = _durationOfOvertime.multiply(_lenOfLeave).divide(_lenOfOvertime, 5, RoundingMode.HALF_UP); + + sql = "update KQ_BalanceOfLeave set extraAmount=?,update_time=? where id=?"; + if (recordSet.getDBType().equals("postgresql")) { + sql = "update KQ_BalanceOfLeave set extraAmount=?,update_time=?::timestamp where id=?"; + } + result = recordSet.executeUpdate(sql, durationOfLeave.setScale(5, RoundingMode.HALF_UP).doubleValue(), KQDateUtil.getUpdateTimeStamp(), id); + if (result) { + kqUsageHistoryEntities = new ArrayList<>(); + kqUsageHistoryEntity = new KQUsageHistoryEntity(leaveRulesId, resourceId, requestId, resourceId, currentDate, currentTime, "8", belongYear, baseAmount, baseAmount, extraAmount, durationOfLeave.setScale(5, RoundingMode.HALF_UP).toPlainString(), usedAmount + , usedAmount, "0", "0", "0", "0", "0", "0", "" + minimumUnit, "" + minimumUnit, "update", id,workflowid); + kqUsageHistoryEntities.add(kqUsageHistoryEntity); + kqUsageHistoryBiz.save(kqUsageHistoryEntities); + } else { + logger.info("加班重新生成调休,员工假期余额更新失败。"); + logger.info("balanceOfLeaveId=" + balanceOfLeaveId + ",newExtraAmount=" + durationOfOvertime + ",requestId=" + requestId + ",_durationOfOvertime=" + durationOfLeave.doubleValue()); + return false; + } + } else { + logger.info("未找到对应的员工假期余额。"); + logger.info("balanceOfLeaveId=" + balanceOfLeaveId + ",newExtraAmount=" + durationOfOvertime + ",requestId=" + requestId); + return false; + } + } catch (Exception e) { + new BaseBean().writeLog(e); + } + return result; + } + + public static String getDeductOrder(String changetype,String ruledetailid){ + RecordSet recordSet = new RecordSet(); + String deductorder = "-1"; + if(Util.null2String(ruledetailid).length() == 0 || Util.null2String(changetype).length() == 0){ + recordSet.writeLog("getDeductOrder.changetype="+changetype+",ruledetailid="+ruledetailid); + return deductorder; + } + String sql = "select ruleId,ruleName,scopeType,scopeValue,distributionMode,deductorder from kq_LeaveRulesDetail where id = '"+ruledetailid+"'"; + recordSet.executeQuery(sql); + if(recordSet.next()){ + String tmp_order = Util.null2String(recordSet.getString("deductorder")); + if(tmp_order.length()>0){ + String[] orders = tmp_order.split(","); + if(null != orders && orders.length>0){ + for (int i = 0; i < orders.length; i++) { + if(orders[i].equals(changetype) && i==0){ + deductorder = "1"; + }else if(orders[i].equals(changetype) && i==1){ + deductorder = "2"; + }else if(orders[i].equals(changetype) && i==2){ + deductorder = "3"; + } + } + } + } + } + recordSet.writeLog("getDeductOrder.changetype="+changetype+",ruledetailid="+ruledetailid+",deductorder="+deductorder+",sql="+sql); + + return deductorder; + } + + /** + * 累加已用的假期时长 + * + * @param resourceId 指定人员ID + * @param date 请假日期(目前请假扣减逻辑:如果请假跨了多天,会拆分成一天一天扣减) + * @param ruleId 指定假期规则 + * @param duration 请假时长 + * @param type 时长类型:0-分钟、1-小时、2-天 + * 传入空值则默认取假期规则设置中的单位 + * @param fromDateDb 请假流程表单中的请假开始日期(根据请假开始日期判断假期余额是否有效) + * @param requestId 请假流程的requestId + */ + public static void addUsedAmount(String resourceId, String date, String ruleId, String duration, String type, String requestId, String fromDateDb) { + try { + if(Util.getDoubleValue(duration) <= 0) { + logger.info("请假时长为0不做扣减。resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + java.sql.Timestamp updateDate = KQDateUtil.getUpdateTimeStamp(); + /*获取当前日期,当前时间*/ + Calendar today = Calendar.getInstance(); + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + String currentTime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" + + Util.add0(today.get(Calendar.MINUTE), 2) + ":" + + Util.add0(today.get(Calendar.SECOND), 2); + + /****************************************************************************************************************/ + + //人力资源缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //分部ID + String subcompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + /****************************************************************************************************************/ + + //假期类型缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + //最小请假单位:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假 + int minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(ruleId)); + //最小请假单位获取有误,记录错误日志,直接退出方法 + if (minimumUnit < 1 || minimumUnit > 6) { + logger.info("最小请假单位获取有误。resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + //是否启用假期余额:0-不启用、1-启用 + int balanceEnable = Util.getIntValue(rulesComInfo.getBalanceEnable(ruleId), 0); + //该假期未开启假期余额,记录错误日志,退出方法 + if (balanceEnable != 1) { + logger.info("该假期未开启假期余额。resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + //前台传回的请假时长类型与后台设置的假期限制的最小请假单位不相符,暂不支持转换,记录错误日志,直接退出方法 + boolean flag = type.equals("") || ("1".equals(type) && KQUnitBiz.isLeaveHour(minimumUnit+"")) || ("2".equals(type) && (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4)); + if (!flag) { + logger.info("前台传回的请假时长类型与后台设置的请假类型限制的最小请假单位不相符。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + + /****************************************************************************************************************/ + + //假期规则缓存类(每个假期类型下可能存在多个假期规则) + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //余额发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放 + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subcompanyId, departmentId, resourceId)); + //扣减优先级:1-法定年假、2-福利年假 + int priority = Util.getIntValue(detailComInfo.getPriority(ruleId, subcompanyId, departmentId, resourceId), 1); + + /****************************************************************************************************************/ + + //如果请假开始日期为空,默认取请假日期 + fromDateDb = date; + + boolean istiaoxiu = false; + + + //员工假期余额变更记录 + KQUsageHistoryEntity usageHistoryEntity = new KQUsageHistoryEntity(); + List usageHistoryEntityList = new ArrayList(); + + List updateList = new ArrayList(); + BigDecimal _duration = new BigDecimal(Util.null2s(duration, "0")); + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId=" + ruleId + " and resourceId=" + resourceId + " order by belongYear"; + if (distributionMode == 5) { + istiaoxiu = true; + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql = " select * from kq_balanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceId + " and leaveRulesId=" + ruleId + " and (expirationDate is null or expirationDate='' or expirationDate>='" + fromDateDb + "') " + + " order by deductorder asc,belongYear asc,expirationDate asc,id asc "; + } else { + sql = " select * from kq_balanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceId + " and leaveRulesId=" + ruleId + " and (expirationDate is null or expirationDate>='" + fromDateDb + "') " + + " order by deductorder asc,belongYear asc,expirationDate asc,id asc "; + } + } + // 如果是育儿假 + boolean leaveOfParental = KQLeaveRulesBiz.isLeaveOfParentalNum(ruleId); + if(leaveOfParental){ + sql = " select * from kq_balanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceId + " and leaveRulesId=" + ruleId + " and (expirationDate is null or expirationDate='' or expirationDate>='" + fromDateDb + "') " + + " order by belongYear asc,expirationDate asc,id asc "; + } + new BaseBean().writeLog("==查询的sql==selectsql:"+sql); + recordSet.executeQuery(sql); + int total = recordSet.getCounts(); + int index = 0; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String allow_negative = Util.null2String(kqSettingsComInfo.getMain_val("allow_negative"),"0"); + boolean allow_negative_flag = "1".equals(allow_negative); + int indexStatus = 0; + while (recordSet.next()) { + index++; + // + String id = recordSet.getString("id"); + //所属年份 + String belongYear = recordSet.getString("belongYear"); + //失效日期 + String expirationDate = recordSet.getString("expirationDate"); + //生效日期 + String effectiveDate = recordSet.getString("effectiveDate"); + //判断假期余额是否失效 + boolean status = getBalanceStatus(ruleId, resourceId, belongYear, fromDateDb, effectiveDate, expirationDate); + if (!status) { + //如果是调休+开启了负数+最后一行 + if(allow_negative_flag && index == total){ + indexStatus = 1; + } + continue; + } + + + String changetype = Util.null2String(recordSet.getString("changetype")); + //基数 + BigDecimal baseAmount = new BigDecimal(Util.null2s(recordSet.getString("baseAmount"), "0")); + //额外 + 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")); + //福利年假的基数 + BigDecimal baseAmount2 = new BigDecimal(Util.null2s(recordSet.getString("baseAmount2"), "0")); + //福利年假的额外 + BigDecimal usedAmount2 = new BigDecimal(Util.null2s(recordSet.getString("usedAmount2"), "0")); + //福利年假的已休 + BigDecimal extraAmount2 = new BigDecimal(Util.null2s(recordSet.getString("extraAmount2"), "0")); + if (distributionMode == 6) { + if (baseAmount.add(extraAmount).add(tiaoxiuAmount).subtract(usedAmount).add(baseAmount2).add(extraAmount2).subtract(usedAmount2).doubleValue() <= 0) { + if(!(allow_negative_flag && index == total)){ + continue; + } + } + + baseAmount = getCanUseAmount(resourceId, ruleId, belongYear, baseAmount, "legal", fromDateDb); + baseAmount2 = getCanUseAmount(resourceId, ruleId, belongYear, baseAmount2, "welfare", fromDateDb); + } else if(distributionMode == 5||leaveOfParental){ + //不过滤前端会有扣减为0的记录 + if (baseAmount.add(extraAmount).add(tiaoxiuAmount).subtract(usedAmount).doubleValue() <= 0) { + if(!(allow_negative_flag && index == total)) { + continue; + } + } + } else{ + if (baseAmount.add(extraAmount).add(tiaoxiuAmount).subtract(usedAmount).doubleValue() <= 0) { + if(!(allow_negative_flag && index == total)) { + continue; + } + } + baseAmount = getCanUseAmount(resourceId, ruleId, belongYear, baseAmount, "", fromDateDb); + } + + logger.info("addusedamount.id="+id+",indexStatus="+indexStatus+",baseAmount="+baseAmount+",baseAmount2="+baseAmount2+",distributionMode="+distributionMode+",extraAmount="+extraAmount+",usedAmount="+usedAmount); + + //员工假期余额使用记录 + usageHistoryEntity = new KQUsageHistoryEntity(); + usageHistoryEntity.setLeaveRulesId(ruleId); + usageHistoryEntity.setRelatedId(resourceId); + usageHistoryEntity.setWfRequestId(requestId); + usageHistoryEntity.setOperator(resourceId); + usageHistoryEntity.setOperateDate(currentDate); + usageHistoryEntity.setOperateTime(currentTime); + usageHistoryEntity.setOperateType("1"); + usageHistoryEntity.setInsertOrUpdate("update"); + usageHistoryEntity.setBelongYear(belongYear); + usageHistoryEntity.setOldUsedAmount(usedAmount.setScale(5, RoundingMode.HALF_UP).toPlainString()); + usageHistoryEntity.setOldUsedAmount2(usedAmount2.setScale(5, RoundingMode.HALF_UP).toPlainString()); + usageHistoryEntity.setOldMinimumUnit("" + minimumUnit); + usageHistoryEntity.setNewMinimumUnit("" + minimumUnit); + usageHistoryEntityList.add(usageHistoryEntity); + + if (distributionMode == 6) {//如果年假为混合模式(法定年假+福利年假) + if (priority == 1) {//扣减优先级:先扣减法定年假、再扣减福利年假 + BigDecimal temp = baseAmount.add(extraAmount).subtract(usedAmount).subtract(_duration); + if (temp.doubleValue() >= 0) { + String newUsedAmount = usedAmount.add(_duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + + //请假时长扣减完了重置下,以免影响下面的新增逻辑 + _duration = new BigDecimal("0"); + break; + } else { + temp = baseAmount.add(extraAmount).subtract(usedAmount).add(baseAmount2).add(extraAmount2).subtract(usedAmount2).subtract(_duration); + //该假期剩余假期余额不足以扣减,记录错误日志,退出方法 + if (index == total && temp.doubleValue() < 0) { + logger.info("该人员的该假期所有的剩余假期余额都不足以扣减。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId + + ",baseAmount=" + baseAmount.doubleValue() + ",extraAmount=" + extraAmount.doubleValue() + ",usedAmount=" + usedAmount.doubleValue() + + ",baseAmount2=" + baseAmount2.doubleValue() + ",extraAmount2=" + extraAmount2.doubleValue() + ",usedAmount2=" + usedAmount2.doubleValue()); + String newUsedAmount = baseAmount.add(extraAmount).setScale(5,RoundingMode.HALF_UP).toPlainString(); + String newUsedAmount2 = _duration.subtract(baseAmount.add(extraAmount).subtract(usedAmount)).add(usedAmount2).setScale(5, RoundingMode.HALF_UP).toString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ",usedAmount2=" + (newUsedAmount2) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setBalanceOfLeaveId(id); + + //请假时长扣减完了重置下,以免影响下面的新增逻辑 + _duration = new BigDecimal("0"); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount = baseAmount.add(extraAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String newUsedAmount2 = _duration.subtract(baseAmount.add(extraAmount).subtract(usedAmount)).add(usedAmount2).setScale(5, RoundingMode.HALF_UP).toString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ",usedAmount2=" + (newUsedAmount2) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setBalanceOfLeaveId(id); + + //请假时长扣减完了重置下,以免影响下面的新增逻辑 + _duration = new BigDecimal("0"); + break; + } else { + _duration = new BigDecimal("0").subtract(temp); + String newUsedAmount = baseAmount.add(extraAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String newUsedAmount2 = baseAmount2.add(extraAmount2).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ",usedAmount2=" + (newUsedAmount2) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setBalanceOfLeaveId(id); + continue; + } + } + } else {//扣减优先级:先扣减福利年假、再扣减法定年假 + BigDecimal temp = baseAmount2.add(extraAmount2).subtract(usedAmount2).subtract(_duration); + if (temp.doubleValue() >= 0) { + String newUsedAmount2 = usedAmount2.add(_duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount2=" + (newUsedAmount2) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setBalanceOfLeaveId(id); + break; + } else { + temp = baseAmount2.add(extraAmount2).subtract(usedAmount2).add(baseAmount).add(extraAmount).subtract(usedAmount).subtract(_duration); + /*该假期剩余假期余额不足以扣减,记录错误日志,退出方法*/ + if (index == total && temp.doubleValue() < 0) { + logger.info("该人员的该假期所有的剩余假期余额都不足以扣减。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId + + ",baseAmount=" + baseAmount.doubleValue() + ",extraAmount=" + extraAmount.doubleValue() + ",usedAmount=" + usedAmount.doubleValue() + + ",baseAmount2=" + baseAmount2.doubleValue() + ",extraAmount2=" + extraAmount2.doubleValue() + ",usedAmount2=" + usedAmount2.doubleValue()); + String newUsedAmount2 = baseAmount2.add(extraAmount2).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String newUsedAmount = _duration.subtract(baseAmount2.add(extraAmount2).subtract(usedAmount2)).add(usedAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount2=" + (newUsedAmount2) + ",usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + + //请假时长扣减完了重置下,以免影响下面的新增逻辑 + _duration = new BigDecimal("0"); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount2 = baseAmount2.add(extraAmount2).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String newUsedAmount = _duration.subtract(baseAmount2.add(extraAmount2).subtract(usedAmount2)).add(usedAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount2=" + (newUsedAmount2) + ",usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + + //请假时长扣减完了重置下,以免影响下面的新增逻辑 + _duration = new BigDecimal("0"); + break; + } else { + _duration = new BigDecimal("0").subtract(temp); + String newUsedAmount2 = baseAmount2.add(extraAmount2).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String newUsedAmount = baseAmount.add(extraAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount2=" + (newUsedAmount2) + ",usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + continue; + } + } + } + } else {//非混合模式 + BigDecimal temp = baseAmount.add(extraAmount).add(tiaoxiuAmount).subtract(usedAmount).subtract(_duration); + logger.info("addusedamount.temp="+temp+",index="+index+",total="+total); + /*该假期剩余假期余额不足以扣减,记录错误日志,退出方法*/ + if (index == total && temp.doubleValue() < 0) { + logger.info("该人员的该假期所有的剩余假期余额都不足以扣减。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId + + ",baseAmount=" + baseAmount.doubleValue() + ",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) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + logger.info("addusedamount.updateSql1="+updateSql); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + + //请假时长扣减完了重置下,以免影响下面的新增逻辑 + _duration = new BigDecimal("0"); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount = usedAmount.add(_duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + logger.info("addusedamount.updateSql2="+updateSql); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + + //请假时长扣减完了重置下,以免影响下面的新增逻辑 + _duration = new BigDecimal("0"); + break; + } else { + _duration = new BigDecimal("0").subtract(temp); + String newUsedAmount = baseAmount.add(extraAmount).add(tiaoxiuAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + + logger.info("addusedamount.updateSql3="+updateSql); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + continue; + } + } + } + + //index=0表示没有假期数据 + if (allow_negative_flag && (index == 0 || indexStatus==1)) { + //所属年份 + String belongYear = fromDateDb.substring(0, 4); + //基数 + BigDecimal baseAmount = new BigDecimal("0"); + //额外 + BigDecimal extraAmount = new BigDecimal("0"); + //加班生成调休 + BigDecimal tiaoxiuAmount = new BigDecimal("0"); + //已休 + BigDecimal usedAmount = new BigDecimal("0"); + + if(_duration.doubleValue()>0){ + //员工假期余额使用记录 + usageHistoryEntity = new KQUsageHistoryEntity(); + usageHistoryEntity.setLeaveRulesId(ruleId); + usageHistoryEntity.setRelatedId(resourceId); + usageHistoryEntity.setWfRequestId(requestId); + usageHistoryEntity.setOperator(resourceId); + usageHistoryEntity.setOperateDate(currentDate); + usageHistoryEntity.setOperateTime(currentTime); + usageHistoryEntity.setOperateType("1"); + usageHistoryEntity.setInsertOrUpdate("insert"); + usageHistoryEntity.setBelongYear(belongYear); + usageHistoryEntity.setOldUsedAmount("0"); + usageHistoryEntity.setOldMinimumUnit("" + minimumUnit); + usageHistoryEntity.setNewMinimumUnit("" + minimumUnit); + usageHistoryEntityList.add(usageHistoryEntity); + + + //非混合模式 + BigDecimal temp = baseAmount.add(extraAmount).add(tiaoxiuAmount).subtract(usedAmount).subtract(_duration); + /*该假期剩余假期余额不足以扣减,记录错误日志,退出方法*/ + if (temp.doubleValue() < 0) { + logger.info("该人员的该假期所有的剩余假期余额都不足以扣减。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId + + ",baseAmount=" + baseAmount.doubleValue() + ",extraAmount=" + extraAmount.doubleValue() + ",usedAmount=" + usedAmount.doubleValue()); + String newUsedAmount = usedAmount.add(_duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "INSERT INTO KQ_BalanceOfLeave(resourceId,leaveRulesId,belongYear,baseAmount,extraAmount,usedAmount,effectiveDate, update_time) " + + "VALUES(" + resourceId + "," + ruleId + ",'" + belongYear + "',0,0," + newUsedAmount + ",'" + fromDateDb + "',?)"; + if (recordSet.getDBType().equals("postgresql")) { + updateSql = "INSERT INTO KQ_BalanceOfLeave(resourceId,leaveRulesId,belongYear,baseAmount,extraAmount,usedAmount,effectiveDate, update_time) " + + "VALUES(" + resourceId + "," + ruleId + ",'" + belongYear + "',0,0," + newUsedAmount + ",'" + fromDateDb + "',?::timestamp)"; + } + updateList.add(updateSql); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + + logger.info("addusedamount.updateSql4="+updateSql); + } + } + } + + logger.info("requestId:"+requestId+"::updateList:"+updateList); + /*SQL操作批处理*/ + for (int i = 0; i < updateList.size(); i++) { + flag = recordSet.executeUpdate(updateList.get(i),updateDate); + if (!flag) { + logger.info("员工提交请假流程累计已休假期的SQL执行失败。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + } + /*记录假期使用记录*/ + if (flag && usageHistoryEntityList.size() > 0) { + KQUsageHistoryBiz usageHistoryBiz = new KQUsageHistoryBiz(); + flag = usageHistoryBiz.save(usageHistoryEntityList); + if (!flag) { + logger.info("请假流程,员工假期余额变更记录SQL执行失败。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + logger.info("请假流程扣减出错。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + } + + /** + * 销假流程归档时,需要将曾经扣减的假期余额返还给相应人员 + * + * @param resourceId 指定人员ID + * @param date 指定日期 + * 根据日期取指定指定日期年份之前的所有有效的余额,传入空值则取所有年份的有效余额 + * @param ruleId 指定假期规则 + * @param duration 请假时长 + * @param type 时长类型:1-小时、2-天 + * 传入空值则默认取假期规则设置中的单位 + * @param requestId 请假流程的requestId + * @return + */ + public static void reduceUsedAmount(String resourceId, String date, String ruleId, String duration, String type, String requestId) { + KQBalanceOfLeaveBiz.reduceUsedAmount(resourceId, date, ruleId, duration, type,requestId,null); + } + public static void reduceUsedAmount(String resourceId, String date, String ruleId, String duration, String type, String requestId, String back_requestid) { + try { + if(Util.getDoubleValue(duration) <= 0) { + logger.info("时长为0不做返还。resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + java.sql.Timestamp updateDate = KQDateUtil.getUpdateTimeStamp(); + /*获取当前日期,当前时间*/ + Calendar today = Calendar.getInstance(); + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + String currentTime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" + + Util.add0(today.get(Calendar.MINUTE), 2) + ":" + + Util.add0(today.get(Calendar.SECOND), 2); + + /****************************************************************************************************************/ + + //人力资源缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //分部 + String subcompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + /****************************************************************************************************************/ + logger.info("reduceUsedAmount:resourceId:"+resourceId+":fromdatedb:"+date+":newLeaveType:"+ruleId+":duration:"+duration+":requestid:"+requestId+":back_requestid:"+back_requestid); + + //假期规则缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + //最小请假单位:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假 + int minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(ruleId)); + //最小请假单位获取有误,记录错误日志,直接退出方法 + if (minimumUnit < 1 || minimumUnit > 6) { + logger.info("最小请假单位获取有误。resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + //是否启用假期余额:0-不启用、1-启用 + int balanceEnable = Util.getIntValue(rulesComInfo.getBalanceEnable(ruleId), 0); + //该假期未开启假期余额,记录错误日志,退出方法 + if (balanceEnable != 1) { + logger.info("该假期未开启假期余额。resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + //前台传回的请假时长类型与后台设置的假期限制的最小请假单位不相符,暂不支持转换,记录错误日志,直接退出方法 + boolean flag = type.equals("") || ("1".equals(type) && KQUnitBiz.isLeaveHour(minimumUnit+"")) || ("2".equals(type) && (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4)); + if (!flag) { + logger.info("前台传回的请假时长类型与后台设置的请假类型限制的最小请假单位不相符。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + + /****************************************************************************************************************/ + + //假期规则缓存类(每个假期类型下可能存在多个假期规则) + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //余额发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放 + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subcompanyId, departmentId, resourceId)); + //扣减优先级:1-法定年假、2-福利年假 + int priority = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subcompanyId, departmentId, resourceId)); + + /****************************************************************************************************************/ + + logger.info("reduceUsedAmount:distributionMode:"+distributionMode+":priority:"+priority); + + //员工假期余额变更记录 + KQUsageHistoryEntity usageHistoryEntity = new KQUsageHistoryEntity(); + + List usageHistoryEntityList = new ArrayList(); + + + String deductYear = ""; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leaveback_handle = Util.null2String(kqSettingsComInfo.getMain_val("leaveback_handle"),"0"); + if("1".equals(leaveback_handle) && null != back_requestid && back_requestid.length()>0){ + RecordSet rs1 = new RecordSet(); + String historySql = "select * from kq_usagehistory where relatedId='"+resourceId+"' and leaveRulesId='"+ruleId+"' and wfRequestId='"+back_requestid+"' order by belongYear"; + rs1.executeQuery(historySql); + logger.info("reduceUsedAmount:historySql:"+historySql); + while (rs1.next()){ + String belongyear = Util.null2String(rs1.getString("belongyear")); + deductYear += ",'"+belongyear+"'"; + } + } + logger.info("reduceUsedAmount:deductYear:"+deductYear+",leaveback_handle="+leaveback_handle); + + BigDecimal _duration = new BigDecimal(Util.null2s(duration, "0")); + List updateList = new ArrayList(); + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId=" + ruleId + " and resourceId=" + resourceId + " order by belongYear desc"; + if(null != deductYear && deductYear.length()>0){ + deductYear = deductYear.substring(1); + sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId=" + ruleId + " and resourceId=" + resourceId + + " and belongYear in ("+deductYear+") " + + " order by belongYear "; + } + boolean leaveOfParental = KQLeaveRulesBiz.isLeaveOfParentalNum(ruleId); + if(distributionMode == 5||leaveOfParental){ + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId=" + ruleId + " and resourceId=" + resourceId + " and (expirationDate is null or expirationDate='' or expirationDate>='" + date + "') order by belongYear asc, expirationDate asc, id asc "; + } else { + sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId=" + ruleId + " and resourceId=" + resourceId + " and (expirationDate is null or expirationDate>='" + date + "') order by belongYear asc, expirationDate asc, id asc "; + } + } + recordSet.executeQuery(sql); + int total = recordSet.getCounts(); + int index = 0; + logger.info("reduceUsedAmount:sql:"+sql); + while (recordSet.next()) { + index++; + // + String id = recordSet.getString("id"); + //所属年份 + String belongYear = recordSet.getString("belongYear"); + //已休 + BigDecimal usedAmount = new BigDecimal(Util.null2s(recordSet.getString("usedAmount"), "0")); + //福利年假的已休 + BigDecimal usedAmount2 = new BigDecimal(Util.null2s(recordSet.getString("usedAmount2"), "0")); + + //记录使用记录 + usageHistoryEntity = new KQUsageHistoryEntity(); + usageHistoryEntity.setLeaveRulesId(ruleId); + usageHistoryEntity.setRelatedId(resourceId); + usageHistoryEntity.setWfRequestId(requestId); + usageHistoryEntity.setOperator(resourceId); + usageHistoryEntity.setOperateDate(currentDate); + usageHistoryEntity.setOperateTime(currentTime); + usageHistoryEntity.setOperateType("2"); + usageHistoryEntity.setInsertOrUpdate("update"); + usageHistoryEntity.setBelongYear(belongYear); + usageHistoryEntity.setOldUsedAmount(usedAmount.setScale(5, RoundingMode.HALF_UP).toPlainString()); + usageHistoryEntity.setOldUsedAmount2(usedAmount2.setScale(5, RoundingMode.HALF_UP).toPlainString()); + usageHistoryEntity.setOldMinimumUnit("" + minimumUnit); + usageHistoryEntity.setNewMinimumUnit("" + minimumUnit); + + if (distributionMode == 6) {//如果年假为混合模式(法定年假+福利年假) + if (priority == 1) { + BigDecimal temp = usedAmount.subtract(_duration); + logger.info("reduceUsedAmount:id1:"+id+":belongYear:"+belongYear+":usedAmount:"+usedAmount+":usedAmount2:"+usedAmount2+":temp1:"+temp); + if (temp.doubleValue() >= 0) { + String newUsedAmount = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + newUsedAmount + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setNewUsedAmount2(usedAmount2.setScale(5, RoundingMode.HALF_UP).toPlainString()); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + break; + } else { + temp = usedAmount.add(usedAmount2).subtract(_duration); + logger.info("reduceUsedAmount:id2:"+id+":belongYear:"+belongYear+":usedAmount:"+usedAmount+":usedAmount2:"+usedAmount2+":temp2:"+temp); + /*此次销假流程的销假天数大于了他的已休假期,流程参数有误*/ + if (index == total && temp.doubleValue() < 0) { + String newUsedAmount = "0"; + String newUsedAmount2 = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=0,usedAmount2=" + newUsedAmount2 + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + + logger.info("此次销假流程的销假天数大于了他的已休假期,流程参数有误。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount = "0"; + String newUsedAmount2 = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=0,usedAmount2=" + newUsedAmount2 + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + break; + } else { + _duration = new BigDecimal("0").subtract(temp); + String updateSql = "update kq_balanceOfLeave set usedAmount=0,usedAmount2=0,update_time=? where id=" + id; + if (recordSet.getDBType().equals("postgresql")) { + updateSql = "update kq_balanceOfLeave set usedAmount=0,usedAmount2=0,update_time=?::timestamp where id=" + id; + } + updateList.add(updateSql); + + if (usedAmount.doubleValue() != 0 || usedAmount2.doubleValue() != 0) { + usageHistoryEntity.setNewUsedAmount("0"); + usageHistoryEntity.setNewUsedAmount2("0"); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + } + continue; + } + } + } else { + BigDecimal temp = usedAmount2.subtract(_duration); + if (temp.doubleValue() >= 0) { + String newUsedAmount2 = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount2=" + newUsedAmount2 + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount2(newUsedAmount2); + usageHistoryEntity.setNewUsedAmount(usedAmount.setScale(5, RoundingMode.HALF_UP).toPlainString()); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + break; + } else { + temp = usedAmount2.add(usedAmount).subtract(_duration); + /*此次销假流程的销假天数大于了他的已休假期,流程参数有误*/ + if (index == total && temp.doubleValue() < 0) { + String newUsedAmount = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount2=0,usedAmount=" + newUsedAmount + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount2("0.00"); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + + logger.info("此次销假流程的销假天数大于了他的已休假期,流程参数有误。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount2=0,usedAmount=" + newUsedAmount + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount2("0.00"); + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + break; + } else { + _duration = new BigDecimal("0").subtract(temp); + String updateSql = "update kq_balanceOfLeave set usedAmount=0,usedAmount2=0,update_time=? where id=" + id; + if (recordSet.getDBType().equals("postgresql")) { + updateSql = "update kq_balanceOfLeave set usedAmount=0,usedAmount2=0,update_time=?::timestamp where id=" + id; + } + updateList.add(updateSql); + + if (usedAmount.doubleValue() != 0 || usedAmount2.doubleValue() != 0) { + usageHistoryEntity.setNewUsedAmount2("0"); + usageHistoryEntity.setNewUsedAmount("0"); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + } + continue; + } + } + } + } else {//非混合模式 + BigDecimal temp = usedAmount.subtract(_duration); + /*此次销假流程的销假天数大于了他的已休假期,流程参数有误*/ + if (index == total && temp.doubleValue() < 0) { + String newUsedAmount = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + newUsedAmount + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + + logger.info("此次销假流程的销假天数大于了他的已休假期,流程参数有误。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount = temp.setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + newUsedAmount + ", update_time=? where id=" + id; + updateList.add(updateSql); + + usageHistoryEntity.setNewUsedAmount(newUsedAmount); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + break; + } else { + _duration = new BigDecimal("0").subtract(temp); + String updateSql = "update kq_balanceOfLeave set usedAmount=0, update_time=? where id=" + id; + updateList.add(updateSql); + + if (usedAmount.doubleValue() != 0) { + usageHistoryEntity.setNewUsedAmount("0"); + usageHistoryEntity.setBalanceOfLeaveId(id); + usageHistoryEntityList.add(usageHistoryEntity); + } + continue; + } + } + } + + logger.info("requestId:"+requestId+"::updateList:"+updateList); + /*SQL操作批处理*/ + for (int i = 0; i < updateList.size(); i++) { + flag = recordSet.executeUpdate(updateList.get(i),updateDate); + if (!flag) { + logger.info("提交销假流程,回退员工假期余额SQL执行失败。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + } + /*记录假期使用记录*/ + if (flag && usageHistoryEntityList.size() > 0) { + KQUsageHistoryBiz usageHistoryBiz = new KQUsageHistoryBiz(); + flag = usageHistoryBiz.save(usageHistoryEntityList); + if (!flag) { + logger.info("提交销假流程,员工假期余额变更记录SQL执行失败。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + logger.info("销假流程恢复假期余额报错。" + + "resourceId=" + resourceId + ",date=" + date + ",ruleId=" + ruleId + ",type=" + type + ",duration=" + duration + ",requestId=" + requestId); + return; + } + } + + /** + * 初始化系统内所有假期的假期余额 + */ + public static void createBalanceOfLeave() { + try { + Calendar today = Calendar.getInstance(); + String currentYear = Util.add0(today.get(Calendar.YEAR), 4); + today.add(Calendar.YEAR,-1); + String lastYear = Util.add0(today.get(Calendar.YEAR), 4); + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + kqLeaveRulesComInfo.setTofirstRow(); + while (kqLeaveRulesComInfo.next()) { + if (!kqLeaveRulesComInfo.getIsEnable().equals("1") || !kqLeaveRulesComInfo.getBalanceEnable().equals("1")) { + continue; + } + createData(kqLeaveRulesComInfo.getId(), currentYear, 0, "", "1"); + + // createData(kqLeaveRulesComInfo.getId(), lastYear, 0, "", "1"); + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 批处理指定机构的指定假期的指定年份的假期余额 + * + * @param leaveRulesId 指定假期类型的ID(对应的是数据库表kq_LeaveRules的主键ID) + * @param belongYear 指定的所属年份(格式yyyy) + * @param organizationType 机构类型:0-总部、1-分部、2-部门 + * @param organizationIds 指定机构的ID(例如当机构类型为分部时,此为分部ID) + * @param operator 批处理的操作人员的人员ID(-1表示是系统定时任务自动批处理) + * @return false--批处理失败、true--批处理成功 + */ + public static boolean createData(String leaveRulesId, String belongYear, int organizationType, String organizationIds, String operator) { + return createData(leaveRulesId, belongYear, organizationType, organizationIds, operator, false); + } + + /** + * 批处理指定机构的指定假期的指定年份的假期余额 + * + * @param ruleId 指定假期类型的ID(对应的是数据库表kq_LeaveRules的主键ID) + * @param belongYear 指定的所属年份(格式yyyy) + * @param organizationType 机构类型:0-总部、1-分部、2-部门 + * @param organizationIds 指定机构的ID(例如当机构类型为分部时,此为分部ID) + * @param operator 批处理的操作人员的人员ID(-1表示是系统定时任务自动批处理) + * @param canUpdate 是否按照规则更新员工的假期余额基数 + * 因为员工的假期基数可以编辑,会出现和规则计算得出的值不一致的情况,只有当假期规则发生变动的情况时,才会按照最新的规则更新员工的假期基数 + * @return false--批处理失败、true--批处理成功 + */ + public static boolean createData(String ruleId, String belongYear, int organizationType, String organizationIds, String operator, boolean canUpdate) { + boolean isSuccess = true; + try { + //假期类型缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + //最小请假单位:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假 + String minimumUnit = rulesComInfo.getMinimumUnit(ruleId); + //假期类型的标识 + String leaveCode = rulesComInfo.getLeaveCode(ruleId); + + //假期规则缓存类 + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //假期规则的ID + String rulesDetailId = ""; + //余额发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放、7-按司龄自动发放(入职日期当天发放余额) + int distributionMode = 1; + //每人发放小时(天)数(当余额发放方式为每年自动发放固定天数时有效) + double annualAmount = 0; + //法定年假规则(当distributionMode=6时有效):0-工龄、1-司龄、2-工龄+司龄 + int legalKey = 0; + //福利年假规则(当distributionMode=6时有效):0-工龄、1-司龄、2-工龄+司龄 + int welfareKey = 1; + //年假基数计算方式: + // 0-假期基数发放日期和假期基数变动日期均为每年的01月01号(但是假期基数是结合 司龄/工龄 变化前后的值按天数比例折算出来的)、 + // 1-假期基数发放日期和假期基数变动日期均为每年的01月01号、 + // 2-假期基数发放日期发放日期为每年的01月01号,假期基数的变动日期为每年的 入职日期/参加工作日期 + int calcMethod = 0; + //假期基数的折算方式 + int convertMode = 0; + + //多孩叠加开关。 + int severalChildren = 0; + + //孩子多少周岁前发放。默认3岁 + int yearsOld = 3; + + int validityRule = 1; + + //是否按照省份发放育儿假。1否,2是 + String isprovince = "1"; + + //假期基数的小数位数 + int decimalDigit = 2; + //次账号是否能享受此假期:0-排除,即次账号不能享受此假期、1-不排除,即次账号正常享受此假期 + int excludeSubAccount = 1; + //转正之前是否能享受此假期:0-不允许、1-允许 + int beforeFormal = 1; + + //假期基数 + double baseAmount = 0.00; + //福利年假(当distributionMode=6时才有作用) + double baseAmount2 = 0.00; + //系统内原来的假期基数的合集 + Map oldBalanceEntities = getBalanceEntities(organizationType, organizationIds, ruleId, belongYear); + //员工假期余额实体类 + KQBalanceOfLeaveEntity oldBalanceEntity = null; + //此次批处理新计算的假期基数的合集 + List newBalanceEntities = new ArrayList(); + //员工假期余额实体类 + KQBalanceOfLeaveEntity newBalanceEntity = null; + // + Map params = null; + //今天的日期 + String currentDate = DateUtil.getCurrentDate(); + + ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo(); + //是否开启了人力资源模块的管理分权 + boolean isUseHrmManageDetach = manageDetachComInfo.isUseHrmManageDetach(); + + boolean addOrUpdate = false; + String expirationDate =DateUtil.getCurrentDate(); + String effectiveDate =""; + String belongYearTemp = belongYear; + String belongYearNew =""; + + String sql = " select * from HrmResource where status in (0,1,2,3) "; + if (organizationType == 1) { + sql += " and subCompanyId1 in (" + organizationIds + ") "; + } else if (organizationType == 2) { + sql += " and departmentId in (" + organizationIds + ") "; + } else if (organizationType == 3) { + sql += " and id in (" + organizationIds + ") "; + } + //如果开启了分权 + if (isUseHrmManageDetach) { + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + String allRightSubComIds = subCompanyComInfo.getRightSubCompany(Util.getIntValue(operator,1),"KQLeaveRulesEdit:Edit",0); + //机构权限只读的情况下,下面的allRightSubComIds是为空的,导致where会拼上一个 and (),导致sql报错 + if(Util.null2String(allRightSubComIds).length()>0){ + sql += " and " + Util.getSubINClause(allRightSubComIds, "subCompanyId1", "in"); + }else{//机构权限只读的情况下。就不让批处理 + sql += " and 1=2 "; + } + + } else { + if (!operator.equals("1")) { + User user = new User(Util.getIntValue(operator)); + String rightLevel = HrmUserVarify.getRightLevel("KQLeaveRulesEdit:Edit", user); + int departmentID = user.getUserDepartment(); + int subcompanyID = user.getUserSubCompany1(); + + if (rightLevel.equals("2")) { + // 总部级别的,什么也不返回 + } else if (rightLevel.equals("1")) { // 分部级别的 + sql += " and subCompanyId1=" + subcompanyID; + } else if (rightLevel.equals("0")) { // 部门级别 + sql += " and departmentId=" + departmentID; + } + } + } + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + while (recordSet.next()) { + /*获取人员的相关信息 start*/ + String resourceId = recordSet.getString("id"); + String accountType = Util.null2String(recordSet.getString("accountType")); + String status = Util.null2String(recordSet.getString("status")); + String createDate = Util.null2String(recordSet.getString("createDate")); + String workStartDate = Util.null2String(recordSet.getString("workStartDate")); + String companyStartDate = Util.null2String(recordSet.getString("companyStartDate")); + //如果参加工作日期为空,则默认采用创建日期 + workStartDate = (workStartDate.equals("")||workStartDate.length()<10||workStartDate.indexOf("-")<=0) ? createDate : workStartDate; + //如果入职日期为空,则默认采用创建日期 + companyStartDate = (companyStartDate.equals("")||companyStartDate.length()<10||companyStartDate.indexOf("-")<=0) ? createDate : companyStartDate; + String subCompanyId = Util.null2String(recordSet.getString("subCompanyId1")); + String departmentId = Util.null2String(recordSet.getString("departmentId")); + String locationid = Util.null2String(recordSet.getString("locationid")); + /*获取人员的相关信息 end*/ + + /*获取人员所属分部对应的假期规则 start*/ + rulesDetailId = detailComInfo.getId(ruleId, subCompanyId, departmentId, resourceId); + distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subCompanyId, departmentId, resourceId), 1); + legalKey = Util.getIntValue(detailComInfo.getLegalKey(ruleId, subCompanyId, departmentId, resourceId), 0); + welfareKey = Util.getIntValue(detailComInfo.getWelfareKey(ruleId, subCompanyId, departmentId, resourceId), 1); + annualAmount = Util.getDoubleValue(detailComInfo.getAnnualAmount(ruleId, subCompanyId, departmentId, resourceId), 0.00); + calcMethod = Util.getIntValue(detailComInfo.getCalcMethod(ruleId, subCompanyId, departmentId, resourceId), 0); + convertMode = Util.getIntValue(detailComInfo.getConvertMode(ruleId, subCompanyId, departmentId, resourceId), 0); + decimalDigit = Util.getIntValue(detailComInfo.getDecimalDigit(ruleId, subCompanyId, departmentId, resourceId), 2); + excludeSubAccount = Util.getIntValue(detailComInfo.getExcludeSubAccount(ruleId, subCompanyId, departmentId, resourceId), 1); + beforeFormal = Util.getIntValue(detailComInfo.getBeforeFormal(ruleId, subCompanyId, departmentId, resourceId), 1); + severalChildren = StringUtil.parseToInt(detailComInfo.getSeveralChildren(ruleId, subCompanyId, departmentId, resourceId), 0); + yearsOld = StringUtil.parseToInt(detailComInfo.getYearsOld(ruleId, subCompanyId, departmentId, resourceId), 0); + isprovince = Util.null2s(detailComInfo.getIsProvince(ruleId, subCompanyId, departmentId, resourceId), "1"); + validityRule = Util.getIntValue(detailComInfo.getValidityRule(ruleId, subCompanyId,departmentId,resourceId)); + + /*获取人员所属分部对应的假期规则 end*/ + + //封装参数 start + params = new HashMap(); + params.put("resourceId", resourceId); + params.put("status", status); + params.put("createDate", createDate); + params.put("workStartDate", workStartDate); + params.put("companyStartDate", companyStartDate); + params.put("subCompanyId", subCompanyId); + + params.put("belongYear", belongYear); + params.put("rulesDetailId", rulesDetailId); + params.put("distributionMode", distributionMode); + params.put("annualAmount", annualAmount); + params.put("legalKey", legalKey); + params.put("welfareKey", welfareKey); + params.put("calcMethod", calcMethod); + params.put("convertMode", convertMode); + params.put("decimalDigit", decimalDigit); + params.put("excludeSubAccount", excludeSubAccount); + params.put("beforeFormal", beforeFormal); + // qc + params.put("operator", operator); + params.put("ruleId", ruleId); + //封装参数 end + + if (distributionMode == 1) { + continue; + } else if (distributionMode == 2 || distributionMode == 3) { + baseAmount = getBaseAmount(params); + } else if (distributionMode == 4) { + baseAmount = getBaseAmountByDis4(params); + } else if (distributionMode == 5) { + continue; + } else if (distributionMode == 6) { + params.put("legalOrWelfare", "legal"); + baseAmount = getBaseAmountByDis6(params); + params.put("legalOrWelfare", "welfare"); + baseAmount2 = getBaseAmountByDis6(params); + } else if (distributionMode == 7) { + baseAmount = getBaseAmountByDis7(params); + } else if (distributionMode == 8) { + params.put("validityRule", validityRule); + if(isprovince.equals("2")){ + getChildrenProvinceId(rulesDetailId,locationid,params); + }else{ + params.put("yearsOld",yearsOld); + } + if (severalChildren==0) { + Map baseAmountMaps = getBaseAmountByDis8(params); + baseAmount = (Double) baseAmountMaps.get("baseAmount"); + addOrUpdate = (boolean) baseAmountMaps.get("addOrUpdate"); + expirationDate = (String) baseAmountMaps.get("expirationDate"); + effectiveDate = (String) baseAmountMaps.get("effectiveDate"); + belongYearNew = (String) baseAmountMaps.get("belongYearNew"); + //这个是去年,育儿假有今年去更新去年的情况,所以对这个所属年份赋值。 + if (addOrUpdate && !belongYearNew.equals("")) { + belongYear = belongYearNew; + } + } else { + getBaseAmountByDis8Num(params); + continue; + } + } + if (beforeFormal == 0 && !status.equals("1")) { + //转正前不允许发放余额 + if (canUpdate) { + baseAmount = 0; + baseAmount2 = 0; + } else { + continue; + } + } + if (excludeSubAccount == 0 && accountType.equals("1")) { + //次账号不允许发放余额 + if (canUpdate) { + baseAmount = 0; + baseAmount2 = 0; + } else { + continue; + } + } + + oldBalanceEntity = (KQBalanceOfLeaveEntity) oldBalanceEntities.get(resourceId); + if (oldBalanceEntity != null) { + //如果假期基数没有发生变化,不需要更新 + if (!addOrUpdate&&oldBalanceEntity.getBaseAmount() == baseAmount && oldBalanceEntity.getBaseAmount2() == baseAmount2) { + continue; + } + //如果是系统自动批处理(默认系统自动批处理不允许修改假期余额基数) + if (!canUpdate) { + if (distributionMode == 8) { + + if (oldBalanceEntity.getExtraAmount() > 0 || oldBalanceEntity.getUsedAmount() > 0) { + if (!addOrUpdate) { + if(resourceId.equals("3858")){ + new BaseBean().writeLog("人员id3858:ExtraAmount="+oldBalanceEntity.getExtraAmount()+ + ";UsedAmount="+ oldBalanceEntity.getUsedAmount() + ); + } + continue; + } + } + } + if (distributionMode != 8&&(oldBalanceEntity.getBaseAmount() > 0 || oldBalanceEntity.getExtraAmount() > 0 || oldBalanceEntity.getUsedAmount() > 0 + || oldBalanceEntity.getBaseAmount2() > 0 + || oldBalanceEntity.getExtraAmount2() > 0 || oldBalanceEntity.getUsedAmount2() > 0)) { + if (calcMethod == 2) { + //但是如果【假期基数计算方式】选择【按最多的计算】时,允许在【工龄or司龄变动日期】更新假期基数 + if (distributionMode == 2) { + String ageLimitChangeDate = belongYear + companyStartDate.substring(4); + if (currentDate.compareTo(ageLimitChangeDate) < 0) { + continue; + } + } else if (distributionMode == 3) { + String ageLimitChangeDate = belongYear + workStartDate.substring(4); + if (currentDate.compareTo(ageLimitChangeDate) < 0) { + continue; + } + } else if (distributionMode == 6) { + String ageLimitChangeDate = belongYear + workStartDate.substring(4); + String ageLimitChangeDate2 = belongYear + companyStartDate.substring(4); + if (currentDate.compareTo(ageLimitChangeDate) < 0 && currentDate.compareTo(ageLimitChangeDate2) < 0) { + continue; + } + } + } else { + if (distributionMode == 6) { + String ageLimitChangeDate = belongYear + workStartDate.substring(4); + String ageLimitChangeDate2 = belongYear + companyStartDate.substring(4); + if (currentDate.compareTo(ageLimitChangeDate) < 0 && currentDate.compareTo(ageLimitChangeDate2) < 0) { + continue; + } + }else{ + if(!addOrUpdate){ + continue; + } + } + } + } + } + } else { + //如果没有生成过假期余额,但是此次生成的假期余额如果为0,则不新增,直接跳过 + if (baseAmount == 0 && baseAmount2 == 0) { + continue; + } + } + + newBalanceEntity = new KQBalanceOfLeaveEntity(); + newBalanceEntity.setResourceId(Util.getIntValue(resourceId)); + newBalanceEntity.setLeaveRulesId(Util.getIntValue(ruleId)); + newBalanceEntity.setBelongYear(belongYear); + newBalanceEntity.setBaseAmount(baseAmount); + newBalanceEntity.setBaseAmount2(baseAmount2); + newBalanceEntity.setEffectiveDate(effectiveDate); + newBalanceEntity.setExpirationDate(expirationDate); + newBalanceEntity.setMinimumUnit(Util.getIntValue(minimumUnit)); + if(addOrUpdate){ + newBalanceEntity.setUsedAmount(baseAmount); + newBalanceEntity.setExtraAmount(baseAmount); + newBalanceEntity.setStatus(1); + }else{ + newBalanceEntity.setStatus(0); + } + newBalanceEntities.add(newBalanceEntity); + belongYear = belongYearTemp; + } + isSuccess = insertOrUpdateBalance(newBalanceEntities, oldBalanceEntities, operator, canUpdate); + } catch (Exception e) { + e.printStackTrace(); + } + return isSuccess; + } + + /** + * 获取指定机构下的人员的假期余额 + * + * @param organizationType 指定机构类型:0-总部、1-分部、2-部门、3-热力资源 + * @param organizationIds 指定机构的ID,用英文逗号分隔 + * @param ruleId 假期类型的ID + * @param belongYear 所属年份 + * @return + */ + private static Map getBalanceEntities(int organizationType, String organizationIds, String ruleId, String belongYear) { + Map balanceEntities = new HashMap(); + try { + KQBalanceOfLeaveEntity balanceEntity = null; + + //假期类型缓存类 + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + //最小请假单位:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假 + String minimumUnit = rulesComInfo.getMinimumUnit(ruleId); + + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_BalanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId=" + ruleId + " and belongYear=" + belongYear; + if (organizationType == 1) { + sql += " and resourceId in (select id from HrmResource where subCompanyId1 in (" + organizationIds + "))"; + } else if (organizationType == 2) { + sql += " and resourceId in (select id from HrmResource where departmentId in (" + organizationIds + "))"; + } else if (organizationType == 3) { + sql += " and resourceId in (" + organizationIds + ")"; + } + recordSet.executeQuery(sql); + while (recordSet.next()) { + int id = recordSet.getInt("id"); + int resourceId = recordSet.getInt("resourceId"); + int leaveRuleId = recordSet.getInt("leaveRulesId"); + double baseAmount = Util.getDoubleValue(recordSet.getString("baseAmount"), 0.00); + double extraAmount = Util.getDoubleValue(recordSet.getString("extraAmount"), 0.00); + double usedAmount = Util.getDoubleValue(recordSet.getString("usedAmount"), 0.00); + double baseAmount2 = Util.getDoubleValue(recordSet.getString("baseAmount2"), 0.00); + double extraAmount2 = Util.getDoubleValue(recordSet.getString("extraAmount2"), 0.00); + double usedAmount2 = Util.getDoubleValue(recordSet.getString("usedAmount2"), 0.00); + + balanceEntity = new KQBalanceOfLeaveEntity(); + balanceEntity.setId(id); + balanceEntity.setResourceId(resourceId); + balanceEntity.setBelongYear(belongYear); + balanceEntity.setLeaveRulesId(leaveRuleId); + balanceEntity.setBaseAmount(baseAmount); + balanceEntity.setExtraAmount(extraAmount); + balanceEntity.setUsedAmount(usedAmount); + balanceEntity.setBaseAmount2(baseAmount2); + balanceEntity.setExtraAmount2(extraAmount2); + balanceEntity.setUsedAmount2(usedAmount2); + balanceEntity.setMinimumUnit(Util.getIntValue(minimumUnit)); + + balanceEntities.put("" + resourceId, balanceEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return balanceEntities; + } + + /** + * 获取指定人员的指定假期的指定年份的假期基数发放日期 + * + * @param resourceId 指定人员的人员ID + * @param ruleId 指定假期类型的ID + * @param belongYear 指定年份 + * @return + */ + private static Calendar getReleaseDate(String resourceId, String ruleId, String belongYear) { + Calendar calendar = null; + try { + //人员缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //分部ID + String subcompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + + //创建日期 + String createDate = resourceComInfo.getCreatedate(resourceId); + //入职日期 + String companyStartDate = resourceComInfo.getCompanyStartDate(resourceId); + //没有维护入职日期时取创建日期 + companyStartDate = companyStartDate.equals("") ? createDate : companyStartDate; + //参加工作日期 + String workStartDate = resourceComInfo.getWorkStartDate(resourceId); + //没有维护参加工作日期时取创建日期 + workStartDate = workStartDate.equals("") ? createDate : workStartDate; + + /**********************************************************************************************************/ + + //假期规则的缓存类 + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //假期规则的ID + String rulesDetailId = Util.null2String(detailComInfo.getId(ruleId, subcompanyId, departmentId, resourceId)); + //余额发放方式 + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subcompanyId, departmentId, resourceId), 1); + //年假基数计算方式: + // 0-假期基数发放日期和假期基数变动日期均为每年的01月01号(但是假期基数是结合 司龄/工龄 变化前后的值按天数比例折算出来的)、 + // 1-假期基数发放日期和假期基数变动日期均为每年的01月01号、 + // 2-假期基数发放日期发放日期为每年的01月01号,假期基数的变动日期为每年的 入职日期/参加工作日期 + int calcMethod = Util.getIntValue(detailComInfo.getCalcMethod(ruleId, subcompanyId, departmentId, resourceId), 1); + + /***********************************************************************************************************/ + + //假期基数发放日期 + String baseAmountReleaseDate = ""; + //工龄or司令的变动日期 + String ageLimitChangeDate = ""; + //入职日期or参加工作日期 + String date4CalcAgeLimit = ""; + if (distributionMode == 1) { + baseAmountReleaseDate = belongYear + "-01-01"; + //默认情况下都是以【假期基数发放日期】作为释放的开始日期 + calendar = DateUtil.getCalendar(baseAmountReleaseDate); + //如果批处理年份等于入职年份,应该以入职日期作为释放的开始日期 + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(companyStartDate); + } + return calendar; + } else if (distributionMode == 2) { + date4CalcAgeLimit = companyStartDate; + //根据假期基数的计算方式得出【假期基数发放日期】、【入职年限/参加工作年限 的变动日期】 + if (calcMethod == 0 || calcMethod == 1) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + companyStartDate.substring(4); + } else if (calcMethod == 2) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + companyStartDate.substring(4); + } + } else if (distributionMode == 3) { + date4CalcAgeLimit = workStartDate; + //根据假期基数的计算方式得出【假期基数发放日期】、【入职年限/参加工作年限 的变动日期】 + if (calcMethod == 0 || calcMethod == 1) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + workStartDate.substring(4); + } else if (calcMethod == 2) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + workStartDate.substring(4); + } + } else if (distributionMode == 4) { + baseAmountReleaseDate = belongYear + "-01-01"; + //默认情况下都是以【假期基数发放日期】作为释放的开始日期 + calendar = DateUtil.getCalendar(baseAmountReleaseDate); + //如果批处理年份等于入职年份,应该以入职日期作为释放的开始日期 + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(companyStartDate); + } + return calendar; + } + + //人员在【假期基数发放日期】时对应的【工龄or司龄】 + int ageLimit = getAgeLimit(date4CalcAgeLimit, baseAmountReleaseDate); + //人员在【假期基数发放日期】时应有的【假期基数】 + BigDecimal baseAmount_releaseDate = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit, -1, -1, -1, ""); + + //人员在【工龄or司龄变动日期】时对应的【工龄or司龄】 + int ageLimit_ageLimitChangeDate = getAgeLimit(date4CalcAgeLimit, ageLimitChangeDate); + //人员在【工龄or司龄变动日期】时应有的【假期基数】 + BigDecimal baseAmount_ageLimitChangeDate = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit_ageLimitChangeDate, -1, -1, -1, ""); + + //默认情况下都是以【假期基数发放日期】作为释放的开始日期 + calendar = DateUtil.getCalendar(baseAmountReleaseDate); + //如果批处理年份等于入职年份,应该以入职日期作为释放的开始日期 + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(companyStartDate); + } + //如果是初始获得年(即年初01-01的时候假期基数为0,但是后面工龄or司龄增加后,假期基数就不再为0了)。应该以【工龄or司龄变动日期】作为释放的开始日期 + if (baseAmount_releaseDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate.doubleValue() > 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDate); + //比如:参加工作日是:2020-02-01,入职日期是:2021-08-16,没有该处理会按:2021-02-01给用户计算“已释放”数值 + if(belongYear.compareTo(companyStartDate.substring(0, 4)) == 0 && ageLimitChangeDate.compareTo(companyStartDate)<0){ + calendar = DateUtil.getCalendar(companyStartDate); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return calendar; + } + + /** + * [6-按司龄+工龄自动发放]获取指定人员的指定假期的指定年份的假期基数发放日期 + * + * @param resourceId 指定人员的人员ID + * @param ruleId 指定假期类型的ID + * @param belongYear 指定年份 + * @param legalOrWelfare 是计算[法定年假]还是计算[福利年假]:legal-法定年假、welfare-福利年假 + * @return + */ + private static Calendar getReleaseDateByDis6(String resourceId, String ruleId, String belongYear, String legalOrWelfare) { + Calendar calendar = null; + try { + //人员缓存类 + ResourceComInfo resourceComInfo = new ResourceComInfo(); + //分部ID + String subCompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + //创建日期 + String createDate = resourceComInfo.getCreatedate(resourceId); + //入职日期 + String companyStartDate = resourceComInfo.getCompanyStartDate(resourceId); + //没有维护入职日期时取创建日期 + companyStartDate = companyStartDate.equals("") ? createDate : companyStartDate; + //参加工作日期 + String workStartDate = resourceComInfo.getWorkStartDate(resourceId); + //没有维护参加工作日期时取创建日期 + workStartDate = workStartDate.equals("") ? createDate : workStartDate; + + /***********************************************************************************************************/ + + //假期规则的缓存类 + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + //假期规则的ID + String rulesDetailId = Util.null2String(detailComInfo.getId(ruleId, subCompanyId, departmentId, resourceId)); + //余额发放方式 + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subCompanyId, departmentId, resourceId), 1); + //年假基数计算方式: + // 0-假期基数发放日期和假期基数变动日期均为每年的01月01号(但是假期基数是结合 司龄/工龄 变化前后的值按天数比例折算出来的)、 + // 1-假期基数发放日期和假期基数变动日期均为每年的01月01号、 + // 2-假期基数发放日期发放日期为每年的01月01号,假期基数的变动日期为每年的 入职日期/参加工作日期 + int calcMethod = Util.getIntValue(detailComInfo.getCalcMethod(ruleId, subCompanyId, departmentId, resourceId), 1); + // + int legalKey = Util.getIntValue(detailComInfo.getLegalKey(ruleId, subCompanyId, departmentId, resourceId), 0); + // + int welfareKey = Util.getIntValue(detailComInfo.getWelfareKey(ruleId, subCompanyId, departmentId, resourceId), 1); + + /***********************************************************************************************************/ + + //假期基数发放日期 + String baseAmountReleaseDate = ""; + //工龄变动日期 + String ageLimitChangeDate = ""; + //司龄变动日期 + String ageLimitChangeDate2 = ""; + //根据假期基数的计算方式得出【假期基数发放日期】、【假期基数变动日期】、【工龄变动日期】、【司龄变动日期】 + if (calcMethod == 0 || calcMethod == 1) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + workStartDate.substring(4); + ageLimitChangeDate2 = belongYear + companyStartDate.substring(4); + } else if (calcMethod == 2) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + workStartDate.substring(4); + ageLimitChangeDate2 = belongYear + companyStartDate.substring(4); + } + + //人员在【假期基数发放日期】时对应的工龄 + int ageLimit_releaseDate = getAgeLimit(workStartDate, baseAmountReleaseDate); + //人员在【假期基数发放日期】时对应的司龄 + int ageLimit2_releaseDate = getAgeLimit(companyStartDate, baseAmountReleaseDate); + //人员在【假期基数发放日期】时对应的假期基数 + BigDecimal baseAmount_releaseDate = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit_releaseDate, ageLimit2_releaseDate, legalKey, welfareKey, legalOrWelfare); + + //人员在【工龄变动日期】时对应的工龄 + int ageLimit_ageLimitChangeDate = getAgeLimit(workStartDate, ageLimitChangeDate); + //人员在【工龄变动日期】时对应的司龄 + int ageLimit2_ageLimitChangeDate = getAgeLimit(companyStartDate, ageLimitChangeDate); + //人员在【工龄变动日期】时对应的假期基数 + BigDecimal baseAmount_ageLimitChangeDate = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit_ageLimitChangeDate, ageLimit2_ageLimitChangeDate, legalKey, welfareKey, legalOrWelfare); + + //人员在【司龄变动日期】时对应的司龄 + int ageLimit_ageLimitChangeDate2 = getAgeLimit(workStartDate, ageLimitChangeDate2); + //人员在【司龄变动日期】时对应的司龄 + int ageLimit2_ageLimitChangeDate2 = getAgeLimit(companyStartDate, ageLimitChangeDate2); + //人员在【司龄变动日期】时对应的假期基数 + BigDecimal baseAmount_ageLimitChangeDate2 = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit_ageLimitChangeDate2, ageLimit2_ageLimitChangeDate2, legalKey, welfareKey, legalOrWelfare); + + //默认情况下都是以【假期基数发放日期】作为释放的开始日期 + calendar = DateUtil.getCalendar(baseAmountReleaseDate); + //如果批处理年份等于入职年份,应该以入职日期作为释放的开始日期 + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(companyStartDate); + } + //如果是初始获得年(即年初01-01的时候假期基数为0,但是后面工龄or司龄增加后,假期基数就不再为0了) + if (ageLimitChangeDate.compareTo(ageLimitChangeDate2) <= 0) { + if (baseAmount_releaseDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate.doubleValue() > 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDate); + } + if (baseAmount_releaseDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate2.doubleValue() > 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDate2); + } + } else { + if (baseAmount_releaseDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate2.doubleValue() > 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDate2); + } + if (baseAmount_releaseDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate2.doubleValue() <= 0 && baseAmount_ageLimitChangeDate.doubleValue() > 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDate2); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return calendar; + } + + /** + * 计算假期基数 + * + * @param params Map + * belongYear:所属年份 + * createDate:人员创建日期 + * workStartDate:参加工作日期 + * companyStartDate:入职日期 + * rulesDetailId:假期规则的ID + * distributionMode:当前假期规则发放方式 + * annualAmount:当[distributionMode]=[4-每年发放固定天数]时有效 + * legalKey:法定年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * welfareKey:福利年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * calcMethod:假期基数计算方式 + * convertMode:折算方式 + * decimalDigit:折算后的假期余额保留几位小数 + * @return + */ + private static double getBaseAmount(Map params) { + BigDecimal baseAmount = new BigDecimal("0"); + int decimalDigit = 2; + try { + //当前日期 + String currentDate = DateUtil.getCurrentDate(); + //当前年份 + String currentYear = currentDate.substring(0, 4); + //批处理年份 + String belongYear = Util.null2String(params.get("belongYear")); + //人员的参加工作日期 + String workStartDate = Util.null2String(params.get("workStartDate")); + //人员的入职日期 + String companyStartDate = Util.null2String(params.get("companyStartDate")); + + //假期规则的ID + String rulesDetailId = Util.null2String(params.get("rulesDetailId")); + //当前假期规则发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放 + int distributionMode = Util.getIntValue("" + params.get("distributionMode"), 1); + //当[distributionMode]=[4-每年发放固定天数]时有效 + double annualAmount = Util.getDoubleValue("" + params.get("annualAmount"), 0); + //法定年假规则(当distributionMode=6时有效):0-工龄、1-司龄、2-工龄+司龄 + int legalKey = Util.getIntValue("" + params.get("legalKey"), 0); + //福利年假规则(当distributionMode=6时有效):0-工龄、1-司龄、2-工龄+司龄 + int welfareKey = Util.getIntValue("" + params.get("welfareKey"), 1); + //年假基数计算方式: + // 0-假期基数发放日期和假期基数变动日期均为每年的01月01号(但是假期基数是结合 司龄/工龄 变化前后的值按天数比例折算出来的)、 + // 1-假期基数发放日期和假期基数变动日期均为每年的01月01号、 + // 2-假期基数发放日期发放日期为每年的01月01号,假期基数的变动日期为每年的 入职日期/参加工作日期 + int calcMethod = Util.getIntValue("" + params.get("calcMethod"), 1); + //假期基数发放日期 + String baseAmountReleaseDate = ""; + //假期基数变动日期 + String baseAmountChangeDate = ""; + //工龄or司龄的变动日期 + String ageLimitChangeDate = ""; + String ageLimitChangeDatetemp = ""; + //入职日期or参加工作日期 + String date4CalcAgeLimit = ""; + if (distributionMode == 2) { + date4CalcAgeLimit = companyStartDate; + //根据假期基数的计算方式得出【假期基数发放日期】、【假期基数变动日期】、【工龄or司龄的变动日期】 + if (calcMethod == 0 || calcMethod == 1) { + baseAmountReleaseDate = belongYear + "-01-01"; + baseAmountChangeDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + companyStartDate.substring(4); + } else if (calcMethod == 2) { + baseAmountReleaseDate = belongYear + "-01-01"; + baseAmountChangeDate = belongYear + companyStartDate.substring(4); + ageLimitChangeDate = belongYear + companyStartDate.substring(4); + } + } else if (distributionMode == 3) { + date4CalcAgeLimit = workStartDate; + //根据假期基数的计算方式得出【假期基数发放日期】、【假期基数变动日期】、【工龄or司龄的变动日期】 + if (calcMethod == 0 || calcMethod == 1) { + baseAmountReleaseDate = belongYear + "-01-01"; + baseAmountChangeDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + workStartDate.substring(4); + } else if (calcMethod == 2) { + baseAmountReleaseDate = belongYear + "-01-01"; + baseAmountChangeDate = belongYear + workStartDate.substring(4); + ageLimitChangeDate = belongYear + workStartDate.substring(4); + } + //如果是初始获得年,那么,入职日期和参加工作日期,取相对较晚的日期,作为变动日期 + if(companyStartDate.substring(4).compareTo(workStartDate.substring(4)) <= 0){ + ageLimitChangeDatetemp = belongYear + workStartDate.substring(4); + }else{ + ageLimitChangeDatetemp = belongYear + companyStartDate.substring(4); + } + } + + //批处理日期(因为存在当前年份批处理上一年份或者批处理下一年份,所以需要做一些特殊处理) + String date4CalcAmount = ""; + if (belongYear.compareTo(currentYear) < 0) { + date4CalcAmount = belongYear + "-12-31"; + } else if (belongYear.compareTo(currentYear) == 0) { + date4CalcAmount = currentDate; + } else { + date4CalcAmount = baseAmountReleaseDate; + } + //折算方式 + int convertMode = Util.getIntValue("" + params.get("convertMode"), 0); + //折算后的假期余额保留几位小数 + decimalDigit = Util.getIntValue("" + params.get("decimalDigit"), 2); + + //人员在【假期基数发放日期】时对应的【工龄or司龄】 + int ageLimit = getAgeLimit(date4CalcAgeLimit, baseAmountReleaseDate); + //人员在【假期基数发放日期】时应有的【假期基数】 + BigDecimal baseAmount_releaseDate = getAmountByAgeLimit(distributionMode, rulesDetailId, annualAmount, ageLimit, -1, -1, -1, ""); + + //人员在【工龄or司龄变动日期】时对应的【工龄or司龄】 + int ageLimit_ageLimitChangeDate = getAgeLimit(date4CalcAgeLimit, ageLimitChangeDate); + //人员在【工龄or司龄变动日期】时应有的【假期基数】 + BigDecimal baseAmount_ageLimitChangeDate = getAmountByAgeLimit(distributionMode, rulesDetailId, annualAmount, ageLimit_ageLimitChangeDate, -1, -1, -1, ""); + + //如果人员在【假期基数发放日期】时对应的【假期基数】为0,并且【批处理日期】小于【工龄or司龄变动日期】,则假期基数应该是0 + if (baseAmount_releaseDate.doubleValue() <= 0 && date4CalcAmount.compareTo(ageLimitChangeDate) < 0) { + return 0; + } + + //如果【calcMethod】==0?假期基数按比例精确计算 + boolean needCalc0 = false; + //是否需要折算 + boolean needConvert = false; + //以哪个日期来折算 + Calendar calendar = null; + //入职前的假期基数应该为0 + if (date4CalcAmount.compareTo(companyStartDate) < 0) { + return 0; + } + //如果批处理年份等于入职年份,那应该以【入职日期】来折算 + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + //需要折算 + needConvert = true; + //以【入职日期来折算】 + calendar = DateUtil.getCalendar(companyStartDate); + } + /** + * 年假基数的计算方法如下: + * 第一种情况:工龄or司龄的变动日期<假期基数发放日期<=假期基数变动日期 + * 批处理日期<假期基数发放日期?假期基数=0 + * 批处理日期>=假期基数基数发放日期?根据假期基数发放日期计算工龄or司龄,然后得出对应的假期基数 + * 第二种情况:假期基数发放日期<=工龄or司龄的变动日期<=假期基数变动日期 + * 批处理日期<假期基数发放日期?假期基数=0 + * 批处理日期=假期基数发放日期?根据假期基数发放日期计算工龄or司龄,然后得出对应的假期基数 + * 批处理日期>假期基数发放日期 && 批处理日期<工龄or司龄的变动日期?根据假期基数发放日期计算工龄or司龄,然后得出对应的假期基数 + * 批处理日期>假期基数发放日期 && 批处理日期>=工龄or司龄的变动日期? + * 如果是初始获得年(即年初01-01的时候假期基数为0,但是后面工龄or司龄增加后,假期基数就不再为0了)?根据【工龄or司龄的变动日期】计算工龄or司龄,然后得出对应的假期基数。此处得到的假期基数需要折算) + * 如果不是初始获得年?批处理日期>=假期基数变动日期?根据【工龄or司龄的变动日期】计算工龄or司龄,然后得出对应的假期基数。此处得到的假期基数不需要折算 + * 第三种情况:假期基数发放日期<假期基数变动日期<工龄or司龄的变动日期 + * 批处理日期<假期基数发放日期?假期基数=0 + * 批处理日期=假期基数发放日期? + * 如果【calcMethod】!=0?根据假期基数发放日期计算工龄or司龄,然后得出对应的假期基数 + * 如果【calcMethod】==0?假期基数按比例精确计算 + * 批处理日期>假期基数发放日期 && 批处理日期<工龄or司龄的变动日期? + * 如果【calcMethod】!=0?根据假期基数发放日期计算工龄or司龄,然后得出对应的假期基数 + * 如果【calcMethod】==0?假期基数按比例精确计算 + * 批处理日期>假期基数发放日期 && 批处理日期>=工龄or司龄的变动日期? + * 如果是初始获得年?根据【工龄or司龄的变动日期】计算工龄or司龄,然后得出对应的假期基数。此处得到的假期基数需要折算 + * 如果不是初始获得年? + * 如果【calcMethod】!=0?根据假期基数发放日期计算工龄or司龄,然后得出对应的假期基数 + * 如果【calcMethod】==0?假期基数按比例精确计算 + */ + if (ageLimitChangeDate.compareTo(baseAmountReleaseDate) < 0 && baseAmountReleaseDate.compareTo(baseAmountChangeDate) <= 0) { + if (date4CalcAmount.compareTo(baseAmountReleaseDate) < 0) { + return 0; + } else if (date4CalcAmount.compareTo(baseAmountReleaseDate) >= 0) { + baseAmount = baseAmount_releaseDate; + } + } else if (baseAmountReleaseDate.compareTo(ageLimitChangeDate) <= 0 && ageLimitChangeDate.compareTo(baseAmountChangeDate) <= 0) { + if (date4CalcAmount.compareTo(baseAmountReleaseDate) < 0) { + return 0; + } else if (date4CalcAmount.compareTo(baseAmountReleaseDate) == 0) { + baseAmount = baseAmount_releaseDate; + } else { + if (date4CalcAmount.compareTo(ageLimitChangeDate) < 0) { + baseAmount = baseAmount_releaseDate; + } else if (date4CalcAmount.compareTo(ageLimitChangeDate) >= 0) { + baseAmount = baseAmount_releaseDate; + if (baseAmount_releaseDate.doubleValue() <= 0) { + needConvert = true; + //如果是当年入职,则按照【入职日期折算】 + if (distributionMode == 3&&belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDatetemp); + }else{ + calendar = DateUtil.getCalendar(ageLimitChangeDate); + } + + baseAmount = baseAmount_ageLimitChangeDate; + } else { + if (date4CalcAmount.compareTo(baseAmountChangeDate) >= 0) { + baseAmount = baseAmount_ageLimitChangeDate; + } + } + } + } + } else if (baseAmountReleaseDate.compareTo(baseAmountChangeDate) <= 0 && baseAmountChangeDate.compareTo(ageLimitChangeDate) < 0) { + if (date4CalcAmount.compareTo(baseAmountReleaseDate) < 0) { + return 0; + } else if (date4CalcAmount.compareTo(baseAmountReleaseDate) == 0) { + baseAmount = baseAmount_releaseDate; + if (calcMethod == 0) { + needCalc0 = true; + } + } else { + if (date4CalcAmount.compareTo(ageLimitChangeDate) < 0) { + baseAmount = baseAmount_releaseDate; + if (calcMethod == 0) { + needCalc0 = true; + } + } else if (date4CalcAmount.compareTo(ageLimitChangeDate) >= 0) { + baseAmount = baseAmount_releaseDate; + if (baseAmount_releaseDate.doubleValue() <= 0) { + needConvert = true; + //如果是当年入职,则按照【入职日期折算】 + if (distributionMode == 3&&belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDatetemp); + }else{ + calendar = DateUtil.getCalendar(ageLimitChangeDate); + } + + baseAmount = baseAmount_ageLimitChangeDate; + } else if (calcMethod == 0) { + needCalc0 = true; + } + } + } + } + + if (needCalc0) { + baseAmount = baseAmount_releaseDate; + + Calendar _calendar1 = DateUtil.getCalendar(baseAmountReleaseDate); + BigDecimal _dayOfYear1 = new BigDecimal("" + (_calendar1.get(Calendar.DAY_OF_YEAR) - 1)); + BigDecimal _actualMaximum = new BigDecimal("" + _calendar1.getActualMaximum(Calendar.DAY_OF_YEAR)); + + Calendar _calendar2 = DateUtil.getCalendar(ageLimitChangeDate); + BigDecimal _dayOfYear2 = new BigDecimal("" + (_calendar2.get(Calendar.DAY_OF_YEAR) - 1)); + + baseAmount = (baseAmount_releaseDate.multiply(_dayOfYear2.subtract(_dayOfYear1)) + .add(baseAmount_ageLimitChangeDate.multiply(_actualMaximum.subtract(_dayOfYear2)))) + .divide(_actualMaximum.subtract(_dayOfYear1), decimalDigit, RoundingMode.HALF_UP); + + if (convertMode == 0) { + if (date4CalcAmount.compareTo(baseAmountReleaseDate) >= 0) { + baseAmount = baseAmount_releaseDate.setScale(decimalDigit, RoundingMode.HALF_UP); + } + if (date4CalcAmount.compareTo(baseAmountChangeDate) >= 0) { + baseAmount = baseAmount_ageLimitChangeDate.setScale(decimalDigit, RoundingMode.HALF_UP); + } + } else if (convertMode == 1) { + baseAmount = baseAmount; + } else if (convertMode == 2) { + baseAmount = baseAmount.setScale(0, RoundingMode.UP); + } else if (convertMode == 3) { + baseAmount = baseAmount.setScale(0, RoundingMode.DOWN); + } else if (convertMode == 4) { + baseAmount = baseAmount.divide(new BigDecimal("0.5"), 0, RoundingMode.UP).multiply(new BigDecimal("0.5")); + } else if (convertMode == 5) { + baseAmount = baseAmount.divide(new BigDecimal("0.5"), 0, RoundingMode.DOWN).multiply(new BigDecimal("0.5")); + } + } + + if (needConvert) { + //这一年一共有多少天 + BigDecimal actualMaximum = new BigDecimal("" + calendar.getActualMaximum(Calendar.DAY_OF_YEAR)); + //年假变动日期是这一天的第几天 + BigDecimal dayOfYear = new BigDecimal("" + (calendar.get(Calendar.DAY_OF_YEAR) - 1)); + + if (convertMode == 0) { + baseAmount = baseAmount; + } else if (convertMode == 1) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, decimalDigit, RoundingMode.HALF_UP); + } else if (convertMode == 2) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, 0, RoundingMode.UP); + } else if (convertMode == 3) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, 0, RoundingMode.DOWN); + } else if (convertMode == 4) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum.multiply(new BigDecimal("0.5")), 0, RoundingMode.UP).multiply(new BigDecimal("0.5")); + } else if (convertMode == 5) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum.multiply(new BigDecimal("0.5")), 0, RoundingMode.DOWN).multiply(new BigDecimal("0.5")); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return baseAmount.setScale(decimalDigit, RoundingMode.HALF_UP).doubleValue(); + } + + /** + * [4-每年发放固定天数]计算假期基数 + * + * @param params Map + * belongYear:所属年份 + * createDate:人员创建日期 + * companyStartDate:入职日期 + * distributionMode:当前假期规则发放方式 + * annualAmount:当[distributionMode]=[4-每年发放固定天数]时有效 + * convertMode:折算方式 + * decimalDigit:折算后的假期余额保留几位小数 + * @return + */ + private static double getBaseAmountByDis4(Map params) { + BigDecimal baseAmount = new BigDecimal("0"); + int decimalDigit = 2; + try { + //当前日期 + String currentDate = DateUtil.getCurrentDate(); + //当前年份 + String currentYear = currentDate.substring(0, 4); + //批处理年份 + String belongYear = Util.null2String(params.get("belongYear")); + //人员的入职日期 + String companyStartDate = Util.null2String(params.get("companyStartDate")); + //当前假期规则发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放 + int distributionMode = Util.getIntValue("" + params.get("distributionMode"), 1); + //当[distributionMode]=[4-每年发放固定天数]时有效 + double annualAmount = Util.getDoubleValue("" + params.get("annualAmount"), 0); + //折算方式 + int convertMode = Util.getIntValue("" + params.get("convertMode"), 0); + //折算后的假期余额保留几位小数 + decimalDigit = Util.getIntValue("" + params.get("decimalDigit"), 2); + //批处理日期(因为存在当前年份批处理上一年份或者批处理下一年份,所以需要做一些特殊处理) + String date4CalcAmount = ""; + if (belongYear.compareTo(currentYear) < 0) { + date4CalcAmount = belongYear + "-12-31"; + } else if (belongYear.compareTo(currentYear) == 0) { + date4CalcAmount = currentDate; + } else { + date4CalcAmount = belongYear + "-01-01"; + } + if (distributionMode == 4) { + if (date4CalcAmount.compareTo(companyStartDate) < 0) { + return 0; + } + baseAmount = new BigDecimal("" + annualAmount); + //当批处理年份=入职年份时,需要折算 + if (!"".equals(companyStartDate) && belongYear.equals(companyStartDate.substring(0, 4))) { + //以入职日期来折算 + Calendar calendar = DateUtil.getCalendar(companyStartDate); + //这一年一共有多少天 + BigDecimal actualMaximum = new BigDecimal("" + calendar.getActualMaximum(Calendar.DAY_OF_YEAR)); + //年假变动日期是这一天的第几天 + BigDecimal dayOfYear = new BigDecimal("" + (calendar.get(Calendar.DAY_OF_YEAR) - 1)); + + if (convertMode == 0) { + baseAmount = baseAmount; + } else if (convertMode == 1) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, decimalDigit, RoundingMode.HALF_UP); + } else if (convertMode == 2) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, 0, RoundingMode.UP); + } else if (convertMode == 3) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, 0, RoundingMode.DOWN); + } else if (convertMode == 4) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum.multiply(new BigDecimal("0.5")), 0, RoundingMode.UP).multiply(new BigDecimal("0.5")); + } else if (convertMode == 5) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum.multiply(new BigDecimal("0.5")), 0, RoundingMode.DOWN).multiply(new BigDecimal("0.5")); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return baseAmount.setScale(decimalDigit, RoundingMode.HALF_UP).doubleValue(); + } + + /** + * [6-按司龄+工龄自动发放]计算假期基数 + * + * @param params Map + * belongYear:所属年份 + * createDate:人员创建日期 + * workStartDate:参加工作日期 + * companyStartDate:入职日期 + * rulesDetailId:假期规则的ID + * distributionMode:当前假期规则发放方式 + * legalKey:法定年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * welfareKey:福利年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * calcMethod:假期基数计算方式 + * convertMode:折算方式 + * decimalDigit:折算后的假期余额保留几位小数 + * @return + */ + private static double getBaseAmountByDis6(Map params) { + //法定年假 + BigDecimal baseAmount = new BigDecimal("0"); + int decimalDigit = 2; + try { + //当前日期 + String currentDate = DateUtil.getCurrentDate(); + //当前年份 + String currentYear = currentDate.substring(0, 4); + //批处理年份 + String belongYear = Util.null2String(params.get("belongYear")); + //人员的参加工作日期 + String workStartDate = Util.null2String(params.get("workStartDate")); + //人员的入职日期 + String companyStartDate = Util.null2String(params.get("companyStartDate")); + //假期规则的ID + String rulesDetailId = Util.null2String(params.get("rulesDetailId")); + //当前假期规则发放规则:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放 + int distributionMode = Util.getIntValue("" + params.get("distributionMode"), 1); + //法定年假规则(当distributionMode=6时有效):0-工龄、1-司龄、2-工龄+司龄 + int legalKey = Util.getIntValue("" + params.get("legalKey"), 0); + //福利年假规则(当distributionMode=6时有效):0-工龄、1-司龄、2-工龄+司龄 + int welfareKey = Util.getIntValue("" + params.get("welfareKey"), 1); + //年假基数计算方式: + // 0-假期基数发放日期和假期基数变动日期均为每年的01月01号(但是假期基数是结合 司龄/工龄 变化前后的值按天数比例折算出来的)、 + // 1-假期基数发放日期和假期基数变动日期均为每年的01月01号、 + // 2-假期基数发放日期发放日期为每年的01月01号,假期基数的变动日期为每年的 入职日期/参加工作日期 + int calcMethod = Util.getIntValue("" + params.get("calcMethod"), 1); + //假期基数发放日期 + String baseAmountReleaseDate = ""; + //工龄变动日期 + String ageLimitChangeDate = ""; + //司龄变动日期 + String ageLimitChangeDate2 = ""; + //根据假期基数的计算方式得出【假期基数发放日期】、【假期基数变动日期】、【工龄变动日期】、【司龄变动日期】 + if (calcMethod == 0 || calcMethod == 1) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + workStartDate.substring(4); + ageLimitChangeDate2 = belongYear + companyStartDate.substring(4); + } else if (calcMethod == 2) { + baseAmountReleaseDate = belongYear + "-01-01"; + ageLimitChangeDate = belongYear + workStartDate.substring(4); + ageLimitChangeDate2 = belongYear + companyStartDate.substring(4); + } + //批处理日期(因为存在当前年份批处理上一年份或者批处理下一年份,所以需要做一些特殊处理) + String date4CalcAmount = ""; + if (belongYear.compareTo(currentYear) < 0) { + date4CalcAmount = belongYear + "-12-31"; + } else if (belongYear.compareTo(currentYear) == 0) { + date4CalcAmount = currentDate; + } else { + date4CalcAmount = baseAmountReleaseDate; + } + //获取假期规则的【折算方式】 + int convertMode = Util.getIntValue("" + params.get("convertMode"), 0); + //获取假期规则的【假期余额小数位数】 + decimalDigit = Util.getIntValue("" + params.get("decimalDigit"), 2); + //是计算法定年假还是福利年假 + String legalOrWelfare = Util.null2String(params.get("legalOrWelfare")); + + //人员在【假期基数发放日期】时对应的工龄 + int ageLimit_releaseDate = getAgeLimit(workStartDate, baseAmountReleaseDate); + //人员在【假期基数发放日期】时对应的司龄 + int ageLimit2_releaseDate = getAgeLimit(companyStartDate, baseAmountReleaseDate); + //人员在【假期基数发放日期】时对应的假期基数 + BigDecimal baseAmount_releaseDate = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit_releaseDate, ageLimit2_releaseDate, legalKey, welfareKey, legalOrWelfare); + + //人员在【工龄变动日期】时对应的工龄 + int ageLimit_ageLimitChangeDate = getAgeLimit(workStartDate, ageLimitChangeDate); + //人员在【工龄变动日期】时对应的司龄 + int ageLimit2_ageLimitChangeDate = getAgeLimit(companyStartDate, ageLimitChangeDate); + //人员在【工龄变动日期】时对应的假期基数 + BigDecimal baseAmount_ageLimitChangeDate = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit_ageLimitChangeDate, ageLimit2_ageLimitChangeDate, legalKey, welfareKey, legalOrWelfare); + + //人员在【司龄变动日期】时对应的司龄 + int ageLimit_ageLimitChangeDate2 = getAgeLimit(workStartDate, ageLimitChangeDate2); + //人员在【司龄变动日期】时对应的司龄 + int ageLimit2_ageLimitChangeDate2 = getAgeLimit(companyStartDate, ageLimitChangeDate2); + //人员在【司龄变动日期】时对应的假期基数 + BigDecimal baseAmount_ageLimitChangeDate2 = getAmountByAgeLimit(distributionMode, rulesDetailId, -1, ageLimit_ageLimitChangeDate2, ageLimit2_ageLimitChangeDate2, legalKey, welfareKey, legalOrWelfare); + + //是否需要精确计算 + boolean needCalc0 = false; + //是否需要折算 + boolean needConvert = false; + //根据什么日期进行折算 + Calendar calendar = null; + //如果【批处理日期】小于【入职日期】,假期基数应该为0 + if (date4CalcAmount.compareTo(companyStartDate) < 0) { + return 0; + } + //如果批处理年份等于入职年份,那应该以【入职日期】来折算 + String ageLimitChangeDatetemp = ""; + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + //需要折算 + needConvert = true; + //以【入职日期来折算】 + calendar = DateUtil.getCalendar(companyStartDate); + //如果是按照司龄计算,就只按照司龄折算。 + if(legalKey==1||welfareKey==1){ + ageLimitChangeDatetemp = companyStartDate; + }else{ + //如果是初始获得年,那么,入职日期和参加工作日期,取相对较晚的日期,作为变动日期 + if(companyStartDate.substring(4).compareTo(workStartDate.substring(4)) <= 0){ + ageLimitChangeDatetemp = belongYear + workStartDate.substring(4); + }else{ + ageLimitChangeDatetemp = companyStartDate; + } + } + + + } + for (int i = 0; i < 1; i++) { + //如果【计算假期基数的日期】小于【假期基数发放日期】,假期基数应该为0 + if (date4CalcAmount.compareTo(baseAmountReleaseDate) < 0) { + return 0; + } else if (date4CalcAmount.compareTo(baseAmountReleaseDate) >= 0) { + baseAmount = baseAmount_releaseDate; + //暂定【假期基数发放日期】一定小于等于【工龄变动日期】、【司龄变动日期】 + //【假期基数发放日期】<=【工龄变动日期】<=【司龄变动日期】 + if (baseAmountReleaseDate.compareTo(ageLimitChangeDate) <= 0 && ageLimitChangeDate.compareTo(ageLimitChangeDate2) <= 0) { + if (calcMethod == 0 && baseAmount_releaseDate.doubleValue() > 0) { + Calendar _calendar1 = DateUtil.getCalendar(baseAmountReleaseDate); + BigDecimal _dayOfYear1 = new BigDecimal("" + (_calendar1.get(Calendar.DAY_OF_YEAR) - 1)); + BigDecimal _actualMaximum = new BigDecimal("" + (_calendar1.getActualMaximum(Calendar.DAY_OF_YEAR))); + + Calendar _calender2 = DateUtil.getCalendar(ageLimitChangeDate); + BigDecimal _dayOfYear2 = new BigDecimal("" + (_calender2.get(Calendar.DAY_OF_YEAR) - 1)); + + Calendar _calender3 = DateUtil.getCalendar(ageLimitChangeDate2); + BigDecimal _dayOfYear3 = new BigDecimal("" + (_calender3.get(Calendar.DAY_OF_YEAR) - 1)); + + baseAmount = ((baseAmount_releaseDate.multiply(_dayOfYear2.subtract(_dayOfYear1))) + .add(baseAmount_ageLimitChangeDate.multiply(_dayOfYear3.subtract(_dayOfYear2))) + .add(baseAmount_ageLimitChangeDate2.multiply(_actualMaximum.subtract(_dayOfYear3)))) + .divide(_actualMaximum, decimalDigit, RoundingMode.HALF_UP); + if (convertMode == 0) { + if (date4CalcAmount.compareTo(baseAmountReleaseDate) >= 0) { + baseAmount = baseAmount_releaseDate.setScale(decimalDigit, RoundingMode.HALF_UP); + } + if (date4CalcAmount.compareTo(ageLimitChangeDate) >= 0) { + baseAmount = baseAmount_ageLimitChangeDate.setScale(decimalDigit, RoundingMode.HALF_UP); + } + if (date4CalcAmount.compareTo(ageLimitChangeDate2) >= 0) { + baseAmount = baseAmount_ageLimitChangeDate2.setScale(decimalDigit, RoundingMode.HALF_UP); + } + } else if (convertMode == 1) { + baseAmount = baseAmount; + } else if (convertMode == 2) { + baseAmount = baseAmount.setScale(0, RoundingMode.UP); + } else if (convertMode == 3) { + baseAmount = baseAmount.setScale(0, RoundingMode.DOWN); + } else if (convertMode == 4) { + baseAmount = baseAmount.divide(new BigDecimal("0.5"), 0, RoundingMode.UP).multiply(new BigDecimal("0.5")); + } else if (convertMode == 5) { + baseAmount = baseAmount.divide(new BigDecimal("0.5"), 0, RoundingMode.DOWN).multiply(new BigDecimal("0.5")); + } + break; + } + //【批处理日期】>=【工龄变动日期】&& (人员在【假期基数发放日期】时对应的假期基数是0 || 【假期基数计算方式=2】时) + if ((date4CalcAmount.compareTo(ageLimitChangeDate) >= 0) + && (baseAmount_releaseDate.doubleValue() <= 0 || calcMethod == 2)) { + if (baseAmount_releaseDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate.doubleValue() > 0) { + needConvert = true; + //如果是当年入职,则按照【入职日期折算】 + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDatetemp); + }else{ + calendar = DateUtil.getCalendar(ageLimitChangeDate); + } + + baseAmount = baseAmount_ageLimitChangeDate; + } else { + if (calcMethod == 2) { + baseAmount = baseAmount_ageLimitChangeDate; + } + } + } + //【批处理日期】>=【司龄变动日期】&& (人员在【工龄变动日期】时对应的假期基数是0||【假期基数计算方式=2】时) + if ((date4CalcAmount.compareTo(ageLimitChangeDate2) >= 0) + && (baseAmount_ageLimitChangeDate.doubleValue() <= 0 || calcMethod == 2)) { + if (baseAmount_ageLimitChangeDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate2.doubleValue() > 0) { + needConvert = true; + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDatetemp); + }else{ + calendar = DateUtil.getCalendar(ageLimitChangeDate2); + } + baseAmount = baseAmount_ageLimitChangeDate2; + } else { + if (calcMethod == 2) { + baseAmount = baseAmount_ageLimitChangeDate2; + } + } + } + } else if (baseAmountReleaseDate.compareTo(ageLimitChangeDate2) <= 0 && ageLimitChangeDate2.compareTo(ageLimitChangeDate) <= 0) { + if (calcMethod == 0 && baseAmount_releaseDate.doubleValue() > 0) { + Calendar _calendar1 = DateUtil.getCalendar(baseAmountReleaseDate); + BigDecimal _dayOfYear1 = new BigDecimal("" + (_calendar1.get(Calendar.DAY_OF_YEAR) - 1)); + BigDecimal _actualMaximum = new BigDecimal("" + _calendar1.getActualMaximum(Calendar.DAY_OF_YEAR)); + + Calendar _calender2 = DateUtil.getCalendar(ageLimitChangeDate2); + BigDecimal _dayOfYear2 = new BigDecimal("" + (_calender2.get(Calendar.DAY_OF_YEAR) - 1)); + + Calendar _calender3 = DateUtil.getCalendar(ageLimitChangeDate); + BigDecimal _dayOfYear3 = new BigDecimal("" + (_calender3.get(Calendar.DAY_OF_YEAR) - 1)); + + baseAmount = ((baseAmount_releaseDate.multiply(_dayOfYear2.subtract(_dayOfYear1))) + .add(baseAmount_ageLimitChangeDate2.multiply(_dayOfYear3.subtract(_dayOfYear2))) + .add(baseAmount_ageLimitChangeDate.multiply(_actualMaximum.subtract(_dayOfYear3)))) + .divide(_actualMaximum, decimalDigit, RoundingMode.HALF_UP); + if (convertMode == 0) { + if (date4CalcAmount.compareTo(baseAmountReleaseDate) >= 0) { + baseAmount = baseAmount_releaseDate.setScale(decimalDigit, RoundingMode.HALF_UP); + } + if (date4CalcAmount.compareTo(ageLimitChangeDate2) >= 0) { + baseAmount = baseAmount_ageLimitChangeDate2.setScale(decimalDigit, RoundingMode.HALF_UP); + } + if (date4CalcAmount.compareTo(ageLimitChangeDate) >= 0) { + baseAmount = baseAmount_ageLimitChangeDate.setScale(decimalDigit, RoundingMode.HALF_UP); + } + } else if (convertMode == 1) { + baseAmount = baseAmount; + } else if (convertMode == 2) { + baseAmount = baseAmount.setScale(0, RoundingMode.UP); + } else if (convertMode == 3) { + baseAmount = baseAmount.setScale(0, RoundingMode.DOWN); + } else if (convertMode == 4) { + baseAmount = baseAmount.divide(new BigDecimal("0.5"), 0, RoundingMode.UP).multiply(new BigDecimal("0.5")); + } else if (convertMode == 5) { + baseAmount = baseAmount.divide(new BigDecimal("0.5"), 0, RoundingMode.DOWN).multiply(new BigDecimal("0.5")); + } + break; + } + if ((date4CalcAmount.compareTo(ageLimitChangeDate2) >= 0) + && (baseAmount_releaseDate.doubleValue() <= 0 || calcMethod == 2)) { + if (baseAmount_releaseDate.doubleValue() <= 0 && baseAmount_ageLimitChangeDate2.doubleValue() > 0) { + needConvert = true; + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDatetemp); + }else{ + calendar = DateUtil.getCalendar(ageLimitChangeDate2); + } + + baseAmount = baseAmount_ageLimitChangeDate2; + } else { + if (calcMethod == 2) { + baseAmount = baseAmount_ageLimitChangeDate2; + } + } + } + if ((date4CalcAmount.compareTo(ageLimitChangeDate) >= 0) + && (baseAmount_ageLimitChangeDate2.doubleValue() <= 0 || calcMethod == 2)) { + if (baseAmount_ageLimitChangeDate2.doubleValue() <= 0 && baseAmount_ageLimitChangeDate.doubleValue() > 0) { + needConvert = true; + if (belongYear.compareTo(companyStartDate.substring(0, 4)) == 0) { + calendar = DateUtil.getCalendar(ageLimitChangeDatetemp); + }else{ + calendar = DateUtil.getCalendar(ageLimitChangeDate); + } + + baseAmount = baseAmount_ageLimitChangeDate; + } else { + if (calcMethod == 2) { + baseAmount = baseAmount_ageLimitChangeDate; + } + } + } + } + } + } + + if (needConvert) { + //这一年一共有多少天 + BigDecimal actualMaximum = new BigDecimal("" + calendar.getActualMaximum(Calendar.DAY_OF_YEAR)); + //年假变动日期是这一天的第几天 + BigDecimal dayOfYear = new BigDecimal("" + (calendar.get(Calendar.DAY_OF_YEAR) - 1)); + + if (convertMode == 0) { + baseAmount = baseAmount; + } else if (convertMode == 1) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, decimalDigit, RoundingMode.HALF_UP); + } else if (convertMode == 2) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, 0, RoundingMode.UP); + } else if (convertMode == 3) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum, 0, RoundingMode.DOWN); + } else if (convertMode == 4) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum.multiply(new BigDecimal("0.5")), 0, RoundingMode.UP).multiply(new BigDecimal("0.5")); + } else if (convertMode == 5) { + baseAmount = baseAmount.multiply(actualMaximum.subtract(dayOfYear)).divide(actualMaximum.multiply(new BigDecimal("0.5")), 0, RoundingMode.DOWN).multiply(new BigDecimal("0.5")); + } + } else { + baseAmount = baseAmount; + } + + } catch (Exception e) { + e.printStackTrace(); + } + return baseAmount.setScale(decimalDigit, RoundingMode.HALF_UP).doubleValue(); + } + + /** + * [8-育儿假]计算假期基数 + * + * @param params Map + * belongYear:所属年份 + * createDate:人员创建日期 + * workStartDate:参加工作日期 + * companyStartDate:入职日期 + * rulesDetailId:假期规则的ID + * distributionMode:当前假期规则发放方式 + * annualAmount:当[distributionMode]=[4-每年发放固定天数]时有效 + * legalKey:法定年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * welfareKey:福利年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * calcMethod:假期基数计算方式 + * convertMode:折算方式 + * decimalDigit:折算后的假期余额保留几位小数 + * @return + */ + private static Map getBaseAmountByDis8(Map params) { + Map returnMap = Maps.newHashMap(); + + try{ + String resourceId = Util.null2String(params.get("resourceId")); + ArrayList listDates = getParentalLeaveDate(resourceId); + //当前日期 + String currentDate = DateUtil.getCurrentDate(); + //批处理年份 + String belongYear = Util.null2String(params.get("belongYear")); + String belongYearNew = ""; + //当[distributionMode]=[8-每年发放固定天数]时有效 + double annualAmount = Util.getDoubleValue("" + params.get("annualAmount"), 0); + //孩子周岁 + int yearsOld = Util.getIntValue(Util.null2String(params.get("yearsOld")),3); + + + BigDecimal baseAmount = new BigDecimal("0"); + int decimalDigit = 2; + boolean addOrUpdate = false; + String expirationDate = ""; + String expirationDateNew = ""; + //折算后的假期余额保留几位小数 + decimalDigit = Util.getIntValue("" + params.get("decimalDigit"), 2); + //批处理日期(因为存在当前年份批处理上一年份或者批处理下一年份,所以需要做一些特殊处理) + String date4CalcAmount = currentDate; + String effectiveDate = ""; + int validityRule = Util.getIntValue(Util.null2String(params.get("validityRule")),1); + /* + * 1、考虑1个孩子,0年、1年、2年发放 + * 2、考虑2个孩子,0年、1年、2年发放,第一个孩子有效期到期了,才考虑第二个孩子的。如果当前日期在第二个孩子有效期内,那么就存到有效期对应的当前年份 + *第二个孩子的2021年1月1号 + * */ + for (int i = 0; i < listDates.size(); i++) { + String dateOfBirth=listDates.get(i); + + String yearOfBirth=dateOfBirth.substring(0,4); + + String baseAmountReleaseDate = belongYear + dateOfBirth.substring(4); + int ageLimit = getAgeLimit(dateOfBirth, baseAmountReleaseDate); + + if(ageLimit>=0&&ageLimit<=yearsOld-1){ + baseAmount = new BigDecimal("" + annualAmount); + }else{ + baseAmount = new BigDecimal("0"); + } + effectiveDate=baseAmountReleaseDate; +//第二个孩子的情况 + if(!expirationDateNew.equals("")&& belongYear.compareTo(expirationDateNew.substring(0, 4)) == 0){ + if(baseAmountReleaseDate.compareTo(expirationDateNew) > 0){ + if(date4CalcAmount.compareTo(expirationDateNew) > 0&&date4CalcAmount.compareTo(baseAmountReleaseDate) < 0){ + belongYearNew = (Util.getIntValue(belongYear) - 1) + ""; + addOrUpdate = true; + new BaseBean().writeLog("育儿假1:belongYearNew="+belongYearNew); + continue; + }else if(date4CalcAmount.compareTo(expirationDateNew) <= 0){ + baseAmount = new BigDecimal("0"); + new BaseBean().writeLog("育儿假2:baseAmount="+baseAmount); + continue; + } + }else{ + if(date4CalcAmount.compareTo(expirationDateNew) >= 0){ + new BaseBean().writeLog("育儿假3:baseAmount="+baseAmount); + break; + }else{ + baseAmount = new BigDecimal("0"); + new BaseBean().writeLog("育儿假4:baseAmount="+baseAmount); + continue; + } + } + } + expirationDateNew = (Util.getIntValue(yearOfBirth) + yearsOld) + dateOfBirth.substring(4); + + String _expirationDate = (Util.getIntValue(belongYear) + 1) + dateOfBirth.substring(4); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate yesterday = LocalDate.parse(_expirationDate, formatter).minusDays(1); + expirationDate = yesterday.toString(); // 过期日期提前了一天 + + if(ageLimit>=0&&ageLimit<=yearsOld-1){ + }else{ + baseAmount = new BigDecimal("0"); + new BaseBean().writeLog("育儿假5:baseAmount="+baseAmount); + continue; + } + + //批处理日期>=假期基数释放日期--出生日期 + if (date4CalcAmount.compareTo(baseAmountReleaseDate) >= 0) { + } else { + baseAmount = new BigDecimal("0"); + } + new BaseBean().writeLog("育儿假6:baseAmount="+baseAmount); + break; + } + new BaseBean().writeLog("育儿假7:baseAmount="+baseAmount); + if (validityRule == 0) { + + expirationDate = "2222-12-31"; + } + returnMap.put("baseAmount", baseAmount.setScale(decimalDigit, RoundingMode.HALF_UP).doubleValue()); + returnMap.put("addOrUpdate",addOrUpdate); + returnMap.put("expirationDate",expirationDate); + returnMap.put("effectiveDate",effectiveDate); + returnMap.put("belongYearNew",belongYearNew); + } catch (Exception e) { + e.printStackTrace(); + } + return returnMap; + } + /** + * [8-育儿假]计算假期基数 + * + * @param params Map + * belongYear:所属年份 + * createDate:人员创建日期 + * workStartDate:参加工作日期 + * companyStartDate:入职日期 + * rulesDetailId:假期规则的ID + * distributionMode:当前假期规则发放方式 + * annualAmount:当[distributionMode]=[4-每年发放固定天数]时有效 + * legalKey:法定年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * welfareKey:福利年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * calcMethod:假期基数计算方式 + * convertMode:折算方式 + * decimalDigit:折算后的假期余额保留几位小数 + * @return + */ + private static Map getBaseAmountByDis8Num(Map params) { + Map returnMap = Maps.newHashMap(); + + try{ + String resourceId = Util.null2String(params.get("resourceId")); + String ruleId = Util.null2String(params.get("ruleId")); + String operator = Util.null2String(params.get("operator")); + ArrayList listDates = getParentalLeaveDate(resourceId); + ArrayList listChildId = getChildId(resourceId); + //当前日期 + String currentDate = DateUtil.getCurrentDate(); + + /*获取当前日期,当前时间*/ + Calendar today = Calendar.getInstance(); + String currentTime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" + + Util.add0(today.get(Calendar.MINUTE), 2) + ":" + + Util.add0(today.get(Calendar.SECOND), 2); + //当前年份 + String currentYear = currentDate.substring(0, 4); + //批处理年份 + String belongYear = Util.null2String(params.get("belongYear")); + String belongYearNew = ""; + //当[distributionMode]=[8-每年发放固定天数]时有效 + double annualAmount = Util.getDoubleValue("" + params.get("annualAmount"), 0); + //孩子周岁 + int yearsOld = Util.getIntValue(Util.null2String(params.get("yearsOld")),3); + BigDecimal baseAmount = new BigDecimal("0"); + int decimalDigit = 2; + boolean addOrUpdate = false; + String expirationDate = ""; + String expirationDateNew = currentDate; + + + //折算后的假期余额保留几位小数 + decimalDigit = Util.getIntValue("" + params.get("decimalDigit"), 2); + //批处理日期(因为存在当前年份批处理上一年份或者批处理下一年份,所以需要做一些特殊处理) + String date4CalcAmount = currentDate; + + int validityRule = Util.getIntValue(Util.null2String(params.get("validityRule")),1); + RecordSet rs = new RecordSet(); + // 查询当年育儿假数据 + String sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId = "+ruleId+" and ( OVERTIMETYPE<>'7' or overtimeType is null ) and resourceId = "+resourceId + " and belongYear = "+belongYear; + KQBalanceOfLeaveEntity balanceEntity = null; + Map balanceEntities = new HashMap(); + rs.executeQuery(sql); + while (rs.next()) { + int id = rs.getInt("id"); + String childId = Util.null2s(rs.getString("childId"), ""); + if(StringUtils.isNotBlank(childId)){ + double baseAmountvalue = Util.getDoubleValue(rs.getString("baseAmount"), 0.00); + double extraAmountvalue = Util.getDoubleValue(rs.getString("extraAmount"), 0.00); + double usedAmountvalue = Util.getDoubleValue(rs.getString("usedAmount"), 0.00); + balanceEntity = new KQBalanceOfLeaveEntity(); + balanceEntity.setId(id); + balanceEntity.setBaseAmount(baseAmountvalue); + balanceEntity.setExtraAmount(extraAmountvalue); + balanceEntity.setUsedAmount(usedAmountvalue); + balanceEntities.put(childId, balanceEntity); + } + } + + for (int i = 0; i < listDates.size(); i++) { + // 孩子的生日 + String dateOfBirth=listDates.get(i); + // 孩子的id + String childId = listChildId.get(i); + String baseAmountReleaseDate = belongYear + dateOfBirth.substring(4); + int ageLimit = getAgeLimit(dateOfBirth, baseAmountReleaseDate); + new BaseBean().writeLog("==getBaseAmountByDis8Num==ageLimit"+ageLimit); + if(ageLimit>=0&&ageLimit<=yearsOld-1) { + baseAmount = new BigDecimal("" + annualAmount); + + // 首先是查询数据库中是否存在这条数据 + // 旧数据是不存在孩子id的,所以现在根据孩子id和是否导入判断删除旧数据 + sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId = " + ruleId + " and childId IS NULL and ( OVERTIMETYPE<>'7' or overtimeType is null ) and resourceId = " + resourceId + " and belongYear = " + belongYear; + rs.executeQuery(sql); + double usedAmount = 0; + int id = -1; + if (rs.next()) { + // 旧数据使用量 + usedAmount = Util.getDoubleValue(rs.getString("usedamount"), 0.0); + // 旧数据记录id + id = rs.getInt("id"); + rs.writeLog("==lzl==resourceId=" + resourceId + "的旧数据id" + id + "使用情况:usedAmount" + usedAmount); + } + if (id > 0) { + // 删除旧数据 + rs.executeUpdate("DELETE FROM kq_balanceOfLeave WHERE id =" + id); + } + RecordSet recordSet = new RecordSet(); + KQBalanceOfLeaveEntity oldBalanceEntity = (KQBalanceOfLeaveEntity) balanceEntities.get(childId); + if (oldBalanceEntity != null) { + balanceEntities.remove(childId); + //如果假期基数没有发生变化,不需要更新 + if (oldBalanceEntity.getBaseAmount() == baseAmount.doubleValue()) { + continue; + } + // 如果存在数据就更新 baseAmount,为什么需要跟新这个数据呢?这是因为基数是可能发生改变的。 + int balanceOfLeaveId = oldBalanceEntity.getId(); + + String _expirationDate = (Util.getIntValue(belongYear) + 1) + dateOfBirth.substring(4); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate yesterday = LocalDate.parse(_expirationDate, formatter).minusDays(1); + expirationDate = yesterday.toString(); // 过期日期提前了一天 + if (validityRule == 0) { + //不限制有效期,默认永久有效(永久有效时有效日期默认为2222-12-31) + expirationDate = "2222-12-31"; + } + String updateSql = "UPDATE kq_balanceOfLeave SET baseAmount = " + baseAmount + ",expirationDate='" + expirationDate + "' WHERE id = " + balanceOfLeaveId; + recordSet.writeLog("==lzl==updateSql" + updateSql); + recordSet.executeUpdate(updateSql); + + /* 执行 update 操作的日志记录 */ + String sql3 = "insert into kq_UsageHistory(leaveRulesId,relatedId,operator,operateDate,operateTime,operateType," + + "belongYear,oldBaseAmount,newBaseAmount,insertOrUpdate,oldMinimumUnit,newMinimumUnit,balanceOfLeaveId)" + + "values(" + ruleId + "," + resourceId + "," + operator + ",'" + currentDate + "','" + currentTime + "',6,'" + belongYear + "'," + oldBalanceEntity.getBaseAmount() + "," + baseAmount + ",'update',1,1," + balanceOfLeaveId + ")"; + recordSet.executeUpdate(sql3); + } else { + // 发放日期的年份加1 + String _expirationDate = (Util.getIntValue(belongYear) + 1) + dateOfBirth.substring(4); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate yesterday = LocalDate.parse(_expirationDate, formatter).minusDays(1); + expirationDate = yesterday.toString(); // 过期日期提前了一天 + if (validityRule == 0) { + //不限制有效期,默认永久有效(永久有效时有效日期默认为2222-12-31) + expirationDate = "2222-12-31"; + } + // 解析日期字符串为 LocalDate 对象 + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate releaseDate = LocalDate.parse(baseAmountReleaseDate, dateFormatter); + LocalDate now = LocalDate.parse(currentDate, dateFormatter); + // 比较日期 只有当前日期大于发放日期才可以用 + int comparisonResult = releaseDate.compareTo(now); + if (comparisonResult <= 0) { + String insertSql = "INSERT INTO " + + "kq_balanceOfLeave (LEAVERULESID,RESOURCEID,BELONGYEAR,STATUS,EXPIRATIONDATE,EFFECTIVEDATE,BASEAMOUNT,EXTRAAMOUNT,USEDAMOUNT,BASEAMOUNT2,EXTRAAMOUNT2,USEDAMOUNT2,TIAOXIUAMOUNT,childId,isdelete) " + + "VALUES (" + ruleId + "," + resourceId + ",'" + belongYear + "',0,'" + expirationDate + "','" + baseAmountReleaseDate + "'," + baseAmount + " ,0," + usedAmount + ",0,0,0,0," + childId + ",0)"; + recordSet.writeLog("==lzl==insertSql" + insertSql); + recordSet.executeUpdate(insertSql); + String sql2 = "select * from kq_balanceOfLeave where leaveRulesId = " + ruleId + " and resourceId = " + resourceId + " and childId =" + childId + " and ( OVERTIMETYPE<>'7' or overtimeType is null ) and belongYear = '" + belongYear + "' and (isdelete <> 1 OR isdelete IS NULL)"; + recordSet.executeQuery(sql2); + String balanceOfLeaveId = ""; + if (recordSet.next()) { + balanceOfLeaveId = recordSet.getString("id"); + } + /* 执行 insert 操作的日志记录 */ + String sql3 = "insert into kq_UsageHistory(leaveRulesId,relatedId,operator,operateDate,operateTime,operateType," + + "belongYear,oldBaseAmount,newBaseAmount,insertOrUpdate,oldMinimumUnit,newMinimumUnit,oldExtraAmount,newExtraAmount,oldUsedAmount,newUsedAmount,oldBaseAmount2,newBaseAmount2,oldExtraAmount2,newExtraAmount2,oldUsedAmount2,newUsedAmount2,balanceOfLeaveId)" + + "values(" + ruleId + "," + resourceId + "," + operator + ",'" + currentDate + "','" + currentTime + "',6,'" + belongYear + "'," + 0 + "," + baseAmount + ",'insert',1,1,0,0,0,0,0,0,0,0,0,0," + balanceOfLeaveId + ")"; + recordSet.executeUpdate(sql3); + } + } + } + } + + // 删除不是当前孩子列表中的考勤数据 + + balanceEntities.forEach((key, value) -> { + String chlied = key; + KQBalanceOfLeaveEntity oldBalanceEntity = (KQBalanceOfLeaveEntity) value; + + String deleteSql = "UPDATE kq_balanceOfLeave SET isdelete=1 WHERE id = " + oldBalanceEntity.getId(); + String sql3 = "insert into kq_UsageHistory(leaveRulesId,relatedId,operator,operateDate,operateTime,operateType," + + "belongYear,oldBaseAmount,newBaseAmount,insertOrUpdate,oldMinimumUnit,newMinimumUnit,balanceOfLeaveId)" + + "values(" + ruleId + "," + resourceId + "," + operator + ",'" + currentDate + "','" + currentTime + "',6,'" + belongYear + "'," + oldBalanceEntity.getBaseAmount() + ",0,'update',1,1," + oldBalanceEntity.getId() + ")"; + if (oldBalanceEntity.getExtraAmount() > 0 || + oldBalanceEntity.getUsedAmount() > 0) { + deleteSql = "UPDATE kq_balanceOfLeave SET baseAmount=0 WHERE id = " + oldBalanceEntity.getId(); + } + rs.executeUpdate(deleteSql); + rs.executeUpdate(sql3); + }); + + returnMap.put("baseAmount", baseAmount.setScale(decimalDigit, RoundingMode.HALF_UP).doubleValue()); + returnMap.put("addOrUpdate",addOrUpdate); + returnMap.put("expirationDate",expirationDateNew); + returnMap.put("belongYearNew",belongYearNew); + } catch (Exception e) { + e.printStackTrace(); + } + return returnMap; + } + + + /** + * [7-按司龄自动发放(入职日期当天发放假期余额)]计算假期基数 + * + * @param params Map + * belongYear:所属年份 + * createDate:人员创建日期 + * workStartDate:参加工作日期 + * companyStartDate:入职日期 + * rulesDetailId:假期规则的ID + * distributionMode:当前假期规则发放方式 + * annualAmount:当[distributionMode]=[4-每年发放固定天数]时有效 + * legalKey:法定年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * welfareKey:福利年假规则(当[distributionMode=6]时有效):0-工龄、1-司龄、2-工龄+司龄 + * calcMethod:假期基数计算方式 + * convertMode:折算方式 + * decimalDigit:折算后的假期余额保留几位小数 + * @return + */ + private static double getBaseAmountByDis7(Map params) { + double baseAmount = 0; + try{ + //当前日期 + String currentDate = DateUtil.getCurrentDate(); + //当前年份 + String currentYear = currentDate.substring(0, 4); + //批处理年份 + String belongYear = Util.null2String(params.get("belongYear")); + //人员的参加工作日期 + String workStartDate = Util.null2String(params.get("workStartDate")); + //人员的入职日期 + String companyStartDate = Util.null2String(params.get("companyStartDate")); + + //假期规则的ID + String rulesDetailId = Util.null2String(params.get("rulesDetailId")); + //当前假期规则发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放 + int distributionMode = Util.getIntValue("" + params.get("distributionMode"), 1); + //假期基数发放日期 + String baseAmountReleaseDate = belongYear + companyStartDate.substring(4); + //默认保留两位小数 + int decimalDigit = Util.getIntValue("" + params.get("decimalDigit"), 2); + + if (distributionMode != 7) { + return baseAmount; + } + + //批处理日期 + String date4CalcAmount = currentDate; + + //人员在【假期基数发放日期】时对应的【司龄】 + int ageLimit = getAgeLimit(companyStartDate, baseAmountReleaseDate); + //人员在【假期基数发放日期】时应有的【假期基数】 + BigDecimal baseAmount_releaseDate = getAmountByAgeLimit(distributionMode, rulesDetailId, 0, ageLimit, -1, -1, -1, ""); + + //批处理日期>=假期基数释放日期 + if (date4CalcAmount.compareTo(baseAmountReleaseDate) >= 0) { + baseAmount = baseAmount_releaseDate.setScale(2, RoundingMode.HALF_UP).doubleValue(); + } else { + baseAmount = 0; + } + }catch (Exception e){ + e.printStackTrace(); + } + return baseAmount; + } + + /** + * 获取调休的余额 + * + * @param ruleId 假期类型的ID + * @param resourceId 人员ID + * @param searchDate 计算是否失效的指定日期 + * @param calcByCurrentDate 是根据当前日期计算还是根据指定日期计算假期是否失效:true-当前日期、false-指定日期 + * @param isAll 是获取所有年份的还是获取指定年份的:true-所有年份的、false-指定年份的 + * @return + */ + private static BigDecimal getRestAmountByDis5(String ruleId, String resourceId, String searchDate, boolean calcByCurrentDate, boolean isAll) { + BigDecimal restAmount = new BigDecimal("0"); + try { + //获取当前日期 + Calendar today = Calendar.getInstance(); + //当前日期 + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + //所属年份 + String searchYear = searchDate.substring(0, 4); + //根据指定日期(或者根据当前日期)判断假期是否已经过了有效期 + String date = calcByCurrentDate ? currentDate : searchDate; + String sql = ""; + RecordSet recordSet = new RecordSet(); + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql = " select sum(tiaoxiuamount) as allTiaoxiuamount,sum(baseAmount) as allBaseAmount,sum(extraAmount) as allExtraAmount,sum(usedAmount) as allUsedAmount from KQ_BalanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceId + " and leaveRulesId=" + ruleId + " and (expirationDate is null or expirationDate='' or expirationDate>='" + date + "') "; + } else { + sql = " select sum(tiaoxiuamount) as allTiaoxiuamount,sum(baseAmount) as allBaseAmount,sum(extraAmount) as allExtraAmount,sum(usedAmount) as allUsedAmount from KQ_BalanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceId + " and leaveRulesId=" + ruleId + " and (expirationDate is null or expirationDate>='" + date + "') "; + } + //是查询所有有效的假期余额还是仅仅查询指定日期当年的 + if(KQSettingsBiz.is_balanceofleave()){//开启开关 + if (!isAll) { + sql += " and belongYear='" + searchYear + "'"; + }else{ + sql += " and belongYear<='" + searchYear + "'"; + } + }else{ + if (!isAll) { + sql += " and belongYear='" + searchYear + "'"; + } + } + recordSet.executeQuery(sql); + while (recordSet.next()) { + BigDecimal _baseAmount = new BigDecimal(Util.null2s(recordSet.getString("allBaseAmount"), "0")); + BigDecimal _extraAmount = new BigDecimal(Util.null2s(recordSet.getString("allExtraAmount"), "0")); + BigDecimal _usedAmount = new BigDecimal(Util.null2s(recordSet.getString("allUsedAmount"), "0")); + BigDecimal _tiaoxiuamount = new BigDecimal(Util.null2s(recordSet.getString("allTiaoxiuamount"), "0"));//加班生成调休 + + restAmount = restAmount.add(_baseAmount).add(_tiaoxiuamount).add(_extraAmount).subtract(_usedAmount); + } + } catch (Exception e) { + e.printStackTrace(); + } + return restAmount; + } + + private static BigDecimal getRestAmountByDis8(String ruleId, String resourceId, String searchDate, boolean calcByCurrentDate, boolean isAll) { + BigDecimal restAmount = new BigDecimal("0"); + try { + //获取当前日期 + Calendar today = Calendar.getInstance(); + //当前日期 + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + //所属年份 + String searchYear = searchDate.substring(0, 4); + //根据指定日期(或者根据当前日期)判断假期是否已经过了有效期 + String date = calcByCurrentDate ? currentDate : searchDate; + String sql = ""; + RecordSet recordSet = new RecordSet(); + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql = " select sum(baseAmount) as allBaseAmount,sum(extraAmount) as allExtraAmount,sum(usedAmount) as allUsedAmount from KQ_BalanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceId + " and leaveRulesId=" + ruleId + " and (expirationDate is null or expirationDate='' or expirationDate>='" + date + "') "; + } else { + sql = " select sum(baseAmount) as allBaseAmount,sum(extraAmount) as allExtraAmount,sum(usedAmount) as allUsedAmount from KQ_BalanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceId + " and leaveRulesId=" + ruleId + " and (expirationDate is null or expirationDate>='" + date + "') "; + } + //是查询所有有效的假期余额还是仅仅查询指定日期当年的 + if(KQSettingsBiz.is_balanceofleave()){//开启开关 + if (!isAll) { + sql += " and belongYear='" + searchYear + "'"; + }else{ + sql += " and belongYear<='" + searchYear + "'"; + } + }else{ + if (!isAll) { + sql += " and belongYear='" + searchYear + "'"; + } + } + recordSet.executeQuery(sql); + while (recordSet.next()) { + BigDecimal _baseAmount = new BigDecimal(Util.null2s(recordSet.getString("allBaseAmount"), "0")); + BigDecimal _extraAmount = new BigDecimal(Util.null2s(recordSet.getString("allExtraAmount"), "0")); + BigDecimal _usedAmount = new BigDecimal(Util.null2s(recordSet.getString("allUsedAmount"), "0")); + restAmount = restAmount.add(_baseAmount).add(_extraAmount).subtract(_usedAmount); + } + } catch (Exception e) { + e.printStackTrace(); + } + return restAmount; + } + /** + * 获取调休的余额 + * + * @param params + * @param user + * @return + */ + public static Map getRestAmountMapByDis5(Map params, User user) { + Map balanceMap = new HashMap(); + try { + /** + * 分页控件返回的值 + * currentPage:当前页数 + * pageSize:每页多少条数据 + * showAll:是显示分页还是显示所有 + */ + int currentPage = Util.getIntValue((String) params.get("currentPage"), 1); + int pageSize = Util.getIntValue((String) params.get("pageSize"), 10); + boolean showAll = Util.null2s((String) params.get("showAll"), "true").equals("true"); + /** + * 时间范围选择的年份 + * dateScope:5-本年、8-上一年 + * selectedYear:指定年份 + */ + String dateScope = Util.null2String(params.get("dateScope")); + String selectedYear = Util.null2String(params.get("selectedYear")); + if (dateScope.equals("5") || dateScope.equals("8")) { + selectedYear = TimeUtil.getDateByOption(dateScope, "0").substring(0, 4); + } + /** + * 数据范围 + * dataScope:0-总部、1-分部、2-分部、3-人员、4-我的下属 + * subcomId:指定分部ID + * deptId:指定部门ID + * resourceId:指定人员ID + * allLevel:是否包含下级下属:0-不包含、1-包含 + */ + String dataScope = Util.null2String(params.get("dataScope")); + String subcomId = Util.null2String(params.get("subcomId")); + String deptId = Util.null2String(params.get("deptId")); + String resourceId = Util.null2String(params.get("resourceId")); + String allLevel = Util.null2String(params.get("allLevel")); + //人员状态 + String resourceStatus = Util.null2String(params.get("status")); + + /** + * isNoAccount:是否显示无账号人员:true-显示、false-不显示 + */ + String isNoAccount = Util.null2String(params.get("isNoAccount")); + /** + * 假期类型的ID + */ + String leaveRulesId = Util.null2String(params.get("leaveRulesId")); + /** + * 当前日期 + */ + String currentDate = DateUtil.getCurrentDate(); + /** + * 获取考勤报表权限共享设置 + */ + KQReportBiz kqReportBiz = new KQReportBiz(); + String rightStr = kqReportBiz.getReportRight("4", "" + user.getUID(), "a"); + + RecordSet recordSet = new RecordSet(); + String sql = "select a.id hrmResourceId,b.* from HrmResource a left join "; + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sql = "select a.id hrmResourceId,b.*,ROW_NUMBER() OVER(order by dspOrder,a.id) as rn from HrmResource a left join "; + } + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql += "(select resourceId, sum(baseAmount) as allBaseAmount, sum(tiaoxiuamount) as allTiaoxiuamount,sum(extraAmount) as allExtraAmount, sum(usedAmount) as allUsedAmount " + + "from kq_balanceOfLeave " + + "where 1=1 and (isDelete is null or isDelete<>1) and (expirationDate is null or expirationDate='' or expirationDate >= '" + currentDate + "') and belongYear='" + selectedYear + "' and leaveRulesId=" + leaveRulesId + " " + + "group by resourceId) b " + + "on a.id = b.resourceId where 1=1 "; + } else { + sql += "(select resourceId, sum(baseAmount) as allBaseAmount, sum(tiaoxiuamount) as allTiaoxiuamount,sum(extraAmount) as allExtraAmount, sum(usedAmount) as allUsedAmount " + + "from kq_balanceOfLeave " + + "where 1=1 and (isDelete is null or isDelete<>1) and (expirationDate is null or expirationDate >= '" + currentDate + "') and belongYear='" + selectedYear + "' and leaveRulesId=" + leaveRulesId + " " + + "group by resourceId) b " + + "on a.id = b.resourceId where 1=1 "; + } + if (dataScope.equals("0")) { + //总部 + } else if (dataScope.equals("1")) { + sql += " and a.subcompanyId1 in (" + subcomId + ") "; + } else if (dataScope.equals("2")) { + sql += " and a.departmentId in (" + deptId + ") "; + } else if (dataScope.equals("3")) { + sql += " and a.id in (" + resourceId + ")"; + } else if (dataScope.equals("4")) { + if (allLevel.equals("1")) { + sql += " and (a.id=" + user.getUID() + " or a.managerStr like '%," + user.getUID() + ",%' )"; + } else { + sql += " and (a.id=" + user.getUID() + " or a.managerid = " + user.getUID() + ")"; + } + } + + if(resourceStatus.length()>0){ + if (!resourceStatus.equals("8") && !resourceStatus.equals("9")) { + sql += " and a.status = "+resourceStatus+ ""; + }else if (resourceStatus.equals("8")) { + sql += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + if (isNoAccount.equals("false")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql += " and (loginId is not null and loginId<>'')"; + } else { + sql += " and (loginId is not null)"; + } + } + //考勤报表共享设置 + if (!rightStr.equals("") && !dataScope.equals("4")) { + sql += rightStr; + } + if (!recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sql += " order by dspOrder,hrmResourceId "; + } + if (!showAll) { + String pageSql = "select * from (select tmp.*,rownum rn from (" + sql + ") tmp where rownum<=" + (pageSize * currentPage) + ") where rn>=" + (pageSize * (currentPage - 1) + 1); + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + pageSql = "select t.* from (" + sql + ") t where 1=1 and rn>=" + (pageSize * (currentPage - 1) + 1) + " and rn<=" + (pageSize * currentPage); + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + pageSql = sql + " limit " + (currentPage - 1) * pageSize + "," + pageSize; + }else if (recordSet.getDBType().equalsIgnoreCase("postgresql")) { + pageSql = sql + " limit " + pageSize + " offset " + (currentPage - 1) * pageSize; + } + recordSet.executeQuery(pageSql); + } else { + recordSet.executeQuery(sql); + } + while (recordSet.next()) { + String hrmResourceId = Util.null2String(recordSet.getString("hrmResourceId")); + BigDecimal allBaseAmount = new BigDecimal(Util.null2s(recordSet.getString("allBaseAmount"), "0")); + BigDecimal allExtraAmount = new BigDecimal(Util.null2s(recordSet.getString("allExtraAmount"), "0")); + BigDecimal allUsedAmount = new BigDecimal(Util.null2s(recordSet.getString("allUsedAmount"), "0")); + BigDecimal allTiaoxiuamount = new BigDecimal(Util.null2s(recordSet.getString("allTiaoxiuamount"), "0")); + + balanceMap.put(hrmResourceId + "_" + leaveRulesId, allBaseAmount.add(allExtraAmount).add(allTiaoxiuamount).subtract(allUsedAmount)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return balanceMap; + } + + + + /** + * qc 获取育儿假的余额 + * + * @param params + * @param user + * @return + */ + public static Map getRestAmountMapByDis8(Map params, User user) { + Map balanceMap = new HashMap(); + try { + /** + * 分页控件返回的值 + * currentPage:当前页数 + * pageSize:每页多少条数据 + * showAll:是显示分页还是显示所有 + */ + int currentPage = Util.getIntValue((String) params.get("currentPage"), 1); + int pageSize = Util.getIntValue((String) params.get("pageSize"), 10); + boolean showAll = Util.null2s((String) params.get("showAll"), "true").equals("true"); + /** + * 时间范围选择的年份 + * dateScope:5-本年、8-上一年 + * selectedYear:指定年份 + */ + String dateScope = Util.null2String(params.get("dateScope")); + String selectedYear = Util.null2String(params.get("selectedYear")); + if (dateScope.equals("5") || dateScope.equals("8")) { + selectedYear = TimeUtil.getDateByOption(dateScope, "0").substring(0, 4); + } + /** + * 数据范围 + * dataScope:0-总部、1-分部、2-分部、3-人员、4-我的下属 + * subcomId:指定分部ID + * deptId:指定部门ID + * resourceId:指定人员ID + * allLevel:是否包含下级下属:0-不包含、1-包含 + */ + String dataScope = Util.null2String(params.get("dataScope")); + String subcomId = Util.null2String(params.get("subcomId")); + String deptId = Util.null2String(params.get("deptId")); + String resourceId = Util.null2String(params.get("resourceId")); + String allLevel = Util.null2String(params.get("allLevel")); + //人员状态 + String resourceStatus = Util.null2String(params.get("status")); + + /** + * isNoAccount:是否显示无账号人员:true-显示、false-不显示 + */ + String isNoAccount = Util.null2String(params.get("isNoAccount")); + /** + * 假期类型的ID + */ + String leaveRulesId = Util.null2String(params.get("leaveRulesId")); + /** + * 当前日期 + */ + String currentDate = DateUtil.getCurrentDate(); + /** + * 获取考勤报表权限共享设置 + */ + KQReportBiz kqReportBiz = new KQReportBiz(); + String rightStr = kqReportBiz.getReportRight("4", "" + user.getUID(), "a"); + + RecordSet recordSet = new RecordSet(); + String sql = "select a.id hrmResourceId,b.* from HrmResource a left join "; + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sql = "select a.id hrmResourceId,b.*,ROW_NUMBER() OVER(order by dspOrder,a.id) as rn from HrmResource a left join "; + } + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql += "(select resourceId, sum(baseAmount) as allBaseAmount,sum(extraAmount) as allExtraAmount, sum(usedAmount) as allUsedAmount " + + "from kq_balanceOfLeave " + + "where 1=1 and (isDelete is null or isDelete<>1) and (expirationDate is null or expirationDate='' or expirationDate >= '" + currentDate + "') and belongYear='" + selectedYear + "' and leaveRulesId=" + leaveRulesId + " " + + "group by resourceId) b " + + "on a.id = b.resourceId where 1=1 "; + } else { + sql += "(select resourceId, sum(baseAmount) as allBaseAmount,sum(extraAmount) as allExtraAmount, sum(usedAmount) as allUsedAmount " + + "from kq_balanceOfLeave " + + "where 1=1 and (isDelete is null or isDelete<>1) and (expirationDate is null or expirationDate >= '" + currentDate + "') and belongYear='" + selectedYear + "' and leaveRulesId=" + leaveRulesId + " " + + "group by resourceId) b " + + "on a.id = b.resourceId where 1=1 "; + } + if (dataScope.equals("0")) { + //总部 + } else if (dataScope.equals("1")) { + sql += " and a.subcompanyId1 in (" + subcomId + ") "; + } else if (dataScope.equals("2")) { + sql += " and a.departmentId in (" + deptId + ") "; + } else if (dataScope.equals("3")) { + sql += " and a.id in (" + resourceId + ")"; + } else if (dataScope.equals("4")) { + if (allLevel.equals("1")) { + sql += " and (a.id=" + user.getUID() + " or a.managerStr like '%," + user.getUID() + ",%' )"; + } else { + sql += " and (a.id=" + user.getUID() + " or a.managerid = " + user.getUID() + ")"; + } + } + + if(resourceStatus.length()>0){ + if (!resourceStatus.equals("8") && !resourceStatus.equals("9")) { + sql += " and a.status = "+resourceStatus+ ""; + }else if (resourceStatus.equals("8")) { + sql += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + if (isNoAccount.equals("false")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver") + || recordSet.getDBType().equalsIgnoreCase("mysql")) { + sql += " and (loginId is not null and loginId<>'')"; + } else { + sql += " and (loginId is not null)"; + } + } + //考勤报表共享设置 + if (!rightStr.equals("") && !dataScope.equals("4")) { + sql += rightStr; + } + if (!recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sql += " order by dspOrder,hrmResourceId "; + } + if (!showAll) { + String pageSql = "select * from (select tmp.*,rownum rn from (" + sql + ") tmp where rownum<=" + (pageSize * currentPage) + ") where rn>=" + (pageSize * (currentPage - 1) + 1); + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + pageSql = "select t.* from (" + sql + ") t where 1=1 and rn>=" + (pageSize * (currentPage - 1) + 1) + " and rn<=" + (pageSize * currentPage); + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + pageSql = sql + " limit " + (currentPage - 1) * pageSize + "," + pageSize; + }else if (recordSet.getDBType().equalsIgnoreCase("postgresql")) { + pageSql = sql + " limit " + pageSize + " offset " + (currentPage - 1) * pageSize; + } + recordSet.executeQuery(pageSql); + } else { + recordSet.executeQuery(sql); + } + while (recordSet.next()) { + String hrmResourceId = Util.null2String(recordSet.getString("hrmResourceId")); + BigDecimal allBaseAmount = new BigDecimal(Util.null2s(recordSet.getString("allBaseAmount"), "0")); + BigDecimal allExtraAmount = new BigDecimal(Util.null2s(recordSet.getString("allExtraAmount"), "0")); + BigDecimal allUsedAmount = new BigDecimal(Util.null2s(recordSet.getString("allUsedAmount"), "0")); + + balanceMap.put(hrmResourceId + "_" + leaveRulesId, allBaseAmount.add(allExtraAmount).subtract(allUsedAmount)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return balanceMap; + } + + /** + * 插入或者更新员工假期余额 + * + * @param newBalanceEntities 新假期余额 + * @param oldBalanceEntities 旧假期余额 + * @param operator 操作者 + * @param canUpdate 是否允许更新 + * @return + */ + private static boolean insertOrUpdateBalance(List newBalanceEntities, Map oldBalanceEntities, String operator, boolean canUpdate) { + /*获取今天的日期、此刻的时间*/ + Calendar today = Calendar.getInstance(); + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + String currentTime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" + + Util.add0(today.get(Calendar.MINUTE), 2) + ":" + + Util.add0(today.get(Calendar.SECOND), 2); + + RecordSet recordSet1 = new RecordSet(); + java.sql.Timestamp date = KQDateUtil.getUpdateTimeStamp(); + String insertSql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,baseAmount,extraAmount,usedAmount,baseAmount2,extraAmount2,usedAmount2,create_time,update_time,creator,effectiveDate,expirationDate) " + + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + if (recordSet1.getDBType().equals("postgresql")) { + insertSql = "insert into kq_balanceOfLeave(leaveRulesId,resourceId,belongYear,baseAmount,extraAmount,usedAmount,baseAmount2,extraAmount2,usedAmount2,create_time,update_time,creator,effectiveDate,expirationDate) " + + "values(?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?,?,?)"; + } + List insertList = new ArrayList(); + List insertParamList = new ArrayList(); + String updateSql = "update kq_balanceOfLeave set leaveRulesId=?,resourceId=?,belongYear=?,baseAmount=?,baseAmount2=?,update_time=?,effectiveDate=?,expirationDate=? where id=?"; + String updateSql2 ="update kq_balanceOfLeave set leaveRulesId=?,resourceId=?,belongYear=?,baseAmount=?,baseAmount2=?,usedAmount=?,extraAmount=?,update_time=?,effectiveDate=?,expirationDate=? where id=?"; + + if (recordSet1.getDBType().equals("postgresql")) { + updateSql = "update kq_balanceOfLeave set leaveRulesId=?,resourceId=?,belongYear=?,baseAmount=?,baseAmount2=?,update_time=?::timestamp,effectiveDate=?,expirationDate=? where id=?"; + updateSql2 ="update kq_balanceOfLeave set leaveRulesId=?,resourceId=?,belongYear=?,baseAmount=?,baseAmount2=?,usedAmount=?,extraAmount=?,update_time=?::timestamp,effectiveDate=?,expirationDate=? where id=?"; + } + List updateList = new ArrayList(); + List updateParamList = new ArrayList(); + List updateParamList2 = new ArrayList(); + List usageHistoryEntities = new ArrayList(); + KQUsageHistoryEntity usageHistoryEntity = null; + for (KQBalanceOfLeaveEntity newBalanceEntity : newBalanceEntities) { + int resourceId = newBalanceEntity.getResourceId(); + int status = newBalanceEntity.getStatus(); + KQBalanceOfLeaveEntity oldBalanceEntity = (KQBalanceOfLeaveEntity) oldBalanceEntities.get("" + resourceId); + if (status == 1) { + String belongYear = newBalanceEntity.getBelongYear(); + String ruleId = newBalanceEntity.getLeaveRulesId() + ""; + Map oldBalanceEntitiesLast = getBalanceEntities(3, resourceId + "", ruleId, belongYear); + oldBalanceEntity = (KQBalanceOfLeaveEntity) oldBalanceEntitiesLast.get("" + resourceId); + } + if (oldBalanceEntity == null || oldBalanceEntity.getId() <= 0) { + insertList = new ArrayList(); + insertList.add(newBalanceEntity.getLeaveRulesId()); + insertList.add(newBalanceEntity.getResourceId()); + insertList.add(newBalanceEntity.getBelongYear()); + insertList.add(newBalanceEntity.getBaseAmount()); + insertList.add(newBalanceEntity.getExtraAmount()); + insertList.add(newBalanceEntity.getUsedAmount()); + insertList.add(newBalanceEntity.getBaseAmount2()); + insertList.add(newBalanceEntity.getExtraAmount2()); + insertList.add(newBalanceEntity.getUsedAmount2()); + insertList.add(date); + insertList.add(date); + insertList.add(Util.getIntValue(resourceId)); + insertList.add(newBalanceEntity.getEffectiveDate()); + insertList.add(newBalanceEntity.getExpirationDate()); + insertParamList.add(insertList); + + usageHistoryEntity = new KQUsageHistoryEntity(); + usageHistoryEntity.setLeaveRulesId("" + newBalanceEntity.getLeaveRulesId()); + usageHistoryEntity.setRelatedId("" + newBalanceEntity.getResourceId()); + usageHistoryEntity.setOperator("" + operator); + usageHistoryEntity.setOperateDate(currentDate); + usageHistoryEntity.setOperateTime(currentTime); + usageHistoryEntity.setOperateType("6"); + usageHistoryEntity.setBelongYear(newBalanceEntity.getBelongYear()); + usageHistoryEntity.setNewBaseAmount("" + newBalanceEntity.getBaseAmount()); + usageHistoryEntity.setNewExtraAmount("" + newBalanceEntity.getExtraAmount()); + usageHistoryEntity.setNewUsedAmount("" + newBalanceEntity.getUsedAmount()); + usageHistoryEntity.setNewBaseAmount2("" + newBalanceEntity.getBaseAmount2()); + usageHistoryEntity.setNewExtraAmount2("" + newBalanceEntity.getExtraAmount2()); + usageHistoryEntity.setNewUsedAmount2("" + newBalanceEntity.getUsedAmount2()); + usageHistoryEntity.setOldMinimumUnit("" + newBalanceEntity.getMinimumUnit()); + usageHistoryEntity.setNewMinimumUnit("" + newBalanceEntity.getMinimumUnit()); + usageHistoryEntity.setInsertOrUpdate("insert"); + usageHistoryEntities.add(usageHistoryEntity); + } else { + updateList = new ArrayList(); + updateList.add(newBalanceEntity.getLeaveRulesId()); + updateList.add(newBalanceEntity.getResourceId()); + updateList.add(newBalanceEntity.getBelongYear()); + updateList.add(newBalanceEntity.getBaseAmount()); + updateList.add(newBalanceEntity.getBaseAmount2()); + if(status==1){ + updateList.add(newBalanceEntity.getUsedAmount()); + updateList.add(newBalanceEntity.getExtraAmount()); + } + updateList.add(date); + updateList.add(newBalanceEntity.getEffectiveDate()); + updateList.add(newBalanceEntity.getExpirationDate()); + updateList.add(oldBalanceEntity.getId()); + if(status==1){ + updateParamList2.add(updateList); + }else{ + updateParamList.add(updateList); + } + + usageHistoryEntity = new KQUsageHistoryEntity(); + usageHistoryEntity.setLeaveRulesId("" + newBalanceEntity.getLeaveRulesId()); + usageHistoryEntity.setRelatedId("" + newBalanceEntity.getResourceId()); + usageHistoryEntity.setOperator("" + operator); + usageHistoryEntity.setOperateDate(currentDate); + usageHistoryEntity.setOperateTime(currentTime); + usageHistoryEntity.setOperateType("6"); + usageHistoryEntity.setBelongYear(newBalanceEntity.getBelongYear()); + usageHistoryEntity.setOldBaseAmount("" + oldBalanceEntity.getBaseAmount()); + usageHistoryEntity.setNewBaseAmount("" + newBalanceEntity.getBaseAmount()); + if(status==1){ + usageHistoryEntity.setOldUsedAmount("" + oldBalanceEntity.getUsedAmount()); + usageHistoryEntity.setNewUsedAmount("" + newBalanceEntity.getUsedAmount()); + usageHistoryEntity.setOldExtraAmount("" + oldBalanceEntity.getExtraAmount()); + usageHistoryEntity.setNewExtraAmount("" + newBalanceEntity.getExtraAmount()); + } + usageHistoryEntity.setOldBaseAmount2("" + oldBalanceEntity.getBaseAmount2()); + usageHistoryEntity.setNewBaseAmount2("" + newBalanceEntity.getBaseAmount2()); + usageHistoryEntity.setOldMinimumUnit("" + oldBalanceEntity.getMinimumUnit()); + usageHistoryEntity.setNewMinimumUnit("" + newBalanceEntity.getMinimumUnit()); + usageHistoryEntity.setInsertOrUpdate("update"); + usageHistoryEntities.add(usageHistoryEntity); + } + } + + boolean isSuccess = true; + RecordSet recordSet = new RecordSet(); + /*新增员工假期余额数据 start*/ + if (insertParamList.size() > 0) { + isSuccess = recordSet.executeBatchSql(insertSql, insertParamList); + } + /*新增员工假期余额数据 end*/ + + /*更新员工假期余额数据 start*/ + if (updateParamList.size() > 0) { + isSuccess = recordSet.executeBatchSql(updateSql, updateParamList); + } + if (updateParamList2.size() > 0) { + isSuccess = recordSet.executeBatchSql(updateSql2, updateParamList2); + } + /*更新员工假期余额数据 end*/ + + /*记录员工假期余额变更记录 start*/ + KQUsageHistoryBiz kqUsageHistoryBiz = new KQUsageHistoryBiz(); + if (usageHistoryEntities.size() > 0) { + isSuccess = kqUsageHistoryBiz.save(usageHistoryEntities); + } + /*记录员工假期余额变更记录 end*/ + + return isSuccess; + } + + /** + * 根据[工龄]、[司龄]获取对应的假期基数 + * + * @param distributionMode [发放方式] + * @param rulesDetailId [假期规则的ID] + * @param annualAmount [发放方式]=[4-每年发放固定天数]时的[固定天数] + * @param ageLimit [工龄]or[司龄]、当[发放方式]=[6-按司龄+工龄自动发放]时的[工龄] + * @param ageLimit2 当[发放方式]=[6-按司龄+工龄自动发放]时的[司龄] + * @param legalKey [法定年假规则]:当[发放方式]=[6-按司龄+工龄自动发放]时有效 + * @param welfareKey [福利年假规则]:当[发放方式]=[6-按司龄+工龄自动发放]时有效 + * @param legalOrWelfare 是计算[法定年假]还是计算[福利年假]:legal-[法定年假]、welfare-[福利年假] + * @return [假期基数] + */ + private static BigDecimal getAmountByAgeLimit(int distributionMode, String rulesDetailId, double annualAmount, + int ageLimit, int ageLimit2, int legalKey, int welfareKey, String legalOrWelfare) { + BigDecimal amount = new BigDecimal("0"); + try { + RecordSet recordSet = new RecordSet(); + if (distributionMode == 2 || distributionMode == 7) { + String sql = "select * from kq_entryToLeave where leaveRulesId=? and lowerLimit<=? and upperLimit>?"; + recordSet.executeQuery(sql, rulesDetailId, ageLimit, ageLimit); + if (recordSet.next()) { + double _amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + amount = new BigDecimal("" + _amount); + } + } else if (distributionMode == 3) { + String sql = "select * from kq_workingAgeToLeave where leaveRulesId=? and lowerLimit<=? and upperLimit>?"; + recordSet.executeQuery(sql, rulesDetailId, ageLimit, ageLimit); + if (recordSet.next()) { + double _amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + amount = new BigDecimal("" + _amount); + } + } else if (distributionMode == 4) { + amount = new BigDecimal("" + annualAmount); + } else if (distributionMode == 6) { + String sql = ""; + if (legalOrWelfare.equals("legal")) { + sql = "select * from kq_MixModeToLegalLeave where 1=1 and leaveRulesId=" + rulesDetailId; + if (legalKey == 0) { + sql += " and limit1<=" + ageLimit; + } else if (legalKey == 1) { + sql += " and limit2<=" + ageLimit2; + } else if (legalKey == 2) { + sql += " and limit1<=" + ageLimit + " and limit2<=" + ageLimit2; + } + } else { + sql = "select * from kq_MixModeToWelfareLeave where 1=1 and leaveRulesId=" + rulesDetailId; + if (welfareKey == 0) { + sql += " and limit1<=" + ageLimit; + } else if (welfareKey == 1) { + sql += " and limit2<=" + ageLimit2; + } else if (welfareKey == 2) { + sql += " and limit1<=" + ageLimit + " and limit2<=" + ageLimit2; + } + } + sql += " order by id desc "; + recordSet.executeQuery(sql); + if (recordSet.next()) { + double _amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + amount = new BigDecimal("" + _amount); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return amount; + } + + + private static ThreadLocal simpleDateFormatThreadLocal = new ThreadLocal<>(); + + private static void init() { + if (simpleDateFormatThreadLocal.get() == null) { + simpleDateFormatThreadLocal.set(new SimpleDateFormat("yyyy-MM-dd")); + } + } + + /** + * 获取两个日期之间的时间差距有几年 + * + * @param fromDate 开始时间 + * @param toDate 结束时间 + * @return + */ + public static int getAgeLimit(String fromDate, String toDate) { + init(); + int ageLImit = 0; + try { + if (toDate.compareTo(fromDate) < 0) { + return -1; + } + Date fd = simpleDateFormatThreadLocal.get().parse(fromDate); + Date td = simpleDateFormatThreadLocal.get().parse(toDate); + Instant fInstant = fd.toInstant(); + Instant tInstant = td.toInstant(); + LocalDate localFromDate = LocalDateTime.ofInstant(fInstant, ZoneId.systemDefault()).toLocalDate(); + LocalDate localToDate = LocalDateTime.ofInstant(tInstant, ZoneId.systemDefault()).toLocalDate(); + + //LocalDate localFromDate = LocalDate.parse(fromDate); + //LocalDate localToDate = LocalDate.parse(toDate); + Period period = Period.between(localFromDate, localToDate); + ageLImit = period.getYears(); + } catch (Exception e) { + e.printStackTrace(); + } + return ageLImit; + } + + + /****************************************************下面是正式系统用的****************************************************/ + + /** + * 获取年假、带薪事假、带薪病假、调休的假期余额信息 + * + * @param resourceId 指定人员ID + * @param languageId 当前系统语言 + * @return + */ + public static List getBalanceInfo(String resourceId, int languageId) { + String resultStr = ""; + List dataList = new ArrayList(); + try { + /*获取当前日期,当前时间*/ + Calendar today = Calendar.getInstance(); + String lastDayOfLastYear = Util.add0(today.get(Calendar.YEAR) - 1, 4) + "-12-31"; + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + + Map itemMap = new HashMap(); + List itemList = new ArrayList(); + Map dataMap = new HashMap(); + + String sql = "select * from kq_LeaveRules where 1=1 and (isDelete is null or isDelete<>1) and isEnable=1 and leaveCode in ('annualLeave','paidCompassionateLeave','paidSickLeave','vacationLeave')"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + while (recordSet.next()) { + String ruleId = recordSet.getString("id"); + String leaveCode = recordSet.getString("leaveCode"); + + String title = ""; + switch (leaveCode) { + case "annualLeave": + title = SystemEnv.getHtmlLabelName(501313, languageId); + break; + case "paidCompassionateLeave": + title = SystemEnv.getHtmlLabelName(501314, languageId); + break; + case "paidSickLeave": + title = SystemEnv.getHtmlLabelName(501315, languageId); + break; + case "vacationLeave": + title = SystemEnv.getHtmlLabelName(31297, languageId); + break; + default: + break; + } + + String minimumUnit = kqLeaveRulesComInfo.getMinimumUnit(ruleId);//最小请假单位:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假 + + String currentYearAmount = getRestAmount(resourceId, ruleId, currentDate, true, false);//本年剩余年假时长 + String allAmount = getRestAmount(resourceId, ruleId, currentDate, true, true);//当前剩余年假时长 + String lastYearAmount = String.format("%.2f", Util.getDoubleValue(allAmount, 0) - Util.getDoubleValue(currentYearAmount, 0));;//历年剩余年假时长 + + itemList = new ArrayList(); + if (!leaveCode.equals("vacationLeave")) { + itemMap = new HashMap(); + itemMap.put("name", KQUnitBiz.isLeaveHour(minimumUnit+"") ? SystemEnv.getHtmlLabelName(513286, languageId) : SystemEnv.getHtmlLabelName(513287, languageId)); + itemMap.put("value", lastYearAmount); + itemList.add(itemMap); + itemMap = new HashMap(); + itemMap.put("name", KQUnitBiz.isLeaveHour(minimumUnit+"") ? SystemEnv.getHtmlLabelName(501311, languageId) : SystemEnv.getHtmlLabelName(132012, languageId)); + itemMap.put("value", currentYearAmount); + itemList.add(itemMap); + } + itemMap = new HashMap(); + itemMap.put("name", KQUnitBiz.isLeaveHour(minimumUnit+"") ? SystemEnv.getHtmlLabelName(513288, languageId) : SystemEnv.getHtmlLabelName(513289, languageId)); + itemMap.put("value", allAmount); + itemList.add(itemMap); + + dataMap = new HashMap(); + dataMap.put("detail", itemList); + dataMap.put("title", title); + dataMap.put("leaveCode", leaveCode); + + dataList.add(dataMap); + } + } catch (Exception e) { + e.printStackTrace(); + } + return dataList; + } + + /** + * 获取正式系统请假流程协同区所需的相关数据 + * + * @param resourceId + * @param searchYear + * @return + */ + public static Map getSynergyZoneInfo(String resourceId, String searchYear) { + Map resultMap = new HashMap(); + try { + /*获取当前日期,当前时间*/ + Calendar today = Calendar.getInstance(); + String lastDayOfLastYear = Util.add0(today.get(Calendar.YEAR) - 1, 4) + "-12-31"; + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + + double usedAmount1 = 0.00;//年假已用 + double restAmount1 = 0.00;//年假剩余 + + String sql = "select * from kq_leaveRules where 1=1 and (isDelete is null or isDelete <>1) and leaveCode='annualLeave'"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + if (recordSet.next()) { + String ruleId = recordSet.getString("id"); + + sql = "select * from kq_BalanceOfLeave where belongYear=? and resourceId=? and leaveRulesId=?"; + recordSet.executeQuery(sql, searchYear, resourceId, ruleId); + if (recordSet.next()) { + usedAmount1 = Util.getDoubleValue(recordSet.getString("usedAmount"), 0.00); + } + restAmount1 = Util.getDoubleValue(getRestAmount(resourceId, ruleId, currentDate, true, false), 0.00); + } + + double usedAmount2 = 0.00;//带薪病假已用 + double restAmount2 = 0.00;//带薪病假剩余 + + sql = "select * from kq_leaveRules where 1=1 and (isDelete is null or isDelete <>1) and leaveCode='paidSickLeave'"; + recordSet.executeQuery(sql); + if (recordSet.next()) { + String ruleId = recordSet.getString("id"); + + sql = "select * from kq_BalanceOfLeave where belongYear=? and resourceId=? and leaveRulesId=?"; + recordSet.executeQuery(sql, searchYear, resourceId, ruleId); + if (recordSet.next()) { + usedAmount2 = Util.getDoubleValue(recordSet.getString("usedAmount"), 0.00); + } + restAmount2 = Util.getDoubleValue(getRestAmount(resourceId, ruleId, currentDate, true, false), 0.00); + } + + double usedAmount3 = 0.00;//带薪事假已用 + sql = "select * from kq_leaveRules where 1=1 and (isDelete is null or isDelete <>1) and leaveCode='paidCompassionateLeave'"; + recordSet.executeQuery(sql); + if (recordSet.next()) { + String ruleId = recordSet.getString("id"); + + sql = "select * from kq_BalanceOfLeave where belongYear=? and resourceId=? and leaveRulesId=?"; + recordSet.executeQuery(sql, searchYear, resourceId, ruleId); + if (recordSet.next()) { + usedAmount3 = Util.getDoubleValue(recordSet.getString("usedAmount"), 0.00); + } + } + + + double restAmount4 = 0.00;//调休剩余 + sql = "select * from kq_leaveRules where 1=1 and (isDelete is null or isDelete <>1) and leaveCode='vacationLeave'"; + recordSet.executeQuery(sql); + if (recordSet.next()) { + String ruleId = recordSet.getString("id"); + + restAmount4 = Util.getDoubleValue(getRestAmount(resourceId, ruleId, currentDate, true, false), 0.00); + } + + resultMap.put("usedAmount1", usedAmount1); + resultMap.put("restAmount1", restAmount1); + resultMap.put("usedAmount2", usedAmount2); + resultMap.put("restAmount2", restAmount2); + resultMap.put("usedAmount3", usedAmount3); + resultMap.put("restAmount4", restAmount4); + } catch (Exception e) { + e.printStackTrace(); + } + return resultMap; + } + + /** + * 获取年假开始日期 + * + * @param resourceId 人员ID + * @return + */ + private static String getAnnualDate(String resourceId) { + String result = ""; + try { + String sql = "select t2.field3 annualDate from hrmResource t1 left join cus_fielddata t2 on t1.id=t2.id and t2.scope='HrmCustomFieldByInfoType' and t2.scopeid=-1 where t1.id=" + resourceId; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + if (recordSet.next()) { + String annualDate = recordSet.getString("annualDate"); + if (annualDate.contains("\\/")) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/M/dd"); + Date date = simpleDateFormat.parse(annualDate); + simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + annualDate = simpleDateFormat.format(date); + } catch (Exception e) { + e.printStackTrace(); + annualDate = ""; + } + } + Pattern pattern = Pattern.compile("^\\d{4}\\-\\d{2}\\-\\d{2}$"); + Matcher matcher_1 = pattern.matcher(annualDate); + if (!annualDate.equals("") && matcher_1.matches()) { + result = annualDate; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + public static void logOvertimeMap(Map overtimeLogMap,Object params, String keys){ + if(overtimeLogMap != null){ + overtimeLogMap.put(keys, params); + } + } + /** + * 获取育儿假开始日期 + * + * @param resourceId 人员ID + * @return + */ + public static ArrayList getParentalLeaveDate(String resourceId) { + ArrayList list = new ArrayList<>(); + try { + String sql = "select birthday from hrmfamilyinfo where WhetherChildren=1 and resourceid=? order by birthday "; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql,resourceId); + while (recordSet.next()) { + String annualDate = recordSet.getString("birthday"); + if (annualDate.contains("\\/")) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/M/dd"); + Date date = simpleDateFormat.parse(annualDate); + simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + annualDate = simpleDateFormat.format(date); + } catch (Exception e) { + e.printStackTrace(); + annualDate = ""; + } + } + Pattern pattern = Pattern.compile("^\\d{4}\\-\\d{2}\\-\\d{2}$"); + Matcher matcher_1 = pattern.matcher(annualDate); + if (!annualDate.equals("") && matcher_1.matches()) { + list.add(annualDate); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } + + /** + * 获取人员的省份 + * @return + */ + private static void getChildrenProvinceId(String leaveRulesId, String locationid, Map params ) { + RecordSet rs = new RecordSet(); + String provinceid = "0"; + params.put("yearsOld","0"); + params.put("annualAmount","0"); + try { + if(StringUtil.isNotNull(locationid)){ + String sql = "select * from hrmcity where id in (select locationcity from HrmLocations where id = " + locationid + " )"; + rs.executeSql(sql); + while (rs.next()) { + provinceid = Util.null2s(rs.getString("provinceid"),"0"); + } + } + if(!provinceid.equals("0")){ + String sql = "select * from kq_provinceToLeave where leaveRulesId = " + leaveRulesId + " and provinceid= " + provinceid; + rs.executeQuery(sql); + if (rs.next()) { + int yearsOldValue = rs.getInt("yearsOld"); + double amount = Util.getDoubleValue(rs.getString("amount"), 0); + params.put("yearsOld",yearsOldValue); + params.put("annualAmount",amount); + } + } + } catch (Exception e) { + rs.writeLog(e); + } + } + + // qc 获取孩子的记录id + public static ArrayList getChildId(String resourceId) { + ArrayList list = new ArrayList<>(); + try { + String sql = "select id from hrmfamilyinfo where WhetherChildren=1 and resourceid=? order by birthday "; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql,resourceId); + while (recordSet.next()) { + String id = recordSet.getString("id"); + list.add(id); + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } + public static ArrayList getChildBean(String resourceId) { + ArrayList list = new ArrayList<>(); + try { + String sql = "select id,birthday,member from hrmfamilyinfo where WhetherChildren=1 and resourceid=? order by birthday "; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql,resourceId); + KQChildrenBean bean = null; + while (recordSet.next()) { + bean = new KQChildrenBean(); + String id = recordSet.getString("id"); + String birthday = recordSet.getString("birthday"); + String title = recordSet.getString("member"); + bean.setId(id); + bean.setBirthday(birthday); + bean.setTitle(title); + bean.setResourceid(resourceId); + list.add(bean); + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } +} diff --git a/src/com/engine/kq/biz/KQLeaveRulesBiz.java b/src/com/engine/kq/biz/KQLeaveRulesBiz.java new file mode 100644 index 0000000..b0c4b4c --- /dev/null +++ b/src/com/engine/kq/biz/KQLeaveRulesBiz.java @@ -0,0 +1,1307 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSONObject; +import com.api.hrm.util.ServiceUtil; +import com.engine.kq.entity.KQBalanceOfLeaveEntity; +import com.engine.kq.log.KQLog; +import com.engine.kq.util.KQTransMethod; +import com.weaver.general.TimeUtil; +import org.apache.commons.lang.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.StringUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.common.Tools; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.util.*; + +public class KQLeaveRulesBiz { + + public static final ThreadLocal THREAD_LOCAL = new ThreadLocal<>(); + + + /** + * 记录日志 + */ + private static KQLog logger = new KQLog(); + + /** + * 根据假期规则ID获取假期规则名称 + * + * @param ruleId 假期规则的ID + * @return + */ + public static String getLeaveName(String ruleId) { + String leaveName = ""; + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + leaveName = kqLeaveRulesComInfo.getLeaveName(ruleId); + return leaveName; + } + + /** + * 判断是否具有假期余额 + * + * @param ruleId + * @return + */ + public static boolean getBalanceEnable(String ruleId) { + int balanceEnable = 0; + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + balanceEnable = Util.getIntValue(kqLeaveRulesComInfo.getBalanceEnable(ruleId), 0); + if (balanceEnable == 1) { + return true; + } else { + return false; + } + } + /** + * 判断优先假期类型id字符串 + * + * @param ruleId + * @return + */ + public static String getLeaveids(String ruleId) { + int schevacationON = 0; + String schevacation = "-1"; + + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + schevacationON = Util.getIntValue(kqLeaveRulesComInfo.getSchevacationON(ruleId), 0); + if (schevacationON == 1) { + schevacation=Util.null2s(kqLeaveRulesComInfo.getSchevacation(ruleId), "-1"); + } + return schevacation; + + } + + /** + * 判断人员的假期类型id字符串 + * + * @param scheLeaveids + * @param resourceId + * @return + */ + public static String getusedLeaveids(String scheLeaveids, String resourceId) { + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subcompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + + List scheLeaveidsList = Util.splitString2List(scheLeaveids, ","); + + /** + * 加载应用范围为总部的以及应用范围为分部(但是范围中包含了所属分部ID)的假期规则 + */ + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_LeaveRules "; + String sqlWhere = " where (isDelete is null or isDelete <>1) and isEnable=1 and balanceEnable=1 "; + /*如果找不到人员所在分部,则只返回应用范围为总部的假期规则*/ + if (!resourceId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere += " and ( (scopeType=3 and ','+scopeValue+',' like '%," + resourceId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere += " and ( (scopeType=3 and concat(',',scopeValue,',') like '%," + resourceId + ",%') "; + } else { + sqlWhere += " and ( (scopeType=3 and ','||scopeValue||',' like '%," + resourceId + ",%') "; + } + } + if (!departmentId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere += " or (scopeType=2 and ','+scopeValue+',' like '%," + departmentId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere += " or (scopeType=2 and concat(',',scopeValue,',') like '%," + departmentId + ",%') "; + } else { + sqlWhere += " or (scopeType=2 and ','||scopeValue||',' like '%," + departmentId + ",%') "; + } + } + if (!subcompanyId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere += " or (scopeType=1 and ','+scopeValue+',' like '%," + subcompanyId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere += " or (scopeType=1 and concat(',',scopeValue,',') like '%," + subcompanyId + ",%') "; + } else { + sqlWhere += " or (scopeType=1 and ','||scopeValue||',' like '%," + subcompanyId + ",%') "; + } + } + + sqlWhere += " or scopeType=0 )"; + sql = sql + sqlWhere + " order by showOrder,id "; + scheLeaveids = ""; + List remleaveidsList = new ArrayList<>(); + recordSet.executeQuery(sql); + /*如果指定人员所在分部下面单独设置过假期规则,则取分部下面的假期规则*/ + while (recordSet.next()) { + String leaveid = recordSet.getString("id");//假期类型id + remleaveidsList.add(leaveid); + } + + for (String id : scheLeaveidsList) { + if (remleaveidsList.contains(id)) { + if (scheLeaveids.equals("")) { + scheLeaveids = id; + } else { + scheLeaveids += "," + id; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return scheLeaveids; + + } + /** + * 获取最小请假单位 + * 1-按天请假 + * 2-按半天请假 + * 3-按小时请假 + * 4-按整天请假 + * 其他:无效数据 + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static int getMinimumUnit(String ruleId) { + int minimumUnit = -1;//最小请假单位 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + minimumUnit = Util.getIntValue(kqLeaveRulesComInfo.getMinimumUnit(ruleId), -1); + return minimumUnit; + } + + /** + * 获取请假时长计算方式 + * 1-按照工作日计算请假时长 + * 2-按照自然日计算请假时长 + * 其他:无效数据 + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static int getComputingMode(String ruleId) { + int computingMode = -1;//计算请假时长方式 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + computingMode = Util.getIntValue(kqLeaveRulesComInfo.getComputingMode(ruleId), -1); + return computingMode; + } + + /** + * 按照自然日计算请假时长排除节假日、休息日 + * 0-不排除 + * 1-排除节假日 + * 2-排除休息日 + * 1,2-排除节假日和休息日 + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static String getFilterHolidays(String ruleId) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + String filterHolidays = Util.null2s(kqLeaveRulesComInfo.getFilterHolidays(ruleId), "0"); + return filterHolidays; + } + + /** + * 获取日折算时长(多少小时算一天) + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static String getHoursToDay(String ruleId) { + double hoursToDay = -1;//日折算时长 + int computingMode = -1;//计算请假时长方式 + int minimumUnit = -1;//最小请假单位 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + hoursToDay = Util.getDoubleValue(kqLeaveRulesComInfo.getHoursToDay(ruleId), -1); + computingMode = Util.getIntValue(kqLeaveRulesComInfo.getComputingMode(ruleId), -1); + minimumUnit = Util.getIntValue(kqLeaveRulesComInfo.getMinimumUnit(ruleId), -1); + if (computingMode != 2) { + hoursToDay = -1; + } + return String.format("%.2f", hoursToDay); + } + + /** + * 1-按天请假 + * 2-按半天请假 + * 3-按小时请假 + * 4-按整天请假 + * + * @param minimumUnit + * @param lan + * @return + */ + public static String getMinimumUnitName(String minimumUnit, int lan) { + String minimumUnitName = ""; + switch (minimumUnit) { + case "1": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + case "2": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + case "3": + case "5": + case "6": + minimumUnitName = SystemEnv.getHtmlLabelName(391, lan); + break; + case "4": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + default: + break; + } + return minimumUnitName; + } + + /** + * 获取所有的假期规则 + * unitType:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假、-1:数据异常,无效数据 + * + * @return + */ + public static List> getAllLeaveRules() { + Map ruleMap = new HashMap(); + List> ruleList = new ArrayList>(); + + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + kqLeaveRulesComInfo.setTofirstRow(); + while (kqLeaveRulesComInfo.next()) { + if (kqLeaveRulesComInfo.getIsEnable().equals("1")) { + ruleMap = new HashMap(); + ruleMap.put("id", kqLeaveRulesComInfo.getId()); + ruleMap.put("name", kqLeaveRulesComInfo.getLeaveName()); + ruleMap.put("unitType", kqLeaveRulesComInfo.getMinimumUnit()); + ruleMap.put("proportion", kqLeaveRulesComInfo.getProportion()); + ruleMap.put("scopeType",kqLeaveRulesComInfo.getScopeType()); + ruleMap.put("scopeValue",kqLeaveRulesComInfo.getScopeValue()); + ruleList.add(ruleMap); + } + } + return ruleList; + } + + /** + * 根据人员ID获取其可见的所有假期类型 + * + * @param resourceId 指定人员ID + * @return + */ + public static String getAllLeaveRulesByUserId(String resourceId, String languageId) { + String resultStr = ""; + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subcomId = resourceComInfo.getSubCompanyID(resourceId); + String deptId = resourceComInfo.getDepartmentID(resourceId); + + List tempList = new ArrayList(); + + Map itemMap = new HashMap(); + List itemList = new ArrayList(); + + String sql = "select * from kq_leaveRules where 1=1 and (isDelete is null or isDelete <>1) and isEnable=1"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + while (recordSet.next()) { + String scopeType = recordSet.getString("scopeType"); + String scopeValue = recordSet.getString("scopeValue"); + String leaveName = recordSet.getString("leaveName"); + String id = recordSet.getString("id"); + + if (scopeType.equals("1")) { + tempList = Util.TokenizerString(scopeValue, ","); + if (!tempList.contains(subcomId)) { + continue; + } + } + + itemMap = new HashMap(); + itemMap.put("name", Util.formatMultiLang(leaveName, languageId)); + itemMap.put("id", id); + itemList.add(itemMap); + } + resultStr = JSONObject.toJSONString(itemList); + } catch (Exception e) { + e.printStackTrace(); + } + return resultStr; + } + public static boolean filterSubLeaveRule(KQLeaveRulesComInfo kqLeaveRulesComInfo, User user, String leaveId) { + return filterSubLeaveRule(Util.null2String(user.getUID()), kqLeaveRulesComInfo.getScopeType(leaveId), kqLeaveRulesComInfo.getScopeValue(leaveId), Util.null2String(user.getUserSubCompany1()),Util.null2String(user.getUserDepartment())); + } + public static boolean filterSubLeaveRule(String userId, String scopeType, String scopeValue, String subCompany, String deptId) { + boolean isAdmin = ServiceUtil.isAdmin(userId); + if (isAdmin) { + return false; + } + if ("1".equals(scopeType)) { + if (scopeValue.indexOf(",") > 0) { + String[] split = scopeValue.split(","); + for (String v : split) { + if (!StringUtil.isEmpty(v) && v.equals(subCompany)) { + return false; + } + } + return true; + } else { + return !scopeValue.equals(subCompany); + } + }else if("2".equals(scopeType)){ + if (scopeValue.indexOf(",") > 0) { + String[] split = scopeValue.split(","); + for (String v : split) { + if (!StringUtil.isEmpty(v) && v.equals(deptId)) { + return false; + } + } + return true; + } else { + return !scopeValue.equals(deptId); + } + }else if("3".equals(scopeType)){ + if (scopeValue.indexOf(",") > 0) { + String[] split = scopeValue.split(","); + for (String v : split) { + if (!StringUtil.isEmpty(v) && v.equals(userId)) { + return false; + } + } + return true; + } else { + return !scopeValue.equals(userId); + } + } + return false; + } + /** + * 初始化年假 + * + * @param ruleId + * @return + */ + public static boolean initAnnualLeave(int ruleId) { + boolean isInitSuccess = false; + try { + /*判断年假是否初始化过*/ + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='年假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=1," + + "isDelete=0,isEnable=1,leaveCode='annualLeave' where id=" + ruleId; + isInitSuccess = recordSet.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + + String deleteDetailSql = "delete from kq_LeaveRulesDetail where scopeType=0 and ruleId=" + ruleId; + recordSet.executeUpdate(deleteDetailSql); + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('年假-总部规则'," + ruleId + ",0,'',3,0,1,0,'','',0,0,0,0)"; + isInitSuccess = recordSet.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'年假-初始化',0,'',1,8,1,1,0,1,'annualLeave')"; + isInitSuccess = recordSet.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('年假-总部规则'," + nextId + ",0,'',3,0,1,0,'','',0,0,0,0)"; + isInitSuccess = recordSet.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set annualLeave=" + nextId + " where id=1"; + isInitSuccess = recordSet.executeUpdate(historySql); + + ruleId = nextId; + } + + String detailId = ""; + sql = "select * from kq_LeaveRulesDetail where scopeType=0 and ruleId=" + ruleId; + recordSet.executeQuery(sql); + if (recordSet.next()) { + detailId = recordSet.getString("id"); + } + if (detailId.equals("")) { + return false; + } + + /*先删除原来的明细记录,在插入新的明细记录*/ + String detailSql = "delete from kq_WorkingAgeToLeave where leaveRulesId=" + detailId; + isInitSuccess = recordSet.executeUpdate(detailSql); + if (!isInitSuccess) { + sql = "delete from kq_LeaveRules where leaveRulesId=" + detailId; + recordSet.executeUpdate(sql); + return false; + } + + /*插入明细记录*/ + detailSql = "insert into kq_WorkingAgeToLeave(leaveRulesId,lowerLimit,upperLimit,amount) values(?,?,?,?)"; + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 0, 1, 0); + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 1, 10, 5); + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 10, 20, 10); + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 20, 9999, 15); + } catch (Exception e) { + logger.info(e.getMessage()); + } + return isInitSuccess; + } + + /** + * 初始化带薪事假 + * + * @param ruleId + * @return + */ + public static boolean initPaidCompassionateLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='带薪事假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='paidCompassionateLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'带薪事假-初始化',0,'',1,8,1,0,0,1,'paidCompassionateLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set paidCompassionateLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化带薪病假 + * + * @param ruleId + * @return + */ + public static boolean initPaidSickLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='带薪病假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='paidSickLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'带薪病假-初始化',0,'',1,8,1,0,0,1,'paidSickLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set paidSickLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化调休 + * + * @param ruleId + * @return + */ + public static boolean initVacationLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='调休-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=1," + + "isDelete=0,isEnable=1,leaveCode='vacationLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + + String deleteDetailSql = "delete from kq_LeaveRulesDetail where scopeType=0 and ruleId=" + ruleId; + rs.executeUpdate(deleteDetailSql); + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('调休-总部规则'," + ruleId + ",0,'',5,0,1,0,'','',0,0,0,0)"; + isInitSuccess = rs.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + } else { + /*判断系统中是否已经存在调休了,如果已存在,则不允许新建新的调休假期*/ + sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id in (select ruleId from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5)"; + rs.executeQuery(sql); + if (rs.getCounts() > 0) { + return false; + } + + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'调休-初始化',0,'',1,8,1,1,0,1,'vacationLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('调休-总部规则'," + nextId + ",0,'',5,0,1,0,'','',0,0,0,0)"; + isInitSuccess = rs.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set vacationLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化事假 + * + * @param ruleId + * @return + */ + public static boolean initCompassionateLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='事假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='compassionateLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'事假-初始化',0,'',1,8,1,0,0,1,'compassionateLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set compassionateLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化病假 + * + * @param ruleId + * @return + */ + public static boolean initSickLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='病假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='sickLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'病假-初始化',0,'',1,8,1,0,0,1,'sickLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set sickLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化产假 + * + * @param ruleId + * @return + */ + public static boolean initMaternityLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='产假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=2,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='maternityLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'产假-初始化',0,'',1,8,2,0,0,1,'maternityLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set maternityLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化陪产假 + * + * @param ruleId + * @return + */ + public static boolean initPaternityLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (recordSet.next()) { + String updateSql = "update kq_LeaveRules set leaveName='陪产假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=2,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='paternityLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'陪产假-初始化',0,'',1,8,2,0,0,1,'paternityLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set paternityLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化婚假 + * + * @param ruleId + * @return + */ + public static boolean initMarriageLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='婚假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=2,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='marriageLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'婚假-初始化',0,'',1,8,2,0,0,1,'marriageLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set marriageLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化丧假 + * + * @param ruleId + * @return + */ + public static boolean initFuneralLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='丧假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='funeralLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'丧假-初始化',0,'',1,8,1,0,0,1,'funeralLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set funeralLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化哺乳假 + * + * @param ruleId + * @return + */ + public static boolean initBreastfeedingLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='哺乳假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='breastfeedingLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'哺乳假-初始化',0,'',1,8,1,0,0,1,'breastfeedingLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set breastfeedingLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 根据人员ID以及名称获取对应的假期规则ID(主要对于对接小E) + * + * @param resourceId 人员ID + * @param leaveName 假期规则名称 + * @return + */ + public static List getLeaveRuleIdByName(String resourceId, String leaveName) { + List dataList = new ArrayList(); + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subcomId = resourceComInfo.getSubCompanyID(resourceId); + + Map dataMap = new HashMap(); + + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete <>1) and isEnable=1 and leaveName like '%" + leaveName + "%'"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + while (recordSet.next()) { + int scopeType = Util.getIntValue(recordSet.getString("scopeType"), 0); + String scopeValue = Util.null2String(recordSet.getString("scopeValue")); + + if (scopeType == 1) { + List tempList = Util.TokenizerString(scopeValue, ","); + if (!tempList.contains(subcomId)) { + continue; + } + } + + dataMap = new HashMap(); + dataMap.put("ruleId", recordSet.getString("id")); + dataMap.put("name", Util.formatMultiLang(recordSet.getString("leaveName"), "7")); + dataList.add(dataMap); + } + } catch (Exception e) { + e.printStackTrace(); + } + return dataList; + } + + /** + * 判断此请假类型是否是由 法定年假+福利年假 组合而成的混合模式 + * + * @param ruleId 指定的请假类型的id(对应于kq_LeaveRules表的主键ID) + * @return true--是混合模式、false--不是 + */ + public static boolean isMixMode(String ruleId) { + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=6 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + flag = true; + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + + /** + * 获取请假类型的颜色(随机生成) + * + * @return + */ + public static String getColor() { + String color = ""; + try { + StringBuffer result = new StringBuffer(); + for (int i = 0; i < 6; i++) { + //随机生成0-15的数值并转换成16进制 + result.append(Integer.toHexString(new Random().nextInt(16))); + } + color = "#" + result.toString().toUpperCase(); + } catch (Exception e) { + System.out.println("获取16进制字符串异常,返回默认..."); + color = "#00CCCC"; + } + return color; + } + + public static String getChildName(String balanceofleaveid){ + String name = ""; + try { + String sql = "select childId from kq_balanceOfLeave where id=?"; + RecordSet recordSet = new RecordSet(); + KQChildrenComInfo kqChildrenComInfo = new KQChildrenComInfo(); + recordSet.executeQuery(sql, balanceofleaveid); + if (recordSet.next()) { + String chlid = Util.null2s(recordSet.getString("childId"), ""); + if(StringUtils.isNotBlank(chlid)){ + name= kqChildrenComInfo.getChildrenName(chlid); + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return name; + } + /** + * 是否是调休 + * @param ruleId + * @return + */ + public static boolean isTiaoXiu(String ruleId){ + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + flag = true; + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + + public static boolean isTiaoXiu(String ruleId, String subCompanyId, String departmentId, String resourceId) { + boolean flag = false; + RecordSet recordSet = new RecordSet(); + try { + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + recordSet.writeLog("isTiaoXiu>>1=" +ruleId+";2="+ subCompanyId+";3="+ departmentId+";4="+ resourceId ); + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subCompanyId, departmentId, resourceId), 1); + if (distributionMode == 5) { + flag = true; + } + recordSet.writeLog("isTiaoXiu>>distributionMode=" +distributionMode); +// if (!flag) { + if (true) { + + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) " + + "and distributionMode=5 and ruleId=? "; + String sqlWhere = ""; + if (!resourceId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=3 and ','+scopeValue+',' like '%," + resourceId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=3 and concat(',',scopeValue,',') like '%," + resourceId + ",%') "; + } else { + sqlWhere = " and (scopeType=3 and ','||scopeValue||',' like '%," + resourceId + ",%') "; + } + recordSet.writeLog("isTiaoXiu>>sql1=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } else if (!departmentId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=2 and ','+scopeValue+',' like '%," + departmentId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=2 and concat(',',scopeValue,',') like '%," + departmentId + ",%') "; + } else { + sqlWhere = " and (scopeType=2 and ','||scopeValue||',' like '%," + departmentId + ",%') "; + } + recordSet.writeLog("isTiaoXiu>>sql2=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } else if (!subCompanyId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=1 and ','+scopeValue+',' like '%," + subCompanyId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=1 and concat(',',scopeValue,',') like '%," + subCompanyId + ",%') "; + } else { + sqlWhere = " and (scopeType=1 and ','||scopeValue||',' like '%," + subCompanyId + ",%') "; + } + recordSet.writeLog("isTiaoXiu>>sql3=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } else { + sqlWhere = " and scopeType=0 "; + recordSet.writeLog("isTiaoXiu>>sql4=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } + } + + recordSet.writeLog("isTiaoXiu>>flag=" + flag); + } catch (Exception e) { + recordSet.writeLog(e.getMessage()); + recordSet.writeLog(e); + } + return flag; + } + + public static int getTiaoXiu(String subCompanyId, String departmentId, String resourceId) { + int ruleid = 0; + RecordSet recordSet = new RecordSet(); + try { + + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) " + + "and distributionMode=5 "; + String sqlWhere = ""; + if (!resourceId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=3 and ','+scopeValue+',' like '%," + resourceId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=3 and concat(',',scopeValue,',') like '%," + resourceId + ",%') "; + } else { + sqlWhere = " and (scopeType=3 and ','||scopeValue||',' like '%," + resourceId + ",%') "; + } + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + } + if (!departmentId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=2 and ','+scopeValue+',' like '%," + departmentId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=2 and concat(',',scopeValue,',') like '%," + departmentId + ",%') "; + } else { + sqlWhere = " and (scopeType=2 and ','||scopeValue||',' like '%," + departmentId + ",%') "; + } + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + } + if (!subCompanyId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=1 and ','+scopeValue+',' like '%," + subCompanyId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=1 and concat(',',scopeValue,',') like '%," + subCompanyId + ",%') "; + } else { + sqlWhere = " and (scopeType=1 and ','||scopeValue||',' like '%," + subCompanyId + ",%') "; + } + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + } + + sqlWhere = " and scopeType=0 "; + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + + } catch (Exception e) { + recordSet.writeLog(e.getMessage()); + recordSet.writeLog(e); + } + return ruleid; + } + + public static Map isRepeat(String ruleid,int scopeType,String scopeValue,User user,String ruleDetailId){ + Map result = new HashMap<>(); + result.put("flag","0");//0=未重复,1=重复了不让保存 +// String sql = "select id,ruleid,scopetype,scopevalue,distributionmode from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5 "; + String sql = "select id,ruleid,scopetype,scopevalue,distributionmode from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) "; + RecordSet recordSet = new RecordSet(); + recordSet.writeLog("ruleid="+ruleid+",scopeType="+scopeType+",scopeValue="+scopeValue); + recordSet.executeQuery(sql); + while (recordSet.next()) { + String tmp_id = Util.null2String(recordSet.getString("id")); + String tmp_ruleid = Util.null2String(recordSet.getString("ruleid")); + String tmp_scopetype = Util.null2String(recordSet.getString("scopetype")); + String tmp_scopevalue = Util.null2String(recordSet.getString("scopevalue")); + String tmp_distributionmode = Util.null2String(recordSet.getString("distributionmode")); + recordSet.writeLog("tmp_id="+tmp_id+",tmp_ruleid="+tmp_ruleid+",tmp_scopetype="+tmp_scopetype+",tmp_scopevalue="+tmp_scopevalue); + if(tmp_ruleid.equals(ruleid) && ("".equals(ruleDetailId) || !tmp_id.equals(ruleDetailId))){ + //同一个假期类型,不能同时设置为【加班自动计入调休】和其他的规则,比如按工龄自动发放 + if(!tmp_distributionmode.equals("5")){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546798, user.getLanguage())); + return result; + } + } + + if(tmp_distributionmode.equals("5") && tmp_scopetype.equals(Util.null2String(scopeType)) && ("".equals(ruleDetailId) || !tmp_id.equals(ruleDetailId))){ + //总部级别的范围单独处理下,因为存在之前是分部级别,维护了分部id,这个时候即便是scopytype=0,但是scopevalue依然有值了,所以总部级别不用进行scopevalue的比对 + if("0".equals(tmp_scopetype)){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546797, user.getLanguage())); + return result; + } + if(null != scopeValue && scopeValue.indexOf(",")>-1){ + String[] values = scopeValue.split(","); + for (String value : values) { + if((","+tmp_scopevalue+",").indexOf(","+value+",")>-1){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546797, user.getLanguage())); + return result; + } + } + }else { + if((","+tmp_scopevalue+",").indexOf(","+scopeValue+",")>-1){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546797, user.getLanguage())); + return result; + } + } + } + } + + return result; + } + + /** + * 是否是育儿假,且不开启叠加 + * @param ruleId + * @return + */ + public static boolean isLeaveOfParental(String ruleId){ + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=8 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + String severalChildren = Util.null2s(recordSet.getString("severalChildren"), "0"); + if(severalChildren.equals("0")){ + flag = true; + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + /** + * 是否是育儿假且开启了叠加 + * @param ruleId + * @return + */ + public static boolean isLeaveOfParentalNum(String ruleId){ + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=8 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + String severalChildren = Util.null2s(recordSet.getString("severalChildren"), "0"); + if(severalChildren.equals("1")){ + flag = true; + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + + /** + * 半天单位 时间选择方式:1-下拉框选择 、2-具体时间 + * @param ruleId + * @return + */ + public static int getTimeselection(String ruleId) { + int timeselection = 1;//最小请假单位 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + timeselection = Util.getIntValue(kqLeaveRulesComInfo.getTimeSelection(ruleId), 1); + return timeselection; + } + + public void updateChildLeaveDate(int scopeType,String scopeValue,int validityRule,String ruleId){ + RecordSet rs = new RecordSet(); + try { + // 查询当年育儿假数据 + String sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId = "+ruleId ; + + if (scopeType == 1 ) { + sql += " and resourceid in (select id from hrmresource where subCompanyId1 in (" + scopeValue + ") )"; + }else if (scopeType == 2 ) { + sql += " and resourceid in (select id from hrmresource where departmentId in (" + scopeValue + ") )"; + }else if (scopeType == 3) { + sql += " and (" + Tools.getOracleSQLIn(scopeValue, "resourceid") + ") "; + } + KQBalanceOfLeaveEntity balanceEntity = null; + ArrayList balanceEntities = new ArrayList<>(); + rs.executeQuery(sql); + while (rs.next()) { + int id = rs.getInt("id"); + String childId = Util.null2s(rs.getString("childId"), ""); + if(StringUtils.isNotBlank(childId)){ + String expirationDate = Util.null2s(rs.getString("expirationDate"), ""); + String effectiveDate = Util.null2s(rs.getString("effectiveDate"), ""); + balanceEntity = new KQBalanceOfLeaveEntity(); + balanceEntity.setId(id); + balanceEntity.setExpirationDate(expirationDate); + balanceEntity.setEffectiveDate(effectiveDate); + balanceEntities.add(balanceEntity); + } + } + sql = " update kq_balanceOfLeave set expirationDate =? where id= ? "; + for (int i = 0; balanceEntities != null && i < balanceEntities.size(); i++) { + KQBalanceOfLeaveEntity balance = balanceEntities.get(i); + String uid = Util.null2String(balance.getId()); + String effectiveDate = Util.null2String(balance.getEffectiveDate()); + String expirationDate = "2222-12-31"; + if (validityRule != 0) { + expirationDate = TimeUtil.dateAdd(TimeUtil.yearAdd(effectiveDate, 1), -1); + } + rs.executeUpdate(sql, expirationDate,uid); + } + + }catch (Exception e){ + e.printStackTrace(); + rs.writeLog(e); + } + } +} diff --git a/src/com/engine/kq/biz/KQLeaveRulesComInfo.java b/src/com/engine/kq/biz/KQLeaveRulesComInfo.java new file mode 100644 index 0000000..3790b34 --- /dev/null +++ b/src/com/engine/kq/biz/KQLeaveRulesComInfo.java @@ -0,0 +1,319 @@ +package com.engine.kq.biz; + +import com.engine.kq.wfset.util.KQAttFlowCheckUtil; +import weaver.cache.CacheBase; +import weaver.cache.CacheColumn; +import weaver.cache.CacheColumnType; +import weaver.cache.PKColumn; +import weaver.general.Util; +import weaver.systeminfo.SystemEnv; + +/** + * 假期规则缓存类 + */ +public class KQLeaveRulesComInfo extends CacheBase { + + /** + * 数据来源 + */ + protected static String TABLE_NAME = "kq_leaveRules"; + /** + * sql中的where信息,不要以where开始 + */ + protected static String TABLE_WHERE = " (isDelete is null or isDelete !=1) "; + /** + * sql中的order by信息,不要以order by开始 + */ + protected static String TABLE_ORDER = " showOrder,id "; + + /** + * 主键 + */ + @PKColumn(type = CacheColumnType.NUMBER) + protected static String PK_NAME = "id"; + + /** + * 假期规则名称 + */ + @CacheColumn(name = "leaveName") + protected static int leaveName; + + @CacheColumn(name = "SchevacationON") + protected static int SchevacationON; + + @CacheColumn(name = "Schevacation") + protected static int Schevacation; + + /** + * 是否禁用:0-未禁用、1-已禁用 + */ + @CacheColumn(name = "isEnable") + protected static int isEnable; + + /** + * 应用范围:0-总部、1-分部 + */ + @CacheColumn(name = "scopeType") + protected static int scopeType; + + /** + * 分部ID(当应用范围为分部时选择的分部ID) + */ + @CacheColumn(name = "scopeValue") + protected static int scopeValue; + + /** + * 最小请假单位 + * 1-按天请假 + * 2-按半天请假 + * 3-按小时请假 + * 4-按整天请假 + * 其他:无效数据 + */ + @CacheColumn(name = "minimumUnit") + protected static int minimumUnit; + + /** + * 余额单位变更时的换算比例 + * XX小时=1天 + */ + @CacheColumn(name = "proportion") + protected static int proportion; + + /** + * 日折算时长(1天=XX小时) + */ + @CacheColumn(name = "hoursToDay") + protected static int hoursToDay; + + /** + * 按自然日计算请假时长,0-不排除,1-排除节假日,2-排除休息日,3-排除节假日和休息日 + */ + @CacheColumn(name = "filterHolidays") + protected static int filterHolidays; + + /** + * 计算请假时长方式: + * 1-按工作日计算请假时长 + * 2-按自然日计算请假时长 + */ + @CacheColumn(name = "computingMode") + protected static int computingMode; + + /** + * 启用假期余额: + * 0-不启用 + * 1-启用 + */ + @CacheColumn(name = "balanceEnable") + protected static int balanceEnable; + + /** + * 假期类型标识 + */ + @CacheColumn(name = "leaveCode") + protected static int leaveCode; + + /** + * 半天单位 时间选择方式:1-下拉框选择 、2-具体时间 + */ + @CacheColumn(name = "timeselection") + protected static int timeselection; + + /** + * 折算方式 1是四舍五入 2是向上取整 3是向下取整 + */ + @CacheColumn(name = "conversion") + protected static int conversion; + + /** + * 流程重复时段 1是重复 0是不重复,默认不重复 + */ + @CacheColumn(name = "repeat_time") + protected static int repeatTime; + + public String getId(){ + return (String)getRowValue(PK_INDEX); + } + + public String getLeaveName() { + return (String)getRowValue(leaveName); + } + + public String getLeaveName(String key){ + return (String) getValue(leaveName,key); + } + + public String getSchevacationON() { + return (String)getRowValue(SchevacationON); + } + + public String getSchevacationON(String key){ + return (String) getValue(SchevacationON,key); + } + + public String getSchevacation() { + return (String)getRowValue(Schevacation); + } + + public String getSchevacation(String key){ + return (String) getValue(Schevacation,key); + } + + public String getIsEnable() { + return (String)getRowValue(isEnable); + } + + public String getIsEnable(String key){ + return (String) getValue(isEnable,key); + } + + public String getScopeType() { + return (String)getRowValue(scopeType); + } + + public String getScopeType(String key){ + return (String) getValue(scopeType,key); + } + + public String getScopeValue() { + return (String)getRowValue(scopeValue); + } + + public String getScopeValue(String key){ + return (String) getValue(scopeValue,key); + } + + public String getMinimumUnit() { + return (String)getRowValue(minimumUnit); + } + + public String getMinimumUnit(String key){ + return (String)getValue(minimumUnit,key); + } + + public String getProportion() { + return (String)getRowValue(proportion); + } + + public String getProportion(String key){ + return (String)getValue(proportion,key); + } + + public String getHoursToDay() { + return (String)getRowValue(hoursToDay); + } + + public String getHoursToDay(String key){ + return (String)getValue(hoursToDay,key); + } + public String getFilterHolidays() { + return (String)getRowValue(filterHolidays); + } + + public String getFilterHolidays(String key){ + return (String)getValue(filterHolidays,key); + } + + public String getComputingMode() { + return (String)getRowValue(computingMode); + } + + public String getComputingMode(String key){ + return (String)getValue(computingMode,key); + } + + public String getBalanceEnable() { + return (String)getRowValue(balanceEnable); + } + + public String getBalanceEnable(String key){ + return (String)getValue(balanceEnable,key); + } + + public String getLeaveCode() { + return (String)getRowValue(leaveCode); + } + + public String getLeaveCode(String key){ + return (String)getValue(leaveCode,key); + } + + public String getTimeSelection() { + String value = (String) getRowValue(timeselection); + if (value == null || value.equals("")) { + value = "1"; + } + return value; + } + + public String getTimeSelection(String key) { + String value = (String) getValue(timeselection, key); + if (value == null || value.equals("")) { + value = "1"; + } + return value; + } + + public String getConversion() { + return (String)getRowValue(conversion); + } + + public String getConversion(String key){ + return (String)getValue(conversion,key); + } + + public String getRepeatTime() { + return (String)getRowValue(repeatTime); + } + + public String getRepeatTime(String key){ + return (String)getValue(repeatTime,key); + } + + public String getUnitName(int language){ + String unitName = "";//单位名称,天/小时 + int minimumUnit = Util.getIntValue(getMinimumUnit(),1); + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) { + unitName = SystemEnv.getHtmlLabelName(389325, language);//(天) + } else { + unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时) + } + return unitName; + } + + public String getUnitName(String key,int language){ + String unitName = "";//单位名称,天/小时 + int minimumUnit = Util.getIntValue(getMinimumUnit(key),1); + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) { + unitName = SystemEnv.getHtmlLabelName(389325, language);//(天) + } else { + unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时) + } + +// KQTransMethod method = new KQTransMethod(); +// unitName = "("+method.getMinimumUnitName4Browser(""+minimumUnit, ""+language)+")"; + return unitName; + } + + public String getUnitNameNew(String key,int language){ + String unitName = "";//单位名称,天/小时 + int minimumUnit = Util.getIntValue(getMinimumUnit(key),1); + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) { + unitName = SystemEnv.getHtmlLabelName(389325, language);//(天) + } else { + unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时) + } + return unitName; + } + + + + @Override + public void removeCache() { + super.removeCache(); + KQAttFlowCheckUtil kqAttFlowCheckUtil = new KQAttFlowCheckUtil(); + kqAttFlowCheckUtil.initLeaveUnit(); + } + +} diff --git a/src/com/engine/kq/biz/KQLeaveRulesDetailComInfo.java b/src/com/engine/kq/biz/KQLeaveRulesDetailComInfo.java new file mode 100644 index 0000000..b7398ec --- /dev/null +++ b/src/com/engine/kq/biz/KQLeaveRulesDetailComInfo.java @@ -0,0 +1,1329 @@ +package com.engine.kq.biz; + +import weaver.cache.*; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.general.Util; + +/** + * @Auther: Administrator + * @Date: 2019-03-08 16:23 + * @Description: + */ +public class KQLeaveRulesDetailComInfo extends CacheBase { + + /** + * 数据来源 + */ + protected static String TABLE_NAME = "kq_leaveRulesDetail"; + /** + * sql中的where信息,不要以where开始 + */ + protected static String TABLE_WHERE = " (isDelete is null or isDelete !=1) "; + /** + * sql中的order by信息,不要以order by开始 + */ + protected static String TABLE_ORDER = "id"; + + /** + * 主键 + */ + @PKColumn(type = CacheColumnType.NUMBER) + protected static String PK_NAME = "id"; + + /** + * 假期规则的ID + */ + @CacheColumn(name = "id") + protected static int id; + + /** + * 假期类型的ID + */ + @CacheColumn(name = "ruleId") + protected static int ruleId; + + /** + * 假期规则名称 + */ + @CacheColumn(name = "ruleName") + protected static int ruleName; + + /** + * 应用范围:0-总部、1-分部 + */ + @CacheColumn(name = "scopeType") + protected static int scopeType; + + /** + * 分部ID(当应用范围为分部时选择的分部ID) + */ + @CacheColumn(name = "scopeValue") + protected static int scopeValue; + + /** + * 余额发放方式: + * 1-手动发放 + * 2-按司龄自动发放 + * 3-按工龄自动发放 + * 4-每年自动发放固定天数 + * 5-加班时长自动计入余额 + * 6-按司龄+工龄自动发放 + */ + @CacheColumn(name = "distributionMode") + protected static int distributionMode; + + /** + * 每人发放小时(天)数 + * 注:当余额发放方式为"4-每年自动发放固定天数"时有效 + */ + @CacheColumn(name = "annualAmount") + protected static int annualAmount; + + /** + * 法定年假的规则:(当【余额发放方式】选择【6-按司龄+工龄自动发放】才有效) + * 0-工龄(默认) + * 1-司龄 + * 2-司龄+工龄 + */ + @CacheColumn(name = "legalKey") + protected static int legalKey; + + /** + * 福利年假的规则:(当【余额发放方式】选择【6-按司龄+工龄自动发放】才有效) + * 0-工龄 + * 1-司龄(默认) + * 2-司龄+工龄 + */ + @CacheColumn(name = "welfareKey") + protected static int welfareKey; + + /** + * 扣减优先级:(当【余额发放方式】选择【6-按司龄+工龄自动发放】才有效) + * 1-法定年假 + * 2-福利年假 + */ + @CacheColumn(name = "priority") + protected static int priority; + + /** + * 计算方式 + */ + @CacheColumn(name = "calcMethod") + protected static int calcMethod; + + /** + * //假期基数的发放日期 + * //1--每年的1月1号 + * //2--入职日期 + * //3--参加工作日期 + */ + @CacheColumn(name = "baseAmountReleaseDate") + protected static int baseAmountReleaseDate; + + /** + * //假期基数的变动日期 + * //1--每年的1月1号 + * //2--入职日期 + * //3--参加工作日期 + */ + @CacheColumn(name = "baseAmountChangeDate") + protected static int baseAmountChangeDate; + + /** + * 假期基数折算方式 + * 0--不折算 + * 1--四舍五入 + * 2--向上取整 + * 3--向下取整 + * 4--向上取0.5的倍数 + * 5--向下取0.5的倍数 + */ + @CacheColumn(name = "convertMode") + protected static int convertMode; + + /** + * 折算后保留的小数点位数 + */ + @CacheColumn(name = "decimalDigit") + protected static int decimalDigit; + + /** + * 有效期规则 + * 0-永久有效 + * 1-按自然年(1月1日-12月31日) + * 2-按入职日期起12个月 + * 3-自定义次年失效日期 + * 4-按天数失效 + * 5-按季度失效 + * 6-按月数失效 + */ + @CacheColumn(name = "validityRule") + protected static int validityRule; + + /** + * 失效日期-月 + */ + @CacheColumn(name = "expirationMonth") + protected static int expirationMonth; + + /** + * 失效日期-日 + */ + @CacheColumn(name = "expirationDay") + protected static int expirationDay; + + /** + * 有效天数 + */ + @CacheColumn(name = "effectiveDays") + protected static int effectiveDays; + + /** + * 有效月数 + */ + @CacheColumn(name = "effectiveMonths") + protected static int effectiveMonths; + + /** + * 是否允许延长有效期 + * 0-不允许 + * 1-允许 + */ + @CacheColumn(name = "extensionEnable") + protected static int extensionEnable; + + /** + * 允许延长的有效期天数 + */ + @CacheColumn(name = "extendedDays") + protected static int extendedDays; + + /** + * 释放规则 + * 0-不限制 + * 1-按天释放 + * 2-按月释放 + */ + @CacheColumn(name = "releaseRule") + protected static int releaseRule; + + /** + * 假期类型 + */ + @CacheColumn(name = "leaveCode") + protected static int leaveCode; + + /** + * 是否需要排除次账号 + * 0--不排除,即次账号正常享受年假 + * 1--排除,即次账号不能享受年假 + */ + @CacheColumn(name = "excludeSubAccount") + protected static int excludeSubAccount; + + /** + * 转正之前是否允许发放假期余额 + * 0--不允许 + * 1--允许 + */ + @CacheColumn(name = "beforeFormal") + protected static int beforeFormal; + + /** + * 多孩叠加开关 + * 0--不 + * 1--开 + */ + @CacheColumn(name = "severalChildren") + protected static int severalChildren; + + /** + * 孩子多少周岁前发放。 + */ + @CacheColumn(name = "yearsOld") + protected static int yearsOld; + + /** + *是否按照省份发放育儿假。1否,2是 + */ + @CacheColumn(name = "isprovince") + protected static int isprovince; + + /** + *是否按照省份发放育儿假。1否,2是 + */ + @CacheColumn(name = "carryOver") + protected static int carryOver; + + private static final String[] SCOPE_TYPES = {"3", "2", "1"}; + @Override + public CacheMap initCache() throws Exception { + CacheMap localData = super.createCacheMap(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_leaveRulesDetail where (isDelete is null or isDelete<>1) order by id"; + rs.executeQuery(sql); + while (rs.next()) { + String _id = rs.getString("id"); + String _ruleId = rs.getString("ruleId");//假期类型的ID + String _ruleName = rs.getString("ruleName");//假期类型的ID + String _scopeType = rs.getString("scopeType");//假期类型的流程可见范围 + String _scopeValue = rs.getString("scopeValue");//流程可见范围为分部时勾选的分部ID + String _distributionMode = rs.getString("distributionMode"); + String _annualAmount = rs.getString("annualAmount"); + String _legalKey = rs.getString("legalKey"); + String _welfareKey = rs.getString("welfareKey"); + String _priority = rs.getString("priority"); + String _calcMethod = rs.getString("calcMethod"); + String _baseAmountReleaseDate = rs.getString("baseAmountReleaseDate"); + String _baseAmountChangeDate = rs.getString("baseAmountChangeDate"); + String _convertMode = rs.getString("convertMode"); + String _decimalDigit = rs.getString("decimalDigit"); + String _validityRule = rs.getString("validityRule"); + String _expirationMonth = rs.getString("expirationMonth"); + String _expirationDay = rs.getString("expirationDay"); + String _effectiveDays = rs.getString("effectiveDays"); + String _effectiveMonths = rs.getString("effectiveMonths"); + String _extensionEnable = rs.getString("extensionEnable"); + String _extendedDays = rs.getString("extendedDays"); + String _releaseRule = rs.getString("releaseRule"); + String _leaveCode = rs.getString("leaveCode"); + String _excludeSubAccount = rs.getString("excludeSubAccount"); + String _beforeFormal = rs.getString("beforeFormal"); + String _severalChildren = rs.getString("severalChildren"); + String _yearsOld = rs.getString("yearsOld"); + String _isprovince = rs.getString("isprovince"); + String _carryOver = rs.getString("carryOver"); + if (_scopeType.equals("1") || _scopeType.equals("2") || _scopeType.equals("3")) { + String[] scopeValueArr = _scopeValue.split(","); + for (int i = 0; i < scopeValueArr.length; i++) { + String PK = _ruleId + "|" + _scopeType + "|" + scopeValueArr[i]; + + + CacheItem row = createCacheItem(); + row.set(PK_INDEX, PK); + row.set(id, _id); + row.set(ruleId, _ruleId); + row.set(ruleName, _ruleName); + row.set(scopeType, _scopeType); + row.set(scopeValue, _scopeValue); + row.set(distributionMode, _distributionMode); + row.set(annualAmount, _annualAmount); + row.set(legalKey, _legalKey); + row.set(welfareKey, _welfareKey); + row.set(priority, _priority); + row.set(calcMethod, _calcMethod); + row.set(baseAmountReleaseDate, _baseAmountReleaseDate); + row.set(baseAmountChangeDate, _baseAmountChangeDate); + row.set(convertMode, _convertMode); + row.set(decimalDigit, _decimalDigit); + row.set(validityRule, _validityRule); + row.set(expirationMonth, _expirationMonth); + row.set(expirationDay, _expirationDay); + row.set(effectiveDays, _effectiveDays); + row.set(effectiveMonths, _effectiveMonths); + row.set(extensionEnable, _extensionEnable); + row.set(extendedDays, _extendedDays); + row.set(releaseRule, _releaseRule); + row.set(leaveCode, _leaveCode); + row.set(excludeSubAccount, _excludeSubAccount); + row.set(beforeFormal, _beforeFormal); + row.set(severalChildren, _severalChildren); + row.set(yearsOld, _yearsOld); + row.set(isprovince, _isprovince); + row.set(carryOver, _carryOver); + modifyCacheItem(PK, row); + localData.put(PK, row); + } + } else { + String PK = ruleId + "|" + scopeType; + + CacheItem row = createCacheItem(); + row.set(PK_INDEX, PK); + row.set(id, _id); + row.set(ruleId, _ruleId); + row.set(ruleName, _ruleName); + row.set(scopeType, _scopeType); + row.set(scopeValue, _scopeValue); + row.set(distributionMode, _distributionMode); + row.set(annualAmount, _annualAmount); + row.set(legalKey, _legalKey); + row.set(welfareKey, _welfareKey); + row.set(priority, _priority); + row.set(calcMethod, _calcMethod); + row.set(baseAmountReleaseDate, _baseAmountReleaseDate); + row.set(baseAmountChangeDate, _baseAmountChangeDate); + row.set(convertMode, _convertMode); + row.set(decimalDigit, _decimalDigit); + row.set(validityRule, _validityRule); + row.set(expirationMonth, _expirationMonth); + row.set(expirationDay, _expirationDay); + row.set(effectiveDays, _effectiveDays); + row.set(effectiveMonths, _effectiveMonths); + row.set(extensionEnable, _extensionEnable); + row.set(extendedDays, _extendedDays); + row.set(releaseRule, _releaseRule); + row.set(leaveCode, _leaveCode); + row.set(excludeSubAccount, _excludeSubAccount); + row.set(beforeFormal, _beforeFormal); + row.set(severalChildren, _severalChildren); + row.set(yearsOld, _yearsOld); + row.set(isprovince, _isprovince); + row.set(carryOver, _carryOver); + modifyCacheItem(PK, row); + localData.put(PK, row); + } + } + return localData; + } + + @Override + public CacheItem initCache(String key) { + if (key == null || "".equals(key.trim())) { + return null; + } + + String ruleIdTemp = "";//假期类型的ID + String scopeTypeTemp = "";//假期类型的流程可见范围 + String scopeValueTemp = "";//流程可见范围为分部时勾选的分部ID + String PK = ""; + + String[] keyArr = key.split("\\|"); + String sql = ""; + RecordSet rs = new RecordSet(); + if (keyArr.length == 2) { + ruleIdTemp = keyArr[0]; + scopeTypeTemp = keyArr[1]; + PK = ruleIdTemp + "|0"; + + sql = "select * from kq_leaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=" + ruleIdTemp + " and scopeType=" + scopeTypeTemp + " order by id"; + } + if (keyArr.length == 3) { + ruleIdTemp = keyArr[0]; + scopeTypeTemp = keyArr[1]; + scopeValueTemp = keyArr[2]; + PK = ruleIdTemp + "|1|" + scopeValueTemp; + + sql = "select * from kq_leaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=" + ruleIdTemp + " and scopeType=" + scopeTypeTemp; + if (rs.getDBType().equalsIgnoreCase("sqlserver")) { + sql += " and ','+scopeValue+',' like '%," + scopeValueTemp + ",%'"; + } else if (rs.getDBType().equalsIgnoreCase("mysql")) { + sql += " and concat(',',scopeValue,',') like '%," + scopeValueTemp + ",%'"; + } else { + sql += " and ','||scopeValue||',' like '%," + scopeValueTemp + ",%'"; + } + sql += " order by id "; + } + rs.executeQuery(sql); + if (rs.next()) { + String _id = rs.getString("id"); + String _ruleId = rs.getString("ruleId");//假期类型的ID + String _ruleName = rs.getString("ruleName");//假期类型的ID + String _scopeType = rs.getString("scopeType");//假期类型的流程可见范围 + String _scopeValue = rs.getString("scopeValue");//流程可见范围为分部时勾选的分部ID + String _distributionMode = rs.getString("distributionMode"); + String _annualAmount = rs.getString("annualAmount"); + String _legalKey = rs.getString("legalKey"); + String _welfareKey = rs.getString("welfareKey"); + String _priority = rs.getString("priority"); + String _calcMethod = rs.getString("calcMethod"); + String _baseAmountReleaseDate = rs.getString("baseAmountReleaseDate"); + String _baseAmountChangeDate = rs.getString("baseAmountChangeDate"); + String _convertMode = rs.getString("convertMode"); + String _decimalDigit = rs.getString("decimalDigit"); + String _validityRule = rs.getString("validityRule"); + String _expirationMonth = rs.getString("expirationMonth"); + String _expirationDay = rs.getString("expirationDay"); + String _effectiveDays = rs.getString("effectiveDays"); + String _effectiveMonths = rs.getString("effectiveMonths"); + String _extensionEnable = rs.getString("extensionEnable"); + String _extendedDays = rs.getString("extendedDays"); + String _releaseRule = rs.getString("releaseRule"); + String _leaveCode = rs.getString("leaveCode"); + String _excludeSubAccount = rs.getString("excludeSubAccount"); + String _beforeFormal = rs.getString("beforeFormal"); + String _severalChildren = rs.getString("severalChildren"); + String _yearsOld = rs.getString("yearsOld"); + String _isprovince = rs.getString("isprovince"); + String _carryOver = rs.getString("carryOver"); + + CacheItem row = createCacheItem(); + row.set(PK_INDEX, PK); + row.set(id, _id); + row.set(ruleId, _ruleId); + row.set(ruleName, _ruleName); + row.set(scopeType, _scopeType); + row.set(scopeValue, _scopeValue); + row.set(distributionMode, _distributionMode); + row.set(annualAmount, _annualAmount); + row.set(legalKey, _legalKey); + row.set(welfareKey, _welfareKey); + row.set(priority, _priority); + row.set(calcMethod, _calcMethod); + row.set(baseAmountReleaseDate, _baseAmountReleaseDate); + row.set(baseAmountChangeDate, _baseAmountChangeDate); + row.set(convertMode, _convertMode); + row.set(decimalDigit, _decimalDigit); + row.set(validityRule, _validityRule); + row.set(expirationMonth, _expirationMonth); + row.set(expirationDay, _expirationDay); + row.set(effectiveDays, _effectiveDays); + row.set(effectiveMonths, _effectiveMonths); + row.set(extensionEnable, _extensionEnable); + row.set(extendedDays, _extendedDays); + row.set(releaseRule, _releaseRule); + row.set(leaveCode, _leaveCode); + row.set(excludeSubAccount, _excludeSubAccount); + row.set(beforeFormal, _beforeFormal); + row.set(severalChildren, _severalChildren); + row.set(yearsOld, _yearsOld); + row.set(isprovince, _isprovince); + row.set(carryOver, _carryOver); + modifyCacheItem(key, row); + return row; + } else { + CacheItem row = createCacheItem(); + modifyCacheItem(key, row); + return row; + } + } + + private String getId(String key) { + return (String) getValue(id, key); + } + +// public String getId(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String id = getId(PK); +// if (id == null || id == "") { +// PK = ruleId + "|0"; +// id = getId(PK); +// } +// return id; +// } + + private String getRuleId(String key) { + return (String) getValue(ruleId, key); + } + + private String getRuleName(String key) { + return (String) getValue(ruleName, key); + } + +// public String getRuleName(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String ruleName = getRuleName(PK); +// if (ruleName == null || ruleName == "") { +// PK = ruleId + "|0"; +// ruleName = getRuleName(PK); +// } +// return ruleName; +// } + + private String getScopeType(String key) { + return (String) getValue(scopeType, key); + } + +// public String getScopeType(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String scopeType = getScopeType(PK); +// if (scopeType == null || scopeType == "") { +// PK = ruleId + "|0"; +// scopeType = getScopeType(PK); +// } +// return scopeType; +// } + + private String getScopeValue(String key) { + return (String) getValue(scopeValue, key); + } + +// public String getScopeValue(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String scopeValue = getScopeValue(PK); +// if (scopeValue == null || scopeValue == "") { +// PK = ruleId + "|0"; +// scopeValue = getScopeValue(PK); +// } +// return scopeValue; +// } + + private String getDistributionMode(String key) { + return (String) getValue(distributionMode, key); + } + +// public String getDistributionMode(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String distributionMode = getDistributionMode(PK); +// if (distributionMode == null || distributionMode == "") { +// PK = ruleId + "|0"; +// distributionMode = getDistributionMode(PK); +// } +// return distributionMode; +// } + + private String getAnnualAmount(String key) { + return (String) getValue(annualAmount, key); + } + +// public String getAnnualAmount(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String annualAmount = getAnnualAmount(PK); +// if (annualAmount == null || annualAmount == "") { +// PK = ruleId + "|0"; +// annualAmount = getAnnualAmount(PK); +// } +// return annualAmount; +// } + + private String getLegalKey(String key) { + return (String) getValue(legalKey, key); + } + +// public String getLegalKey(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String legalKey = getLegalKey(PK); +// if (legalKey == null || legalKey == "") { +// PK = ruleId + "|0"; +// legalKey = getLegalKey(PK); +// } +// return legalKey; +// } + + private String getWelfareKey(String key) { + return (String) getValue(welfareKey, key); + } + +// public String getWelfareKey(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String welfareKey = getWelfareKey(PK); +// if (welfareKey == null || welfareKey == "") { +// PK = ruleId + "|0"; +// welfareKey = getWelfareKey(PK); +// } +// return welfareKey; +// } + + private String getPriority(String key) { + return (String) getValue(priority, key); + } + +// public String getPriority(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String priority = getPriority(PK); +// if (priority == null || priority == "") { +// PK = ruleId + "|0"; +// priority = getPriority(PK); +// } +// return priority; +// } + + private String getValidityRule(String key) { + return (String) getValue(validityRule, key); + } + +// public String getValidityRule(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String validityRule = getValidityRule(PK); +// if (validityRule == null || validityRule == "") { +// PK = ruleId + "|0"; +// validityRule = getValidityRule(PK); +// } +// return validityRule; +// } + + private String getExpirationMonth(String key) { + return (String) getValue(expirationMonth, key); + } + +// public String getExpirationMonth(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String expirationMonth = getExpirationMonth(PK); +// if (expirationMonth == null || expirationMonth == "") { +// PK = ruleId + "|0"; +// expirationMonth = getExpirationMonth(PK); +// } +// if (expirationMonth.length() == 1) { +// expirationMonth = "0" + expirationMonth; +// } +// return expirationMonth; +// } + + private String getExpirationDay(String key) { + return (String) getValue(expirationDay, key); + } + +// public String getExpirationDay(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String expirationDay = getExpirationDay(PK); +// if (expirationDay == null || expirationDay == "") { +// PK = ruleId + "|0"; +// expirationDay = getExpirationDay(PK); +// } +// if (expirationDay.length() == 1) { +// expirationDay = "0" + expirationDay; +// } +// return expirationDay; +// } + + private String getEffectiveDays(String key) { + return (String) getValue(effectiveDays, key); + } + +// public String getEffectiveDays(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String effectiveDays = getEffectiveDays(PK); +// if (effectiveDays == null || effectiveDays == "") { +// PK = ruleId + "|0"; +// effectiveDays = getEffectiveDays(PK); +// } +// if (Util.getIntValue(effectiveDays, 0) < 1) { +// effectiveDays = "1"; +// } +// return effectiveDays; +// } + + private String getEffectiveMonths(String key) { + return (String) getValue(effectiveMonths, key); + } + +// public String getEffectiveMonths(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String effectiveMonths = getEffectiveMonths(PK); +// if (effectiveMonths == null || effectiveMonths == "") { +// PK = ruleId + "|0"; +// effectiveMonths = getEffectiveMonths(PK); +// } +// if (Util.getIntValue(effectiveMonths, 0) < 1) { +// effectiveMonths = "1"; +// } +// return effectiveMonths; +// } + + private String getExtensionEnable(String key) { + return (String) getValue(extensionEnable, key); + } + +// public String getExtensionEnable(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String extensionEnable = getExtensionEnable(PK); +// if (extensionEnable == null || extensionEnable == "") { +// PK = ruleId + "|0"; +// extensionEnable = getExtensionEnable(PK); +// } +// return extensionEnable; +// } + + private String getExtendedDays(String key) { + return (String) getValue(extendedDays, key); + } + +// public String getExtendedDays(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String extendedDays = getExtendedDays(PK); +// if (extendedDays == null || extendedDays == "") { +// PK = ruleId + "|0"; +// extendedDays = getExtendedDays(PK); +// } +// return extendedDays; +// } + + private String getReleaseRule(String key) { + return (String) getValue(releaseRule, key); + } + +// public String getReleaseRule(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String releaseRule = getReleaseRule(PK); +// if (releaseRule == null || releaseRule == "") { +// PK = ruleId + "|0"; +// releaseRule = getReleaseRule(PK); +// } +// return releaseRule; +// } + + private String getLeaveCode(String key) { + return (String) getValue(leaveCode, key); + } + +// public String getLeaveCode(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String leaveCode = getLeaveCode(PK); +// if (leaveCode == null || leaveCode == "") { +// PK = ruleId + "|0"; +// leaveCode = getLeaveCode(PK); +// } +// return leaveCode; +// } + + private String getCalcMethod(String key) { + return (String) getValue(calcMethod, key); + } + +// public String getCalcMethod(String ruleId, String subcompanyId) { +// String PK = ruleId + "|1|" + subcompanyId; +// String calcMethod = getCalcMethod(PK); +// if (calcMethod == null || calcMethod == "") { +// PK = ruleId + "|0"; +// calcMethod = getCalcMethod(PK); +// } +// return calcMethod; +// } + + private String getBaseAmountReleaseDate(String key) { + return (String) getValue(baseAmountReleaseDate, key); + } + +// public String getBaseAmountReleaseDate(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String baseAmountReleaseDate = getBaseAmountReleaseDate(PK); +// if (baseAmountReleaseDate == null || baseAmountReleaseDate == "") { +// PK = ruleId + "|0"; +// baseAmountReleaseDate = getBaseAmountReleaseDate(PK); +// } +// return baseAmountReleaseDate; +// } + + private String getBaseAmountChangeDate(String key) { + return (String) getValue(baseAmountChangeDate, key); + } + +// public String getBaseAmountChangeDate(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String baseAmountChangeDate = getBaseAmountChangeDate(PK); +// if (baseAmountChangeDate == null || baseAmountChangeDate == "") { +// PK = ruleId + "|0"; +// baseAmountChangeDate = getBaseAmountChangeDate(PK); +// } +// return baseAmountChangeDate; +// } + + private String getConvertMode(String key) { + return (String) getValue(convertMode, key); + } + +// public String getConvertMode(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String convertMode = getConvertMode(PK); +// if (convertMode == null || convertMode == "") { +// PK = ruleId + "|0"; +// convertMode = getConvertMode(PK); +// } +// if (convertMode == null || convertMode.equals("")) { +// convertMode = "1"; +// } +// return convertMode; +// } + + private String getDecimalDigit(String key) { + return (String) getValue(decimalDigit, key); + } + +// public String getDecimalDigit(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String decimalDigit = getDecimalDigit(PK); +// if (decimalDigit == null || decimalDigit == "") { +// PK = ruleId + "|0"; +// decimalDigit = getDecimalDigit(PK); +// } +// if (decimalDigit == null || decimalDigit == "" || Util.getIntValue(decimalDigit, 0) < 2) { +// decimalDigit = "2"; +// } +// return decimalDigit; +// } + + private String getExcludeSubAccount(String key) { + return (String) getValue(excludeSubAccount, key); + } + +// public String getExcludeSubAccount(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String excludeSubAccount = getExcludeSubAccount(PK); +// if (excludeSubAccount == null || excludeSubAccount == "") { +// PK = ruleId + "|0"; +// excludeSubAccount = getExcludeSubAccount(PK); +// } +// return excludeSubAccount; +// } + + private String getBeforeFormal(String key) { + return (String) getValue(beforeFormal, key); + } + +// public String getBeforeFormal(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String beforeFormal = getBeforeFormal(PK); +// if (beforeFormal == null || beforeFormal == "") { +// PK = ruleId + "|0"; +// beforeFormal = getBeforeFormal(PK); +// } +// return beforeFormal; +// } + private String getSeveralChildren(String key) { + return (String) getValue(severalChildren, key); + } + +// public String getSeveralChildren(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String severalChildren = getSeveralChildren(PK); +// if (severalChildren == null || severalChildren == "") { +// PK = ruleId + "|0"; +// severalChildren = getSeveralChildren(PK); +// } +// return severalChildren; +// } + + private String getYearsOld(String key) { + return (String) getValue(yearsOld, key); + } + +// public String getYearsOld(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String yearsOld = getYearsOld(PK); +// if (yearsOld == null || yearsOld == "") { +// PK = ruleId + "|0"; +// yearsOld = getYearsOld(PK); +// } +// return yearsOld; +// } + private String getIsProvince(String key) { + return (String) getValue(isprovince, key); + } + + private String getCarryOver(String key) { + return (String) getValue(carryOver, key); + } + +// public String getIsProvince(String ruleId, String subcompanyId){ +// String PK = ruleId + "|1|" + subcompanyId; +// String isprovince = getIsProvince(PK); +// if (isprovince == null || isprovince == "") { +// PK = ruleId + "|0"; +// isprovince = getIsProvince(PK); +// } +// return isprovince; +// } + + + + public String getId(String ruleId, String subcompanyId, String departmentId, String resourceId) { + String value = ""; + String[] scopeValue = {resourceId, departmentId, subcompanyId}; + for(int i=0; i> { + + private SimpleBizLogger logger; + + public AddLeaveRulesCmd(Map params, User user) { + this.user = user; + this.params = params; + this.logger = new SimpleBizLogger(); + + String ruleId = Util.null2String(params.get("typeId")); + String ruleName = Util.null2String(params.get("ruleName")); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM_ENGINE);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_LEAVERULES);//所属大类型 + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_LEAVERULES);//当前小类型 + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String mainSql = "select * from kq_LeaveRulesDetail where ruleId=" + ruleId + " and ruleName like '%" + ruleName + "%'"; + logger.setMainSql(mainSql, "id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("rulename"); + + SimpleBizLogger.SubLogInfo subLogInfo1 = logger.getNewSubLogInfo(); + String subSql1 = "select * from kq_EntryToLeave where leaveRulesId in (select id from kq_LeaveRulesDetail where ruleId=" + ruleId + " and ruleName like '%" + ruleName + "%')"; + subLogInfo1.setSubSql(subSql1, "id"); + logger.addSubLogInfo(subLogInfo1); + + SimpleBizLogger.SubLogInfo subLogInfo2 = logger.getNewSubLogInfo(); + String subSql2 = "select * from kq_WorkingAgeToLeave where leaveRulesId in (select id from kq_LeaveRulesDetail where ruleId=" + ruleId + " and ruleName like '%" + ruleName + "%')"; + subLogInfo2.setSubSql(subSql2, "id"); + logger.addSubLogInfo(subLogInfo2); + + SimpleBizLogger.SubLogInfo subLogInfo3 = logger.getNewSubLogInfo(); + String subSql3 = "select * from kq_MixModeToLegalLeave where leaveRulesId in (select id from kq_LeaveRulesDetail where ruleId=" + ruleId + " and ruleName like '%" + ruleName + "%')"; + subLogInfo3.setSubSql(subSql3, "id"); + logger.addSubLogInfo(subLogInfo3); + + SimpleBizLogger.SubLogInfo subLogInfo4 = logger.getNewSubLogInfo(); + String subSql4 = "select * from kq_MixModeToWelfareLeave where leaveRulesId in (select id from kq_LeaveRulesDetail where ruleId=" + ruleId + " and ruleName like '%" + ruleName + "%')"; + subLogInfo4.setSubSql(subSql4, "id"); + logger.addSubLogInfo(subLogInfo4); + + logger.before(bizLogContext); + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public List getLogContexts() { + return logger.getBizLogContexts(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map resultMap = new HashMap(); + try { + boolean canAdd = HrmUserVarify.checkUserRight("KQLeaveRulesAdd:Add", user);//是否具有新建权限 + if (!canAdd) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));//没有权限 + return resultMap; + } + + /*假期规则对应的假期类型的ID*/ + String ruleId = Util.null2String(params.get("typeId")); + + /*假期规则名称*/ + String ruleName = Util.null2String(params.get("ruleName")); + + /*应用范围:0-总部、1-分部*/ + int scopeType = Util.getIntValue((String) params.get("scopeType")); + + /*应用范围为分部时,选择的分部ID*/ + String scopeValue = Util.null2String(params.get("scopeValue")); + String deductorder = Util.null2String(params.get("deductorder")); + + /*应用范围为部门时,选择的部门ID*/ + String scopeValueDepartment = Util.null2String(params.get("scopeValueDepartment")); + + /*应用范围为人员时,选择的人员ID*/ + String scopeValueMember = Util.null2String(params.get("scopeValueMember")); + + if(scopeType == 2) { + scopeValue = scopeValueDepartment; + } else if(scopeType == 3) { + scopeValue = scopeValueMember; + } + + /*余额发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按司龄+工龄自动发放*/ + int distributionMode = Util.getIntValue((String) params.get("distributionMode"), 1); + + /*每人发放小时(天)数(当余额发放方式为每年自动发放固定天数时有效)*/ + double annualAmount = Util.getDoubleValue((String) params.get("annualAmount"), 0); + + //法定年假规则:0-工龄、1-司龄、2-工龄+司龄 (当余额发放方式为按工龄+司龄自动发放时有效) + String legalKey = Util.null2s((String) params.get("legalKey"), "0"); + + //福利年假规则:0-工龄、1-工龄、2-工龄+司龄 (当余额发放方式为按工龄+司龄自动发放时有效) + String welfareKey = Util.null2s((String) params.get("welfareKey"), "1"); + + /*扣减优先级:1-法定年假、2-福利年假*/ + int priority = Util.getIntValue((String) params.get("priority"), 1); + + /*有效期规则:0-不限制、1-按自然月(1月1日-12月31日)、2-按入职日期起12个月、3-自定义次年失效日期、4-自定义有效天数*/ + int validityRule = Util.getIntValue((String) params.get("validityRule"), 1); + + /*有效期天数:(当有效期天数选择按天数失效的时候有效)*/ + int effectiveDays = Util.getIntValue((String) params.get("effectiveDays"), 30); + + //有效月数(当有效期规则选择自定义有效月数时) + int effectiveMonths = Util.getIntValue((String) params.get("effectiveMonths"), 1); + + /*失效日期--月(当有效期规则选择3-自定义次年失效日期时有效)*/ + String expirationMonth = Util.null2String(params.get("expirationMonth")); + + /*失效日期--日(当有效期规则选择3-自定义次年失效日期时有效)*/ + String expirationDay = Util.null2String(params.get("expirationDay")); + + /*允许延长有效期:0-不允许、1-允许*/ + int extensionEnable = Util.getIntValue((String) params.get("extensionEnable"), 0); + + /*允许超过有效期天数*/ + int extendedDays = Util.getIntValue((String) params.get("extendedDays"), 0); + + /*释放规则:0-不限制、1-按天释放、2-按月释放*/ + int releaseRule = Util.getIntValue((String) params.get("releaseRule"), 0); + + /*假期基数计算方式:0-精确计算、1-按最少的假期余额计算、2-按最多的假期余额计算*/ + int calcMethod = Util.getIntValue((String) params.get("calcMethod"), 0); + + /*是否折算:0-不折算、1-四舍五入、2-向上取整、3-向下取整、4-向上取0.5的倍数、5-向下取0.5的倍数*/ + int convertMode = Util.getIntValue("" + params.get("convertMode"), 1); + + /*次账号是否发放假期余额:0-不发放、1-发放*/ + int excludeSubAccount = Util.getIntValue("" + params.get("excludeSubAccount"), 1); + + //多孩叠加开关。 + int severalChildren = Util.getIntValue("" + params.get("severalChildren"), 0); + + //孩子多少周岁前发放。 + int yearsOld = Util.getIntValue("" + params.get("yearsOld"), 3); + + //是否按照省份发放育儿假。 + int isprovince = Util.getIntValue("" + params.get("isprovince"), 1); + +// 2、在假期规则页面,增加开关控制是否开启。carryOver +// 3、增加输入框控制结转天数。 carryOverDays + int carryOver = Util.getIntValue("" + params.get("carryOver"), 0); + double carryOverDays = Util.getDoubleValue((String) params.get("carryOverDays"), 0); + + /*转正之前是否发放假期余额:0-不发放、1-发放*/ + int beforeFormal = Util.getIntValue("" + params.get("beforeFormal"), 1); + + if (scopeType != 0 && scopeValue.equals("")) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(388858, user.getLanguage()));//参数有误 + return resultMap; + } + /*两个不同的假期类型下不能同时存在 加班时长自动计入余额 的余额发放方式*/ + if (distributionMode == 5) { + releaseRule = 0; + Map data = KQLeaveRulesBiz.isRepeat(ruleId,scopeType,scopeValue,user,""); + if(null != data && "1".equals(data.get("flag"))){ + resultMap.put("status", "-1"); + resultMap.put("message", data.get("msg"));//两个不同的假期类型下不能同时存在 加班时长自动计入余额 的余额发放方式 + return resultMap; + } +// String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id<>? and id in (select ruleId from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5)"; +// RecordSet recordSet = new RecordSet(); +// recordSet.executeQuery(sql, ruleId); +// if (recordSet.next()) { +// resultMap.put("status", "-1"); +// resultMap.put("message", SystemEnv.getHtmlLabelName(505664, user.getLanguage()));//两个不同的假期类型下不能同时存在 加班时长自动计入余额 的余额发放方式 +// return resultMap; +// } + if(null != deductorder && deductorder.length()>0){ + String[] orders = deductorder.split(","); + if(null != orders && orders.length != 3){ + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(547752, user.getLanguage())); + return resultMap; + } + } + } else if (distributionMode == 6) { + /*同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存*/ + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode<>6"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505665, user.getLanguage()));//同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存 + return resultMap; + } + } else if (distributionMode == 8) { + /*同一假期类型下 育儿假 不能与其他余额发放方式共存*/ + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode<>8"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(546858, user.getLanguage()));//同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存 + return resultMap; + } + sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=8"; + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + int severalChildrenValue = Util.getIntValue(Util.null2s(recordSet.getString("severalChildren"), "0"), 0); + if(severalChildrenValue!=severalChildren){ + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(546859, user.getLanguage()));//同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存 + return resultMap; + } + } + } else { + /*同一个假期类型下其他余额发放方式不能与 按司龄+工龄自动发放 共存*/ + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=6"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505666, user.getLanguage()));//同一个假期类型下其他余额发放方式不能与 按司龄+工龄自动发放 共存 + return resultMap; + } + + //同一个假期类型下其他余额发放方式不能与 加班时长自动计入余额 共存 + sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=5"; + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(510357, user.getLanguage()));//同一个假期类型下其他余额发放方式不能与 加班时长自动计入余额 共存 + return resultMap; + } + //同一个假期类型下其他余额发放方式不能与 育儿假叠加 共存 + sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=8"; + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(546858, user.getLanguage())); + return resultMap; + } + } + + String searchSql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(searchSql, ruleId); + while (recordSet.next()) { + int scopeTypeTemp = Util.getIntValue(recordSet.getString("scopeType"), 0); + String scopeValueTemp = recordSet.getString("scopeValue"); + + if (scopeType == 0 && scopeTypeTemp == 0) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505667, user.getLanguage()));//该假期类型下已经新建过总部的假期规则,请勿重复新建 + return resultMap; + } + if (scopeType == 1 && scopeTypeTemp == 1) { + List scopeValueTempList = Util.TokenizerString(scopeValueTemp, ","); + List scopeValueList = Util.TokenizerString(scopeValue, ","); + for (String temp : scopeValueList) + if (scopeValueTempList.contains(temp)) { + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + String subcomName = subCompanyComInfo.getSubCompanyname(temp); + + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505668, user.getLanguage()).replace("$", subcomName));//该假期类型下已经新建过分部的假期规则,请勿重复新建 + return resultMap; + } + } + if (scopeType == 2 && scopeTypeTemp == 2) { + List scopeValueTempList = Util.TokenizerString(scopeValueTemp, ","); + List scopeValueList = Util.TokenizerString(scopeValue, ","); + for (String temp : scopeValueList) + if (scopeValueTempList.contains(temp)) { + DepartmentComInfo comInfo = new DepartmentComInfo(); + String name = comInfo.getDepartmentname(temp); + + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(534890, user.getLanguage()).replace("$", name));//该假期类型下已经新建过部门的假期规则,请勿重复新建 + return resultMap; + } + } + if (scopeType == 3 && scopeTypeTemp == 3) { + List scopeValueTempList = Util.TokenizerString(scopeValueTemp, ","); + List scopeValueList = Util.TokenizerString(scopeValue, ","); + for (String temp : scopeValueList) + if (scopeValueTempList.contains(temp)) { + ResourceComInfo comInfo = new ResourceComInfo(); + String name = comInfo.getLastname(temp); + + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(534891, user.getLanguage()).replace("$", name));//该假期类型下已经新建过人员的假期规则,请勿重复新建 + return resultMap; + } + } + } + boolean flag = false;//数据是否插入成功 + String sql = "insert into kq_LeaveRulesDetail(ruleId,ruleName,scopeType,scopeValue," + + "distributionMode,annualAmount,legalKey,welfareKey,priority,validityRule,effectiveDays,effectiveMonths,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod,convertMode,excludeSubAccount,beforeFormal,severalChildren,yearsOld,isprovince,carryOver,carryOverDays,deductorder,isDelete) values(?,?,?,?, ?,?,?,?, ?,?,?,?, ?,?,?,?, ?,?,?,?, ?,?,?,?,?,?,?,0)"; + flag = recordSet.executeUpdate(sql, ruleId, ruleName, scopeType, scopeValue, + distributionMode, annualAmount, legalKey, welfareKey, priority, validityRule, effectiveDays, effectiveMonths, expirationMonth, expirationDay, extensionEnable, extendedDays, releaseRule, calcMethod, convertMode, excludeSubAccount, beforeFormal,severalChildren,yearsOld,isprovince,carryOver,carryOverDays,deductorder); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + + /*获取刚才插入的假期规则详情的ID*/ + int ruleDetailId = 0; + sql = "select max(id) maxId from kq_LeaveRulesDetail"; + recordSet.executeQuery(sql); + if (recordSet.next()) { + ruleDetailId = Util.getIntValue(recordSet.getString("maxId"), 0); + } + + if ((distributionMode == 2 || distributionMode == 7) && ruleDetailId != 0) { + int lowerLimit = 0;//司龄下限 + int upperLimit = 0;//司龄上限 + String data = Util.null2String(params.get("detailRule")); + JSONArray jsonArray = JSONArray.parseArray(data); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int timePoint = jsonObject.getIntValue("timePoint"); + double amount = jsonObject.getDoubleValue("amount"); + + lowerLimit = i == 0 ? 0 : timePoint; + upperLimit = i == jsonArray.size() - 1 ? 9999 : jsonArray.getJSONObject(i + 1).getIntValue("timePoint"); + + sql = "insert into kq_EntryToLeave(leaveRulesId,lowerLimit,upperLimit,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, lowerLimit, upperLimit, amount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + + if (distributionMode == 3 && ruleDetailId != 0) { + int lowerLimit = 0;//工龄下限 + int upperLimit = 0;//工龄上限 + String data = Util.null2String(params.get("detailRule")); + JSONArray jsonArray = JSONArray.parseArray(data); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int timePoint = jsonObject.getIntValue("timePoint"); + double amount = jsonObject.getDoubleValue("amount"); + + lowerLimit = i == 0 ? 0 : timePoint; + upperLimit = i == jsonArray.size() - 1 ? 9999 : jsonArray.getJSONObject(i + 1).getIntValue("timePoint"); + + sql = "insert into kq_WorkingAgeToLeave(leaveRulesId,lowerLimit,upperLimit,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, lowerLimit, upperLimit, amount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + + if (distributionMode == 6 && ruleDetailId != 0) { + String mixModeData = Util.null2String(params.get("legalRule")); + JSONArray jsonArray = JSONArray.parseArray(mixModeData); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int workYear = jsonObject.getIntValue("workYear"); + int entryTime = jsonObject.getIntValue("entryTime"); + double legalAmount = jsonObject.getDoubleValue("legalAmount"); + + sql = "insert into kq_MixModeToLegalLeave(leaveRulesId,limit1,limit2,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, workYear, entryTime, legalAmount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + + mixModeData = Util.null2String(params.get("welfareRule")); + jsonArray = JSONArray.parseArray(mixModeData); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int workYear = jsonObject.getIntValue("workYear"); + int entryTime = jsonObject.getIntValue("entryTime"); + double welfareAmount = jsonObject.getDoubleValue("welfareAmount"); + + sql = "insert into kq_MixModeToWelfareLeave(leaveRulesId,limit1,limit2,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, workYear, entryTime, welfareAmount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + + if (distributionMode == 8 && ruleDetailId != 0) { + int provinceidValue = 0;//省份id + int yearsOldValue = 0;//孩子周岁 + double amountValue = 0;//假期天数 + String data = Util.null2String(params.get("detailRule")); + JSONArray jsonArray = JSONArray.parseArray(data); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + provinceidValue = jsonObject.getIntValue("provinceid"); + yearsOldValue = jsonObject.getIntValue("yearsOld"); + amountValue = jsonObject.getDoubleValue("amount"); + + sql = "insert into kq_provinceToLeave(leaveRulesId,provinceid,yearsOld,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, provinceidValue, yearsOldValue, amountValue); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + + if (flag) { + resultMap.put("sign", "1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功 + } + } catch (Exception e) { + writeLog(e); + } finally { + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + detailComInfo.removeCache(); + } + return resultMap; + } +} diff --git a/src/com/engine/kq/cmd/leaverules/EditLeaveRulesCmd.java b/src/com/engine/kq/cmd/leaverules/EditLeaveRulesCmd.java new file mode 100644 index 0000000..0de627d --- /dev/null +++ b/src/com/engine/kq/cmd/leaverules/EditLeaveRulesCmd.java @@ -0,0 +1,489 @@ +package com.engine.kq.cmd.leaverules; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.constant.BizLogSmallType4Hrm; +import com.engine.common.constant.BizLogType; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.KQLeaveRulesBiz; +import com.engine.kq.biz.KQLeaveRulesDetailComInfo; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 假期规则--编辑 + */ +public class EditLeaveRulesCmd extends AbstractCommonCommand> { + + private SimpleBizLogger logger; + + public EditLeaveRulesCmd(Map params, User user) { + this.user = user; + this.params = params; + this.logger = new SimpleBizLogger(); + + int ruleDetailId = Util.getIntValue((String) params.get("ruleId")); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM_ENGINE);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_LEAVERULES);//所属大类型 + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_LEAVERULES);//当前小类型 + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String mainSql = "select * from kq_LeaveRulesDetail where id=" + ruleDetailId; + logger.setMainSql(mainSql, "id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("rulename"); + + SimpleBizLogger.SubLogInfo subLogInfo1 = logger.getNewSubLogInfo(); + String subSql1 = "select * from kq_EntryToLeave where leaveRulesId=" + ruleDetailId; + subLogInfo1.setSubSql(subSql1, "id"); + logger.addSubLogInfo(subLogInfo1); + + SimpleBizLogger.SubLogInfo subLogInfo2 = logger.getNewSubLogInfo(); + String subSql2 = "select * from kq_WorkingAgeToLeave where leaveRulesId=" + ruleDetailId; + subLogInfo2.setSubSql(subSql2, "id"); + logger.addSubLogInfo(subLogInfo2); + + SimpleBizLogger.SubLogInfo subLogInfo3 = logger.getNewSubLogInfo(); + String subSql3 = "select * from kq_MixModeToLegalLeave where leaveRulesId=" + ruleDetailId; + subLogInfo3.setSubSql(subSql3, "id"); + logger.addSubLogInfo(subLogInfo3); + + SimpleBizLogger.SubLogInfo subLogInfo4 = logger.getNewSubLogInfo(); + String subSql4 = "select * from kq_MixModeToLegalLeave where leaveRulesId=" + ruleDetailId; + subLogInfo4.setSubSql(subSql4, "id"); + logger.addSubLogInfo(subLogInfo4); + + logger.before(bizLogContext); + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public List getLogContexts() { + return logger.getBizLogContexts(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map resultMap = new HashMap(); + try { + boolean canEdit = HrmUserVarify.checkUserRight("KQLeaveRulesEdit:Edit", user);//是否具有新建权限 + if (!canEdit) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return resultMap; + } + /*假期类型的ID*/ + int ruleId = Util.getIntValue((String) params.get("typeId")); + + /*假期规则详情的ID*/ + int ruleDetailId = Util.getIntValue((String) params.get("ruleId")); + + /*假期规则名称*/ + String ruleName = Util.null2String(params.get("ruleName")); + + /*应用范围:0-总部、1-分部*/ + int scopeType = Util.getIntValue((String) params.get("scopeType")); + + /*应用范围为分部时,选择的分部ID*/ + String scopeValue = Util.null2String(params.get("scopeValue")); + String deductorder = Util.null2String(params.get("deductorder")); + + /*应用范围为部门时,选择的部门ID*/ + String scopeValueDepartment = Util.null2String(params.get("scopeValueDepartment")); + + /*应用范围为人员时,选择的人员ID*/ + String scopeValueMember = Util.null2String(params.get("scopeValueMember")); + + if(scopeType == 2) { + scopeValue = scopeValueDepartment; + } else if(scopeType == 3) { + scopeValue = scopeValueMember; + } + + /*余额发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、 5-加班时长自动计入余额*/ + int distributionMode = Util.getIntValue((String) params.get("distributionMode"), 1); + + /*每人发放小时(天)数(当余额发放方式为每年自动发放固定天数时有效)*/ + double annualAmount = Util.getDoubleValue((String) params.get("annualAmount"), 0); + + /*扣减优先级:1-法定年假、2-福利年假*/ + int priority = Util.getIntValue((String) params.get("priority"), 1); + + //法定年假规则:0-工龄、1-司龄、2-工龄+司龄 (当余额发放方式为按工龄+司龄自动发放时有效) + String legalKey = Util.null2s((String) params.get("legalKey"), "0"); + + //福利年假规则:0-工龄、1-工龄、2-工龄+司龄 (当余额发放方式为按工龄+司龄自动发放时有效) + String welfareKey = Util.null2s((String) params.get("welfareKey"), "1"); + + /*有效期规则:0-不限制、1-按自然月(1月1日-12月31日)、2-按入职日期起12个月、3-自定义次年失效日期、4-自定义有效天数*/ + int validityRule = Util.getIntValue((String) params.get("validityRule"), 1); + + /*有效期天数:(当有效期天数选择按天数失效的时候有效)*/ + int effectiveDays = Util.getIntValue((String) params.get("effectiveDays"), 30); + + //有效月数(当有效期规则选择自定义有效月数时) + int effectiveMonths = Util.getIntValue((String) params.get("effectiveMonths"), 1); + + /*失效日期--月(当有效期规则选择3-自定义次年失效日期时有效)*/ + String expirationMonth = Util.null2String(params.get("expirationMonth")); + + /*失效日期--日(当有效期规则选择3-自定义次年失效日期时有效)*/ + String expirationDay = Util.null2String(params.get("expirationDay")); + + /*允许延长有效期:0-不允许、1-允许*/ + int extensionEnable = Util.getIntValue((String) params.get("extensionEnable"), 0); + + /*允许超过有效期天数*/ + int extendedDays = Util.getIntValue((String) params.get("extendedDays"), 0); + + /*释放规则:0-不限制、1-按天释放、2-按月释放*/ + int releaseRule = Util.getIntValue((String) params.get("releaseRule"), 0); + + /*假期基数计算方式:0-精确计算、1-按最少的假期余额计算、2-按最多的假期余额计算*/ + int calcMethod = Util.getIntValue((String) params.get("calcMethod"), 0); + + /*是否折算:0-不折算、1-四舍五入、2-向上取整、3-向下取整、4-向上取0.5的倍数、5-向下取0.5的倍数*/ + int convertMode = Util.getIntValue("" + params.get("convertMode"), 1); + + /*次账号是否发放假期余额:0-不发放、1-发放*/ + int excludeSubAccount = Util.getIntValue("" + params.get("excludeSubAccount"), 1); + + /*转正之前是否发放假期余额:0-不发放、1-发放*/ + int beforeFormal = Util.getIntValue("" + params.get("beforeFormal"), 1); + + //多孩叠加开关。 + int severalChildren = Util.getIntValue("" + params.get("severalChildren"), 0); + + //孩子多少周岁前发放。 + int yearsOld = Util.getIntValue("" + params.get("yearsOld"), 3); + + //是否按照省份发放育儿假。 + int isprovince = Util.getIntValue("" + params.get("isprovince"), 1); +// 2、在假期规则页面,增加开关控制是否开启。carryOver +// 3、增加输入框控制结转天数。 carryOverDays + + int carryOver = Util.getIntValue("" + params.get("carryOver"), 0); + double carryOverDays = Util.getDoubleValue((String) params.get("carryOverDays"), 0); + if (scopeType == 1 && scopeValue.equals("")) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(388858, user.getLanguage()));//参数有误 + return resultMap; + } + if (distributionMode == 5) { + releaseRule = 0; + Map data = KQLeaveRulesBiz.isRepeat(Util.null2String(ruleId),scopeType,scopeValue,user,Util.null2String(ruleDetailId)); + if(null != data && "1".equals(data.get("flag"))){ + resultMap.put("status", "-1"); + resultMap.put("message", data.get("msg"));//两个不同的假期类型下不能同时存在 加班时长自动计入余额 的余额发放方式 + return resultMap; + } + /*两个不同的假期类型下不能同时存在 加班时长自动计入余额 的余额发放方式*/ +// String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id<>? and id in (select ruleId from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5)"; +// RecordSet recordSet = new RecordSet(); +// recordSet.executeQuery(sql, ruleId); +// if (recordSet.next()) { +// resultMap.put("status", "-1"); +// resultMap.put("message", SystemEnv.getHtmlLabelName(505664, user.getLanguage()));//两个不同的假期类型下不能同时存在 加班时长自动计入余额 的余额发放方式 +// return resultMap; +// } + if(null != deductorder && deductorder.length()>0){ + String[] orders = deductorder.split(","); + if(null != orders && orders.length != 3){ + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(547752, user.getLanguage())); + return resultMap; + } + } + } else if (distributionMode == 6) { + /*同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存*/ + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode<>6"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505665, user.getLanguage()));//同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存 + return resultMap; + } + }else if (distributionMode == 8) { + /*同一假期类型下 育儿假 不能与其他余额发放方式共存*/ + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode<>8"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(546858, user.getLanguage()));//同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存 + return resultMap; + } + sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=8 and id<>?"; + recordSet.executeQuery(sql, ruleId,ruleDetailId); + if (recordSet.next()) { + int severalChildrenValue = Util.getIntValue(Util.null2s(recordSet.getString("severalChildren"), "0"), 0); + if(severalChildrenValue!=severalChildren){ + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(546859, user.getLanguage()));//同一假期类型下 按司龄+工龄自动发放 不能与其他余额发放方式共存 + return resultMap; + } + } + } else { + /*同一个假期类型下其他余额发放方式不能与 按司龄+工龄自动发放 共存*/ + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=6"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505666, user.getLanguage()));//同一个假期类型下其他余额发放方式不能与 按司龄+工龄自动发放 共存 + return resultMap; + } + + //同一个假期类型下其他余额发放方式不能与 加班时长自动计入余额 共存 + sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=5"; + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(510357, user.getLanguage()));//同一个假期类型下其他余额发放方式不能与 加班时长自动计入余额 共存 + return resultMap; + } + //同一个假期类型下其他余额发放方式不能与 育儿假叠加 共存 + sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and distributionMode=8"; + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(546858, user.getLanguage())); + return resultMap; + } + } + + String searchSql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=? and id<>?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(searchSql, ruleId, ruleDetailId); + while (recordSet.next()) { + int scopeTypeTemp = Util.getIntValue(recordSet.getString("scopeType"), 0); + String scopeValueTemp = recordSet.getString("scopeValue"); + + if (scopeType == 0 && scopeTypeTemp == 0) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505667, user.getLanguage()));//该假期类型下已经新建过总部的假期规则,请勿重复新建 + return resultMap; + } + if (scopeType == 1 && scopeTypeTemp == 1) { + List scopeValueTempList = Util.TokenizerString(scopeValueTemp, ","); + List scopeValueList = Util.TokenizerString(scopeValue, ","); + for (String temp : scopeValueList) + if (scopeValueTempList.contains(temp)) { + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + String subcomName = subCompanyComInfo.getSubCompanyname(temp); + + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(505668, user.getLanguage()).replace("$", subcomName));//该假期类型下已经新建过分部的假期规则,请勿重复新建 + return resultMap; + } + } + if (scopeType == 2 && scopeTypeTemp == 2) { + List scopeValueTempList = Util.TokenizerString(scopeValueTemp, ","); + List scopeValueList = Util.TokenizerString(scopeValue, ","); + for (String temp : scopeValueList) + if (scopeValueTempList.contains(temp)) { + DepartmentComInfo comInfo = new DepartmentComInfo(); + String name = comInfo.getDepartmentname(temp); + + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(534890, user.getLanguage()).replace("$", name));//该假期类型下已经新建过部门的假期规则,请勿重复新建 + return resultMap; + } + } + if (scopeType == 3 && scopeTypeTemp == 3) { + List scopeValueTempList = Util.TokenizerString(scopeValueTemp, ","); + List scopeValueList = Util.TokenizerString(scopeValue, ","); + for (String temp : scopeValueList) + if (scopeValueTempList.contains(temp)) { + ResourceComInfo comInfo = new ResourceComInfo(); + String name = comInfo.getLastname(temp); + + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(534891, user.getLanguage()).replace("$", name));//该假期类型下已经新建过人员的假期规则,请勿重复新建 + return resultMap; + } + } + } + boolean flag = false;//数据是否更新成功 + String sql = "update kq_LeaveRulesDetail set ruleId=?,ruleName=?,scopeType=?,scopeValue=?," + + "distributionMode=?,annualAmount=?,legalKey=?,welfareKey=?,priority=?,validityRule=?,effectiveDays=?,effectiveMonths=?,expirationMonth=?,expirationDay=?,extensionEnable=?,extendedDays=?,releaseRule=?,calcMethod=?,convertMode=?,excludeSubAccount=?,beforeFormal=?,severalChildren=?,yearsOld=?,isprovince=? ,carryOver=?,carryOverDays=?,deductorder=? where id=?"; + flag = recordSet.executeUpdate(sql, ruleId, ruleName, scopeType, scopeValue, + distributionMode, annualAmount, legalKey, welfareKey, priority, validityRule, effectiveDays, effectiveMonths, expirationMonth, expirationDay, extensionEnable, extendedDays, releaseRule, calcMethod, convertMode, excludeSubAccount, beforeFormal,severalChildren,yearsOld,isprovince,carryOver,carryOverDays,deductorder,ruleDetailId); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + + if ((distributionMode == 2 || distributionMode == 7) && ruleDetailId != 0) { + sql = "delete from kq_EntryToLeave where leaveRulesId=?"; + flag = recordSet.executeUpdate(sql, ruleDetailId); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + int lowerLimit = 0;//司龄下限 + int upperLimit = 0;//司龄上限 + String data = Util.null2String(params.get("detailRule")); + JSONArray jsonArray = JSONArray.parseArray(data); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int timePoint = jsonObject.getIntValue("timePoint"); + double amount = jsonObject.getDoubleValue("amount"); + + lowerLimit = i == 0 ? 0 : timePoint; + upperLimit = i == jsonArray.size() - 1 ? 9999 : jsonArray.getJSONObject(i + 1).getIntValue("timePoint"); + + sql = "insert into kq_EntryToLeave(leaveRulesId,lowerLimit,upperLimit,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, lowerLimit, upperLimit, amount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + + if (distributionMode == 3 && ruleDetailId != 0) { + sql = "delete from kq_WorkingAgeToLeave where leaveRulesId=?"; + flag = recordSet.executeUpdate(sql, ruleDetailId); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + int lowerLimit = 0;//工龄下限 + int upperLimit = 0;//工龄上限 + String data = Util.null2String(params.get("detailRule")); + JSONArray jsonArray = JSONArray.parseArray(data); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int timePoint = jsonObject.getIntValue("timePoint"); + double amount = jsonObject.getDoubleValue("amount"); + + lowerLimit = i == 0 ? 0 : timePoint; + upperLimit = i == jsonArray.size() - 1 ? 9999 : jsonArray.getJSONObject(i + 1).getIntValue("timePoint"); + + sql = "insert into kq_WorkingAgeToLeave(leaveRulesId,lowerLimit,upperLimit,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, lowerLimit, upperLimit, amount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + + if (distributionMode == 6 && ruleDetailId != 0) { + sql = "delete from kq_MixModeToLegalLeave where leaveRulesId=?"; + flag = recordSet.executeUpdate(sql, ruleDetailId); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + + sql = "delete from kq_MixModeToWelfareLeave where leaveRulesId=?"; + flag = recordSet.executeUpdate(sql, ruleDetailId); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + String mixModeData = Util.null2String(params.get("legalRule")); + JSONArray jsonArray = JSONArray.parseArray(mixModeData); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int workYear = jsonObject.getIntValue("workYear"); + int entryTime = jsonObject.getIntValue("entryTime"); + double legalAmount = jsonObject.getDoubleValue("legalAmount"); + + sql = "insert into kq_MixModeToLegalLeave(leaveRulesId,limit1,limit2,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, workYear, entryTime, legalAmount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + + mixModeData = Util.null2String(params.get("welfareRule")); + jsonArray = JSONArray.parseArray(mixModeData); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + int workYear = jsonObject.getIntValue("workYear"); + int entryTime = jsonObject.getIntValue("entryTime"); + double welfareAmount = jsonObject.getDoubleValue("welfareAmount"); + + sql = "insert into kq_MixModeToWelfareLeave(leaveRulesId,limit1,limit2,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, workYear, entryTime, welfareAmount); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + if (distributionMode == 8 && ruleDetailId != 0) { + sql = "delete from kq_provinceToLeave where leaveRulesId=?"; + flag = recordSet.executeUpdate(sql, ruleDetailId); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + int provinceidValue = 0;//省份id + int yearsOldValue = 0;//孩子周岁 + double amountValue = 0;//假期天数 + String data = Util.null2String(params.get("detailRule")); + JSONArray jsonArray = JSONArray.parseArray(data); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + provinceidValue = jsonObject.getIntValue("provinceid"); + yearsOldValue = jsonObject.getIntValue("yearsOld"); + amountValue = jsonObject.getDoubleValue("amount"); + + sql = "insert into kq_provinceToLeave(leaveRulesId,provinceid,yearsOld,amount) values(?,?,?,?)"; + flag = recordSet.executeUpdate(sql, ruleDetailId, provinceidValue, yearsOldValue, amountValue); + if (!flag) { + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + return resultMap; + } + } + } + if (flag) { + resultMap.put("sign", "1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(83551, user.getLanguage()));//保存成功 + } + } catch (Exception e) { + writeLog(e); + resultMap.put("sign", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(84544, user.getLanguage()));//保存失败 + } finally { + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + detailComInfo.removeCache(); + } + return resultMap; + } +} diff --git a/src/com/engine/kq/cmd/leaverules/GetLeaveRulesFormCmd.java b/src/com/engine/kq/cmd/leaverules/GetLeaveRulesFormCmd.java new file mode 100644 index 0000000..95706d6 --- /dev/null +++ b/src/com/engine/kq/cmd/leaverules/GetLeaveRulesFormCmd.java @@ -0,0 +1,1065 @@ +package com.engine.kq.cmd.leaverules; + +import com.api.browser.bean.SearchConditionItem; +import com.api.browser.bean.SearchConditionOption; +import com.api.hrm.bean.HrmFieldBean; +import com.api.hrm.util.HrmFieldSearchConditionComInfo; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.KQLeaveRulesComInfo; +import weaver.conn.RecordSet; +import weaver.filter.XssUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.province.ProvinceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.util.*; + +/** + * 假期规则--获取新建编辑的表单 + */ +public class GetLeaveRulesFormCmd extends AbstractCommonCommand> { + + public GetLeaveRulesFormCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + Map resultMap = new HashMap(); + try { + boolean canEdit = HrmUserVarify.checkUserRight("KQLeaveRulesEdit:Edit", user);//是否具有编辑权限 + if (!canEdit) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return resultMap; + } + /**假期类型的相关信息:*/ + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + + /*新建假期规则时选择完请假类型后会再次请求此表单接口*/ + /*规则对应的假期类型的ID*/ + String ruleId = Util.null2String(params.get("typeId")); + + /*是否启用:0-未启用、1-启用*/ + int isEnable = 1; + + /*最小请假单位:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假*/ + int minimumUnit = 1; + + /******************************************************************************/ + + /**假期规则详情的相关信息:*/ + + /*是否是编辑*/ + boolean isEdit = false; + + /*假期规则详情的ID*/ + String ruleDetailId = Util.null2String(params.get("ruleId")); + + /*假期规则名称*/ + String ruleName = ""; + + /*应用范围:0-总部、1-分部*/ + int scopeType = 0; + + /*应用范围为分部时,选择的分部ID*/ + String scopeValue = ""; + + /*余额发放方式:1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按工龄+司龄自动发放*/ + int distributionMode = 1; + + //年假基数计算方式: + // 0(精确计算)-假期基数发放日期和假期基数变动日期均为每年的01月01号(但是假期基数是结合 司龄/工龄 变化前后的值按天数比例折算出来的)、 + // 1(按最少的余额计算)-假期基数发放日期和假期基数变动日期均为每年的01月01号、 + // 2(按最多的余额计算)-假期基数发放日期发放日期为每年的01月01号,假期基数的变动日期为每年的 入职日期/参加工作日期 + int calcMethod = 1; + + //是否折算:0-不折算、1-四舍五入、2-向上取整、3-向下取整、4-向上取0.5的倍数、向下取0.5的倍数 + int convertMode = 1; + + //折算后的小数点位数 + int decimalDigit = 2; + + /*每人发放小时(天)数(当余额发放方式为是每年发放固定天数时有效)*/ + double annualAmount = 0; + + //法定年假规则:0-工龄、1-司龄、2-工龄+司龄 (当余额发放方式为按工龄+司龄自动发放时有效) + String legalKey = "0"; + + //福利年假规则:0-工龄、1司龄、2-工龄+司龄 (当余额发放方式为按工龄+司龄自动发放时有效) + String welfareKey = "1"; + + /*扣减优先级:1-法定年假、2-福利年假(当余额发放方式为按工龄+司龄自动发放时有效)*/ + int priority = 1; + + //有效期规则:0-永久有效、1-按自然年(1月1日-12月31日)、2-按入职日期起12个月、3-自定义次年失效日期、4、按天数失效、5-按季度失效、6-按月数失效 + int validityRule = 0; + + /*失效日期--月(当有效期规则选择自定义次年失效日期时有效)*/ + String expirationMonth = "1"; + + /*失效日期--日(当有效期规则选择自定义次年失效日期时有效)*/ + String expirationDay = "1"; + + //有效天数(当有效期规则选择自定义有效天数时) + String effectiveDays = "30"; + + //有效月数(当有效期规则选择自定义有效月数时) + String effectiveMonths = "1"; + + /*允许延长有效期:0-不允许、1-允许*/ + int extensionEnable = 0; + + /*允许超过有效期天数*/ + int extendedDays = 90; + + /*释放规则:0-不限制、1-按天释放、2-按月释放*/ + int releaseRule = 0; + + //是否需要排除次账号:0--不排除,即次账号正常享受年假、1--排除,即次账号不能享受年假 + int excludeSubAccount = 1; + + //转正之前是否允许发放假期余额:0-不允许、1-允许 + int beforeFormal = 1; + + //多孩叠加开关。 + int severalChildren = 0; + + //孩子多少周岁前发放。 + int yearsOld = 3; + + //是否按照省份发放育儿假。1否,2是 + String isprovince = "1"; + +// 2、在假期规则页面,增加开关控制是否开启。carryOver +// 3、增加输入框控制结转天数。 carryOverDays + + int carryOver =0; + double carryOverDays = 0; + + String deductorder =""; + + /*入职时长--年假*/ + Map entryMap = new HashMap(); + List entryList = new ArrayList(); + + /*工龄--年假*/ + Map workingAgeMap = new HashMap(); + List workingAgeList = new ArrayList(); + + /*入职时长+工龄混合--年假*/ + Map mixedModeMap = new HashMap(); + List mixedModeList = new ArrayList(); + + if (!ruleDetailId.equals("")) { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete != 1) and id=" + ruleDetailId; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + if (recordSet.next()) { + isEdit = true; + + ruleName = recordSet.getString("ruleName"); + ruleId = recordSet.getString("ruleId"); + scopeType = recordSet.getInt("scopeType"); + scopeValue = recordSet.getString("scopeValue"); + deductorder = recordSet.getString("deductorder"); + distributionMode = Util.getIntValue(recordSet.getString("distributionMode"), 1); + annualAmount = Util.getDoubleValue(recordSet.getString("annualAmount"), 0); + legalKey = "" + Util.getIntValue(recordSet.getString("legalKey"), 0); + welfareKey = "" + Util.getIntValue(recordSet.getString("welfareKey"), 1); + priority = Util.getIntValue(recordSet.getString("priority"), 1); + validityRule = Util.getIntValue(recordSet.getString("validityRule"), 0); + effectiveDays = Util.null2s(recordSet.getString("effectiveDays"), "30"); + effectiveMonths = Util.null2s(recordSet.getString("effectiveMonths"),"1"); + expirationMonth = Util.null2s(recordSet.getString("expirationMonth"), "1"); + expirationDay = Util.null2s(recordSet.getString("expirationDay"), "1"); + extensionEnable = Util.getIntValue(recordSet.getString("extensionEnable"), 0); + extendedDays = Util.getIntValue(recordSet.getString("extendedDays"), 90); + releaseRule = Util.getIntValue(recordSet.getString("releaseRule"), 0); + calcMethod = Util.getIntValue(recordSet.getString("calcMethod"), 1); + convertMode = Util.getIntValue(recordSet.getString("convertMode"), 1); + excludeSubAccount = Util.getIntValue(recordSet.getString("excludeSubAccount"), 1); + beforeFormal = Util.getIntValue(recordSet.getString("beforeFormal"), 1); + severalChildren = Util.getIntValue(recordSet.getString("severalChildren"), 0); + yearsOld = Util.getIntValue(recordSet.getString("yearsOld"), 3); + isprovince = Util.null2s(recordSet.getString("isprovince"), "1"); + carryOver = Util.getIntValue(recordSet.getString("carryOver"), 0); + carryOverDays = Util.getDoubleValue(recordSet.getString("carryOverDays"), 0); + } + + if (distributionMode == 2 || distributionMode == 7) { + sql = "select * from kq_EntryToLeave where leaveRulesId = ? order by lowerLimit,upperLimit"; + recordSet.executeQuery(sql, ruleDetailId); + int lowerLimit = 0;//入职年限下限 + int upperLimit = 0;//入职年限上限 + double amount = 0;//假期天数 + while (recordSet.next()) { + lowerLimit = recordSet.getInt("lowerLimit"); + upperLimit = recordSet.getInt("upperLimit"); + amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + + entryMap = new HashMap(); + entryMap.put("timePoint", lowerLimit); + entryMap.put("amount", String.format("%.2f", amount)); + entryList.add(entryMap); + } + resultMap.put("detailRule", entryList); + } + + if (distributionMode == 3) { + sql = "select * from kq_WorkingAgeToLeave where leaveRulesId = ? order by lowerLimit,upperLimit"; + recordSet.executeQuery(sql, ruleDetailId); + int lowerLimit = 0;//工龄下限 + int upperLimit = 0;//工龄上限 + double amount = 0;//假期天数 + while (recordSet.next()) { + lowerLimit = recordSet.getInt("lowerLimit"); + upperLimit = recordSet.getInt("upperLimit"); + amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + + workingAgeMap = new HashMap(); + workingAgeMap.put("timePoint", lowerLimit); + workingAgeMap.put("amount", String.format("%.2f", amount)); + workingAgeList.add(workingAgeMap); + } + resultMap.put("detailRule", workingAgeList); + } + + if (distributionMode == 6) { + sql = "select * from kq_MixModeToLegalLeave where leaveRulesId=? order by id "; + recordSet.executeQuery(sql, ruleDetailId); + double limit1 = 0;//工龄下限 + double limit2 = 0;//司龄下限 + double amount = 0;//法定年假天数or福利年假天数 + while (recordSet.next()) { + limit1 = Util.getDoubleValue(recordSet.getString("limit1"), 0); + limit2 = Util.getDoubleValue(recordSet.getString("limit2"), 0); + amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + + mixedModeMap = new HashMap(); + if (legalKey.equals("0") || legalKey.equals("2")) { + mixedModeMap.put("workYear", limit1); + } + if (legalKey.equals("1") || legalKey.equals("2")) { + mixedModeMap.put("entryTime", limit2); + } + mixedModeMap.put("legalAmount", String.format("%.2f", amount)); + mixedModeList.add(mixedModeMap); + } + resultMap.put("legalRule", mixedModeList); + resultMap.put("legalKey", legalKey); + + mixedModeList = new ArrayList(); + sql = "select * from kq_MixModeToWelfareLeave where leaveRulesId=? order by id "; + recordSet.executeQuery(sql, ruleDetailId); + while (recordSet.next()) { + limit1 = Util.getDoubleValue(recordSet.getString("limit1"), 0); + limit2 = Util.getDoubleValue(recordSet.getString("limit2"), 0); + amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + + mixedModeMap = new HashMap(); + if (welfareKey.equals("0") || welfareKey.equals("2")) { + mixedModeMap.put("workYear", limit1); + } + if (welfareKey.equals("1") || welfareKey.equals("2")) { + mixedModeMap.put("entryTime", limit2); + } + mixedModeMap.put("welfareAmount", String.format("%.2f", amount)); + mixedModeList.add(mixedModeMap); + } + resultMap.put("welfareRule", mixedModeList); + resultMap.put("welfareKey", welfareKey); + } + if (distributionMode == 8) { + sql = "select * from kq_provinceToLeave where leaveRulesId = ? order by id "; + recordSet.executeQuery(sql, ruleDetailId); + int provinceid = 0;//省份id + int yearsOldValue = 0;//孩子周岁 + int id = 0;//id + double amount = 0;//假期天数 + String provincename = ""; + ProvinceComInfo coun = new ProvinceComInfo(); + while (recordSet.next()) { + id = recordSet.getInt("id"); + provinceid = recordSet.getInt("provinceid"); + yearsOldValue = recordSet.getInt("yearsOld"); + amount = Util.getDoubleValue(recordSet.getString("amount"), 0); + provincename = coun.getProvincename(provinceid + ""); + workingAgeMap = new HashMap(); + workingAgeMap.put("id", id); + workingAgeMap.put("provinceid", provinceid); + workingAgeMap.put("provincename", provincename); + workingAgeMap.put("yearsOld", yearsOldValue); + workingAgeMap.put("amount", String.format("%.2f", amount)); + workingAgeList.add(workingAgeMap); + } + resultMap.put("detailRule", workingAgeList); + } + } + + if (isEdit) { + isEnable = Util.getIntValue(rulesComInfo.getIsEnable(ruleId), 1); + } + + List> groupList = new ArrayList>(); + Map groupItem = new HashMap(); + List itemList = new ArrayList(); + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + SearchConditionItem searchConditionItem = null; + HrmFieldBean hrmFieldBean = null; + + /****************************************************基本信息****************************************************/ + + groupItem.put("title", SystemEnv.getHtmlLabelName(1361, user.getLanguage())); + groupItem.put("defaultshow", true); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("typeId");//假期类型 + hrmFieldBean.setFieldlabel("129811"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(ruleId); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 || isEdit ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + List optionsList = new ArrayList(); + if (!isEdit) { + rulesComInfo.setTofirstRow(); + while (rulesComInfo.next()) { + if (!rulesComInfo.getIsEnable().equals("1") || !rulesComInfo.getBalanceEnable().equals("1")) { + continue; + } + optionsList.add(new SearchConditionOption(rulesComInfo.getId(), Util.formatMultiLang(rulesComInfo.getLeaveName(), "" + user.getLanguage()), ruleId.equals(rulesComInfo.getId()))); + } + } else { + optionsList.add(new SearchConditionOption(ruleId, Util.formatMultiLang(rulesComInfo.getLeaveName(ruleId), "" + user.getLanguage()), true)); + } + searchConditionItem.setOptions(optionsList); + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(505298, user.getLanguage()));//只能选择启用状态下开启了假期余额的假期类型,并且编辑假期规则时不能变更假期类型 + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("ruleName");//规则名称 + hrmFieldBean.setFieldlabel("19829"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(ruleName); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + /*应用范围是否能够选择总部,如果已经新建过总部的假期规则,则无法新建总部的假期规则*/ + boolean canSelectCom = true; + /*已经新建过某分部的假期规则,则无法继续新建该分部的假期规则*/ + String selectedSubcomIds = "", selectedDepartmentIds = "", selectedMemberIds = ""; + /*新建假期规则的时候选择完假期类型后重亲请求了此接口*/ + if (!ruleId.equals("") && !isEdit) { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + while (recordSet.next()) { + int scopeTypeTemp = Util.getIntValue(recordSet.getString("scopeType"), 0); + String scopeValueTemp = recordSet.getString("scopeValue"); + + if (scopeTypeTemp == 0) { + canSelectCom = false; + } else if (scopeTypeTemp == 1) { + selectedSubcomIds += "," + scopeValueTemp; + } else if (scopeTypeTemp == 2) { + selectedDepartmentIds += "," + scopeValueTemp; + } else if (scopeTypeTemp == 3) { + selectedMemberIds += "," + scopeValueTemp; + } + } + } + selectedSubcomIds = selectedSubcomIds.length() > 0 ? selectedSubcomIds.substring(1) : ""; + selectedDepartmentIds = selectedDepartmentIds.length() > 0 ? selectedDepartmentIds.substring(1) : ""; + selectedMemberIds = selectedMemberIds.length() > 0 ? selectedMemberIds.substring(1) : ""; + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("scopeType");//此规则适用范围 + hrmFieldBean.setFieldlabel("19374"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 || !canSelectCom ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(140, user.getLanguage()), scopeType == 0 || !canSelectCom)); + optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(33553, user.getLanguage()), scopeType == 1)); + optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(124, user.getLanguage()), scopeType == 2)); + optionsList.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(1867, user.getLanguage()), scopeType == 3)); + searchConditionItem.setOptions(optionsList); + //对于一个请假类型,各分部能够且仅能够设置一个属于本分部的假期规则,如果未设置本分部的假期规则,默认取总部的假期规则,如果总部也未设置,则假期基数视作0.00 + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(534889, user.getLanguage())); + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("scopeValue");//分部 + hrmFieldBean.setFieldlabel("33553"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("170"); + hrmFieldBean.setFieldvalue(scopeType == 1 ? scopeValue : ""); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "KQLeaveRulesAdd:Add"); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("rightStr", "KQLeaveRulesAdd:Add"); + if (selectedSubcomIds.length() > 0) { + XssUtil xssUtil = new XssUtil(); + String sqlWhere = " id not in (" + selectedSubcomIds + ") "; + searchConditionItem.getBrowserConditionParam().getDataParams().put("sqlWhere", xssUtil.put(sqlWhere)); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("sqlWhere", xssUtil.put(sqlWhere)); + searchConditionItem.getBrowserConditionParam().getDestDataParams().put("sqlWhere", xssUtil.put(sqlWhere)); + } + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("scopeValueDepartment");//部门 + hrmFieldBean.setFieldlabel("124"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("168"); + hrmFieldBean.setFieldvalue(scopeType == 2 ? scopeValue : ""); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "KQLeaveRulesAdd:Add"); + if (selectedDepartmentIds.length() > 0) { + XssUtil xssUtil = new XssUtil(); + String sqlWhere = " id not in (" + selectedDepartmentIds + ") "; + searchConditionItem.getBrowserConditionParam().getDataParams().put("sqlWhere", xssUtil.put(sqlWhere)); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("sqlWhere", xssUtil.put(sqlWhere)); + searchConditionItem.getBrowserConditionParam().getDestDataParams().put("sqlWhere", xssUtil.put(sqlWhere)); + } + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("scopeValueMember");//人员 + hrmFieldBean.setFieldlabel("1867"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("166"); + hrmFieldBean.setFieldvalue(scopeType == 3 ? scopeValue : ""); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "KQLeaveRulesAdd:Add"); + if (selectedMemberIds.length() > 0) { + XssUtil xssUtil = new XssUtil(); + String sqlWhere = " id not in (" + selectedMemberIds + ") "; + searchConditionItem.getBrowserConditionParam().getDataParams().put("sqlWhere", xssUtil.put(sqlWhere)); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("sqlWhere", xssUtil.put(sqlWhere)); + searchConditionItem.getBrowserConditionParam().getDestDataParams().put("sqlWhere", xssUtil.put(sqlWhere)); + } + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + groupItem.put("items", itemList); + groupList.add(groupItem); + + /****************************************************发放规则****************************************************/ + + groupItem = new HashMap(); + itemList = new ArrayList(); + groupItem.put("title", SystemEnv.getHtmlLabelName(508539, user.getLanguage())); + groupItem.put("defaultshow", true); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("distributionMode");//余额发放方式 + hrmFieldBean.setFieldlabel("388946"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr((isEnable == 0 || (isEdit && distributionMode == 6)) ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(388947, user.getLanguage()), distributionMode == 1)); + optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(390374, user.getLanguage()), distributionMode == 2)); + optionsList.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(388949, user.getLanguage()), distributionMode == 3)); + optionsList.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(390323, user.getLanguage()), distributionMode == 4)); + optionsList.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(388951, user.getLanguage()), distributionMode == 5)); + SearchConditionOption searchConditionOption = new SearchConditionOption("6", SystemEnv.getHtmlLabelName(390822, user.getLanguage()), distributionMode == 6); + searchConditionOption.setDisabled((isEdit && distributionMode != 6) ? true : false); + optionsList.add(searchConditionOption); + optionsList.add(new SearchConditionOption("7", SystemEnv.getHtmlLabelName(514025, user.getLanguage()), distributionMode == 7)); + optionsList.add(new SearchConditionOption("8", SystemEnv.getHtmlLabelName(536880, user.getLanguage()), distributionMode == 8)); + searchConditionItem.setOptions(optionsList); + searchConditionItem.setHelpfulTip("★" + SystemEnv.getHtmlLabelName(10000815,user.getLanguage()) + "★" + SystemEnv.getHtmlLabelName(501107, user.getLanguage())); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + List distributionModeTips = new ArrayList(); + distributionModeTips.add(SystemEnv.getHtmlLabelName(389735, user.getLanguage()) + " " + SystemEnv.getHtmlLabelName(511045, user.getLanguage()) + ""); + distributionModeTips.add(SystemEnv.getHtmlLabelName(500952, user.getLanguage()) + " " + SystemEnv.getHtmlLabelName(511045, user.getLanguage()) + ""); + distributionModeTips.add(SystemEnv.getHtmlLabelName(500953, user.getLanguage()) + " " + SystemEnv.getHtmlLabelName(511046, user.getLanguage()) + ""); + distributionModeTips.add(SystemEnv.getHtmlLabelName(389736, user.getLanguage()) + " " + SystemEnv.getHtmlLabelName(511045, user.getLanguage()) + ""); + distributionModeTips.add(SystemEnv.getHtmlLabelName(389737, user.getLanguage()) + " " + SystemEnv.getHtmlLabelName(511045, user.getLanguage()) + ""); + distributionModeTips.add(SystemEnv.getHtmlLabelName(500954, user.getLanguage()) + " " + SystemEnv.getHtmlLabelName(511046, user.getLanguage()) + ""); + distributionModeTips.add(SystemEnv.getHtmlLabelName(514026, user.getLanguage()) + " " + SystemEnv.getHtmlLabelName(511045, user.getLanguage()) + ""); + distributionModeTips.add(SystemEnv.getHtmlLabelName(536881, user.getLanguage())); + resultMap.put("distributionMode", distributionModeTips); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("calcMethod");//假期基数计算方式 + hrmFieldBean.setFieldlabel("501121"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(505302, user.getLanguage()), calcMethod == 0)); + optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(505303, user.getLanguage()), calcMethod == 1)); + optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(505304, user.getLanguage()), calcMethod == 2)); + searchConditionItem.setOptions(optionsList); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + List calcMethodTips = new ArrayList(); + //以入职日期(或参加工作日期)为分隔点将一年划分为上半年和下半年,全年可用假期天数=上半年天数/全年总天数*上半年司龄(或工龄)对应的假期天数+下半年天数/全年总天数*下半年司龄(或工龄)对应的假期天数。每年1月1日自动发放假期天数。 + calcMethodTips.add(SystemEnv.getHtmlLabelName(505305, user.getLanguage())); + //每年1月1日计算员工的司龄(或工龄),取对应的假期天数,于1月1日自动发放。 + calcMethodTips.add(SystemEnv.getHtmlLabelName(505306, user.getLanguage())); + //每年1月1日计算员工的司龄(或工龄),取对应的假期天数,于1月1日自动发放。若一年中员工司龄(或工龄)增加后,对应的假期天数也随之增加,则自动补发增加的假期天数。 + calcMethodTips.add(SystemEnv.getHtmlLabelName(505307, user.getLanguage())); + resultMap.put("calcMethod", calcMethodTips); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("priority");//扣减优先级 + hrmFieldBean.setFieldlabel("2093"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(129819, user.getLanguage()), priority == 1)); + optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(132046, user.getLanguage()), priority == 2)); + searchConditionItem.setOptions(optionsList); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("annualAmount");//每人发放小时数 + hrmFieldBean.setFieldlabel("503237"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(annualAmount); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|numeric"); + searchConditionItem.setPrecision(2); + searchConditionItem.setMin("0"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("carryOver"); + hrmFieldBean.setFieldlabel("546921"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(carryOver); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 2); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + Map otherParamsMap = new HashMap(); + otherParamsMap.put("display", "switch"); + searchConditionItem.setOtherParams(otherParamsMap); + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(547604, user.getLanguage())); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("carryOverDays"); + hrmFieldBean.setFieldlabel("546922"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(carryOverDays); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|numeric"); + searchConditionItem.setPrecision(2); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + //育儿假多孩叠加 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("severalChildren"); + hrmFieldBean.setFieldlabel("546788"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(severalChildren); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 2); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + otherParamsMap = new HashMap(); + otherParamsMap.put("display", "switch"); + searchConditionItem.setOtherParams(otherParamsMap); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + //育儿假孩子多少周岁 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("yearsOld"); + hrmFieldBean.setFieldlabel("546789"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(yearsOld); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|integer"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + //育儿假是否按照省份发放 +// hrmFieldBean = new HrmFieldBean(); +// hrmFieldBean.setFieldname("isprovince"); +// hrmFieldBean.setFieldlabel("546790"); +// hrmFieldBean.setFieldhtmltype("4"); +// hrmFieldBean.setType("1"); +// hrmFieldBean.setFieldvalue(isprovince); +// hrmFieldBean.setIsFormField(true); +// hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 2); +// searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); +// otherParamsMap = new HashMap(); +// otherParamsMap.put("display", "switch"); +// searchConditionItem.setOtherParams(otherParamsMap); +// if (hrmFieldBean.getViewAttr() == 1) { +// Map OtherParamsMap = new HashMap(); +// OtherParamsMap.put("hasBorder", true); +// searchConditionItem.setOtherParams(OtherParamsMap); +// } +// itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("isprovince"); + hrmFieldBean.setFieldlabel("546825"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(isprovince); + List options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(546827, user.getLanguage())+yearsOld+ + SystemEnv.getHtmlLabelName(546828, user.getLanguage())+annualAmount, + isprovince.equals("1"))); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(546790, user.getLanguage()),isprovince.equals("2"))); + hrmFieldBean.setSelectOption(options); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + otherParamsMap = new HashMap(); + otherParamsMap.put("display", "switch"); + searchConditionItem.setOtherParams(otherParamsMap); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("convertMode");//是否折算 + hrmFieldBean.setFieldlabel("508419"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(508423, user.getLanguage()), convertMode == 0)); + optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(389654, user.getLanguage()), convertMode == 1)); + optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(508424, user.getLanguage()), convertMode == 2)); + optionsList.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(508425, user.getLanguage()), convertMode == 3)); + optionsList.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(508426, user.getLanguage()), convertMode == 4)); + optionsList.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(508427, user.getLanguage()), convertMode == 5)); + searchConditionItem.setOptions(optionsList); + //当假期基数计算方式选择【精确计算】时,不能选择【不折算】 + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(510491, user.getLanguage())); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + List convertModeTips = new ArrayList(); + //指不考虑是否是入职当年还是初始获得年(即年初01月01日的时候计算工龄或者司龄,得出对应的假期基数为0。但是当这一年的工龄或者司龄增加后,对应的假期基数就不再是0了,这样的年份称作初始获得年),通过工龄或司龄计算出对应的假期基数,不做任何扣减折算 + convertModeTips.add(SystemEnv.getHtmlLabelName(510131, user.getLanguage())); + //通过工龄或司龄计算出对应的假期基数后(若是入职当年或初始获得年会进行扣减折算),折算后四舍五入保留两位小数 + convertModeTips.add(SystemEnv.getHtmlLabelName(510132, user.getLanguage())); + //通过工龄或司龄计算出对应的假期基数后(若是入职当年或初始获得年会进行扣减折算),折算后的数值取整,例如:折算后的基数为3.21,取整后为4.0 + convertModeTips.add(SystemEnv.getHtmlLabelName(510133, user.getLanguage())); + //通过工龄或司龄计算出对应的假期基数后(若是入职当年或初始获得年会进行扣减折算),折算后的数值取整,例如:折算后的基数为3.21,取整后为3.0 + convertModeTips.add(SystemEnv.getHtmlLabelName(510134, user.getLanguage())); + //通过工龄或司龄计算出对应的假期基数后(若是入职当年或初始获得年会进行扣减折算),折算后的数值取0.5的倍数,例如:折算后的基数为3.21,最终为3.5 + convertModeTips.add(SystemEnv.getHtmlLabelName(510135, user.getLanguage())); + //通过工龄或司龄计算出对应的假期基数后(若是入职当年或初始获得年会进行扣减折算),折算后的数值取0.5的倍数,例如:折算后的基数为3.21,最终后为3.0 + convertModeTips.add(SystemEnv.getHtmlLabelName(510136, user.getLanguage())); + resultMap.put("convertModeTips", convertModeTips); + + groupItem.put("items", itemList); + groupList.add(groupItem); + + /****************************************************有效期****************************************************/ + + groupItem = new HashMap(); + itemList = new ArrayList(); + groupItem.put("title", SystemEnv.getHtmlLabelName(15030, user.getLanguage())); + groupItem.put("defaultshow", true); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("validityRule");//有效期规则 + hrmFieldBean.setFieldlabel("388952"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(22135, user.getLanguage()), validityRule == 0)); + optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(388953, user.getLanguage()), validityRule == 1)); + optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(388954, user.getLanguage()), validityRule == 2)); + optionsList.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(389739, user.getLanguage()), validityRule == 3)); + optionsList.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(508428, user.getLanguage()), validityRule == 4)); + optionsList.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(513525, user.getLanguage()), validityRule == 5)); + optionsList.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(515135, user.getLanguage()), validityRule == 6)); + optionsList.add(new SearchConditionOption("7", SystemEnv.getHtmlLabelName(536941, user.getLanguage()), validityRule == 7)); + searchConditionItem.setOptions(optionsList); + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(515354, user.getLanguage())); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("effectiveDays");//有效月数 + hrmFieldBean.setFieldlabel("132356"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(effectiveDays); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|integer"); + searchConditionItem.setMin("1"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("effectiveMonths");//有效月数 + hrmFieldBean.setFieldlabel("515174"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(effectiveMonths); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|integer"); + searchConditionItem.setMin("1"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("expirationMonth");//失效日期--月 + hrmFieldBean.setFieldlabel("390103"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(expirationMonth); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + for (int i = 1; i <= 12; i++) { + if(user.getLanguage()==8){ + optionsList.add(new SearchConditionOption("" + i, i+"", Util.getIntValue(expirationMonth, 1) == i)); + }else { + optionsList.add(new SearchConditionOption("" + i, i + SystemEnv.getHtmlLabelName(383373, user.getLanguage()), Util.getIntValue(expirationMonth, 1) == i)); + } + } + searchConditionItem.setOptions(optionsList); + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("expirationDay");//失效日期--日 + hrmFieldBean.setFieldlabel("390103"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(expirationDay); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + for (int i = 1; i <= 31; i++) { + if(user.getLanguage()==8){ + optionsList.add(new SearchConditionOption("" + i, i+"", Util.getIntValue(expirationMonth, 1) == i)); + }else { + optionsList.add(new SearchConditionOption("" + i, i + SystemEnv.getHtmlLabelName(390, user.getLanguage()), Util.getIntValue(expirationDay, 1) == i)); + } + } + searchConditionItem.setOptions(optionsList); + searchConditionItem.setRules("required|string"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("extensionEnable");//允许延长有效期 + hrmFieldBean.setFieldlabel("388955"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(extensionEnable); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 2); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + otherParamsMap = new HashMap(); + otherParamsMap.put("display", "switch"); + searchConditionItem.setOtherParams(otherParamsMap); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("extendedDays");//允许延长的天数 + hrmFieldBean.setFieldlabel("389198"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(extendedDays); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|integer"); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + groupItem.put("items", itemList); + groupList.add(groupItem); + + /****************************************************其他设置****************************************************/ + + groupItem = new HashMap(); + itemList = new ArrayList(); + groupItem.put("title", SystemEnv.getHtmlLabelName(20824, user.getLanguage())); + groupItem.put("defaultshow", true); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("releaseRule");//释放规则 + hrmFieldBean.setFieldlabel("389093"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + optionsList = new ArrayList(); + optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(32499, user.getLanguage()), releaseRule == 0)); + optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(127263, user.getLanguage()), releaseRule == 1)); + optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(127262, user.getLanguage()), releaseRule == 2)); + searchConditionItem.setOptions(optionsList); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(510129, user.getLanguage())); + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("excludeSubAccount");//次账号发放假期余额 + hrmFieldBean.setFieldlabel("510174"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(excludeSubAccount); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 2); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + otherParamsMap = new HashMap(); + otherParamsMap.put("display", "switch"); + searchConditionItem.setOtherParams(otherParamsMap); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("beforeFormal");//转正之前发放假期余额 + hrmFieldBean.setFieldlabel("510175"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(beforeFormal); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(isEnable == 0 ? 1 : 2); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + otherParamsMap = new HashMap(); + otherParamsMap.put("display", "switch"); + searchConditionItem.setOtherParams(otherParamsMap); + if (hrmFieldBean.getViewAttr() == 1) { + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + + /** + *调休扣减顺序 + */ + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("deductorder"); + hrmFieldBean.setFieldlabel("547670"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("391"); + hrmFieldBean.setFieldvalue(deductorder); + hrmFieldBean.setIsFormField(true); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + List> replaceDatas = new ArrayList>(); + Map datas = new HashMap(); + if(null != deductorder){ + String[] leaveidArr = deductorder.split(","); +// Collections.sort(leaveidArr, Comparator.comparingInt(Util::getIntValue)); + if(null != leaveidArr && leaveidArr.length>0){ + for (int i = 0; i < leaveidArr.length; i++) { + String leaveid = leaveidArr[i]; + datas = new HashMap(); + datas.put("id", leaveid); + datas.put("name", "1".equals(leaveid)?"节假日":("2".equals(leaveid)?"工作日":"休息日")); + replaceDatas.add(datas); + } + } + } + searchConditionItem.getBrowserConditionParam().setReplaceDatas(replaceDatas); + Map dataMap = new HashMap(); + Map completeMap = new HashMap(); + XssUtil xssUtil = new XssUtil(); + dataMap.put("sqlWhere", xssUtil.put(" id not in (" + deductorder + ")")); + completeMap.put("sqlWhere", xssUtil.put(" id not in (" + deductorder+ ")") ); + searchConditionItem.getBrowserConditionParam().setDataParams(dataMap); + searchConditionItem.getBrowserConditionParam().setCompleteParams(completeMap); + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(547671, user.getLanguage())); + itemList.add(searchConditionItem); + + + + groupItem.put("items", itemList); + groupList.add(groupItem); + resultMap.put("condition", groupList); + resultMap.put("isEnable", "" + isEnable); + if (isEdit) { + minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(ruleId), 1); + + String unitName = "";//单位名称,天/小时 + if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) { + unitName = SystemEnv.getHtmlLabelName(1925, user.getLanguage());//天 + } else { + unitName = SystemEnv.getHtmlLabelName(391, user.getLanguage());//小时 + } + resultMap.put("unitName", unitName); + } + } catch (Exception e) { + e.printStackTrace(); + } + return resultMap; + } +} diff --git a/src/com/engine/kq/entity/KQBalanceOfLeaveEntity.java b/src/com/engine/kq/entity/KQBalanceOfLeaveEntity.java new file mode 100644 index 0000000..3d6144d --- /dev/null +++ b/src/com/engine/kq/entity/KQBalanceOfLeaveEntity.java @@ -0,0 +1,234 @@ +package com.engine.kq.entity; + +/** + * 假期余额 + */ +public class KQBalanceOfLeaveEntity { + /** + * 主键ID + */ + int id; + /** + * 假期规则ID + */ + int leaveRulesId; + /** + * 人员ID + */ + int resourceId; + /** + * 所属年份 + * 数据格式:yyyy + */ + String belongYear; + /** + * 假期余额基数 + * 混合模式下为法定年假的基数 + */ + double baseAmount = 0.00; + /** + * 已用的假期余额 + * 混合模式下为已用的法定年假的数量 + */ + double usedAmount = 0.00; + /** + * 额外的假期余额 + * 混合模式下为额外的法定年假的数量 + */ + double extraAmount = 0.00; + /** + * 仅用于混合模式下的福利年假的基数 + */ + double baseAmount2 = 0.00; + /** + * 仅用于混合模式下的已用的福利年假的数量 + */ + double usedAmount2 = 0.00; + /** + * 仅用于混合模式下的额外的福利年假的数量 + */ + double extraAmount2 = 0.00; + /** + * 是有有效:0-有效、1-无效 + */ + int status; + /** + * 失效日期 + */ + String expirationDate; + /** + * 生效日期 + */ + String effectiveDate; + /** + * 最小请假单位 + */ + int minimumUnit; + + public KQBalanceOfLeaveEntity() { + } + + public KQBalanceOfLeaveEntity(int id, int leaveRulesId, int resourceId, String belongYear, double baseAmount, double usedAmount, double extraAmount, double baseAmount2, double usedAmount2, double extraAmount2, int status, String expirationDate) { + this.id = id; + this.leaveRulesId = leaveRulesId; + this.resourceId = resourceId; + this.belongYear = belongYear; + this.baseAmount = baseAmount; + this.usedAmount = usedAmount; + this.extraAmount = extraAmount; + this.baseAmount2 = baseAmount2; + this.usedAmount2 = usedAmount2; + this.extraAmount2 = extraAmount2; + this.status = status; + this.expirationDate = expirationDate; + } + public KQBalanceOfLeaveEntity(int id, int leaveRulesId, int resourceId, String belongYear, double baseAmount, double usedAmount, double extraAmount, double baseAmount2, double usedAmount2, double extraAmount2, int status, String expirationDate ,String effectiveDate) { + this.id = id; + this.leaveRulesId = leaveRulesId; + this.resourceId = resourceId; + this.belongYear = belongYear; + this.baseAmount = baseAmount; + this.usedAmount = usedAmount; + this.extraAmount = extraAmount; + this.baseAmount2 = baseAmount2; + this.usedAmount2 = usedAmount2; + this.extraAmount2 = extraAmount2; + this.status = status; + this.expirationDate = expirationDate; + this.effectiveDate = effectiveDate; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getLeaveRulesId() { + return leaveRulesId; + } + + public void setLeaveRulesId(int leaveRulesId) { + this.leaveRulesId = leaveRulesId; + } + + public int getResourceId() { + return resourceId; + } + + public void setResourceId(int resourceId) { + this.resourceId = resourceId; + } + + public String getBelongYear() { + return belongYear; + } + + public void setBelongYear(String belongYear) { + this.belongYear = belongYear; + } + + public double getBaseAmount() { + return baseAmount; + } + + public void setBaseAmount(double baseAmount) { + this.baseAmount = baseAmount; + } + + public double getUsedAmount() { + return usedAmount; + } + + public void setUsedAmount(double usedAmount) { + this.usedAmount = usedAmount; + } + + public double getExtraAmount() { + return extraAmount; + } + + public void setExtraAmount(double extraAmount) { + this.extraAmount = extraAmount; + } + + public double getBaseAmount2() { + return baseAmount2; + } + + public void setBaseAmount2(double baseAmount2) { + this.baseAmount2 = baseAmount2; + } + + public double getUsedAmount2() { + return usedAmount2; + } + + public void setUsedAmount2(double usedAmount2) { + this.usedAmount2 = usedAmount2; + } + + public double getExtraAmount2() { + return extraAmount2; + } + + public void setExtraAmount2(double extraAmount2) { + this.extraAmount2 = extraAmount2; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getExpirationDate() { + return expirationDate; + } + + public void setExpirationDate(String expirationDate) { + this.expirationDate = expirationDate; + } + + public String getEffectiveDate() { + return effectiveDate; + } + + public void setEffectiveDate(String effectiveDate) { + this.effectiveDate = effectiveDate; + } + + public int getMinimumUnit() { + return minimumUnit; + } + + public void setMinimumUnit(int minimumUnit) { + this.minimumUnit = minimumUnit; + } + + public boolean equals(KQBalanceOfLeaveEntity entity) { + if (this.baseAmount != entity.getBaseAmount() + || this.extraAmount != entity.getExtraAmount() + || this.usedAmount != entity.getUsedAmount() + || this.baseAmount2 != entity.getBaseAmount2() + || this.extraAmount2 != entity.getExtraAmount2() + || this.usedAmount2 != entity.getUsedAmount2()) { + return false; + } else { + return true; + } + } + + public boolean equalsByBaseAmount(KQBalanceOfLeaveEntity entity) { + if (this.baseAmount != entity.getBaseAmount() + || this.baseAmount2 != entity.getBaseAmount2()) { + return false; + } else { + return true; + } + } +} diff --git a/src/com/engine/kq/entity/KQOvertimeRulesDetailEntity.java b/src/com/engine/kq/entity/KQOvertimeRulesDetailEntity.java new file mode 100644 index 0000000..0437b68 --- /dev/null +++ b/src/com/engine/kq/entity/KQOvertimeRulesDetailEntity.java @@ -0,0 +1,253 @@ +package com.engine.kq.entity; + +/** + * 加班规则明细 + */ +public class KQOvertimeRulesDetailEntity { + /** + * 加班规则明细表的ID + */ + int id; + /** + * 加班规则主表的ID + */ + int ruleId; + /** + * 日期类型:1-节假日、2-工作日、3-休息日 + */ + int dayType; + /** + * 是否允许加班:0-不允许、1-允许 + */ + int overtimeEnable = 0; + /** + * 加班计算方式: + * 1-需审批,以审批单为准 + * 2-需审批,以打卡为准,但是不能超过审批时长 + * 3-无需审批,根据打卡时间计算加班时长 + * 4-需审批,打卡和流程均统计,取两者的交集 + */ + int computingMode = -1; + /** + * 加班起算时间 + */ + int startTime = -1; + /** + * 最小加班时长 + */ + int minimumLen = -1; + + int maxmumLen = -1; + /** + * 是否允许加班转调休:0-不允许、1-允许 + */ + int paidLeaveEnable = 0; + /** + * 加班时长转调休时长的比例中的加班时长 + */ + double lenOfOvertime = -1; + /** + * 加班时长转调休时长的比例中的调休时长 + */ + double lenOfLeave = -1; + + /** + * 是否排除休息时间 + */ + int hasRestTime = 0; + /** + * 上班前 加班起算时间 + */ + int before_startTime = 0; + + /** + * 是否开启加班归属临界点 + */ + int has_cut_point = 0; + + /** + * 是否开启午休时间算加班 + */ + int isovertimecal=0; + /** + * 加班归属 临界点 + */ + String cut_point = ""; + /** + * 加班补偿方式 1-默认加班补偿规则、2-根据员工在加班流程上选择的加班补偿类型进行补偿两种 + */ + int paidLeaveEnableType = 1; + /** + * 默认加班补偿方式 里转调休的方式: 1-按加班时长比例转调休时长、2-按加班时长范围设置转调休时长、3-按加班的时间段设置转调休时长 + */ + int paidLeaveEnableDefaultType = 1; + /** + * 根据员工在加班流程上选择的加班补偿类型进行补偿 里转调休的方式: 1-按加班时长比例转调休时长、2-按加班时长范围设置转调休时长、3-按加班的时间段设置转调休时长 + */ + int paidLeaveEnableFlowType = 1; + /** + * 排除休息时间: 1-设置休息时间、2-根据加班时长扣除 + */ + int restTimeType = 1; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getRuleId() { + return ruleId; + } + + public void setRuleId(int ruleId) { + this.ruleId = ruleId; + } + + public int getDayType() { + return dayType; + } + + public void setDayType(int dayType) { + this.dayType = dayType; + } + + public int getOvertimeEnable() { + return overtimeEnable; + } + + public void setOvertimeEnable(int overtimeEnable) { + this.overtimeEnable = overtimeEnable; + } + + public int getComputingMode() { + return computingMode; + } + + public void setComputingMode(int computingMode) { + this.computingMode = computingMode; + } + + public int getStartTime() { + return startTime; + } + + public void setStartTime(int startTime) { + this.startTime = startTime; + } + + public int getMinimumLen() { + return minimumLen; + } + + public void setMinimumLen(int minimumLen) { + this.minimumLen = minimumLen; + } + + + public int getMaxmumLen() { + return maxmumLen; + } + + public void setMaxmumLen(int maxmumLen) { + this.maxmumLen = maxmumLen; + } + + public int getPaidLeaveEnable() { + return paidLeaveEnable; + } + + public void setPaidLeaveEnable(int paidLeaveEnable) { + this.paidLeaveEnable = paidLeaveEnable; + } + + public double getLenOfOvertime() { + return lenOfOvertime; + } + + public void setLenOfOvertime(double lenOfOvertime) { + this.lenOfOvertime = lenOfOvertime; + } + + public double getLenOfLeave() { + return lenOfLeave; + } + + public void setLenOfLeave(double lenOfLeave) { + this.lenOfLeave = lenOfLeave; + } + + public int getHasRestTime() { + return hasRestTime; + } + + public void setHasRestTime(int hasRestTime) { + this.hasRestTime = hasRestTime; + } + + public int getBefore_startTime() { + return before_startTime; + } + + public void setBefore_startTime(int before_startTime) { + this.before_startTime = before_startTime; + } + + public String getCut_point() { + return cut_point; + } + + public void setCut_point(String cut_point) { + this.cut_point = cut_point; + } + + public int getHas_cut_point() { + return has_cut_point; + } + + public void setHas_cut_point(int has_cut_point) { + this.has_cut_point = has_cut_point; + } + + public int getIsOvertimeCal() { + return isovertimecal; + } + + public void setIsOvertimeCal(int isovertimecal) { + this.isovertimecal = isovertimecal; + } + + public int getPaidLeaveEnableType() { + return paidLeaveEnableType; + } + + public void setPaidLeaveEnableType(int paidLeaveEnableType) { + this.paidLeaveEnableType = paidLeaveEnableType; + } + + public int getPaidLeaveEnableDefaultType() { + return paidLeaveEnableDefaultType; + } + + public void setPaidLeaveEnableDefaultType(int paidLeaveEnableDefaultType) { + this.paidLeaveEnableDefaultType = paidLeaveEnableDefaultType; + } + + public int getPaidLeaveEnableFlowType() { + return paidLeaveEnableFlowType; + } + + public void setPaidLeaveEnableFlowType(int paidLeaveEnableFlowType) { + this.paidLeaveEnableFlowType = paidLeaveEnableFlowType; + } + + public int getRestTimeType() { + return restTimeType; + } + + public void setRestTimeType(int restTimeType) { + this.restTimeType = restTimeType; + } +}