package com.ruoyi.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.dto.OfficialInventoryDto;
import com.ruoyi.business.dto.PendingInventoryDto;
import com.ruoyi.business.entity.InputInventoryRecord;
import com.ruoyi.business.mapper.InputInventoryRecordMapper;
import com.ruoyi.business.service.InputInventoryRecordService;
import com.ruoyi.business.service.InventorySummaryService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import static com.ruoyi.business.constant.InventoryRecordConstant.OFFICIAL_INVENTORY;
import static com.ruoyi.business.constant.InventoryRecordConstant.PENDING_INVENTORY;
/**
*
* 入库记录表 服务实现类
*
*
* @author chenhj
* @since 2025-06-14
*/
@Service
@RequiredArgsConstructor
public class InputInventoryRecordServiceImpl extends ServiceImpl implements InputInventoryRecordService {
@Autowired
private InputInventoryRecordMapper inputInventoryRecordMapper;
@Autowired
private InventorySummaryService inventorySummaryService;
@Override
public int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) {
if ((pendingInventoryDto != null && officialInventoryDto != null) || (pendingInventoryDto == null && officialInventoryDto == null)) {
throw new RuntimeException("库存记录异常");
}
InputInventoryRecord inputInventoryRecord = new InputInventoryRecord();
if (officialInventoryDto != null) {
inputInventoryRecord.setInventoryType(OFFICIAL_INVENTORY);
inputInventoryRecord.setId(officialInventoryDto.getId());
} else {
inputInventoryRecord.setInventoryType(PENDING_INVENTORY);
inputInventoryRecord.setId(pendingInventoryDto.getId());
}
inputInventoryRecord.setQuantity(quantity);
inputInventoryRecordMapper.insert(inputInventoryRecord);
// 更新库存
return inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto);
}
}