@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper ;
import com.wms.constants.enums.* ;
import com.wms.entity.app.dto.KateOrdersDto ;
import com.wms.entity.app.dto.WorkCenterAndOrderDto ;
import com.wms.entity.app.dto.extend.StockDetailInfo ;
import com.wms.entity.table.* ;
@ -25,8 +26,11 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.math.BigDecimal ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.format.DateTimeFormatter ;
import java.util.* ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
import static com.wms.config.InitLocalConfig.* ;
import static com.wms.constants.WmsConstants.MYSQL_JSON_CI ;
@ -56,9 +60,12 @@ public class WorkServiceImplements implements IWorkService {
private final StandService standService ; / / 站台服务
private final TaskService taskService ; / / 任务服务
private final WorkFlowLastService workFlowLastService ; / / 服务
private final List < String > workCreatingStations = new ArrayList < > ( ) ; / / 当前正在创建任务的站台
private final List < String > workDoingStations = new ArrayList < > ( ) ; / / 当前正在执行任务的站台
private final List < String > workFinishingStations = new ArrayList < > ( ) ; / / 当前正在完成任务的站台
/ / private final List < String > workCreatingStations = new ArrayList < > ( ) ; / / 当前正在创建任务的站台
/ / private final List < String > workDoingStations = new ArrayList < > ( ) ; / / 当前正在执行任务的站台
/ / private final List < String > workFinishingStations = new ArrayList < > ( ) ; / / 当前正在完成任务的站台
private final Map < String , Boolean > workCreatingStations = new ConcurrentHashMap < > ( ) ;
private final Map < String , Boolean > workDoingStations = new ConcurrentHashMap < > ( ) ;
private final Map < String , Boolean > workFinishingStations = new ConcurrentHashMap < > ( ) ;
private final VehicleService vehicleService ; / / 料箱服务
/ * *
@ -69,17 +76,15 @@ public class WorkServiceImplements implements IWorkService {
@Override
@Transactional ( isolation = Isolation . REPEATABLE_READ , propagation = Propagation . REQUIRED )
public void createWork ( String workStation ) {
if ( workCreatingStations . contains ( workStation ) ) {
/ / 当前站台正在创建任务
return ;
} else {
/ / 添加站台
workCreatingStations . add ( workStation ) ;
}
if ( StringUtils . isEmpty ( workStation ) ) {
/ / 站台号为空
return ;
}
if ( workCreatingStations . putIfAbsent ( workStation , Boolean . TRUE ) ! = null ) {
/ / 当前站台正在创建任务
return ;
}
try {
/ / 先判断当日是否是工作日
LocalDate currentWorkDate = LocalDate . now ( ) ;
@ -122,7 +127,7 @@ public class WorkServiceImplements implements IWorkService {
. orderByAsc ( ETagLocation : : getSequenceId ) ) ;
if ( ! StringUtils . isEmpty ( workPriority ) & & workPriority . equals ( " 1 " ) ) {
/ / 找非MWL机型 - - 先平地机
findWorks ( workStation , currentStationWorkFlows , " NOT_MWL " , currentWorkDate ) ;
findWorks ( workStation , currentStationWorkFlows , " MG " , currentWorkDate ) ;
if ( currentStationWorkFlows . isEmpty ( ) ) {
findWorks ( workStation , currentStationWorkFlows , " MWL " , currentWorkDate ) ;
}
@ -131,7 +136,7 @@ public class WorkServiceImplements implements IWorkService {
findWorks ( workStation , currentStationWorkFlows , " MWL " , currentWorkDate ) ;
if ( currentStationWorkFlows . isEmpty ( ) ) {
/ / 找非MWL机型
findWorks ( workStation , currentStationWorkFlows , " NOT_MWL " , currentWorkDate ) ;
findWorks ( workStation , currentStationWorkFlows , " MG " , currentWorkDate ) ;
}
}
@ -255,12 +260,9 @@ public class WorkServiceImplements implements IWorkService {
@Override
@Transactional ( isolation = Isolation . REPEATABLE_READ , propagation = Propagation . REQUIRED )
public void doWork ( String workStation ) {
if ( workDoingStations . contains( workStation ) ) {
if ( workDoingStations . putIfAbsent( workStation , Boolean . TRUE ) ! = null ) {
/ / 当前站台正在创建任务
return ;
} else {
/ / 添加站台
workDoingStations . add ( workStation ) ;
}
try {
/ / 查找当前站台未开始的工作流
@ -447,12 +449,9 @@ public class WorkServiceImplements implements IWorkService {
* /
@Override
public String finishWork ( String workStation ) {
if ( workFinishingStations . contains( workStation ) ) {
if ( workFinishingStations . putIfAbsent( workStation , Boolean . TRUE ) ! = null ) {
/ / 当前站台正在完成工作
return " 当前站台正在完成工作,请勿重复操作 " ;
} else {
/ / 添加站台
workFinishingStations . add ( workStation ) ;
}
String result = " " ;
try {
@ -560,92 +559,43 @@ public class WorkServiceImplements implements IWorkService {
* /
private void findWorks ( String workStation , List < WorkFlow > workFlows , String model , LocalDate currentWorkDate ) {
/ / 查到当前站台所有的小工位
LambdaQueryWrapper < WorkStationConfig > stationConfigQueryWrapper = new LambdaQueryWrapper < WorkStationConfig > ( )
. eq ( StringUtils . isNotEmpty ( workStation ) , WorkStationConfig : : getWorkStation , workStation ) ;
if ( Objects . equals ( model , " MWL " ) ) {
stationConfigQueryWrapper . eq ( WorkStationConfig : : getModel , " MWL " ) ;
} else {
stationConfigQueryWrapper . ne ( WorkStationConfig : : getModel , " MWL " ) ;
}
stationConfigQueryWrapper . orderByAsc ( WorkStationConfig : : getSmallBox ) ;
List < WorkStationConfig > currentStationConfigsOfNwl = workStationConfigService . list ( stationConfigQueryWrapper ) ;
/ / 没有工站配置
if ( currentStationConfigsOfNwl = = null | | currentStationConfigsOfNwl . isEmpty ( ) ) {
return ;
}
/ / LambdaQueryWrapper < WorkStationConfig > stationConfigQueryWrapper = new LambdaQueryWrapper < WorkStationConfig > ( )
/ / . eq ( StringUtils . isNotEmpty ( workStation ) , WorkStationConfig : : getWorkStation , workStation ) ;
/ / if ( Objects . equals ( model , " MWL " ) ) {
/ / stationConfigQueryWrapper . eq ( WorkStationConfig : : getModel , " MWL " ) ;
/ / } else {
/ / stationConfigQueryWrapper . ne ( WorkStationConfig : : getModel , " MWL " ) ;
/ / }
/ / stationConfigQueryWrapper . orderByAsc ( WorkStationConfig : : getSmallBox ) ;
/ / List < WorkStationConfig > currentStationConfigsOfNwl = workStationConfigService . list ( stationConfigQueryWrapper ) ;
/ / / / 没有工站配置
/ / if ( currentStationConfigsOfNwl = = null | | currentStationConfigsOfNwl . isEmpty ( ) ) {
/ / return ;
/ / }
/ / 今日开工的工单和小工位
Map < String , List < WorkCenterAndOrderDto > > tasksOfTodayMap = new HashMap < > ( ) ;
/ / 查询当前未开始的工单
List < KateOrders > allNewKateWorkOrders = kateOrdersService . list ( new LambdaQueryWrapper < KateOrders > ( )
. eq ( KateOrders : : getOrderStatus , 0 )
. eq ( KateOrders : : getSortString , configMap . get ( ConfigMapKeyEnum . SLOC_FILTER_STRING . getConfigKey ( ) ) ) ) ;
/ / 查询所有的dbs
List < KateDBS > allKateDBS = kateDBSService . list ( new LambdaQueryWrapper < KateDBS > ( ) . orderByAsc ( KateDBS : : getWorkSequence ) ) ;
/ / 根据所有小工位 , 查到对应的任务
for ( WorkStationConfig workConfig : currentStationConfigsOfNwl ) {
/ / 查询当前小工位是否已经判断过开工日期
if ( StringUtils . isEmpty ( workConfig . getSmallBox ( ) ) | | tasksOfTodayMap . containsKey ( workConfig . getSmallBox ( ) ) ) {
continue ;
}
/ / 通过工单表查询到对应的工单
List < KateOrders > kateWorkOrders = allNewKateWorkOrders . stream ( ) . filter ( kateWorkOrder - >
kateWorkOrder . getSupplyArea ( ) . equals ( workConfig . getSmallBox ( ) ) ) . toList ( ) ;
/ / 当前工位没有未完成的工单
if ( kateWorkOrders . isEmpty ( ) ) {
continue ;
}
List < WorkCenterAndOrderDto > toDaysOrders = new ArrayList < > ( ) ;
/ / 防止重复查询
Map < String , KateDBS > ordersAndDBSMap = new HashMap < > ( ) ;
for ( KateOrders kateWorkOrder : kateWorkOrders ) {
if ( ! ordersAndDBSMap . containsKey ( kateWorkOrder . getWorkOrder ( ) ) ) {
/ / 从DBS表查询对应的工单以及开工时间
KateDBS kateDBS = allKateDBS . stream ( ) . filter ( tempKateDBS - >
tempKateDBS . getWorkOrder ( ) . equals ( kateWorkOrder . getWorkOrder ( ) ) ) . findFirst ( ) . orElse ( null ) ;
if ( kateDBS = = null | | StringUtils . isEmpty ( kateDBS . getWorkOrder ( ) ) ) { / / 不存在对应的工单计划
continue ;
}
/ / 判断是否是当天开工
int indexOfDbs = localWorkDateList . indexOf ( kateDBS . getPlanStartDate ( ) . toLocalDate ( ) ) ;
if ( indexOfDbs = = - 1 ) {
/ / 工作日不包含此开工日期
continue ;
}
int indexAfterAdjust = indexOfDbs + workConfig . getStartDateAdjust ( ) ;
if ( indexAfterAdjust < 0 | | indexAfterAdjust > = localWorkDateList . size ( ) ) {
/ / 调整后的日期不再工作日范围
continue ;
}
if ( localWorkDateList . get ( indexAfterAdjust ) . equals ( currentWorkDate ) ) {
/ / 已经查询过的为了不重复查询 , 添加map
ordersAndDBSMap . put ( kateWorkOrder . getWorkOrder ( ) , kateDBS ) ;
/ / 添加工作计划
WorkCenterAndOrderDto wcoDto = new WorkCenterAndOrderDto ( ) ;
wcoDto . setWorkCenter ( workConfig . getSmallBox ( ) ) ;
wcoDto . setWorkOrder ( kateWorkOrder . getWorkOrder ( ) ) ;
wcoDto . setStartDate ( LocalDateTime . now ( ) . toLocalDate ( ) . atStartOfDay ( ) ) ;
wcoDto . setDbsSequence ( kateDBS . getWorkSequence ( ) ) ;
toDaysOrders . add ( wcoDto ) ;
}
}
}
tasksOfTodayMap . put ( workConfig . getSmallBox ( ) , toDaysOrders ) ;
}
/ / 判断是否有今天开工的工单和小工位
if ( ! tasksOfTodayMap . isEmpty ( ) ) {
for ( String smallBoxKey : tasksOfTodayMap . keySet ( ) ) {
List < WorkCenterAndOrderDto > currentWorkCenterAndOrderDtoList = tasksOfTodayMap . get ( smallBoxKey ) . stream ( ) . sorted ( Comparator . comparingInt ( WorkCenterAndOrderDto : : getDbsSequence ) ) . toList ( ) ;
for ( WorkCenterAndOrderDto currentWorkCenterAndOrderDto : currentWorkCenterAndOrderDtoList ) {
/ / 通过工单表查询到对应的工单
List < KateOrders > kateWorkOrderList = allNewKateWorkOrders . stream ( ) . filter ( kateWorkOrder - >
kateWorkOrder . getWorkOrder ( ) . equals ( currentWorkCenterAndOrderDto . getWorkOrder ( ) )
& & kateWorkOrder . getSupplyArea ( ) . equals ( currentWorkCenterAndOrderDto . getWorkCenter ( ) ) ) . toList ( ) ;
for ( KateOrders tempOrder : kateWorkOrderList ) {
/ / Map < String , List < WorkCenterAndOrderDto > > tasksOfTodayMap = new HashMap < > ( ) ;
/ / 查询currentWorkDate的工单 连表查询 根据tbl_app_kate_order的work_order字段和tbL_app_kate_dbs的work_order字段
/ / 查询出supplay_area字段 , 再根据supply_area字段查询tbl_app_e_location_config表的small_box字段相等的 , 根据
/ / tbl_app_e_location_config的start_date_adjust字段的值 ,
/ / 如果小于0 , 则在currentWorkDate减n的值 , 如果大于0 , 则在currentWorkDate加n的值 , 如果 = 0 , 则currentWorkDate
KateOrdersDto kateOrders = new KateOrdersDto ( ) ;
kateOrders . setSortString ( configMap . get ( ConfigMapKeyEnum . SLOC_FILTER_STRING . getConfigKey ( ) ) ) ;
kateOrders . setOrderStatus ( 0 ) ;
String currentDay = currentWorkDate . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) ;
kateOrders . setCurrentWorkDay ( currentDay ) ;
kateOrders . setModel ( model ) ;
kateOrders . setWorkStation ( workStation ) ;
List < KateOrdersDto > allNewKateWorkOrders = kateOrdersService . selectCurrentWorkDateKateOrders ( kateOrders ) ;
for ( KateOrdersDto tempOrder : allNewKateWorkOrders ) {
/ / 生成workFlow
WorkFlow tempWorkFlow = new WorkFlow ( ) ;
tempWorkFlow . setWorkFlowId ( WmsUtils . generateId ( " WORKFLOW_ " ) ) ;
tempWorkFlow . setOrderId ( tempOrder . getOrderId ( ) ) ;
if ( " MWL " . equals ( model ) ) {
tempWorkFlow . setWorkStation ( tempOrder . getWorkStation ( ) ) ;
} else {
tempWorkFlow . setWorkStation ( workStation ) ;
}
tempWorkFlow . setWorkOrder ( tempOrder . getWorkOrder ( ) ) ;
tempWorkFlow . setWorkCenter ( tempOrder . getSupplyArea ( ) ) ;
tempWorkFlow . setGoodsId ( tempOrder . getGoodsId ( ) ) ;
@ -660,9 +610,110 @@ public class WorkServiceImplements implements IWorkService {
workFlows . add ( tempWorkFlow ) ;
}
}
}
}
}
/ / List < KateOrders > allNewKateWorkOrders = kateOrdersService . list ( new LambdaQueryWrapper < KateOrders > ( )
/ / . eq ( KateOrders : : getOrderStatus , 0 )
/ / . eq ( KateOrders : : getSortString , configMap . get ( ConfigMapKeyEnum . SLOC_FILTER_STRING . getConfigKey ( ) ) ) ) ;
/ / 查询所有的dbs
/ / List < KateDBS > allKateDBS = kateDBSService . list ( new LambdaQueryWrapper < KateDBS > ( ) . orderByAsc ( KateDBS : : getWorkSequence ) ) ;
/ / 根据所有小工位 , 查到对应的任务
/ / for ( WorkStationConfig workConfig : currentStationConfigsOfNwl ) {
/ / / / 查询当前小工位是否已经判断过开工日期
/ / if ( StringUtils . isEmpty ( workConfig . getSmallBox ( ) ) | | tasksOfTodayMap . containsKey ( workConfig . getSmallBox ( ) ) ) {
/ / continue ;
/ / }
/ / / / 通过工单表查询到对应的工单
/ / List < KateOrders > kateWorkOrders = allNewKateWorkOrders . stream ( ) . filter ( kateWorkOrder - >
/ / kateWorkOrder . getSupplyArea ( ) . equals ( workConfig . getSmallBox ( ) ) ) . toList ( ) ;
/ / / / 当前工位没有未完成的工单
/ / if ( kateWorkOrders . isEmpty ( ) ) {
/ / continue ;
/ / }
/ / List < WorkCenterAndOrderDto > toDaysOrders = new ArrayList < > ( ) ;
/ / / / 防止重复查询
/ / Map < String , KateDBS > ordersAndDBSMap = new HashMap < > ( ) ;
/ / for ( KateOrders kateWorkOrder : kateWorkOrders ) {
/ / if ( ! ordersAndDBSMap . containsKey ( kateWorkOrder . getWorkOrder ( ) ) ) {
/ / / / 从DBS表查询对应的工单以及开工时间
/ / KateDBS kateDBS = allKateDBS . stream ( ) . filter ( tempKateDBS - >
/ / tempKateDBS . getWorkOrder ( ) . equals ( kateWorkOrder . getWorkOrder ( ) ) ) . findFirst ( ) . orElse ( null ) ;
/ / if ( kateDBS = = null | | StringUtils . isEmpty ( kateDBS . getWorkOrder ( ) ) ) { / / 不存在对应的工单计划
/ / continue ;
/ / }
/ / / / 判断是否是当天开工
/ / int indexOfDbs = localWorkDateList . indexOf ( kateDBS . getPlanStartDate ( ) . toLocalDate ( ) ) ;
/ / if ( indexOfDbs = = - 1 ) {
/ / / / 工作日不包含此开工日期
/ / continue ;
/ / }
/ / int indexAfterAdjust = indexOfDbs + workConfig . getStartDateAdjust ( ) ;
/ / if ( indexAfterAdjust < 0 | | indexAfterAdjust > = localWorkDateList . size ( ) ) {
/ / / / 调整后的日期不再工作日范围
/ / continue ;
/ / }
/ / if ( localWorkDateList . get ( indexAfterAdjust ) . equals ( currentWorkDate ) ) {
/ / / / 已经查询过的为了不重复查询 , 添加map
/ / ordersAndDBSMap . put ( kateWorkOrder . getWorkOrder ( ) , kateDBS ) ;
/ / / / 添加工作计划
/ / WorkCenterAndOrderDto wcoDto = new WorkCenterAndOrderDto ( ) ;
/ / wcoDto . setWorkCenter ( workConfig . getSmallBox ( ) ) ;
/ / wcoDto . setWorkOrder ( kateWorkOrder . getWorkOrder ( ) ) ;
/ / wcoDto . setStartDate ( LocalDateTime . now ( ) . toLocalDate ( ) . atStartOfDay ( ) ) ;
/ / wcoDto . setDbsSequence ( kateDBS . getWorkSequence ( ) ) ;
/ / toDaysOrders . add ( wcoDto ) ;
/ / }
/ / }
/ / }
/ / tasksOfTodayMap . put ( workConfig . getSmallBox ( ) , toDaysOrders ) ;
/ / }
/ / 过滤allNewKateWorkOrders , 根据smallBox进行分组 , 然后根据workOrder进行排序 , 然后根据workSequence进行排序
/ / Map < String , List < KateOrdersDto > > smallBoxAndKateOrdersMap = allNewKateWorkOrders . stream ( ) . collect ( Collectors . groupingBy ( KateOrdersDto : : getSmallBox ) ) ;
/ / for ( String smallBoxKey : smallBoxAndKateOrdersMap . keySet ( ) ) {
/ / List < KateOrdersDto > kateWorkOrderList = smallBoxAndKateOrdersMap . get ( smallBoxKey ) ;
/ / List < KateOrdersDto > kateWorkOrderListSorted = kateWorkOrderList . stream ( ) . sorted ( Comparator . comparingInt ( KateOrdersDto : : getWorkSequence ) ) . toList ( ) ;
/ / List < WorkCenterAndOrderDto > toDaysOrders = new ArrayList < > ( ) ;
/ / for ( KateOrdersDto kateWorkOrder : kateWorkOrderListSorted ) {
/ / / / 添加工作计划
/ / WorkCenterAndOrderDto wcoDto = new WorkCenterAndOrderDto ( ) ;
/ / wcoDto . setWorkCenter ( kateWorkOrder . getSmallBox ( ) ) ;
/ / wcoDto . setWorkOrder ( kateWorkOrder . getWorkOrder ( ) ) ;
/ / wcoDto . setStartDate ( LocalDateTime . now ( ) . toLocalDate ( ) . atStartOfDay ( ) ) ;
/ / wcoDto . setDbsSequence ( kateWorkOrder . getWorkSequence ( ) ) ;
/ / toDaysOrders . add ( wcoDto ) ;
/ / }
/ / tasksOfTodayMap . put ( smallBoxKey , toDaysOrders ) ;
/ / }
/ / 判断是否有今天开工的工单和小工位
/ / if ( ! tasksOfTodayMap . isEmpty ( ) ) {
/ / for ( String smallBoxKey : tasksOfTodayMap . keySet ( ) ) {
/ / List < WorkCenterAndOrderDto > currentWorkCenterAndOrderDtoList = tasksOfTodayMap . get ( smallBoxKey ) . stream ( ) . sorted ( Comparator . comparingInt ( WorkCenterAndOrderDto : : getDbsSequence ) ) . toList ( ) ;
/ / for ( WorkCenterAndOrderDto currentWorkCenterAndOrderDto : currentWorkCenterAndOrderDtoList ) {
/ / / / 通过工单表查询到对应的工单
/ / List < KateOrders > kateWorkOrderList = allNewKateWorkOrders . stream ( ) . filter ( kateWorkOrder - >
/ / kateWorkOrder . getWorkOrder ( ) . equals ( currentWorkCenterAndOrderDto . getWorkOrder ( ) )
/ / & & kateWorkOrder . getSupplyArea ( ) . equals ( currentWorkCenterAndOrderDto . getWorkCenter ( ) ) ) . toList ( ) ;
/ / for ( KateOrders tempOrder : kateWorkOrderList ) {
/ / / / 生成workFlow
/ / WorkFlow tempWorkFlow = new WorkFlow ( ) ;
/ / tempWorkFlow . setWorkFlowId ( WmsUtils . generateId ( " WORKFLOW_ " ) ) ;
/ / tempWorkFlow . setOrderId ( tempOrder . getOrderId ( ) ) ;
/ / tempWorkFlow . setWorkStation ( workStation ) ;
/ / tempWorkFlow . setWorkOrder ( tempOrder . getWorkOrder ( ) ) ;
/ / tempWorkFlow . setWorkCenter ( tempOrder . getSupplyArea ( ) ) ;
/ / tempWorkFlow . setGoodsId ( tempOrder . getGoodsId ( ) ) ;
/ / tempWorkFlow . setNeedNum ( tempOrder . getRequirementQuantity ( ) ) ;
/ / tempWorkFlow . setCreateTime ( LocalDateTime . now ( ) ) ;
/ / tempWorkFlow . setWorkStatus ( 0 ) ;
/ / tempWorkFlow . setLightStatus ( 0 ) ;
/ / tempWorkFlow . setPickedNum ( BigDecimal . ZERO ) ;
/ / / / 改动
/ / tempWorkFlow . setMachineType ( Objects . equals ( model , " MWL " ) ? 1 : 2 ) ;
/ / tempWorkFlow . setPlanDate ( currentWorkDate ) ;
/ / workFlows . add ( tempWorkFlow ) ;
/ / }
/ / }
/ / }
/ / }
/ / }
/ * *
* 获取当前的工作日期
@ -678,12 +729,13 @@ public class WorkServiceImplements implements IWorkService {
if ( ! StringUtils . isEmpty ( useSettingDate ) & & useSettingDate . equals ( " 1 " ) ) {
String settingDate = configMap . get ( ConfigMapKeyEnum . SETTING_DATE . getConfigKey ( ) ) ;
if ( ! StringUtils . isEmpty ( settingDate ) ) {
String [ ] settingDateArray = settingDate . split ( " - " ) ;
int settingDateYear = Integer . parseInt ( settingDateArray [ 0 ] ) ;
int settingDateMonth = Integer . parseInt ( settingDateArray [ 1 ] ) ;
int settingDateDay = Integer . parseInt ( settingDateArray [ 2 ] ) ;
/ / 系统配置的当前日期
currentWorkDate = LocalDate . of ( settingDateYear , settingDateMonth , settingDateDay ) ;
/ / String [ ] settingDateArray = settingDate . split ( " - " ) ;
/ / int settingDateYear = Integer . parseInt ( settingDateArray [ 0 ] ) ;
/ / int settingDateMonth = Integer . parseInt ( settingDateArray [ 1 ] ) ;
/ / int settingDateDay = Integer . parseInt ( settingDateArray [ 2 ] ) ;
/ / / / 系统配置的当前日期
/ / currentWorkDate = LocalDate . of ( settingDateYear , settingDateMonth , settingDateDay ) ;
currentWorkDate = LocalDate . parse ( settingDate ) ;
}
}
} catch ( Exception e ) {
@ -709,10 +761,12 @@ public class WorkServiceImplements implements IWorkService {
findWorks ( " " , thisDayMWLWorks , " MWL " , currentWorkDate ) ;
if ( ! thisDayMWLWorks . isEmpty ( ) ) {
allFlows . addAll ( thisDayMWLWorks ) ;
} else {
System . out . println ( " 查询MWL为空 " ) ;
}
/ / 获取到当天所有的平地机工作
List < WorkFlow > thisDayMGWorks = new ArrayList < > ( ) ;
findWorks ( " " , thisDayMGWorks , " NOT_MWL " , currentWorkDate ) ;
findWorks ( " " , thisDayMGWorks , " MG " , currentWorkDate ) ;
if ( ! thisDayMGWorks . isEmpty ( ) ) {
allFlows . addAll ( thisDayMGWorks ) ;
/ / 查询配置是否需要合并第二天的配置
@ -723,35 +777,41 @@ public class WorkServiceImplements implements IWorkService {
/ / 获取下一个工作日
LocalDate nextWorkDate = nextWorkDate ( currentWorkDate ) ;
if ( nextWorkDate ! = null & & nextWorkDate . isAfter ( currentWorkDate ) ) {
findWorks ( " " , nextDayMGWorks , " NOT_MWL " , nextWorkDate ) ;
findWorks ( " " , nextDayMGWorks , " MG " , nextWorkDate ) ;
}
if ( ! nextDayMGWorks . isEmpty ( ) ) {
/ / 添加第二天的平地机工作进汇总
allFlows . addAll ( nextDayMGWorks ) ;
}
}
} else {
System . out . println ( " 查询MG为空 " ) ;
}
/ / 处理这些工作流
List < WorkFlow > oldWorkFlows = workFlowService . list ( ) ;
/ / 按照工单号 + 小盒子号 + 料号来map一下
Map < String , WorkFlow > oldWorkFlowsMap = oldWorkFlows . stream ( ) . collect (
Collectors . toMap ( workFlow - >
workFlow . getWorkOrder ( ) + " _ " + workFlow . getWorkCenter ( ) + " _ " + workFlow . getGoodsId ( ) , workFlow - > workFlow ) ) ;
/ / List < WorkFlow > oldWorkFlows = workFlowService . list ( ) ;
/ / / / 按照工单号 + 小盒子号 + 料号来map一下
/ / Map < String , WorkFlow > oldWorkFlowsMap = oldWorkFlows . stream ( ) . collect (
/ / Collectors . toMap ( workFlow - >
/ / workFlow . getWorkOrder ( ) + " _ " + workFlow . getWorkCenter ( ) + " _ " + workFlow . getGoodsId ( ) , workFlow - > workFlow ) ) ;
/ / 最后需要存储的工作
List < WorkFlow > finalWorkFlows = new ArrayList < > ( ) ;
for ( WorkFlow workFlow : allFlows ) {
String key = workFlow . getWorkOrder ( ) + " _ " + workFlow . getWorkCenter ( ) + " _ " + workFlow . getGoodsId ( ) ;
if ( oldWorkFlowsMap . containsKey ( key ) ) {
continue ;
}
workFlow . setWorkStatus ( - 1 ) ; / / 设置暂存状态
finalWorkFlows . add ( workFlow ) ;
}
if ( ! finalWorkFlows . isEmpty ( ) ) {
/ / List < WorkFlow > finalWorkFlows = new ArrayList < > ( ) ;
/ / for ( WorkFlow workFlow : allFlows ) {
/ / String key = workFlow . getWorkOrder ( ) + " _ " + workFlow . getWorkCenter ( ) + " _ " + workFlow . getGoodsId ( ) ;
/ / if ( oldWorkFlowsMap . containsKey ( key ) ) {
/ / continue ;
/ / }
/ / workFlow . setWorkStatus ( - 1 ) ; / / 设置暂存状态
/ / finalWorkFlows . add ( workFlow ) ;
/ / }
/ / if ( ! finalWorkFlows . isEmpty ( ) ) {
if ( ! allFlows . isEmpty ( ) ) {
/ / 存储数据
workFlowService . saveBatch ( finalWorkFlows ) ;
/ / 设置allFlows的workStatus = - 1
allFlows . forEach ( workFlow - > workFlow . setWorkStatus ( - 1 ) ) ; / / 暂存状态
workFlowService . saveBatch ( allFlows ) ;
/ / 更新工单状态
List < String > orderIds = finalWorkFlows . stream ( ) . map ( WorkFlow : : getOrderId ) . toList ( ) ;
/ / List < String > orderIds = finalWorkFlows . stream ( ) . map ( WorkFlow : : getOrderId ) . toList ( ) ;
List < String > orderIds = allFlows . stream ( ) . map ( WorkFlow : : getOrderId ) . toList ( ) ;
if ( ! orderIds . isEmpty ( ) ) {
kateOrdersService . update ( new LambdaUpdateWrapper < KateOrders > ( )
. set ( KateOrders : : getOrderStatus , 1 )
@ -759,14 +819,20 @@ public class WorkServiceImplements implements IWorkService {
. eq ( KateOrders : : getOrderStatus , 0 ) ) ;
}
/ / 更新dbs表
List < String > workOrderList = finalWorkFlows . stream ( ) . map ( WorkFlow : : getWorkOrder ) . distinct ( ) . toList ( ) ;
/ / List < String > workOrderList = finalWorkFlows . stream ( ) . map ( WorkFlow : : getWorkOrder ) . distinct ( ) . toList ( ) ;
List < String > workOrderList = allFlows . stream ( ) . map ( WorkFlow : : getWorkOrder ) . distinct ( ) . toList ( ) ;
if ( ! workOrderList . isEmpty ( ) ) {
kateDBSService . update ( new LambdaUpdateWrapper < KateDBS > ( )
. set ( KateDBS : : getDbsStatus , 1 )
. in ( KateDBS : : getWorkOrder , workOrderList )
. eq ( KateDBS : : getDbsStatus , 0 ) ) ;
}
System . out . println ( " createTempWorkFlows 成功 " ) ;
}
else {
System . out . println ( " createTempWorkFlows 为空 " ) ;
}
}
/ * *
@ -777,56 +843,67 @@ public class WorkServiceImplements implements IWorkService {
@Override
@Transactional ( rollbackFor = Exception . class )
public void distributeWorks ( String workStation ) {
if ( workCreatingStations . contains ( workStation ) ) {
/ / 当前站台正在创建任务
return ;
} else {
/ / 添加站台
workCreatingStations . add ( workStation ) ;
}
if ( StringUtils . isEmpty ( workStation ) ) {
/ / 站台号为空
logger . error ( " 站台号为空===》》》》》》 " ) ;
return ;
}
if ( workCreatingStations . putIfAbsent ( workStation , Boolean . TRUE ) ! = null ) {
/ / 当前站台正在创建任务
logger . warn ( " 当前站台正常创建任务:{} " , workStation ) ;
return ;
}
try {
/ / 获取工作优先级
String workPriority = configMap . get ( ConfigMapKeyEnum . WORK_PRIORITY . getConfigKey ( ) ) ;
List < WorkFlow > needDistributeWorks = new ArrayList < > ( ) ;
List < WorkFlow > commonMwlWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( ) ) ;
/ / . eq ( WorkFlow : : getWorkStation , workStation )
/ / . eq ( WorkFlow : : getMachineType , 1 )
/ / . ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
if ( ! StringUtils . isEmpty ( workPriority ) & & workPriority . equals ( " 1 " ) ) {
/ / 当前工作优先级为先平地机后装载机
/ / 查询当前站台是否还有装载机的任务没做完
List < WorkFlow > oldMwlWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getWorkStation , workStation )
. eq ( WorkFlow : : getMachineType , 1 )
. ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / List < WorkFlow > oldMwlWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getWorkStation , workStation )
/ / . eq ( WorkFlow : : getMachineType , 1 )
/ / . ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / 过滤commonMwlWorks 根据workStation和machineType和workStatus = - 1 workStation = workStation
List < WorkFlow > oldMwlWorks = filterWorkFlow ( commonMwlWorks , workStation , 2 , - 1 , - 1 ) ;
if ( ! oldMwlWorks . isEmpty ( ) ) {
/ / 装载机没做完 , 不允许做平地机
return ;
}
/ / 查询已经生成的工作
List < WorkFlow > oldWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getMachineType , 2 )
. eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / List < WorkFlow > oldWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getMachineType , 2 )
/ / . eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / 过滤commonMwlWorks 根据machineType = 2
List < WorkFlow > oldWorkFlows = filterWorkFlow ( commonMwlWorks , null , 2 , - 1 , 0 ) ;
if ( oldWorkFlows . isEmpty ( ) ) {
/ / 判断下是否有平地机任务还未生成
List < WorkFlow > notCreatedMGWorks = new ArrayList < > ( ) ;
findWorks ( " " , notCreatedMGWorks , " NOT_MWL " , getCurrentWorkDate ( ) ) ;
findWorks ( " " , notCreatedMGWorks , " MG " , getCurrentWorkDate ( ) ) ;
if ( ! notCreatedMGWorks . isEmpty ( ) ) {
/ / 仍有未生成的平地机任务 , 跳过
return ;
}
List < WorkFlow > doingMgWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getWorkStation , workStation )
. eq ( WorkFlow : : getMachineType , 2 )
. ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / 过滤commonMwlWorks 根据machineType = 2 , workStatus = - 1 和workStation = 1
List < WorkFlow > doingMgWorkFlows = filterWorkFlow ( commonMwlWorks , workStation , 2 , - 1 , - 1 ) ;
/ / List < WorkFlow > doingMgWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getWorkStation , workStation )
/ / . eq ( WorkFlow : : getMachineType , 2 )
/ / . ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
if ( ! doingMgWorkFlows . isEmpty ( ) ) {
/ / 当前站台平地机正在做
return ;
}
/ / 查询装载机
List < WorkFlow > mwlWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getMachineType , 1 )
. eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / 过滤commonMwlWorks 根据machineType = 1 , workStatus = - 1
List < WorkFlow > mwlWorks = filterWorkFlow ( commonMwlWorks , null , 1 , - 1 , 0 ) ;
/ / List < WorkFlow > mwlWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getMachineType , 1 )
/ / . eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
if ( mwlWorks . isEmpty ( ) ) {
/ / 没有装载机任务 , 跳过
return ;
@ -838,17 +915,20 @@ public class WorkServiceImplements implements IWorkService {
} else {
/ / 默认优先级为先装载机后平地机
/ / 查询当前站台是否还有平地机的任务没做完
List < WorkFlow > oldMgWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getWorkStation , workStation )
. eq ( WorkFlow : : getMachineType , 2 )
. ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / 过滤commonMwlWorks 根据machineType = 2 , workStatus ! = - 1 和workStation = 1
List < WorkFlow > oldMgWorks = filterWorkFlow ( commonMwlWorks , workStation , 2 , - 1 , - 1 ) ;
/ / List < WorkFlow > oldMgWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getWorkStation , workStation )
/ / . eq ( WorkFlow : : getMachineType , 2 )
/ / . ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
if ( ! oldMgWorks . isEmpty ( ) ) {
/ / 平地机没做完 , 不允许做装载机
return ;
}
List < WorkFlow > oldWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getMachineType , 1 )
. eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / List < WorkFlow > oldWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getMachineType , 1 )
/ / . eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
List < WorkFlow > oldWorkFlows = filterWorkFlow ( commonMwlWorks , null , 1 , - 1 , 0 ) ;
if ( oldWorkFlows . isEmpty ( ) ) {
/ / 判断下是否有装载机任务还未生成
List < WorkFlow > notCreatedMWLWorks = new ArrayList < > ( ) ;
@ -857,18 +937,20 @@ public class WorkServiceImplements implements IWorkService {
/ / 仍有未生成的装载机任务 , 跳过
return ;
}
List < WorkFlow > doingMwlWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getWorkStation , workStation )
. eq ( WorkFlow : : getMachineType , 1 )
. ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / List < WorkFlow > doingMwlWorkFlows = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getWorkStation , workStation )
/ / . eq ( WorkFlow : : getMachineType , 1 )
/ / . ne ( WorkFlow : : getWorkStatus , - 1 ) ) ;
List < WorkFlow > doingMwlWorkFlows = filterWorkFlow ( commonMwlWorks , workStation , 1 , - 1 , - 1 ) ;
if ( ! doingMwlWorkFlows . isEmpty ( ) ) {
/ / 当前站台装载机正在做
return ;
}
/ / 查询平地机
List < WorkFlow > mgWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
. eq ( WorkFlow : : getMachineType , 2 )
. eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
/ / List < WorkFlow > mgWorks = workFlowService . list ( new LambdaQueryWrapper < WorkFlow > ( )
/ / . eq ( WorkFlow : : getMachineType , 2 )
/ / . eq ( WorkFlow : : getWorkStatus , - 1 ) ) ;
List < WorkFlow > mgWorks = filterWorkFlow ( commonMwlWorks , null , 2 , - 1 , 0 ) ;
if ( mgWorks . isEmpty ( ) ) {
/ / 没有平地机任务 , 跳过
return ;
@ -1057,6 +1139,37 @@ public class WorkServiceImplements implements IWorkService {
}
}
/ * *
*
* @param workFlows
* @param workStation
* @param machineType
* @param workStatus
* @param flag 0 : eq - 1 : ne
* @return
* /
private List < WorkFlow > filterWorkFlow ( List < WorkFlow > workFlows , String workStation , int machineType , int workStatus , int flag ) {
Stream < WorkFlow > stream = workFlows . stream ( ) ;
if ( StringUtils . isNotEmpty ( workStation ) ) {
stream = stream . filter ( workFlow - > workFlow . getWorkStation ( ) . equals ( workStation ) ) ;
}
if ( machineType > 0 ) {
stream = stream . filter ( workFlow - > workFlow . getMachineType ( ) . equals ( machineType ) ) ;
}
if ( workStatus ! = 0 ) {
if ( flag = = 0 ) {
stream = stream . filter ( workFlow - > workFlow . getWorkStatus ( ) . equals ( workStatus ) ) ;
} else {
stream = stream . filter ( workFlow - > ! workFlow . getWorkStatus ( ) . equals ( workStatus ) ) ;
}
}
return stream . collect ( Collectors . toList ( ) ) ;
}
/ * *
* 新版开始工作
* /