diff --git a/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java b/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java index 8d40975..a0e5ea8 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java +++ b/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java @@ -18,6 +18,16 @@ public class ArchivesController { private final ArchivesService archivesService; + @ApiOperation("档案列表") + @GetMapping("/initArchivesView") + public ApiResponse initArchivesView( + String categoryId,String query,Pageable page + ){ + return ApiResponse.success(archivesService.initArchivesView(categoryId,query,page)); + } + + + @ApiOperation("测试档案") @GetMapping("/test") public ApiResponse test( diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java index fa7fbfb..3966c0d 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java @@ -1,5 +1,9 @@ package com.storeroom.modules.archives.service; +import org.springframework.data.domain.Pageable; + public interface ArchivesService { + //初始化档案列表 + Object initArchivesView(String categoryId, String query, Pageable page); String test(); } diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java b/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java index 4b8b439..8985c01 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java @@ -1,24 +1,61 @@ package com.storeroom.modules.archives.service.impl; +import cn.hutool.json.JSONArray; import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; 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 org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class ArchivesServiceImpl implements ArchivesService { private final ArchivesSummaryRepository archivesSummaryRepository; + private final ArchivesTypeRepository archivesTypeRepository; + private final ArchivesDictionaryRepository archivesDictionaryRepository; @PersistenceContext EntityManager entityManager; + @Override + public Object initArchivesView(String categoryId, String query, Pageable page) { + categoryId = "FFAFBB1647D459C82080A"; + Optional optional = archivesTypeRepository.findById(categoryId); + if(!optional.isPresent()) + return "未查询到到门类信息!"; + ArchivesType archivesType = optional.get(); + List 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 list = entityManager.createNativeQuery("select "+queryField+" from "+queryTable+quertOrder).getResultList(); + JSONArray jsons = new JSONArray(); + jsons.put(queryFields); + jsons.put(list); + return jsons; + } + @Override public String test() { diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java b/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java index 13bf27d..b7bbf29 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java @@ -3,6 +3,14 @@ package com.storeroom.modules.dictionary.repository; import com.storeroom.modules.dictionary.domain.ArchivesType; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; public interface ArchivesDictionaryRepository extends JpaRepository, JpaSpecificationExecutor { + + @Query(nativeQuery = true, + value = "select field_name from archives_dictionary where category_id = ?1 and is_display is true order by is_displayorder asc") + List findDisPlayField(String categoryId); + } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java index 998c32e..44384c4 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java @@ -6,4 +6,8 @@ import org.springframework.stereotype.Service; @Service public class ArchivesTypeServiceImpl implements ArchivesTypeService { + @Override + public void create() { + + } }