shiyunteng
2 天以前 96119ca3973d5ea643db6a87b6a23fe404ddb8cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.by4cloud.platformx.business.service.impl;
 
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by4cloud.platformx.business.dto.ProductQueryDTO;
import com.by4cloud.platformx.business.entity.Product;
import com.by4cloud.platformx.business.mapper.ProductMapper;
import com.by4cloud.platformx.business.service.ProductService;
import com.by4cloud.platformx.business.vo.ProductSelectVo;
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.data.datascope.DataScope;
import jakarta.validation.constraints.NotNull;
import org.springframework.stereotype.Service;
 
 
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
 
/**
 * 产品信息
 *
 * @author platformx
 * @date 2026-05-07 10:17:52
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Override
    public List<Tree<Long>> treeList() {
        List<TreeNode<Long>> collect = baseMapper
                .selectListByScope(Wrappers.<Product>lambdaQuery()
                        .orderByAsc(Product::getCreateTime), DataScope.of("comp_id"))
                .stream().map(getNodeFunction()).collect(Collectors.toList());
 
        // 模糊查询 不组装树结构 直接返回 表格方便编辑
//        if (StrUtil.isNotBlank(productName)) {
//            return collect.stream().map(node -> {
//                Tree<Long> tree = new Tree<>();
//                tree.putAll(node.getExtra());
//                BeanUtils.copyProperties(node, tree);
//                return tree;
//            }).collect(Collectors.toList());
//        }
        TreeNode<Long> parent = new TreeNode<>();
        parent.setId(0L);
        parent.setName("目录");
        parent.setParentId(-1L);
        collect.add(parent);
        return TreeUtil.build(collect, 0L);
    }
 
    @Override
    public List<ProductSelectVo> getProductList(Product product) {
        return baseMapper.getProductListByScope(product,DataScope.of("comp_id"));
    }
 
 
    @NotNull
    private Function<Product, TreeNode<Long>> getNodeFunction() {
        return product -> {
            TreeNode<Long> node = new TreeNode<>();
            node.setId(product.getId());
            node.setName(product.getProductName());
            node.setParentId(product.getParentId());
            //node.setWeight(product.getParentId());
            // 扩展属性
//            Map<String, Object> extra = new HashMap<>();
//            extra.put("picPath", category.getPicPath());
//            extra.put("Type", category.getType());
//            extra.put("isShow", category.getIsShow());
//            extra.put("iconPicPath", category.getIconPath());
//            extra.put("status", category.getStatus());
 
            // 适配 vue3
//            Map<String, Object> meta = new HashMap<>();
           /* meta.put("title", product.getProductName());
            meta.put("icon", product.getPrice());*/
 
            //extra.put("meta", meta);
            //node.setExtra(extra);
            return node;
        };
    }
 
    @Override
    public R getProductListByParentId(ProductQueryDTO queryDTO) {
        String[] erpCodes = new String[]{"房租租赁","dianli","water"};
//        MPJLambdaWrapper<Product> wrapper = new MPJLambdaWrapper<Product>()
//                .selectAs("( SELECT count(1) FROM product t1 WHERE t1.parent_id = t.id )",Product::getChildNum)
//                .selectAll(Product.class)
//                .like(StrUtil.isNotEmpty(queryDTO.getProductName()),Product::getProductName,queryDTO.getProductName())
//                .eq(StrUtil.isNotEmpty(queryDTO.getParentId()),Product::getParentId,queryDTO.getParentId())
//                .in(StrUtil.isNotEmpty(queryDTO.getContractCategory())&&StrUtil.equals(queryDTO.getContractCategory(), "water_house"),
//                        Product::getErpCode,erpCodes);
        List<ProductSelectVo> selectVos = baseMapper.getProductListByParentId(queryDTO, Arrays.asList(erpCodes),DataScope.of("comp_id"));
        if (selectVos.size()>2000){
            return R.ok(selectVos.subList(0,1999));
        }
        return R.ok(selectVos);
    }
}