lyh
2025-04-17 bb696e8e702854b62b144b22e20e36981301e6cf
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
@@ -1,5 +1,7 @@
package org.jeecg.modules.dnc.service.impl;
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.toolkit.Wrappers;
@@ -11,6 +13,8 @@
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;
@@ -24,10 +28,8 @@
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 {
@@ -43,6 +45,8 @@
    @Lazy
    private IPartsInfoService partsInfoService;
    @Autowired
    private IProcessSpecVersionService processSpecVersionService;
    @Autowired
    private IProcessStreamService processStreamService;
    @Autowired
    private IProductMixService productMixService;
@@ -50,7 +54,9 @@
    private IDocRelativeService iDocRelativeService;
    @Autowired
    private IProductPermissionService productPermissionService;
    @Autowired
    @Lazy
    private IDocInfoService docInfoService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addComponentInfo(ComponentInfo componentInfo) {
@@ -121,15 +127,22 @@
            ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
        }
        //添加结构树
        ProductMix productMix = new ProductMix(Long.parseLong(componentInfo.getComponentId()),Long.parseLong(productInfo.getProductId())
                ,componentInfo.getComponentName(),componentInfo.getComponentCode(),"2");
        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);
        //添加权限
        PermissionStreamNew stream = new PermissionStreamNew();
        stream.setUserId(userId);
        stream.setBusinessId(componentInfo.getComponentId());
        stream.setBusinessType("2");
        return permissionStreamNewService.save(stream);
        return permissionStreamNewService.addPermissionStreamNew(stream);
    }
    @Override
@@ -152,6 +165,11 @@
        componentInfo.setRankLevel(null);
        componentInfo.setProductId(null);
        boolean b = super.updateById(componentInfo);
        //同步修改结构树
        ProductMix productMix = productMixService.getById(Long.parseLong(id));
        productMix.setName(componentInfo.getComponentName());
        productMix.setCode(componentInfo.getComponentCode());
        productMixService.updateById(productMix);
        if(!b)
            return false;
        ComponentPermission permission = componentPermissionService.getByComponentIdAndUserId(id, userId);
@@ -506,4 +524,46 @@
        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);
        }
        return docInfos;
    }
}