lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/dto/ComponentHierarchy.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,28 @@ package org.jeecg.modules.dnc.dto; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; import org.jeecg.modules.dnc.entity.ComponentInfo; import org.jeecg.modules.dnc.entity.ProductInfo; import java.util.ArrayList; import java.util.List; @Data @JsonIgnoreProperties(ignoreUnknown = true) public class ComponentHierarchy { private ProductInfo rootProduct; private final List<ComponentInfo> components = new ArrayList<>(); // 仿 ¹é¨ä»¶å°åºå±é¨ä»¶çé¡ºåº public void addComponentToTop(ComponentInfo component) { components.add(0, component); } public List<ComponentInfo> getComponentsFromTop() { return new ArrayList<>(components); } public ComponentInfo getLeafComponent() { return components.isEmpty() ? null : components.get(components.size() - 1); } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/dto/ProcessTraceChain.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,86 @@ package org.jeecg.modules.dnc.dto; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; import org.jeecg.modules.dnc.entity.*; import java.util.List; /** * @Description: æ¶å¯ç½åæ¥å·¥æ§ç½éè¦çæ°æ® * @Author: lyh * @Date: 2025-06-13 * @Version: V1.0 * @remark: åç»éè¦å¢å ï¼æ·»å 对åºåæ°ä¸ç»ææ°æ®ï¼éç¨JSONåºååä¸ååºååè¿è¡ä¼ è¾ï¼æ¹ä¾¿ä¼ è¾ï¼å 坿ä½ï¼é¿å æ°æ®æ±¡æï¼ */ @Data @Builder @JsonIgnoreProperties(ignoreUnknown = true) public class ProcessTraceChain { /**ç¨åºå 工确认表*/ private GuideCardBatch guideCardBatch; /**åå ·å表*/ private List<Cutter> cutterList; /**æä»¶*/ private DocFile docFile; /**è®¾å¤ææ¡£å¯¹åºå ³ç³»*/ private DocRelative docRelative; /**ææ¡£*/ private DocInfo docInfo; /**设å¤ç±»*/ private DeviceType deviceType; /**设å¤ç±»å¯¹åºå ³ç³»*/ private DeviceManagement deviceManagement; /**å·¥æ¥*/ private WorkStep workStep; /**å·¥åº*/ private ProcessStream process; /**å·¥èºè§ç¨çæ¬*/ private ProcessSpecVersion processSpec; /**é¶ä»¶*/ private PartsInfo parts; /**é¨ä»¶*/ private ComponentHierarchy componentHierarchy; /**产å*/ private ProductInfo product; /**äº§åæ è·¯å¾*/ private List<ProductMix> treePath; /**æé表*/ private List<PermissionStreamNew> permissionStreamNewList; @JsonCreator public ProcessTraceChain( @JsonProperty("guideCardBatch") GuideCardBatch guideCardBatch, @JsonProperty("cutterList") List<Cutter> cutterList, @JsonProperty("docFile") DocFile docFile, @JsonProperty("docRelative") DocRelative docRelative, @JsonProperty("docInfo") DocInfo docInfo, @JsonProperty("deviceType") DeviceType deviceType, @JsonProperty("deviceManagement") DeviceManagement deviceManagement, @JsonProperty("workStep") WorkStep workStep, @JsonProperty("process") ProcessStream process, @JsonProperty("processSpec") ProcessSpecVersion processSpec, @JsonProperty("parts") PartsInfo parts, @JsonProperty("componentHierarchy") ComponentHierarchy componentHierarchy, @JsonProperty("product") ProductInfo product, @JsonProperty("treePath") List<ProductMix> treePath, @JsonProperty("permissionStreamNewList") List<PermissionStreamNew> permissionStreamNewList ) { this.guideCardBatch = guideCardBatch; this.cutterList = cutterList; this.docFile = docFile; this.docRelative = docRelative; this.docInfo = docInfo; this.deviceType = deviceType; this.deviceManagement = deviceManagement; this.workStep = workStep; this.process = process; this.processSpec = processSpec; this.parts = parts; this.componentHierarchy = componentHierarchy; this.product = product; this.treePath = treePath; this.permissionStreamNewList = permissionStreamNewList; } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/dto/TransferPackage.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,31 @@ package org.jeecg.modules.dnc.dto; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; import org.jeecg.modules.dnc.entity.*; @Data @Builder @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class TransferPackage { public enum DataType { PROCESS, WORKSTEP } private final DataType dataType; private final DocRelative docRelative; private final ProcessTraceChain traceChain; @JsonCreator public TransferPackage( @JsonProperty("dataType") DataType dataType, @JsonProperty("docRelative") DocRelative docRelative, @JsonProperty("traceChain") ProcessTraceChain traceChain ) { this.dataType = dataType; this.docRelative = docRelative; this.traceChain = traceChain; } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/entity/ProductMix.java
@@ -29,13 +29,13 @@ private Long parentId; // åç§° @TableField(value = "tree_name") private String name; private String treeName; // code @TableField(value = "tree_code") private String code; private String treeCode; // ç±»å @TableField(value = "tree_type") private Integer type; private Integer treeType; @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") @TableField(value = "create_time") private Date createTime; @@ -43,17 +43,19 @@ //å±ç¤ºåç§° private transient String label; //ç±»å æ¹ä¾¿å端å±ç¤º private transient Integer type; private transient List<ProductMix> children = new ArrayList<>(); public ProductMix(Long id, Long parentId, String name, String code, Integer type, Date createTime) { public ProductMix(Long id, Long parentId, String treeName, String trrCode, Integer type, Date createTime) { this.id = id; this.parentId = parentId; this.name = name; this.code = code; this.treeName = treeName; this.treeCode = trrCode; this.type = type; this.children = new ArrayList<>(); this.label="["+code+"]"+name; this.label="["+ trrCode +"]"+ treeName; this.createTime = createTime; } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/listener/FileListener.java
@@ -1,25 +1,26 @@ package org.jeecg.modules.dnc.listener; import org.apache.commons.io.monitor.FileAlterationListener; import org.apache.commons.io.monitor.FileAlterationObserver; import org.jeecg.common.util.FileUtil; import org.jeecg.modules.dnc.service.IDocInfoService; import org.jeecg.modules.dnc.utils.file.FileUtilS; import org.jeecg.modules.message.enums.DeployEnum; import org.jeecg.modules.dnc.dto.TransferPackage; import org.jeecg.modules.dnc.service.impl.DataImportService; import org.jeecg.modules.dnc.service.impl.FileFerryService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.io.File; import java.util.Objects; @Component public class FileListener implements FileAlterationListener { private static final Logger log = LoggerFactory.getLogger(FileListener.class); @Autowired private IDocInfoService docInfoService; // ææ¡£æå¡ private FileFerryService fileFerryService; @Autowired private DataImportService dataImportService; @Override public void onStart(FileAlterationObserver observer) { @@ -45,6 +46,13 @@ public void onFileCreate(File file) { String filePath = file.getAbsolutePath(); log.info("[æ°å»º]: {}", filePath); // if (filePath.startsWith(fileMonitorConfig.getPaths().get(0))){ if (filePath.endsWith(".ferry")){ TransferPackage data = fileFerryService.importData(filePath); dataImportService.importTransferPackage(data); log.info("æä»¶å¯¼å ¥å®æ"); } // } } @Override public void onFileChange(File file) { lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/xml/PermissionStreamNewMapper.xml
@@ -4,8 +4,8 @@ <select id="loadProductMix" resultType="org.jeecg.modules.dnc.entity.ProductMix"> SELECT DISTINCT mix.id, mix.tree_code 'code', mix.tree_name 'name', mix.tree_code, mix.tree_name, mix.parent_id, mix.tree_type AS 'type', mix.extend, @@ -31,8 +31,8 @@ </select> <select id="loadProductMixAll" resultType="org.jeecg.modules.dnc.entity.ProductMix"> SELECT DISTINCT mix.id, mix.tree_code 'code', mix.tree_name 'name', mix.tree_code , mix.tree_name , mix.parent_id, mix.tree_type AS 'type', mix.extend, @@ -92,8 +92,8 @@ ) SELECT DISTINCT mix.id, mix.tree_code 'code', mix.tree_name 'name', mix.tree_code, mix.tree_name, mix.parent_id, mix.tree_type AS 'type', mix.extend, lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
@@ -189,8 +189,8 @@ boolean b = super.updateById(componentInfo); //åæ¥ä¿®æ¹ç»ææ ProductMix productMix = productMixService.getById(Long.parseLong(id)); productMix.setName(componentInfo.getComponentName()); productMix.setCode(componentInfo.getComponentCode()); productMix.setTreeName(componentInfo.getComponentName()); productMix.setTreeCode(componentInfo.getComponentCode()); productMixService.updateById(productMix); if(!b) return false; lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DataImportService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,456 @@ package org.jeecg.modules.dnc.service.impl; import cn.hutool.core.util.StrUtil; import com.jeecg.weibo.exception.BusinessException; import liquibase.pro.packaged.S; import org.jeecg.modules.dnc.dto.ComponentHierarchy; import org.jeecg.modules.dnc.dto.TransferPackage; import org.jeecg.modules.dnc.entity.*; import org.jeecg.modules.dnc.mapper.*; import org.jeecg.modules.dnc.service.*; import org.jeecg.modules.system.service.IMdcProductionService; import org.jeecg.modules.system.service.ISysUserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service public class DataImportService { private static final Logger logger = LoggerFactory.getLogger(DataImportService.class); @Autowired private ProductInfoMapper productMapper; @Autowired private ComponentInfoMapper componentMapper; @Autowired private PartsInfoMapper partsMapper; @Autowired private ProcessSpecVersionMapper psvMapper; @Autowired private ProcessStreamMapper processMapper; @Autowired private WorkStepMapper workStepMapper; @Autowired private ProductMixMapper productMixMapper; @Autowired private PermissionStreamNewMapper permissionStreamNewMapper; @Autowired private DeviceManagementMapper deviceManagementMapper; @Autowired private DeviceTypeMapper deviceTypeMapper; @Autowired private DocInfoMapper docInfoMapper; @Autowired private DocFileMapper docFileMapper; @Autowired private DocRelativeMapper docRelativeMapper; @Autowired private CutterMapper cutterMapper; @Autowired private GuideCardBatchMapper guideCardBatchMapper; @Autowired private ISysUserService sysUserService; @Autowired private IMdcProductionService mdcProductionService; @Autowired private IProductPermissionService productPermissionService; @Autowired private IProductDepartmentService productDepartmentService; @Autowired private IComponentPermissionService componentPermissionService; @Autowired private IComponentDepartmentService componentDepartmentService; @Autowired private IPartsPermissionService partsPermissionService; @Autowired private IPartsDepartmentService partsDepartmentService; @Autowired private IProcessSpecVersionPermissionService processSpecVersionPermissionService; @Autowired private IProcessSpecVersionDepartmentService processSpecVersionDepartmentService; @Autowired private IProcessStreamPermissionService processStreamPermissionService; @Autowired private IProcessionDepartmentService processionDepartmentService; @Autowired private IWorkStepPermissionService workStepPermissionService; @Autowired private IWorkStepDepartmentService workStepDepartmentService; @Transactional(rollbackFor = Exception.class) public void importTransferPackage(TransferPackage transferPackage) { try { logger.info("å¼å§å¯¼å ¥ä¼ è¾å æ°æ®, ç±»å: {}", transferPackage.getDataType()); // ä¿å产å if (transferPackage.getTraceChain() != null && transferPackage.getTraceChain().getProduct() != null) { saveProduct(transferPackage.getTraceChain().getProduct()); } // ä¿åé¨ä»¶å±çº§ if (transferPackage.getTraceChain() != null && transferPackage.getTraceChain().getComponentHierarchy() != null) { saveComponentHierarchy(transferPackage.getTraceChain().getComponentHierarchy()); } // ä¿åé¶ä»¶ if (transferPackage.getTraceChain() != null && transferPackage.getTraceChain().getParts() != null) { saveParts(transferPackage.getTraceChain().getParts()); } // ä¿åå·¥èºè§ç¨ if (transferPackage.getTraceChain() != null && transferPackage.getTraceChain().getProcessSpec() != null) { saveProcessSpec(transferPackage.getTraceChain().getProcessSpec()); } // ä¿åå·¥åº if (transferPackage.getTraceChain() != null&& transferPackage.getTraceChain().getProcess() != null) { saveProcess(transferPackage.getTraceChain().getProcess()); } // ä¿åå·¥æ¥ if (transferPackage.getTraceChain() != null&& transferPackage.getTraceChain().getWorkStep() != null) { saveWorkSteps(transferPackage.getTraceChain().getWorkStep()); } // ä¿åç»ææ if (transferPackage.getTraceChain() != null&& transferPackage.getTraceChain().getTreePath() != null) { saveTreePath(transferPackage.getTraceChain().getTreePath()); } //ä¿åæé if (transferPackage.getTraceChain() != null&& transferPackage.getTraceChain().getPermissionStreamNewList() != null) { savePermissionStreamNewList(transferPackage.getTraceChain().getPermissionStreamNewList()); } // ä¿å设å¤ç±» if (transferPackage.getTraceChain() != null&& transferPackage.getTraceChain().getDeviceManagement() != null) { saveDeviceManagement(transferPackage.getTraceChain().getDeviceManagement()); } // ä¿å设å¤ç±»å¯¹åºä¿¡æ¯ if (transferPackage.getTraceChain() != null&& transferPackage.getTraceChain().getDeviceType() != null) { saveDeviceType(transferPackage.getTraceChain().getDeviceType()); } // ä¿åææ¡£ if (transferPackage.getTraceChain() != null&& transferPackage.getTraceChain().getDocInfo() != null) { saveDocInfo(transferPackage.getTraceChain().getDocInfo()); } // ä¿åæä»¶ if (transferPackage.getTraceChain() !=null&& transferPackage.getTraceChain().getDocFile() != null) { saveDocFile(transferPackage.getTraceChain().getDocFile()); } // ä¿åææ¡£æä»¶å¯¹åºå ³ç³» if (transferPackage.getDocRelative() !=null){ saveDocRelative(transferPackage.getDocRelative()); } // ä¿ååå ·ç³»ç» if (transferPackage.getTraceChain() !=null&& transferPackage.getTraceChain().getCutterList() != null) { saveCutterList(transferPackage.getTraceChain().getCutterList()); } //ä¿åæ°æ§ç¨åºå 工确认表 if (transferPackage.getTraceChain() !=null&& transferPackage.getTraceChain().getGuideCardBatch() != null) { saveGuideCardBatch(transferPackage.getTraceChain().getGuideCardBatch()); } logger.info("æ°æ®å¯¼å ¥æå"); } catch (DuplicateKeyException e) { logger.warn("主é®å²çª: {}", e.getMessage()); throw new BusinessException("æ°æ®å·²åå¨ï¼æ æ³éå¤å¯¼å ¥"); } catch (DataIntegrityViolationException e) { logger.error("æ°æ®å®æ´æ§è¿å: {}", e.getMessage()); throw new BusinessException("æ°æ®ä¸å®æ´ï¼è¯·æ£æ¥å¿ å¡«åæ®µ"); } catch (Exception e) { logger.error("æ°æ®å¯¼å ¥å¤±è´¥: {}", e.getMessage(), e); throw new BusinessException("æ°æ®å¯¼å ¥å¤±è´¥: " + e.getMessage()); } } private void saveProduct(ProductInfo product) { if (productMapper.selectById(product.getProductId()) == null) { productMapper.insert(product); logger.debug("产åå·²ä¿å: {}", product.getProductId()); } else { logger.debug("产åå·²åå¨: {}", product.getProductId()); } } private void saveComponentHierarchy(ComponentHierarchy hierarchy) { for (ComponentInfo component : hierarchy.getComponents()) { if (componentMapper.selectById(component.getComponentId()) == null) { componentMapper.insert(component); logger.debug("é¨ä»¶å·²ä¿å: {}", component.getComponentId()); } else { logger.debug("é¨ä»¶å·²åå¨: {}", component.getComponentId()); } } } private void saveParts(PartsInfo parts) { if (partsMapper.selectById(parts.getPartsId()) == null) { partsMapper.insert(parts); logger.debug("é¶ä»¶å·²ä¿å: {}", parts.getPartsId()); } else { logger.debug("é¶ä»¶å·²åå¨: {}", parts.getPartsId()); } } private void saveProcessSpec(ProcessSpecVersion processSpec) { if (psvMapper.selectById(processSpec.getId()) == null) { psvMapper.insert(processSpec); logger.debug("å·¥èºè§ç¨å·²ä¿å: {}", processSpec.getId()); } else { logger.debug("å·¥èºè§ç¨å·²åå¨: {}", processSpec.getId()); } } private void saveProcess(ProcessStream process) { if (processMapper.selectById(process.getProcessId()) == null) { processMapper.insert(process); logger.debug("å·¥åºå·²ä¿å: {}", process.getProcessId()); } else { logger.debug("å·¥åºå·²åå¨: {}", process.getProcessId()); } } private void saveWorkSteps(WorkStep workStep) { if (workStepMapper.selectById(workStep.getId()) == null) { workStepMapper.insert(workStep); logger.debug("å·¥æ¥å·²ä¿å: {}", workStep.getId()); } else { logger.debug("å·¥æ¥å·²åå¨: {}", workStep.getId()); } } private void saveTreePath(List<ProductMix> productMixList){ for (ProductMix productMix : productMixList) { if (productMixMapper.selectById(productMix.getId()) == null) { productMixMapper.insert(productMix); logger.debug("产åç»åå·²ä¿å: {}", productMix.getId()); } else { logger.debug("产åç»åå·²åå¨: {}", productMix.getId()); } } } private void savePermissionStreamNewList(List<PermissionStreamNew> permissionStreamNewList) { for (PermissionStreamNew permissionStreamNew : permissionStreamNewList) { if (permissionStreamNew.getUserId() != null) { String id=sysUserService.getUserByName(permissionStreamNew.getUserId()).getId(); if (id!=null){ permissionStreamNew.setUserId(id); } } if (permissionStreamNew.getDepartId() != null) { String id=mdcProductionService.findByOrgCode(permissionStreamNew.getDepartId()).getId(); if (id!=null){ permissionStreamNew.setDepartId(id); } } permissionStreamNewMapper.insert(permissionStreamNew); logger.debug("æéå·²ä¿å: {}", permissionStreamNew.getId()); } //åæ¹æ·»å 产åãé¨ä»¶ãé¶ä»¶ãå·¥èºè§ç¨ãå·¥åºãå·¥æ¥æé permissionStreamNewList.forEach(item -> { switch (item.getBusinessType()){ case "1": if (StrUtil.isNotEmpty(item.getUserId())){ ProductPermission productPermission = new ProductPermission(); productPermission.setProductId(item.getBusinessId()); productPermission.setUserId(item.getUserId()); productPermissionService.save(productPermission); }else { ProductDepartment productDepartment = new ProductDepartment(); productDepartment.setProductId(item.getBusinessId()); productDepartment.setDepartId(item.getDepartId()); productDepartmentService.save(productDepartment); } break; case "2": if (StrUtil.isNotEmpty(item.getUserId())){ ComponentPermission componentPermission = new ComponentPermission(); componentPermission.setComponentId(item.getBusinessId()); componentPermission.setUserId(item.getUserId()); componentPermissionService.save(componentPermission); }else { ComponentDepartment componentDepartment = new ComponentDepartment(); componentDepartment.setComponentId(item.getBusinessId()); componentDepartment.setDepartId(item.getDepartId()); componentDepartmentService.save(componentDepartment); } break; case "3": if (StrUtil.isNotEmpty(item.getUserId())){ PartsPermission partsPermission = new PartsPermission(); partsPermission.setPartsId(item.getBusinessId()); partsPermission.setUserId(item.getUserId()); partsPermissionService.save(partsPermission); }else { PartsDepartment partsDepartment = new PartsDepartment(); partsDepartment.setPartsId(item.getBusinessId()); partsDepartment.setDepartId(item.getDepartId()); partsDepartmentService.save(partsDepartment); } break; case "4": if (StrUtil.isNotEmpty(item.getUserId())){ ProcessSpecVersionPermission processSpecVersionPermission = new ProcessSpecVersionPermission(); processSpecVersionPermission.setPsvId(item.getBusinessId()); processSpecVersionPermission.setUserId(item.getUserId()); processSpecVersionPermissionService.save(processSpecVersionPermission); }else { ProcessSpecVersionDepartment processSpecVersionDepartment = new ProcessSpecVersionDepartment(); processSpecVersionDepartment.setPsvId(item.getBusinessId()); processSpecVersionDepartment.setDepartId(item.getDepartId()); processSpecVersionDepartmentService.save(processSpecVersionDepartment); } break; case "5": if (StrUtil.isNotEmpty(item.getUserId())){ ProcessionPermission processionPermission = new ProcessionPermission(); processionPermission.setProcessId(item.getBusinessId()); processionPermission.setUserId(item.getUserId()); processStreamPermissionService.save(processionPermission); }else { ProcessionDepartment processionDepartment = new ProcessionDepartment(); processionDepartment.setProcessId(item.getBusinessId()); processionDepartment.setDepartId(item.getDepartId()); processionDepartmentService.save(processionDepartment); } break; case "6": if (StrUtil.isNotEmpty(item.getUserId())){ WorkStepPermission workStepPermission = new WorkStepPermission(); workStepPermission.setStepId(item.getBusinessId()); workStepPermission.setUserId(item.getUserId()); workStepPermissionService.save(workStepPermission); }else { WorkStepDepartment workStepDepartment = new WorkStepDepartment(); workStepDepartment.setStepId(item.getBusinessId()); workStepDepartment.setDepartId(item.getDepartId()); workStepDepartmentService.save(workStepDepartment); } break; default: } }); } private void saveDeviceManagement(DeviceManagement deviceManagement) { if (deviceManagementMapper.selectById(deviceManagement.getId()) == null) { deviceManagementMapper.insert(deviceManagement); logger.debug("设å¤ç±»ä¿¡æ¯å·²ä¿å: {}", deviceManagement.getId()); } else { logger.debug("设å¤ç±»ä¿¡æ¯å·²åå¨: {}", deviceManagement.getId()); } } private void saveDeviceType(DeviceType deviceType) { if (deviceTypeMapper.selectById(deviceType.getId()) == null) { deviceTypeMapper.insert(deviceType); logger.debug("设å¤ç±»å·²ä¿å: {}", deviceType.getId()); } else { logger.debug("设å¤ç±»å·²åå¨: {}", deviceType.getId()); } } private void saveDocInfo(DocInfo docInfo) { if (docInfoMapper.selectById(docInfo.getDocId()) == null) { docInfoMapper.insert(docInfo); logger.debug("ææ¡£å·²ä¿å: {}", docInfo.getDocId()); } else { logger.debug("ææ¡£å·²åå¨: {}", docInfo.getDocId()); } } private void saveDocFile(DocFile docFile) { if (docFileMapper.selectById(docFile.getFileId()) == null) { docFileMapper.insert(docFile); logger.debug("ææ¡£æä»¶å·²ä¿å: {}", docFile.getFileId()); } else { logger.debug("ææ¡£æä»¶å·²åå¨: {}", docFile.getFileId()); } } private void saveDocRelative(DocRelative docRelative) { if (docRelativeMapper.selectById(docRelative.getId()) == null) { docRelativeMapper.insert(docRelative); logger.debug("ææ¡£å¯¹åºå ³ç³»å·²ä¿å: {}", docRelative.getId()); } else { logger.debug("ææ¡£å¯¹åºå ³ç³»å·²åå¨: {}", docRelative.getId()); } } private void saveCutterList(List<Cutter> cutterList) { for (Cutter cutter : cutterList) { if (cutterMapper.selectById(cutter.getId()) == null) { cutterMapper.insert(cutter); logger.debug("åå ·å·²ä¿å: {}", cutter.getId()); } else { cutterMapper.updateById(cutter); } } } private void saveGuideCardBatch(GuideCardBatch guideCardBatch) { if (guideCardBatchMapper.selectById(guideCardBatch.getId()) == null) { guideCardBatchMapper.insert(guideCardBatch); logger.debug("åçæ¹æ¬¡å·²ä¿å: {}", guideCardBatch.getId()); } else { logger.debug("åçæ¹æ¬¡å·²åå¨: {}", guideCardBatch.getId()); } } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FileFerryService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,224 @@ package org.jeecg.modules.dnc.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import liquibase.pro.packaged.S; import org.apache.commons.lang3.StringUtils; import org.jeecg.modules.dnc.dto.ComponentHierarchy; import org.jeecg.modules.dnc.dto.TransferPackage; import org.jeecg.modules.dnc.entity.*; import org.jeecg.modules.dnc.exception.ExceptionCast; import org.jeecg.modules.dnc.mapper.DocRelativeMapper; import org.jeecg.modules.dnc.response.ActivitiCode; import org.jeecg.modules.dnc.response.DocumentCode; import org.jeecg.modules.dnc.service.IDocClassificationService; import org.jeecg.modules.dnc.service.IDocFileService; import org.jeecg.modules.dnc.service.IDocInfoService; import org.jeecg.modules.dnc.service.IDocRelativeService; import org.jeecg.modules.dnc.utils.CompressionUtils; import org.jeecg.modules.dnc.utils.JsonUtils; import org.jeecg.modules.dnc.utils.file.FileUtilS; import org.jeecg.modules.dncFlow.service.IAssignFileStreamService; import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; import org.jeecg.modules.system.service.IMdcProductionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; @Service public class FileFerryService { private static final Logger logger = LoggerFactory.getLogger(FileFerryService.class); @Value("${deploy.secretFolder}") private String ferryPath; @Value("${fileHomePath}") private String fileHomePath; @Autowired private MdcEquipmentMapper mdcEquipmentMapper; @Autowired private IMdcProductionService mdcProductionService; @Autowired private IDocInfoService docInfoService; @Autowired private IDocClassificationService classificationService; @Autowired private IDocRelativeService docRelativeService; public TransferPackage importData(String filePath) { try { // 1. 读åæä»¶ Path path = Paths.get(filePath); String fileName = path.getFileName().toString(); byte[] encrypted = Files.readAllBytes(path); logger.debug("读åæä»¶å®æ, 大å°: {} åè", encrypted.length); // 2. è§£å¯ (å½å已注é) // byte[] compressed = securityService.decrypt(encrypted); // 3. è§£å缩 // byte[] jsonBytes = CompressionUtils.gzipDecompress(encrypted); String json = new String(encrypted, StandardCharsets.UTF_8); logger.debug("è§£åç¼©å®æ, JSONé¿åº¦: {} å符", json.length()); // è®°å½JSONå 容ç¨äºè°è¯ logger.trace("åå§JSONå 容:\n{}", json); // 4. JSONååºåå logger.debug("å¼å§ååºåå..."); TransferPackage pkg = JsonUtils.fromJson(json, TransferPackage.class); // 5. å¤çæä»¶å - 示ä¾: 10A20250614000026_3102038 String[] split = fileName.split("_"); if (split.length < 2) { throw new IllegalArgumentException("æ æçæä»¶åæ ¼å¼: " + fileName); } String id = split[0]; String equipmentId = split[1].split("\\.")[0]; // æååç¼åæ°åé¨å int aIndex = id.indexOf("A"); if (aIndex == -1 || aIndex == id.length() - 1) { throw new IllegalArgumentException("æ æçIDæ ¼å¼: " + id); } String prefix = id.substring(0, aIndex + 1); String numericPart = id.substring(aIndex + 1); // 计ç®åä¸ä¸ªæä»¶å long number = Long.parseLong(numericPart); number--; // è·ååä¸ä¸ªåºåå· // ä¿æç¸å使°æ ¼å¼ String newNumeric = String.format("%0" + numericPart.length() + "d", number); String ncFileName = prefix + newNumeric + "_" + equipmentId+".NC"; String ncFilePath = path.getParent().resolve(ncFileName).toString(); // 6. è·åæä»¶å¤å¶ç®æ è·¯å¾ DocFile docFile = pkg.getTraceChain().getDocFile(); DocInfo docInfo = pkg.getTraceChain().getDocInfo(); if (docFile == null) { throw new IllegalStateException("ä¼ è¾å ä¸ç¼ºå°ææ¡£æä»¶ä¿¡æ¯"); } // æå»ºç®æ è·¯å¾ String targetDirectory = fileHomePath + docFile.getFilePath(); String targetPath = Paths.get(targetDirectory, docFile.getFileEncodeName()).toString(); // ç¡®ä¿ç®æ ç®å½åå¨ File targetDir = new File(targetDirectory); if (!targetDir.exists() && !targetDir.mkdirs()) { throw new IOException("æ æ³åå»ºç®æ ç®å½: " + targetDirectory); } // 7. å¤å¶æä»¶å¹¶éå½å logger.info("å¤å¶æä»¶: {} â {}", ncFilePath, targetPath); Path source = Paths.get(ncFilePath); Files.copy(source, Paths.get(targetPath), StandardCopyOption.REPLACE_EXISTING); // 8. æ¥è¯¢è®¾å¤id MdcEquipment mdcEquipment=mdcEquipmentMapper.selectOne(new QueryWrapper<MdcEquipment>().eq("equipment_id",equipmentId)); if (mdcEquipment == null) { throw new IllegalArgumentException("æ æç设å¤ID: " + equipmentId); } // 9.ä¼ è¾æä»¶å°è®¾å¤ä¸ List<String> strings = mdcProductionService.findListParentTreeAll(mdcEquipment.getId()); if (strings != null && !strings.isEmpty()) { DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(docInfo.getDocId(), 7, mdcEquipment.getId()); if (deviceDoc == null) { DocClassification classification = classificationService.getByCode("send"); if(classification == null) ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR); DocRelative docRelative = new DocRelative(); docRelative.setDocId(docInfo.getDocId()); docRelative.setClassificationId(classification.getClassificationId()); docRelative.setAttributionType(7); docRelative.setAttributionId(mdcEquipment.getId()); docRelativeService.save(docRelative); } String sendPath = StringUtils.join(strings.toArray(), "/"); boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(), sendPath + "/" + mdcEquipment.getEquipmentId(), docFile.getFileEncodeName(), docFile.getFileName(), docFile.getFileSuffix()); if (!copyFileNc) { ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); } else { FileUtilS.deleteZipFromToSend(sendPath + "/" + mdcEquipment.getEquipmentId(), docFile.getFileName(), docFile.getFileSuffix()); } } else { throw new RuntimeException("æä»¶ä¼ è¾è·¯å¾è·å失败"); } // 10.å é¤ä¸´æ¶NCæä»¶ä¸jsonæä»¶ logger.info("å é¤ä¸´æ¶æä»¶: {}", ncFilePath); Files.delete(source); Files.delete(path); return JsonUtils.fromJson(json, TransferPackage.class); } catch (NumberFormatException e) { throw new RuntimeException("æä»¶åä¸çæ°åæ ¼å¼æ æ: " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("æä»¶æä½å¤±è´¥: " + e.getMessage(), e); } catch (Exception e) { logger.error("æä»¶å¯¼å ¥å¤±è´¥ [è·¯å¾: {}]", filePath, e); throw new RuntimeException("æä»¶å¯¼å ¥å¤±è´¥: " + e.getMessage(), e); } } private void compressHierarchy(TransferPackage pkg) { if (pkg.getTraceChain() == null || pkg.getTraceChain().getComponentHierarchy() == null || pkg.getTraceChain().getComponentHierarchy().getComponents().size() < 4) { return; } ComponentHierarchy hierarchy = pkg.getTraceChain().getComponentHierarchy(); List<ComponentInfo> compressed = new ArrayList<>(); // ä¿çæ ¹é¨ä»¶ compressed.add(hierarchy.getComponents().get(0)); // ä¿çå ³é®ä¸é´èç¹ int step = Math.max(1, hierarchy.getComponents().size() / 3); for (int i = step; i < hierarchy.getComponents().size() - 1; i += step) { compressed.add(hierarchy.getComponents().get(i)); } // ä¿çå¶åé¨ä»¶ compressed.add(hierarchy.getLeafComponent()); // æ´æ°å±çº§ hierarchy.getComponents().clear(); hierarchy.getComponents().addAll(compressed); } private String generateFilename(TransferPackage.DataType type, String id) { return String.format("%s_%s_%d.ferry", type.name().toLowerCase(), id, System.currentTimeMillis()); } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsInfoServiceImpl.java
@@ -151,8 +151,8 @@ boolean b = super.updateById(partsInfo); //åæ¥ä¿®æ¹ç»ææ ProductMix productMix = productMixService.getById(Long.parseLong(id)); productMix.setName(partsInfo.getPartsName()); productMix.setCode(partsInfo.getPartsCode()); productMix.setTreeName(partsInfo.getPartsName()); productMix.setTreeCode(partsInfo.getPartsCode()); productMixService.updateById(productMix); if(!b) return false; lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessSpecVersionServiceImpl.java
@@ -205,8 +205,8 @@ boolean b = super.updateById(processSpecVersion); //åæ¥ä¿®æ¹ç»ææ ProductMix productMix = productMixService.getById(Long.parseLong(id)); productMix.setName(processSpecVersion.getProcessSpecVersionName()); productMix.setCode(processSpecVersion.getProcessSpecVersionCode()); productMix.setTreeName(processSpecVersion.getProcessSpecVersionName()); productMix.setTreeCode(processSpecVersion.getProcessSpecVersionCode()); productMixService.updateById(productMix); if(!b) return false; lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java
@@ -176,8 +176,8 @@ boolean b = super.updateById(stream); //åæ¥ä¿®æ¹ç»ææ ProductMix productMix = productMixService.getById(Long.parseLong(id)); productMix.setName(stream.getProcessName()); productMix.setCode(stream.getProcessCode()); productMix.setTreeName(stream.getProcessName()); productMix.setTreeCode(stream.getProcessCode()); productMixService.updateById(productMix); if(!b) ExceptionCast.cast(CommonCode.FAIL); lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductInfoServiceImpl.java
@@ -164,8 +164,8 @@ boolean b = super.updateById(productInfo); //åæ¥ä¿®æ¹ç»ææ ProductMix productMix = productMixService.getById(Long.parseLong(id)); productMix.setName(productInfo.getProductName()); productMix.setCode(productInfo.getProductNo()); productMix.setTreeName(productInfo.getProductName()); productMix.setTreeCode(productInfo.getProductNo()); productMixService.updateById(productMix); if (!b) return false; lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/SecurityService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,48 @@ package org.jeecg.modules.dnc.service.impl; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.security.Security; @Service public class SecurityService { private static final String ALGORITHM = "SM4/ECB/PKCS5Padding"; private final String secretKey; static { Security.addProvider(new BouncyCastleProvider()); } @Autowired public SecurityService(@Value("${security.encryption-key}") String secretKey) { this.secretKey = secretKey; } public byte[] encrypt(byte[] data) { try { Cipher cipher = Cipher.getInstance(ALGORITHM, "BC"); SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "SM4"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); return cipher.doFinal(data); } catch (Exception e) { throw new RuntimeException("å å¯å¤±è´¥", e); } } public byte[] decrypt(byte[] encryptedData) { try { Cipher cipher = Cipher.getInstance(ALGORITHM, "BC"); SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "SM4"); cipher.init(Cipher.DECRYPT_MODE, keySpec); return cipher.doFinal(encryptedData); } catch (Exception e) { throw new RuntimeException("è§£å¯å¤±è´¥", e); } } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/WorkStepServiceImpl.java
@@ -175,8 +175,8 @@ ExceptionCast.cast(ProcessInfoCode.WORKSTEP_NOT_EXIST); //åæ¥ä¿®æ¹ç»ææ ProductMix productMix = productMixService.getById(Long.parseLong(id)); productMix.setName(workStep.getStepName()); productMix.setCode(workStep.getStepCode()); productMix.setTreeName(workStep.getStepName()); productMix.setTreeCode(workStep.getStepCode()); productMixService.updateById(productMix); return super.updateById(workStep); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/utils/CompressionUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,35 @@ package org.jeecg.modules.dnc.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; public class CompressionUtils { public static byte[] gzipCompress(byte[] data) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(bos)) { gzip.write(data); gzip.finish(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException("GZIPå缩失败", e); } } public static byte[] gzipDecompress(byte[] compressed) { try (ByteArrayInputStream bis = new ByteArrayInputStream(compressed); GZIPInputStream gzip = new GZIPInputStream(bis); ByteArrayOutputStream bos = new ByteArrayOutputStream()) { byte[] buffer = new byte[1024]; int len; while ((len = gzip.read(buffer)) > 0) { bos.write(buffer, 0, len); } return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException("GZIPè§£å失败", e); } } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/utils/JsonUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,48 @@ package org.jeecg.modules.dnc.utils; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.text.SimpleDateFormat; public class JsonUtils { private static final ObjectMapper objectMapper = createObjectMapper(); private static ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); // é ç½®æ¥ææ ¼å¼ mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); mapper.registerModule(new JavaTimeModule()); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // é ç½®åºååé项 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // é ç½®ååºååé项 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); return mapper; } public static String toJson(Object object) { try { return objectMapper.writeValueAsString(object); } catch (Exception e) { throw new RuntimeException("JSONåºåå失败: " + e.getMessage(), e); } } public static <T> T fromJson(String json, Class<T> valueType) { try { return objectMapper.readValue(json, valueType); } catch (Exception e) { throw new RuntimeException("JSONååºåå失败: " + e.getMessage() + "\nJSONå 容: " + json, e); } } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/utils/TreeBuilder.java
@@ -108,8 +108,8 @@ ProductMix newNode = new ProductMix( node.getId(), node.getParentId(), node.getName(), node.getCode(), node.getTreeName(), node.getTreeCode(), node.getType(), node.getCreateTime() ); lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/IMdcProductionService.java
@@ -175,4 +175,11 @@ * @return */ List<String> findProIdsByUId(String userId, List<String> allProductionIds); /** * æ ¹æ®äº§çº¿orgCodeæ¥è¯¢äº§çº¿ * @param orgCode * @return */ MdcProduction findByOrgCode(String orgCode); } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcProductionServiceImpl.java
@@ -627,4 +627,9 @@ super.update(updateWrapper); } } @Override public MdcProduction findByOrgCode(String orgCode){ return this.baseMapper.selectOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getOrgCode, orgCode)); } }