| | |
| | | package com.ruoyi.business.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private final SupplyMapper supplyMapper; |
| | | |
| | | @Override |
| | | public IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page page, PurchaseRegistrationDto purchaseRegistrationDto) { |
| | | public IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page<PurchaseRegistration> page, PurchaseRegistrationDto dto) { |
| | | LambdaQueryWrapper<PurchaseRegistration> queryWrapper = new LambdaQueryWrapper<>(); |
| | | if (StringUtils.isNotBlank(purchaseRegistrationDto.getSearchAll())){ |
| | | queryWrapper.and(wrapper -> wrapper |
| | | .like(PurchaseRegistration::getCoalId, purchaseRegistrationDto.getSearchAll()) |
| | | .or() |
| | | .like(PurchaseRegistration::getSupplierName, purchaseRegistrationDto.getSearchAll()) |
| | | ); |
| | | |
| | | String keyword = dto.getSearchAll(); |
| | | if (StringUtils.isNotBlank(keyword)) { |
| | | // 查询煤种名称中模糊匹配的coalId列表 |
| | | List<Long> matchedCoalIds = coalInfoMapper.selectList( |
| | | new LambdaQueryWrapper<CoalInfo>().like(CoalInfo::getCoal, keyword) |
| | | ).stream() |
| | | .map(CoalInfo::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 组装查询条件:煤种ID在匹配的列表中 或 供应商名称匹配 |
| | | queryWrapper.and(w -> { |
| | | if (!matchedCoalIds.isEmpty()) { |
| | | w.in(PurchaseRegistration::getCoalId, matchedCoalIds).or(); |
| | | } |
| | | w.like(PurchaseRegistration::getSupplierName, keyword); |
| | | }); |
| | | } |
| | | |
| | | queryWrapper.orderByDesc(PurchaseRegistration::getCreateTime); |
| | | |
| | | return purchaseRegistrationMapper.selectPage(page, queryWrapper); |
| | | } |
| | | |
| | |
| | | if (coalInfo == null) { |
| | | throw new BaseException("煤种信息不存在"); |
| | | } |
| | | // purchaseRegistration.setCoal(coalInfo.getCoal()); |
| | | Supply supply = supplyMapper.selectById(purchaseRegistrationDto.getSupplierId()); |
| | | if (supply == null) { |
| | | throw new BaseException("供应商信息不存在"); |
| | |
| | | BeanUtils.copyProperties(purchaseRegistration, pendingInventory); |
| | | |
| | | // 设置待入库记录特有的属性(如果有) |
| | | pendingInventory.setId(null); |
| | | pendingInventory.setPurchaseId(purchaseRegistration.getId()); |
| | | pendingInventory.setCoalId(purchaseRegistration.getCoalId()); |
| | | pendingInventory.setInventoryQuantity(purchaseRegistration.getPurchaseQuantity()); |
| | | return pendingInventory; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int delByIds(Long[] ids) { |
| | | // 检查参数 |
| | | if (ids == null || ids.length == 0) { |
| | | return 0; |
| | | } |
| | | // 构造更新条件 |
| | | UpdateWrapper<PurchaseRegistration> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.in("id", ids) |
| | | .set("deleted", 1); // 设置 deleted 为 1 表示已删除 |
| | | // 执行批量逻辑删除 |
| | | return purchaseRegistrationMapper.update(null, updateWrapper); |
| | | |
| | | // 1. 删除关联的PendingInventory记录 |
| | | LambdaQueryWrapper<PendingInventory> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.in(PendingInventory::getPurchaseId, Arrays.asList(ids)); |
| | | pendingInventoryMapper.delete(wrapper); // 改为delete操作 |
| | | |
| | | // 2. 批量删除采购注册记录 |
| | | return purchaseRegistrationMapper.deleteByIds(Arrays.asList(ids)); |
| | | } |
| | | |
| | | } |