@@ -1,5 +1,6 @@
package org.nl.b_lms.pdm.subpackagerelation.service.impl ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
@@ -26,6 +27,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import org.nl.modules.common.exception.BadRequestException ;
import org.nl.system.service.param.ISysParamService ;
import org.springframework.beans.factory.annotation.Qualifier ;
import org.springframework.scheduling.annotation.Async ;
import org.springframework.stereotype.Service ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import org.nl.common.domain.query.PageQuery ;
@@ -34,6 +37,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource ;
import java.math.BigDecimal ;
import java.util.* ;
import java.util.concurrent.CompletableFuture ;
import java.util.concurrent.ThreadPoolExecutor ;
import java.util.stream.Collectors ;
@@ -55,7 +60,6 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
private ISysParamService iSysParamService ;
@Resource
private DjqTask djqTask ;
@Resource
@@ -84,6 +88,9 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
private TaskQueueManager taskQueueManager ;
@Resource
private TaskQueue taskQueue ;
@Resource
@Qualifier ( " threadPoolExecutor " )
private ThreadPoolExecutor pool ;
/**
* 查询数据分页
@@ -101,11 +108,10 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
@Override
public IPage < PdmBiSubpackagerelation > queryContainerization ( Map whereJson , PageQuery pageable ) {
Page < PdmBiSubpackagerelation > pageObject = new Page < > ( pageable . getPage ( ) , pageable . getSize ( ) ) ;
return pdmBiSubpackagerelationMapper . selectGroupedSubPackageRelation ( pageObject , ( String ) whereJson . get ( " sale_order_name " ) , ( String ) whereJson . get ( " customer_name " ) , ( String ) whereJson . get ( " customer_description " ) , ( String ) whereJson . get ( " status " ) ) ;
return pdmBiSubpackagerelationMapper . selectGroupedSubPackageRelation ( pageObject , ( String ) whereJson . get ( " sale_order_name " ) , ( String ) whereJson . get ( " customer_name " ) , ( String ) whereJson . get ( " customer_description " ) , ( String ) whereJson . get ( " status " ) ) ;
}
/**
* 查询订单装箱信息
*
@@ -140,10 +146,6 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
}
/**
* 根据订单号查询子卷信息
*
@@ -405,15 +407,12 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
if ( isOutBox . size ( ) > 0 ) {
throw new BadRequestException ( " 标记为黄色的子卷号已分配木箱,请重新选择未分配木箱的子卷 " ) ;
}
List < String > entityList = JSONObject . parseArray ( whereJson . getJSONArray ( " tableMater " ) . toJSONString ( ) , PdmBiSubpackagerelation . class ) . stream ( )
. map ( PdmBiSubpackagerelation : : getWorkorder_id )
. map ( String : : valueOf )
. collect ( Collectors . toList ( ) ) ;
if ( entityList . isEmpty ( ) ) {
return ;
JSONArray jsonArray = whereJson . getJSONArray ( " tableMater " ) ;
if ( jsonArray = = null | | jsonArray . size ( ) = = 0 ) {
throw new BadRequestException ( " 无选中子卷信息 " ) ;
}
List < PdmBiSubpackagerelation > pdmBiSubpackagerelationList = pdmBiSubpackagerelationMapper
. selectList ( new LambdaQueryWrapper < PdmBiSubpackagerelation > ( ) . eq ( PdmBiSubpackagerelation : : getSale_order_name , whereJson . getString ( " sale_order_name " ) ) ) ;
. selectList ( new LambdaQueryWrapper < PdmBiSubpackagerelation > ( ) . eq ( PdmBiSubpackagerelation : : getSale_order_name , jsonArray . getJSONObject ( 0 ) . getString ( " sale_order_name " ) ) ) ;
Integer maxBoxGroup = pdmBiSubpackagerelationList . stream ( )
. map ( PdmBiSubpackagerelation : : getBox_group )
. filter ( Objects : : nonNull )
@@ -421,6 +420,13 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
. max ( Integer : : compareTo )
. orElse ( 0 ) + 1 ;
try {
List < String > entityList = JSONObject . parseArray ( whereJson . getJSONArray ( " tableMater " ) . toJSONString ( ) , PdmBiSubpackagerelation . class ) . stream ( )
. map ( PdmBiSubpackagerelation : : getWorkorder_id )
. map ( String : : valueOf )
. collect ( Collectors . toList ( ) ) ;
if ( entityList . isEmpty ( ) ) {
return ;
}
// code: 终点,material_code: 木箱规格,num: 子卷数
UpdateWrapper < PdmBiSubpackagerelation > updateWrapper = new UpdateWrapper < > ( ) ;
String boxType = whereJson . getString ( " checked " ) ;
@@ -440,8 +446,38 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
* 空木箱出库
*/
private void outBox ( List < String > entityList , List < PdmBiSubpackagerelation > packagerelationList , String boxType ) {
//均衡获取装箱对接位
//String deviceCode= getPointCode();
String deviceCode = " ZXQ_1_1 " ;
JSONObject boxInfo = new JSONObject ( ) ;
String deviceCode ;
//确定装箱区终点
boxInfo . put ( " device_code " , deviceCode ) ;
boxInfo . put ( " material_code " , boxType ) ;
boxInfo . put ( " num " , entityList . size ( ) ) ;
String boxSn = outBoxManageService . outBox ( boxInfo ) ;
if ( StringUtils . isBlank ( boxSn ) ) {
throw new BadRequestException ( " 库位 -> 装箱对接位,木箱码不能为空! " ) ;
}
//更新子卷包装关系更新木箱号
CompletableFuture . runAsync ( ( ) - > {
try {
updateBoxInfo ( entityList , boxSn ) ;
} catch ( Exception e ) {
log . error ( " 异常信息: " + e ) ;
}
} , pool ) ;
//待检区->装箱区agv任务
String finalDeviceCode = deviceCode ;
CompletableFuture . runAsync ( ( ) - > {
try {
agvTransfer ( packagerelationList , finalDeviceCode , boxSn ) ;
} catch ( Exception e ) {
log . error ( " 异常信息: " + e ) ;
}
} , pool ) ;
}
private String getPointCode ( ) {
//均衡获取木箱出库终点
List < BstIvtPackageinfoivt > bstIvtPackageinfoivtList = bstIvtPackageinfoivtMapper . selectList ( new LambdaQueryWrapper < BstIvtPackageinfoivt > ( ) . eq ( BstIvtPackageinfoivt : : getPoint_status , " 5 " ) . eq ( BstIvtPackageinfoivt : : getIs_used , " 1 " ) . orderByAsc ( BstIvtPackageinfoivt : : getPoint_code ) ) ;
if ( CollectionUtils . isEmpty ( bstIvtPackageinfoivtList ) ) {
@@ -476,23 +512,15 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
Optional < String > minPointCode = result . stream ( )
. min ( Comparator . comparingInt ( map - > map . entrySet ( ) . iterator ( ) . next ( ) . getValue ( ) ) )
. map ( map - > map . keySet ( ) . iterator ( ) . next ( ) ) ;
deviceCode = minPointCode . orElseGet ( ( ) - > bstIvtPackageinfoivtList . get ( 0 ) . getPoint_code ( ) ) ;
//确定装箱区终点
boxInfo . put ( " device_code " , deviceCode ) ;
boxInfo . put ( " material_code " , boxType ) ;
boxInfo . put ( " num " , entityList . size ( ) ) ;
String boxSn = outBoxManageService . outBox ( boxInfo ) ;
//String boxSn = "MX61401" ;
if ( StringUtils . isBlank ( boxSn ) ) {
throw new BadRequestException ( " 库位 -> 装箱对接位,木箱码不能为空! " ) ;
}
//更新子卷包装关系更新木箱号
UpdateWrapper < PdmBiSubpackagerelation > updateWrapper1 = new UpdateWrapper < > ( ) ;
updateWrapper1 . set ( " package_box_sn " , boxSn ) ;
updateWrapper1 . in ( " workorder_id " , entityList ) ;
pdmBiSubpackagerelationMapper . update ( null , updateWrapper1 ) ;
//待检区->装箱区agv任务
agvTransfer ( packagerelationList , deviceCode , boxSn ) ;
return minPointCode . orElseGet ( ( ) - > bstIvtPackageinfoivtList . get ( 0 ) . getPoint_code ( ) ) ;
}
protected void updateBoxInfo ( List < String > entityList , String boxSn ) {
UpdateWrapper < PdmBiSubpackagerelation > updateWrapper = new UpdateWrapper < > ( ) ;
updateWrapper . set ( " package_box_sn " , boxSn ) ;
updateWrapper . in ( " workorder_id " , entityList ) ;
pdmBiSubpackagerelationMapper . update ( null , updateWrapper ) ;
}
@@ -539,7 +567,7 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
}
private void agvTransfer ( List < PdmBiSubpackagerelation > packagerelationList , String deviceCode , String boxSn ) {
protected void agvTransfer ( List < PdmBiSubpackagerelation > packagerelationList , String deviceCode , String boxSn ) {
//待检区点位
List < BstIvtPackageinfoivt > djqPointList = packageinfoivtService
. list ( new LambdaUpdateWrapper < BstIvtPackageinfoivt > ( )
@@ -571,7 +599,7 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl<PdmBiSubpack
schBaseTaskList . add ( task ) ;
} ) ;
//taskQueueManager.addTasksToQueue(groupId, schBaseTaskList);
taskQueue. addTasksToQueue( groupId, schBaseTaskList) ;
// taskQueue. addTasksToQueue( groupId, schBaseTaskList) ;
}