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 index b17ceff..504d4ff 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDisplayController.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDisplayController.java @@ -6,6 +6,7 @@ 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.modules.dictionary.service.dto.ArchivesDictionarySmallDTO; import com.storeroom.utils.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -19,19 +20,19 @@ import java.util.List; @Api(tags = "著录界面预览") @RestController @RequiredArgsConstructor -@RequestMapping("/arc-display/") +@RequestMapping("/api/arc-display/") public class ArchivesDisplayController { private final ArchivesDictionaryService archivesDictionaryService; @ApiOperation("修改门类字典排序") @AnonymousPutMapping("sort") - public ApiResponse ardicSort(@RequestBody List arcDicDto) { + public ApiResponse ardicSort(@RequestBody List arcDicDto) { if (arcDicDto.size() != 0 && arcDicDto.size() > 1) { archivesDictionaryService.upSort(arcDicDto); return ApiResponse.success(ResponseStatus.SUCCESS); } - throw new BaseException("排序数据至少两条"); + throw new BaseException("数据异常"); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java b/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java index 1f4494b..7c00fbf 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java @@ -1,20 +1,24 @@ package com.storeroom.modules.dictionary.domain; +import com.alibaba.fastjson.annotation.JSONField; import com.storeroom.base.BaseEntity; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; +import lombok.experimental.Accessors; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; +import java.util.List; import java.util.Objects; @Entity @Getter @Setter @Table(name = "archives_type") +@Accessors(chain = true) public class ArchivesType extends BaseEntity implements Serializable { @Id @@ -25,30 +29,43 @@ public class ArchivesType extends BaseEntity implements Serializable { @Column(name = "cn_name") @ApiModelProperty(value = "门类名称") + @JSONField(ordinal = 1) private String cnName; @Column(name = "en_name") @ApiModelProperty(value = "表名") + @JSONField(ordinal = 2) private String enName; @Column(name = "pid") @ApiModelProperty(value = "父类id") + @JSONField(ordinal = 3) private String pid; @Column(name = "is_type") @ApiModelProperty(value = "门类级别") + @JSONField(ordinal = 4) private Integer isType; - @Column(name = "is_type_metic") - @ApiModelProperty(value = "是否为模板档案") - private Boolean isTypeMetic; @Column(name = "category_seq") @ApiModelProperty(value = "排序") + @JSONField(ordinal = 5) private Integer categorySeq; + @Transient + @JSONField(ordinal = 6) + private List children; + + @Column(name = "is_type_metic") + @ApiModelProperty(value = "是否为模板档案") + @JSONField(ordinal = 7) + private Boolean isTypeMetic; + + @Column(name = "remark") @ApiModelProperty(value = "备注") + @JSONField(ordinal = 8) private String remark; @Override 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 6aabaf7..ff90180 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 @@ -3,6 +3,7 @@ package com.storeroom.modules.dictionary.service; import com.storeroom.modules.dictionary.domain.ArchivesDictionary; import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; +import com.storeroom.modules.dictionary.service.dto.ArchivesDictionarySmallDTO; import java.util.List; @@ -57,7 +58,7 @@ public interface ArchivesDictionaryService { * @param archivesDictionaryDTO / * @return / */ - List upSort(List archivesDictionaryDTO); + void 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 e4a0dd1..d595bd0 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,6 +2,7 @@ package com.storeroom.modules.dictionary.service; +import com.storeroom.modules.dictionary.domain.ArchivesType; import com.storeroom.modules.dictionary.service.dto.ArcTypeSmallDTO; import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; @@ -23,7 +24,7 @@ public interface ArchivesTypeService { * 构建菜单树 * @return */ - List buildTree(); + List buildTree(); /** * 修改门类类型 diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesDictionarySmallDTO.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesDictionarySmallDTO.java new file mode 100644 index 0000000..042508e --- /dev/null +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesDictionarySmallDTO.java @@ -0,0 +1,19 @@ +package com.storeroom.modules.dictionary.service.dto; + +import lombok.Getter; +import lombok.Setter; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + + +@Getter +@Setter +public class ArchivesDictionarySmallDTO implements Serializable { + + @NotNull + private String id; + + @NotNull + private Integer sort; +} 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 c307c44..592deb7 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 @@ -6,6 +6,7 @@ import com.storeroom.modules.dictionary.domain.ArchivesDictionary; import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository; import com.storeroom.modules.dictionary.service.ArchivesDictionaryService; import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; +import com.storeroom.modules.dictionary.service.dto.ArchivesDictionarySmallDTO; import com.storeroom.modules.dictionary.service.mapstruct.ArchivesDictionaryMapper; import com.storeroom.utils.NanoIdUtils; import com.storeroom.utils.ValidationUtil; @@ -107,15 +108,14 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { } @Override - public List upSort(List archivesDictionaryDTO) { + public void upSort(List archivesDictionaryDTO) { List list = new ArrayList<>(); - for (ArchivesDictionaryDTO ar : archivesDictionaryDTO) { + for (ArchivesDictionarySmallDTO ar : archivesDictionaryDTO) { ArchivesDictionary ad = archivesDictionaryRepository.findById(ar.getId()).orElseGet(ArchivesDictionary::new); - ad.setIsSequence(ar.getIsSequence()); + ad.setIsSequence(ar.getSort()); 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 6916b60..fd5001c 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 @@ -41,6 +41,10 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { List archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName()); if (archivesType1.size() == 0) { tableName += DateUtils.getNowDateTime(); + if (archivesType.getPid() == null) { + archivesType.setPid("0"); + } + archivesType.setPid("0"); archivesType.setId(NanoIdUtils.randomNanoId()); archivesType.setEnName(tableName); archivesTypeRepository.save(archivesType); @@ -51,36 +55,53 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { } } +// @Override +// public List buildTree() { +// List arcList = archivesTypeRepository.findAll(); +// List archivesTypeDTOS = archivesTypeMapper.toDto(arcList); +// List trees = new ArrayList<>(); +// Set ids = new HashSet<>(); +// for (ArchivesTypeDTO archivesTypeDTO : archivesTypeDTOS) { +// //如果父节点id为空就是一级菜单 +// if (archivesTypeDTO.getPid() == null) { +// //直接加入树列表 +// trees.add(archivesTypeDTO); +// } +// for (ArchivesTypeDTO at : archivesTypeDTOS) { +// if (archivesTypeDTO.getId().equals(at.getPid())) { +// if (archivesTypeDTO.getChildren() == null) { +// archivesTypeDTO.setChildren(new ArrayList<>()); +// } +// archivesTypeDTO.getChildren().add(at); +// 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; +// } + @Override - public List buildTree() { - List arcList = archivesTypeRepository.findAll(); - List archivesTypeDTOS = archivesTypeMapper.toDto(arcList); - List trees = new ArrayList<>(); - Set ids = new HashSet<>(); - for (ArchivesTypeDTO archivesTypeDTO : archivesTypeDTOS) { - //如果父节点id为空就是一级菜单 - if (archivesTypeDTO.getPid() == null) { - //直接加入树列表 - trees.add(archivesTypeDTO); - } - for (ArchivesTypeDTO at : archivesTypeDTOS) { - if (archivesTypeDTO.getId().equals(at.getPid())) { - if (archivesTypeDTO.getChildren() == null) { - archivesTypeDTO.setChildren(new ArrayList<>()); - } - archivesTypeDTO.getChildren().add(at); - 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; + public List buildTree() { + List list = archivesTypeRepository.findAll(); + + return list.stream().filter(item -> item.getPid().equals("0")) + .map(item -> item.setChildren(getChildren(item.getId(), list))) + .sorted(Comparator.comparingInt(menu -> (menu.getCategorySeq() == null ? 0 : menu.getCategorySeq()))) + .collect(Collectors.toList()); + } + + private List getChildren(String id, List list) { + return list.stream().filter(item -> item.getPid().equals(id)) + .map(item -> item.setChildren(getChildren(item.getId(), list))) + .sorted(Comparator.comparingInt(menu -> (menu.getCategorySeq() == null ? 0 : menu.getCategorySeq()))) + .collect(Collectors.toList()); } @Override