From 69347d7505543adc33af8c43182b928ef34f5384 Mon Sep 17 00:00:00 2001 From: xia Date: Mon, 20 Jun 2022 15:24:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3=E9=99=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ArchivesController.java | 13 +++- .../archives/service/ArchivesService.java | 8 ++- .../archives/service/dto/ArchivesFileDTO.java | 26 ++++++++ .../service/impl/ArchivesServiceImpl.java | 59 ++++++++++++++++--- .../ArchivesDictionaryRepository.java | 1 + 5 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesFileDTO.java 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 09003a3..fad70d4 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 @@ -2,6 +2,7 @@ package com.storeroom.modules.archives.controller; import com.storeroom.modules.archives.service.ArchivesService; import com.storeroom.modules.archives.service.dto.ArchivesDTO; +import com.storeroom.modules.archives.service.dto.ArchivesFileDTO; import com.storeroom.modules.dictionary.service.dto.FieldDTO; import com.storeroom.utils.ApiResponse; import com.storeroom.utils.SecurityUtils; @@ -57,13 +58,21 @@ public class ArchivesController { public ApiResponse edit( @Validated @RequestBody ArchivesDTO dto ){ - return ApiResponse.success(archivesService.edit(dto)); + return archivesService.edit(dto); + } + + @ApiOperation("初始化档案附件列表") + @GetMapping("/initArchiveFilesView") + public ApiResponse initArchiveFilesView( + String categoryId,String archiveId + ){ + return ApiResponse.success(archivesService.initArchiveFilesView(categoryId,archiveId)); } @ApiOperation("编辑档案附件") @PostMapping("/editFile") public ApiResponse editFile( - @Validated @RequestBody ArchivesDTO dto + @Validated @RequestBody ArchivesFileDTO dto ){ return ApiResponse.success(archivesService.editFile(dto)); } 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 e5fd114..da722a9 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,6 +1,8 @@ package com.storeroom.modules.archives.service; import com.storeroom.modules.archives.service.dto.ArchivesDTO; +import com.storeroom.modules.archives.service.dto.ArchivesFileDTO; +import com.storeroom.utils.ApiResponse; import org.springframework.data.domain.Pageable; public interface ArchivesService { @@ -13,9 +15,11 @@ public interface ArchivesService { //档案编辑 判断值是否超昂福 Object doeditIsRepeat(String categoryId,String archivesId,String fieldName,String value); //编辑档案 - Object edit(ArchivesDTO dto); + ApiResponse edit(ArchivesDTO dto); + //初始化档案附件列表 + Object initArchiveFilesView(String categoryId,String archiveId); //编辑档案附件 - Object editFile(ArchivesDTO dto); + Object editFile(ArchivesFileDTO dto); //档案删除进回收站 Object delete(ArchivesDTO dto); //档案回收站删除 diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesFileDTO.java b/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesFileDTO.java new file mode 100644 index 0000000..5b9a9e9 --- /dev/null +++ b/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesFileDTO.java @@ -0,0 +1,26 @@ +package com.storeroom.modules.archives.service.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class ArchivesFileDTO { + + @JSONField(name="categoryId") + @JsonProperty("categoryId") + private String categoryId; + + @JSONField(name="ids") + @JsonProperty("ids") + private List ids; + + @JSONField(name="jsonString") + @JsonProperty("jsonString") + private String jsonString; + +} 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 53280b6..87b617b 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 @@ -6,11 +6,13 @@ import com.storeroom.modules.archives.domain.ArchivesSummary; import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; import com.storeroom.modules.archives.service.ArchivesService; import com.storeroom.modules.archives.service.dto.ArchivesDTO; +import com.storeroom.modules.archives.service.dto.ArchivesFileDTO; import com.storeroom.modules.common.ArchivesTypeEnum; import com.storeroom.modules.dictionary.domain.ArchivesDictionary; import com.storeroom.modules.dictionary.domain.ArchivesType; import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository; import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository; +import com.storeroom.utils.ApiResponse; import com.storeroom.utils.NanoIdUtils; import com.storeroom.utils.PageUtil; import com.storeroom.utils.StringUtils; @@ -139,21 +141,21 @@ public class ArchivesServiceImpl implements ArchivesService { @Override @Transactional(rollbackFor = Exception.class) - public Object edit(ArchivesDTO dto) { + public ApiResponse edit(ArchivesDTO dto) { ArchivesSummary archivesSummary = new ArchivesSummary(); JSONObject json = new JSONObject(dto.getJsonString()); ArchivesType archivesType = archivesTypeRepository.findById(dto.getCategoryId()).get(); List showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(dto.getCategoryId(),true); List filedNameList = new ArrayList<>(); - String insertFiled = ""; - String insertValue = ""; + String insertFiled = "category_id,category_name,"; + String insertValue = "'"+dto.getCategoryId()+"','"+archivesType.getCnName()+"',"; String updateValue = ""; for(ArchivesDictionary archivesDictionary:showFiled){ filedNameList.add(archivesDictionary.getFieldName()); //是否必填 if(archivesDictionary.getIsRequired()){ if(null == json.get(archivesDictionary.getFieldName()) || "null".equals(json.get(archivesDictionary.getFieldName())) || "".equals(json.get(archivesDictionary.getFieldName()))){ - return archivesDictionary.getFieldName()+"不可为空!"; + return ApiResponse.error(50001,archivesDictionary.getFieldName()+"不可为空!"); } } //是否重复 @@ -167,7 +169,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 archivesDictionary.getFieldName()+"不可重复"; + return ApiResponse.error(50002,archivesDictionary.getFieldName()+"不可重复"); } } } @@ -251,12 +253,55 @@ public class ArchivesServiceImpl implements ArchivesService { archivesSummary.setCategoryName(archivesType.getCnName());//门类名称 archivesSummary.setCategoryType(archivesType.getIsType());//门类级别 archivesSummary.setArchivesTableName(archivesType.getEnName());//档案表名 + archivesSummary = archivesSummaryRepository.saveAndFlush(archivesSummary); } - return "成功更新"+result+"条数据。"; + return ApiResponse.success("成功更新"+result+"条数据。"); } @Override - public Object editFile(ArchivesDTO dto) { + public Object initArchiveFilesView(String categoryId,String archiveId) { + JSONObject json = new JSONObject(); + ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get(); + List queryShow = archivesDictionaryRepository.findAllByCategoryIdAndIsTypeOrderByIsSequenceAsc(categoryId,3); + json.put("queryShow",queryShow); + List fields = queryShow.stream().map(archivesDictionary -> { + return archivesDictionary.getFieldName(); + }).collect(Collectors.toList()); + fields.add("id"); + String queryFields = fields.stream().map(String::valueOf).collect(Collectors.joining(",")); + String sql = "select "+queryFields+" from file_"+archivesType.getEnName()+" where archive_id = '"+archiveId+"'"; + List list = entityManager.createNativeQuery(sql).getResultList(); + List returnlist = new ArrayList<>(); + for(Object[] objs:list){ + Map map = new HashMap(); + for(int i = 0;i queryShow = archivesDictionaryRepository.findAllByCategoryIdAndIsTypeOrderByIsSequenceAsc(dto.getCategoryId(),3); + JSONArray jsonArray = new JSONArray(dto.getJsonString()); + String archivesId = new JSONObject(jsonArray.get(0)).get("archive_id")+""; + List fields = queryShow.stream().map(archivesDictionary -> { + return archivesDictionary.getFieldName(); + }).collect(Collectors.toList()); + fields.add("id"); + for (Object obj:jsonArray){ + JSONObject json = new JSONObject(obj); + String insertValue = ""; + for(ArchivesDictionary archivesDictionary:queryShow){ + + } + + } return null; } 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 e752548..50502e8 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 @@ -14,6 +14,7 @@ public interface ArchivesDictionaryRepository extends JpaRepository findDisPlayField(String categoryId); + List findAllByCategoryIdAndIsTypeOrderByIsSequenceAsc(String categoryId,Integer isType); List findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(String categoryId, boolean isInput);