From 3059430a0db3f75426e435c06090358646fc3792 Mon Sep 17 00:00:00 2001
From: Fixiaobai <fixiaobai@163.com>
Date: 星期四, 09 十一月 2023 09:11:17 +0800
Subject: [PATCH] Changes11

---
 mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java |   49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java b/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java
index a6243fe..eef703c 100644
--- a/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java
+++ b/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java
@@ -17,6 +17,7 @@
 package com.chinaztt.mes.technology.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.lang.Console;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.ExcelWriter;
 import com.alibaba.excel.write.metadata.WriteSheet;
@@ -46,9 +47,13 @@
 import com.chinaztt.mes.technology.mapper.StructureMapper;
 import com.chinaztt.mes.technology.service.StructureService;
 import com.chinaztt.ztt.common.core.util.R;
+import com.chinaztt.ztt.common.security.util.SecurityUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
@@ -58,6 +63,7 @@
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
 
 
 /**
@@ -79,6 +85,10 @@
 	private NumberGenerator<Structure> numberGenerator;
 	private DictUtils dictUtils;
 	private IfsFeignClient ifsFeignClient;
+
+	private RedisTemplate redisTemplate;
+	@Autowired
+	private ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
 	/**
 	 * @Author: Hans
@@ -257,7 +267,20 @@
 	}
 
 	@Override
+	@Transactional(rollbackFor = Exception.class)
 	public void importExcel(List<StructureData> list) {
+		String key = "syncStructure_lock" + SecurityUtils.getUser().getId();
+		if (redisTemplate.hasKey(key)) {
+			throw new RuntimeException("鏈夊鍏ヤ换鍔℃鍦ㄥ鐞�");
+		}
+		CompletableFuture.runAsync(()->{
+			asyncImport(list);
+			redisTemplate.delete(key);
+		},threadPoolTaskExecutor);
+	}
+
+
+	void asyncImport(List<StructureData> list){
 		if (CollectionUtil.isEmpty(list)) {
 			return;
 		}
@@ -265,14 +288,17 @@
 			List<Part> parts = partMapper.selectList(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getPartNo()));
 			Part part = parts.get(0);
 			if (part == null) {
-				throw new RuntimeException("闆朵欢鍙�:" + data.getPartNo() + "涓嶅瓨鍦�");
+				log.error("闆朵欢鍙�:" + data.getPartNo() + "涓嶅瓨鍦�");
+				return;
 			}
 			Structure structure = baseMapper.selectOne(Wrappers.<Structure>lambdaQuery().eq(Structure::getPartId, part.getId()));
 			if (structure == null) {
 				structure = new Structure();
 				BeanUtils.copyProperties(data, structure);
 				structure.setPartId(part.getId());
-				structure.setActive(true);
+				structure.setMaster(false);
+				structure.setVersion("1");
+				//structure.setActive(true);
 				structure.setBomTypeDb("M");
 				structure.setIfsSync(false);
 				structure.setAlternativeNo("*");
@@ -281,7 +307,8 @@
 			List<Part> childParts = partMapper.selectList(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getSonPartNo()));
 			Part childPart = childParts.get(0);
 			if (childPart == null) {
-				throw new RuntimeException("闆朵欢鍙�:" + data.getSonPartNo() + "涓嶅瓨鍦�");
+				log.error("闆朵欢鍙�:" + data.getSonPartNo() + "涓嶅瓨鍦�");
+				return;
 			}
 			List<Operation> operations = operationMapper.selectList(Wrappers.<Operation>lambdaQuery().eq(Operation::getName, data.getOperationName()));
 			Operation operation = operations.get(0);
@@ -289,8 +316,21 @@
 			component.setStructureId(structure.getId());
 			component.setPartId(childPart.getId());
 			component.setPlanningMethod(childPart.getPlanningMethod());
+			QueryWrapper<StructureComponent> queryWrapper = new QueryWrapper<>();
+			queryWrapper.lambda().select(StructureComponent::getLineItemNo).eq(StructureComponent::getStructureId,structure.getId()).orderByDesc(StructureComponent::getLineItemNo);
+			List<StructureComponent> structureComponents = structureComponentMapper.selectList(queryWrapper);
 			component.setQpa(new BigDecimal(1));// todo: 浜у搧缁撴瀯瀵煎叆鏁伴噺,杩樼己涓�涓鍙�
+			Console.log("鍊�===銆�"+structureComponents);
+			if(structureComponents.size()<1){
+				component.setLineItemNo(1);
+			}else {
+				Integer lineItemNo = structureComponents.get(0).getLineItemNo();
+				component.setLineItemNo(lineItemNo+1);
+			}
 			component.setOperationId(operation.getId());
+			component.setPlanningMethod("A");
+			component.setSpecs(childPart.getSpecs());
+			component.setPartModel(childPart.getPartModel());
 			structureComponentMapper.insert(component);
 		}
 	}
@@ -441,6 +481,9 @@
 		Structure structure = baseMapper.selectById(component.getStructureId());
 		structure.setIfsSync(false);
 		validate(structure.getPartId(), component.getPartId());
+		Part part = partMapper.selectById(component.getPartId());
+		component.setPartModel(part.getPartModel());
+		component.setSpecs(part.getSpecs());
 		structureComponentMapper.insert(component);
 		// 瀵规帴ifs
 //		List<StructureDTO> structureDTOS = structureMapper.getStructureDtoByIds(Arrays.asList(component.getStructureId()));

--
Gitblit v1.9.3