From ca3a6dab564d4274d2e0a69c5274cc2d3bb57839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8A=9B?= Date: Tue, 14 Jun 2022 20:11:08 +0800 Subject: [PATCH] commit code --- .../controller/ArchivesDisplayController.java | 38 +++++++++++++++++++ .../controller/ArchivesTypeController.java | 9 +++-- .../service/ArchivesDictionaryService.java | 2 +- .../service/ArchivesTypeService.java | 4 +- ...cDicSmallDTO.java => ArcTypeSmallDTO.java} | 6 +-- .../service/dto/ArchivesTypeDTO.java | 7 +++- .../service/impl/ArchivesDictionaryImpl.java | 15 +++++--- .../service/impl/ArchivesTypeServiceImpl.java | 17 ++++----- 8 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDisplayController.java rename archives/src/main/java/com/storeroom/modules/dictionary/service/dto/{ArcDicSmallDTO.java => ArcTypeSmallDTO.java} (67%) diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDisplayController.java b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDisplayController.java new file mode 100644 index 0000000..b17ceff --- /dev/null +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDisplayController.java @@ -0,0 +1,38 @@ +package com.storeroom.modules.dictionary.controller; + + +import com.storeroom.annotaion.rest.AnonymousPutMapping; +import com.storeroom.exception.BaseException; +import com.storeroom.exception.constant.ResponseStatus; +import com.storeroom.modules.dictionary.service.ArchivesDictionaryService; +import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; +import com.storeroom.utils.ApiResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(tags = "著录界面预览") +@RestController +@RequiredArgsConstructor +@RequestMapping("/arc-display/") +public class ArchivesDisplayController { + + private final ArchivesDictionaryService archivesDictionaryService; + + @ApiOperation("修改门类字典排序") + @AnonymousPutMapping("sort") + public ApiResponse ardicSort(@RequestBody List arcDicDto) { + if (arcDicDto.size() != 0 && arcDicDto.size() > 1) { + archivesDictionaryService.upSort(arcDicDto); + return ApiResponse.success(ResponseStatus.SUCCESS); + } + throw new BaseException("排序数据至少两条"); + + } + +} diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java index 26f0f1e..5ab3ab9 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java @@ -11,12 +11,11 @@ import com.storeroom.modules.common.ArchivesTypeEnum; import com.storeroom.modules.dictionary.service.ArchivesDictionaryService; import com.storeroom.modules.dictionary.service.ArchivesTypeService; import com.storeroom.modules.dictionary.service.DictionaryService; -import com.storeroom.modules.dictionary.service.dto.ArcDicSmallDTO; +import com.storeroom.modules.dictionary.service.dto.ArcTypeSmallDTO; import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; import com.storeroom.utils.ApiResponse; import com.storeroom.utils.StringUtils; -import com.storeroom.utils.ValidationUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -159,10 +158,12 @@ public class ArchivesTypeController { throw new BaseException("id异常"); } - @ApiOperation("修改排序") + @ApiOperation("修改门类菜单排序") @AnonymousPutMapping("sort") - public ApiResponse upSort(@Validated @RequestBody Set arcDicSmallDTO){ + public ApiResponse dicTypeSort(@Validated @RequestBody Set arcDicSmallDTO) { archivesTypeService.updateSort(arcDicSmallDTO); return ApiResponse.success(ResponseStatus.SUCCESS); } + + } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java index cfa0742..6aabaf7 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java @@ -57,7 +57,7 @@ public interface ArchivesDictionaryService { * @param archivesDictionaryDTO / * @return / */ - ArchivesDictionaryDTO upSort(ArchivesDictionaryDTO archivesDictionaryDTO); + List upSort(List archivesDictionaryDTO); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java index a0bd694..e4a0dd1 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java @@ -2,7 +2,7 @@ package com.storeroom.modules.dictionary.service; -import com.storeroom.modules.dictionary.service.dto.ArcDicSmallDTO; +import com.storeroom.modules.dictionary.service.dto.ArcTypeSmallDTO; import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; import java.util.List; @@ -42,7 +42,7 @@ public interface ArchivesTypeService { /** * */ - void updateSort(Set arcDicSmallDTO); + void updateSort(Set arcDicSmallDTO); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArcDicSmallDTO.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArcTypeSmallDTO.java similarity index 67% rename from archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArcDicSmallDTO.java rename to archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArcTypeSmallDTO.java index 8223af6..4fa0b41 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArcDicSmallDTO.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArcTypeSmallDTO.java @@ -1,18 +1,16 @@ package com.storeroom.modules.dictionary.service.dto; -import com.storeroom.base.BaseDTO; -import lombok.Data; import lombok.Getter; import lombok.Setter; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.List; + @Getter @Setter -public class ArcDicSmallDTO implements Serializable { +public class ArcTypeSmallDTO implements Serializable { @NotNull private String id; diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java index ee1d605..2cda9be 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java @@ -12,7 +12,7 @@ import java.util.Objects; @Getter @Setter -public class ArchivesTypeDTO extends BaseDTO implements Serializable { +public class ArchivesTypeDTO extends BaseDTO implements Serializable, Comparable { private String id; @@ -33,6 +33,11 @@ public class ArchivesTypeDTO extends BaseDTO implements Serializable { private String remark; + @Override + public int compareTo(ArchivesTypeDTO o) { + return this.getCategorySeq() + o.getCategorySeq(); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java index 5cb12ff..c307c44 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java @@ -107,12 +107,15 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { } @Override - public ArchivesDictionaryDTO upSort(ArchivesDictionaryDTO archivesDictionaryDTO) { - ArchivesDictionary archivesDictionary = archivesDictionaryMapper.toEntity(archivesDictionaryDTO); - ArchivesDictionary archivesDictionary1 = archivesDictionaryRepository.findById(archivesDictionary.getId()).orElseGet(ArchivesDictionary::new); - archivesDictionary1.setIsSequence(archivesDictionary.getIsSequence()); - archivesDictionaryRepository.save(archivesDictionary1); - return archivesDictionaryMapper.toDto(archivesDictionary1); + public List upSort(List archivesDictionaryDTO) { + List list = new ArrayList<>(); + for (ArchivesDictionaryDTO ar : archivesDictionaryDTO) { + ArchivesDictionary ad = archivesDictionaryRepository.findById(ar.getId()).orElseGet(ArchivesDictionary::new); + ad.setIsSequence(ar.getIsSequence()); + list.add(ad); + } + archivesDictionaryRepository.saveAll(list); + return null; } 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 40bf23c..6916b60 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 @@ -1,22 +1,19 @@ package com.storeroom.modules.dictionary.service.impl; import com.storeroom.exception.BaseException; -import com.storeroom.modules.dictionary.domain.ArchivesDictionary; import com.storeroom.modules.dictionary.domain.ArchivesType; import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository; import com.storeroom.modules.dictionary.service.ArchivesTypeService; import com.storeroom.modules.dictionary.service.DynamicTableService; -import com.storeroom.modules.dictionary.service.dto.ArcDicSmallDTO; +import com.storeroom.modules.dictionary.service.dto.ArcTypeSmallDTO; import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; import com.storeroom.modules.dictionary.service.mapstruct.ArchivesTypeMapper; import com.storeroom.utils.DateUtils; import com.storeroom.utils.NanoIdUtils; -import com.storeroom.utils.SpringUtils; import com.storeroom.utils.ValidationUtil; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,13 +32,11 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { private final DynamicTableService dynamicTableService; - - @Override @Transactional(rollbackFor = Exception.class) public void create(ArchivesTypeDTO archivesTypeDTO) { //#生成表名称 - String tableName="tb_"; + String tableName = "tb_"; ArchivesType archivesType = archivesTypeMapper.toEntity(archivesTypeDTO); List archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName()); if (archivesType1.size() == 0) { @@ -77,10 +72,14 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { ids.add(at.getId()); } } + if (archivesTypeDTO.getChildren() != null && archivesTypeDTO.getCategorySeq() != null) { + archivesTypeDTO.getChildren().sort(Comparator.reverseOrder()); + } } if (trees.size() == 0) { trees = archivesTypeDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList()); } + trees.sort(Comparator.reverseOrder()); return trees; } @@ -111,9 +110,9 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { } @Override - public void updateSort(Set arcDicSmallDTO) { + public void updateSort(Set arcDicSmallDTO) { List list = new ArrayList<>(); - for (ArcDicSmallDTO id : arcDicSmallDTO) { + for (ArcTypeSmallDTO id : arcDicSmallDTO) { ArchivesType ar = archivesTypeRepository.findById(id.getId()).orElseGet(ArchivesType::new); ar.setCategorySeq(id.getSort()); list.add(ar);