From d36ab456546d2232a1637fdc4a1e70de4fed46de Mon Sep 17 00:00:00 2001 From: "HUOJIN\\92525" <925258474@qq.com> Date: Fri, 13 Sep 2024 15:51:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E6=96=99=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basicdata/rest/ImportDataController.java | 3 - .../service/impl/ImportDataServiceImpl.java | 100 +++++++++--------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/youchain-system/src/main/java/com/youchain/basicdata/rest/ImportDataController.java b/youchain-system/src/main/java/com/youchain/basicdata/rest/ImportDataController.java index 728354b..9d37250 100644 --- a/youchain-system/src/main/java/com/youchain/basicdata/rest/ImportDataController.java +++ b/youchain-system/src/main/java/com/youchain/basicdata/rest/ImportDataController.java @@ -107,11 +107,8 @@ public class ImportDataController { @Log("导入部品品番") @ApiOperation("导入部品品番") @PostMapping(value = "/item") - @Transactional @AnonymousAccess public ResponseEntity importItem( @RequestParam("file") MultipartFile multipartFile) { - - //编码、名称、物料类型 try { String result = importDataService.importItem(multipartFile); return new ResponseEntity(result, HttpStatus.OK); diff --git a/youchain-system/src/main/java/com/youchain/basicdata/service/impl/ImportDataServiceImpl.java b/youchain-system/src/main/java/com/youchain/basicdata/service/impl/ImportDataServiceImpl.java index 64fa65d..2ba220f 100644 --- a/youchain-system/src/main/java/com/youchain/basicdata/service/impl/ImportDataServiceImpl.java +++ b/youchain-system/src/main/java/com/youchain/basicdata/service/impl/ImportDataServiceImpl.java @@ -31,6 +31,7 @@ import com.youchain.businessdata.domain.PickDetail; import com.youchain.businessdata.domain.PickTicket; import com.youchain.businessdata.service.*; import com.youchain.config.FileProperties; +import com.youchain.config.thread.ThreadPoolExecutorUtil; import com.youchain.exception.BadRequestException; import com.youchain.modules.system.domain.Dept; import com.youchain.modules.system.domain.DictDetail; @@ -51,6 +52,9 @@ import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; /** * @author HJL @@ -179,8 +183,8 @@ public class ImportDataServiceImpl implements ImportDataService { } @Override + @Transactional(rollbackFor = Exception.class) public String importItem(MultipartFile multipartFile) { - //编码、名称、物料类型 FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize()); String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename()); String type = FileUtil.getFileType(suffix); @@ -201,7 +205,7 @@ public class ImportDataServiceImpl implements ImportDataService { Map existingPoint = itemService.findByCodes(itemCodes); - List itemsToInsert= new ArrayList<>();//新增物料集合 + List itemsToInsert = new ArrayList<>();//新增物料集合 List itemsToUpdate = new ArrayList<>();//修改物料集合 for (Map record : readAll) { String itemCode = record.get("料号").toString().trim(); @@ -225,61 +229,61 @@ public class ImportDataServiceImpl implements ImportDataService { if (!itemsToUpdate.isEmpty()) { batchCreateOrUpdate.batchUpdate(itemsToUpdate); } + return ("导入成功:" + " 新增(" + itemsToInsert.size() + ")修改(" + itemsToUpdate.size() + ")"); } private Item updateItems(Item item, Dept dept, Map record) { - item.setDept(dept); - item.setName(record.get("物料描述").toString().trim()); - item.setPackageType(record.get("包装类型").toString().trim()); - item.setSpecQuantity(record.get("规格数量") == null ? 0 : Double.parseDouble(record.get("规格数量").toString())); - item.setSpecWeight(record.get("规格重量") == null ? 0 : Double.parseDouble(record.get("规格重量").toString())); - item.setGrossWeight(record.get("毛重") == null ? 0 : Double.parseDouble(record.get("毛重").toString())); - item.setLength(record.get("长") == null ? 0 : Double.parseDouble(record.get("长").toString())); - item.setWidth(record.get("宽") == null ? 0 : Double.parseDouble(record.get("宽").toString())); - item.setHeight(record.get("高") == null ? 0 : Double.parseDouble(record.get("高").toString())); - item.setVolume(record.get("体积") == null ? 0 : Double.parseDouble(record.get("体积").toString())); - item.setUnit(record.get("单位").toString().trim()); - item.setType(record.get("类型").toString().trim()); - item.setValueGrade(record.get("物料价值等级").toString().trim()); - item.setValidPeriod(record.get("保质期") == null ? 0 : Integer.parseInt(record.get("保质期").toString())); - item.setAlertDays(record.get("预警天数") == null ? 0 : Integer.parseInt(record.get("预警天数").toString())); - item.setIsBatch("是".equals(record.get("是否批次").toString().trim()) ? true : false); - item.setIsSerial("是".equals(record.get("是否序列号").toString().trim()) ? true : false); - item.setIsValidPeriod("是".equals(record.get("是否有效期").toString().trim()) ? true : false); - item.setIsHazardous("是".equals(record.get("是否危化品").toString().trim()) ? true : false); - item.setIsInvAvailable("是".equals(record.get("是否有库存").toString().trim()) ? true : false); - item.setIsSapMaterial("是".equals(record.get("是否SAP料号").toString().trim()) ? true : false); - item.setHeatValue(record.get("热度值") == null ? 0 : Integer.parseInt(record.get("热度值").toString())); - item.setDescription(record.get("备注").toString().trim()); + item.setName(Optional.ofNullable(record.get("物料描述")).map(Object::toString).map(String::trim).orElse("")); + item.setPackageType(Optional.ofNullable(record.get("包装类型")).map(Object::toString).map(String::trim).orElse("")); + item.setSpecQuantity(Optional.ofNullable(record.get("规格数量")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setSpecWeight(Optional.ofNullable(record.get("规格重量")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setGrossWeight(Optional.ofNullable(record.get("毛重")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setLength(Optional.ofNullable(record.get("长")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setWidth(Optional.ofNullable(record.get("宽")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setHeight(Optional.ofNullable(record.get("高")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setVolume(Optional.ofNullable(record.get("体积")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setUnit(Optional.ofNullable(record.get("单位")).map(Object::toString).map(String::trim).orElse("")); + item.setType(Optional.ofNullable(record.get("类型")).map(Object::toString).map(String::trim).orElse("")); + item.setValueGrade(Optional.ofNullable(record.get("物料价值等级")).map(Object::toString).map(String::trim).orElse("")); + item.setValidPeriod(Optional.ofNullable(record.get("保质期天数")).map(Object::toString).map(Integer::parseInt).orElse(0)); + item.setAlertDays(Optional.ofNullable(record.get("预警天数")).map(Object::toString).map(Integer::parseInt).orElse(0)); + item.setIsBatch(Optional.ofNullable(record.get("是否批次")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsSerial(Optional.ofNullable(record.get("是否序列号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsValidPeriod(Optional.ofNullable(record.get("是否有效期")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsHazardous(Optional.ofNullable(record.get("是否危化品")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsInvAvailable(Optional.ofNullable(record.get("是否有库存")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsSapMaterial(Optional.ofNullable(record.get("是否SAP料号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setHeatValue(Optional.ofNullable(record.get("热度值")).map(Object::toString).map(Integer::parseInt).orElse(0)); + item.setDescription(Optional.ofNullable(record.get("备注")).map(Object::toString).map(String::trim).orElse("")); return item; } private Item createItem(Dept dept, Map record) { Item item = new Item(); - item.setCode(record.get("料号").toString().trim()); - item.setName(record.get("物料描述").toString().trim()); - item.setPackageType(record.get("包装类型").toString().trim()); - item.setSpecQuantity(record.get("规格数量") == null ? 0 : Double.parseDouble(record.get("规格数量").toString())); - item.setSpecWeight(record.get("规格重量") == null ? 0 : Double.parseDouble(record.get("规格重量").toString())); - item.setGrossWeight(record.get("毛重") == null ? 0 : Double.parseDouble(record.get("毛重").toString())); - item.setLength(record.get("长") == null ? 0 : Double.parseDouble(record.get("长").toString())); - item.setWidth(record.get("宽") == null ? 0 : Double.parseDouble(record.get("宽").toString())); - item.setHeight(record.get("高") == null ? 0 : Double.parseDouble(record.get("高").toString())); - item.setVolume(record.get("体积") == null ? 0 : Double.parseDouble(record.get("体积").toString())); - item.setUnit(record.get("单位").toString().trim()); - item.setType(record.get("类型").toString().trim()); - item.setValueGrade(record.get("物料价值等级").toString().trim()); - item.setValidPeriod(record.get("保质期") == null ? 0 : Integer.parseInt(record.get("保质期").toString())); - item.setAlertDays(record.get("预警天数") == null ? 0 : Integer.parseInt(record.get("预警天数").toString())); - item.setIsBatch("是".equals(record.get("是否批次").toString().trim()) ? true : false); - item.setIsSerial("是".equals(record.get("是否序列号").toString().trim()) ? true : false); - item.setIsValidPeriod("是".equals(record.get("是否有效期").toString().trim()) ? true : false); - item.setIsHazardous("是".equals(record.get("是否危化品").toString().trim()) ? true : false); - item.setIsInvAvailable("是".equals(record.get("是否有库存").toString().trim()) ? true : false); - item.setIsSapMaterial("是".equals(record.get("是否SAP料号").toString().trim()) ? true : false); - item.setHeatValue(record.get("热度值") == null ? 0 : Integer.parseInt(record.get("热度值").toString())); - item.setDescription(record.get("备注").toString().trim()); + item.setCode(Optional.ofNullable(record.get("料号")).map(Object::toString).map(String::trim).orElse("")); + item.setName(Optional.ofNullable(record.get("物料描述")).map(Object::toString).map(String::trim).orElse("")); + item.setPackageType(Optional.ofNullable(record.get("包装类型")).map(Object::toString).map(String::trim).orElse("")); + item.setSpecQuantity(Optional.ofNullable(record.get("规格数量")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setSpecWeight(Optional.ofNullable(record.get("规格重量")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setGrossWeight(Optional.ofNullable(record.get("毛重")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setLength(Optional.ofNullable(record.get("长")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setWidth(Optional.ofNullable(record.get("宽")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setHeight(Optional.ofNullable(record.get("高")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setVolume(Optional.ofNullable(record.get("体积")).map(Object::toString).map(Double::parseDouble).orElse(0D)); + item.setUnit(Optional.ofNullable(record.get("单位")).map(Object::toString).map(String::trim).orElse("")); + item.setType(Optional.ofNullable(record.get("类型")).map(Object::toString).map(String::trim).orElse("")); + item.setValueGrade(Optional.ofNullable(record.get("物料价值等级")).map(Object::toString).map(String::trim).orElse("")); + item.setValidPeriod(Optional.ofNullable(record.get("保质期天数")).map(Object::toString).map(Integer::parseInt).orElse(0)); + item.setAlertDays(Optional.ofNullable(record.get("预警天数")).map(Object::toString).map(Integer::parseInt).orElse(0)); + item.setIsBatch(Optional.ofNullable(record.get("是否批次")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsSerial(Optional.ofNullable(record.get("是否序列号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsValidPeriod(Optional.ofNullable(record.get("是否有效期")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsHazardous(Optional.ofNullable(record.get("是否危化品")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsInvAvailable(Optional.ofNullable(record.get("是否有库存")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setIsSapMaterial(Optional.ofNullable(record.get("是否SAP料号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false)); + item.setHeatValue(Optional.ofNullable(record.get("热度值")).map(Object::toString).map(Integer::parseInt).orElse(0)); + item.setDescription(Optional.ofNullable(record.get("备注")).map(Object::toString).map(String::trim).orElse("")); item.setDept(dept); item.setEnabled(true); return item;