lyh
2025-04-11 2cf1565485060fd56e1f1f1cffbba7a4d70d42a6
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductMixServiceImpl.java
@@ -1,9 +1,7 @@
package org.jeecg.modules.dnc.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.entity.ProductMix;
import org.jeecg.modules.dnc.mapper.ProductMixMapper;
@@ -12,7 +10,8 @@
import org.jeecg.modules.dnc.utils.TreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.*;
@Service
public class ProductMixServiceImpl extends ServiceImpl<ProductMixMapper, ProductMix> implements IProductMixService {
@@ -20,16 +19,33 @@
    @Autowired
    private IPermissionStreamNewService permissionStreamNewService;
    /**
     * 默认结构树查询
     * @return
     */
    @Override
    public List<ProductMix> getTree() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<ProductMix> rawData = permissionStreamNewService.loadProductMix(loginUser.getId());
        List<ProductMix> rawData = new ArrayList<>();
        if (loginUser.getUsername().equals("admin")) {
            //不需要权限过滤
            rawData=permissionStreamNewService.loadProductMixAll(loginUser.getId());
        }else{
            //需要权限过滤
            String productIds = loginUser.getProductionIds();
            if (productIds != null && !productIds.isEmpty()) {
                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()
        );
        return builder.assembleTree(sorted, cleanResult.getNodeMap());
        List<ProductMix> result =builder.assembleTree(sorted, cleanResult.getNodeMap());
        result.sort(Comparator.comparing(ProductMix::getCreateTime, Comparator.nullsLast(Date::compareTo)));
        return result;
    }
}
}