lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/constant/DncPassLogPassType.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,39 @@ package org.jeecg.modules.dnc.constant; public enum DncPassLogPassType { //NCæä»¶ DOCUMENT("01", "ncæä»¶"), //ncæä»¶ NCFILE("02", "NCæä»¶"), //产åç»ææ PRODUCTSTRUCTURE("03", "产åç»ææ "), //ç¨åºå 工确认表 PROGRAMPROCESSING("04", "ç¨åºå 工确认表"); private String code; private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } DncPassLogPassType() { } DncPassLogPassType(String code, String name) { this.code = code; this.name = name; } } 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,32 @@ 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.DocRelative; @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
@@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; import java.io.Serializable; @@ -14,7 +13,6 @@ import java.util.Date; import java.util.List; @Getter @Data @NoArgsConstructor @TableName(value = "nc_product_mix") @@ -29,13 +27,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 +41,20 @@ //å±ç¤ºåç§° 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 treeCode, Integer type, Date createTime) { this.id = id; this.parentId = parentId; this.name = name; this.code = code; this.treeName = treeName; this.treeCode = treeCode; this.type = type; this.children = new ArrayList<>(); this.label="["+code+"]"+name; this.label="["+treeCode+"]"+treeName; this.createTime = createTime; } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/ext/NcTxtFilePathInfo.java
@@ -24,6 +24,18 @@ private Integer fileAddOrDelete; /*æä»¶å¤§å°*/ private String fileSize; /*äº§åæ·»å æ§è¡è¯å¥*/ private String productAddSql; /*é¨ä»¶æ·»å æ§è¡è¯å¥*/ private String componentAddSql; /*é¶ä»¶æ·»å æ§è¡è¯å¥*/ private String partAddSql; /*å·¥èºè§ç¨çæ¬æ·»å æ§è¡è¯å¥*/ private String processVersionAddSql; /*å·¥åºçæ¬æ·»å æ§è¡è¯å¥*/ private String processAddSql; /*å·¥æ¥çæ¬æ·»å æ§è¡è¯å¥*/ private String processStepAddSql; @Override public String toString() { lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/ComponentInfoMapper.java
@@ -1,9 +1,9 @@ package org.jeecg.modules.dnc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.jeecg.modules.dnc.dto.ComponentExt; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.jeecg.modules.dnc.dto.ComponentExt; import org.jeecg.modules.dnc.entity.ComponentInfo; import java.util.List; @@ -38,4 +38,10 @@ */ List<ComponentExt> getByParentIdAndUserPerms(@Param("parentId") String parentId, @Param("userId") String userId); @Select("SELECT * FROM nc_component_info WHERE component_id = #{componentId}") ComponentInfo selectById(@Param("componentId") String componentId); // é彿¥è¯¢é¨ä»¶å±çº§ç»æ List<ComponentInfo> findComponentHierarchy(@Param("componentId") String componentId); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/PartsInfoMapper.java
@@ -1,8 +1,9 @@ package org.jeecg.modules.dnc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.jeecg.modules.dnc.entity.PartsInfo; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.jeecg.modules.dnc.entity.PartsInfo; import java.util.List; @@ -14,4 +15,7 @@ * @return */ List<PartsInfo> getByUserPerms(@Param("userId") String userId); @Select("SELECT * FROM nc_parts_info WHERE parts_id = #{partsId}") PartsInfo selectById(@Param("partsId") String partsId); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/ProcessSpecVersionMapper.java
@@ -1,8 +1,9 @@ package org.jeecg.modules.dnc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import io.lettuce.core.dynamic.annotation.Param; import org.apache.ibatis.annotations.Select; import org.jeecg.modules.dnc.entity.ProcessSpecVersion; import org.jeecg.modules.dnc.entity.WorkStep; import java.util.List; @@ -14,4 +15,7 @@ * @return */ List<ProcessSpecVersion> getByUserPerms(String userId); @Select("SELECT * FROM nc_process_spec_version WHERE id = #{id}") ProcessSpecVersion selectById(@Param("id") String id); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/ProcessStreamMapper.java
@@ -1,6 +1,8 @@ package org.jeecg.modules.dnc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import io.lettuce.core.dynamic.annotation.Param; import org.apache.ibatis.annotations.Select; import org.jeecg.modules.dnc.entity.ProcessStream; import java.util.List; @@ -22,4 +24,6 @@ */ List<ProcessStream> findByPartsAndComponents(String productId, List<String> componentIds, List<String> partsIds); @Select("SELECT * FROM nc_process_stream WHERE process_id = #{processId}") ProcessStream selectById(@Param("processId") String processId); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/ProductInfoMapper.java
@@ -1,8 +1,9 @@ package org.jeecg.modules.dnc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.jeecg.modules.dnc.entity.ProductInfo; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.jeecg.modules.dnc.entity.ProductInfo; import java.util.List; @@ -13,4 +14,7 @@ * @return */ List<ProductInfo> getByUserPerms(@Param("userId") String userId); @Select("SELECT * FROM nc_product_info WHERE product_id = #{productId}") ProductInfo selectById(@Param("productId") String productId); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/ProductMixMapper.java
@@ -1,7 +1,29 @@ package org.jeecg.modules.dnc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import io.lettuce.core.dynamic.annotation.Param; import org.apache.ibatis.annotations.Select; import org.jeecg.modules.dnc.entity.ProductMix; public interface ProductMixMapper extends BaseMapper<ProductMix> { @Select("SELECT * FROM nc_product_mix WHERE id = #{productId} AND tree_type = 1") ProductMix findByProductId(@Param("productId") String productId); @Select("SELECT * FROM nc_product_mix WHERE id = #{componentId} AND tree_type = 2") ProductMix findByComponentId(@Param("componentId") String componentId); @Select("SELECT * FROM nc_product_mix WHERE id = #{partsId} AND tree_type = 3") ProductMix findByPartsId(@Param("partsId") String partsId); @Select("SELECT * FROM nc_product_mix WHERE id = #{operationId} AND tree_type = 4") ProductMix findByOperationId(@Param("operationId") String operationId); @Select("SELECT * FROM nc_product_mix WHERE id = #{processId} AND tree_type = 5") ProductMix findByProcessId(@Param("operationId") String processId); @Select("SELECT * FROM nc_product_mix WHERE id = #{worksiteId} AND tree_type = 6") ProductMix findByWorksiteId(@Param("operationId") String worksiteId); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/WorkStepMapper.java
@@ -1,7 +1,8 @@ package org.jeecg.modules.dnc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.jeecg.modules.dnc.entity.SynchronizedFlag; import io.lettuce.core.dynamic.annotation.Param; import org.apache.ibatis.annotations.Select; import org.jeecg.modules.dnc.entity.WorkStep; import java.util.List; @@ -13,4 +14,10 @@ * @return */ List<WorkStep> getByUserPerms(String userId); @Select("SELECT * FROM nc_work_step WHERE id = #{workStepId}") WorkStep selectById(@Param("workStepId") String workStepId); @Select("SELECT * FROM nc_work_step WHERE process_id = #{processId}") List<WorkStep> selectByProcessId(@Param("processId") String processId); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/xml/ComponentInfoMapper.xml
@@ -158,4 +158,26 @@ on comp.component_id=s.component_id where delete_flag = 0 and parent_id=#{parentId} </select> <select id="findComponentHierarchy" resultType="org.jeecg.modules.dnc.entity.ComponentInfo"> WITH component_tree AS ( SELECT *, 0 AS LEVEL FROM nc_component_info WHERE component_id = #{componentId} UNION ALL SELECT c.*, ct.level + 1 FROM nc_component_info c INNER JOIN component_tree ct ON c.component_id = ct.parent_id ) SELECT * FROM component_tree ORDER BY LEVEL ASC </select> </mapper> 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/DataPackageStrategy.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,13 @@ package org.jeecg.modules.dnc.service; import org.jeecg.modules.dnc.dto.TransferPackage; // æ°æ®å°è£ çç¥æ¥å£ public interface DataPackageStrategy { /** * å°è£ ä¸å¡æ°æ®ä¸ºä¼ è¾å * @param id ä¸å¡å®ä½IDï¼å·¥åºIDæå·¥æ¥IDï¼ * @return å°è£ 好çä¼ è¾å */ TransferPackage packageData(String id); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IProductInfoService.java
@@ -221,7 +221,7 @@ /** * è·åå ·ä½å±çº§å®ä½ * @param id,type * @param id,treeType * @return */ Result<?> getTreeById(String id, Integer type); lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IProductMixService.java
@@ -1,8 +1,6 @@ package org.jeecg.modules.dnc.service; import cn.hutool.core.lang.tree.Tree; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.dnc.entity.ProductMix; import java.util.List; @@ -10,8 +8,20 @@ public interface IProductMixService extends IService<ProductMix> { //è·åå°è£ 产åç»ææ public List<ProductMix> getTree(); List<ProductMix> getTree(); //模æçæäº§åç»ææ /** * æ¥è¯¢å¯¹åºidçææç¶çº§(æéåé 使ç¨) * @param id * @return */ List<ProductMix> getParentList(String id); /** * æ¥è¯¢å¯¹åºidçææåèç¹(æéåé 使ç¨) * @param id * @return */ List<ProductMix> getChildrenList(String id); } 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,455 @@ package org.jeecg.modules.dnc.service.impl; import cn.hutool.core.util.StrUtil; import com.jeecg.weibo.exception.BusinessException; 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/DataPackageService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,36 @@ package org.jeecg.modules.dnc.service.impl; import org.jeecg.modules.dnc.dto.TransferPackage; import org.jeecg.modules.dnc.service.DataPackageStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.EnumMap; import java.util.List; import java.util.Map; @Service public class DataPackageService { private final Map<TransferPackage.DataType, DataPackageStrategy> strategies; @Autowired public DataPackageService(List<DataPackageStrategy> strategyList) { strategies = new EnumMap<>(TransferPackage.DataType.class); strategyList.forEach(strategy -> { if (strategy instanceof ProcessPackageStrategy) { strategies.put(TransferPackage.DataType.PROCESS, strategy); } else if (strategy instanceof WorkStepPackageStrategy) { strategies.put(TransferPackage.DataType.WORKSTEP, strategy); } }); } public TransferPackage packageData(TransferPackage.DataType type, String id) { DataPackageStrategy strategy = strategies.get(type); if (strategy == null) { throw new IllegalArgumentException("䏿¯æçæ°æ®ç±»å: " + type); } return strategy.packageData(id); } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DevicePermissionServiceImpl.java
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DocInfoServiceImpl.java
@@ -342,10 +342,20 @@ @Override @Transactional(rollbackFor = {Exception.class}) public boolean addDocInfoAnalysisSmwNcService(String pathFile,File fileRec){ //todo ç¨åºåä¼ //确认解æç®å½ return true; } /** * ææ¡£è§£æ * todo ä¿®æ¹å建æä»¶å ³èå ³ç³»ï¼æ¹æåºå®docIdï¼å»é¤å建DocInfo * @param equipmentId * @param fileRec * @param fileNameSuffix * @param fileNameNew * @param filePath * @return */ @Override @Transactional(rollbackFor = {Exception.class}) public boolean addDocInfoRecService(String equipmentId,File fileRec,String fileNameSuffix,String fileNameNew,String filePath ) { lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FileFerryService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,254 @@ package org.jeecg.modules.dnc.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.response.ActivitiCode; import org.jeecg.modules.dnc.response.DocumentCode; import org.jeecg.modules.dnc.service.IDocClassificationService; import org.jeecg.modules.dnc.service.IDocInfoService; import org.jeecg.modules.dnc.service.IDocRelativeService; import org.jeecg.modules.dnc.utils.JsonUtils; import org.jeecg.modules.dnc.utils.file.FileUtilS; 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 final DataPackageService dataPackageService; private final SecurityService securityService; 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 IDocClassificationService classificationService; @Autowired private IDocRelativeService docRelativeService; @Autowired private IDocInfoService docInfoService; @Autowired public FileFerryService(DataPackageService dataPackageService, SecurityService securityService) { this.dataPackageService = dataPackageService; this.securityService = securityService; } public String exportData(TransferPackage.DataType type, String id,String fileName) { // 1. è·åå°è£ æ°æ® TransferPackage transferPackage = dataPackageService.packageData(type, id); // 2. å缩å±çº§ç»æ compressHierarchy(transferPackage); // 3. JSONåºåå String json = JsonUtils.toJson(transferPackage); // // 4. å缩å å¯ // byte[] compressed = CompressionUtils.gzipCompress(json.getBytes(StandardCharsets.UTF_8)); // byte[] encrypted = securityService.encrypt(compressed); //ææ¶ä¸å å¯ byte[] compressed = json.getBytes(StandardCharsets.UTF_8); // 5. çææä»¶ Path filePath = Paths.get(ferryPath,fileName); try { Files.createDirectories(filePath.getParent()); Files.write(filePath, compressed); return filePath.toString(); } catch (IOException e) { throw new RuntimeException("æä»¶åå ¥å¤±è´¥", e); } } 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/FullHierarchyTraceService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,236 @@ package org.jeecg.modules.dnc.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum; import org.jeecg.modules.dnc.dto.ComponentHierarchy; import org.jeecg.modules.dnc.dto.ProcessTraceChain; import org.jeecg.modules.dnc.entity.*; import org.jeecg.modules.dnc.mapper.*; import org.jeecg.modules.dnc.service.IPermissionStreamNewService; import org.jeecg.modules.system.service.IMdcProductionService; import org.jeecg.modules.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @Service public class FullHierarchyTraceService { @Autowired private ProductMixMapper productMixMapper; @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 DeviceTypeMapper deviceTypeMapper; @Autowired private DeviceManagementMapper deviceManagementMapper; @Autowired private DocInfoMapper docInfoMapper; @Autowired private DocFileMapper docFileMapper; @Autowired private CutterMapper cutterMapper; @Autowired private GuideCardBatchMapper guideCardBatchMapper; @Autowired private IPermissionStreamNewService permissionStreamNewService; @Autowired private ISysUserService sysUserService; @Autowired private IMdcProductionService mdcProductionService; public ProcessTraceChain traceFromProcess(DocRelative docRelative) { ProcessTraceChain chain = initChainWithDocInfo(docRelative); DeviceType deviceType = deviceTypeMapper.selectById(docRelative.getAttributionId()); chain.setDeviceType(deviceType); if (isProcessType(deviceType)) { chain.setDeviceManagement(deviceManagementMapper.selectById(deviceType.getDeviceManagementId())); traceProcessChain(chain, deviceType.getAttributionId()); } completeChainWithProductInfo(chain); List<ProductMix> productMixList=buildFullTreePath(chain); chain.setTreePath(productMixList); chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList)); return chain; } public ProcessTraceChain traceFromWorkStep(DocRelative docRelative) { ProcessTraceChain chain = initChainWithDocInfo(docRelative); DeviceType deviceType = deviceTypeMapper.selectById(docRelative.getAttributionId()); chain.setDeviceType(deviceType); if (isWorkSiteType(deviceType)) { chain.setDeviceManagement(deviceManagementMapper.selectById(deviceType.getDeviceManagementId())); traceWorkStepChain(chain, deviceType.getAttributionId()); } completeChainWithProductInfo(chain); List<ProductMix> productMixList=buildFullTreePath(chain); chain.setTreePath(productMixList); chain.setPermissionStreamNewList(buildFullTreePathPermission(productMixList)); return chain; } private ProcessTraceChain initChainWithDocInfo(DocRelative docRelative) { ProcessTraceChain chain = ProcessTraceChain.builder().docRelative(docRelative).build(); Optional.ofNullable(docInfoMapper.selectById(docRelative.getDocId())) .ifPresent(doc -> { chain.setDocInfo(doc); chain.setDocFile(docFileMapper.selectById(doc.getPublishFileId())); chain.setCutterList(getCuttersByDocId(doc.getDocId())); getLatestGuideCardBatch(doc.getDocId()).ifPresent(chain::setGuideCardBatch); }); return chain; } private List<Cutter> getCuttersByDocId(String docId) { return cutterMapper.selectList(new QueryWrapper<Cutter>().eq("doc_id", docId)); } private Optional<GuideCardBatch> getLatestGuideCardBatch(String docId) { List<GuideCardBatch> batches = guideCardBatchMapper.selectList( new QueryWrapper<GuideCardBatch>() .eq("doc_id", docId) .orderByDesc("SUBSTRING(serial_number, LEN(serial_number)-3, 4)")); return CollectionUtils.isEmpty(batches) ? Optional.empty() : Optional.of(batches.get(0)); } private boolean isProcessType(DeviceType deviceType) { return deviceType != null && Objects.equals(deviceType.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode()); } private boolean isWorkSiteType(DeviceType deviceType) { return deviceType != null && Objects.equals(deviceType.getAttributionType(), DocAttributionTypeEnum.WORKSITE.getCode()); } private void traceProcessChain(ProcessTraceChain chain, String processId) { ProcessStream process = processMapper.selectById(processId); if (process == null) return; chain.setProcess(process); if (process.getPsvId() != null) { ProcessSpecVersion psv = psvMapper.selectById(process.getPsvId()); chain.setProcessSpec(psv); if (psv != null && psv.getPartsId() != null) { PartsInfo parts = partsMapper.selectById(psv.getPartsId()); chain.setParts(parts); if (parts != null && parts.getComponentId() != null) { chain.setComponentHierarchy(traceComponentHierarchy(parts.getComponentId())); } } } else if (process.getComponentId() != null) { chain.setComponentHierarchy(traceComponentHierarchy(process.getComponentId())); } } private void traceWorkStepChain(ProcessTraceChain chain, String workStepId) { WorkStep workStep = workStepMapper.selectById(workStepId); if (workStep == null) return; chain.setWorkStep(workStep); traceProcessChain(chain, workStep.getProcessId()); } private ComponentHierarchy traceComponentHierarchy(String componentId) { ComponentHierarchy hierarchy = new ComponentHierarchy(); ComponentInfo current = componentMapper.selectById(componentId); while (current != null) { hierarchy.addComponentToTop(current); if (current.getParentId() == null || current.getParentId().isEmpty()) { Optional.ofNullable(current.getProductId()) .map(productMapper::selectById) .ifPresent(hierarchy::setRootProduct); break; } current = componentMapper.selectById(current.getParentId()); } return hierarchy; } private void completeChainWithProductInfo(ProcessTraceChain chain) { Optional.ofNullable(chain.getComponentHierarchy()) .map(ComponentHierarchy::getComponents) .filter(components -> !components.isEmpty()) .map(components -> components.get(0)) .map(ComponentInfo::getProductId) .map(productMapper::selectById) .ifPresent(chain::setProduct); } private List<ProductMix> buildFullTreePath(ProcessTraceChain chain) { List<ProductMix> path = new ArrayList<>(); Optional.ofNullable(chain.getProduct()) .map(ProductInfo::getProductId) .map(productMixMapper::findByProductId) .ifPresent(path::add); Optional.ofNullable(chain.getComponentHierarchy()) .map(ComponentHierarchy::getComponentsFromTop) .ifPresent(components -> components.stream() .map(ComponentInfo::getComponentId) .map(productMixMapper::findByComponentId) .filter(Objects::nonNull) .forEach(path::add)); Optional.ofNullable(chain.getParts()) .map(PartsInfo::getPartsId) .map(productMixMapper::findByPartsId) .ifPresent(path::add); Optional.ofNullable(chain.getProcessSpec()) .map(ProcessSpecVersion::getId) .map(productMixMapper::findByOperationId) .ifPresent(path::add); Optional.ofNullable(chain.getProcess()) .map(ProcessStream::getProcessId) .map(productMixMapper::findByProcessId) .ifPresent(path::add); Optional.ofNullable(chain.getWorkStep()) .map(WorkStep::getId) .map(productMixMapper::findByWorksiteId) .ifPresent(path::add); 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){ item.setDepartId(mdcProductionService.getById(item.getDepartId()).getOrgCode()); } if (item.getUserId()!=null){ item.setUserId(sysUserService.getById(item.getUserId()).getUsername()); } }); return path; } } 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/ProcessPackageStrategy.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,42 @@ package org.jeecg.modules.dnc.service.impl; import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum; import org.jeecg.modules.dnc.dto.TransferPackage; import org.jeecg.modules.dnc.entity.DeviceType; import org.jeecg.modules.dnc.entity.DocRelative; import org.jeecg.modules.dnc.entity.ProcessStream; import org.jeecg.modules.dnc.mapper.DeviceTypeMapper; import org.jeecg.modules.dnc.mapper.DocRelativeMapper; import org.jeecg.modules.dnc.mapper.ProcessStreamMapper; import org.jeecg.modules.dnc.service.DataPackageStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class ProcessPackageStrategy implements DataPackageStrategy { @Autowired private ProcessStreamMapper processMapper; @Autowired private DeviceTypeMapper deviceTypeMapper; @Autowired private FullHierarchyTraceService traceService; @Autowired private DocRelativeMapper docRelativeMapper; @Override public TransferPackage packageData(String relativeId) { DocRelative docRelative=docRelativeMapper.selectById(relativeId); DeviceType deviceType=deviceTypeMapper.selectById(docRelative.getAttributionId()); if (deviceType!=null&&deviceType.getAttributionType().equals(DocAttributionTypeEnum.PROCESS.getCode())) { ProcessStream process = processMapper.selectById(deviceType.getAttributionId()); if (process == null) { throw new IllegalArgumentException("设å¤ç±»å¯¹åºçå·¥åºä¸åå¨: " + deviceType.getDeviceManagementId()); } } return TransferPackage.builder() .dataType(TransferPackage.DataType.PROCESS) .docRelative(docRelative) .traceChain(traceService.traceFromProcess(docRelative)) .build(); } } 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
@@ -61,7 +61,6 @@ private IDocInfoService docInfoService; @Autowired private IDeviceTypeService deviceTypeService; @Override @Transactional(rollbackFor = {Exception.class}) public boolean addProcessStream(ProcessStream stream) { @@ -177,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/ProcessionDepartmentServiceImpl.java
ÎļþÃû´Ó lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessionDepartmentService.java ÐÞ¸Ä @@ -10,10 +10,11 @@ import org.jeecg.modules.system.entity.MdcProduction; import org.springframework.stereotype.Service; import java.util.*; import java.util.ArrayList; import java.util.List; @Service public class ProcessionDepartmentService extends ServiceImpl<ProcessionDepartmentMapper, ProcessionDepartment> implements IProcessionDepartmentService { public class ProcessionDepartmentServiceImpl extends ServiceImpl<ProcessionDepartmentMapper, ProcessionDepartment> implements IProcessionDepartmentService { @Override public boolean deleteByProcessId(String processId) { 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/ProductMixServiceImpl.java
@@ -48,4 +48,67 @@ result.sort(Comparator.comparing(ProductMix::getCreateTime, Comparator.nullsLast(Date::compareTo))); return result; } @Override public List<ProductMix> getParentList(String id) { List<ProductMix> parentList = new ArrayList<>(); // 1. æ ¹æ®IDæ¥è¯¢å½åèç¹ ProductMix current = this.getById(id); if (current == null) { return parentList; // èç¹ä¸å卿¶è¿å空å表 } // 2. ä»å½åèç¹å¼å§å䏿¥æ¾ç¶èç¹ Long parentId = current.getParentId(); while ( parentId != 0L) { ProductMix parent = this.getById(parentId.toString()); if (parent == null) { break; } parentList.add(parent); parentId = parent.getParentId(); } return parentList; } @Override public List<ProductMix> getChildrenList(String id) { List<ProductMix> childrenList = new ArrayList<>(); ProductMix current = this.getById(id); if (current == null) { return childrenList; } // 使ç¨éåè¿è¡BFS Queue<ProductMix> queue = new LinkedList<>(); queue.add(current); // å å ¥å½åèç¹ä½ä¸ºèµ·ç¹ // è®°å½å·²è®¿é®èç¹çIDï¼é¿å 循ç¯å¼ç¨ Set<String> visited = new HashSet<>(); visited.add(id); // èµ·å§èç¹å·²è®¿é® while (!queue.isEmpty()) { ProductMix node = queue.poll(); // è·³è¿èµ·å§èç¹ï¼å³ä¼ å ¥çèç¹ï¼ï¼ä¸å å ¥ç»æå表 if (!node.getId().toString().equals(id)) { childrenList.add(node); } // æ¥è¯¢å½åèç¹çç´æ¥åèç¹ List<ProductMix> directChildren = this.lambdaQuery().eq(ProductMix::getParentId, node.getId()).list(); if (directChildren != null && !directChildren.isEmpty()) { for (ProductMix child : directChildren) { String childId = child.getId().toString(); // å¦æè¯¥åèç¹è¿æªè®¿é®è¿ if (!visited.contains(childId)) { visited.add(childId); queue.add(child); } // å¦å忽ç¥ï¼é¿å 循ç¯å¼ç¨å¯¼è´çæ»å¾ªç¯ } } } return childrenList; } } lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductPermissionServiceImpl.java
@@ -143,7 +143,7 @@ break; default: // å¤çæªç¥ç±»å throw new IllegalArgumentException("Unknown permission type: " + type); throw new IllegalArgumentException("Unknown permission treeType: " + type); } } 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/WorkStepPackageStrategy.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,43 @@ package org.jeecg.modules.dnc.service.impl; import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum; import org.jeecg.modules.dnc.dto.TransferPackage; import org.jeecg.modules.dnc.entity.DeviceType; import org.jeecg.modules.dnc.entity.DocRelative; import org.jeecg.modules.dnc.entity.WorkStep; import org.jeecg.modules.dnc.mapper.DeviceTypeMapper; import org.jeecg.modules.dnc.mapper.DocRelativeMapper; import org.jeecg.modules.dnc.mapper.WorkStepMapper; import org.jeecg.modules.dnc.service.DataPackageStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class WorkStepPackageStrategy implements DataPackageStrategy { @Autowired private WorkStepMapper workStepMapper; @Autowired private FullHierarchyTraceService traceService; @Autowired private DeviceTypeMapper deviceTypeMapper; @Autowired private DocRelativeMapper docRelativeMapper; @Override public TransferPackage packageData(String relativeId) { DocRelative docRelative=docRelativeMapper.selectById(relativeId); DeviceType deviceType=deviceTypeMapper.selectById(docRelative.getAttributionId()); if (deviceType!=null&&deviceType.getAttributionType().equals(DocAttributionTypeEnum.WORKSITE.getCode())) { WorkStep workStep = workStepMapper.selectById(deviceType.getAttributionId()); if (workStep == null) { throw new IllegalArgumentException("设å¤ç±»å¯¹åºçå·¥æ¥ä¸åå¨: " + deviceType.getDeviceManagementId()); } } return TransferPackage.builder() .dataType(TransferPackage.DataType.WORKSTEP) .docRelative(docRelative) .traceChain(traceService.traceFromWorkStep(docRelative)) .build(); } } 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-dnc/src/main/java/org/jeecg/modules/dncFlow/service/IAssignFileStreamService.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.dnc.entity.DocFile; import org.jeecg.modules.dnc.response.QueryPageResponseResult; import org.jeecg.modules.dncFlow.entity.AssignFileStream; import org.jeecg.modules.dncFlow.ext.AssignFileStreamExt; @@ -9,6 +10,7 @@ import org.jeecg.modules.dncFlow.request.AssignFileRequest; import org.jeecg.modules.dncFlow.request.AssignFileStreamQueryRequest; import org.jeecg.modules.dncFlow.vo.AssignFlowTaskVo; import org.jeecg.modules.mdc.entity.MdcEquipment; public interface IAssignFileStreamService extends IService<AssignFileStream> { /** @@ -41,9 +43,7 @@ /** * å®¡æ¹æå¡ * @param taskId * @param streamId * @param stream * @param assignFlowTaskVo * @return */ boolean approveAssignFile(AssignFlowTaskVo assignFlowTaskVo); @@ -84,4 +84,6 @@ * @return */ Boolean getFlowableEnable(); void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile); } lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java
@@ -16,11 +16,14 @@ import org.flowable.task.api.Task; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.dnc.constant.DncPassLogPassType; import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum; 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.ext.NcTxtFilePathInfo; import org.jeecg.modules.dnc.response.*; import org.jeecg.modules.dnc.service.*; import org.jeecg.modules.dnc.service.impl.FileFerryService; import org.jeecg.modules.dnc.utils.ValidateUtil; import org.jeecg.modules.dnc.utils.date.DateUtil; import org.jeecg.modules.dnc.utils.file.FileUtilS; @@ -42,7 +45,6 @@ import org.jeecg.modules.flowable.service.IFlowTaskService; import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.service.IMdcEquipmentService; import org.jeecg.modules.message.enums.DeployEnum; import org.jeecg.modules.system.service.IMdcProductionService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -51,23 +53,17 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.*; import java.util.stream.Collectors; @Service("IAssignFileStreamService") public class AssignFileStreamServiceImpl extends ServiceImpl<AssignFileStreamMapper, AssignFileStream> implements IAssignFileStreamService , FlowCallBackServiceI { private static final String PROCESS_KEY = "assign_nc_to_device"; private static final String APPLY_VARIABLE = "apply_user"; private static final String APPROVE_VARIABLE = "approve_users"; private static final String SEND_CODE = "SEND"; @Value("${flowable.enable}") private Boolean flowableEnable; @Value("${fileHomePath}") private String fileHomePath; @Autowired private IDocInfoService docInfoService; @Autowired @@ -98,11 +94,10 @@ private PermissionService permissionService; @Autowired private IDncPassLogService dncPassLogService; @Value("${deploy.deployType}") private String deployType; //å·¥æ§ç½/æ¶å¯ç½é¨ç½² 0为工æ§ç½ 1为æ¶å¯ç½ @Value("${deploy.secretFolder}") private String secretFolder; //æ¶å¯ç½ä¼ è¾ncæä»¶å¤¹ @Autowired private FileFerryService ferryService; @Override @Transactional(rollbackFor = {Exception.class}) public Result applyAssignFile(AssignFileStream stream) { @@ -253,11 +248,19 @@ } } handleFileTransfer(mdcEquipment, docFile); //注æ----åºåå·¥æ§ç½ä¸æ¶å¯ç½ï¼ï¼ï¼ æ¶å¯ç½è¿è¡NCæä»¶çæ·è´ï¼å·¥æ§ç½è´è´£è¿è¡è§£æNCæä»¶ if (deployType.equals(DeployEnum.SMW.getCode())) { handleFileProcessing(docFile, mdcEquipment, secretFolder); List<DocRelative> docRelativeList=docRelativeService. list(new QueryWrapper<DocRelative>() .eq("attribution_type",stream.getAttributionType()) .eq("attribution_id",stream.getAttributionId()) .eq("doc_id",stream.getDocId())); if (docRelativeList.isEmpty()){ ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); } handleFileTransfer(mdcEquipment, docFile); //NCæä»¶çæ·è´ handleFileProcessing(docFile, mdcEquipment, secretFolder); //对åºäº§åç»ææ æ·è´ handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId()); synchronizedFlagService.updateFlag(2); return Result.OK("æä½æå"); } @@ -383,10 +386,20 @@ } } } //注æ----åºåå·¥æ§ç½ä¸æ¶å¯ç½ï¼ï¼ï¼ æ¶å¯ç½è¿è¡NCæä»¶çæ·è´ï¼å·¥æ§ç½è´è´£è¿è¡è§£æNCæä»¶ if (deployType.equals(DeployEnum.SMW.getCode())) { handleFileProcessing(docFile, mdcEquipment, secretFolder); List<DocRelative> docRelativeList=docRelativeService. list(new QueryWrapper<DocRelative>() .eq("attribution_type",en.getAttributionType()) .eq("attribution_id",en.getAttributionId()) .eq("doc_id",en.getDocId())); if (docRelativeList.isEmpty()){ ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); } //æ¶å¯ç½è¿è¡NCæä»¶çæ·è´ handleFileTransfer(mdcEquipment, docFile); //NCæä»¶çæ·è´ handleFileProcessing(docFile, mdcEquipment, secretFolder); //对åºäº§åç»ææ æ·è´ handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId()); return synchronizedFlagService.updateFlag(1); }else if(up.getStatus() == 3) { //æç»æä½ ä»ä¹ä¹ä¸å @@ -579,7 +592,8 @@ } //æå ¥æä»¶ä¼ è¾ä»»å¡è¡¨ private void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile) { @Override public void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile) { List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); if (strings != null && !strings.isEmpty()) { String path = StringUtils.join(strings.toArray(), "/"); @@ -600,7 +614,6 @@ //å°è£ å¤çæä»¶ private void handleFileProcessing(DocFile docFile, MdcEquipment mdcEquipment, String secretFolder) { if (!docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar")) { String size = FileUtilS.fileSizeNC(docFile.getFilePath(), docFile.getFileEncodeName()); List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); if (strings != null && !strings.isEmpty()) { DncPassLog passInfoTxt = new DncPassLog(); @@ -611,23 +624,14 @@ /*æ¥è¯¢æå䏿¡è®°å½*/ //ä¼ç 500æ¯«ç§ DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); int fileTxt = 0, fileNc =0; int fileNc =0; if (dncPassLog !=null) { fileTxt = dncPassLog.getSequenceNumber() + 1; fileNc = dncPassLog.getSequenceNumber() + 1; } else { fileTxt = 1; fileNc = 1; } fileNc = fileTxt + 1; //å¤çæä»¶åç§° æä»¶è·¯å¾ String sequence = String.format("%06d",fileTxt); String sequenceNc = String.format("%06d",fileNc); passInfoTxt.setSequenceNumber(fileTxt); passInfoTxt.setSequenceOrder(sequence); passInfoTxt.setCreateTime(dateFirst); System.out.println(DateUtil.format(dateFirst,DateUtil.STR_DATE_TIME)); passInfoTxt.setPassType("02"); dncPassLogService.save(passInfoTxt); DncPassLog passInfoNc = new DncPassLog(); passInfoNc.setSequenceNumber(fileNc); passInfoNc.setSequenceOrder(sequenceNc); @@ -642,41 +646,50 @@ } catch (InterruptedException e) { e.printStackTrace(); } dncPassLogService.save(passInfoNc); NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo(); ncTxt.setEquipmentId(mdcEquipment.getEquipmentId()); ncTxt.setFileNcName("10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc); ncTxt.setFileTxtName("10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequence); ncTxt.setFilePath(path + "/" + mdcEquipment.getEquipmentId() + "/"); ncTxt.setOrigFileName(docFile.getFileName()); ncTxt.setOrigFileSuffix(docFile.getFileSuffix()); ncTxt.setFileAddOrDelete(1); String loFilePath = secretFolder +"/"+ ncTxt.getFileTxtName() + ".nc"; try { String allList = ncTxt.getFileTxtName() + "\n" + ncTxt.getFileNcName() + "\n" + ncTxt.getOrigFileName() + "\n" + ncTxt.getOrigFileSuffix() + "\n" + ncTxt.getFilePath() + "\n" + ncTxt.getEquipmentId() + "\n" + ncTxt.getFileAddOrDelete().toString() + "\n" + size + "\n"; FileUtilS.fileWriterSql(loFilePath, allList); boolean copyFileNc = FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" + FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" + docFile.getFileName(), secretFolder +"/"+ncTxt.getFileNcName(), secretFolder +"/"+"10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc+"_"+mdcEquipment.getEquipmentId(), docFile.getFileSuffix(), "NC"); if (!copyFileNc) { FileUtilS.deleteNcFile(loFilePath); } } catch (IOException e) { throw new RuntimeException("æä»¶å¤ç失败", e); } } } } /** * å¤ç对åºäº§åç»ææ ãncæä»¶ãåå ·å表ãç¨åºå 工确认表å°è£ * @param docInfo */ private void handleProductTree(DocInfo docInfo,DocRelative docRelative,String equipmentId) { /*æ¥è¯¢æå䏿¡è®°å½*/ //ä¼ç 500æ¯«ç§ DncPassLog passInfoTxt = new DncPassLog(); Date dateFirst = DateUtil.getNow(); passInfoTxt.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); int fileTxt = 0, fileNc =0; if (dncPassLog !=null) { fileTxt = dncPassLog.getSequenceNumber() + 1; } else { fileTxt = 1; } String sequence = String.format("%06d",fileTxt); passInfoTxt.setSequenceNumber(fileTxt); passInfoTxt.setCreateTime(dateFirst); passInfoTxt.setSequenceOrder(sequence); System.out.println(DateUtil.format(dateFirst,DateUtil.STR_DATE_TIME)); passInfoTxt.setPassType(DncPassLogPassType.PRODUCTSTRUCTURE.getCode()); dncPassLogService.save(passInfoTxt); String fileName="10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY); if (Objects.equals(docInfo.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode())){ //å·¥åºå¯¹åºè®¾å¤ç±» String filePath = ferryService.exportData(TransferPackage.DataType.PROCESS, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry"); System.out.println("å·¥åºæ°æ®å·²å¯¼åº: " + filePath); }else { //å·¥æ¥å¯¹åºè®¾å¤ç±» String filePath = ferryService.exportData(TransferPackage.DataType.WORKSTEP, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry"); System.out.println("å·¥æ¥æ°æ®å·²å¯¼åº: " + filePath); } } @Override public void afterFlowHandle(FlowMyBusiness business) { business.getTaskNameId();//æ¥ä¸æ¥å®¡æ¹çèç¹ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/IMdcProductionService.java
@@ -185,4 +185,11 @@ String findProName(String equipmentId); /** * æ ¹æ®äº§çº¿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
@@ -637,4 +637,9 @@ public String findProName(String equipmentId) { return this.baseMapper.findProName(equipmentId); } @Override public MdcProduction findByOrgCode(String orgCode){ return this.baseMapper.selectOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getOrgCode, orgCode)); } }