lyh
2025-03-19 ed839069a1df066d9559263129e999de7e9c2ccc
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
package org.jeecg.modules.dnc.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.entity.ProductMix;
import org.jeecg.modules.dnc.mapper.ProductMixMapper;
import org.jeecg.modules.dnc.service.IPermissionStreamNewService;
import org.jeecg.modules.dnc.service.IProductMixService;
import org.jeecg.modules.dnc.utils.TreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
@Service
public class ProductMixServiceImpl extends ServiceImpl<ProductMixMapper, ProductMix> implements IProductMixService {
 
    @Autowired
    private IPermissionStreamNewService permissionStreamNewService;
 
    @Override
    public List<ProductMix> getTree() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<ProductMix> rawData = new ArrayList<>();
        if (loginUser.getUsername().equals("admin")) {
            //不需要权限过滤
            rawData=permissionStreamNewService.loadProductMixAll(loginUser.getId());
        }else{
            //需要权限过滤
            String productIds = loginUser.getProductionIds();
            List<String> productIdList = Arrays.asList(productIds.split(","));
            rawData = permissionStreamNewService.loadProductMix(loginUser.getId(),productIdList);
        }
        TreeBuilder builder = new TreeBuilder();
        TreeBuilder.CleanResult cleanResult = builder.preprocessData(rawData);
        List<ProductMix> sorted = builder.topologicalSort(
                cleanResult.getValidNodes(),
                cleanResult.getNodeMap()
        );
        List<ProductMix> result =builder.assembleTree(sorted, cleanResult.getNodeMap());
        result.sort(Comparator.comparing(ProductMix::getCreateTime, Comparator.nullsLast(Date::compareTo)));
        return result;
    }
}