| | |
| | | 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; |
| | |
| | | private CutterMapper cutterMapper; |
| | | @Autowired |
| | | private GuideCardBatchMapper guideCardBatchMapper; |
| | | @Autowired |
| | | private IPermissionStreamNewService permissionStreamNewService; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @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()); |
| | |
| | | completeChainWithProductInfo(chain); |
| | | List<ProductMix> productMixList=buildFullTreePath(chain); |
| | | chain.setTreePath(productMixList); |
| | | chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList)); |
| | | return chain; |
| | | } |
| | | |
| | | /** |
| | | * 工步封装 |
| | | * @param docRelative |
| | | * @return |
| | | */ |
| | | public ProcessTraceChain traceFromWorkStep(DocRelative docRelative) { |
| | | ProcessTraceChain chain = initChainWithDocInfo(docRelative); |
| | | DeviceType deviceType = deviceTypeMapper.selectById(docRelative.getAttributionId()); |
| | |
| | | completeChainWithProductInfo(chain); |
| | | List<ProductMix> productMixList=buildFullTreePath(chain); |
| | | chain.setTreePath(productMixList); |
| | | chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList)); |
| | | return chain; |
| | | } |
| | | |
| | |
| | | .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; |
| | | } |
| | | |
| | |
| | | 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) { |
| | |
| | | return path; |
| | | } |
| | | |
| | | private List<PermissionStreamNew> buildFullTreePathPermission(List<ProductMix> productMixList) { |
| | | List<Long> ids=productMixList.stream().map(ProductMix::getId).collect(Collectors.toList()); |
| | | List<PermissionStreamNew> path = permissionStreamNewService |
| | | .list(new QueryWrapper<PermissionStreamNew>().in("business_id",ids) |
| | | .eq("delete_flag",0)); |
| | | path.forEach(item->{ |
| | | if (item.getDepartId()!=null){ |
| | | MdcProduction mdcProduction=mdcProductionService.getById(item.getDepartId()); |
| | | if(mdcProduction!=null){ |
| | | item.setDepartId(item.getDepartId()); |
| | | } |
| | | } |
| | | if (item.getUserId()!=null){ |
| | | item.setUserId(sysUserService.getById(item.getUserId()).getUsername()); |
| | | } |
| | | }); |
| | | return path; |
| | | } |
| | | } |