|
|
|
package com.engine.sskj.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
import com.engine.kq.biz.KQTimesArrayComInfo;
|
|
|
|
import com.engine.kq.util.KQDurationCalculatorUtil;
|
|
|
|
import com.engine.sskj.service.KqWorkflowService;
|
|
|
|
import com.engine.sskj.util.SskjUtil;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import weaver.conn.RecordSet;
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class KqWorkflowServiceImpl extends Service implements KqWorkflowService {
|
|
|
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Object> calWorkTime(Map<String, Object> params) {
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
|
|
|
String startTime = Util.null2String(params.get("starttime"));
|
|
|
|
bb.writeLog("startTime: " + startTime);
|
|
|
|
String endTime = Util.null2String(params.get("endtime"));
|
|
|
|
bb.writeLog("endTime: " + endTime);
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(startTime) || StringUtils.isBlank(endTime)) {
|
|
|
|
result.put("code",500);
|
|
|
|
result.put("msg", "开始时间或结束时间为空");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (startTime.length() == 16) {
|
|
|
|
startTime = startTime + ":00";
|
|
|
|
}
|
|
|
|
if (endTime.length() == 16) {
|
|
|
|
endTime = endTime + ":00";
|
|
|
|
}
|
|
|
|
SskjUtil sskjUtil = new SskjUtil();
|
|
|
|
long time = sskjUtil.getTime(startTime, endTime);
|
|
|
|
bb.writeLog("time: " + time);
|
|
|
|
|
|
|
|
String betweenHours = KQDurationCalculatorUtil.getDurationRound(String.valueOf(Util.getDoubleValue(time+"")/60.0));
|
|
|
|
bb.writeLog("betweenHours: " + betweenHours);
|
|
|
|
|
|
|
|
result.put("code",200);
|
|
|
|
result.put("data",betweenHours);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Object> checkConOverTime(Map<String, Object> params) {
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
|
|
|
bb.writeLog("checkConOverTime start");
|
|
|
|
|
|
|
|
try {
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
|
|
|
|
|
|
|
|
String overTimeInfo = Util.null2String(params.get("overtimeinfo"));
|
|
|
|
bb.writeLog("overTimeInfo: " + overTimeInfo);
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(overTimeInfo)) {
|
|
|
|
result.put("code", 500);
|
|
|
|
result.put("msg", "请传入加班明细数据");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//resourceId=10_fromDate=2023-11-24_fromTime=12:00_toDate=2023-11-24_toTime=13:00|resourceId=10_fromDate=2023-11-24_fromTime=12:00_toDate=2023-11-24_toTime=13:00
|
|
|
|
String[] overTimeInfos = overTimeInfo.split("\\|");
|
|
|
|
/*同条流程间校验*/
|
|
|
|
if (overTimeInfos.length > 1) {
|
|
|
|
// String minDate = "";
|
|
|
|
// String maxDate = "";
|
|
|
|
// for (String oti : overTimeInfos) {
|
|
|
|
//
|
|
|
|
// String resourceId = "";
|
|
|
|
// String fromDate = "";
|
|
|
|
// String fromTime = "";
|
|
|
|
// String toDate = "";
|
|
|
|
// String toTime = "";
|
|
|
|
//
|
|
|
|
// String[] otiArray = oti.split("_");
|
|
|
|
// for (String ot : otiArray) {
|
|
|
|
// String[] split = ot.split("=");
|
|
|
|
// if ("fromDate".equals(split[0])) {
|
|
|
|
// fromDate = split[1];
|
|
|
|
// if ( minDate.compareTo(fromDate) > 0 ) {
|
|
|
|
// minDate = fromDate;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if ("toDate".equals(split[0])) {
|
|
|
|
// toDate = split[1];
|
|
|
|
// if ( maxDate.compareTo(toDate) > 0 ) {
|
|
|
|
// maxDate = toDate;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// List<String> allDays = new ArrayList<>();
|
|
|
|
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
//
|
|
|
|
// LocalDate start = LocalDate.parse(minDate, formatter);
|
|
|
|
// LocalDate end = LocalDate.parse(maxDate, formatter);
|
|
|
|
//
|
|
|
|
// while (!start.isAfter(end)) {
|
|
|
|
// allDays.add(start.format(formatter));
|
|
|
|
// start = start.plusDays(1);
|
|
|
|
// }
|
|
|
|
|
|
|
|
Map<String, int[]> resToOvInMap = new HashMap<>();
|
|
|
|
for (String oti : overTimeInfos) {
|
|
|
|
|
|
|
|
String resourceId = "";
|
|
|
|
String fromDate = "";
|
|
|
|
String fromTime = "";
|
|
|
|
String toDate = "";
|
|
|
|
String toTime = "";
|
|
|
|
|
|
|
|
String[] otiArray = oti.split("_");
|
|
|
|
for (String ot : otiArray) {
|
|
|
|
String[] split = ot.split("=");
|
|
|
|
if ("resourceId".equals(split[0])) {
|
|
|
|
resourceId = split[1];
|
|
|
|
}
|
|
|
|
if ("fromDate".equals(split[0])) {
|
|
|
|
fromDate = split[1];
|
|
|
|
}
|
|
|
|
if ("fromTime".equals(split[0])) {
|
|
|
|
fromTime = split[1];
|
|
|
|
}
|
|
|
|
if ("toDate".equals(split[0])) {
|
|
|
|
toDate = split[1];
|
|
|
|
}
|
|
|
|
if ("toTime".equals(split[0])) {
|
|
|
|
toTime = split[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
bb.writeLog("ot: " + ot);
|
|
|
|
}
|
|
|
|
if (resToOvInMap.containsKey(resourceId)) {
|
|
|
|
bb.writeLog("containsKey" );
|
|
|
|
|
|
|
|
int[] dayMins = resToOvInMap.get(resourceId);
|
|
|
|
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins) );
|
|
|
|
|
|
|
|
int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime);
|
|
|
|
bb.writeLog("fromTimeIdx: " + fromTimeIdx );
|
|
|
|
|
|
|
|
int toTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(toTime);
|
|
|
|
bb.writeLog("toTimeIdx: " + toTimeIdx );
|
|
|
|
|
|
|
|
if (fromDate.compareTo(toDate) < 0 ) {
|
|
|
|
toTimeIdx = toTimeIdx + 1440;
|
|
|
|
}
|
|
|
|
|
|
|
|
//先判断是否已经存在了
|
|
|
|
boolean isExist = false;
|
|
|
|
for (int i = fromTimeIdx; i <= toTimeIdx; i++) {
|
|
|
|
if (dayMins[i] == 1) {
|
|
|
|
isExist = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bb.writeLog("isExist: " + isExist );
|
|
|
|
|
|
|
|
if (!isExist) {
|
|
|
|
|
|
|
|
bb.writeLog("!isExist to do " );
|
|
|
|
bb.writeLog("fromTimeIdx: " + fromTimeIdx );
|
|
|
|
bb.writeLog("toTimeIdx: " + toTimeIdx );
|
|
|
|
bb.writeLog("dayMins: " + dayMins.length );
|
|
|
|
|
|
|
|
Arrays.fill(dayMins, fromTimeIdx, toTimeIdx, 1);//加班时段标识 1
|
|
|
|
} else {
|
|
|
|
bb.writeLog("!isExist else " );
|
|
|
|
String lastname = "";
|
|
|
|
String acqResLastNameSql = "select lastname from hrmresource where id = ? ";
|
|
|
|
|
|
|
|
rs.executeQuery(acqResLastNameSql, resourceId);
|
|
|
|
while (rs.next()) {
|
|
|
|
lastname = Util.null2String(rs.getString("lastname"));
|
|
|
|
}
|
|
|
|
bb.writeLog("lastname: " + lastname );
|
|
|
|
|
|
|
|
result.put("code", 500);
|
|
|
|
result.put("msg", "加班人员:" + lastname + " 的" + fromDate + " " + fromTime + "--" + toDate + " " + toTime + "在明细表中存在重复部分,请调整!");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
resToOvInMap.put(resourceId, dayMins);
|
|
|
|
} else {
|
|
|
|
bb.writeLog("containsKey else" );
|
|
|
|
|
|
|
|
// int[] dayMins =new int[2880];
|
|
|
|
// if (allDays != null && allDays.size() > 0) {
|
|
|
|
// dayMins = new int[1440 * (allDays.size())];
|
|
|
|
// }
|
|
|
|
int[] dayMins = new int[2880];//一天所有分钟数
|
|
|
|
|
|
|
|
bb.writeLog("fromTime: " + fromTime );
|
|
|
|
int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime);
|
|
|
|
bb.writeLog("fromTimeIdx: " + fromTimeIdx );
|
|
|
|
|
|
|
|
bb.writeLog("toTime: " + toTime );
|
|
|
|
int toTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(toTime);
|
|
|
|
bb.writeLog("toTimeIdx: " + toTimeIdx );
|
|
|
|
|
|
|
|
if (fromDate.compareTo(toDate) < 0 ) {
|
|
|
|
toTimeIdx = toTimeIdx + 1440;
|
|
|
|
}
|
|
|
|
bb.writeLog("toTimeIdx: " + toTimeIdx );
|
|
|
|
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins) );
|
|
|
|
Arrays.fill(dayMins, fromTimeIdx, toTimeIdx, 1);//加班时段标识 1
|
|
|
|
resToOvInMap.put(resourceId + "_" + fromDate, dayMins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*与历史数据校验*/
|
|
|
|
bb.writeLog("历史数据校验 " );
|
|
|
|
for (String oti : overTimeInfos) {
|
|
|
|
String[] otiArray = oti.split("_");
|
|
|
|
bb.writeLog("otiArray: " + otiArray.toString() );
|
|
|
|
|
|
|
|
String resourceId = "";
|
|
|
|
String fromDate = "";
|
|
|
|
String fromTime = "";
|
|
|
|
String toDate = "";
|
|
|
|
String toTime = "";
|
|
|
|
|
|
|
|
//取出加班数据
|
|
|
|
for (String ot : otiArray) {
|
|
|
|
String[] split = ot.split("=");
|
|
|
|
if ("resourceId".equals(split[0])) {
|
|
|
|
resourceId = split[1];
|
|
|
|
}
|
|
|
|
if ("fromDate".equals(split[0])) {
|
|
|
|
fromDate = split[1];
|
|
|
|
}
|
|
|
|
if ("fromTime".equals(split[0])) {
|
|
|
|
fromTime = split[1];
|
|
|
|
}
|
|
|
|
if ("toDate".equals(split[0])) {
|
|
|
|
toDate = split[1];
|
|
|
|
}
|
|
|
|
if ("toTime".equals(split[0])) {
|
|
|
|
toTime = split[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取已有的连班加班的数据--(此处连班加班指班次的休息时间)
|
|
|
|
//设置一个时间轴数组,长度为一天的分钟数
|
|
|
|
int[] dayMins = new int[2880];//一天所有分钟数
|
|
|
|
Arrays.fill(dayMins, 0);
|
|
|
|
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins));
|
|
|
|
String acqConOverTimeSql = "select fromDate, fromTime, toDate, toTime from uf_conOvertime where resourceId = ? and fromDate = ? and toDate = ?";
|
|
|
|
rs.executeQuery(acqConOverTimeSql, resourceId, fromDate, toDate);
|
|
|
|
while (rs.next()) {
|
|
|
|
String fTime = Util.null2String(rs.getString("fromTime"));
|
|
|
|
String fDate = Util.null2String(rs.getString("fromDate"));
|
|
|
|
String tTime = Util.null2String(rs.getString("toTime"));
|
|
|
|
String tDate = Util.null2String(rs.getString("toDate"));
|
|
|
|
//将时间转成时间轴上对应的点
|
|
|
|
int fTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fTime);
|
|
|
|
int tTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(tTime);
|
|
|
|
if (fDate.compareTo(tDate) < 0) {
|
|
|
|
tTimeIdx = tTimeIdx +1440;
|
|
|
|
}
|
|
|
|
bb.writeLog("fTimeIdx: " + fTimeIdx);
|
|
|
|
bb.writeLog("tTimeIdx: " + tTimeIdx);
|
|
|
|
Arrays.fill(dayMins, fTimeIdx, tTimeIdx, 1);//加班时段标识 1
|
|
|
|
bb.writeLog("dayMins: " + JSONObject.toJSONString(dayMins));
|
|
|
|
}
|
|
|
|
int fromTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(fromTime);
|
|
|
|
int toTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(toTime);
|
|
|
|
|
|
|
|
bb.writeLog("fromTimeIdx: " + fromTimeIdx);
|
|
|
|
bb.writeLog("toTimeIdx: " + toTimeIdx);
|
|
|
|
|
|
|
|
//确认fromTimeIdx-toTimeIdx在时间轴上是否有1
|
|
|
|
boolean isExist = false;
|
|
|
|
for (int i = fromTimeIdx; i <= toTimeIdx; i++) {
|
|
|
|
if (dayMins[i] == 1) {
|
|
|
|
isExist = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isExist) {
|
|
|
|
String lastname = "";
|
|
|
|
String acqResLastNameSql = "select lastname from hrmresource where id = ? ";
|
|
|
|
rs.executeQuery(acqResLastNameSql, resourceId);
|
|
|
|
while (rs.next()) {
|
|
|
|
lastname = Util.null2String(rs.getString("lastname"));
|
|
|
|
}
|
|
|
|
result.put("code", 500);
|
|
|
|
result.put("msg", "加班人员:" + lastname + " 的" + fromDate + " " + fromTime + "--" + toDate + " " + toTime + "已经申请过连班加班,不可重复申请!");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
bb.writeLog("checkConOverTime exception: " + e);
|
|
|
|
result.put("code",500);
|
|
|
|
result.put("msg","加班数据校验异常");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.put("code",200);
|
|
|
|
result.put("msg","加班数据没有重复");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Object> importOverTime(Map<String, Object> params) {
|
|
|
|
|
|
|
|
bb.writeLog("importOverTime start");
|
|
|
|
|
|
|
|
String coiledWf = Util.null2String(bb.getPropValue("project_sskj", "coiledOverTimeWorkflow"));
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(coiledWf)) {
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
//流程明细表中获取没有加班时长的数据
|
|
|
|
List< Map< String, Object>> overtimeInfos = new ArrayList<>();
|
|
|
|
String acqSql = "select id, ksrq, kssj, jsrq, jssj from " + coiledWf + " where jbsch is null ";
|
|
|
|
rs.executeQuery(acqSql);
|
|
|
|
while (rs.next()) {
|
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
|
String ksrq = Util.null2String(rs.getString("ksrq"));
|
|
|
|
String kssj = Util.null2String(rs.getString("kssj"));
|
|
|
|
String jsrq = Util.null2String(rs.getString("jsrq"));
|
|
|
|
String jssj = Util.null2String(rs.getString("jssj"));
|
|
|
|
Map< String, Object> overtimeInfo = new HashMap<>();
|
|
|
|
overtimeInfo.put("id", id);
|
|
|
|
overtimeInfo.put("starttime", ksrq + " " + kssj);
|
|
|
|
overtimeInfo.put("endtime", jsrq + " " + jssj);
|
|
|
|
overtimeInfos.add(overtimeInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
String syncSql = "update " + coiledWf + " set jbsch = ? where id = ?";
|
|
|
|
for (Map< String, Object> overtimeInfo : overtimeInfos) {
|
|
|
|
String id = Util.null2String(overtimeInfo.get("id"));
|
|
|
|
Map<String, Object> stringObjectMap = this.calWorkTime(overtimeInfo);
|
|
|
|
if (Util.null2String(stringObjectMap.get("code")).equals("200")) {
|
|
|
|
rs.executeUpdate(syncSql, Util.null2String(stringObjectMap.get("data")), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Object> getEntryType(Map<String, Object> params) {
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
bb.writeLog("getEntryType start ");
|
|
|
|
|
|
|
|
String resourceId = Util.null2String(params.get("resourceid"));
|
|
|
|
bb.writeLog("resourceId: " + resourceId);
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(resourceId) ) {
|
|
|
|
result.put("code",500);
|
|
|
|
result.put("msg", "请先选择请假人");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
String entryTypeField = Util.null2String(bb.getPropValue("project_sskj", "entryTypeField"));
|
|
|
|
bb.writeLog("entryTypeField: " + entryTypeField);
|
|
|
|
String entryTypeValue = Util.null2String(bb.getPropValue("project_sskj", "entryTypeValue"));
|
|
|
|
bb.writeLog("entryTypeValue: " + entryTypeValue);
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(entryTypeField)) {
|
|
|
|
result.put("code",500);
|
|
|
|
result.put("msg", "请先配置劳务工类型字段");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(entryTypeValue)) {
|
|
|
|
result.put("code",500);
|
|
|
|
result.put("msg", "请先配置劳务工类型值");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean entryTypeFieldValue = false;
|
|
|
|
String acqEntryTypeSql = "select " + entryTypeField + " from cus_fielddata where scopeid = -1 and id = ? ";
|
|
|
|
bb.writeLog("acqEntryTypeSql: " + acqEntryTypeSql);
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
rs.executeQuery(acqEntryTypeSql, resourceId);
|
|
|
|
if (rs.next()) {
|
|
|
|
String temp = Util.null2String(rs.getString(1));
|
|
|
|
bb.writeLog("temp: " + temp);
|
|
|
|
|
|
|
|
if(temp.equals(entryTypeValue)) {
|
|
|
|
entryTypeFieldValue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.put("code",200);
|
|
|
|
result.put("data",entryTypeFieldValue);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|