|
@ -1,24 +1,61 @@ |
|
|
package com.storeroom.modules.archives.service.impl; |
|
|
package com.storeroom.modules.archives.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONArray; |
|
|
import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; |
|
|
import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; |
|
|
import com.storeroom.modules.archives.service.ArchivesService; |
|
|
import com.storeroom.modules.archives.service.ArchivesService; |
|
|
|
|
|
import com.storeroom.modules.dictionary.domain.ArchivesType; |
|
|
|
|
|
import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository; |
|
|
|
|
|
import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
|
|
import org.springframework.data.domain.Sort; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager; |
|
|
import javax.persistence.EntityManager; |
|
|
import javax.persistence.PersistenceContext; |
|
|
import javax.persistence.PersistenceContext; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
|
public class ArchivesServiceImpl implements ArchivesService { |
|
|
public class ArchivesServiceImpl implements ArchivesService { |
|
|
|
|
|
|
|
|
private final ArchivesSummaryRepository archivesSummaryRepository; |
|
|
private final ArchivesSummaryRepository archivesSummaryRepository; |
|
|
|
|
|
private final ArchivesTypeRepository archivesTypeRepository; |
|
|
|
|
|
private final ArchivesDictionaryRepository archivesDictionaryRepository; |
|
|
|
|
|
|
|
|
@PersistenceContext |
|
|
@PersistenceContext |
|
|
EntityManager entityManager; |
|
|
EntityManager entityManager; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Object initArchivesView(String categoryId, String query, Pageable page) { |
|
|
|
|
|
categoryId = "FFAFBB1647D459C82080A"; |
|
|
|
|
|
Optional<ArchivesType> optional = archivesTypeRepository.findById(categoryId); |
|
|
|
|
|
if(!optional.isPresent()) |
|
|
|
|
|
return "未查询到到门类信息!"; |
|
|
|
|
|
ArchivesType archivesType = optional.get(); |
|
|
|
|
|
List<String> queryFields = archivesDictionaryRepository.findDisPlayField(categoryId); |
|
|
|
|
|
String queryField = queryFields.stream().map(String::valueOf).collect(Collectors.joining(",")); |
|
|
|
|
|
String queryTable = archivesType.getEnName(); |
|
|
|
|
|
String quertOrder = ""; |
|
|
|
|
|
Sort sort = page.getSort(); |
|
|
|
|
|
Object[] objects = sort.get().toArray(); |
|
|
|
|
|
for(Object obj:objects){ |
|
|
|
|
|
String[] splits = obj.toString().split(":"); |
|
|
|
|
|
quertOrder += splits[0].trim()+" "+splits[1].trim() +","; |
|
|
|
|
|
} |
|
|
|
|
|
if(objects.length > 0) |
|
|
|
|
|
quertOrder = " order by " + quertOrder.substring(0,quertOrder.length()-1); |
|
|
|
|
|
|
|
|
|
|
|
List<Object[]> list = entityManager.createNativeQuery("select "+queryField+" from "+queryTable+quertOrder).getResultList(); |
|
|
|
|
|
JSONArray jsons = new JSONArray(); |
|
|
|
|
|
jsons.put(queryFields); |
|
|
|
|
|
jsons.put(list); |
|
|
|
|
|
return jsons; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String test() { |
|
|
public String test() { |
|
|
|
|
|
|
|
|