@ -18,10 +18,14 @@ import com.storeroom.utils.NanoIdUtils;
import com.storeroom.utils.PageUtil ;
import com.storeroom.utils.StringUtils ;
import lombok.RequiredArgsConstructor ;
import org.jdom2.Document ;
import org.jdom2.output.Format ;
import org.jdom2.output.XMLOutputter ;
import org.springframework.data.domain.Pageable ;
import org.springframework.data.domain.Sort ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.jdom2.Element ;
import javax.persistence.EntityManager ;
import javax.persistence.PersistenceContext ;
@ -82,11 +86,11 @@ public class ArchivesServiceImpl implements ArchivesService {
String queryparentsId = StringUtils . isEmpty ( parentsId ) ? " " : " and parent_id = '" + parentsId + "' " ;
additional = StringUtils . isEmpty ( archiveYear ) ? archiveYear : additional + " and archive_year = '" + archiveYear + "'" ;
additional = StringUtils . isEmpty ( department ) ? department : additional + " and department = '" + department + "'" ;
additional = StringUtils . isEmpty ( retention ) ? retention : additional + " and retention = '" + retention + "'" ;
additional = StringUtils . isEmpty ( securityClass ) ? securityClass : additional + " and security_class = '" + securityClass + "'" ;
additional = StringUtils . isEmpty ( organizationMatter ) ? organizationMatter : additional + " and organization_matter = '" + organizationMatter + "'" ;
additional = StringUtils . isEmpty ( archiveYear ) ? additional : additional + " and archive_year = '" + archiveYear + "'" ;
additional = StringUtils . isEmpty ( department ) ? additional : additional + " and department = '" + department + "'" ;
additional = StringUtils . isEmpty ( retention ) ? additional : additional + " and retention = '" + retention + "'" ;
additional = StringUtils . isEmpty ( securityClass ) ? additional : additional + " and security_class = '" + securityClass + "'" ;
additional = StringUtils . isEmpty ( organizationMatter ) ? additional : additional + " and organization_matter = '" + organizationMatter + "'" ;
additional = StringUtils . isEmpty ( query ) ? additional : additional
+ " and (maintitle like '%" + query + "%' or archive_no like '%" + query + "%' or archive_year like '%" + query + "%') " ;
@ -116,30 +120,89 @@ public class ArchivesServiceImpl implements ArchivesService {
@Override
public List < ArchivesDetailsVO > archiveDetails ( String categoryId , String archivesId ) {
List < ArchivesDetailsVO > returnVo = new ArrayList < > ( ) ;
List < ArchivesDictionary > archivesDictionaries = archivesDictionaryRepository . findDisPlay ( categoryId ) ;
ArchivesType archivesType = archivesTypeRepository . findById ( categoryId ) . get ( ) ;
List < String > queryFields = archivesDictionaryRepository . findDisPlayField ( categoryId ) ;
List < String > queryCnFields = archivesDictionaryRepository . findDisPlayCnField ( categoryId ) ;
List < String > queryFields = new ArrayList < > ( ) ;
List < String > queryCnFields = new ArrayList < > ( ) ;
List < Integer > queryEditLength = new ArrayList < > ( ) ;
List < Boolean > queryisLine = new ArrayList < > ( ) ;
for ( ArchivesDictionary archivesDictionary : archivesDictionaries ) {
queryFields . add ( archivesDictionary . getFieldName ( ) ) ;
queryCnFields . add ( archivesDictionary . getFieldCnName ( ) ) ;
queryEditLength . add ( archivesDictionary . getEditLength ( ) ) ;
queryisLine . add ( archivesDictionary . getIsLine ( ) ) ;
}
/ / archivesDictionaryRepository . findDisPlayField ( categoryId ) ;
/ / archivesDictionaryRepository . findDisPlayCnField ( categoryId ) ;
String queryField = queryFields . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "," ) ) ;
String queryTable = archivesType . getEnName ( ) ;
String appendQuery = ",tid,(select group_concat(case_name) from archives_case t inner join archives_case_cartoning t1 on t.id = t1.case_id where archives_id = z.id)," +
"folder_location,borrow_type,barcode " ;
List < Object [ ] > list = entityManager . createNativeQuery ( "select " + queryField + appendQuery + " from " + queryTable + " z where z.id = '" + archivesId + "'" ) . getResultList ( ) ;
queryFields . add ( "tid" ) ; queryCnFields . add ( "TID" ) ;
queryFields . add ( "case_name" ) ; queryCnFields . add ( "盒名称" ) ;
queryFields . add ( "folder_location" ) ; queryCnFields . add ( "库房位置" ) ;
queryFields . add ( "borrow_type" ) ; queryCnFields . add ( "借阅状态" ) ;
queryFields . add ( "barcode" ) ; queryCnFields . add ( "条形码" ) ;
queryFields . add ( "tid" ) ; queryCnFields . add ( "TID" ) ; queryEditLength . add ( null ) ; queryisLine . add ( null ) ;
queryFields . add ( "case_name" ) ; queryCnFields . add ( "盒名称" ) ; queryEditLength . add ( null ) ; queryisLine . add ( null ) ;
queryFields . add ( "folder_location" ) ; queryCnFields . add ( "库房位置" ) ; queryEditLength . add ( null ) ; queryisLine . add ( null ) ;
queryFields . add ( "borrow_type" ) ; queryCnFields . add ( "借阅状态" ) ; queryEditLength . add ( null ) ; queryisLine . add ( null ) ;
queryFields . add ( "barcode" ) ; queryCnFields . add ( "条形码" ) ; queryEditLength . add ( null ) ; queryisLine . add ( null ) ;
for ( int i = 0 ; i < queryFields . size ( ) ; i + + ) {
Object [ ] obj = list . get ( 0 ) ;
ArchivesDetailsVO vo = new ArchivesDetailsVO ( ) ;
vo . setFieldName ( queryFields . get ( i ) ) ;
vo . setFieldCnName ( queryCnFields . get ( i ) ) ;
vo . setEditLength ( queryEditLength . get ( i ) ) ;
vo . setIsLine ( queryisLine . get ( i ) ) ;
vo . setContext ( obj [ i ] ) ;
returnVo . add ( vo ) ;
}
return returnVo ;
}
@Override
public StringBuffer archivesMetadata ( String categoryId , String archivesId ) {
ArchivesType archivesType = archivesTypeRepository . findById ( categoryId ) . get ( ) ;
List < ArchivesDictionary > ads = archivesDictionaryRepository . findAllByCategoryIdAndIsTypeAndIsInputOrderByIsSequenceAsc ( categoryId , 2 , true ) ;
List < String > queryFields = new ArrayList < > ( ) ;
List < String > queryCnFields = new ArrayList < > ( ) ;
for ( ArchivesDictionary archivesDictionary : ads ) {
queryFields . add ( archivesDictionary . getFieldName ( ) ) ;
queryCnFields . add ( archivesDictionary . getFieldCnName ( ) ) ;
}
String queryField = queryFields . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "," ) ) ;
String queryTable = archivesType . getEnName ( ) ;
String appendQuery = "" ;
if ( archivesType . getIsType ( ) = = ArchivesTypeEnum . project . getCode ( ) | | archivesType . getIsType ( ) = = ArchivesTypeEnum . archives . getCode ( ) ) {
String childrenTable = archivesTypeRepository . findEnNameByPid ( archivesType . getId ( ) ) ;
appendQuery = StringUtils . isEmpty ( childrenTable ) ? "0 as zj6 " : "(select count(1) from " + childrenTable + " c where c.parent_id = t.id) as zj6 " ;
} else {
appendQuery = "(select count(1) from file_" + queryTable + " c where c.archive_id = t.id) as zj6 " ;
}
List < Object [ ] > list = entityManager . createNativeQuery ( "select " + queryField + "" +
",roomplace as zj1,case_no as zj2,folder_location as zj3,tid as zj4,barcode as zj5," + appendQuery +
" from " + queryTable + " t where id = '" + archivesId + "'" ) . getResultList ( ) ;
Object [ ] doeditEntity = list . size ( ) > 0 ? list . get ( 0 ) : new Object [ queryFields . size ( ) + 6 ] ;
StringBuffer sb = new StringBuffer ( ) ;
sb . append ( "<? xml version=\"1.0\" encoding=\"UTF-8\"?>" ) ;
sb . append ( "<元数据信息>" ) ;
sb . append ( "<内容描述>" ) ;
for ( int i = 0 ; i < queryFields . size ( ) ; i + + ) {
sb . append ( "<" + queryCnFields . get ( i ) + ">" + doeditEntity [ i ] + "</" + queryCnFields . get ( i ) + ">" ) ;
}
sb . append ( "</内容描述>" ) ;
sb . append ( "<系统数据>" ) ;
sb . append ( "<库房名>" + doeditEntity [ queryFields . size ( ) ] + "</库房名>" ) ;
sb . append ( "<盒号>" + doeditEntity [ queryFields . size ( ) + 1 ] + "</盒号>" ) ;
sb . append ( "<存放位置>" + doeditEntity [ queryFields . size ( ) + 2 ] + "</存放位置>" ) ;
sb . append ( "<标签编号>" + doeditEntity [ queryFields . size ( ) + 3 ] + "</标签编号>" ) ;
sb . append ( "<条码号>" + doeditEntity [ queryFields . size ( ) + 4 ] + "</条码号>" ) ;
sb . append ( "<子条目数>" + doeditEntity [ queryFields . size ( ) + 5 ] + "</子条目数>" ) ;
sb . append ( "</系统数据>" ) ;
sb . append ( "</元数据信息>" ) ;
return sb ;
}
@Override
public List < Object [ ] > exportArchivesData ( String categoryId , String archivesId , Pageable page ) {
ArchivesType archivesType = archivesTypeRepository . findById ( categoryId ) . get ( ) ;