@ -7,13 +7,17 @@ import com.storeroom.modules.archives.repository.ArchivesCaseCartoningRepository 
		
	
		
			
				import  com.storeroom.modules.archives.repository.ArchivesCaseRepository ; import  com.storeroom.modules.archives.repository.ArchivesCaseRepository ;  
		
	
		
			
				import  com.storeroom.modules.archives.repository.ArchivesSummaryRepository ; import  com.storeroom.modules.archives.repository.ArchivesSummaryRepository ;  
		
	
		
			
				import  com.storeroom.modules.archives.service.ArchivesCaseService ; import  com.storeroom.modules.archives.service.ArchivesCaseService ;  
		
	
		
			
				import  com.storeroom.modules.archives.service.dto.ArchivesCaseCartoningDTO ;  
		
	
		
			
				import  com.storeroom.modules.archives.domain.vo.ArchivesCaseVO ;  
		
	
		
			
				import  com.storeroom.modules.archives.service.dto.CaseDTO ; import  com.storeroom.modules.archives.service.dto.CaseDTO ;  
		
	
		
			
				import  com.storeroom.modules.common.ArchivesTypeEnum ;  
		
	
		
			
				import  com.storeroom.modules.dictionary.domain.ArchivesType ; import  com.storeroom.modules.dictionary.domain.ArchivesType ;  
		
	
		
			
				import  com.storeroom.modules.dictionary.repository.ArchivesTypeRepository ; import  com.storeroom.modules.dictionary.repository.ArchivesTypeRepository ;  
		
	
		
			
				import  com.storeroom.utils.NanoIdUtils ; import  com.storeroom.utils.NanoIdUtils ;  
		
	
		
			
				import  com.storeroom.utils.PageUtil ; import  com.storeroom.utils.PageUtil ;  
		
	
		
			
				import  com.storeroom.utils.StringUtils ; import  com.storeroom.utils.StringUtils ;  
		
	
		
			
				import  lombok.RequiredArgsConstructor ; import  lombok.RequiredArgsConstructor ;  
		
	
		
			
				import  org.springframework.beans.BeanUtils ;  
		
	
		
			
				import  org.springframework.data.domain.Page ; import  org.springframework.data.domain.Page ;  
		
	
		
			
				import  org.springframework.data.domain.Pageable ; import  org.springframework.data.domain.Pageable ;  
		
	
		
			
				import  org.springframework.stereotype.Service ; import  org.springframework.stereotype.Service ;  
		
	
	
		
			
				
					
						
							 
					
					
						
							 
					
					
				 
				@ -130,22 +134,31 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { 
		
	
		
			
				
 
		
	
		
			
				    @Override     @Override  
		
	
		
			
				    @Transactional ( rollbackFor  =  Exception . class )     @Transactional ( rollbackFor  =  Exception . class )  
		
	
		
			
				    public  Object  cartoning ( List < ArchivesCaseCartoning >  dtos )  {  
		
	
		
			
				    public  Object  cartoning ( List < ArchivesCaseCartoningDTO  >  dtos )  {  
		
	
		
			
				        Set < String >  caseIds  =  new  HashSet < > ( ) ;         Set < String >  caseIds  =  new  HashSet < > ( ) ;  
		
	
		
			
				        dtos  =  archivesCaseCartoningRepository . saveAllAndFlush ( dtos ) ;  
		
	
		
			
				        Set < String >  caseNames  =  new  HashSet < > ( ) ;  
		
	
		
			
				        List < ArchivesCaseCartoning >  archivesCaseCartonings  =  dtos . stream ( ) . map ( archivesCaseCartoning  - > {  
		
	
		
			
				            ArchivesCaseCartoning  Cartoning  =  new  ArchivesCaseCartoning ( ) ;  
		
	
		
			
				            caseIds . add ( archivesCaseCartoning . getCaseId ( ) ) ;  
		
	
		
			
				            caseNames . add ( archivesCaseCartoning . getCaseName ( ) ) ;  
		
	
		
			
				            BeanUtils . copyProperties ( Cartoning , archivesCaseCartoning ) ;  
		
	
		
			
				            return  Cartoning ;  
		
	
		
			
				        } ) . collect ( Collectors . toList ( ) ) ;  
		
	
		
			
				        archivesCaseCartonings  =  archivesCaseCartoningRepository . saveAllAndFlush ( archivesCaseCartonings ) ;  
		
	
		
			
				        ArchivesType  archivesType  =  new  ArchivesType ( ) ;         ArchivesType  archivesType  =  new  ArchivesType ( ) ;  
		
	
		
			
				        Integer  caseType  =  0 ;         Integer  caseType  =  0 ;  
		
	
		
			
				        for ( ArchivesCaseCartoning  archivesCaseCartoning : dtos ) {  
		
	
		
			
				            caseIds . add ( archivesCaseCartoning . getCaseId ( ) ) ;  
		
	
		
			
				        for ( int  i  =  0 ; i < archivesCaseCartonings . size ( ) ; i + + ) {  
		
	
		
			
				            ArchivesCaseCartoning  archivesCaseCartoning  =  archivesCaseCartonings . get ( i ) ;  
		
	
		
			
				            / / 判断档案是案卷还是文件             / / 判断档案是案卷还是文件  
		
	
		
			
				            archivesType  =  archivesTypeRepository . findById ( archivesCaseCartoning . getCategoryId ( ) ) . get ( ) ;             archivesType  =  archivesTypeRepository . findById ( archivesCaseCartoning . getCategoryId ( ) ) . get ( ) ;  
		
	
		
			
				            caseType  =  archivesType . getIsType ( )  = =  4  ?  2  :  archivesType . getIsType ( )  = =  5  ?  1  :  0 ;             caseType  =  archivesType . getIsType ( )  = =  4  ?  2  :  archivesType . getIsType ( )  = =  5  ?  1  :  0 ;  
		
	
		
			
				            String  sql  =  "update " + archivesType . getEnName ( ) + " set case_no = '" + archivesCaseCartoning . getCaseId ( ) + "' where id = '" + archivesCaseCartoning . getArchivesId ( ) + "'" ;             String  sql  =  "update " + archivesType . getEnName ( ) + " set case_no = '" + archivesCaseCartoning . getCaseId ( ) + "' where id = '" + archivesCaseCartoning . getArchivesId ( ) + "'" ;  
		
	
		
			
				            entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;             entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;  
		
	
		
			
				            archivesSummaryRepository . cartoning ( archivesCaseCartoning . getArchivesId ( ) , archivesCaseCartoning . getCaseId ( ) , dtos . get ( i ) . getCaseName ( ) ) ;  
		
	
		
			
				        }         }  
		
	
		
			
				        for  ( String  caseId : caseIds ) {         for  ( String  caseId : caseIds ) {  
		
	
		
			
				            Integer  count  =  0 ;             Integer  count  =  0 ;  
		
	
		
			
				            for ( ArchivesCaseCartoning  archivesCaseCartoning : dto s) {  
		
	
		
			
				            for ( ArchivesCaseCartoning  archivesCaseCartoning : archivesCaseCartoning s) {  
		
	
		
			
				                if ( caseId . equals ( archivesCaseCartoning . getCaseId ( ) ) ) {                 if ( caseId . equals ( archivesCaseCartoning . getCaseId ( ) ) ) {  
		
	
		
			
				                    count + + ;                     count + + ;  
		
	
		
			
				                }                 }  
		
	
	
		
			
				
					
					
					
						
							 
					
				 
				@ -157,10 +170,67 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { 
		
	
		
			
				        if ( caseType  = =  2 ) {         if ( caseType  = =  2 ) {  
		
	
		
			
				            ArchivesType  archivesTypeP  =  archivesTypeRepository . findById ( archivesType . getPid ( ) ) . get ( ) ;             ArchivesType  archivesTypeP  =  archivesTypeRepository . findById ( archivesType . getPid ( ) ) . get ( ) ;  
		
	
		
			
				            String  psql  =  "update " + archivesTypeP . getEnName ( ) + " set case_no = '" + caseIdArr             String  psql  =  "update " + archivesTypeP . getEnName ( ) + " set case_no = '" + caseIdArr  
		
	
		
			
				                    + "' where id = (select pid from " + archivesType . getEnName ( ) + " where id =  '" + dtos . get ( 0 ) . getArchivesId ( ) + "' limit 0,1) " ;  
		
	
		
			
				                    + "' where id = '" + dtos . get ( 0 ) . getArchivesParents Id ( ) + "'" ;  
		
	
		
			
				            entityManager . createNativeQuery ( psql ) . executeUpdate ( ) ;             entityManager . createNativeQuery ( psql ) . executeUpdate ( ) ;  
		
	
		
			
				            archivesSummaryRepository . cartoning ( dtos . get ( 0 ) . getArchivesParentsId ( ) , caseIdArr , caseNames . stream ( ) . collect ( Collectors . joining ( "," ) ) ) ;  
		
	
		
			
				        }  
		
	
		
			
				        return  null ;  
		
	
		
			
				    }     }  
		
	
		
			
				
 
		
	
		
			
				    @Override  
		
	
		
			
				    public  Object  doUnpacking ( String  caseId )  {  
		
	
		
			
				        ArchivesCase  archivesCase  =  caseRepository . findById ( caseId ) . get ( ) ;  
		
	
		
			
				        List  returnList  =  new  ArrayList ( ) ;  
		
	
		
			
				        / / 文件类型档案盒  
		
	
		
			
				        if ( archivesCase . getCaseType ( ) = = 1 ) {  
		
	
		
			
				            ArchivesCaseVO  vo  =  new  ArchivesCaseVO ( ) ;  
		
	
		
			
				            BeanUtils . copyProperties ( vo , archivesCase ) ;  
		
	
		
			
				            List < ArchivesSummary >  archivesSummaries  =  archivesSummaryRepository . findAllByCaseNoAndCategoryType ( caseId ,  ArchivesTypeEnum . files . getCode ( ) ) ;  
		
	
		
			
				            vo . setArchives ( archivesSummaries ) ;  
		
	
		
			
				            returnList . add ( vo ) ;  
		
	
		
			
				        / / 案卷类型盒  
		
	
		
			
				        } else  if ( archivesCase . getCaseType ( ) = = 2 ) {  
		
	
		
			
				            List < ArchivesSummary >  archivesSummaries  =  archivesSummaryRepository . findAllByCaseNoAndCategoryType ( caseId , ArchivesTypeEnum . inChive . getCode ( ) ) ;  
		
	
		
			
				            Set < String >  caseIds  =  new  HashSet < > ( ) ;  
		
	
		
			
				            for ( ArchivesSummary  archivesSummary : archivesSummaries ) {  
		
	
		
			
				                caseIds . add ( archivesSummary . getCaseNo ( ) ) ;  
		
	
		
			
				            }  
		
	
		
			
				            if ( caseIds . size ( ) = = 1 ) {  
		
	
		
			
				                ArchivesCaseVO  vo  =  new  ArchivesCaseVO ( ) ;  
		
	
		
			
				                BeanUtils . copyProperties ( vo , archivesCase ) ;  
		
	
		
			
				                vo . setArchives ( archivesSummaries ) ;  
		
	
		
			
				                returnList . add ( vo ) ;  
		
	
		
			
				            } else {  
		
	
		
			
				                for  ( String  thisCaseId : caseIds ) {  
		
	
		
			
				                    ArchivesCase  newCase  =  caseRepository . findById ( thisCaseId ) . get ( ) ;  
		
	
		
			
				                    ArchivesCaseVO  thisVo  =  new  ArchivesCaseVO ( ) ;  
		
	
		
			
				                    BeanUtils . copyProperties ( thisVo , newCase ) ;  
		
	
		
			
				                    List < ArchivesSummary >  newSummary  =  new  ArrayList < > ( ) ;  
		
	
		
			
				                    for ( ArchivesSummary  thisSummary : archivesSummaries ) {  
		
	
		
			
				                        if ( thisCaseId . equals ( thisSummary . getCaseNo ( ) ) ) {  
		
	
		
			
				                            newSummary . add ( thisSummary ) ;  
		
	
		
			
				                        }  
		
	
		
			
				                    }  
		
	
		
			
				                    returnList . add ( thisVo ) ;  
		
	
		
			
				                }  
		
	
		
			
				            }  
		
	
		
			
				
 
		
	
		
			
				        }  
		
	
		
			
				        return  returnList ;  
		
	
		
			
				    }  
		
	
		
			
				
 
		
	
		
			
				    @Override  
		
	
		
			
				    @Transactional ( rollbackFor  =  Exception . class )  
		
	
		
			
				    public  Object  unpacking ( List < ArchivesCaseCartoningDTO >  dtos )  {  
		
	
		
			
				        Set < String >  categoryIds  =  new  HashSet < > ( ) ;  
		
	
		
			
				        for ( ArchivesCaseCartoningDTO  dto : dtos ) {  
		
	
		
			
				            categoryIds . add ( dto . getCategoryId ( ) ) ;  
		
	
		
			
				        }  
		
	
		
			
				        for ( String  categoryId : categoryIds ) {  
		
	
		
			
				            ArchivesType  archivesType  =  archivesTypeRepository . findById ( categoryId ) . get ( ) ;  
		
	
		
			
				/ /             String  sql  =  "update " + archivesType . getEnName ( ) + " set case_no = null where id = '" + archivesCaseCartoning . getArchivesId ( ) + "'" ;  
		
	
		
			
				/ /             entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;  
		
	
		
			
				        }  
		
	
		
			
				        return  null ;         return  null ;  
		
	
		
			
				    }     }  
		
	
		
			
				} }