考勤加班规则取并集计算 修改文件 KQOverTimeRuleCalBiz 其余编译使用

AISIN
Chengliang 7 months ago
parent f37a487f3a
commit 1766fc6077

File diff suppressed because it is too large Load Diff

@ -0,0 +1,796 @@
package com.engine.kq.biz;
import com.engine.kq.enums.FlowReportTypeEnum;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.wfset.bean.SplitBean;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
/**
*
*/
public class KQFlowDataBiz {
private String resourceid;
private String fromDate;
private String toDate;
private String fromTime;
private String toTime;
private String belongDate;
private String newLeaveType;
private String orderby_sql;
public KQFlowDataBiz(FlowDataParamBuilder build){
this.resourceid = build.resourceid;
this.fromDate = build.fromDate;
this.toDate = build.toDate;
this.fromTime = build.fromTime;
this.toTime = build.toTime;
this.belongDate = build.belongDate;
this.newLeaveType = build.newLeaveType;
this.orderby_sql = build.orderby_sql;
}
/**
*
*
* @param flowMaps
* @param isAll truefalse
* @return
*/
public List<SplitBean> getAllFlowData(Map<String,Object> flowMaps,boolean isAll){
List<SplitBean> allSplitBeans = new ArrayList<>();
Map<String,String> flowDeductCard = getFlowDeductCard();
allSplitBeans.addAll(getLeaveData(flowMaps,flowDeductCard));
allSplitBeans.addAll(getEvectionData(flowMaps,flowDeductCard));
allSplitBeans.addAll(getOutData(flowMaps,flowDeductCard));
if(isAll){
allSplitBeans.addAll(getOverTimeData(flowMaps));
}
allSplitBeans.addAll(getOtherData(flowMaps));
return allSplitBeans;
}
/**
*
*/
public Map<String,String> getFlowDeductCard() {
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
Map<String,String> flowDeductCard = new HashMap<>();
String flowDeductCardSql = "select * from kq_flow_deduct_card t where 1=1 and (isclear is null or isclear<>1) ";
String sqlWhere = sqlFlowCardParamWhere();
if(sqlWhere.length() > 0){
flowDeductCardSql += sqlWhere;
}
rs.execute(flowDeductCardSql);
while(rs.next()){
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String signtype= rs.getString("signtype");
String serialnumber= rs.getString("serialnumber");
String flowtype= rs.getString("flowtype");
String key = requestId+"_"+resourceid+"_"+flowtype;
String serial_signtype = serialnumber+"_"+signtype;
if(flowDeductCard.containsKey(key)){
String tmpSignType = Util.null2String(flowDeductCard.get(key));
flowDeductCard.put(key, tmpSignType+","+serial_signtype);
}else{
flowDeductCard.put(key, serial_signtype);
}
}
return flowDeductCard;
}
/**
*
*/
public List<SplitBean> getLeaveData(Map<String, Object> flowMaps,
Map<String, String> flowDeductCard){
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
int[] initArrays = kqTimesArrayComInfo.getInitArr();
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
String leavebackrequestid= Util.null2String(rs.getString("leavebackrequestid"));
String fromtimedb= rs.getString("fromtimedb");
String totimedb= rs.getString("totimedb");
if(Util.getDoubleValue(duration) <= 0){
continue;
}
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.LEAVE.getFlowtype();
String serial_signtype = "";
String serial = "";
String signtype = "";
if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){
serial_signtype = Util.null2String(flowDeductCard.get(card_key));
if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){
serial = serial_signtype.split("_")[0];
signtype = serial_signtype.split("_")[1];
}
}
Map<String,String> infoMap = new HashMap<>();
infoMap.put("requestId", requestId);
infoMap.put(newleavetype, duration);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){
infoMap.put("ishalf", "true");
}else{
infoMap.put("ishalf", "false");
}
infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
infoMap.put("signtype", signtype);
infoMap.put("serial", serial);
infoMap.put("fromtimedb", fromtimedb);
infoMap.put("totimedb", totimedb);
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){
initArrays = kqTimesArrayComInfo.getInitArr();
int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime);
int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime);
Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1);
leavebackrequestid = leavebackrequestid.substring(1);
String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'";
rs1.executeQuery(backSql);
while (rs1.next()){
String back_fromtime = rs1.getString("fromtime");
String back_totime = rs1.getString("totime");
String back_duration= rs.getString("duration");
if(Util.getDoubleValue(back_duration) <= 0){
continue;
}
if(back_fromtime.equalsIgnoreCase(fromtime)){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
}else{
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
}
}
List<List<String>> backLists = new ArrayList<>();
List<String> backList = new ArrayList<>();
for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){
if(initArrays[i] == 1){
backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i));
}else{
if(!backList.isEmpty()){
backLists.add(backList);
backList = new ArrayList<>();
}else{
continue;
}
}
}
if(!backList.isEmpty()){
backLists.add(backList);
}
if(backLists != null && !backLists.isEmpty()){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
for(int j = 0 ; j < backLists.size() ;j++){
List<String> backListTmp = backLists.get(j);
String back_tmp_fromtime = backListTmp.get(0);
String back_tmp_totime = backListTmp.get(backListTmp.size()-1);
infoMap = new HashMap<>();
infoMap.put("requestId", requestId);
infoMap.put(newleavetype, duration);
infoMap.put("begintime", back_tmp_fromtime);
infoMap.put("endtime", back_tmp_totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule)){
infoMap.put("ishalf", "true");
}
infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
time_list_tmp.add(infoMap);
}
}
}else{
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}
}else{
if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){
initArrays = kqTimesArrayComInfo.getInitArr();
int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime);
int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime);
Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1);
leavebackrequestid = leavebackrequestid.substring(1);
String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'";
rs1.executeQuery(backSql);
while (rs1.next()){
String back_fromtime = rs1.getString("fromtime");
String back_totime = rs1.getString("totime");
if(back_fromtime.equalsIgnoreCase(fromtime)){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
}else{
if(back_fromtime.compareTo(back_totime) < 0){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
}
}
}
List<List<String>> backLists = new ArrayList<>();
List<String> backList = new ArrayList<>();
for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){
if(initArrays[i] == 1){
backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i));
}else{
if(!backList.isEmpty()){
backLists.add(backList);
backList = new ArrayList<>();
}else{
continue;
}
}
}
if(!backList.isEmpty()){
backLists.add(backList);
}
if(backLists != null && !backLists.isEmpty()){
List<Map<String,String>> time_list = new ArrayList<>();
for(int j = 0 ; j < backLists.size() ;j++){
List<String> backListTmp = backLists.get(j);
String back_tmp_fromtime = backListTmp.get(0);
String back_tmp_totime = backListTmp.get(backListTmp.size()-1);
infoMap = new HashMap<>();
infoMap.put("requestId", requestId);
infoMap.put(newleavetype, duration);
infoMap.put("begintime", back_tmp_fromtime);
infoMap.put("endtime", back_tmp_totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule)){
infoMap.put("ishalf", "true");
}
infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
time_list.add(infoMap);
}
flowMaps.put(key, time_list);
}
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getEvectionData(Map<String, Object> flowMaps,
Map<String, String> flowDeductCard){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.EVECTION.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBeans.add(splitBean);
if(Util.getDoubleValue(duration) <= 0){
continue;
}
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.EVECTION.getFlowtype();
String serial_signtype = "";
String serial = "";
String signtype = "";
if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){
serial_signtype = Util.null2String(flowDeductCard.get(card_key));
if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){
serial = serial_signtype.split("_")[0];
signtype = serial_signtype.split("_")[1];
}
}
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration);
infoMap.put("requestId", requestId);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){
infoMap.put("ishalf", "true");
}else{
infoMap.put("ishalf", "false");
}
infoMap.put("duration", duration);
infoMap.put("flowtype", FlowReportTypeEnum.EVECTION.getFlowType());
infoMap.put("signtype", signtype);
infoMap.put("serial", serial);
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getOutData(Map<String, Object> flowMaps,
Map<String, String> flowDeductCard){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.OUT.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBeans.add(splitBean);
if(Util.getDoubleValue(duration) <= 0){
continue;
}
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.OUT.getFlowtype();
String serial_signtype = "";
String serial = "";
String signtype = "";
if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){
serial_signtype = Util.null2String(flowDeductCard.get(card_key));
if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){
serial = serial_signtype.split("_")[0];
signtype = serial_signtype.split("_")[1];
}
}
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.officialBusiness.getFlowType(), duration);
infoMap.put("requestId", requestId);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){
infoMap.put("ishalf", "true");
}else{
infoMap.put("ishalf", "false");
}
infoMap.put("duration", duration);
infoMap.put("flowtype", FlowReportTypeEnum.OUT.getFlowType());
infoMap.put("signtype", signtype);
infoMap.put("serial", serial);
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getOverTimeData(Map<String,Object> flowMaps){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.OVERTIME.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String leaveSql = "select * from ("+tablename+") t where 1=1 ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
if(orderby_sql.length() > 0){
leaveSql = leaveSql+orderby_sql;
}
new BaseBean().writeLog("加班流程获取Sql=>"+leaveSql);
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String dataid= rs.getString("dataid");
String detailid= rs.getString("detailid");
String requestId= rs.getString("requestId");
new BaseBean().writeLog("start"+requestId);
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
String changetype= rs.getString("changetype");
String d_mins= rs.getString("d_mins");
String overtime_type= rs.getString("overtime_type");
String fromdatedb= rs.getString("fromdatedb");
String fromtimedb= rs.getString("fromtimedb");
String todatedb= rs.getString("todatedb");
String totimedb= rs.getString("totimedb");
splitBean.setDataId(dataid);
splitBean.setDetailId(detailid);
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBean.setChangeType(Util.getIntValue(changetype));
splitBean.setD_Mins(Util.getDoubleValue(d_mins));
splitBean.setOvertime_type(overtime_type);
splitBean.setFromdatedb(fromdatedb);
splitBean.setFromtimedb(fromtimedb);
splitBean.setTodatedb(todatedb);
splitBean.setTotimedb(totimedb);
splitBeans.add(splitBean);
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
unitType = "2".equalsIgnoreCase(durationrule)?"1":"2";
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("duration", duration);
infoMap.put("flowtype", FlowReportTypeEnum.OVERTIME.getFlowType());
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getOtherData(Map<String,Object> flowMaps){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.OTHER.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String leaveSql = "select * from ("+tablename+") t where 1=1 ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBeans.add(splitBean);
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
* @param ruleid
* @return true
*/
public static boolean leaveTypeUsed(String ruleid){
KQFlowDataBiz kqFlowDataBiz = new FlowDataParamBuilder().newLeaveTypeParam(ruleid).build();
List<SplitBean> splitBeans = kqFlowDataBiz.getLeaveData(null, new HashMap<>());
if(!splitBeans.isEmpty()){
return true;
}else{
return false;
}
}
/**
*
* @return
*/
private String sqlParamWhere() {
String sqlWhere = "";
if(resourceid.length() > 0){
sqlWhere += " and resourceid in ( "+resourceid+" )";
}
if(fromDate.length() > 0 && toDate.length() > 0){
sqlWhere += " and ( fromdate between '"+fromDate+"' and '"+toDate+"' or todate between '"+fromDate+"' and '"+toDate+"' )";
}else{
if(fromDate.length() > 0){
sqlWhere += " and fromdate between '"+fromDate+"' and '"+fromDate+"' ";
}
if(toDate.length() > 0){
sqlWhere += " and todate between '"+toDate+"' and '"+toDate+"' ";
}
}
if(belongDate.length() > 0){
sqlWhere += " and belongdate = '"+belongDate+"' ";
}
if(fromTime.length() > 0){
sqlWhere += " and fromtime >= '"+fromTime+"' ";
}
if(toTime.length() > 0){
sqlWhere += " and totime <= '"+toTime+"' ";
}
if(newLeaveType.length() > 0){
sqlWhere += " and newleavetype in ( "+newLeaveType+" )";
}
return sqlWhere;
}
private String sqlFlowCardParamWhere() {
String sqlWhere = "";
if(resourceid.length() > 0){
sqlWhere += " and resourceid in ( "+resourceid+" )";
}
if(fromDate.length() > 0 && toDate.length() > 0){
sqlWhere += " and ( fromdate between '"+fromDate+"' and '"+toDate+"' or todate between '"+fromDate+"' and '"+toDate+"' )";
}else{
if(fromDate.length() > 0){
sqlWhere += " and fromdate between '"+fromDate+"' and '"+fromDate+"' ";
}
if(toDate.length() > 0){
sqlWhere += " and todate between '"+toDate+"' and '"+toDate+"' ";
}
}
if(belongDate.length() > 0){
sqlWhere += " and belongdate = '"+belongDate+"' ";
}
if(fromTime.length() > 0){
sqlWhere += " and fromtime >= '"+fromTime+"' ";
}
if(toTime.length() > 0){
sqlWhere += " and totime <= '"+toTime+"' ";
}
return sqlWhere;
}
/**
* Builder
*/
public static class FlowDataParamBuilder {
private String resourceid = "";
private String fromDate = "";
private String toDate = "";
private String fromTime = "";
private String toTime = "";
private String belongDate = "";
/**
*
*/
private String newLeaveType = "";
private String orderby_sql = "";
public FlowDataParamBuilder() {
this.resourceid = "";
//初始化的时候需要把其他参数先清空下
this.fromDate = "";
this.toDate = "";
this.fromTime = "";
this.toTime = "";
this.newLeaveType = "";
this.belongDate = "";
this.orderby_sql = "";
}
//成员方法返回其自身,所以可以链式调用
public FlowDataParamBuilder resourceidParam(final String resourceid) {
this.resourceid = resourceid;
return this;
}
public FlowDataParamBuilder fromDateParam(final String fromDate) {
this.fromDate = fromDate;
return this;
}
public FlowDataParamBuilder toDateParam(final String toDate) {
this.toDate = toDate;
return this;
}
public FlowDataParamBuilder fromTimeParam(final String fromTime) {
this.fromTime = fromTime;
return this;
}
public FlowDataParamBuilder toTimeParam(final String toTime) {
this.toTime = toTime;
return this;
}
public FlowDataParamBuilder newLeaveTypeParam(final String newLeaveType) {
this.newLeaveType = newLeaveType;
return this;
}
public FlowDataParamBuilder belongDateParam(final String belongDate) {
this.belongDate = belongDate;
return this;
}
public FlowDataParamBuilder orderby_sqlParam(final String orderby_sql) {
this.orderby_sql = orderby_sql;
return this;
}
//Builder的build方法返回外部类的实例
public KQFlowDataBiz build() {
return new KQFlowDataBiz(this);
}
}
}

@ -18,6 +18,7 @@ import java.sql.Timestamp;
import org.apache.commons.collections4.CollectionUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import java.io.PrintWriter;
@ -111,6 +112,7 @@ public class KQOverTimeRuleCalBiz {
int computingMode = Util.getIntValue(""+computingModeMap.get(changeType_key),-1);
boolean isOk = true;
new BaseBean().writeLog("新加班规则计算开始 ==>"+computingMode);
//把原来下面一个方法里的内容要抽出来是因为存在如下的问题如果我是跨天打卡次日3点加班归属点设置的是次日2点2-3这部分的是属于第二天的需要判断下第二天的加班方式是不是doComputingMode2如果不是就需要去走对应的doComputingMode方法
if(2 == computingMode){
isOk = doComputingMode2WithCard(kqOvertimeCardBean,mapKey,resourceid,changeTypeMap,
@ -124,6 +126,10 @@ public class KQOverTimeRuleCalBiz {
isOk = doComputingMode4WithCard(kqOvertimeCardBean,mapKey,resourceid,changeTypeMap,
dateFormatter,overtimeLogMap,splitDate,overRulesDetailMap,eventMap,kqTimesArrayComInfo,
restTimeMap,kqEventLogBiz,uuid,realSplitDate);
}else if(5 == computingMode){
isOk = doComputingMode5WithCard(kqOvertimeCardBean,mapKey,resourceid,changeTypeMap,
dateFormatter,overtimeLogMap,splitDate,overRulesDetailMap,eventMap,kqTimesArrayComInfo,
restTimeMap,kqEventLogBiz,uuid,realSplitDate);
}
if(!isOk){
continue;
@ -326,6 +332,263 @@ public class KQOverTimeRuleCalBiz {
}
/**
* todo 5
*/
private boolean doComputingMode5WithCard(KQOvertimeCardBean kqOvertimeCardBean, String mapKey, String resourceid, Map<String, Integer> changeTypeMap, DateTimeFormatter dateFormatter, Map<String, Object> overtimeLogMap,
String splitDate, Map<String, KQOvertimeRulesDetailEntity> overRulesDetailMap, Map<String, Object> eventMap, KQTimesArrayComInfo kqTimesArrayComInfo, Map<String, List<String[]>> restTimeMap, KQOvertimeLogBiz kqEventLogBiz, String uuid,
String realSplitDate) throws Exception{
BaseBean bb = new BaseBean();
Map<String,List<SplitBean>> splitBeanMaps = Maps.newHashMap();
//获取加班流程数据
getOverTimeFlowData(resourceid,realSplitDate,realSplitDate,splitBeanMaps,dateFormatter);
String change_key = realSplitDate+"_"+resourceid;
int changeType = Util.getIntValue(""+changeTypeMap.get(change_key),-1);
String changeType_key = realSplitDate+"_"+changeType;
LocalDate localbelongDate = LocalDate.parse(realSplitDate);
LocalDate preLocalDate = localbelongDate.minusDays(1);
String preSplitDate = preLocalDate.format(dateFormatter);
String preChange_key = preSplitDate+"_"+resourceid;
int preChangeType = Util.getIntValue(""+changeTypeMap.get(preChange_key),-1);
String preChangeType_key = preSplitDate+"_"+preChangeType;
LocalDate nextLocalDate = localbelongDate.plusDays(1);
String nextSplitDate = nextLocalDate.format(dateFormatter);
String nextChange_key = nextSplitDate+"_"+resourceid;
int nextChangeType = Util.getIntValue(""+changeTypeMap.get(nextChange_key),-1);
String nextChangeType_key = nextSplitDate+"_"+nextChangeType;
String changetypeName = 1==changeType ? "节假日" : (2 == changeType ? "工作日" : (3 == changeType ? "休息日" : "异常"));
String changetypeLogInfo = change_key+"|changeType|"+changeType+"|"+changetypeName;
logOvertimeMap(overtimeLogMap, changetypeLogInfo, mapKey+"|"+"加班日期属性|changetypeLogInfo");
clearOvertimeTX(resourceid, realSplitDate,overtimeLogMap,splitDate);
logOvertimeMap(overtimeLogMap, kqOvertimeCardBean, mapKey+"|"+"打卡和上下班数据|KQOvertimeCardBean");
KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key);
if(kqOvertimeRulesDetailEntity == null){
String overRuleInfo = "changeType_key:"+changeType_key+":kqOvertimeRulesDetailEntity:"+kqOvertimeRulesDetailEntity;
logOvertimeMap(overtimeLogMap, overRuleInfo, mapKey+"|"+"加班规则为null|kqOvertimeRulesDetailEntity");
return false;
}
int overtimeEnable = kqOvertimeRulesDetailEntity.getOvertimeEnable();
if(overtimeEnable != 1){
String overtimeEnableInfo = "overtimeEnable:"+overtimeEnable;
logOvertimeMap(overtimeLogMap, overtimeEnableInfo, mapKey+"|"+"未开启加班规则|overtimeEnable");
return false;
}
if(kqOvertimeCardBean != null){
int[] initArrays = kqTimesArrayComInfo.getInitArr();
bb.writeLog("初始化一天时间数组==>"+ Arrays.toString(initArrays));
List<Map<String, String>> hasOverTime4SignList = Lists.newArrayList();
getHasOverTimeData(resourceid,realSplitDate,hasOverTime4SignList);
Map<String,String> signinoffMap = buildOvertimeCard(kqOvertimeCardBean, resourceid, realSplitDate, kqTimesArrayComInfo, restTimeMap, changeType_key,initArrays,hasOverTime4SignList,
overRulesDetailMap,true,overtimeLogMap, preChangeType_key,nextChangeType_key);
logOvertimeMap(overtimeLogMap, signinoffMap, mapKey+"|"+"获取上下班打卡数据|signinoffMap");
String signinTime = Util.null2String(signinoffMap.get("signinTime"));
String signoutTime = Util.null2String(signinoffMap.get("signoutTime"));
String signinDate = Util.null2String(signinoffMap.get("signinDate"));
String signoutDate = Util.null2String(signinoffMap.get("signoutDate"));
int signinTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signinTime);
int signoutTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signoutTime);
if(signinTimeIndex < signoutTimeIndex){
//先覆盖打卡 打卡区间都是1
int over_count = kqTimesArrayComInfo.getCnt(initArrays, signinTimeIndex, signoutTimeIndex, 1);
String overCountLogInfo = "signinTimeIndex:"+signinTimeIndex+":signoutTimeIndex:"+signoutTimeIndex+":over_count:"+over_count;
bb.writeLog("打卡时长获取:"+overCountLogInfo+"=>"+Arrays.toString(initArrays));
logOvertimeMap(overtimeLogMap, overCountLogInfo, mapKey+"|"+"打卡区间,得到打卡时长|over_count");
if(over_count > 0){
int restTimeType = 1;
String kqOvertimeRulesDetailEntityLogInfo = kqOvertimeRulesDetailEntity==null ? "" :JSON.toJSONString(kqOvertimeRulesDetailEntity);
logOvertimeMap(overtimeLogMap, kqOvertimeRulesDetailEntityLogInfo, mapKey+"|具体这个人这一天对应的加班规则|KQOvertimeRulesDetailEntity");
int minimumLen = -1;
if(kqOvertimeRulesDetailEntity != null){
minimumLen = kqOvertimeRulesDetailEntity.getMinimumLen();
if(over_count < minimumLen){
String minInfo = "over_count:"+over_count+":minimumLen:"+minimumLen;
bb.writeLog("打卡时长小于最小加班时长=>"+minInfo);
logOvertimeMap(overtimeLogMap, minInfo, mapKey+"|打卡时长小于最小加班时长|over_count<minimumUnit");
return false;
}
}
bb.writeLog("进入计算 => "+splitBeanMaps.containsKey(mapKey));
if(splitBeanMaps.containsKey(mapKey)) {
List<SplitBean> splitBeans = splitBeanMaps.get(mapKey);
String flowinfo = "";
if(splitBeans != null && !splitBeans.isEmpty()){
flowinfo = JSON.toJSONString(splitBeans, SerializerFeature.DisableCheckSpecialChar,SerializerFeature.DisableCircularReferenceDetect);
}
eventMap.put(mapKey+"|"+"加班流程数据|flowinfo", flowinfo);
bb.writeLog("splitBeans size => "+splitBeans.isEmpty());
if(splitBeans == null || splitBeans.isEmpty()){
return false;
}
for (int m = 0; m < splitBeans.size(); m++) {
SplitBean splitBean = splitBeans.get(m);
String dataid = splitBean.getDataId();
String detailid = splitBean.getDetailId();
String flow_fromdate = splitBean.getFromDate();
String flow_fromtime = splitBean.getFromTime();
String flow_todate = splitBean.getToDate();
String flow_totime = splitBean.getToTime();
String fromdatedb = splitBean.getFromdatedb();
String fromtimedb = splitBean.getFromtimedb();
String todatedb = splitBean.getTodatedb();
String totimedb = splitBean.getTotimedb();
String requestid = splitBean.getRequestId();
double d_mins = splitBean.getD_Mins();
if(d_mins <= 0){
continue;
}
String flow_key = mapKey+"|"+"flow_fromdate|"+flow_fromdate+"|flow_todate|"+flow_todate
+"|flow_fromtime|"+flow_fromtime+"|flow_totime|"+flow_totime;
bb.writeLog("加班流程数据集:"+flow_key);
//如果打卡数据有了,再拿流程数据去覆盖,得到有效的打卡区间,这个区间肯定已经是去除了上下班时间和休息时间还有重复打卡的部分
List<Integer> cross_time_list = Lists.newArrayList();
// cross_time_list里存的是排除了工作时间的打卡段找到1表示找到打卡开始的点了找到-2表示找到打卡结束的点了
get_cross_time_list(cross_time_list,initArrays,signinTimeIndex,signoutTimeIndex,1,-2);
bb.writeLog("cross_time_list集合=>"+cross_time_list.toString()+"覆盖前1=>"+Arrays.toString(initArrays));
logOvertimeMap(overtimeLogMap, cross_time_list, flow_key+"|cross_time_list");
if(flow_fromdate.compareTo(realSplitDate) > 0){
flow_fromtime = kqTimesArrayComInfo.turn24to48Time(flow_fromtime);
}
if(flow_todate.compareTo(realSplitDate) > 0){
flow_totime = kqTimesArrayComInfo.turn24to48Time(flow_totime);
}
int flow_fromIndex = kqTimesArrayComInfo.getArrayindexByTimes(flow_fromtime);
int flow_toIndex = kqTimesArrayComInfo.getArrayindexByTimes(flow_totime);
bb.writeLog("流程加班开始和结束索引=>"+flow_fromIndex+"=>"+flow_toIndex);
//2.根据流程加班时间 在已有的数组上覆盖成2
Arrays.fill(initArrays, flow_fromIndex, flow_toIndex,2);
bb.writeLog("覆盖2后=>"+Arrays.toString(initArrays));
int across_mins = 0;
//3.获取一天数组中有多少2流程和多少 1打卡
int flow_count = kqTimesArrayComInfo.getCnt(initArrays, flow_fromIndex, flow_toIndex, 2);
bb.writeLog("flow_count => "+flow_count);
int dk_count = 0;
int mins = signoutTimeIndex-signinTimeIndex;
if(mins <= 0){
String crossInfo = "flow_cross_fromtime_index:"+signinTimeIndex+":flow_cross_totime_index:"+signoutTimeIndex+":mins:"+mins;
bb.writeLog("打卡时长小于最小加班时长|crossInfo"+crossInfo);
logOvertimeMap(overtimeLogMap, crossInfo, flow_key+"|打卡时长小于最小加班时长|crossInfo");
}else {
dk_count = kqTimesArrayComInfo.getCnt(initArrays, signinTimeIndex, signoutTimeIndex, 1);
}
across_mins = flow_count + dk_count;
String flow_cross_key = "加班计算区间|"+kqTimesArrayComInfo.getTimesByArrayindex(signinTimeIndex)+"-"+kqTimesArrayComInfo.getTimesByArrayindex(signoutTimeIndex);
logOvertimeMap(overtimeLogMap, mins, flow_cross_key+"|原始加班区间生成的加班时长|mins");
bb.writeLog("原始加班区间生成的加班时长|mins"+mins);
bb.writeLog("across_mins => "+across_mins);
if(kqOvertimeRulesDetailEntity != null){
//我这个方法是针对每次生成的加班数据做排除休息时长的处理
restTimeType = kqOvertimeRulesDetailEntity.getRestTimeType();
if(restTimeType == 2){
across_mins = new KQOverTimeFlowBiz().handle_restlength(across_mins,restTimeMap,changeType_key);
}
}
int card_mins = over_count;
double double_mins = getD_MinsByUnit((1.0*across_mins));
across_mins = (int)double_mins;
if(across_mins <= 0){
logOvertimeMap(overtimeLogMap, across_mins, flow_key+"|经过单位换算之后时长为0|across_mins");
continue;
}
if(across_mins < minimumLen){
String minInfo = "across_mins:"+across_mins+":minimumLen:"+minimumLen;
logOvertimeMap(overtimeLogMap, minInfo, flow_key+"|打卡时长小于最小加班时长|over_count<minimumUnit");
continue;
}
RecordSet rs = new RecordSet();
String overtime_uuid = UUID.randomUUID().toString();
String tiaoxiuId = "";
String flow_dataid = dataid+"_"+detailid;
int computingMode = 4;
int unit = KQOvertimeRulesBiz.getMinimumUnit();
String workingHours = "";
String overtime_type = splitBean.getOvertime_type();
Map<String,Object> otherParam = Maps.newHashMap();
otherParam.put("overtime_type", overtime_type);
otherParam.put("changeType", String.valueOf(changeType));
int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType();
if(2 == paidLeaveEnableType){
logOvertimeMap(overtimeLogMap, overtime_type, flow_key+"|关联调休与否来自于流程选择,加班类型下拉框值|overtime_type");
}
int paidLeaveEnable = getPaidLeaveEnable(kqOvertimeRulesDetailEntity, overtime_type);
otherParam.put("overtimeLogMap", overtimeLogMap);
logOvertimeMap(overtimeLogMap, across_mins, flow_key+"|最终生成的加班分钟数|overtime_mins");
tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid,realSplitDate,across_mins+"","0",workingHours,requestid,"1",realSplitDate,otherParam);
if(Util.getIntValue(tiaoxiuId) > 0){
kqLog.info("doComputingMode4 生成调休成功调休id:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate);
}else{
kqLog.info("doComputingMode4 生成调休失败调休id:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate);
}
logOvertimeMap(overtimeLogMap, tiaoxiuId, flow_key+"|最终生成的调休id|tiaoxiuId");
String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,"
+ "workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid,fromdatedb,fromtimedb,todatedb,totimedb,flow_mins,card_mins,ori_belongdate,flow_dataid,create_time,update_time,creator)"+
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
if (rs.getDBType().equals("postgresql")) {
flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,"
+ "workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid,fromdatedb,fromtimedb,todatedb,totimedb,flow_mins,card_mins,ori_belongdate,flow_dataid,create_time,update_time,creator)"+
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?) ";
}
signinTime = kqTimesArrayComInfo.turn48to24Time(signinTime);
signoutTime = kqTimesArrayComInfo.turn48to24Time(signoutTime);
if(signinTime.length() == 5){
signinTime = signinTime+":00";
}
if(signoutTime.length() == 5){
signoutTime = signoutTime+":00";
}
Long cur = System.currentTimeMillis();
Timestamp date = new Timestamp(cur);
boolean isUp = rs.executeUpdate(flow_overtime_sql, requestid,resourceid,signinDate,signinTime,signoutDate,signoutTime,across_mins,"",realSplitDate,
"",unit,changeType,paidLeaveEnable,computingMode,tiaoxiuId,overtime_uuid,fromdatedb,fromtimedb,todatedb,totimedb,d_mins,card_mins,splitDate,flow_dataid,date,date,Util.getIntValue(resourceid));
String overtimeid = get_overtime_uuid(overtime_uuid);
kqEventLogBiz.updateOvertimeId(uuid, overtimeid);
}
}else{
//有打卡没有流程
logOvertimeMap(overtimeLogMap, mapKey, mapKey+"|"+"加班流程为空");
}
}else{
logOvertimeMap(overtimeLogMap, overCountLogInfo, mapKey+"|"+"打卡数据时长为0");
}
}else{
String overCountLogInfo = "signinTimeIndex:"+signinTimeIndex+":signoutTimeIndex:"+signoutTimeIndex;
logOvertimeMap(overtimeLogMap, overCountLogInfo, mapKey+"|"+"打卡数据异常");
}
}else{
logOvertimeMap(overtimeLogMap, "打卡数据KQOvertimeCardBean为null", mapKey+"|"+"打卡和上下班数据|KQOvertimeCardBean");
}
return true;
}
/**
*
*/

@ -0,0 +1,73 @@
package com.engine.kq.wfset.action;
import com.engine.kq.biz.KQFlowActiontBiz;
import com.engine.kq.log.KQLog;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.workflow.WorkflowComInfo;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
/**
* action
*/
public class KqSplitAction extends BaseBean implements Action {
private KQLog kqLog = new KQLog();
@Override
public String execute(RequestInfo request) {
this.writeLog("KqSplitAction", "do action on request:" + request.getRequestid());
String requestid = request.getRequestid();
kqLog.info("do KqSplitAction on request:"+request.getRequestid());
int requestidInt = Util.getIntValue(requestid, 0);
String workflowid = request.getWorkflowid();
String formid = new WorkflowComInfo().getFormId(workflowid);
try {
KQFlowActiontBiz kqFlowActiontBiz = new KQFlowActiontBiz();
RecordSet rs = new RecordSet();
String proc_set_sql = "select * from kq_att_proc_set where field001 = ? and field002 = ? ";
rs.executeQuery(proc_set_sql, workflowid,formid);
if(rs.next()){
String proc_set_id = rs.getString("id");
//得到这个考勤流程设置是否使用明细
String usedetails = rs.getString("usedetail");
int kqtype = Util.getIntValue(rs.getString("field006"));
kqLog.info("do action on kqtype:" + kqtype+":requestidInt:"+requestidInt);
Map<String, String> map = new HashMap<String, String>();
if(requestidInt > 0){
map.put("requestId", "and t.requestId = " + requestidInt);
map.put("operatorId", ""+request.getRequestManager().getCreater());
}
Map<String,String> result = kqFlowActiontBiz.handleKQFlowAction(proc_set_id, usedetails, requestidInt, kqtype, Util.getIntValue(workflowid), false,false,map);
if(!result.isEmpty()){
String error = Util.null2String(result.get("message"));
request.getRequestManager().setMessageid("666" + request.getRequestid() + "999");
request.getRequestManager().setMessagecontent(error);
return Action.FAILURE_AND_CONTINUE;
}
}
} catch (Exception e) {
kqLog.info("流程数据报错:KqSplitAction:");
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
request.getRequestManager().setMessageid("11111" + request.getRequestid() + "22222");
request.getRequestManager().setMessagecontent("【考勤报表统计action】报错请联系管理员");
return Action.FAILURE_AND_CONTINUE;
}
return Action.SUCCESS;
}
}

@ -0,0 +1,457 @@
package com.engine.kq.wfset.util;
import com.alibaba.fastjson.JSON;
import com.engine.kq.biz.KQExitRulesBiz;
import com.engine.kq.biz.KQFormatData;
import com.engine.kq.biz.KQLeaveRulesBiz;
import com.engine.kq.biz.KQOvertimeRulesBiz;
import com.engine.kq.biz.KQTravelRulesBiz;
import com.engine.kq.enums.DurationTypeEnum;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.log.KQLog;
import com.engine.kq.wfset.bean.SplitBean;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;
import weaver.workflow.workflow.WorkflowRequestComInfo;
public class KQFlowUtil {
private KQLog kqLog = new KQLog();
/**
* bean
* @param splitBean
* @param rs1
* @param requestId
* @param rci
* @param workflowId
* @param durationTypeEnum
* @param key
* @param result
* @param datetimeFormatter
* @param uuid
*/
public boolean fillSplitBean(SplitBean splitBean, RecordSet rs1, String requestId,
ResourceComInfo rci, String workflowId, DurationTypeEnum durationTypeEnum, String key,
Map<String, String> result, DateTimeFormatter datetimeFormatter, String uuid){
boolean isFillRight = true;
String concort = "###" ;
int usedetail = Util.getIntValue(key.split(concort)[2], 0);
String tableDetailName= key.split(concort)[1] ;
String tableName= key.split(concort)[0] ;
String prefix = "";
String id = "dataId";
if(usedetail == 1){
prefix = "detail_";
id = "detailId";
}
boolean isLeaveBack = false;
if(durationTypeEnum == DurationTypeEnum.LEAVEBACK){
isLeaveBack = true;
}
boolean isProcessChange = false;
boolean isProcessDrawBack = false;
if(durationTypeEnum == DurationTypeEnum.PROCESSCHANGE){
isProcessChange = true;
String changetype = Util.null2s(rs1.getString("changetype"), "");
if("1".equalsIgnoreCase(changetype)){
//如果是撤销的话,没有开始日期时间和结束日期时间
isProcessDrawBack = true;
}
}
String resourceId = "";
//查询到的requestid
String requestId_rs = "";
String idVal = Util.null2s(rs1.getString(id), "0");
String fromDate = Util.null2s(rs1.getString(prefix+"fromDate"), "");
String toDate = Util.null2s(rs1.getString(prefix+"toDate"), "");
String fromTime = Util.null2s(rs1.getString(prefix+"fromTime"), "");
String toTime = Util.null2s(rs1.getString(prefix+"toTime"), "");
String durationDB = Util.null2s(rs1.getString(prefix+"duration"), "");
if(isLeaveBack || isProcessChange){
resourceId = Util.null2s(rs1.getString("resourceId"), "");
}else{
resourceId = Util.null2s(rs1.getString(prefix+"resourceId"), "");
}
if(Util.getIntValue(requestId,0) <= 0){
requestId_rs = Util.null2s(rs1.getString("requestId"), "0");
}
boolean isVal = checkActionValidate(result, fromDate, toDate, fromTime, toTime, datetimeFormatter);
if(isProcessDrawBack){
result.clear();
result.put("isProcessDrawBack", "1");
isVal = true;
}
if(!isVal){
isFillRight = false;
return isFillRight;
}
if(isLeaveBack){
LocalDateTime localFromDateTime = LocalDateTime.parse(fromDate+" "+fromTime,datetimeFormatter);
LocalDateTime localToDateTime = LocalDateTime.parse(toDate+" "+toTime,datetimeFormatter);
isFillRight = KQFlowLeaveBackUtil.leaveBackCheck(rs1 ,datetimeFormatter,prefix,localFromDateTime,localToDateTime,result);
if(!isFillRight){
return isFillRight;
}
}
if(isProcessChange){
isFillRight = KQFlowProcessChangeUtil.processChangeCheck(rs1 ,requestId_rs,result);
if(!isFillRight){
return isFillRight;
}
}
if(usedetail == 1){
splitBean.setDataId("0");
splitBean.setDetailId(idVal);
splitBean.setTablenamedb(tableDetailName);
}else{
splitBean.setDataId(idVal);
splitBean.setDetailId("0");
splitBean.setTablenamedb(tableName);
}
splitBean.setFromdatedb(fromDate);
splitBean.setFromtimedb(fromTime);
splitBean.setTodatedb(toDate);
splitBean.setTotimedb(toTime);
if(requestId_rs.length() > 0){
WorkflowRequestComInfo workflowRequestComInfo = new WorkflowRequestComInfo();
splitBean.setRequestId(requestId_rs);
splitBean.setWorkflowId(workflowRequestComInfo.getWorkflowId(requestId_rs));
}else{
splitBean.setRequestId(requestId);
splitBean.setWorkflowId(workflowId);
}
splitBean.setUsedetail(""+usedetail);
splitBean.setResourceId(resourceId);
splitBean.setSubcompanyid(Util.null2s(rci.getSubCompanyID(resourceId),"0"));
splitBean.setDepartmentid(Util.null2s(rci.getDepartmentID(resourceId),"0"));
splitBean.setJobtitle(Util.null2s(rci.getJobTitle(resourceId),"0"));
splitBean.setFromDate(fromDate);
splitBean.setFromTime(fromTime);
splitBean.setToDate(toDate);
splitBean.setToTime(toTime);
splitBean.setDurationDB(durationDB);
//默认记录的状态都为0
splitBean.setStatus("0");
splitBean.setDurationTypeEnum(durationTypeEnum);
switch (durationTypeEnum){
case LEAVE:
KQFlowLeaveUtil.bean4Leave(prefix,rs1,splitBean);
break;
case EVECTION:
KQFlowEvectionUtil.bean4Evection(prefix,rs1,splitBean);
break;
case OUT:
KQFlowOutUtil.bean4Out(splitBean);
break;
case OVERTIME:
KQFlowOvertimeUtil.bean4Overtime(prefix,rs1,splitBean);
break;
case LEAVEBACK:
KQFlowLeaveBackUtil.bean4LeaveBack(prefix,rs1,splitBean);
break;
case OTHER:
bean4Other(prefix,rs1,splitBean);
break;
case PROCESSCHANGE:
KQFlowProcessChangeUtil.bean4ProcessChange(prefix,rs1,splitBean);
break;
default:
break;
}
String computingMode = splitBean.getComputingMode();
String newLeaveType = splitBean.getNewLeaveType();
if("2".equalsIgnoreCase(computingMode)){
if(durationTypeEnum == DurationTypeEnum.PROCESSCHANGE){
double oneDayHour = getOneDayHour(splitBean.getDurationTypeEnum(),newLeaveType);
splitBean.setOneDayHour(oneDayHour);
}else{
double oneDayHour = getOneDayHour(durationTypeEnum,newLeaveType);
splitBean.setOneDayHour(oneDayHour);
}
}
return isFillRight;
}
private void bean4Other(String prefix, RecordSet rs1, SplitBean splitBean) {
String minimumUnit = "1";
String computingMode = "1";
splitBean.setDurationrule(minimumUnit);
splitBean.setComputingMode(computingMode);
}
/**
* /
* @param durationTypeEnum
* @param newLeaveType
* @return
*/
public static double getOneDayHour(DurationTypeEnum durationTypeEnum,String newLeaveType){
double oneDayHour = 0.0;
//TODO KQLeaveRulesBiz.getHoursToDay如果单位是小时的时候取不到日折算时长
switch (durationTypeEnum){
case LEAVE:
oneDayHour = Util.getDoubleValue(KQLeaveRulesBiz.getHoursToDay(newLeaveType), 0.0);
break;
case EVECTION:
oneDayHour = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay(), 0.0);
break;
case OUT:
oneDayHour = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay(), 0.0);
break;
case OVERTIME:
oneDayHour = KQOvertimeRulesBiz.getHoursToDay();
break;
case LEAVEBACK:
oneDayHour = Util.getDoubleValue(KQLeaveRulesBiz.getHoursToDay(newLeaveType), 0.0);
break;
default:
}
return oneDayHour;
}
public boolean checkActionValidate(Map<String,String> result,String fromDate,String toDate,String fromTime,String toTime, DateTimeFormatter datetimeFormatter){
boolean isVal = true;
if(Util.null2String(fromDate,"").length() == 0 ||
Util.null2String(toDate,"").length() == 0 ||
Util.null2String(fromTime,"").length() == 0 ||
Util.null2String(toTime,"").length() == 0){
result.put("status", "-1");
result.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005411,weaver.general.ThreadVarLanguage.getLang())+"");
isVal = false;
return isVal;
}
if((fromDate+" "+fromTime).length() != 16 || (toDate+" "+toTime).length() != 16){
result.put("status", "-1");
result.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005412,weaver.general.ThreadVarLanguage.getLang())+""+(fromDate+" "+fromTime)+":"+(toDate+" "+toTime));
isVal = false;
return isVal;
}
LocalDate localFromDate = LocalDate.parse(fromDate);
LocalDate localToDate = LocalDate.parse(toDate);
LocalDateTime localFromDateTime = LocalDateTime.parse(fromDate+" "+fromTime,datetimeFormatter);
LocalDateTime localToDateTime = LocalDateTime.parse(toDate+" "+toTime,datetimeFormatter);
if(localFromDateTime.isAfter(localToDateTime)){
result.put("status", "-1");
result.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(511480,weaver.general.ThreadVarLanguage.getLang())+"");
isVal = false;
return isVal;
}
if (localFromDate.isAfter(localToDate)) {
result.put("status", "-1");
result.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005413,weaver.general.ThreadVarLanguage.getLang())+"");
isVal = false;
return isVal;
}
return isVal;
}
/**
*
* @param splitBeans
* @param flowTypeEnum
* @param rci
* @param result
* @param isForce
* @param requestId
* @param workflowId
* @param isUpgrade
* @throws Exception
*/
public void handleSplitFLowActionData(
List<SplitBean> splitBeans, KqSplitFlowTypeEnum flowTypeEnum,
ResourceComInfo rci, Map<String, String> result, boolean isForce, int requestId,
int workflowId,boolean isUpgrade) throws Exception{
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
Map<String,String> custome_map = Maps.newHashMap();
List<String> custome_field = Lists.newArrayList();
if(flowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
custome_field.add("overtime_type");
}
String batchSql = "insert into "+flowTypeEnum.getTablename()+" ("
+ "requestid,workflowid,dataid,detailid,resourceid,fromdate,fromtime,"
+ "todate,totime,newleavetype,duration,usedetail,durationrule,tablenamedb,fromdatedb,"
+ "fromtimedb,todatedb,totimedb,durationdb,status,belongDate,D_Mins,serialid,"
+ "changeType,subcompanyid,departmentid,jobtitle,companion,iscompanion"+getCustomField(custome_field,"field",null,
custome_map)+")"+
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"+getCustomField(custome_field,"param",null,
custome_map)+") ";
List<List> params = new ArrayList<List>();
List<String> formateList = new ArrayList<>();
for(SplitBean bean : splitBeans){
List<Object> beanParams = new ArrayList<Object>();
beanParams.add(bean.getRequestId());
beanParams.add(bean.getWorkflowId());
beanParams.add(bean.getDataId());
beanParams.add(bean.getDetailId());
beanParams.add(bean.getResourceId());
beanParams.add(bean.getFromDate());
beanParams.add(bean.getFromTime());
beanParams.add(bean.getToDate());
beanParams.add(bean.getToTime());
beanParams.add(bean.getNewLeaveType());
beanParams.add(Util.null2s(bean.getDuration(),"0"));
beanParams.add(bean.getUsedetail());
beanParams.add(bean.getDurationrule());
beanParams.add(bean.getTablenamedb());
beanParams.add(bean.getFromdatedb());
beanParams.add(bean.getFromtimedb());
beanParams.add(bean.getTodatedb());
beanParams.add(bean.getTotimedb());
beanParams.add(bean.getDurationDB());
beanParams.add(bean.getStatus());
beanParams.add(bean.getBelongDate());
beanParams.add(bean.getD_Mins());
beanParams.add(bean.getSerialid());
beanParams.add(bean.getChangeType());
beanParams.add(bean.getSubcompanyid());
beanParams.add(bean.getDepartmentid());
beanParams.add(bean.getJobtitle());
beanParams.add(bean.getCompanion());
beanParams.add(bean.getIscompanion());
if(!custome_field.isEmpty()){
if(flowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
custome_map.put("overtime_type", bean.getOvertime_type());
}
getCustomField(custome_field, "value",beanParams,custome_map);
}
String format = bean.getResourceId()+"_"+bean.getBelongDate();
formateList.add(format);
params.add(beanParams);
if(flowTypeEnum == KqSplitFlowTypeEnum.EVECTION && false){
//qc898997 已经改成根据每个人的班次来计算了,这里就屏蔽了
KQFlowEvectionUtil kqFlowEvectionUtil = new KQFlowEvectionUtil();
String companion = Util.null2s(bean.getCompanion(), "");
if(companion.length() > 0){
kqFlowEvectionUtil.splitEvectionCompanion(companion,bean,params,rci,formateList);
}
}
}
if(!params.isEmpty()){
//先根据requestid删除中间表里的数据再做啥插入操作
String delSql = "delete from "+flowTypeEnum.getTablename()+" where requestid = "+requestId;
rs.executeUpdate(delSql);
for(int i = 0 ; i < params.size() ; i++){
List<Object> beanParams = params.get(i);
boolean isOk = rs1.executeUpdate(batchSql, beanParams);
if(!isOk){
delSql = "delete from "+flowTypeEnum.getTablename()+" where requestid = "+requestId;
rs.executeUpdate(delSql);
result.put("status", "-1");
result.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005408,weaver.general.ThreadVarLanguage.getLang())+":"+flowTypeEnum.getTablename()+""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005414,weaver.general.ThreadVarLanguage.getLang())+"");
kqLog.info("handleSplitFLowActionData:"+flowTypeEnum.getTablename()+"拆分保存失败:"+params);
return ;
}
}
kqLog.info("handleSplitFLowActionData:formateList:"+formateList+":flowTypeEnum:"+flowTypeEnum);
for(String format: formateList){
kqLog.info("handleSplitFLowActionData:format:"+ JSON.toJSONString(format)+":flowTypeEnum:"+flowTypeEnum);
String[] formats = format.split("_");
if(!isUpgrade){
//考勤设置升级的话 流程数据就不需要格式化考勤了
new KQFormatData().formatKqDate(formats[0],formats[1]);
}
}
if(!isUpgrade){
if(isForce){
if(flowTypeEnum == KqSplitFlowTypeEnum.LEAVE){
//先在这里执行扣减动作
SplitActionUtil.handleLeaveAction(splitBeans,""+requestId);
//然后再把扣减的了数据更新下KQ_ATT_VACATION表
String updateFreezeSql = "update KQ_ATT_VACATION set status=0 where requestId=? and workflowId = ? ";
boolean isUpdate = rs.executeUpdate(updateFreezeSql,requestId,""+workflowId);
if(!isUpdate){
result.put("status", "-1");
result.put("message", (""+weaver.systeminfo.SystemEnv.getHtmlLabelName(82823,weaver.general.ThreadVarLanguage.getLang())+"action"+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005361,weaver.general.ThreadVarLanguage.getLang())+""+updateFreezeSql+"(0,"+requestId+","+workflowId+")"));
kqLog.info("扣减action保存失败"+updateFreezeSql+"(0,"+requestId+","+workflowId+")");
return ;
}
}else if(flowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
// 强制归档,加班数据第一第二种规则都需要处理
SplitActionUtil.handleOverTimeAction(splitBeans, ""+requestId,true, "");
}
}else{
if(flowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
//正常归档的时候 单独针对加班规则的第一 第二种模式 生成加班数据
SplitActionUtil.handleOverTimeActionMode2(splitBeans, ""+requestId);
}
}
}else{
if(flowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
if(!splitBeans.isEmpty()){
for (SplitBean splitBean : splitBeans) {
String sql = "delete from kq_flow_overtime where requestid=? ";
rs.executeUpdate(sql, splitBean.getRequestId());
}
}
SplitActionUtil.handleOverTimeActionMode2(splitBeans, ""+requestId);
}
}
}else{
rs1.writeLog(flowTypeEnum.getTablename()+"生成的params是空");
return ;
}
}
/**
*
* @param custome_field
* @param key
* @param beanParams
* @param custome_map
* @return
*/
public String getCustomField(List<String> custome_field, String key, List<Object> beanParams,
Map<String, String> custome_map) {
String fieldValue = "";
if(!custome_field.isEmpty()){
for(int i = 0 ; i < custome_field.size() ; i++){
String tmp_value = Util.null2String(custome_field.get(i));
if(tmp_value.length() > 0){
if("field".equalsIgnoreCase(key)){
fieldValue += ","+tmp_value;
}else if("param".equalsIgnoreCase(key)){
fieldValue += ",?";
}else if("value".equalsIgnoreCase(key)){
String value = custome_map.get(tmp_value);
beanParams.add(value);
}
}
}
}
return fieldValue;
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save