hyingbo
7 天以前 cc0e9036de6e922e8fe254fef01d8de9996024b7
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
@@ -1,37 +1,39 @@
package org.jeecg.modules.dnc.service.impl;
import com.alibaba.fastjson.JSONObject;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.constant.DocAttributionTypeEnum;
import org.jeecg.modules.dnc.dto.ComponentExt;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.dnc.exception.ExceptionCast;
import org.jeecg.modules.dnc.mapper.ComponentInfoMapper;
import org.jeecg.modules.dnc.mapper.ProductInfoMapper;
import org.jeecg.modules.dnc.request.DocInfoQueryRequest;
import org.jeecg.modules.dnc.request.TreeInfoRequest;
import org.jeecg.modules.dnc.response.CommonCode;
import org.jeecg.modules.dnc.response.ComponentInfoCode;
import org.jeecg.modules.dnc.response.ProductInfoCode;
import org.jeecg.modules.dnc.response.UcenterCode;
import org.jeecg.modules.dnc.service.*;
import org.jeecg.modules.dnc.ucenter.Department;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.dnc.entity.ComponentInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ComponentInfoSeServiceImpl extends ServiceImpl<ComponentInfoMapper, ComponentInfo> implements IComponentInfoService {
@@ -40,19 +42,29 @@
    @Autowired
    public ProductInfoMapper productInfoMapper;
    @Autowired
    private IPermissionStreamService permissionStreamService;
    private IPermissionStreamNewService permissionStreamNewService;
    @Autowired
    private IComponentDepartmentService componentDepartmentService;
    @Autowired
    @Lazy
    private IPartsInfoService partsInfoService;
    @Autowired
    private IProcessSpecVersionService processSpecVersionService;
    @Autowired
    private IProcessStreamService processStreamService;
    @Autowired
    private IWorkStepService workStepService;
    @Autowired
    private IProductMixService productMixService;
    @Autowired
    private IDocRelativeService iDocRelativeService;
    @Autowired
    private IProductPermissionService productPermissionService;
    @Autowired
    @Lazy
    private IDocInfoService docInfoService;
    @Autowired
    private INcLogInfoService iNcLogInfoService;
    private IDocRelativeService docRelativeService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addComponentInfo(ComponentInfo componentInfo) {
@@ -65,14 +77,13 @@
        if(!ValidateUtil.validateString(componentInfo.getComponentCode()))
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_CODE_NONE);
        ComponentInfo en = getByCode(componentInfo.getComponentCode());
        if(en != null)
        if(en != null&&componentInfo.getBorrowId()==null)
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_IS_EXIST);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
        List<PermissionStream> oldPermissionList;
        List<PermissionStreamNew> oldPermissionList;
        ProductInfo productInfo = productInfoMapper.selectById(componentInfo.getProductId());
        if(productInfo == null)
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_PRODUCT_NONE);
@@ -81,40 +92,31 @@
            if(en == null) {
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_PARENT_NOT_EXIST);
            }
            oldPermissionList = permissionStreamService.getByComponentId(en.getProductId(), en.getComponentId());
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(en.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"1");
            componentInfo.setRankLevel(en.getRankLevel() + 1);
        } else {
            oldPermissionList = permissionStreamService.getByProductId(productInfo.getProductId());
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(productInfo.getProductId(),DocAttributionTypeEnum.PRODUCT.getCode().toString(),"1");
            componentInfo.setParentId(null);
            componentInfo.setRankLevel(1);
        }
        componentInfo.setComponentStatus(1);
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("产品结构树");
        //类型
        ncLogInfo.setOperateType(2);
        //日志内容
        ncLogInfo.setLogContent("部件名称:"+componentInfo.getComponentName()+",部件代号:"+componentInfo.getComponentCode());
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        boolean b = super.save(componentInfo);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //部门权限
        List<ComponentDepartment> componentDepartmentList = new ArrayList<>();
        List<PermissionStream> componentDepartPermList = new ArrayList<>();
        List<PermissionStreamNew> componentDepartPermList = new ArrayList<>();
        if(oldPermissionList != null && !oldPermissionList.isEmpty()) {
            oldPermissionList.forEach(item -> {
                ComponentDepartment componentDepartment = new ComponentDepartment();
                componentDepartment.setComponentId(componentInfo.getComponentId());
                componentDepartment.setDepartId(item.getDepartId());
                componentDepartmentList.add(componentDepartment);
                PermissionStream permissionStream = new PermissionStream();
                permissionStream.setProductId(componentInfo.getProductId());
                permissionStream.setComponentId(componentInfo.getComponentId());
                PermissionStreamNew permissionStream = new PermissionStreamNew();
                permissionStream.setBusinessId(componentInfo.getComponentId());
                permissionStream.setDepartId(item.getDepartId());
                permissionStream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
                componentDepartPermList.add(permissionStream);
            });
        }
