@ -81,9 +81,12 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
}
private int getContainerPackageDetailCount ( MesContainerSnBindModel model , MesContainerSn containerSn ) {
return containerPackageDetailRDao . findByPropertyCount (
new String [ ] { MesPcnExtConstWords . ORGANIZE_CODE , MesPcnExtConstWords . IS_DELETED , MesPcnExtConstWords . IS_VALID , "containerSn" } ,
new Object [ ] { model . getOrganizeCode ( ) , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn . getContainerSn ( ) } ) ;
List < MesContainerPackageDetail > bottomPackageDetails = new ArrayList < > ( ) ;
getBottomPackageDetails ( model . getOrganizeCode ( ) , containerSn . getContainerSn ( ) , bottomPackageDetails ) ;
return bottomPackageDetails . size ( ) ;
// return containerPackageDetailRDao.findByPropertyCount(
// new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"},
// new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()});
}
private List < MesContainerPartsModel > getContainerParts ( String organizeCode , String containerTypeCode , String containerSn ) {
@ -176,8 +179,8 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
continue ;
}
Map < String , Object > re uls t = matchRegularService . matchNumberRule ( organizeCode , barcode , "" , snPart . getMatchRule ( ) ) ;
if ( re uls t ! = null & & Objects . equals ( re uls t. get ( MesPcnExtConstWords . RESULT ) , true ) ) {
Map < String , Object > re s ult = matchRegularService . matchNumberRule ( organizeCode , barcode , "" , snPart . getMatchRule ( ) ) ;
if ( re s ult ! = null & & Objects . equals ( re s ult. get ( MesPcnExtConstWords . RESULT ) , true ) ) {
model = MesContainerPartsModel . builder ( )
. partNo ( snPart . getPartNo ( ) )
. partName ( snPart . getPartName ( ) )
@ -282,27 +285,30 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
return false ;
}
private void checkContainerBarcode ( String organizeCode , String barcode ) {
MesContainerSn containerSn = containerSnService . getContainerSn ( organizeCode , barcode ) ;
if ( containerSn = = null ) {
return ;
}
private List < MesContainerPackageDetail > checkContainerBarcode ( String organizeCode , String barcode , List < MesContainerPackageDetail > oldPackageDetails ) {
MesContainerPackage containerPackage = containerPackageRDao . getByProperty (
new String [ ] { MesPcnExtConstWords . ORGANIZE_CODE , MesPcnExtConstWords . IS_DELETED , MesPcnExtConstWords . IS_VALID , "containerSn" } ,
new Object [ ] { organizeCode , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn. getContainerSn ( ) } ) ;
new Object [ ] { organizeCode , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , barcode } ) ;
if ( containerPackage = = null | | ! Objects . equals ( containerPackage . getPackageStatus ( ) , MesExtEnumUtil . CONTAINER_PACKAGE_STATUS . STATUS_20 . getValue ( ) ) ) {
MesPcnException . throwMesBusiException ( "容器条码【%s】未关箱, 不能进行上料操作! " , containerSn . getContainerSn ( ) ) ;
MesPcnException . throwMesBusiException ( "容器条码【%s】未关箱, 不能进行上料操作! " , barcode ) ;
}
MesContainerPackageDetail bindDetail = containerPackageDetailRDao . getByProperty (
new String [ ] { MesPcnExtConstWords . ORGANIZE_CODE , MesPcnExtConstWords . IS_DELETED , MesPcnExtConstWords . IS_VALID , "barCode" } ,
new Object [ ] { organizeCode , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , barcode }
) ;
if ( bindDetail ! = null ) {
MesPcnException . throwMesBusiException ( "容器条码【%s】被容器【%s】绑定, 不能进行上料操作! " , barcode , bindDetail . getContainerSn ( ) ) ;
}
String topContainerSn = getTopContainerSn ( organizeCode , containerSn . getContainerSn ( ) ) ;
List < MesContainerPackageDetail > bottomPackageDetails = new ArrayList < > ( ) ;
getBottomPackageDetails ( organizeCode , topContainerSn , bottomPackageDetails ) ;
getBottomPackageDetails ( organizeCode , barcode , bottomPackageDetails ) ;
if ( CollectionUtils . isEmpty ( bottomPackageDetails ) ) {
return ;
return new ArrayList < > ( ) ;
}
final Set < String > containerSnSet = bottomPackageDetails . stream ( ) . map ( MesContainerPackageDetail : : getContainerSn ) . collect ( Collectors . toSet ( ) ) ;
List < MesContainerPackageDetail > combPackageDetails = new ArrayList < > ( oldPackageDetails ) ;
combPackageDetails . addAll ( bottomPackageDetails ) ;
final Set < String > containerSnSet = combPackageDetails . stream ( ) . map ( MesContainerPackageDetail : : getContainerSn ) . collect ( Collectors . toSet ( ) ) ;
StringBuilder hql = new StringBuilder ( ) ;
hql . append ( " select count(DISTINCT mss.top_container_sn) from mes_container_sn_station mss where mss.organize_code=:organizeCode and mss.is_deleted=:isDeleted and mss.is_valid=:isValid" ) ;
if ( containerSnSet . size ( ) = = 1 ) {
@ -317,17 +323,19 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
//本次查询满足条件的总数
int count = countQuery . getResultList ( ) . size ( ) ;
if ( count > 1 ) {
MesPcnException . throwMesBusiException ( "容器条码【%s】在多个站点进行过绑定! " , containerSn. getContainerSn ( ) ) ;
MesPcnException . throwMesBusiException ( "容器条码【%s】在多个站点进行过绑定! " , barcode ) ;
}
return bottomPackageDetails ;
}
@Override
public MesContainerSnBindModel doScanBarcode ( MesContainerSnBindModel model ) {
final String organizeCode = model . getOrganizeCode ( ) ;
//校验容器条码
MesContainerSn containerSn = containerSnService . checkContainerSn ( m odel. getO rganizeCode( ) , model . getContainerSn ( ) ) ;
MesContainerSn containerSn = containerSnService . checkContainerSn ( organizeCode, model . getContainerSn ( ) ) ;
MesContainerType containerType = containerTypeRDao . getByProperty (
new String [ ] { MesPcnExtConstWords . ORGANIZE_CODE , MesPcnExtConstWords . IS_DELETED , MesPcnExtConstWords . IS_VALID , "containerTypeCode" } ,
new Object [ ] { m odel. getO rganizeCode( ) , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn . getContainerTypeCode ( ) } ) ;
new Object [ ] { organizeCode, CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn . getContainerTypeCode ( ) } ) ;
if ( containerType = = null ) {
MesPcnException . throwMesBusiException ( "容器类型代码【%s】信息不存在, 请检查容器类型主数据" , containerSn . getContainerTypeCode ( ) ) ;
}
@ -338,7 +346,7 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
List < MesContainerPackageDetail > packageDetails ;
MesContainerPackage containerPackage = containerPackageRDao . getByProperty (
new String [ ] { MesPcnExtConstWords . ORGANIZE_CODE , MesPcnExtConstWords . IS_DELETED , MesPcnExtConstWords . IS_VALID , "containerSn" } ,
new Object [ ] { m odel. getO rganizeCode( ) , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn . getContainerSn ( ) } ) ;
new Object [ ] { organizeCode, CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn . getContainerSn ( ) } ) ;
if ( containerPackage = = null ) {
containerPackage = createContainerPackage ( model , containerType ) ;
packageDetails = new ArrayList < > ( ) ;
@ -348,41 +356,67 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
}
packageDetails = containerPackageDetailRDao . findByProperty (
new String [ ] { MesPcnExtConstWords . ORGANIZE_CODE , MesPcnExtConstWords . IS_DELETED , MesPcnExtConstWords . IS_VALID , "containerSn" } ,
new Object [ ] { m odel. getO rganizeCode( ) , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn . getContainerSn ( ) } ) ;
new Object [ ] { organizeCode, CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) , CommonEnumUtil . IS_VAILD . VAILD . getValue ( ) , containerSn . getContainerSn ( ) } ) ;
}
for ( MesContainerPackageDetail packageDetail : packageDetails ) {
if ( Objects . equals ( packageDetail . getBarCode ( ) , model . getBarCode ( ) ) ) {
MesPcnException . throwMesBusiException ( "容器条码【%s】与条码【%s】已绑定, 请检查数据" , containerSn . getContainerSn ( ) , model . getBarCode ( ) ) ;
}
}
List < MesContainerPackageDetail > oldPackageDetails = new ArrayList < > ( ) ;
getBottomPackageDetails ( organizeCode , containerSn . getContainerSn ( ) , oldPackageDetails ) ;
// 判断扫描的是否为容器条码
List < MesContainerPackageDetail > bottomPackageDetails ;
MesContainerSn childContainerSn = containerSnService . getContainerSn ( organizeCode , model . getBarCode ( ) ) ;
if ( childContainerSn ! = null ) {
if ( ! Objects . equals ( CommonEnumUtil . TRUE_OR_FALSE . TRUE . getValue ( ) , containerType . getIsAllowRecursion ( ) ) ) {
MesPcnException . throwBusiException ( "扫描的容器条码:%s, 不允许绑定容器! " , containerSn . getContainerSn ( ) ) ;
}
bottomPackageDetails = checkContainerBarcode ( organizeCode , model . getBarCode ( ) , oldPackageDetails ) ;
} else {
bottomPackageDetails = new ArrayList < > ( ) ;
}
checkContainerBarcode ( model . getOrganizeCode ( ) , model . getBarCode ( ) ) ;
MesContainerSnBindModel containerResult = packageContainerSnService . packageContain ( model . getOrganizeCode ( ) , model . getUserName ( ) , model . getContainerSn ( ) , model . getBarCode ( ) ) ;
if ( containerResult ! = null ) {
return containerResult ;
// MesContainerSnBindModel containerResult = packageContainerSnService.packageContain(organizeCode, model.getUserName(), model.getContainerSn(), model.getBarCode());
// if (containerResult != null) {
// return containerResult;
// }
String barcode = model . getBarCode ( ) ;
if ( ! CollectionUtils . isEmpty ( bottomPackageDetails ) ) {
barcode = bottomPackageDetails . get ( 0 ) . getBarCode ( ) ;
}
MesContainerPartsModel containerPart = checkProduceSn ( model . getOrganizeCode ( ) , containerSn , model . getBarCode ( ) , model . getPartNo ( ) ) ;
MesContainerPartsModel containerPart = checkProduceSn ( model . getOrganizeCode ( ) , containerSn , barcode , model . getPartNo ( ) ) ;
containerPart . setContainerType ( containerType . getContainerType ( ) ) ;
containerPart . setContainerPackage ( containerPackage ) ;
// 调用策略校验条码与容器是否可以绑定
Map < String , Object > matchResult = ContainerBindManager . INSTANCE . matchNumberRule ( model . getOrganizeCode ( ) , model . getBarCode ( ) , containerPart ) ;
Map < String , Object > matchResult = ContainerBindManager . INSTANCE . matchNumberRule ( model . getOrganizeCode ( ) , barcode , containerPart ) ;
assert matchResult ! = null ;
if ( Objects . equals ( matchResult . get ( MesPcnExtConstWords . RESULT ) , false ) ) {
MesPcnException . throwMesBusiException ( matchResult . get ( MesPcnExtConstWords . MESSAGE ) . toString ( ) ) ;
}
MesContainerPackageDetail packageDetail = createContainerPackageDetail ( model , containerPackage , containerPart , matchResult ) ;
packageDetails . add ( packageDetail ) ;
List < MesContainerPackageDetail > combPackageDetails = new ArrayList < > ( oldPackageDetails ) ;
if ( CollectionUtils . isEmpty ( bottomPackageDetails ) ) {
combPackageDetails . add ( packageDetail ) ;
} else {
packageDetail . setDataType ( MesExtEnumUtil . CONTAINER_BARCODE_DATA_TYPE . STATUS_30 . getValue ( ) ) ;
packageDetail . setQty ( ( double ) bottomPackageDetails . size ( ) ) ;
combPackageDetails . addAll ( bottomPackageDetails ) ;
}
containerPackage . setQty ( combPackageDetails . size ( ) ) ;
MesAbstractContainerBindCheckQtyService checkQtyService = ContainerBindManager . INSTANCE . getCheckQtyService ( MesExtEnumUtil . CONTAINER_TYPE_MIX_TYPE . getByValue ( containerType . getMixType ( ) ) ) ;
Map < String , Object > checkQtyResult = checkQtyService . doCheck ( model . getOrganizeCode ( ) , containerPackage , packageDetails , containerPart , getContainerParts ( model . getOrganizeCode ( ) , containerType . getContainerTypeCode ( ) , containerSn . getContainerSn ( ) ) ) ;
Map < String , Object > checkQtyResult = checkQtyService . doCheck ( model . getOrganizeCode ( ) , containerPackage , combPackageDetails , getContainerParts ( model . getOrganizeCode ( ) , containerType . getContainerTypeCode ( ) , containerSn . getContainerSn ( ) ) ) ;
if ( checkQtyResult ! = null & & Objects . equals ( checkQtyResult . get ( MesPcnExtConstWords . RESULT ) , false ) ) {
MesPcnException . throwMesBusiException ( checkQtyResult . get ( MesPcnExtConstWords . MESSAGE ) . toString ( ) ) ;
}
MesContainerPackageDetailBinding binding = createContainerPackageDetailBinding ( containerPackage , packageDetail , MesExtEnumUtil . CONTAINER_RAW_SN_BINDING_STATUS . BINDING , model . getUserName ( ) ) ;
packageDetails . add ( packageDetail ) ;
model . setContainerPackage ( containerPackage ) ;
model . setPackageDetails ( packageDetails ) ;
model . addPackageDetailBinding ( binding ) ;
@ -395,7 +429,6 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
private void saveContainerPackage ( MesContainerSnBindModel model ) {
MesContainerPackage containerPackage = model . getContainerPackage ( ) ;
if ( containerPackage ! = null ) {
containerPackage . setQty ( model . getPackageDetails ( ) . size ( ) ) ;
containerPackageRDao . save ( containerPackage ) ;
}
if ( ! CollectionUtils . isEmpty ( model . getPackageDetails ( ) ) ) {
@ -511,7 +544,7 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
return model ;
}
private MesContainerPartsModel checkProduceSn ( String organizeCode , MesContainerSn containerSn , String barCode , String p artNo) {
private MesContainerPartsModel checkProduceSn ( String organizeCode , MesContainerSn containerSn , String barCode , String selectP artNo) {
MesContainerPartsModel model ;
MesProduceSn produceSn = produceSnRDao . getByProperty (
new String [ ] { MesPcnExtConstWords . ORGANIZE_CODE , MesPcnExtConstWords . IS_DELETED , MesPcnExtConstWords . IS_VALID , "productSn" } ,
@ -531,7 +564,7 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService
if ( model = = null ) {
MesPcnException . throwMesBusiException ( "容器条码【%s】或容器类型代码【%s】未维护与零件关系, 请检查数据" , containerSn . getContainerSn ( ) , containerSn . getContainerTypeCode ( ) ) ;
}
if ( ! StringUtils . isEmpty ( p artNo) & & ! Objects . equals ( p artNo, model . getPartNo ( ) ) ) {
if ( ! StringUtils . isEmpty ( selectP artNo) & & ! Objects . equals ( selectP artNo, model . getPartNo ( ) ) ) {
MesPcnException . throwMesBusiException ( "条码【%s】的零件号【%s】与选择的零件不匹配, 请检查数据" , barCode , produceSn . getPartNo ( ) ) ;
}