You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
10 KiB
Java
192 lines
10 KiB
Java
package weaver.interfaces.sskj.job;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alipay.api.domain.RecordDetail;
|
|
import com.engine.kq.biz.KQFormatBiz;
|
|
import com.engine.kq.biz.KQLeaveRulesBiz;
|
|
import com.engine.kq.biz.KQLeaveRulesComInfo;
|
|
import com.engine.kq.timer.KQQueue;
|
|
import com.engine.kq.timer.KQTaskBean;
|
|
import com.engine.kq.wfset.util.SplitActionUtil;
|
|
import com.engine.sskj.util.SskjUtil;
|
|
import com.github.pagehelper.dialect.helper.InformixDialect;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Maps;
|
|
import com.jayway.jsonpath.Configuration;
|
|
import com.jayway.jsonpath.JsonPath;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import weaver.conn.BatchRecordSet;
|
|
import weaver.conn.RecordSet;
|
|
import weaver.general.BaseBean;
|
|
import weaver.general.Util;
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
|
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalTime;
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
import static weaver.interfaces.sskj.util.HttpsUtil.doPostJsonRequest;
|
|
|
|
|
|
/**
|
|
* Created with IntelliJ IDEA.
|
|
* 处理加班时长扣减培训时长
|
|
* @Auther: chenwnj
|
|
* @Date: 2023/11/27
|
|
* @Description:
|
|
*/
|
|
public class DeductTrainTimesJob extends BaseCronJob {
|
|
|
|
@Override
|
|
public void execute() {
|
|
BaseBean bb = new BaseBean();
|
|
bb.writeLog("-----DeductTrainTimesJob start-----");
|
|
try {
|
|
RecordSet rs = new RecordSet();
|
|
RecordSet rs2 = new RecordSet();
|
|
|
|
//获取事假类型
|
|
String calLeaveTypeId = bb.getPropValue("project_sskj", "calLeaveId");
|
|
//获取事假单位规则
|
|
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
|
|
String minimumUnit = kqLeaveRulesComInfo.getMinimumUnit(calLeaveTypeId);
|
|
//获取当前年月日
|
|
String nowDay = DateUtil.format(new Date(),"yyyy-MM-dd");
|
|
String firstDayOfMonth = DateUtil.format(DateUtil.beginOfMonth(new Date()),"yyyy-MM-dd");
|
|
//获取培训数据
|
|
Map<String, Object> trainInfo = new HashMap<>();
|
|
List< Map<String, Object>> trainInfos = new ArrayList<>();
|
|
|
|
String acqTrainInfoSql = "select a.pxsj, a.kssj1, a.jssj1, a.ksh, b.xm, b.id, c.departmentid, c.subcompanyid1, c.jobtitle " +
|
|
" from uf_pxjl a " +
|
|
" left join uf_pxjl_dt1 b " +
|
|
" on b.mainid = a.id " +
|
|
" left join hrmresource c " +
|
|
" on c.id = b.xm " +
|
|
" where (b.isdeduct is null or b.isdeduct = 0) and b.xm is not null " +
|
|
" and a.pxsj is not null and a.kssj1 is not null and a.jssj1 is not null " +
|
|
" and a.pxsj >='" + firstDayOfMonth + "' and a.pxsj <='" + nowDay + "' ";
|
|
bb.writeLog("acqTrainInfoSql: " + acqTrainInfoSql);
|
|
|
|
rs.executeQuery(acqTrainInfoSql);
|
|
while ( rs.next()) {
|
|
String pxsj = Util.null2String(rs.getString("pxsj"));
|
|
String kssj = Util.null2String(rs.getString("kssj1"));
|
|
String jssj = Util.null2String(rs.getString("jssj1"));
|
|
String xm = Util.null2String(rs.getString("xm"));
|
|
String detailId = Util.null2String(rs.getString("id"));
|
|
String ksh = Util.null2String(rs.getString("ksh"));
|
|
String departmentid = Util.null2String(rs.getString("departmentid"));
|
|
String subcompanyid = Util.null2String(rs.getString("subcompanyid1"));
|
|
String jobtitle = Util.null2String(rs.getString("jobtitle"));
|
|
trainInfo.put("detailId",detailId);
|
|
trainInfo.put("pxsj",pxsj);
|
|
trainInfo.put("kssj",kssj);
|
|
trainInfo.put("jssj",jssj);
|
|
trainInfo.put("xm",xm);
|
|
trainInfo.put("ksh",ksh);
|
|
trainInfo.put("departmentid",departmentid);
|
|
trainInfo.put("subcompanyid",subcompanyid);
|
|
trainInfo.put("jobtitle",jobtitle);
|
|
trainInfos.add(trainInfo);
|
|
}
|
|
|
|
if ( trainInfos.size() > 0) {
|
|
|
|
String modTrainStatusSql = "update uf_pxjl_dt1 set isdeduct = ? where id = ?";
|
|
|
|
for ( Map<String, Object> train: trainInfos) {
|
|
String detailId = Util.null2String(train.get("detailId"));
|
|
String pxsj = Util.null2String(train.get("pxsj"));
|
|
String kssj = Util.null2String(train.get("kssj"));
|
|
String jssj = Util.null2String(train.get("jssj"));
|
|
String xm = Util.null2String(train.get("xm"));
|
|
String departmentid = Util.null2String(train.get("departmentid"));
|
|
String subcompanyid = Util.null2String(train.get("subcompanyid"));
|
|
String jobtitle = Util.null2String(train.get("jobtitle"));
|
|
double ksh = Util.getDoubleValue(Util.null2String(train.get("ksh")));
|
|
//查找加班记录
|
|
SskjUtil sskjUtil = new SskjUtil();
|
|
String tableName = sskjUtil.getTableName(xm, pxsj);
|
|
if (StringUtils.isNotBlank(tableName)) {
|
|
String acqOverTimeSql = "select count(*) as number from " + tableName + " where jbry = ? and belongdate = ? and kssj <='" + kssj + "' " +
|
|
" and jssj >='" + jssj + "' ";
|
|
String[] split = tableName.split("_dt");
|
|
String addTraNa = "";
|
|
String addLeaNa = "";
|
|
String addOverNa = "";
|
|
if (split.length > 0) {
|
|
addTraNa = split[0] + "_dt5";
|
|
addLeaNa = split[0] + "_dt6";
|
|
addOverNa = split[0];
|
|
}
|
|
String addTrainSql = "insert into " + addTraNa + " (pxry, pxrq, kssj, jssj, pxsc) values (?,?,?,?,?)";
|
|
String addLeaSql = "insert into " + addLeaNa + " (qjry, qjlx, qjrq, kssj, jssj, sfdk, qjbid, qjsc) values (?,?,?,?,?,?,?,?)";
|
|
String acqOverSql = "select jbzsy from " + addOverNa + " where xm = ? and ny = ? ";
|
|
String addCaslLeaSql = "insert into kq_flow_split_leave (resourceid, fromdate, fromtime, todate, totime, newleavetype, " +
|
|
" duration, durationrule, fromdatedb, fromtimedb, todatedb, totimedb, durationdb, belongdate, subcompanyid, " +
|
|
" departmentid, jobtitle, changetype, casleaveuuid ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
String acqCasLeaveSql = "select id from kq_flow_split_leave where casleaveuuid = ?";
|
|
String modTrainSql = "update " + addOverNa + " set pxzsc = (select sum(pxsc) from " + addTraNa + " as dt_table where " +
|
|
" dt_table.mainid = " + addOverNa + ".id ) where xm = ? and ny = ? ";
|
|
String modOverSql = "update " + addOverNa + " set jbzsy = (psjbsy + zmjbsy + jrjbsy - pxzsc) where xm = ? and ny = ? ";
|
|
|
|
rs.executeQuery(acqOverTimeSql, xm, pxsj);
|
|
while (rs.next()) {
|
|
int number = Util.getIntValue(Util.null2String(rs.getString("number")));
|
|
if (number > 0) {
|
|
//插入一条培训记录
|
|
boolean b = rs2.executeUpdate(addTrainSql, xm, pxsj, kssj, jssj, ksh);
|
|
//重新计算主表培训总时长
|
|
if (b) {
|
|
boolean b1 = rs2.executeUpdate(modTrainSql, xm, pxsj.substring(0, 7));
|
|
bb.writeLog("重新计算主表培训总时长: " + b1);
|
|
if (b1) {
|
|
//重新计算主表加班总剩余时长
|
|
boolean b2 = rs2.executeUpdate(modOverSql, xm, pxsj.substring(0, 7));
|
|
bb.writeLog("重新计算主表加班总剩余时长: " + b2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//根据目前加班剩余时长来判断是否需要插入一条事假的数据
|
|
rs2.executeQuery(acqOverSql, xm, pxsj.substring(0, 7));
|
|
while (rs2.next()) {
|
|
double jbzsy = Util.getDoubleValue(Util.null2String(rs.getString("jbzsy")));
|
|
double temp = ksh - jbzsy;
|
|
if (temp > 0) {
|
|
Integer casleaveId = -1;
|
|
//生成一条事假数据
|
|
String uuid = UUID.randomUUID().toString();
|
|
boolean b = rs.executeUpdate(addCaslLeaSql, xm, pxsj, kssj, pxsj, jssj, calLeaveTypeId, ksh,
|
|
minimumUnit, pxsj, kssj, pxsj, jssj, ksh, pxsj, subcompanyid, departmentid, jobtitle, 0, uuid);
|
|
if (b) {
|
|
rs.executeQuery(acqCasLeaveSql, uuid);
|
|
while (rs.next()) {
|
|
casleaveId = Util.getIntValue(Util.null2String(rs.getString("id")));
|
|
}
|
|
}
|
|
//记录事假台账
|
|
rs.executeUpdate(addLeaSql, xm, calLeaveTypeId, pxsj, kssj, jssj, 0, casleaveId, temp);
|
|
}
|
|
}
|
|
}
|
|
//回写培训台账修改状态
|
|
rs.executeUpdate(modTrainStatusSql, 1, detailId);
|
|
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
bb.writeLog(e);
|
|
bb.writeLog("DeductTrainTimesJob Exception: "+e);
|
|
}
|
|
}
|
|
|
|
}
|