@@ -124,40 +126,45 @@
                ExceptionCast.cast(CommonCode.FAIL);
        }
        if(!componentDepartPermList.isEmpty()) {
            b = permissionStreamService.saveBatch(componentDepartPermList);
            b = permissionStreamNewService.saveBatch(componentDepartPermList);
            if(!b)
                ExceptionCast.cast(CommonCode.FAIL);
        }
        ComponentPermission permission = new ComponentPermission();
        permission.setComponentId(componentInfo.getComponentId());
        permission.setUserId(userId);
        b = componentPermissionService.save(permission);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //去除默认新增工序,转为手动添加
        /*/添加默认工序
        ProcessStream processStream = new ProcessStream();
        processStream.setProductId(componentInfo.getProductId());
        processStream.setComponentId(componentInfo.getComponentId());
        processStream.setProcessCode("1");
        //添加日志
        NcLogInfo ncLogInfogx = new NcLogInfo();
        //模块
        ncLogInfogx.setModuleInfo("产品结构树");
        //类型
        ncLogInfogx.setOperateType(2);
        //日志内容
        ncLogInfogx.setLogContent("部件名称:"+componentInfo.getComponentName()+"生成默认工序,工序号:"+processStream.getProcessCode());
        iNcLogInfoService.saveLogNcInfos(ncLogInfogx);
        b = processStreamService.save(processStream);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);*/
        b = productPermissionService.add(componentInfo.getComponentId(), userId,DocAttributionTypeEnum.COMPONENT.getCode().toString());
        if (!b) {
            ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
        }
        //添加结构树
        ProductMix productMix=null;
        if (componentInfo.getParentId() != null) {
            //子部件
            productMix = new ProductMix(Long.parseLong(componentInfo.getComponentId()),Long.parseLong(componentInfo.getParentId())
                    ,componentInfo.getComponentName(),componentInfo.getComponentCode(),2,new Date());
        }else {
            productMix = new ProductMix(Long.parseLong(componentInfo.getComponentId()),Long.parseLong(productInfo.getProductId())
                    ,componentInfo.getComponentName(),componentInfo.getComponentCode(),2,new Date());
        }
        productMixService.save(productMix);
        if (StrUtil.isNotEmpty(componentInfo.getBorrowId())){
            //借用部件,同步添加文件
            List<DocRelative> docRelativeList=docRelativeService.
                    list(new QueryWrapper<DocRelative>().eq("attribution_type",DocAttributionTypeEnum.COMPONENT.getCode().toString()).eq("attribution_id",componentInfo.getBorrowId()));
            if (!docRelativeList.isEmpty()){
                docRelativeList.forEach(item -> {
                    DocRelative docRelative = new DocRelative();
                    BeanUtil.copyProperties(item,docRelative);
                    docRelative.setId(null);
                    docRelative.setAttributionId(componentInfo.getComponentId());
                    docRelativeService.save(docRelative);
                });
            }
        }
        //添加权限
        PermissionStream stream = new PermissionStream();
        PermissionStreamNew stream = new PermissionStreamNew();
        stream.setUserId(userId);
        stream.setProductId(componentInfo.getProductId());
        stream.setComponentId(componentInfo.getComponentId());
        return permissionStreamService.save(stream);
        stream.setBusinessId(componentInfo.getComponentId());
        stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
        return permissionStreamNewService.addPermissionStreamNew(stream);
    }
    @Override
