liding
3 天以前 dc9010b9fc4ca6929992bfc3cc4fa110ebc24b2c
main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
@@ -8,7 +8,9 @@
import com.ruoyi.basic.entity.Customer;
import com.ruoyi.basic.mapper.CustomerMapper;
import com.ruoyi.business.dto.SalesRecordDto;
import com.ruoyi.business.entity.OfficialInventory;
import com.ruoyi.business.entity.SalesRecord;
import com.ruoyi.business.mapper.OfficialInventoryMapper;
import com.ruoyi.business.mapper.SalesRecordMapper;
import com.ruoyi.business.service.SalesRecordService;
import com.ruoyi.common.core.domain.entity.SysUser;
@@ -39,6 +41,8 @@
    private final CustomerMapper customerMapper;
    private final OfficialInventoryMapper officialInventoryMapper;
    @Override
    public IPage<SalesRecord> selectSalesRecordList(Page page, SalesRecordDto salesRecordDto) {
        LambdaQueryWrapper<SalesRecord> queryWrapper = new LambdaQueryWrapper<>();
@@ -52,8 +56,20 @@
        // 参数校验
        validateSalesRecordDto(salesRecordDto);
        // 更新正式库待补库数量
        OfficialInventory officialInventory = officialInventoryMapper.selectById(salesRecordDto.getCoalId());
        if (officialInventory == null) {
            throw new BaseException("正式库煤种信息不存在");
        }
        if (salesRecordDto.getSaleQuantity().compareTo(officialInventory.getInventoryQuantity()) > 0){
            throw new BaseException("销售数量不能大于库存数量");
        }
        officialInventory.setInventoryQuantity(officialInventory.getInventoryQuantity().subtract(salesRecordDto.getSaleQuantity()));
        officialInventory.setPendingReplenishment(salesRecordDto.getSaleQuantity());
        officialInventoryMapper.updateById(officialInventory);
        // 构建销售记录实体
        SalesRecord salesRecord = buildSalesRecord(salesRecordDto);
        SalesRecord salesRecord = buildSalesRecord(salesRecordDto,officialInventory.getCoal());
        // 处理新增/更新逻辑
        if (salesRecordDto.getId() == null) {
@@ -73,9 +89,12 @@
        if (dto.getCustomerId() == null) {
            throw new BaseException("客户ID不能为空");
        }
        if (dto.getCoalId() == null) {
            throw new BaseException("请选择一条煤种信息");
        }
    }
    private SalesRecord buildSalesRecord(SalesRecordDto dto) {
    private SalesRecord buildSalesRecord(SalesRecordDto dto,String coal) {
        SalesRecord record = new SalesRecord();
        BeanUtils.copyProperties(dto, record);
@@ -109,6 +128,9 @@
            record.setRegistrationDate(existing.getRegistrationDate());
        }
        // 煤种
        record.setCoal(coal);
        return record;
    }