|
|
|
@ -0,0 +1,293 @@
|
|
|
|
|
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.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();
|
|
|
|
|
|
|
|
|
|
//获取当前年月日
|
|
|
|
|
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, b.xm, b.id " +
|
|
|
|
|
" from uf_pxjl a " +
|
|
|
|
|
" left join uf_pxjl_dt1 b " +
|
|
|
|
|
" on b.mainid = a.id " +
|
|
|
|
|
" 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"));
|
|
|
|
|
trainInfo.put("detailId",detailId);
|
|
|
|
|
trainInfo.put("pxsj",pxsj);
|
|
|
|
|
trainInfo.put("kssj",kssj);
|
|
|
|
|
trainInfo.put("jssj",jssj);
|
|
|
|
|
trainInfo.put("xm",xm);
|
|
|
|
|
trainInfos.add(trainInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( trainInfos.size() > 0) {
|
|
|
|
|
List deduIdList = new ArrayList<>();//记录满足减去培训时长的加班数据
|
|
|
|
|
Map< String, Object > deduTiaoxiuMap = new HashMap<>();//记录调休扣减的数据
|
|
|
|
|
Map< String, Integer > overtimeTiaoxiuMap = new HashMap<>();//记录加班和调休id
|
|
|
|
|
List< List > deduOvertimeList = new ArrayList<>();//批量修改加班时长的数据
|
|
|
|
|
|
|
|
|
|
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 acqOverTimeSql = "select id, duration_min, tiaoxiuid from kq_flow_overtime where resourceid = ? and belongdate = ? " +
|
|
|
|
|
"and fromtimedb <='" + kssj + "' and totimedb >='" + jssj + "' ";
|
|
|
|
|
rs.executeQuery(acqOverTimeSql, xm, pxsj);
|
|
|
|
|
while ( rs.next()) {
|
|
|
|
|
Integer id = Util.getIntValue(Util.null2String(rs.getString("id")));
|
|
|
|
|
Integer durationMin = Util.getIntValue(Util.null2String(rs.getString("duration_min")));
|
|
|
|
|
String tiaoxiuid = Util.null2String(rs.getString("tiaoxiuid"));
|
|
|
|
|
//加班时长减去培训时长
|
|
|
|
|
long minutesDifference = 0;
|
|
|
|
|
if ( durationMin> 0 ) {
|
|
|
|
|
List deduId = new ArrayList();
|
|
|
|
|
deduId.add(detailId);
|
|
|
|
|
deduIdList.add(deduId);
|
|
|
|
|
LocalTime timeStart = LocalTime.parse(pxsj +" " + kssj);
|
|
|
|
|
LocalTime timeEnd = LocalTime.parse(pxsj +" " + jssj);
|
|
|
|
|
|
|
|
|
|
minutesDifference = ChronoUnit.MINUTES.between(timeStart, timeEnd);
|
|
|
|
|
|
|
|
|
|
durationMin = durationMin - ((int) minutesDifference);
|
|
|
|
|
if ( durationMin < 0) {
|
|
|
|
|
durationMin = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List deduOvertime = new ArrayList<>();
|
|
|
|
|
deduOvertime.add(durationMin);
|
|
|
|
|
deduOvertime.add(id);
|
|
|
|
|
deduOvertimeList.add(deduOvertime);
|
|
|
|
|
|
|
|
|
|
//记录调休id
|
|
|
|
|
if (StringUtils.isNotBlank(tiaoxiuid)) {
|
|
|
|
|
deduTiaoxiuMap.put(tiaoxiuid,minutesDifference);
|
|
|
|
|
//记录加班和调休id
|
|
|
|
|
overtimeTiaoxiuMap.put(tiaoxiuid,id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//先扣除掉加班的时长
|
|
|
|
|
String subOverTimeSql = "update kq_flow_overtime set duration_min = ? where id = ?";
|
|
|
|
|
boolean subOverTimeSqlFlag = rs.executeBatchSql(subOverTimeSql, deduOvertimeList);
|
|
|
|
|
bb.writeLog("subOverTimeSqlFlag: " + subOverTimeSqlFlag);
|
|
|
|
|
|
|
|
|
|
//再回写培训台账
|
|
|
|
|
String syncTrainSql = "update uf_pxjl set isdeduct = 1 where id = ? ";
|
|
|
|
|
boolean syncTrainSqlFlag = rs.executeBatchSql(syncTrainSql, deduIdList);
|
|
|
|
|
bb.writeLog("syncTrainSqlFlag: " + syncTrainSqlFlag);
|
|
|
|
|
|
|
|
|
|
//处理调休时长
|
|
|
|
|
String tiaoxiuLeaveId = Util.null2String(bb.getPropValue("project_sskj","tiaoxiuleaveid"));
|
|
|
|
|
String casualLeaveId = Util.null2String(bb.getPropValue("project_sskj","casualleaveid"));
|
|
|
|
|
if (StringUtils.isNotBlank(tiaoxiuLeaveId) && StringUtils.isNotBlank(casualLeaveId) ) {
|
|
|
|
|
|
|
|
|
|
String overtimeSubTrainModeId = bb.getPropValue("project_sskj", "overtimeSubTrainModeId");
|
|
|
|
|
Integer modedatacreater = 1;
|
|
|
|
|
Integer modedatacreatertype = 0;
|
|
|
|
|
String modedatacreatedate = DateUtil.format(new Date(), "yyyy-MM-dd");
|
|
|
|
|
String modedatacreatetime = DateUtil.format(new Date(), "HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
//获取在职员工的信息
|
|
|
|
|
Map<String, List<String>> resInfos = new HashMap<>();
|
|
|
|
|
String acqResSql = "select id, subcompanyid1, departmentid, jobtitle from hrmresource where status in (0,1,2,3)";
|
|
|
|
|
rs.executeQuery(acqResSql);
|
|
|
|
|
while ( rs.next()) {
|
|
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
|
|
String subcompanyid = Util.null2String(rs.getString("subcompanyid1"));
|
|
|
|
|
String departmentid = Util.null2String(rs.getString("departmentid"));
|
|
|
|
|
String jobtitle = Util.null2String(rs.getString("jobtitle"));
|
|
|
|
|
List<String> infos = new ArrayList<>();
|
|
|
|
|
infos.add(subcompanyid);
|
|
|
|
|
infos.add(departmentid);
|
|
|
|
|
infos.add(jobtitle);
|
|
|
|
|
resInfos.put(id, infos);
|
|
|
|
|
}
|
|
|
|
|
//获取事假最小请假单位
|
|
|
|
|
String minimumUnit = new KQLeaveRulesComInfo().getMinimumUnit(casualLeaveId);
|
|
|
|
|
|
|
|
|
|
//调休时长扣减
|
|
|
|
|
List<List> tiaoxiuSubList = new ArrayList<>();
|
|
|
|
|
//转事假
|
|
|
|
|
List<List> casualLeaveList = new ArrayList<>();
|
|
|
|
|
//变动记录
|
|
|
|
|
List<List> changeLogList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
String leaveDetailIds = deduTiaoxiuMap.keySet().stream()
|
|
|
|
|
.map(Object::toString)
|
|
|
|
|
.collect(Collectors.joining(","));
|
|
|
|
|
|
|
|
|
|
String acqTiaoxiuSql = "select id, tiaoxiuamount, usedAmount, resourceId from kq_balanceofleave where id in (" + leaveDetailIds + ")";
|
|
|
|
|
rs.executeQuery(acqTiaoxiuSql);
|
|
|
|
|
while ( rs.next()) {
|
|
|
|
|
double tiaoxiuAmount = Util.getDoubleValue(Util.null2String(rs.getString("tiaoxiuamount")));
|
|
|
|
|
double usedAmount = Util.getDoubleValue(Util.null2String(rs.getString("usedAmount")));
|
|
|
|
|
int resourceId = Util.getIntValue(Util.null2String(rs.getString("resourceId")));
|
|
|
|
|
int id = Util.getIntValue(Util.null2String(rs.getString("id")));//调休表id
|
|
|
|
|
double duration = Util.getDoubleValue(Util.null2String(deduTiaoxiuMap.get(id)));
|
|
|
|
|
if ( (tiaoxiuAmount - usedAmount - duration) >=0 ) {//调休
|
|
|
|
|
List tiaoxiuSub = new ArrayList();
|
|
|
|
|
tiaoxiuSub.add(tiaoxiuAmount - duration);
|
|
|
|
|
tiaoxiuSub.add(id);
|
|
|
|
|
tiaoxiuSubList.add(tiaoxiuSub);
|
|
|
|
|
List changeLog = new ArrayList();
|
|
|
|
|
changeLog.add(resourceId);
|
|
|
|
|
Integer overtimeId = overtimeTiaoxiuMap.get(String.valueOf(id));
|
|
|
|
|
changeLog.add(overtimeId);
|
|
|
|
|
changeLog.add(id);
|
|
|
|
|
changeLog.add(duration);
|
|
|
|
|
changeLog.add(tiaoxiuAmount);
|
|
|
|
|
changeLog.add(tiaoxiuAmount - duration);
|
|
|
|
|
changeLog.add(tiaoxiuLeaveId);
|
|
|
|
|
changeLogList.add(changeLog);
|
|
|
|
|
} else {//事假
|
|
|
|
|
List casualLeave = new ArrayList();
|
|
|
|
|
casualLeave.add(resourceId);//resourceid
|
|
|
|
|
casualLeave.add(resourceId);//fromdate
|
|
|
|
|
casualLeave.add(resourceId);//fromtime
|
|
|
|
|
casualLeave.add(resourceId);//todate
|
|
|
|
|
casualLeave.add(resourceId);//totime
|
|
|
|
|
casualLeave.add(casualLeaveId);//newleavetype
|
|
|
|
|
casualLeave.add(duration);//duration
|
|
|
|
|
casualLeave.add(minimumUnit);//durationrule
|
|
|
|
|
casualLeave.add(resourceId);//fromdatedb
|
|
|
|
|
casualLeave.add(resourceId);//fromtimedb
|
|
|
|
|
casualLeave.add(resourceId);//todatedb
|
|
|
|
|
casualLeave.add(resourceId);//totimedb
|
|
|
|
|
casualLeave.add(duration);//durationdb
|
|
|
|
|
casualLeave.add(resourceId);//belongdate
|
|
|
|
|
List<String> infos = resInfos.get(resourceId);
|
|
|
|
|
String subcompanyid = infos.get(0);
|
|
|
|
|
String departmentid = infos.get(1);
|
|
|
|
|
String jobtitle = infos.get(2);
|
|
|
|
|
casualLeave.add(subcompanyid);//subcompanyid
|
|
|
|
|
casualLeave.add(departmentid);//departmentid
|
|
|
|
|
casualLeave.add(jobtitle);//jobtitle
|
|
|
|
|
casualLeave.add(resourceId);//changetype
|
|
|
|
|
casualLeaveList.add(casualLeave);
|
|
|
|
|
List changeLog = new ArrayList();
|
|
|
|
|
changeLog.add(resourceId);
|
|
|
|
|
Integer overtimeId = overtimeTiaoxiuMap.get(String.valueOf(id));
|
|
|
|
|
changeLog.add(overtimeId);
|
|
|
|
|
changeLog.add("0");
|
|
|
|
|
changeLog.add(duration);
|
|
|
|
|
changeLog.add("0.0000");
|
|
|
|
|
changeLog.add(duration);
|
|
|
|
|
changeLog.add(casualLeaveId);
|
|
|
|
|
changeLog.add(overtimeSubTrainModeId);
|
|
|
|
|
changeLog.add(modedatacreater);
|
|
|
|
|
changeLog.add(modedatacreatertype);
|
|
|
|
|
changeLog.add(modedatacreatedate);
|
|
|
|
|
changeLog.add(modedatacreatetime);
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
changeLog.add(uuid);
|
|
|
|
|
changeLogList.add(changeLog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//调休扣减
|
|
|
|
|
String subTiaoxiuSql = "update kq_balanceofleave set tiaoxiuamount = ? where id = ?";
|
|
|
|
|
boolean subTiaoxiuSqlFlag = rs.executeBatchSql(subTiaoxiuSql, tiaoxiuSubList);
|
|
|
|
|
bb.writeLog("subTiaoxiuSqlFlag: " + subTiaoxiuSqlFlag);
|
|
|
|
|
|
|
|
|
|
//事假扣减
|
|
|
|
|
String addCasSql = "insert into kq_flow_split_leave " +
|
|
|
|
|
" (resourceid, fromdate, fromtime, todate, totime, newleavetype, duration, durationrule, fromdatedb, fromtimedb, todatedb, totimedb," +
|
|
|
|
|
" durationdb, belongdate, subcompanyid, departmentid, jobtitle, changetype )" +
|
|
|
|
|
" values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
|
boolean addCasSqlFlag = rs.executeBatchSql(addCasSql, casualLeaveList);
|
|
|
|
|
bb.writeLog("addCasSqlFlag: " + addCasSqlFlag);
|
|
|
|
|
|
|
|
|
|
//变动记录
|
|
|
|
|
String syncChangeSql = "insert into uf_overtimesubtrain " +
|
|
|
|
|
" (resourceId, overtimedataId, tiaoxiudataId, subduration, beforeduration, afterduration, leavetype, " +
|
|
|
|
|
" formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime, MODEUUID ) " +
|
|
|
|
|
" values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
|
bb.writeLog("syncChangeSql:" + syncChangeSql);
|
|
|
|
|
|
|
|
|
|
boolean syncChangeSqlFlag = rs.executeBatchSql(syncChangeSql, changeLogList);
|
|
|
|
|
bb.writeLog("addFlag:" + syncChangeSqlFlag);
|
|
|
|
|
if (syncChangeSqlFlag) {
|
|
|
|
|
for ( List changeLog: changeLogList) {
|
|
|
|
|
String uuid = Util.null2String(changeLog.get(changeLog.size() - 1));
|
|
|
|
|
String billid = "-1";
|
|
|
|
|
String acqModeIdSql = "select id from uf_NoOutEmpNum where MODEUUID = ?";
|
|
|
|
|
rs.executeQuery(acqModeIdSql, uuid);
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
billid = Util.null2String(rs.getString("id"));
|
|
|
|
|
}
|
|
|
|
|
bb.writeLog("billid:" + billid);
|
|
|
|
|
SskjUtil sskjUtil = new SskjUtil();
|
|
|
|
|
sskjUtil.modePerRecon(modedatacreater, overtimeSubTrainModeId, billid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
bb.writeLog(e);
|
|
|
|
|
bb.writeLog("DeductTrainTimesJob Exception: "+e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|