@@ -179,18 +186,12 @@
        componentInfo.setComponentStatus(null);
        componentInfo.setRankLevel(null);
        componentInfo.setProductId(null);
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("产品结构树");
        //类型
        ncLogInfo.setOperateType(3);
        //日志内容
        ncLogInfo.setLogContent("修改部件名称:"+productInfoMapper.selectById(en.getProductId()).getProductName()+"子集部件");
        //修改保存备注
        ncLogInfo.setRemark(JSONObject.toJSONString(en));
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        boolean b = super.updateById(componentInfo);
        //同步修改结构树
        ProductMix productMix = productMixService.getById(Long.parseLong(id));
        productMix.setTreeName(componentInfo.getComponentName());
        productMix.setTreeCode(componentInfo.getComponentCode());
        productMixService.updateById(productMix);
        if(!b)
            return false;
        ComponentPermission permission = componentPermissionService.getByComponentIdAndUserId(id, userId);
@@ -202,15 +203,19 @@
            if(!b)
                return false;
        }
        PermissionStream stream = permissionStreamService.getByComponentIdAndUserId(en.getProductId(), id, userId);
        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId,DocAttributionTypeEnum.COMPONENT.getCode().toString());
        if(stream == null) {
            stream = new PermissionStream();
            stream = new PermissionStreamNew();
            stream.setUserId(userId);
            stream.setProductId(en.getProductId());
            stream.setComponentId(id);
            return permissionStreamService.save(stream);
            stream.setBusinessId(id);
            stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
            return permissionStreamNewService.save(stream);
        }
        return b;
        List<ComponentInfo> list = super.lambdaQuery().eq(ComponentInfo::getBorrowId,id).list();
        if (list != null && !list.isEmpty()) {
            list.forEach(item -> editComponentInfo(item.getComponentId(),componentInfo));
        }
        return true;
    }
    @Override
@@ -263,10 +268,10 @@
            b = componentDepartmentService.deleteByComponentId(item.getComponentId());
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = permissionStreamService.deleteUserPermsByComponentId(item.getProductId(), item.getComponentId());
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"0");
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = permissionStreamService.deleteDepartPermsByComponentId(item.getProductId(), item.getComponentId());
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"1");
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = super.removeById(item.getComponentId());
@@ -288,38 +293,41 @@
        if(childrenList != null && !childrenList.isEmpty()) {
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_CHILD_EXIST);
        }
        //验证产品下是否有零件
        //验证部件下是否有零件
        List<PartsInfo> partsInfoList = partsInfoService.getByComponentId(componentInfo.getProductId(), componentInfo.getComponentId());
        if(partsInfoList != null && !partsInfoList.isEmpty()) {
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_PARTS_EXIST);
        }
        //验证部件下是否有工序信息
        List<ProcessStream> processStreamList = processStreamService.findByComponentId(id);
        if(processStreamList != null && !processStreamList.isEmpty()) {
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_PROCESS_EXIST);
        }
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("产品结构树");
        //类型
        ncLogInfo.setOperateType(4);
        //日志内容
        ncLogInfo.setLogContent("部件名称:"+componentInfo.getComponentName());
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        boolean b = docInfoService.deleteByComponentId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //验证部件是否被借用
        List<ComponentInfo> list = super.lambdaQuery().eq(ComponentInfo::getBorrowId,id).list();
        if (list != null && !list.isEmpty()) {
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_BORROW_EXIST);
        }
        boolean b;
        //验证是否存在文档
        List<DocRelative> docRelativeList=iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type",DocAttributionTypeEnum.COMPONENT.getCode().toString()).eq("attribution_id",id));
        if (!docRelativeList.isEmpty()){
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_DOC_EXIST);
        }
        b = componentPermissionService.deleteByComponentId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = componentDepartmentService.deleteByComponentId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = permissionStreamService.deleteUserPermsByComponentId(componentInfo.getProductId(), componentInfo.getComponentId());
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"0");
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = permissionStreamService.deleteDepartPermsByComponentId(componentInfo.getProductId(), componentInfo.getComponentId());
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"1");
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = productMixService.removeById(id);
        if (!b)
            ExceptionCast.cast(CommonCode.FAIL);
        return super.removeById(id);
    }
