| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.other.pojo.TempFile; |
| | | import com.ruoyi.production.dto.ProductionProductRouteItemDto; |
| | | import com.ruoyi.production.dto.ProductionProductRouteItemParamDto; |
| | | import com.ruoyi.production.dto.ProductionRecordDto; |
| | | import com.ruoyi.production.dto.*; |
| | | import com.ruoyi.production.enums.ProductOrderStatusEnum; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.production.service.*; |
| | |
| | | throw new ServiceException("æ¥å·¥å¤±è´¥,ç产订åä¸åå¨"); |
| | | } |
| | | |
| | | // å½åæ¥å·¥åæ ¼æ°é |
| | | // å½åæ¥å·¥åæ ¼æ°éï¼å端已ä¿è¯ = æå
¥æ°é - ä¸åæ ¼æ°éï¼ç´æ¥ä½¿ç¨ï¼ |
| | | BigDecimal qualifiedQty = dto.getQualifiedQuantity() == null ? BigDecimal.ZERO : dto.getQualifiedQuantity(); |
| | | // 已宿æ°é |
| | | // 订å已宿æ°éï¼åå²ç´¯è®¡ï¼ |
| | | BigDecimal completeQty = productOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productOrder.getCompleteQuantity(); |
| | | // ç´¯å (åªç®åæ ¼) |
| | | BigDecimal newCompleteQty = completeQty.add(qualifiedQty); |
| | | productOrder.setCompleteQuantity(newCompleteQty); |
| | | // éæ±æ°é |
| | | BigDecimal totalQty = productOrder.getQuantity() == null ? BigDecimal.ZERO : productOrder.getQuantity(); |
| | | // å©ä½å¯æ¥å·¥æ°é |
| | | BigDecimal remainQty = totalQty.subtract(completeQty); |
| | | // æ¬æ¬¡æ¥å·¥ä¸è½è¶
è¿å©ä½æ°é |
| | | // æ¬æ¬¡æ¥å·¥åæ ¼æ°éä¸è½è¶
è¿å©ä½æ°éï¼æ ¡éªå¿
é¡»å¨ç´¯å åæ§è¡ï¼ |
| | | if (qualifiedQty.compareTo(remainQty) > 0) { |
| | | throw new ServiceException("æ¥å·¥å¤±è´¥ï¼æ¬æ¬¡æ¥å·¥æ°éä¸è½å¤§äºå©ä½å¯æ¥å·¥æ°é"); |
| | | throw new ServiceException("æ¥å·¥å¤±è´¥ï¼æ¬æ¬¡æ¥å·¥æ°éä¸è½å¤§äºå©ä½å¯æ¥å·¥æ°éï¼å©ä½æ¥å·¥æ°é:[" + remainQty + "]"); |
| | | } |
| | | // åå²å·²å®æ + æ¬æ¬¡åæ ¼æ°é |
| | | BigDecimal newCompleteQty = completeQty.add(qualifiedQty); |
| | | productOrder.setCompleteQuantity(newCompleteQty); |
| | | // 设置å¼å§æ¶é´ï¼ç¬¬ä¸æ¬¡æ¥å·¥ï¼ |
| | | if (productOrder.getStartTime() == null) { |
| | | productOrder.setStartTime(LocalDateTime.now()); |
| | |
| | | |
| | | // 宿æ¥å·¥ä¸»è¡¨-æå
¥è¡¨-产åºè¡¨æ°æ® |
| | | ProductionProductMain productionProductMain = new ProductionProductMain(); |
| | | productionProductMain.setProductNo("BG" + UUID.randomUUID()); |
| | | productionProductMain.setProductNo(productionProductMainService.generateProductNo()); |
| | | productionProductMain.setProductOrderId(dto.getProductOrderId()); |
| | | productionProductMain.setSchedule(dto.getSchedule()); |
| | | productionProductMain.setPostName(dto.getPostName()); |
| | | productionProductMain.setReportingTime(LocalDateTime.now()); |
| | | boolean result = productionProductMainService.save(productionProductMain); |
| | | if (!result) { |
| | | throw new ServiceException("æ¥å·¥å¤±è´¥,æ°æ®åå¨å¤±è´¥"); |
| | |
| | | ProductionProductRouteItemParam paramEntity = new ProductionProductRouteItemParam(); |
| | | BeanUtils.copyProperties(productRouteItemParamDto, paramEntity, "id"); |
| | | paramEntity.setProductionProductRouteItemId(productRouteItemEntity.getId()); |
| | | paramEntity.setOrderItemParamId(productRouteItemParamDto.getId()); |
| | | if (paramEntity.getProductId() == null) { |
| | | ProductionOrderRouteItemParam productionOrderRouteItemParam = productionOrderRouteItemParamService.getById(productRouteItemParamDto.getId()); |
| | | paramEntity.setParamName(productionOrderRouteItemParam.getParamName()); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteProductMain(Long productMainId) { |
| | | if (productMainId == null) { |
| | | throw new ServiceException("å é¤å¤±è´¥ï¼æ¥å·¥IDä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | // æ ¡éªæ¥å·¥ä¸»è¡¨æ¯å¦åå¨ |
| | | ProductionProductMain productMain = productionProductMainService.getById(productMainId); |
| | | if (productMain == null) { |
| | | throw new ServiceException("å é¤å¤±è´¥ï¼æ¥å·¥è®°å½ä¸åå¨"); |
| | | } |
| | | |
| | | // æ¥è¯¢è¯¥æ¥å·¥ä¸ææå·¥åºè®°å½ |
| | | List<ProductionProductRouteItem> routeItemList = productionProductRouteItemService.list(new LambdaQueryWrapper<ProductionProductRouteItem>() |
| | | .eq(ProductionProductRouteItem::getProductMainId, productMainId)); |
| | | |
| | | if (routeItemList != null && !routeItemList.isEmpty()) { |
| | | List<Long> routeItemIds = routeItemList.stream() |
| | | .map(ProductionProductRouteItem::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // æ¥è¯¢å¹¶å 餿¯ä¸ªå·¥åºä¸çéä»¶ |
| | | List<ProductionProductRouteItemFile> fileList = productionProductRouteItemFileService.list(new LambdaQueryWrapper<ProductionProductRouteItemFile>() |
| | | .in(ProductionProductRouteItemFile::getProductionProductRouteItemId, routeItemIds)); |
| | | |
| | | if (fileList != null && !fileList.isEmpty()) { |
| | | for (ProductionProductRouteItemFile file : fileList) { |
| | | if (StringUtils.hasText(file.getFileUrl())) { |
| | | try { |
| | | Files.deleteIfExists(Paths.get(file.getFileUrl())); |
| | | } catch (IOException e) { |
| | | log.warn("å é¤éä»¶æä»¶å¤±è´¥: {}", file.getFileUrl(), e); |
| | | } |
| | | } |
| | | } |
| | | productionProductRouteItemFileService.remove(new LambdaQueryWrapper<ProductionProductRouteItemFile>() |
| | | .in(ProductionProductRouteItemFile::getProductionProductRouteItemId, routeItemIds)); |
| | | } |
| | | |
| | | // å é¤å·¥åºåæ° |
| | | productionProductRouteItemParamService.remove(new LambdaQueryWrapper<ProductionProductRouteItemParam>() |
| | | .in(ProductionProductRouteItemParam::getProductionProductRouteItemId, routeItemIds)); |
| | | |
| | | // å é¤å·¥åºè®°å½ |
| | | productionProductRouteItemService.remove(new LambdaQueryWrapper<ProductionProductRouteItem>() |
| | | .eq(ProductionProductRouteItem::getProductMainId, productMainId)); |
| | | } |
| | | |
| | | // å 餿å
¥è¡¨ |
| | | productionProductInputService.remove(new LambdaQueryWrapper<ProductionProductInput>() |
| | | .eq(ProductionProductInput::getProductMainId, productMainId)); |
| | | |
| | | // åæ»ç产订å宿æ°é |
| | | ProductionProductOutput output = productionProductOutputService.getOne(new LambdaQueryWrapper<ProductionProductOutput>() |
| | | .eq(ProductionProductOutput::getProductMainId, productMainId) |
| | | .last("LIMIT 1")); |
| | | |
| | | ProductOrder productOrder = productOrderService.getById(productMain.getProductOrderId()); |
| | | if (productOrder == null) { |
| | | throw new ServiceException("å é¤å¤±è´¥ï¼å
³èçç产订åä¸åå¨"); |
| | | } |
| | | |
| | | BigDecimal qualifiedQty = (output != null && output.getQuantity() != null) |
| | | ? output.getQuantity() : BigDecimal.ZERO; |
| | | BigDecimal currentCompleteQty = productOrder.getCompleteQuantity() == null |
| | | ? BigDecimal.ZERO : productOrder.getCompleteQuantity(); |
| | | BigDecimal totalQty = productOrder.getQuantity() == null ? BigDecimal.ZERO : productOrder.getQuantity(); |
| | | |
| | | // æ£åæ¬æ¡æ¥å·¥è´¡ç®çåæ ¼æ°éï¼ä¸å
许åºç°è´æ° |
| | | BigDecimal updatedCompleteQty = currentCompleteQty.subtract(qualifiedQty).max(BigDecimal.ZERO); |
| | | productOrder.setCompleteQuantity(updatedCompleteQty); |
| | | |
| | | // éæ°å¤æè®¢åç¶æ |
| | | if (updatedCompleteQty.compareTo(totalQty) >= 0 && totalQty.compareTo(BigDecimal.ZERO) > 0) { |
| | | // å®ææ° >= éæ±æ° â 已宿 |
| | | productOrder.setStatus(ProductOrderStatusEnum.FINISHED.getCode()); |
| | | } else if (updatedCompleteQty.compareTo(BigDecimal.ZERO) == 0) { |
| | | // 宿æ°å½é¶ â åå°å¾
å¼å§ï¼æ¸
空å¼å§/ç»ææ¶é´ |
| | | productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode()); |
| | | productOrder.setStartTime(null); |
| | | productOrder.setEndTime(null); |
| | | } else { |
| | | // 宿æ°ä»äº 0 ~ éæ±æ°ä¹é´ â è¿è¡ä¸ |
| | | productOrder.setStatus(ProductOrderStatusEnum.RUNNING.getCode()); |
| | | productOrder.setEndTime(null); |
| | | } |
| | | productOrderService.updateById(productOrder); |
| | | |
| | | // å é¤äº§åºè¡¨ |
| | | productionProductOutputService.remove(new LambdaQueryWrapper<ProductionProductOutput>() |
| | | .eq(ProductionProductOutput::getProductMainId, productMainId)); |
| | | |
| | | // å 餿¥å·¥ä¸»è¡¨ |
| | | productionProductMainService.removeById(productMainId); |
| | | log.info("æ¥å·¥è®°å½å 餿åï¼productMainId={}", productMainId); |
| | | } |
| | | |
| | | @Override |
| | | public ProductionRecordDto detailProductMain(Long productMainId) { |
| | | if (productMainId == null) { |
| | | throw new ServiceException("æ¥è¯¢å¤±è´¥ï¼æ¥å·¥IDä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | // æ¥è¯¢æ¥å·¥ä¸»è¡¨ |
| | | ProductionProductMain productMain = productionProductMainService.getById(productMainId); |
| | | if (productMain == null) { |
| | | throw new ServiceException("æ¥è¯¢å¤±è´¥ï¼æ¥å·¥è®°å½ä¸åå¨"); |
| | | } |
| | | |
| | | ProductionRecordDto dto = new ProductionRecordDto(); |
| | | dto.setProductMainId(productMainId); |
| | | dto.setProductOrderId(productMain.getProductOrderId()); |
| | | dto.setPostName(productMain.getPostName()); |
| | | dto.setSchedule(productMain.getSchedule()); |
| | | dto.setReportingTime(productMain.getReportingTime()); |
| | | dto.setCreateTime(productMain.getCreateTime()); |
| | | dto.setUpdateTime(productMain.getUpdateTime()); |
| | | |
| | | // ç产订åä¿¡æ¯ |
| | | ProductOrder productOrder = productOrderService.getById(productMain.getProductOrderId()); |
| | | if (productOrder == null) { |
| | | throw new ServiceException("æ¥è¯¢å¤±è´¥,æªæ¥è¯¢å°ç产订åä¿¡æ¯"); |
| | | } |
| | | dto.setNpsNo(productOrder.getNpsNo()); |
| | | |
| | | /// 产åä¿¡æ¯ |
| | | ProductMaterialSkuDto productMaterialSkuDto = productMaterialService.selectProductByProductMainId(productOrder.getId()); |
| | | dto.setProductName(productMaterialSkuDto.getProductName()); |
| | | dto.setMaterialCode(productMaterialSkuDto.getMaterialCode()); |
| | | dto.setModel(productMaterialSkuDto.getModel()); |
| | | |
| | | // æ¥è¯¢æå
¥è¡¨ï¼è·å产åIDåæå
¥æ°éï¼ |
| | | ProductionProductInput input = productionProductInputService.getOne( |
| | | new LambdaQueryWrapper<ProductionProductInput>() |
| | | .eq(ProductionProductInput::getProductMainId, productMainId) |
| | | .last("LIMIT 1")); |
| | | if (input != null) { |
| | | dto.setProductId(input.getProductModelId()); |
| | | dto.setQuantity(input.getQuantity()); |
| | | } |
| | | |
| | | // æ¥è¯¢äº§åºè¡¨ï¼è·ååæ ¼/ä¸åæ ¼æ°éï¼ |
| | | ProductionProductOutput output = productionProductOutputService.getOne( |
| | | new LambdaQueryWrapper<ProductionProductOutput>() |
| | | .eq(ProductionProductOutput::getProductMainId, productMainId) |
| | | .last("LIMIT 1")); |
| | | if (output != null) { |
| | | dto.setQualifiedQuantity(output.getQuantity()); |
| | | dto.setUnqualifiedQuantity(output.getScrapQty()); |
| | | } |
| | | |
| | | // æ¥è¯¢å·¥åºå表 |
| | | List<ProductionProductRouteItem> routeItemList = productionProductRouteItemService.list( |
| | | new LambdaQueryWrapper<ProductionProductRouteItem>() |
| | | .eq(ProductionProductRouteItem::getProductMainId, productMainId)); |
| | | |
| | | if (routeItemList != null && !routeItemList.isEmpty()) { |
| | | List<ProductionProductRouteItemDto> routeItemDtoList = routeItemList.stream().map(routeItem -> { |
| | | ProductionProductRouteItemDto routeItemDto = new ProductionProductRouteItemDto(); |
| | | BeanUtils.copyProperties(routeItem, routeItemDto); |
| | | |
| | | // æ¥è¯¢å·¥åºåæ° |
| | | List<ProductionProductRouteItemParam> paramList = productionProductRouteItemParamService.list( |
| | | new LambdaQueryWrapper<ProductionProductRouteItemParam>() |
| | | .eq(ProductionProductRouteItemParam::getProductionProductRouteItemId, routeItem.getId())); |
| | | if (paramList != null && !paramList.isEmpty()) { |
| | | List<ProductionProductRouteItemParamDto> paramDtoList = paramList.stream().map(param -> { |
| | | ProductionProductRouteItemParamDto paramDto = new ProductionProductRouteItemParamDto(); |
| | | BeanUtils.copyProperties(param, paramDto); |
| | | if (paramDto.getProductId() != null) { |
| | | ProductMaterialSkuDto materialSkuDto = productMaterialService.selectProductByModelId(paramDto.getProductId()); |
| | | productMaterialService.selectProductByModelId(paramDto.getProductId()); |
| | | paramDto.setParamName(materialSkuDto.getProductName()); |
| | | } |
| | | return paramDto; |
| | | }).collect(Collectors.toList()); |
| | | routeItemDto.setProductionProductRouteItemParamDtoList(paramDtoList); |
| | | } |
| | | |
| | | // æ¥è¯¢å·¥åºéä»¶ |
| | | List<ProductionProductRouteItemFile> fileRecordList = productionProductRouteItemFileService.list( |
| | | new LambdaQueryWrapper<ProductionProductRouteItemFile>() |
| | | .eq(ProductionProductRouteItemFile::getProductionProductRouteItemId, routeItem.getId())); |
| | | if (fileRecordList != null && !fileRecordList.isEmpty()) { |
| | | List<ProductionProductRouteItemFileDto> fileDtoList = fileRecordList.stream().map(file -> { |
| | | ProductionProductRouteItemFileDto fileDto = new ProductionProductRouteItemFileDto(); |
| | | BeanUtils.copyProperties(file, fileDto); |
| | | return fileDto; |
| | | }).collect(Collectors.toList()); |
| | | routeItemDto.setFileList(fileDtoList); |
| | | } |
| | | |
| | | return routeItemDto; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | dto.setProductionProductRouteItemDtoList(routeItemDtoList); |
| | | } |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void editProductMain(ProductionRecordDto dto) { |
| | | if (dto == null || dto.getProductMainId() == null) { |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼æ¥å·¥IDä¸è½ä¸ºç©º"); |
| | | } |
| | | if (dto.getProductId() == null) { |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼äº§åä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (StringUtils.isEmpty(dto.getPostName()) || StringUtils.isEmpty(dto.getSchedule())) { |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼å²ä½äººå/çæ¬¡ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Long productMainId = dto.getProductMainId(); |
| | | |
| | | // æ¥è¯¢æ¥å·¥ä¸»è¡¨æ¯å¦åå¨ |
| | | ProductionProductMain productMain = productionProductMainService.getById(productMainId); |
| | | if (productMain == null) { |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼æ¥å·¥è®°å½ä¸åå¨"); |
| | | } |
| | | |
| | | // åæ»ç产订åçåæ ¼æ°é |
| | | ProductionProductOutput oldOutput = productionProductOutputService.getOne(new LambdaQueryWrapper<ProductionProductOutput>() |
| | | .eq(ProductionProductOutput::getProductMainId, productMainId) |
| | | .last("LIMIT 1")); |
| | | |
| | | ProductOrder productOrder = productOrderService.getById(productMain.getProductOrderId()); |
| | | if (productOrder == null) { |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼å
³èçç产订åä¸åå¨"); |
| | | } |
| | | |
| | | BigDecimal oldQualifiedQty = (oldOutput != null && oldOutput.getQuantity() != null) |
| | | ? oldOutput.getQuantity() : BigDecimal.ZERO; |
| | | BigDecimal newQualifiedQty = dto.getQualifiedQuantity() == null ? BigDecimal.ZERO : dto.getQualifiedQuantity(); |
| | | BigDecimal currentCompleteQty = productOrder.getCompleteQuantity() == null |
| | | ? BigDecimal.ZERO : productOrder.getCompleteQuantity(); |
| | | BigDecimal totalQty = productOrder.getQuantity() == null ? BigDecimal.ZERO : productOrder.getQuantity(); |
| | | |
| | | // åæ»æ§å¼ï¼è®¡ç®æ¬æ¬¡ç¼è¾åçæ°å®ææ°é |
| | | BigDecimal baseQty = currentCompleteQty.subtract(oldQualifiedQty); |
| | | BigDecimal updatedCompleteQty = baseQty.add(newQualifiedQty); |
| | | |
| | | // æ°çåæ ¼æ°éä¸è½è¶
è¿ï¼éæ±æ°é - æ¥å·¥æ»å®ææ°éï¼ |
| | | if (newQualifiedQty.compareTo(totalQty.subtract(baseQty)) > 0) { |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼æ¬æ¬¡æ¥å·¥åæ ¼æ°éä¸è½å¤§äºå©ä½å¯æ¥å·¥æ°é"); |
| | | } |
| | | |
| | | // 鿰夿ç产订åç¶æ |
| | | productOrder.setCompleteQuantity(updatedCompleteQty); |
| | | if (updatedCompleteQty.compareTo(totalQty) >= 0 && totalQty.compareTo(BigDecimal.ZERO) > 0) { |
| | | productOrder.setStatus(ProductOrderStatusEnum.FINISHED.getCode()); |
| | | productOrder.setEndTime(LocalDateTime.now()); |
| | | } else { |
| | | productOrder.setStatus(ProductOrderStatusEnum.RUNNING.getCode()); |
| | | productOrder.setEndTime(null); |
| | | } |
| | | productOrderService.updateById(productOrder); |
| | | |
| | | // æ´æ°æ¥å·¥ä¸»è¡¨ |
| | | productMain.setPostName(dto.getPostName()); |
| | | productMain.setSchedule(dto.getSchedule()); |
| | | productMain.setReportingTime(dto.getReportingTime()); |
| | | productionProductMainService.updateById(productMain); |
| | | |
| | | // æ´æ°æå
¥è¡¨ |
| | | ProductionProductInput input = productionProductInputService.getOne(new LambdaQueryWrapper<ProductionProductInput>() |
| | | .eq(ProductionProductInput::getProductMainId, productMainId) |
| | | .last("LIMIT 1")); |
| | | if (input != null) { |
| | | input.setProductModelId(dto.getProductId()); |
| | | input.setQuantity(dto.getQuantity()); |
| | | productionProductInputService.updateById(input); |
| | | } |
| | | |
| | | // æ´æ°äº§åºè¡¨ |
| | | if (oldOutput != null) { |
| | | oldOutput.setProductModelId(dto.getProductId()); |
| | | oldOutput.setQuantity(dto.getQualifiedQuantity()); |
| | | oldOutput.setScrapQty(dto.getUnqualifiedQuantity()); |
| | | productionProductOutputService.updateById(oldOutput); |
| | | } |
| | | |
| | | // å¤çå·¥åºå表 |
| | | List<ProductionProductRouteItemDto> routeItemDtoList = dto.getProductionProductRouteItemDtoList(); |
| | | if (routeItemDtoList == null || routeItemDtoList.isEmpty()) { |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼å·¥åºåæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | for (ProductionProductRouteItemDto routeItemDto : routeItemDtoList) { |
| | | // æ´æ°å·²æå·¥åº |
| | | ProductionProductRouteItem routeItemEntity = productionProductRouteItemService.getById(routeItemDto.getId()); |
| | | if (routeItemEntity == null) { |
| | | log.error("ç¼è¾å¤±è´¥,å·¥åºè®°å½ä¸åå¨,ID={}", routeItemDto.getId()); |
| | | throw new ServiceException("ç¼è¾å¤±è´¥ï¼å·¥åºè®°å½ä¸åå¨"); |
| | | } |
| | | BeanUtils.copyProperties(routeItemDto, routeItemEntity, "id", "productMainId", "createTime", "tenantId"); |
| | | productionProductRouteItemService.updateById(routeItemEntity); |
| | | |
| | | final Long routeItemId = routeItemEntity.getId(); |
| | | |
| | | // å¤çå·¥åºåæ°: å
å é¤è¯¥å·¥åºä¸æææ§åæ°ï¼åéæ°æå
¥ä¼ å
¥çåæ° |
| | | productionProductRouteItemParamService.remove(new LambdaQueryWrapper<ProductionProductRouteItemParam>() |
| | | .eq(ProductionProductRouteItemParam::getProductionProductRouteItemId, routeItemId)); |
| | | |
| | | List<ProductionProductRouteItemParamDto> paramDtoList = routeItemDto.getProductionProductRouteItemParamDtoList(); |
| | | if (paramDtoList != null && !paramDtoList.isEmpty()) { |
| | | for (ProductionProductRouteItemParamDto paramDto : paramDtoList) { |
| | | ProductionProductRouteItemParam paramEntity = new ProductionProductRouteItemParam(); |
| | | BeanUtils.copyProperties(paramDto, paramEntity, "id"); |
| | | paramEntity.setProductionProductRouteItemId(routeItemId); |
| | | if (paramEntity.getProductId() == null && paramDto.getId() != null) { |
| | | ProductionOrderRouteItemParam orderParam = productionOrderRouteItemParamService.getById(paramDto.getId()); |
| | | if (orderParam != null) { |
| | | paramEntity.setOrderItemParamId(orderParam.getId()); |
| | | paramEntity.setParamName(orderParam.getParamName()); |
| | | paramEntity.setParamType(orderParam.getParamType()); |
| | | paramEntity.setParamFormat(orderParam.getParamFormat()); |
| | | paramEntity.setValueMode(orderParam.getValueMode()); |
| | | } |
| | | } |
| | | productionProductRouteItemParamService.save(paramEntity); |
| | | } |
| | | } |
| | | |
| | | // å¤çæ°ä¸ä¼ ç临æ¶éä»¶ |
| | | List<String> newFiles = routeItemDto.getFiles(); |
| | | if (newFiles != null && !newFiles.isEmpty()) { |
| | | for (String tempId : newFiles) { |
| | | TempFile tempFile = tempFileMapper.selectById(tempId); |
| | | if (tempFile == null) { |
| | | log.warn("æªæ¾å°ä¸´æ¶æä»¶è®°å½: {}", tempId); |
| | | continue; |
| | | } |
| | | try { |
| | | String formalDir = uploadDir + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE); |
| | | Path formalDirPath = Paths.get(formalDir); |
| | | if (!Files.exists(formalDirPath)) { |
| | | Files.createDirectories(formalDirPath); |
| | | } |
| | | String originalFilename = tempFile.getOriginalName(); |
| | | String fileExtension = FilenameUtils.getExtension(originalFilename); |
| | | String formalFilename = routeItemId + "_" |
| | | + System.currentTimeMillis() + "_" |
| | | + UUID.randomUUID().toString().substring(0, 8) |
| | | + (StringUtils.hasText(fileExtension) ? "." + fileExtension : ""); |
| | | Path formalFilePath = formalDirPath.resolve(formalFilename); |
| | | |
| | | Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING); |
| | | Files.deleteIfExists(Paths.get(tempFile.getTempPath())); |
| | | |
| | | ProductionProductRouteItemFile fileEntity = new ProductionProductRouteItemFile(); |
| | | fileEntity.setProductionProductRouteItemId(routeItemId); |
| | | fileEntity.setFileName(originalFilename); |
| | | fileEntity.setFileUrl(formalFilePath.toString()); |
| | | fileEntity.setFileSuffix(fileExtension); |
| | | fileEntity.setFileSize(Files.size(formalFilePath)); |
| | | fileEntity.setCreateTime(LocalDateTime.now()); |
| | | fileEntity.setTenantId(SecurityUtils.getLoginUser().getTenantId()); |
| | | productionProductRouteItemFileService.save(fileEntity); |
| | | |
| | | tempFileMapper.deleteById(tempId); |
| | | log.info("ç¼è¾-å·¥åºéä»¶è¿ç§»æå: {} -> {}", tempFile.getTempPath(), formalFilePath); |
| | | } catch (IOException e) { |
| | | log.error("ç¼è¾-å·¥åºéä»¶è¿ç§»å¤±è´¥: {}", tempFile.getTempPath(), e); |
| | | throw new ServiceException("å·¥åºéä»¶å¤çå¼å¸¸: " + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | List<Long> delFileIds = routeItemDto.getDelFileIds(); |
| | | if (delFileIds != null && !delFileIds.isEmpty()) { |
| | | delFileIds.forEach(productionProductRouteItemFileService::deleteFile); |
| | | } |
| | | } |
| | | log.info("æ¥å·¥è®°å½ç¼è¾æåï¼productMainId={}", productMainId); |
| | | } |
| | | } |