@ -18,6 +18,7 @@ import com.storeroom.utils.NanoIdUtils;
import com.storeroom.utils.PageUtil ;
import com.storeroom.utils.StringUtils ;
import lombok.RequiredArgsConstructor ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.data.domain.Page ;
import org.springframework.data.domain.Pageable ;
import org.springframework.data.domain.Sort ;
@ -40,6 +41,9 @@ public class ArchivesServiceImpl implements ArchivesService {
private final ArchivesTypeRepository archivesTypeRepository ;
private final ArchivesDictionaryRepository archivesDictionaryRepository ;
@Value ( "${file.windows.path}" )
/ / @Value ( "${file.linux.path}" )
private String prefixPath ;
@PersistenceContext
EntityManager entityManager ;
@ -50,9 +54,9 @@ public class ArchivesServiceImpl implements ArchivesService {
}
@Override
public Object initArchivesView ( String categoryId , String parentsId , Integer queryType , String queryTitle , String archiveNo , Integer archivesState ,
String archiveYear , String department , String retention , String securityClass , String organizationMatter ,
boolean isdel , Pageable page ) {
public Object initArchivesView ( String categoryId , String parentsId , Integer queryType , String queryTitle , String itemNo , String archiveNo , String archiveCtgNo ,
String responsibleby , Integer archivesState , String archiveYear , String department , String retention , String securityClass ,
String organizationMatter , boolean isdel , Pageable page ) {
Optional < ArchivesType > optional = archivesTypeRepository . findById ( categoryId ) ;
if ( ! optional . isPresent ( ) )
return "未查询到到门类信息!" ;
@ -66,9 +70,11 @@ public class ArchivesServiceImpl implements ArchivesService {
String quertOrder = "" ;
String appendQuery = "" ;
queryFields . add ( "children_num" ) ;
String append2Query = isdel ? " and is_delete_time is not null " : " and is_delete_time is null " ;
if ( archivesType . getIsType ( ) = = ArchivesTypeEnum . project . getCode ( ) | | archivesType . getIsType ( ) = = ArchivesTypeEnum . archives . getCode ( ) ) {
String childrenTable = archivesTypeRepository . findEnNameByPid ( archivesType . getId ( ) ) ;
appendQuery = StringUtils . isEmpty ( childrenTable ) ? ",0 " : ",(select count(1) from " + childrenTable + " c where c.parent_id = t.id and is_delete_time is null ) " ;
appendQuery = StringUtils . isEmpty ( childrenTable ) ? ",0 " : ",(select count(1) from " + childrenTable + " c where c.parent_id = t.id " + append2Query + " ) " ;
} else {
appendQuery = ",(select count(1) from file_" + queryTable + " c where c.archive_id = t.id) " ;
}
@ -89,7 +95,10 @@ public class ArchivesServiceImpl implements ArchivesService {
additional = StringUtils . isEmpty ( securityClass ) ? additional : additional + " and security_class = '" + securityClass + "'" ;
additional = StringUtils . isEmpty ( organizationMatter ) ? additional : additional + " and organization_matter = '" + organizationMatter + "'" ;
additional = StringUtils . isEmpty ( queryTitle ) ? additional : additional + " and maintitle like '%" + queryTitle + "%' " ;
additional = StringUtils . isEmpty ( itemNo ) ? additional : additional + " and item_no like '%" + itemNo + "%' " ;
additional = StringUtils . isEmpty ( archiveNo ) ? additional : additional + " and archive_no like '%" + archiveNo + "%' " ;
additional = StringUtils . isEmpty ( archiveCtgNo ) ? additional : additional + " and archive_ctg_no like '%" + archiveCtgNo + "%' " ;
additional = StringUtils . isEmpty ( responsibleby ) ? additional : additional + " and responsibleby like '%" + responsibleby + "%' " ;
if ( objects . length > 0 )
quertOrder = " order by " + quertOrder . substring ( 0 , quertOrder . length ( ) - 1 ) ;
@ -102,7 +111,7 @@ public class ArchivesServiceImpl implements ArchivesService {
for ( Object [ ] objs : list ) {
Map map = new HashMap ( ) ;
for ( int i = 0 ; i < queryFields . size ( ) ; i + + ) {
map . put ( queryFields . get ( i ) , objs [ i ] ) ;
map . put ( queryFields . get ( i ) , objs [ i ] = = null ? "" : objs [ i ] ) ;
}
returnlist . add ( map ) ;
}
@ -137,7 +146,7 @@ public class ArchivesServiceImpl implements ArchivesService {
}
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 )," +
String appendQuery = "tid,(select group_concat(case_name) from archives_case t where find_in_set(t.id,z.case_no) )," +
"folder_location,borrow_type,barcode " ;
appendQuery = queryField . length ( ) = = 0 ? appendQuery : "," + appendQuery ;
List < Object [ ] > list = entityManager . createNativeQuery ( "select " + queryField + appendQuery + " from " + queryTable + " z where z.id = '" + archivesId + "'" ) . getResultList ( ) ;
@ -317,7 +326,7 @@ public class ArchivesServiceImpl implements ArchivesService {
for ( Object [ ] objs : list ) {
if ( json . get ( archivesDictionary . getFieldName ( ) ) . equals ( objs [ 1 ] ) ) {
if ( dto . getId ( ) = = null | | ! dto . getId ( ) . equals ( objs [ 0 ] ) ) {
return ApiResponse . error ( 50002 , archivesDictionary . getFieldName ( ) + "不可重复" ) ;
return ApiResponse . error ( 50002 , archivesDictionary . getFieldCn Name ( ) + "不可重复" ) ;
}
}
}
@ -516,6 +525,33 @@ public class ArchivesServiceImpl implements ArchivesService {
String sql = "update " + queryTable + " set is_delete_time = '" + sdf . format ( new Date ( ) ) + "',is_delete_man='" + dto . getDelMan ( )
+ "' where id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
int result = entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;
/ / 若删除为项目
if ( archivesType . getIsType ( ) = = 2 ) {
/ / 获取档案表名
ArchivesType archivesType_3 = archivesTypeRepository . findByPid ( archivesType . getId ( ) ) ;
/ / 获取该项目下所有案卷id
String query3sql = "select id from " + archivesType_3 . getEnName ( ) + " where parent_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > list3 = entityManager . createNativeQuery ( query3sql ) . getResultList ( ) ;
if ( null ! = list3 & & list3 . size ( ) ! = 0 ) {
/ / 删除案卷
String update3sql = "update " + archivesType_3 . getEnName ( ) + " set is_delete_time = '" + sdf . format ( new Date ( ) ) + "',is_delete_man='" + dto . getDelMan ( )
+ "' where id in ('" + list3 . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
/ / 获取卷内表名
String enName_4 = archivesTypeRepository . findEnNameByPid ( archivesType_3 . getId ( ) ) ;
/ / 删除卷内
String update4sql = "update " + enName_4 + " set is_delete_time = '" + sdf . format ( new Date ( ) ) + "',is_delete_man='" + dto . getDelMan ( )
+ "' where parent_id in ('" + list3 . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
entityManager . createNativeQuery ( update3sql ) . executeUpdate ( ) ;
entityManager . createNativeQuery ( update4sql ) . executeUpdate ( ) ;
}
/ / 若删除为案卷
} else if ( archivesType . getIsType ( ) = = 3 ) {
String enName_4 = archivesTypeRepository . findEnNameByPid ( archivesType . getId ( ) ) ;
String update4sql = "update " + enName_4 + " set is_delete_time = '" + sdf . format ( new Date ( ) ) + "',is_delete_man='" + dto . getDelMan ( )
+ "' where parent_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
entityManager . createNativeQuery ( update4sql ) . executeUpdate ( ) ;
}
return result ;
}
@ -523,6 +559,7 @@ public class ArchivesServiceImpl implements ArchivesService {
@Transactional ( rollbackFor = Exception . class )
public Object reduction ( ArchivesDTO dto ) {
List < String > ids = dto . getIds ( ) ;
List < String > eliminate = new ArrayList < > ( ) ;
int success = 0 ;
ArchivesType archivesType = archivesTypeRepository . findById ( dto . getCategoryId ( ) ) . get ( ) ;
List < String > fieldNames = archivesDictionaryRepository . findFieldNameByCategoryIdAndIsTypeAndIsRepeat ( dto . getCategoryId ( ) , 2 , true ) ;
@ -533,18 +570,129 @@ public class ArchivesServiceImpl implements ArchivesService {
"= (select " + fieldName + " from " + archivesType . getEnName ( ) + " where id = '" + id + "')" ;
List < Object [ ] > list = entityManager . createNativeQuery ( querysql ) . getResultList ( ) ;
if ( list . size ( ) > 0 ) {
eliminate . add ( id ) ;
isRepeat = false ;
}
if ( isRepeat ) {
String checkDelRepeatSql = "select id from " + archivesType . getEnName ( ) + " where id = '" + id + "' and " + fieldName +
" in (select " + fieldName + " from " + archivesType . getEnName ( ) + " where is_delete_time is not null" +
" and id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "') group by " + fieldName +
" having count(" + fieldName + ") > 1)" ;
List < String > repeatCount = entityManager . createNativeQuery ( checkDelRepeatSql ) . getResultList ( ) ;
if ( repeatCount . size ( ) > 0 ) {
eliminate . add ( id ) ;
continue ;
}
}
}
}
HashSet < String > setIds = new HashSet < > ( ids ) ;
HashSet < String > setEliminate = new HashSet < > ( eliminate ) ;
setIds . removeAll ( setEliminate ) ;
List < String > screen = new ArrayList < > ( ) ;
screen . addAll ( setIds ) ;
for ( String id : screen ) {
String sql = "update " + archivesType . getEnName ( ) + " set is_delete_time = null,is_delete_man = null " +
"where id = '" + id + "'" ;
int result = entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;
success + = result ;
}
/ / 若恢复为项目时
if ( archivesType . getIsType ( ) = = 2 ) {
/ / 获取案卷门类
ArchivesType archivesType_3 = archivesTypeRepository . findByPid ( archivesType . getId ( ) ) ;
/ / 查看档案不允许重复字段
List < String > fieldNames_3 = archivesDictionaryRepository . findFieldNameByCategoryIdAndIsTypeAndIsRepeat ( archivesType_3 . getId ( ) , 2 , true ) ;
/ / 查询还原所有档案
String add3IdsSql = "select id from " + archivesType_3 . getEnName ( )
+ " where is_delete_time is not null and parent_id in ('"
+ screen . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > all3Ids = entityManager . createNativeQuery ( add3IdsSql ) . getResultList ( ) ;
List < String > eliminate_3 = new ArrayList < > ( ) ;
for ( String fieldName : fieldNames_3 ) {
String eliminate_3_sql1 = "select id from " + archivesType_3 . getEnName ( ) + " where " + fieldName
+ " in (select " + fieldName + " from " + archivesType_3 . getEnName ( )
+ " group by " + fieldName + " having count(" + fieldName + ") > 1) "
+ " and id in ('" + all3Ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > eliminate_3_1 = entityManager . createNativeQuery ( eliminate_3_sql1 ) . getResultList ( ) ;
eliminate_3 . addAll ( eliminate_3_1 ) ;
}
HashSet < String > setIds_3 = new HashSet < > ( all3Ids ) ;
HashSet < String > setEliminate_3 = new HashSet < > ( eliminate_3 ) ;
setIds_3 . removeAll ( setEliminate_3 ) ;
List < String > screen_3 = new ArrayList < > ( ) ;
screen_3 . addAll ( setIds_3 ) ;
for ( String id : screen_3 ) {
String sql_3 = "update " + archivesType_3 . getEnName ( ) + " set is_delete_time = null,is_delete_man = null " +
"where id = '" + id + "'" ;
int result_3 = entityManager . createNativeQuery ( sql_3 ) . executeUpdate ( ) ;
}
/ / 获取卷内门类
ArchivesType archivesType_4 = archivesTypeRepository . findByPid ( archivesType_3 . getId ( ) ) ;
/ / 查看卷内不允许重复字段
List < String > fieldNames_4 = archivesDictionaryRepository . findFieldNameByCategoryIdAndIsTypeAndIsRepeat ( archivesType_4 . getId ( ) , 2 , true ) ;
/ / 查询还原所有卷内
String add4IdsSql = "select id from " + archivesType_4 . getEnName ( )
+ " where is_delete_time is not null and parent_id in ('"
+ screen_3 . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > all4Ids = entityManager . createNativeQuery ( add4IdsSql ) . getResultList ( ) ;
List < String > eliminate_4 = new ArrayList < > ( ) ;
for ( String fieldName : fieldNames_4 ) {
String eliminate_4_sql1 = "select id from " + archivesType_4 . getEnName ( ) + " where " + fieldName
+ " in (select " + fieldName + " from " + archivesType_4 . getEnName ( )
+ " group by " + fieldName + " having count(" + fieldName + ") > 1) "
+ " and id in ('" + all4Ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > eliminate_4_1 = entityManager . createNativeQuery ( eliminate_4_sql1 ) . getResultList ( ) ;
eliminate_4 . addAll ( eliminate_4_1 ) ;
}
/ / 当没有重复
if ( isRepeat ) {
String sql = "update " + archivesType . getEnName ( ) + " set is_delete_time = null,is_delete_man = null " +
HashSet < String > setIds_4 = new HashSet < > ( all4Ids ) ;
HashSet < String > setEliminate_4 = new HashSet < > ( eliminate_4 ) ;
setIds_4 . removeAll ( setEliminate_4 ) ;
List < String > screen_4 = new ArrayList < > ( ) ;
screen_4 . addAll ( setIds_4 ) ;
for ( String id : screen_4 ) {
String sql_4 = "update " + archivesType_4 . getEnName ( ) + " set is_delete_time = null,is_delete_man = null " +
"where id = '" + id + "'" ;
int result = entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;
success + = result ;
int result_3 = entityManager . createNativeQuery ( sql_4 ) . executeUpdate ( ) ;
}
/ / 若恢复为案卷时
} else if ( archivesType . getIsType ( ) = = 3 ) {
/ / 获取卷内门类
ArchivesType archivesType_3 = archivesTypeRepository . findByPid ( archivesType . getId ( ) ) ;
/ / 查看卷内不允许重复字段
List < String > fieldNames_3 = archivesDictionaryRepository . findFieldNameByCategoryIdAndIsTypeAndIsRepeat ( archivesType_3 . getId ( ) , 2 , true ) ;
/ / 查询还原所有卷内
String add3IdsSql = "select id from " + archivesType_3 . getEnName ( )
+ " where is_delete_time is not null and parent_id in ('"
+ screen . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > all3Ids = entityManager . createNativeQuery ( add3IdsSql ) . getResultList ( ) ;
List < String > eliminate_3 = new ArrayList < > ( ) ;
for ( String fieldName : fieldNames_3 ) {
String eliminate_3_sql1 = "select id from " + archivesType_3 . getEnName ( ) + " where " + fieldName
+ " in (select " + fieldName + " from " + archivesType_3 . getEnName ( )
+ " group by " + fieldName + " having count(" + fieldName + ") > 1) "
+ " and id in ('" + all3Ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > eliminate_3_1 = entityManager . createNativeQuery ( eliminate_3_sql1 ) . getResultList ( ) ;
eliminate_3 . addAll ( eliminate_3_1 ) ;
}
HashSet < String > setIds_3 = new HashSet < > ( all3Ids ) ;
HashSet < String > setEliminate_3 = new HashSet < > ( eliminate_3 ) ;
setIds_3 . removeAll ( setEliminate_3 ) ;
List < String > screen_3 = new ArrayList < > ( ) ;
screen_3 . addAll ( setIds_3 ) ;
for ( String id : screen_3 ) {
String sql_3 = "update " + archivesType_3 . getEnName ( ) + " set is_delete_time = null,is_delete_man = null " +
"where id = '" + id + "'" ;
int result_3 = entityManager . createNativeQuery ( sql_3 ) . executeUpdate ( ) ;
}
}
return "成功还原" + success + "条数据" ;
return success ;
}
@Override
@ -556,9 +704,88 @@ public class ArchivesServiceImpl implements ArchivesService {
String sql = "delete from " + queryTable + " where id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
int result = entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;
int result1 = 0 ;
/ / 若删除为文件级 则删除附件
if ( ArchivesTypeEnum . inChive . getCode ( ) = = archivesType . getIsType ( ) | | ArchivesTypeEnum . files . getCode ( ) = = archivesType . getIsType ( ) ) {
String fileSql = "select file_path from file_" + queryTable + " where archive_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > filePath = entityManager . createNativeQuery ( fileSql ) . getResultList ( ) ;
String sql1 = "delete from file_" + queryTable + " where archive_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
result1 = entityManager . createNativeQuery ( sql1 ) . executeUpdate ( ) ;
for ( String paths : filePath ) {
if ( ! StringUtils . isEmpty ( paths ) ) {
File file = new File ( prefixPath + paths ) ;
if ( file . isFile ( ) & & file . exists ( ) ) {
file . delete ( ) ;
}
}
}
/ / 当删除为项目级
} else if ( ArchivesTypeEnum . project . getCode ( ) = = archivesType . getIsType ( ) ) {
/ / 获取档案表名
ArchivesType archivesType_3 = archivesTypeRepository . findByPid ( archivesType . getId ( ) ) ;
/ / 获取该项目下所有案卷id
String query3sql = "select id from " + archivesType_3 . getEnName ( ) + " where is_delete_time is not null and parent_id in ('"
+ ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > list3 = entityManager . createNativeQuery ( query3sql ) . getResultList ( ) ;
if ( null ! = list3 & & list3 . size ( ) ! = 0 ) {
/ / 删除案卷
String delete3sql = "delete from " + archivesType_3 . getEnName ( ) + " where id in ('" + list3 . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
entityManager . createNativeQuery ( delete3sql ) . executeUpdate ( ) ;
/ / 获取卷内表名
String enName_4 = archivesTypeRepository . findEnNameByPid ( archivesType_3 . getId ( ) ) ;
/ / 删除卷内
String delete4sql = "delete from " + enName_4 + " where is_delete_time is not null " +
"and parent_id in ('" + list3 . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
/ / 删除卷内文件
String sql1 = "delete from file_" + enName_4 + " where archive_id in (select id from " + enName_4
+ " where is_delete_time is not null and parent_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')) " ;
/ / 获取卷内附件路径
String fileSql = "select file_path from file_" + enName_4 + " where archive_id in (select id from " + enName_4
+ " where is_delete_time is not null and parent_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')) " ; ;
List < String > filePath = entityManager . createNativeQuery ( fileSql ) . getResultList ( ) ;
/ / 删除卷内
entityManager . createNativeQuery ( delete4sql ) . executeUpdate ( ) ;
/ / 删除卷内附件
result1 = entityManager . createNativeQuery ( sql1 ) . executeUpdate ( ) ;
for ( String paths : filePath ) {
if ( ! StringUtils . isEmpty ( paths ) ) {
File file = new File ( prefixPath + paths ) ;
if ( file . isFile ( ) & & file . exists ( ) ) {
file . delete ( ) ;
}
}
}
}
} else if ( ArchivesTypeEnum . archives . getCode ( ) = = archivesType . getIsType ( ) ) {
/ / 获取卷内表名
ArchivesType archivesType_3 = archivesTypeRepository . findByPid ( archivesType . getId ( ) ) ;
/ / 获取该项目下所有卷内id
String query3sql = "select id from " + archivesType_3 . getEnName ( ) + " where is_delete_time is not null and parent_id in ('"
+ ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
List < String > list3 = entityManager . createNativeQuery ( query3sql ) . getResultList ( ) ;
if ( null ! = list3 & & list3 . size ( ) ! = 0 ) {
/ / 删除卷内
String delete3sql = "delete from " + archivesType_3 . getEnName ( ) + " where id in ('" + list3 . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')" ;
/ / 获取卷内附件路径
String fileSql = "select file_path from file_" + archivesType_3 . getEnName ( ) + " where archive_id in (select id from " + archivesType_3 . getEnName ( )
+ " where is_delete_time is not null and parent_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')) " ;
List < String > filePath = entityManager . createNativeQuery ( fileSql ) . getResultList ( ) ;
/ / 删除卷内文件
String sql1 = "delete from file_" + archivesType_3 . getEnName ( ) + " where archive_id in (select id from " + archivesType_3 . getEnName ( )
+ " where is_delete_time is not null and parent_id in ('" + ids . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "','" ) ) + "')) " ;
/ / 删除卷内
entityManager . createNativeQuery ( delete3sql ) . executeUpdate ( ) ;
/ / 删除卷内附件
result1 = entityManager . createNativeQuery ( sql1 ) . executeUpdate ( ) ;
for ( String paths : filePath ) {
if ( ! StringUtils . isEmpty ( paths ) ) {
File file = new File ( prefixPath + paths ) ;
if ( file . isFile ( ) & & file . exists ( ) ) {
file . delete ( ) ;
}
}
}
}
}
return result + "," + result1 ;
}