¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | 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.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; |
| | | |
| | | @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().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 { |
| | | productMapper.updateById(product); |
| | | 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 { |
| | | componentMapper.updateById(component); |
| | | logger.debug("é¨ä»¶å·²æ´æ°: {}", component.getComponentId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void saveParts(PartsInfo parts) { |
| | | if (partsMapper.selectById(parts.getPartsId()) == null) { |
| | | partsMapper.insert(parts); |
| | | logger.debug("é¶ä»¶å·²ä¿å: {}", parts.getPartsId()); |
| | | } else { |
| | | partsMapper.updateById(parts); |
| | | logger.debug("é¶ä»¶å·²æ´æ°: {}", parts.getPartsId()); |
| | | } |
| | | } |
| | | |
| | | private void saveProcessSpec(ProcessSpecVersion processSpec) { |
| | | if (psvMapper.selectById(processSpec.getId()) == null) { |
| | | psvMapper.insert(processSpec); |
| | | logger.debug("å·¥èºè§ç¨å·²ä¿å: {}", processSpec.getId()); |
| | | } else { |
| | | psvMapper.updateById(processSpec); |
| | | logger.debug("å·¥èºè§ç¨å·²æ´æ°: {}", processSpec.getId()); |
| | | } |
| | | } |
| | | |
| | | private void saveProcess(ProcessStream process) { |
| | | if (processMapper.selectById(process.getProcessId()) == null) { |
| | | processMapper.insert(process); |
| | | logger.debug("å·¥åºå·²ä¿å: {}", process.getProcessId()); |
| | | } else { |
| | | processMapper.updateById(process); |
| | | logger.debug("å·¥åºå·²æ´æ°: {}", process.getProcessId()); |
| | | } |
| | | } |
| | | |
| | | private void saveWorkSteps(WorkStep workStep) { |
| | | if (workStepMapper.selectById(workStep.getId()) == null) { |
| | | workStepMapper.insert(workStep); |
| | | logger.debug("å·¥æ¥å·²ä¿å: {}", workStep.getId()); |
| | | } else { |
| | | workStepMapper.updateById(workStep); |
| | | 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 { |
| | | productMixMapper.updateById(productMix); |
| | | logger.debug("产åç»åå·²æ´æ°: {}", productMix.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void saveDeviceManagement(DeviceManagement deviceManagement) { |
| | | if (deviceManagementMapper.selectById(deviceManagement.getId()) == null) { |
| | | deviceManagementMapper.insert(deviceManagement); |
| | | logger.debug("设å¤ç±»ä¿¡æ¯å·²ä¿å: {}", deviceManagement.getId()); |
| | | } else { |
| | | deviceManagementMapper.updateById(deviceManagement); |
| | | logger.debug("设å¤ç±»ä¿¡æ¯å·²æ´æ°: {}", deviceManagement.getId()); |
| | | } |
| | | } |
| | | |
| | | private void saveDeviceType(DeviceType deviceType) { |
| | | if (deviceTypeMapper.selectById(deviceType.getId()) == null) { |
| | | deviceTypeMapper.insert(deviceType); |
| | | logger.debug("设å¤ç±»å·²ä¿å: {}", deviceType.getId()); |
| | | } else { |
| | | deviceTypeMapper.updateById(deviceType); |
| | | logger.debug("设å¤ç±»å·²æ´æ°: {}", deviceType.getId()); |
| | | } |
| | | } |
| | | |
| | | private void saveDocInfo(DocInfo docInfo) { |
| | | if (docInfoMapper.selectById(docInfo.getDocId()) == null) { |
| | | docInfoMapper.insert(docInfo); |
| | | logger.debug("ææ¡£å·²ä¿å: {}", docInfo.getDocId()); |
| | | } else { |
| | | docInfo.setDocDispatchStatus(5); |
| | | docInfoMapper.updateById(docInfo); |
| | | logger.debug("ææ¡£å·²æ´æ°: {}", docInfo.getDocId()); |
| | | } |
| | | } |
| | | |
| | | private void saveDocFile(DocFile docFile) { |
| | | if (docFileMapper.selectById(docFile.getFileId()) == null) { |
| | | docFileMapper.insert(docFile); |
| | | logger.debug("ææ¡£æä»¶å·²ä¿å: {}", docFile.getFileId()); |
| | | } else { |
| | | docFileMapper.updateById(docFile); |
| | | logger.debug("ææ¡£æä»¶å·²æ´æ°: {}", docFile.getFileId()); |
| | | } |
| | | } |
| | | |
| | | private void saveDocRelative(DocRelative docRelative) { |
| | | if (docRelativeMapper.selectById(docRelative.getId()) == null) { |
| | | docRelativeMapper.insert(docRelative); |
| | | logger.debug("ææ¡£å¯¹åºå
³ç³»å·²ä¿å: {}", docRelative.getId()); |
| | | } else { |
| | | docRelativeMapper.updateById(docRelative); |
| | | 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); |
| | | logger.debug("åå
·å·²æ´æ°: {}", cutter.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void saveGuideCardBatch(GuideCardBatch guideCardBatch) { |
| | | if (guideCardBatchMapper.selectById(guideCardBatch.getId()) == null) { |
| | | guideCardBatchMapper.insert(guideCardBatch); |
| | | logger.debug("ç¨åºå 工确认表已ä¿å: {}", guideCardBatch.getId()); |
| | | } else { |
| | | guideCardBatchMapper.updateById(guideCardBatch); |
| | | logger.debug("ç¨åºå å·¥ç¡®è®¤è¡¨å·²æ´æ°: {}", guideCardBatch.getId()); |
| | | } |
| | | } |
| | | } |