| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.business.dto.PurchaseRegistrationDto; |
| | | import com.ruoyi.business.entity.PendingInventory; |
| | | import com.ruoyi.business.entity.PurchaseRegistration; |
| | | import com.ruoyi.business.mapper.PendingInventoryMapper; |
| | | import com.ruoyi.business.mapper.PurchaseRegistrationMapper; |
| | | import com.ruoyi.business.service.PurchaseRegistrationService; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.Objects; |
| | | |
| | |
| | | |
| | | private final PurchaseRegistrationMapper purchaseRegistrationMapper; |
| | | |
| | | private final PendingInventoryMapper pendingInventoryMapper; |
| | | |
| | | @Override |
| | | public IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page page, PurchaseRegistrationDto purchaseRegistrationDto) { |
| | | LambdaQueryWrapper<PurchaseRegistration> queryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addOrEditPR(PurchaseRegistrationDto purchaseRegistrationDto) { |
| | | // 参数校验 |
| | | Assert.notNull(purchaseRegistrationDto, "采购登记信息不能为空"); |
| | | |
| | | // 创建采购登记实体并复制属性 |
| | | PurchaseRegistration purchaseRegistration = new PurchaseRegistration(); |
| | | BeanUtils.copyProperties(purchaseRegistrationDto,purchaseRegistration); |
| | | |
| | | BeanUtils.copyProperties(purchaseRegistrationDto, purchaseRegistration); |
| | | |
| | | if (Objects.isNull(purchaseRegistrationDto.getId())) { |
| | | return purchaseRegistrationMapper.insert(purchaseRegistration); |
| | | // 新增采购登记 |
| | | int insertCount = purchaseRegistrationMapper.insert(purchaseRegistration); |
| | | if (insertCount > 0) { |
| | | // 采购登记成功,同步创建待入库记录 |
| | | PendingInventory pendingInventory = createPendingInventory(purchaseRegistration); |
| | | return pendingInventoryMapper.insert(pendingInventory); |
| | | } |
| | | return insertCount; |
| | | } else { |
| | | // 更新采购登记 |
| | | return purchaseRegistrationMapper.updateById(purchaseRegistration); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据采购登记信息创建待入库记录 |
| | | * @param purchaseRegistration 采购登记实体 |
| | | * @return 待入库实体 |
| | | */ |
| | | private PendingInventory createPendingInventory(PurchaseRegistration purchaseRegistration) { |
| | | PendingInventory pendingInventory = new PendingInventory(); |
| | | // 复制基本属性 |
| | | BeanUtils.copyProperties(purchaseRegistration, pendingInventory); |
| | | |
| | | // 设置待入库记录特有的属性(如果有) |
| | | // pendingInventory.setStatus(InventoryStatus.PENDING); |
| | | // pendingInventory.setCreateTime(LocalDateTime.now()); |
| | | |
| | | return pendingInventory; |
| | | } |
| | | |
| | | @Override |
| | | public int delByIds(Long[] ids) { |
| | | // 检查参数 |