ecology-kq/src/com/engine/kq/biz/KQLeaveCarryOverJob.java

230 lines
14 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.engine.kq.entity.KQUsageHistoryEntity;
import com.engine.kq.jucailin.util.KQDateUtil;
import com.engine.kq.log.KQLog;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.schedule.BaseCronJob;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 每年1月1日结转去年的年假
*/
public class KQLeaveCarryOverJob extends BaseCronJob {
private KQLog kqLog = new KQLog();
public void execute() {
try {
ResourceComInfo resourceComInfo = new ResourceComInfo();
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);
String currentYear = Util.add0(today.get(Calendar.YEAR), 4);
today.add(Calendar.YEAR, -1);
String lastYear = Util.add0(today.get(Calendar.YEAR), 4);
kqLog.info("begin do KQLeaveCarryOverJob invoke ...");
List<Object> lsCheckInfo = new ArrayList<>();
Map<String, Object> checkInfo = null;
RecordSet rs = new RecordSet();
RecordSet recordSet = new RecordSet();
String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and carryOver=1 ";
rs.executeQuery(sql);
while (rs.next()) {
String ruledetailId = rs.getString("id");
String ruleId = rs.getString("ruleid");
String carryOverDays = Util.null2s(rs.getString("carryOverDays"), "0");
checkInfo = new HashMap<>();
checkInfo.put("leaveid", ruleId);
checkInfo.put("ruledetailId", ruledetailId);
checkInfo.put("carryOverDays", carryOverDays);
lsCheckInfo.add(checkInfo);
}
boolean f = false;
new BaseBean().writeLog(JSON.toJSONString(lsCheckInfo));
//假期规则缓存类(每个假期类型下可能存在多个假期规则)
KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo();
KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo();
for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) {
Map<String, Object> leaveInfo = (Map<String, Object>) lsCheckInfo.get(j);
String leaveid = Util.null2String(leaveInfo.get("leaveid"));
String carryOverDays = Util.null2String(leaveInfo.get("carryOverDays"));
String ruledetailId = Util.null2String(leaveInfo.get("ruledetailId"));
int minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(leaveid), -1);
KQUsageHistoryEntity usageHistoryEntity = new KQUsageHistoryEntity();
List<KQUsageHistoryEntity> usageHistoryEntityList = new ArrayList<KQUsageHistoryEntity>();
List<String> updateList = new ArrayList<String>();
sql = "select * from kq_balanceOfLeave where belongyear=? and leaverulesid=?";
rs.executeQuery(sql, lastYear, leaveid);
while (rs.next()) {
String id = rs.getString("id");
String resourceId = rs.getString("resourceid");
if (resourceId.equals("22")) {
f = true;
}
//分部ID
String subcompanyId = resourceComInfo.getSubCompanyID(resourceId);
String departmentId = resourceComInfo.getDepartmentID(resourceId);
//余额发放方式1-手动发放、2-按司龄自动发放、3-按工龄自动发放、4-每年自动发放固定天数、5-加班时长自动计入余额、6-按入职时长+工龄自动发放
int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(leaveid, subcompanyId, departmentId, resourceId));
String carryOver = detailComInfo.getCarryOver(leaveid, subcompanyId, departmentId, resourceId);
String rulesDetailId = detailComInfo.getId(leaveid, subcompanyId, departmentId, resourceId);
if (!rulesDetailId.equals(ruledetailId) || !carryOver.equals("1")) {
continue;
}
BigDecimal baseAmount = new BigDecimal(Util.null2s(rs.getString("baseAmount"), "0"));//假期余额基数
BigDecimal usedAmount = new BigDecimal(Util.null2s(rs.getString("usedAmount"), "0"));//已休的假期时长
BigDecimal extraAmount = new BigDecimal(Util.null2s(rs.getString("extraAmount"), "0"));//额外的假期时长
//员工假期余额使用记录
usageHistoryEntity = new KQUsageHistoryEntity();
usageHistoryEntity.setLeaveRulesId(leaveid);
usageHistoryEntity.setRelatedId(resourceId);
usageHistoryEntity.setWfRequestId("");
usageHistoryEntity.setOperator(resourceId);
usageHistoryEntity.setOperateDate(currentDate);
usageHistoryEntity.setOperateTime(currentTime);
usageHistoryEntity.setOperateType("9");
usageHistoryEntity.setInsertOrUpdate("update");
usageHistoryEntity.setBelongYear(lastYear);
usageHistoryEntity.setOldMinimumUnit("" + minimumUnit);
usageHistoryEntity.setNewMinimumUnit("" + minimumUnit);
if (distributionMode == 6) {
//扣减优先级1-法定年假、2-福利年假
int priority = Util.getIntValue(detailComInfo.getPriority(leaveid, subcompanyId, departmentId, resourceId), 1);
//福利年假的基数
BigDecimal baseAmount2 = new BigDecimal(Util.null2s(rs.getString("baseAmount2"), "0"));
//福利年假的额外
BigDecimal usedAmount2 = new BigDecimal(Util.null2s(rs.getString("usedAmount2"), "0"));
//福利年假的已休
BigDecimal extraAmount2 = new BigDecimal(Util.null2s(rs.getString("extraAmount2"), "0"));
//剩余=已释放+额外-已休
BigDecimal restAmount1 = baseAmount.add(extraAmount).subtract(usedAmount);
BigDecimal restAmount2 = baseAmount2.add(extraAmount2).subtract(usedAmount2);
BigDecimal restAmount = restAmount1.add(restAmount2);
if (restAmount.compareTo(new BigDecimal(carryOverDays)) > 0) {
BigDecimal _duration = restAmount.subtract(new BigDecimal(carryOverDays));
if (priority == 1) {//扣减优先级:先扣减法定年假、再扣减福利年假
BigDecimal temp = baseAmount.add(extraAmount).subtract(usedAmount).subtract(_duration);
if (temp.doubleValue() >= 0) {
String newUsedAmount = usedAmount.add(_duration).setScale(2, RoundingMode.HALF_UP).toPlainString();
String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id;
updateList.add(updateSql);
usageHistoryEntity.setOldUsedAmount(usedAmount.setScale(2, RoundingMode.HALF_UP).toPlainString());
usageHistoryEntity.setNewUsedAmount(newUsedAmount);
usageHistoryEntity.setBalanceOfLeaveId(id);
usageHistoryEntityList.add(usageHistoryEntity);
} else {
String newUsedAmount = baseAmount.add(extraAmount).setScale(2, RoundingMode.HALF_UP).toPlainString();
String newUsedAmount2 = _duration.subtract(baseAmount.add(extraAmount).subtract(usedAmount)).add(usedAmount2).setScale(2, RoundingMode.HALF_UP).toString();
String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ",usedAmount2=" + (newUsedAmount2) + ", update_time=? where id=" + id;
updateList.add(updateSql);
usageHistoryEntity.setOldUsedAmount(usedAmount.setScale(2, RoundingMode.HALF_UP).toPlainString());
usageHistoryEntity.setOldUsedAmount2(usedAmount2.setScale(2, RoundingMode.HALF_UP).toPlainString());
usageHistoryEntity.setNewUsedAmount(newUsedAmount);
usageHistoryEntity.setNewUsedAmount2(newUsedAmount2);
usageHistoryEntity.setBalanceOfLeaveId(id);
usageHistoryEntityList.add(usageHistoryEntity);
}
} else {//扣减优先级:先扣减福利年假、再扣减法定年假
BigDecimal temp = baseAmount2.add(extraAmount2).subtract(usedAmount2).subtract(_duration);
if (temp.doubleValue() >= 0) {
String newUsedAmount2 = usedAmount2.add(_duration).setScale(2, RoundingMode.HALF_UP).toPlainString();
String updateSql = "update kq_balanceOfLeave set usedAmount2=" + (newUsedAmount2) + ", update_time=? where id=" + id;
updateList.add(updateSql);
usageHistoryEntity.setOldUsedAmount2(usedAmount2.setScale(2, RoundingMode.HALF_UP).toPlainString());
usageHistoryEntity.setNewUsedAmount2(newUsedAmount2);
usageHistoryEntity.setBalanceOfLeaveId(id);
usageHistoryEntityList.add(usageHistoryEntity);
} else {
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.setOldUsedAmount(usedAmount.setScale(2, RoundingMode.HALF_UP).toPlainString());
usageHistoryEntity.setOldUsedAmount2(usedAmount2.setScale(2, RoundingMode.HALF_UP).toPlainString());
usageHistoryEntity.setNewUsedAmount(newUsedAmount);
usageHistoryEntity.setNewUsedAmount2(newUsedAmount2);
usageHistoryEntity.setBalanceOfLeaveId(id);
usageHistoryEntityList.add(usageHistoryEntity);
}
}
}
} else {
//剩余=已释放+额外-已休
BigDecimal restAmount = baseAmount.add(extraAmount).subtract(usedAmount);
if (restAmount.compareTo(new BigDecimal(carryOverDays)) > 0) {
String newUsedAmount = baseAmount.add(extraAmount).subtract(new BigDecimal(carryOverDays)).setScale(2, RoundingMode.HALF_UP).toPlainString();
String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id;
updateList.add(updateSql);
usageHistoryEntity.setOldUsedAmount(usedAmount.setScale(2, RoundingMode.HALF_UP).toPlainString());
usageHistoryEntity.setNewUsedAmount(newUsedAmount);
usageHistoryEntity.setBalanceOfLeaveId(id);
usageHistoryEntityList.add(usageHistoryEntity);
}
}
}
boolean flag = false;
java.sql.Timestamp updateDate = KQDateUtil.getUpdateTimeStamp();
for (int i = 0; i < updateList.size(); i++) {
flag = recordSet.executeUpdate(updateList.get(i), updateDate);
if (!flag) {
kqLog.writeLog("结转SQL执行失败。" + "updateListsql=" + updateList.get(i));
break;
}
}
/*记录假期使用记录*/
if (flag && usageHistoryEntityList.size() > 0) {
KQUsageHistoryBiz usageHistoryBiz = new KQUsageHistoryBiz();
flag = usageHistoryBiz.save(usageHistoryEntityList);
if (!flag) {
kqLog.writeLog("结转SQL日志执行失败。" + "updateListsql=" + JSON.toJSONString(usageHistoryEntityList));
break;
}
}
}
kqLog.info("end do KQLeaveCarryOverJob invoke ...");
} catch (Exception e) {
new BaseBean().writeLog(e.getMessage());
new BaseBean().writeLog(e);
}
}
}