|
@@ -1,16 +1,19 @@
|
|
|
package cn.efunbox.manage.base.service.impl;
|
|
|
|
|
|
+import cn.efunbox.manage.base.entity.Department;
|
|
|
import cn.efunbox.manage.base.entity.Product;
|
|
|
+import cn.efunbox.manage.base.entity.Project;
|
|
|
import cn.efunbox.manage.base.enums.BaseStatusEnum;
|
|
|
+import cn.efunbox.manage.base.repository.DepartmentRepository;
|
|
|
import cn.efunbox.manage.base.repository.ProductRepository;
|
|
|
+import cn.efunbox.manage.base.repository.ProjectRepository;
|
|
|
import cn.efunbox.manage.base.service.ProductService;
|
|
|
import cn.efunbox.manage.common.result.ApiCode;
|
|
|
import cn.efunbox.manage.common.result.ApiResult;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* ProductServiceImpl
|
|
@@ -22,9 +25,39 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
ProductRepository productRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ProjectRepository projectRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DepartmentRepository departmentRepository;
|
|
|
+
|
|
|
@Override
|
|
|
public ApiResult list(Product product) {
|
|
|
List<Product> products = productRepository.findByStatusOrderBySortDesc(BaseStatusEnum.NORMAL);
|
|
|
+ List<Long> deptIds = new ArrayList<>();
|
|
|
+ List<Long> projectIds = new ArrayList<>();
|
|
|
+ products.stream().forEach(p -> {
|
|
|
+ deptIds.add(p.getDeptId());
|
|
|
+ projectIds.add(p.getProjectId());
|
|
|
+ });
|
|
|
+ List<Project> projects = projectRepository.findByIds(projectIds);
|
|
|
+ List<Department> departments = departmentRepository.findByIds(deptIds);
|
|
|
+
|
|
|
+ Map<Long, Project> projectMap = new HashMap<>();
|
|
|
+ Map<Long, Department> departmentMap = new HashMap<>();
|
|
|
+
|
|
|
+ projects.stream().forEach(p -> {
|
|
|
+ projectMap.put(p.getId(), p);
|
|
|
+ });
|
|
|
+ departments.stream().forEach(p -> {
|
|
|
+ departmentMap.put(p.getId(), p);
|
|
|
+ });
|
|
|
+
|
|
|
+ products.stream().forEach(p -> {
|
|
|
+ p.setProject(projectMap.get(p.getProjectId()));
|
|
|
+ p.setDepartment(departmentMap.get(p.getDeptId()));
|
|
|
+ });
|
|
|
+
|
|
|
if(Objects.nonNull(products)){
|
|
|
return ApiResult.ok(products);
|
|
|
}
|
|
@@ -66,4 +99,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
return ApiResult.ok(product);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResult getSelect(){
|
|
|
+ return ApiResult.ok(productRepository.findByStatusOrderBySortDesc(BaseStatusEnum.NORMAL));
|
|
|
+ }
|
|
|
}
|