From 4ac4b1505f60088e59d78d999205377a8f170ca2 Mon Sep 17 00:00:00 2001
From: chenrui <1187576398@qq.com>
Date: 星期二, 25 三月 2025 13:56:27 +0800
Subject: [PATCH] 标准库树查询修改
---
basic-server/src/main/java/com/ruoyi/basic/mapper/ModelMapper.java | 7 +
basic-server/src/main/java/com/ruoyi/basic/service/StandardTreeService.java | 3
basic-server/src/main/java/com/ruoyi/basic/dto/BasicTreeDto.java | 29 ++++
basic-server/src/main/java/com/ruoyi/basic/enums/TestPorjectTypeEnums.java | 44 +++++++
basic-server/src/main/java/com/ruoyi/basic/pojo/Model.java | 42 +++++++
basic-server/src/main/java/com/ruoyi/basic/enums/BasicTreeEnums.java | 37 ++++++
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java | 187 +++++++++++++++++++++++++-----
basic-server/src/main/java/com/ruoyi/basic/dto/StructureTestObjectDto.java | 9 +
8 files changed, 319 insertions(+), 39 deletions(-)
diff --git a/basic-server/src/main/java/com/ruoyi/basic/dto/BasicTreeDto.java b/basic-server/src/main/java/com/ruoyi/basic/dto/BasicTreeDto.java
new file mode 100644
index 0000000..1c62cf3
--- /dev/null
+++ b/basic-server/src/main/java/com/ruoyi/basic/dto/BasicTreeDto.java
@@ -0,0 +1,29 @@
+package com.ruoyi.basic.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.util.List;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString(exclude = {"children"})
+public class BasicTreeDto {
+
+ /**
+ * 灞傜骇
+ */
+ private String level;
+
+ private String label;
+
+ private String value;
+
+ /**
+ * 瀛愯妭鐐�
+ */
+ private List<BasicTreeDto> children;
+}
diff --git a/basic-server/src/main/java/com/ruoyi/basic/dto/StructureTestObjectDto.java b/basic-server/src/main/java/com/ruoyi/basic/dto/StructureTestObjectDto.java
index 3d278ba..2aa9a4f 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/dto/StructureTestObjectDto.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/dto/StructureTestObjectDto.java
@@ -1,15 +1,18 @@
package com.ruoyi.basic.dto;
+import com.ruoyi.basic.pojo.StructureTestObject;
import lombok.Data;
-@Data
-public class StructureTestObjectDto {
+import java.util.List;
- private Integer id;
+@Data
+public class StructureTestObjectDto extends StructureTestObject {
private String name;
private Integer workShopId;
private String workShopName;
+
+ private List<BasicTreeDto> children;
}
diff --git a/basic-server/src/main/java/com/ruoyi/basic/enums/BasicTreeEnums.java b/basic-server/src/main/java/com/ruoyi/basic/enums/BasicTreeEnums.java
new file mode 100644
index 0000000..fd17957
--- /dev/null
+++ b/basic-server/src/main/java/com/ruoyi/basic/enums/BasicTreeEnums.java
@@ -0,0 +1,37 @@
+package com.ruoyi.basic.enums;
+
+public enum BasicTreeEnums {
+
+ FACTORY_TYPE("1","鍏徃"),
+ LABORATORY_TYPE("2","瀹為獙瀹�"),
+ MATERIAL_TYPE("3","鏉愭枡"),
+ WORK_SHOP_TYPE("4","杞﹂棿"),
+ STRUCTURE_TEST_OBJECT_TYPE("5","妫�楠屽璞�"),
+ PRODUCT_TYPE("6","浜у搧"),
+ MODEL_TYPE("7","鍨嬪彿");
+
+ private String code;
+
+ private String name;
+
+ BasicTreeEnums(String code, String name) {
+ this.code = code;
+ this.name = name;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/basic-server/src/main/java/com/ruoyi/basic/enums/TestPorjectTypeEnums.java b/basic-server/src/main/java/com/ruoyi/basic/enums/TestPorjectTypeEnums.java
new file mode 100644
index 0000000..01b0848
--- /dev/null
+++ b/basic-server/src/main/java/com/ruoyi/basic/enums/TestPorjectTypeEnums.java
@@ -0,0 +1,44 @@
+package com.ruoyi.basic.enums;
+
+public enum TestPorjectTypeEnums {
+
+ RAW_MATERIALS("1","鍘熻緟鏂�"),
+ FINISHED_PRODUCT("2","鎴愬搧"),
+ SEMI_FINISHED_PRODUCT("3","鍗婃垚鍝�"),
+ PURCHASED_PART("4","澶栬喘浠�"),
+ PACKAGING_MATERIALS("5","鍖呮潗");
+
+ private String code;
+
+ private String name;
+
+ TestPorjectTypeEnums(String code, String name) {
+ this.code = code;
+ this.name = name;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public static String getNameByCode(String code) {
+ for (TestPorjectTypeEnums type : TestPorjectTypeEnums.values()) {
+ if (type.getCode().equals(code)) {
+ return type.getName();
+ }
+ }
+ return "";
+ }
+}
diff --git a/basic-server/src/main/java/com/ruoyi/basic/mapper/ModelMapper.java b/basic-server/src/main/java/com/ruoyi/basic/mapper/ModelMapper.java
new file mode 100644
index 0000000..ddebefa
--- /dev/null
+++ b/basic-server/src/main/java/com/ruoyi/basic/mapper/ModelMapper.java
@@ -0,0 +1,7 @@
+package com.ruoyi.basic.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.basic.pojo.Model;
+
+public interface ModelMapper extends BaseMapper<Model> {
+}
diff --git a/basic-server/src/main/java/com/ruoyi/basic/pojo/Model.java b/basic-server/src/main/java/com/ruoyi/basic/pojo/Model.java
new file mode 100644
index 0000000..f28cf67
--- /dev/null
+++ b/basic-server/src/main/java/com/ruoyi/basic/pojo/Model.java
@@ -0,0 +1,42 @@
+package com.ruoyi.basic.pojo;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@TableName(value = "model")
+@Data
+public class Model {
+
+ @ApiModelProperty(value = "涓婚敭")
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+
+ @ApiModelProperty(value = "鍨嬪彿鍚嶇О")
+ private String modelName;
+
+ @ApiModelProperty(value = "浜у搧ID")
+ private Integer productId;
+
+ @ApiModelProperty(value = "妫�楠屽璞D")
+ private Integer structureTestObjectId;
+
+ @ApiModelProperty(value = "鍒涘缓浜�")
+ @TableField(fill = FieldFill.INSERT)
+ private Integer createUser;
+
+ @ApiModelProperty(value = "淇敼浜篿d")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private Integer updateUser;
+
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime updateTime;
+
+ @TableField(fill = FieldFill.INSERT)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime createTime;
+}
diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/StandardTreeService.java b/basic-server/src/main/java/com/ruoyi/basic/service/StandardTreeService.java
index 0ad0f47..a7812b5 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/StandardTreeService.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/StandardTreeService.java
@@ -1,6 +1,7 @@
package com.ruoyi.basic.service;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.basic.dto.BasicTreeDto;
import com.ruoyi.basic.dto.FactoryDto;
import com.ruoyi.basic.dto.SampleTypeDto;
import com.ruoyi.basic.pojo.StandardTree;
@@ -16,7 +17,7 @@
*/
public interface StandardTreeService extends IService<StandardTree> {
- List<FactoryDto> selectStandardTreeList();
+ List<BasicTreeDto> selectStandardTreeList();
int addStandardTree(StandardTree standardTree);
diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java
index 29c4b90..4b99a25 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java
@@ -3,29 +3,25 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.basic.dto.SampleDto;
+import com.ruoyi.basic.dto.*;
+import com.ruoyi.basic.enums.BasicTreeEnums;
+import com.ruoyi.basic.enums.TestPorjectTypeEnums;
+import com.ruoyi.basic.mapper.*;
+import com.ruoyi.basic.pojo.*;
import com.ruoyi.common.exception.base.BaseException;
-import com.ruoyi.basic.dto.FactoryDto;
-import com.ruoyi.basic.dto.LaboratoryDto;
-import com.ruoyi.basic.dto.SampleTypeDto;
-import com.ruoyi.basic.mapper.StandardProductListMapper;
-import com.ruoyi.basic.mapper.StandardTreeMapper;
-import com.ruoyi.basic.pojo.StandardProductList;
-import com.ruoyi.basic.pojo.StandardTemplate;
-import com.ruoyi.basic.pojo.StandardTree;
-import com.ruoyi.basic.pojo.StructureTestObject;
import com.ruoyi.basic.service.*;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@@ -57,42 +53,163 @@
private StructureTestObjectService structureTestObjectService;
+ private StructureTestObjectMapper structureTestObjectMapper;
+
+ private ProductMapper productMapper;
+
+ private ModelMapper modelMapper;
+
+ private LaboratoryMapper laboratoryMapper;
+
+ private WorkShopMapper workShopMapper;
+
@Override
- public List<FactoryDto> selectStandardTreeList() {
- List<FactoryDto> factoryDtos = standardTreeMapper.selectStandardTreeList();
- // 鏀堕泦鎵�鏈� sampleTypeDto 鐨� value
- Set<String> sampleTypeValues = new HashSet<>();
- for (FactoryDto factoryDto : factoryDtos) {
- for (LaboratoryDto laboratoryDto : factoryDto.getChildren()) {
- laboratoryDto.getChildren().sort((o1, o2) -> (o1.getSort() == null ? 0 : o1.getSort())
- - (o2.getSort() == null ? 0 : o2.getSort()));
- for (SampleTypeDto sampleTypeDto : laboratoryDto.getChildren()) {
- sampleTypeValues.add(sampleTypeDto.getValue());
+ public List<BasicTreeDto> selectStandardTreeList() {
+ // 鏌ヨ鎵�鏈夋鏌ュ璞�
+ List<StructureTestObject> structureTestObjectList = structureTestObjectMapper.selectList(new QueryWrapper<StructureTestObject>());
+ // 鏌ヨ鎵�鏈変骇鍝�
+ List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>());
+ // 鏌ヨ鎵�鏈夊瀷鍙�
+ List<Model> modelList = modelMapper.selectList(new QueryWrapper<Model>());
+ // 鎸夌収褰掑睘浜у搧id杩樻槸褰掑睘妫�娴嬪璞d灏嗗瀷鍙峰垎缁勫苟缁勮鎴怋asicTreeDto
+ Map<Integer, List<BasicTreeDto>> productModelMap = new HashMap<>();
+ Map<Integer, List<BasicTreeDto>> testObjectModelMap = new HashMap<>();
+ for (Model model : modelList) {
+ BasicTreeDto basicTreeDto = new BasicTreeDto();
+ basicTreeDto.setLevel(BasicTreeEnums.MODEL_TYPE.getCode());
+ basicTreeDto.setValue(String.valueOf(model.getId()));
+ basicTreeDto.setLabel(model.getModelName());
+ basicTreeDto.setChildren(null);
+ if(model.getProductId() != null) {
+ if(CollectionUtils.isEmpty(productModelMap.get(model.getProductId()))){
+ List<BasicTreeDto> basicTreeDtoList = new ArrayList<>();
+ basicTreeDtoList.add(basicTreeDto);
+ productModelMap.put(model.getProductId(),basicTreeDtoList);
+ }else {
+ productModelMap.get(model.getProductId()).add(basicTreeDto);
+ }
+ }
+ if(model.getStructureTestObjectId() != null) {
+ if(CollectionUtils.isEmpty(productModelMap.get(model.getStructureTestObjectId()))){
+ List<BasicTreeDto> basicTreeDtoList = new ArrayList<>();
+ basicTreeDtoList.add(basicTreeDto);
+ testObjectModelMap.put(model.getStructureTestObjectId(),basicTreeDtoList);
+ }else {
+ testObjectModelMap.get(model.getStructureTestObjectId()).add(basicTreeDto);
}
}
}
- // 鎵归噺鏌ヨ鎵�鏈� sampleTypeDto 鐨勬暟鎹�
- List<SampleDto> standardList = standardTreeMapper.getStandardTree3Batch(sampleTypeValues);
- Map<String, List<SampleDto>> standardTreeMap = standardList.stream().collect(Collectors.groupingBy(SampleDto::getValue));
- // 灏嗘煡璇㈢粨鏋滃垎閰嶅埌瀵瑰簲鐨� sampleTypeDto
- for (FactoryDto factoryDto : factoryDtos) {
- for (LaboratoryDto laboratoryDto : factoryDto.getChildren()) {
- for (SampleTypeDto sampleTypeDto : laboratoryDto.getChildren()) {
- List<SampleDto> standardTreeList = standardTreeMap.get(sampleTypeDto.getValue());
- if (standardTreeList != null) {
- sampleTypeDto.getChildren().addAll(standardTreeList);
+ // 鎸夌収妫�娴嬪璞d灏嗕骇鍝佸垎缁勫苟缁勮鎴怋asicTreeDto
+ Map<Integer, List<BasicTreeDto>> productMap = productList.stream().collect(Collectors.groupingBy(
+ Product::getObjectId,
+ Collectors.mapping(product -> {
+ BasicTreeDto basicTreeDto = new BasicTreeDto();
+ basicTreeDto.setValue(String.valueOf(product.getId()));
+ basicTreeDto.setLabel(product.getName());
+ basicTreeDto.setLevel(BasicTreeEnums.PRODUCT_TYPE.getCode());
+ basicTreeDto.setChildren(productModelMap.get(product.getId()));
+ return basicTreeDto;
+ }, Collectors.toList())
+ ));
+ // 瀵规娴嬪璞″厛鎸夌収瀹為獙瀹ゅ湪鎸夌収妫�鏌ュ璞$被鍒垎绫�
+ Map<Integer, Map<String, List<StructureTestObjectDto>>> laboratoryObjectTypeMap = structureTestObjectList.stream().collect(
+ Collectors.groupingBy(
+ StructureTestObject::getLaboratoryId,
+ Collectors.groupingBy(
+ StructureTestObject::getObjectType,
+ Collectors.mapping(structureTestObject -> {
+ StructureTestObjectDto structureTestObjectDto = new StructureTestObjectDto();
+ BeanUtils.copyProperties(structureTestObject, structureTestObjectDto);
+ List<BasicTreeDto> children = new ArrayList<>();
+ if(!CollectionUtils.isEmpty(productMap.get(structureTestObject.getId()))){
+ children.addAll(productMap.get(structureTestObject.getId()));
+ }
+ if(!CollectionUtils.isEmpty(testObjectModelMap.get(structureTestObject.getId()))){
+ children.addAll(testObjectModelMap.get(structureTestObject.getId()));
+ }
+ structureTestObjectDto.setChildren(children);
+ return structureTestObjectDto;
+ },Collectors.toList())
+ )
+ )
+ );
+ // 鏌ヨ杞﹂棿
+ List<WorkShop> workShopList = workShopMapper.selectList(new LambdaQueryWrapper<WorkShop>());
+ // 鏌ヨ瀹為獙瀹�
+ List<Laboratory> laboratoryList = laboratoryMapper.selectList(new QueryWrapper<Laboratory>());
+ // 灏佽瀹為獙瀹ゆ爲
+ List<BasicTreeDto> laboratoryTreeDtoList = laboratoryList.stream().map(laboratory -> {
+ BasicTreeDto laboratoryTreeDto = new BasicTreeDto();
+ laboratoryTreeDto.setValue(String.valueOf(laboratory.getId()));
+ laboratoryTreeDto.setLevel(BasicTreeEnums.LABORATORY_TYPE.getCode());
+ laboratoryTreeDto.setLabel(laboratory.getLaboratoryName());
+ // 灏佽妫�娴嬪璞℃潗鏂欑被鍨嬫爲
+ List<BasicTreeDto> objectTypeChildren = new ArrayList<>();
+ Map<String, List<StructureTestObjectDto>> objectTypeMap = laboratoryObjectTypeMap.get(laboratory.getId());
+ if (!CollectionUtils.isEmpty(objectTypeMap)) {
+ for (String objectType : objectTypeMap.keySet()) {
+ BasicTreeDto objectTypeBasicTreeDto = new BasicTreeDto();
+ objectTypeBasicTreeDto.setValue(objectType);
+ objectTypeBasicTreeDto.setLevel(BasicTreeEnums.MATERIAL_TYPE.getCode());
+ objectTypeBasicTreeDto.setLabel(TestPorjectTypeEnums.getNameByCode(objectType));
+ List<StructureTestObjectDto> structureTestObjectTypeList = objectTypeMap.get(objectType);
+ if (CollectionUtils.isEmpty(structureTestObjectTypeList)) {
+ continue;
}
+ // 灏佽杞﹂棿鏍�
+ if (objectType.equals("1") || objectType.equals("5")) {
+ List<BasicTreeDto> workShopTreeDtoList = new ArrayList<>();
+ for (WorkShop workShop : workShopList) {
+ BasicTreeDto workShopTreeDto = new BasicTreeDto();
+ workShopTreeDto.setLevel(BasicTreeEnums.WORK_SHOP_TYPE.getCode());
+ workShopTreeDto.setValue(String.valueOf(workShop.getId()));
+ workShopTreeDto.setLabel(workShop.getName());
+ List<BasicTreeDto> testObjectChildren = new ArrayList<>();
+ // 灏佽妫�娴嬪璞℃爲
+ for (StructureTestObjectDto structureTestObjectDto : structureTestObjectTypeList) {
+ if (workShop.getId().equals(structureTestObjectDto.getWorkShopId())) {
+ BasicTreeDto testObjectTreeDto = new BasicTreeDto();
+ testObjectTreeDto.setLevel(BasicTreeEnums.STRUCTURE_TEST_OBJECT_TYPE.getCode());
+ testObjectTreeDto.setValue(String.valueOf(structureTestObjectDto.getId()));
+ testObjectTreeDto.setLabel(structureTestObjectDto.getSpecimenName());
+ testObjectTreeDto.setChildren(structureTestObjectDto.getChildren());
+ testObjectChildren.add(testObjectTreeDto);
+ }
+ }
+ workShopTreeDto.setChildren(testObjectChildren);
+ if(!CollectionUtils.isEmpty(testObjectChildren)){
+ workShopTreeDtoList.add(workShopTreeDto);
+ }
+ }
+ objectTypeBasicTreeDto.setChildren(workShopTreeDtoList);
+ }
+ // 灏佽妫�娴嬪璞℃爲
+ if (objectType.equals("2") || objectType.equals("3") || objectType.equals("4")) {
+ objectTypeBasicTreeDto.setChildren(structureTestObjectTypeList.stream().map(structureTestObjectDto -> {
+ BasicTreeDto testObjectBasicTreeDto = new BasicTreeDto(BasicTreeEnums.STRUCTURE_TEST_OBJECT_TYPE.getCode(),
+ structureTestObjectDto.getSpecimenName(),
+ String.valueOf(structureTestObjectDto.getId()),
+ structureTestObjectDto.getChildren());
+ return testObjectBasicTreeDto;
+ }).collect(Collectors.toList()));
+ }
+ objectTypeChildren.add(objectTypeBasicTreeDto);
}
}
- }
- return factoryDtos;
+ laboratoryTreeDto.setChildren(objectTypeChildren);
+ return laboratoryTreeDto;
+ }).collect(Collectors.toList());
+ List<BasicTreeDto> factoryList = new ArrayList<>();
+ factoryList.add(new BasicTreeDto(BasicTreeEnums.FACTORY_TYPE.getCode(),"涓ぉ绉戞妧","1",laboratoryTreeDtoList));
+ return laboratoryTreeDtoList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int addStandardTree(StandardTree standardTree) {
+
LambdaQueryWrapper<StandardTree> wrapper = Wrappers.<StandardTree>lambdaQuery()
.eq(StandardTree::getFactory, standardTree.getFactory())
.eq(StandardTree::getLaboratory, standardTree.getLaboratory())
@@ -449,7 +566,7 @@
.eq(StandardProductList::getSample, standardTree.getSample())
.eq(StandardProductList::getSampleType, standardTree.getSampleType())
.eq(StandardProductList::getModel, standardTree.getOldModel()));
- if (CollectionUtils.isNotEmpty(standardProductLists)) {
+ if (!CollectionUtils.isEmpty(standardProductLists)) {
for (StandardProductList standardProductList : standardProductLists) {
// 淇敼鏍峰搧鍚嶇О
standardProductList.setModel(standardTree.getModel());
--
Gitblit v1.9.3