Browse Source

commit code

master
刘力 3 years ago
parent
commit
618482d9bb
  1. 7
      archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDisplayController.java
  2. 23
      archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java
  3. 3
      archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java
  4. 3
      archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java
  5. 19
      archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesDictionarySmallDTO.java
  6. 8
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java
  7. 77
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java

7
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<Object> ardicSort(@RequestBody List<ArchivesDictionaryDTO> arcDicDto) {
public ApiResponse<Object> ardicSort(@RequestBody List<ArchivesDictionarySmallDTO> arcDicDto) {
if (arcDicDto.size() != 0 && arcDicDto.size() > 1) {
archivesDictionaryService.upSort(arcDicDto);
return ApiResponse.success(ResponseStatus.SUCCESS);
}
throw new BaseException("排序数据至少两条");
throw new BaseException("数据异常");
}

23
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<ArchivesType> 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

3
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<ArchivesDictionaryDTO> upSort(List<ArchivesDictionaryDTO> archivesDictionaryDTO);
void upSort(List<ArchivesDictionarySmallDTO> archivesDictionaryDTO);
}

3
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<ArchivesTypeDTO> buildTree();
List<ArchivesType> buildTree();
/**
* 修改门类类型

19
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;
}

8
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<ArchivesDictionaryDTO> upSort(List<ArchivesDictionaryDTO> archivesDictionaryDTO) {
public void upSort(List<ArchivesDictionarySmallDTO> archivesDictionaryDTO) {
List<ArchivesDictionary> 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;
}

77
archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java

@ -41,6 +41,10 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
List<ArchivesType> 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<ArchivesTypeDTO> buildTree() {
// List<ArchivesType> arcList = archivesTypeRepository.findAll();
// List<ArchivesTypeDTO> archivesTypeDTOS = archivesTypeMapper.toDto(arcList);
// List<ArchivesTypeDTO> trees = new ArrayList<>();
// Set<String> 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<ArchivesTypeDTO> buildTree() {
List<ArchivesType> arcList = archivesTypeRepository.findAll();
List<ArchivesTypeDTO> archivesTypeDTOS = archivesTypeMapper.toDto(arcList);
List<ArchivesTypeDTO> trees = new ArrayList<>();
Set<String> 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());
public List<ArchivesType> buildTree() {
List<ArchivesType> 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());
}
trees.sort(Comparator.reverseOrder());
return trees;
private List<ArchivesType> getChildren(String id, List<ArchivesType> 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

Loading…
Cancel
Save