@ -17,11 +17,10 @@ import weaver.workflow.webservices.*;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.time.LocalDate ;
import java.time.LocalTime ;
import java.time.YearMonth ;
import java.time.format.DateTimeFormatter ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.List ;
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
@ -42,9 +41,9 @@ public class KqConfirmWfCrob extends BaseCronJob {
String workflowId = bb . getPropValue ( "aisinsecond" , "workflowId" ) ;
String tableName = bb . getPropValue ( "aisinsecond" , "tableName" ) ;
String currentDate = DateUtil . getCurrentDate ( ) ;
String kqMonth = getKqMonth ( ) ;
//String kqMonth = getKqMonth();
//测试使用
//String kqMonth = "2024-11";
String kqMonth = "2024-11" ;
List < MainTableInfo > resourceList = new ArrayList < > ( ) ;
//1.获取指定分部下 类型为排班制的 考勤组
@ -147,21 +146,84 @@ public class KqConfirmWfCrob extends BaseCronJob {
//2.2 明细表2( 加班)
List < FlowDetailTableInfo > flowDetails = new ArrayList < > ( ) ;
rs . executeQuery ( "select belongdate,duration_min from KQ_FLOW_OVERTIME where belongdate >= '" + firstDayOfMonth + "' and belongdate <= '" + lastDayOfMonth + "' \n" +
" and resourceid = ? order by belongdate asc", e . getResourceId ( ) ) ;
rs . executeQuery ( "select duration_min,resourceid,ori_belongdate,belongdate,flow_dataid,fromtime,totime from KQ_FLOW_OVERTIME where ori_ belongdate >= '" + firstDayOfMonth + "' and ori_ belongdate <= '" + lastDayOfMonth + "' \n" +
" and resourceid = ? and (flow_dataid <> '' and flow_dataid is not null) order by ori_ belongdate asc", e . getResourceId ( ) ) ;
while ( rs . next ( ) ) {
String belongdate = Util . null2String ( rs . getString ( "belongdate" ) ) ;
String oriBelongDate = Util . null2String ( rs . getString ( "ori_belongdate" ) ) ;
String duration_min = Util . null2String ( rs . getString ( "duration_min" ) ) ;
WorkTimeEntity workTime = kqWorkTime . getWorkTime ( e . getResourceId ( ) , belongdate ) ;
String serialId = workTime . getSerialId ( ) ;
// WorkTimeEntity workTime = kqWorkTime.getWorkTime(e.getResourceId(), belongdate);
// String serialId = workTime.getSerialId();
//(二次需求直接默认值 0)
String serialId = "0" ;
String flowDataId = Util . null2String ( rs . getString ( "flow_dataid" ) ) ;
String fromTime = Util . null2String ( rs . getString ( "fromtime" ) ) ;
String toTime = Util . null2String ( rs . getString ( "totime" ) ) ;
flowDetails . add ( FlowDetailTableInfo . builder ( )
. date ( belongdate )
. belongDate ( belongdate )
. oriBelongDate ( oriBelongDate )
. serialId ( serialId )
. hours ( minutesToHours ( duration_min ) )
. flowDataId ( flowDataId )
. fromTime ( fromTime )
. toTime ( toTime )
. minutes ( duration_min )
//.hours(minutesToHours(duration_min))
. build ( ) ) ;
}
flowDetails . forEach ( flow - > rs . executeUpdate ( "insert into " + tableName + "_dt2 (mainid,jbrq,jbbc,jbxs) values(?,?,?,?)" , mainId , flow . getDate ( ) ,
// 使用Map对flowDataId进行分组
Map < String , List < FlowDetailTableInfo > > groupedByFlowDataId = flowDetails . stream ( )
. collect ( Collectors . groupingBy ( FlowDetailTableInfo : : getFlowDataId ) ) ;
// 对分组后的数据进行处理
List < FlowDetailTableInfo > mergedList = new ArrayList < > ( ) ;
for ( Map . Entry < String , List < FlowDetailTableInfo > > entry : groupedByFlowDataId . entrySet ( ) ) {
List < FlowDetailTableInfo > group = entry . getValue ( ) ;
if ( group . size ( ) = = 1 ) {
// 判断开始时间 结束时间 时长是否符合条件 当天的加班数据不需要 只需要跨天加班
// FlowDetailTableInfo flowDetail = group.get(1);
// String fromTime = flowDetail.getFromTime();
// String toTime = flowDetail.getToTime();
// String minutes = flowDetail.getMinutes();
// String toHours = minutesToHours(minutes);
//
// if (isBeforeTime(fromTime) && isAfterTime(toTime) && isHoursGreaterThanPrecise(toHours,7.5)) {
// flowDetail.setHours(toHours);
// mergedList.add(flowDetail);
// }
} else {
// 处理多条加班数据的情况
// 找到 belongDate 最小和最大的记录
FlowDetailTableInfo minBelongDateRecord = Collections . min ( group , Comparator . comparing ( FlowDetailTableInfo : : getBelongDate ) ) ;
FlowDetailTableInfo maxBelongDateRecord = Collections . max ( group , Comparator . comparing ( FlowDetailTableInfo : : getBelongDate ) ) ;
int totalMinutes = group . stream ( )
. mapToInt ( detail - > Integer . parseInt ( detail . getMinutes ( ) ) )
. sum ( ) ;
String fromTime = minBelongDateRecord . getFromTime ( ) ;
String toTime = maxBelongDateRecord . getToTime ( ) ;
String toHours = minutesToHours ( String . valueOf ( totalMinutes ) ) ;
// 判断开始时间 结束时间 时长是否符合条件
if ( isBeforeTime ( fromTime ) & & isAfterTime ( toTime ) & & isHoursGreaterThanPrecise ( toHours , 7.5 ) ) {
FlowDetailTableInfo mergedDetail = new FlowDetailTableInfo ( ) ;
mergedDetail . setOriBelongDate ( minBelongDateRecord . getOriBelongDate ( ) ) ;
//班次id是前一天还是后一天 (需求直接默认值)
mergedDetail . setSerialId ( "0" ) ;
mergedDetail . setHours ( toHours ) ;
// 添加到合并列表中
mergedList . add ( mergedDetail ) ;
}
}
}
mergedList . forEach ( flow - > rs . executeUpdate ( "insert into " + tableName + "_dt2 (mainid,jbrq,jbbc,jbxs) values(?,?,?,?)" , mainId , flow . getOriBelongDate ( ) ,
flow . getSerialId ( ) , flow . getHours ( ) ) ) ;
//2.3 明细表3( 请假)
@ -301,5 +363,29 @@ public class KqConfirmWfCrob extends BaseCronJob {
return reduceMins ;
}
private boolean isBeforeTime ( String fromTime ) {
String timeToMinute = fromTime . substring ( 0 , 5 ) ;
LocalTime time = LocalTime . parse ( timeToMinute + ":00" ) ;
LocalTime targetTime = LocalTime . of ( 21 , 30 ) ;
return time . isBefore ( targetTime ) ;
}
private boolean isAfterTime ( String toTime ) {
String timeToMinute = toTime . substring ( 0 , 5 ) ;
LocalTime time = LocalTime . parse ( timeToMinute + ":00" ) ;
LocalTime targetTime = LocalTime . of ( 6 , 0 ) ;
return time . isAfter ( targetTime ) ;
}
private boolean isHoursGreaterThanPrecise ( String hoursStr , double target ) {
try {
BigDecimal hours = new BigDecimal ( hoursStr ) ;
BigDecimal targetBigDecimal = BigDecimal . valueOf ( target ) ;
return hours . compareTo ( targetBigDecimal ) > 0 ;
} catch ( NumberFormatException e ) {
return false ;
}
}
}