@@ -342,7 +350,7 @@
        if(componentInfo == null || userList == null || userList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentPermission> permissionList = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        userList.forEach(item -> {
            ComponentPermission en = componentPermissionService.getByComponentIdAndUserId(componentInfo.getComponentId(), item.getId());
            if(en == null) {
@@ -351,12 +359,12 @@
                en.setComponentId(componentInfo.getComponentId());
                permissionList.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndUserId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(), "2 ");
            if(stream == null) {
                stream = new PermissionStream();
                stream = new PermissionStreamNew();
                stream.setUserId(item.getId());
                stream.setProductId(componentInfo.getProductId());
                stream.setComponentId(componentInfo.getComponentId());
                stream.setBusinessId(componentInfo.getComponentId());
                stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
                permissionStreamList.add(stream);
            }
        });
@@ -367,7 +375,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.saveBatch(permissionStreamList);
            boolean b = permissionStreamNewService.saveBatch(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }
@@ -381,13 +389,13 @@
        if(componentInfo == null || userList == null || userList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentPermission> permissionList = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        userList.forEach(item -> {
            ComponentPermission en = componentPermissionService.getByComponentIdAndUserId(componentInfo.getComponentId(), item.getId());
            if(en != null) {
                permissionList.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndUserId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(), "2 ");
            if(stream != null) {
                permissionStreamList.add(stream);
            }
@@ -403,7 +411,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.removeByCollection(permissionStreamList);
            boolean b = permissionStreamNewService.deletePermissionStreamNewByList(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }
@@ -417,7 +425,7 @@
        if(componentInfo == null || departmentList == null || departmentList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentDepartment> componentDepartments = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        departmentList.forEach(item -> {
            ComponentDepartment en = componentDepartmentService.getByComponentIdAndDepartId(componentInfo.getComponentId(), item.getId());
            if(en == null) {
@@ -426,12 +434,12 @@
                en.setComponentId(componentInfo.getComponentId());
                componentDepartments.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndDepartId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
            if(stream == null) {
                stream = new PermissionStream();
                stream = new PermissionStreamNew();
                stream.setDepartId(item.getId());
                stream.setProductId(componentInfo.getProductId());
                stream.setComponentId(componentInfo.getComponentId());
                stream.setBusinessId(componentInfo.getComponentId());
                stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
                permissionStreamList.add(stream);
            }
        });
@@ -442,7 +450,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.saveBatch(permissionStreamList);
            boolean b = permissionStreamNewService.saveBatch(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }
@@ -456,13 +464,13 @@
        if(componentInfo == null || departmentList == null || departmentList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentDepartment> componentDepartments = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        departmentList.forEach(item -> {
            ComponentDepartment en = componentDepartmentService.getByComponentIdAndDepartId(componentInfo.getComponentId(), item.getId());
            if(en != null) {
                componentDepartments.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndDepartId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
            if(stream != null) {
                permissionStreamList.add(stream);
            }
@@ -474,7 +482,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.removeByCollection(permissionStreamList);
            boolean b = permissionStreamNewService.deletePermissionStreamNewByList(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }
@@ -548,4 +556,168 @@
        queryWrapper.orderByAsc(ComponentInfo::getCreateTime);
        return super.list(queryWrapper);
    }
    /**
     * 通过零件号、材质等查询对应电子样板
     * @param treeInfoRequest
     * @return
     */
    @Override
    public List<DocInfo> getByComponentInfo(TreeInfoRequest treeInfoRequest){
        LambdaQueryWrapper<ComponentInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (treeInfoRequest.getProductIds() != null && !treeInfoRequest.getProductIds().isEmpty()) {
            queryWrapper.in(ComponentInfo::getProductId, treeInfoRequest.getProductIds());
        }
        if (treeInfoRequest.getAttributionType()==2){
            queryWrapper.eq(StrUtil.isNotEmpty(treeInfoRequest.getAttributionId()),ComponentInfo::getComponentId,treeInfoRequest.getAttributionId());
        }
        queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeCode()),ComponentInfo::getComponentCode, treeInfoRequest.getTreeCode());
        queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeName()),ComponentInfo::getComponentName, treeInfoRequest.getTreeName());
        queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getStructureType()),ComponentInfo::getStructureType, treeInfoRequest.getStructureType());
        queryWrapper.orderByDesc(ComponentInfo::getCreateTime);
        List<ComponentInfo> list = super.list(queryWrapper);
        List<DocInfo> docInfos = new ArrayList<>();
        if (list != null && !list.isEmpty()) {
            String ids=list.stream().map(ComponentInfo::getComponentId).collect(Collectors.joining(","));
            DocInfoQueryRequest docQuery = new DocInfoQueryRequest();
            BeanUtil.copyProperties(treeInfoRequest,docQuery);
            docQuery.setAttributionIds(ids);
            docQuery.setDocClassCode("OTHER");
            docQuery.setAttributionType(2);
            docInfos=docInfoService.findListByDocQuery(docQuery);
        }
        if (treeInfoRequest.getAttributionType()==2){
            List<String> id =new ArrayList<>();
            id.add(treeInfoRequest.getAttributionId());
            treeInfoRequest.setComponentIds(id);
            //零件
            List<DocInfo> partsInfos = partsInfoService.getByPartsInfo(treeInfoRequest);
            docInfos.addAll(partsInfos);
            //工艺规程版本
            List<DocInfo> processSpecVersions = processSpecVersionService.getByProcessSpecVersion(treeInfoRequest);
            docInfos.addAll(processSpecVersions);
            //工序
            List<DocInfo> processStreams = processStreamService.getByProcessStreamOtherFile(treeInfoRequest);
            docInfos.addAll(processStreams);
            //工步
            List<DocInfo> workSteps = workStepService.getByWorkStepOtherFile(treeInfoRequest);
            docInfos.addAll(workSteps);
        }
        return docInfos;
    }
    /**
     * 查询可以被引用的部件
     * @param componentInfo
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public IPage<ComponentInfo> getByComponentId(ComponentInfo componentInfo, Integer pageNo, Integer pageSize){
        //权限排除,不能引用自己上下级部件
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String productIds = loginUser.getProductionIds();
        ComponentInfo oldComponentInfo = super.getById(componentInfo.getComponentId());
        IPage<ComponentInfo> page = new Page<>(pageNo, pageSize);
        if (productIds != null && !productIds.isEmpty()) {
            List<String> productIdList = Arrays.asList(productIds.split(","));
            List<ProductMix> productMixList = permissionStreamNewService.
                    loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
            List<Long> ids = productMixList.stream().map(ProductMix::getId).collect(Collectors.toList());
            //获取已经自身被借用的部件
            LambdaQueryWrapper<ComponentInfo> borrowQueryWrapper = new LambdaQueryWrapper<>();
            if (!ids.isEmpty()){
                borrowQueryWrapper.in(ComponentInfo::getBorrowId,ids);
            }
            borrowQueryWrapper.eq(ComponentInfo::getParentId,componentInfo.getComponentId());
            List<String> borrowIds= super.list(borrowQueryWrapper).stream().map(ComponentInfo::getBorrowId).collect(Collectors.toList());
            LambdaQueryWrapper<ComponentInfo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.like(StrUtil.isNotEmpty(componentInfo.getComponentName()),ComponentInfo::getComponentName, componentInfo.getComponentName());
            queryWrapper.like(StrUtil.isNotEmpty(componentInfo.getComponentCode()),ComponentInfo::getComponentCode, componentInfo.getComponentCode());
            queryWrapper.isNull(ComponentInfo::getBorrowId);
            if (!ids.isEmpty()){
                queryWrapper.in(ComponentInfo::getComponentId,ids);
            }
            queryWrapper.ne(StrUtil.isNotEmpty(oldComponentInfo.getBorrowId()),ComponentInfo::getComponentId,oldComponentInfo.getBorrowId());
            if (!borrowIds.isEmpty()) {
                queryWrapper.notIn(ComponentInfo::getComponentId,borrowIds);
            }
            queryWrapper.orderByDesc(ComponentInfo::getCreateTime);
            page = super.page(page, queryWrapper);
        }
        return page;
    }
    /**
     * 借用部件(可批量) - 原有部件id,新部件ids
     * @param oldId,newIds
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<?> borrowComponent(String oldId, String newIds){
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ComponentInfo componentInfo = super.getById(oldId);
        if(componentInfo == null) {
            return Result.error("部件不存在");
        }
        List<String> productIdList = Arrays.asList(loginUser.getProductionIds().split(","));
        //获取可以借用的部件
        List<ProductMix> productMixList = permissionStreamNewService.
                loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
        Set<Long> allowedIds = productMixList.stream()
                .map(ProductMix::getId)
                .collect(Collectors.toCollection(HashSet::new));
        List<String> newIdList = Arrays.asList(newIds.split(","));
        boolean allAllowed = newIdList.parallelStream()
                .map(Long::parseLong)
                .allMatch(allowedIds::contains);
        if (!allAllowed) {
            return Result.error("存在未授权的部件借用");
        }
        //获取已经被借用的部件
        LambdaQueryWrapper<ComponentInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(ComponentInfo::getBorrowId,newIdList);
        queryWrapper.eq(ComponentInfo::getParentId,componentInfo.getComponentId());
        List<ComponentInfo> list = super.list(queryWrapper);
        //判断是否已经被当前部件借用
        if(!list.isEmpty()) {
            return Result.error("选择的部件已被当前部件借用");
        }
        List<ComponentInfo> componentInfoList=listByIds(newIdList);
        componentInfoList.forEach(item->{
            //添加部件信息、层级信息、权限信息
            ComponentInfo newComponentInfo=new ComponentInfo();
            BeanUtil.copyProperties(item,newComponentInfo);
            newComponentInfo.setComponentId(null);
            newComponentInfo.setProductId(componentInfo.getProductId());
            newComponentInfo.setParentId(componentInfo.getComponentId());
            newComponentInfo.setBorrowId(item.getComponentId());
            newComponentInfo.setCreateTime(null);
            newComponentInfo.setCreateBy(null);
            newComponentInfo.setUpdateTime(null);
            newComponentInfo.setUpdateBy(null);
            addComponentInfo(newComponentInfo);
        });
        return Result.ok("部件借用成功");
    }
    @Override
    public boolean assignPermission(Object entity, Collection<SysUser> userList, boolean isAdd){
        if (isAdd) {
            return assignAddUser((ComponentInfo) entity, userList);
        } else {
            return assignRemoveUser((ComponentInfo) entity, userList);
        }
    }
    @Override
    public boolean assignDepartPermission(Object entity, Collection<MdcProduction> departments, boolean isAdd) {
        if (isAdd) {
            return assignAddDepart((ComponentInfo) entity, departments);
        } else {
            return assignRemoveDepart((ComponentInfo) entity, departments);
        }
    }
}