@ -11,6 +11,7 @@ import com.storeroom.modules.dictionary.domain.ArchivesType;
import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository ;
import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository ;
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.StringUtils ;
import com.storeroom.utils.StringUtils ;
import lombok.RequiredArgsConstructor ;
import lombok.RequiredArgsConstructor ;
import org.springframework.data.domain.Pageable ;
import org.springframework.data.domain.Pageable ;
@ -36,15 +37,19 @@ public class ArchivesServiceImpl implements ArchivesService {
@PersistenceContext
@PersistenceContext
EntityManager entityManager ;
EntityManager entityManager ;
@Override
public Object initArchivesViewTable ( String categoryId ) {
List < ArchivesDictionary > queryShow = archivesDictionaryRepository . findDisPlay ( categoryId ) ;
return queryShow ;
}
@Override
@Override
public Object initArchivesView ( String categoryId , String query , boolean isdel , Pageable page ) {
public Object initArchivesView ( String categoryId , String query , boolean isdel , Pageable page ) {
categoryId = "FFAFBB1647D459C82080A" ;
Optional < ArchivesType > optional = archivesTypeRepository . findById ( categoryId ) ;
Optional < ArchivesType > optional = archivesTypeRepository . findById ( categoryId ) ;
if ( ! optional . isPresent ( ) )
if ( ! optional . isPresent ( ) )
return "未查询到到门类信息!" ;
return "未查询到到门类信息!" ;
ArchivesType archivesType = optional . get ( ) ;
ArchivesType archivesType = optional . get ( ) ;
List < String > queryFields = archivesDictionaryRepository . findDisPlayField ( categoryId ) ;
List < String > queryFields = archivesDictionaryRepository . findDisPlayField ( categoryId ) ;
List < ArchivesDictionary > queryShow = archivesDictionaryRepository . findDisPlay ( categoryId ) ;
String queryField = queryFields . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "," ) ) ;
String queryField = queryFields . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . joining ( "," ) ) ;
String queryTable = archivesType . getEnName ( ) ;
String queryTable = archivesType . getEnName ( ) ;
String quertOrder = "" ;
String quertOrder = "" ;
@ -58,16 +63,24 @@ public class ArchivesServiceImpl implements ArchivesService {
if ( objects . length > 0 )
if ( objects . length > 0 )
quertOrder = " order by " + quertOrder . substring ( 0 , quertOrder . length ( ) - 1 ) ;
quertOrder = " order by " + quertOrder . substring ( 0 , quertOrder . length ( ) - 1 ) ;
List < Object [ ] > countList = entityManager . createNativeQuery ( "select count(1) from " + queryTable + additional ) . getResultList ( ) ;
Object count = countList . get ( 0 ) ;
List < Object [ ] > list = entityManager . createNativeQuery ( "select " + queryField + " from " + queryTable + additional + quertOrder ) . getResultList ( ) ;
List < Object [ ] > list = entityManager . createNativeQuery ( "select " + queryField + " from " + queryTable + additional + quertOrder ) . getResultList ( ) ;
JSONObject json = new JSONObject ( ) ;
json . put ( "queryFields" , queryShow ) ;
json . put ( "showlist" , list ) ;
return json ;
List < Map > returnlist = new ArrayList < > ( ) ;
for ( Object [ ] objs : list ) {
Map map = new HashMap ( ) ;
for ( int i = 0 ; i < queryFields . size ( ) ; i + + ) {
map . put ( queryFields . get ( i ) , objs [ i ] ) ;
}
returnlist . add ( map ) ;
}
return PageUtil . toPage ( returnlist , count ) ;
}
}
@Override
@Override
public Object doedit ( String categoryId , String archivesId ) {
public Object doedit ( String categoryId , String archivesId ) {
JSONObject json = new JSONObject ( ) ;
JSONObject json = new JSONObject ( ) ;
List < ArchivesDictionary > allFiled = archivesDictionaryRepository . findAllByCategoryIdOrderByIsSequenceAsc ( categoryId ) ;
List < ArchivesDictionary > showFiled = archivesDictionaryRepository . findAllByCategoryIdAndIsInputOrderByIsSequenceAsc ( categoryId , true ) ;
List < ArchivesDictionary > showFiled = archivesDictionaryRepository . findAllByCategoryIdAndIsInputOrderByIsSequenceAsc ( categoryId , true ) ;
if ( ! StringUtils . isEmpty ( archivesId ) ) {
if ( ! StringUtils . isEmpty ( archivesId ) ) {
ArchivesType archivesType = archivesTypeRepository . findById ( categoryId ) . get ( ) ;
ArchivesType archivesType = archivesTypeRepository . findById ( categoryId ) . get ( ) ;
@ -87,6 +100,7 @@ public class ArchivesServiceImpl implements ArchivesService {
json . put ( "echo" , echo ) ;
json . put ( "echo" , echo ) ;
}
}
}
}
json . put ( "allFiled" , allFiled ) ;
json . put ( "showFiled" , showFiled ) ;
json . put ( "showFiled" , showFiled ) ;
return json ;
return json ;
}
}
@ -94,14 +108,10 @@ public class ArchivesServiceImpl implements ArchivesService {
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public Object edit ( ArchivesDTO dto ) {
public Object edit ( ArchivesDTO dto ) {
dto = new ArchivesDTO ( ) ;
dto . setJsonString ( "{'category_name':'测试111','remarks':'这是一个备注2'}" ) ;
String dtoId = "42DA07A3174510955C5636" ;
/ / String dtoId = null ;
/ / String dtoId = null ;
JSONObject json = new JSONObject ( dto . getJsonString ( ) ) ;
JSONObject json = new JSONObject ( dto . getJsonString ( ) ) ;
String categoryId = "FFAFBB1647D459C82080A" ;
ArchivesType archivesType = archivesTypeRepository . findById ( categoryId ) . get ( ) ;
List < ArchivesDictionary > showFiled = archivesDictionaryRepository . findAllByCategoryIdAndIsInputOrderByIsSequenceAsc ( categoryId , true ) ;
ArchivesType archivesType = archivesTypeRepository . findById ( dto . getCategoryId ( ) ) . get ( ) ;
List < ArchivesDictionary > showFiled = archivesDictionaryRepository . findAllByCategoryIdAndIsInputOrderByIsSequenceAsc ( dto . getCategoryId ( ) , true ) ;
String insertFiled = "" ;
String insertFiled = "" ;
String insertValue = "" ;
String insertValue = "" ;
String updateValue = "" ;
String updateValue = "" ;
@ -122,7 +132,7 @@ public class ArchivesServiceImpl implements ArchivesService {
if ( list . size ( ) ! = 0 ) {
if ( list . size ( ) ! = 0 ) {
for ( Object [ ] objs : list ) {
for ( Object [ ] objs : list ) {
if ( json . get ( archivesDictionary . getFieldName ( ) ) . equals ( objs [ 1 ] ) ) {
if ( json . get ( archivesDictionary . getFieldName ( ) ) . equals ( objs [ 1 ] ) ) {
if ( ! dtoId . equals ( objs [ 0 ] ) ) {
if ( ! dto . get Id( ) . equals ( objs [ 0 ] ) ) {
return archivesDictionary . getFieldName ( ) + "不可重复" ;
return archivesDictionary . getFieldName ( ) + "不可重复" ;
}
}
}
}
@ -131,7 +141,7 @@ public class ArchivesServiceImpl implements ArchivesService {
}
}
}
}
if ( StringUtils . isEmpty ( dtoId ) ) {
if ( StringUtils . isEmpty ( dto . get Id( ) ) ) {
insertFiled + = archivesDictionary . getFieldName ( ) + "," ;
insertFiled + = archivesDictionary . getFieldName ( ) + "," ;
insertValue + = archivesDictionary . getIsDataType ( ) = = 1 ?
insertValue + = archivesDictionary . getIsDataType ( ) = = 1 ?
null = = json . get ( archivesDictionary . getFieldName ( ) ) ? null + "," : "'" + json . get ( archivesDictionary . getFieldName ( ) ) + "',"
null = = json . get ( archivesDictionary . getFieldName ( ) ) ? null + "," : "'" + json . get ( archivesDictionary . getFieldName ( ) ) + "',"
@ -148,8 +158,8 @@ public class ArchivesServiceImpl implements ArchivesService {
updateValue = updateValue . length ( ) ! = 0 ? updateValue . substring ( 0 , updateValue . length ( ) - 1 ) : "" ;
updateValue = updateValue . length ( ) ! = 0 ? updateValue . substring ( 0 , updateValue . length ( ) - 1 ) : "" ;
insertFiled = "id," + insertFiled ;
insertFiled = "id," + insertFiled ;
insertValue = "'" + NanoIdUtils . randomNanoId ( ) + "'," + insertValue ;
insertValue = "'" + NanoIdUtils . randomNanoId ( ) + "'," + insertValue ;
String sql = StringUtils . isEmpty ( dtoId ) ? "insert into " + archivesType . getEnName ( ) + "(" + insertFiled + ") values (" + insertValue + ")"
: "update " + archivesType . getEnName ( ) + " set " + updateValue + " where id = '" + dtoId + "'" ;
String sql = StringUtils . isEmpty ( dto . get Id( ) ) ? "insert into " + archivesType . getEnName ( ) + "(" + insertFiled + ") values (" + insertValue + ")"
: "update " + archivesType . getEnName ( ) + " set " + updateValue + " where id = '" + dto . get Id( ) + "'" ;
int result = entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;
int result = entityManager . createNativeQuery ( sql ) . executeUpdate ( ) ;
return "成功更新" + result + "条数据。" ;
return "成功更新" + result + "条数据。" ;
}
}
@ -157,8 +167,6 @@ public class ArchivesServiceImpl implements ArchivesService {
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public Object delete ( ArchivesDTO dto ) {
public Object delete ( ArchivesDTO dto ) {
dto . setId ( "42DA07A3174510955C5635" ) ;
dto . setCategoryId ( "FFAFBB1647D459C82080A" ) ;
ArchivesType archivesType = archivesTypeRepository . findById ( dto . getCategoryId ( ) ) . get ( ) ;
ArchivesType archivesType = archivesTypeRepository . findById ( dto . getCategoryId ( ) ) . get ( ) ;
String queryTable = archivesType . getEnName ( ) ;
String queryTable = archivesType . getEnName ( ) ;
String sql = "update " + queryTable + " set is_delete_time = '" + sdf . format ( new Date ( ) ) + "',is_delete_man='" + dto . getDelMan ( ) + "' where id = '" + dto . getId ( ) + "'" ;
String sql = "update " + queryTable + " set is_delete_time = '" + sdf . format ( new Date ( ) ) + "',is_delete_man='" + dto . getDelMan ( ) + "' where id = '" + dto . getId ( ) + "'" ;
@ -169,8 +177,6 @@ public class ArchivesServiceImpl implements ArchivesService {
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public Object completelyDelete ( ArchivesDTO dto ) {
public Object completelyDelete ( ArchivesDTO dto ) {
dto . setId ( "42DA07A3174510955C5635" ) ;
dto . setCategoryId ( "FFAFBB1647D459C82080A" ) ;
ArchivesType archivesType = archivesTypeRepository . findById ( dto . getCategoryId ( ) ) . get ( ) ;
ArchivesType archivesType = archivesTypeRepository . findById ( dto . getCategoryId ( ) ) . get ( ) ;
String queryTable = archivesType . getEnName ( ) ;
String queryTable = archivesType . getEnName ( ) ;
String sql = "delete from " + queryTable + " where id = '" + dto . getId ( ) + "'" ;
String sql = "delete from " + queryTable + " where id = '" + dto . getId ( ) + "'" ;