| | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.StorageBlobVO; |
| | | import com.ruoyi.basic.mapper.StorageAttachmentMapper; |
| | | import com.ruoyi.basic.mapper.StorageBlobMapper; |
| | | import com.ruoyi.basic.pojo.StorageAttachment; |
| | | import com.ruoyi.basic.pojo.StorageBlob; |
| | | import com.ruoyi.basic.utils.FileUtil; |
| | | import com.ruoyi.common.constant.StorageAttachmentConstants; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.production.bean.dto.ProductionOrderDto; |
| | | import com.ruoyi.production.bean.vo.ProductionOrderVo; |
| | | import com.ruoyi.production.mapper.ProductionBomStructureMapper; |
| | | import com.ruoyi.production.mapper.ProductionOperationTaskMapper; |
| | | import com.ruoyi.production.mapper.ProductionOrderBomMapper; |
| | | import com.ruoyi.production.mapper.ProductionOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductionOrderPickMapper; |
| | | import com.ruoyi.production.mapper.ProductionOrderPickRecordMapper; |
| | | import com.ruoyi.production.mapper.ProductionOrderRoutingMapper; |
| | | import com.ruoyi.production.mapper.ProductionOrderRoutingOperationMapper; |
| | | import com.ruoyi.production.mapper.ProductionOrderRoutingOperationParamMapper; |
| | | import com.ruoyi.production.mapper.ProductionPlanMapper; |
| | | import com.ruoyi.production.mapper.ProductionProductMainMapper; |
| | | import com.ruoyi.production.pojo.ProductionOrderPick; |
| | | import com.ruoyi.production.pojo.ProductionOrderPickRecord; |
| | | import com.ruoyi.production.pojo.ProductionBomStructure; |
| | | import com.ruoyi.production.pojo.ProductionOperationTask; |
| | | import com.ruoyi.production.pojo.ProductionOrder; |
| | | import com.ruoyi.production.pojo.ProductionOrderBom; |
| | | import com.ruoyi.production.pojo.ProductionOrderRouting; |
| | | import com.ruoyi.production.pojo.ProductionOrderRoutingOperation; |
| | | import com.ruoyi.production.pojo.ProductionOrderRoutingOperationParam; |
| | | import com.ruoyi.production.pojo.ProductionPlan; |
| | | import com.ruoyi.production.pojo.ProductionProductMain; |
| | | import com.ruoyi.production.enums.ProductOrderStatusEnum; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.production.service.ProductionOrderService; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.production.service.ProductionOrderService; |
| | | import com.ruoyi.technology.mapper.TechnologyBomMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyBomStructureMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyRoutingMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyRoutingOperationMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyRoutingOperationParamMapper; |
| | | import com.ruoyi.technology.pojo.TechnologyBom; |
| | | import com.ruoyi.technology.pojo.TechnologyBomStructure; |
| | | import com.ruoyi.technology.pojo.TechnologyRouting; |
| | | import com.ruoyi.technology.pojo.TechnologyRoutingOperation; |
| | | import com.ruoyi.technology.pojo.TechnologyRoutingOperationParam; |
| | | import com.ruoyi.technology.mapper.*; |
| | | import com.ruoyi.technology.pojo.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | private final ProductionOrderPickMapper productionOrderPickMapper; |
| | | private final ProductionOrderPickRecordMapper productionOrderPickRecordMapper; |
| | | private final ProductionPlanMapper productionPlanMapper; |
| | | private final StorageAttachmentMapper storageAttachmentMapper; |
| | | private final StorageBlobMapper storageBlobMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | | private final TechnologyRoutingMapper technologyRoutingMapper; |
| | |
| | | private final TechnologyRoutingOperationParamMapper technologyRoutingOperationParamMapper; |
| | | private final TechnologyBomMapper technologyBomMapper; |
| | | private final TechnologyBomStructureMapper technologyBomStructureMapper; |
| | | private final FileUtil fileUtil; |
| | | |
| | | @Override |
| | | public com.baomidou.mybatisplus.core.metadata.IPage<ProductionOrderVo> pageProductionOrder(Page<ProductionOrderDto> page, ProductionOrderDto dto) { |
| | | Page<ProductionOrder> entityPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal()); |
| | | return this.page(entityPage, buildQueryWrapper(dto)).convert(item -> BeanUtil.copyProperties(item, ProductionOrderVo.class)); |
| | | public IPage<ProductionOrderVo> pageProductionOrder(Page<ProductionOrderDto> page, ProductionOrderDto dto) { |
| | | Page<ProductionOrderVo> result = (Page<ProductionOrderVo>) baseMapper.pageProductionOrder(page, dto); |
| | | fillProductImages(result.getRecords()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<ProductionOrderVo> listProductionOrder(ProductionOrderDto dto) { |
| | | return BeanUtil.copyToList(this.list(buildQueryWrapper(dto)), ProductionOrderVo.class); |
| | | List<ProductionOrderVo> records = baseMapper.listProductionOrder(dto); |
| | | fillProductImages(records); |
| | | return records; |
| | | } |
| | | |
| | | @Override |
| | | public ProductionOrderVo getProductionOrderInfo(Long id) { |
| | | ProductionOrder item = this.getById(id); |
| | | return item == null ? null : BeanUtil.copyProperties(item, ProductionOrderVo.class); |
| | | ProductionOrderVo item = baseMapper.getProductionOrderInfo(id); |
| | | if (item == null) { |
| | | return null; |
| | | } |
| | | fillProductImages(java.util.Collections.singletonList(item)); |
| | | return item; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (defaultDecimal(productionOrder.getQuantity()).compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new ServiceException("quantity must be greater than 0"); |
| | | } |
| | | if (productionOrder.getTechnologyRoutingId() == null) { |
| | | // 未显式指定工艺路线时,按产品规格选最新一条工艺作为默认路线。 |
| | | TechnologyRouting technologyRouting = technologyRoutingMapper.selectOne( |
| | | Wrappers.<TechnologyRouting>lambdaQuery() |
| | | .eq(TechnologyRouting::getProductModelId, productionOrder.getProductModelId()) |
| | | .orderByDesc(TechnologyRouting::getId) |
| | | .last("limit 1")); |
| | | if (technologyRouting == null) { |
| | | throw new ServiceException("No technology routing found for the product model"); |
| | | } |
| | | productionOrder.setTechnologyRoutingId(technologyRouting.getId()); |
| | | } |
| | | // if (productionOrder.getTechnologyRoutingId() == null) { |
| | | // // 未显式指定工艺路线时,按产品规格选最新一条工艺作为默认路线。 |
| | | // TechnologyRouting technologyRouting = technologyRoutingMapper.selectOne( |
| | | // Wrappers.<TechnologyRouting>lambdaQuery() |
| | | // .eq(TechnologyRouting::getProductModelId, productionOrder.getProductModelId()) |
| | | // .orderByDesc(TechnologyRouting::getId) |
| | | // .last("limit 1")); |
| | | // if (technologyRouting == null) { |
| | | // throw new ServiceException("No technology routing found for the product model"); |
| | | // } |
| | | // productionOrder.setTechnologyRoutingId(technologyRouting.getId()); |
| | | // } |
| | | if (oldOrder != null && ProductOrderStatusEnum.isStarted(oldOrder.getStatus())) { |
| | | // 开工后只允许修正非核心字段,核心生产依据锁定。 |
| | | if (!Objects.equals(oldOrder.getProductModelId(), productionOrder.getProductModelId()) |
| | |
| | | return null; |
| | | } |
| | | if (productionPlan.getPromisedDeliveryDate() != null) { |
| | | return productionPlan.getPromisedDeliveryDate().toLocalDate(); |
| | | return productionPlan.getPromisedDeliveryDate(); |
| | | } |
| | | if (productionPlan.getRequiredDate() != null) { |
| | | return productionPlan.getRequiredDate().toLocalDate(); |
| | | return productionPlan.getRequiredDate(); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | private int compareDecimal(BigDecimal left, BigDecimal right) { |
| | | return defaultDecimal(left).compareTo(defaultDecimal(right)); |
| | | } |
| | | |
| | | private void fillProductImages(List<ProductionOrderVo> records) { |
| | | if (records == null || records.isEmpty()) { |
| | | return; |
| | | } |
| | | List<Long> productModelIds = records.stream() |
| | | .map(ProductionOrderVo::getProductModelId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (productModelIds.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<StorageAttachment> attachments = storageAttachmentMapper.selectList( |
| | | Wrappers.<StorageAttachment>lambdaQuery() |
| | | .in(StorageAttachment::getRecordId, productModelIds) |
| | | .eq(StorageAttachment::getApplication, StorageAttachmentConstants.StorageAttachmentImage) |
| | | .eq(StorageAttachment::getDeleted, 0L) |
| | | .orderByAsc(StorageAttachment::getId)); |
| | | if (attachments == null || attachments.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | Map<Long, List<StorageAttachment>> attachmentMap = attachments.stream() |
| | | .collect(Collectors.groupingBy(StorageAttachment::getRecordId, java.util.LinkedHashMap::new, Collectors.toList())); |
| | | List<Long> blobIds = attachments.stream() |
| | | .map(StorageAttachment::getStorageBlobId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (blobIds.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | Map<Long, StorageBlob> blobMap = storageBlobMapper.selectBatchIds(blobIds).stream() |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toMap(StorageBlob::getId, item -> item)); |
| | | for (ProductionOrderVo record : records) { |
| | | List<StorageAttachment> modelAttachments = attachmentMap.get(record.getProductModelId()); |
| | | if (modelAttachments == null || modelAttachments.isEmpty()) { |
| | | continue; |
| | | } |
| | | List<StorageBlobVO> images = modelAttachments.stream() |
| | | .map(StorageAttachment::getStorageBlobId) |
| | | .map(blobMap::get) |
| | | .filter(Objects::nonNull) |
| | | .map(this::toStorageBlobVO) |
| | | .collect(Collectors.toList()); |
| | | if (!images.isEmpty()) { |
| | | record.setProductImages(images); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private StorageBlobVO toStorageBlobVO(StorageBlob blob) { |
| | | StorageBlobVO vo = BeanUtil.copyProperties(blob, StorageBlobVO.class); |
| | | vo.setPreviewURL(fileUtil.buildSignedPreviewUrl(vo)); |
| | | vo.setDownloadURL(fileUtil.buildSignedDownloadUrl(vo)); |
| | | return vo; |
| | | } |
| | | } |