| | |
| | | import com.ruoyi.procurementrecord.dto.*; |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper; |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecord; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordOut; |
| | | import com.ruoyi.procurementrecord.service.ProcurementRecordService; |
| | | import com.ruoyi.quality.pojo.QualityInspect; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | @Slf4j |
| | | public class ProcurementRecordServiceImpl extends ServiceImpl<ProcurementRecordMapper, ProcurementRecord> implements ProcurementRecordService { |
| | | public class ProcurementRecordServiceImpl extends ServiceImpl<ProcurementRecordMapper, ProcurementRecordStorage> implements ProcurementRecordService { |
| | | |
| | | private final ProcurementRecordMapper procurementRecordMapper; |
| | | |
| | |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | return procurementDtos; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecord> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecord::getSalesLedgerProductId, collect); |
| | | List<ProcurementRecord> procurementRecords = procurementRecordMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordStorage::getSalesLedgerProductId, collect); |
| | | List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty(procurementRecordStorages)){ |
| | | return procurementDtos; |
| | | } |
| | | for (ProcurementDto dto : procurementDtos) { |
| | | // 根据采购台账ID筛选对应的入库记录 |
| | | List<ProcurementRecord> collect1 = procurementRecords.stream() |
| | | .filter(procurementRecord -> procurementRecord.getSalesLedgerProductId().equals(dto.getId())) |
| | | List<ProcurementRecordStorage> collect1 = procurementRecordStorages.stream() |
| | | .filter(procurementRecordStorage -> procurementRecordStorage.getSalesLedgerProductId().equals(dto.getId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的入库记录,跳过该条数据 |
| | |
| | | |
| | | // 计算已入库数量总和,并设置待入库数量 |
| | | BigDecimal totalInboundNum = collect1.stream() |
| | | .map(ProcurementRecord::getInboundNum) |
| | | .map(ProcurementRecordStorage::getInboundNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 待入库数量 = 总数量 - 已入库数量 |
| | |
| | | return procurementDtos; |
| | | } |
| | | |
| | | public ProcurementRecord getProcurementRecordById(Integer id){ |
| | | ProcurementRecord procurementRecord = procurementRecordMapper.selectById(id); |
| | | if(procurementRecord == null) { |
| | | public ProcurementRecordStorage getProcurementRecordById(Integer id){ |
| | | ProcurementRecordStorage procurementRecordStorage = procurementRecordMapper.selectById(id); |
| | | if(procurementRecordStorage == null) { |
| | | throw new RuntimeException("未找到该采购入库记录"); |
| | | } |
| | | return procurementRecord; |
| | | return procurementRecordStorage; |
| | | } |
| | | |
| | | public List<ProcurementRecord> getProcurementRecordByIds(List<Integer> id){ |
| | | List<ProcurementRecord> procurementRecord = procurementRecordMapper.selectBatchIds(id); |
| | | if(procurementRecord == null) { |
| | | public List<ProcurementRecordStorage> getProcurementRecordByIds(List<Integer> id){ |
| | | List<ProcurementRecordStorage> procurementRecordStorage = procurementRecordMapper.selectBatchIds(id); |
| | | if(procurementRecordStorage == null) { |
| | | throw new RuntimeException("未找到该采购入库记录"); |
| | | } |
| | | return procurementRecord; |
| | | return procurementRecordStorage; |
| | | } |
| | | |
| | | @Override |
| | | public int updatePro(ProcurementUpdateDto procurementDto) { |
| | | ProcurementRecord procurementRecordById = getProcurementRecordById(procurementDto.getId()); |
| | | procurementRecordById.setInboundNum(procurementDto.getQuantityStock()); |
| | | return procurementRecordMapper.updateById(procurementRecordById); |
| | | ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId()); |
| | | procurementRecordStorageById.setInboundNum(procurementDto.getQuantityStock()); |
| | | procurementRecordStorageById.setUpdateUser(SecurityUtils.getLoginUser().getUserId()); |
| | | procurementRecordStorageById.setUpdateTime(LocalDateTime.now()); |
| | | return procurementRecordMapper.updateById(procurementRecordStorageById); |
| | | } |
| | | |
| | | @Override |
| | | public int deletePro(ProcurementUpdateDto procurementDto) { |
| | | List<ProcurementRecord> procurementRecordById = getProcurementRecordByIds(procurementDto.getIds()); |
| | | procurementRecordMapper.deleteBatchIds(procurementRecordById.stream().map(ProcurementRecord::getId).collect(Collectors.toList())); |
| | | List<ProcurementRecordStorage> procurementRecordStorageById = getProcurementRecordByIds(procurementDto.getIds()); |
| | | procurementRecordMapper.deleteBatchIds(procurementRecordStorageById.stream().map(ProcurementRecordStorage::getId).collect(Collectors.toList())); |
| | | // 删除所有对应的出库记录 |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordOutLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordOutLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, procurementDto.getIds()); |
| | |
| | | // 批量新增 |
| | | for (Details detail : procurementDto.getDetails()) { |
| | | // 查询采购入库数量 |
| | | LambdaQueryWrapper<ProcurementRecord> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecord::getSalesLedgerProductId, detail.getId()); |
| | | LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordStorage::getSalesLedgerProductId, detail.getId()); |
| | | Long aLong = procurementRecordMapper.selectCount(procurementRecordLambdaQueryWrapper); |
| | | |
| | | ProcurementRecord.ProcurementRecordBuilder procurementRecordBuilder = ProcurementRecord.builder() |
| | | ProcurementRecordStorage.ProcurementRecordStorageBuilder procurementRecordBuilder = ProcurementRecordStorage.builder() |
| | | .salesLedgerProductId(detail.getId()) |
| | | .inboundBatches(aLong.equals(0L) ? "第1批次" : "第"+ (aLong + 1) + "批次") |
| | | .inboundNum(detail.getInboundQuantity()) |
| | | .createDate(LocalDateTime.now()) |
| | | .userId(loginUser.getUserId()) |
| | | .createTime(LocalDateTime.now()) |
| | | .createUser(loginUser.getUserId()) |
| | | .updateTime(LocalDateTime.now()) |
| | | .updateUser(loginUser.getUserId()) |
| | | .tenantId(loginUser.getTenantId()) |
| | | .createBy(procurementDto.getNickName()); |
| | | this.save(procurementRecordBuilder.build()); |