lyh
3 天以前 b1e37337ac05917ad6989177bc639acc2c065600
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FullHierarchyTraceService.java
@@ -6,6 +6,7 @@
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.dnc.mapper.*;
import org.jeecg.modules.dnc.service.IPermissionStreamNewService;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -53,6 +54,67 @@
    @Autowired
    private IMdcProductionService mdcProductionService;
    /**
     * 产品封装
     * @param docRelative
     * @return
     */
    public ProcessTraceChain traceFromProduct(DocRelative docRelative) {
        ProcessTraceChain chain = initChainWithDocInfo(docRelative);
        traceProductChain(chain, docRelative.getAttributionId());
        List<ProductMix> productMixList=buildFullTreePath(chain);
        chain.setTreePath(productMixList);
        chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList));
        return chain;
    }
    /**
     * 部件封装
     * @param docRelative
     * @return
     */
    public ProcessTraceChain traceFromComponent(DocRelative docRelative) {
        ProcessTraceChain chain = initChainWithDocInfo(docRelative);
        traceComponentChain(chain, docRelative.getAttributionId());
        List<ProductMix> productMixList=buildFullTreePath(chain);
        chain.setTreePath(productMixList);
        chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList));
        return chain;
    }
    /**
     * 零件封装
     * @param docRelative
     * @return
     */
    public ProcessTraceChain traceFromParts(DocRelative docRelative) {
        ProcessTraceChain chain = initChainWithDocInfo(docRelative);
        tracePartsChain(chain, docRelative.getAttributionId());
        List<ProductMix> productMixList=buildFullTreePath(chain);
        chain.setTreePath(productMixList);
        chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList));
        return chain;
    }
    /**
     * 工艺规程版本封装
     * @param docRelative
     * @return
     */
    public ProcessTraceChain traceFromPsv(DocRelative docRelative) {
        ProcessTraceChain chain = initChainWithDocInfo(docRelative);
        traceProcessSpecVersionChain(chain, docRelative.getAttributionId());
        List<ProductMix> productMixList=buildFullTreePath(chain);
        chain.setTreePath(productMixList);
        chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList));
        return chain;
    }
    /**
     * 工序封装
     * @param docRelative
     * @return
     */
    public ProcessTraceChain traceFromProcess(DocRelative docRelative) {
        ProcessTraceChain chain = initChainWithDocInfo(docRelative);
        DeviceType deviceType = deviceTypeMapper.selectById(docRelative.getAttributionId());
@@ -70,6 +132,11 @@
        return chain;
    }
    /**
     * 工步封装
     * @param docRelative
     * @return
     */
    public ProcessTraceChain traceFromWorkStep(DocRelative docRelative) {
        ProcessTraceChain chain = initChainWithDocInfo(docRelative);
        DeviceType deviceType = deviceTypeMapper.selectById(docRelative.getAttributionId());
@@ -93,9 +160,11 @@
                .ifPresent(doc -> {
                    chain.setDocInfo(doc);
                    chain.setDocFile(docFileMapper.selectById(doc.getPublishFileId()));
                    chain.setCutterList(getCuttersByDocId(doc.getDocId()));
                    getLatestGuideCardBatch(doc.getDocId()).ifPresent(chain::setGuideCardBatch);
                });
                    if (Objects.equals(docRelative.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode()) ||
                            Objects.equals(docRelative.getAttributionType(), DocAttributionTypeEnum.WORKSITE.getCode())) {
                        chain.setCutterList(getCuttersByDocId(doc.getDocId()));
                        getLatestGuideCardBatch(doc.getDocId()).ifPresent(chain::setGuideCardBatch);
                    }});
        return chain;
    }
@@ -119,6 +188,48 @@
    private boolean isWorkSiteType(DeviceType deviceType) {
        return deviceType != null &&
                Objects.equals(deviceType.getAttributionType(), DocAttributionTypeEnum.WORKSITE.getCode());
    }
    private void traceProductChain(ProcessTraceChain chain, String productId) {
        ProductInfo product = productMapper.selectById(productId);
        chain.setProduct(product);
    }
    private void traceComponentChain(ProcessTraceChain chain, String componentId) {
        chain.setComponentHierarchy(traceComponentHierarchy(componentId));
        Optional.ofNullable(chain.getComponentHierarchy())
                .map(ComponentHierarchy::getRootProduct)
                .ifPresent(chain::setProduct);
    }
    private void tracePartsChain(ProcessTraceChain chain, String partsId) {
        PartsInfo parts = partsMapper.selectById(partsId);
        chain.setParts(parts);
        if (parts != null) {
            if (parts.getComponentId() != null) {
                chain.setComponentHierarchy(traceComponentHierarchy(parts.getComponentId()));
                Optional.ofNullable(chain.getComponentHierarchy())
                        .map(ComponentHierarchy::getRootProduct)
                        .ifPresent(chain::setProduct);
            }
        }
    }
    private void traceProcessSpecVersionChain(ProcessTraceChain chain, String psvId) {
        ProcessSpecVersion psv = psvMapper.selectById(psvId);
        chain.setProcessSpec(psv);
        if (psv != null) {
            if (psv.getPartsId() != null) {
                PartsInfo parts = partsMapper.selectById(psv.getPartsId());
                chain.setParts(parts);
                if (parts != null && parts.getComponentId() != null) {
                    chain.setComponentHierarchy(traceComponentHierarchy(parts.getComponentId()));
                    Optional.ofNullable(chain.getComponentHierarchy())
                            .map(ComponentHierarchy::getRootProduct)
                            .ifPresent(chain::setProduct);
                }
            }
        }
    }
    private void traceProcessChain(ProcessTraceChain chain, String processId) {
@@ -225,7 +336,10 @@
                        .eq("delete_flag",0));
        path.forEach(item->{
            if (item.getDepartId()!=null){
                item.setDepartId(mdcProductionService.getById(item.getDepartId()).getOrgCode());
                MdcProduction mdcProduction=mdcProductionService.getById(item.getDepartId());
                if(mdcProduction!=null){
                    item.setDepartId(item.getDepartId());
                }
            }
            if (item.getUserId()!=null){
                item.setUserId(sysUserService.getById(item.getUserId()).getUsername());