| | |
| | | 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; |
| | |
| | | |
| | | private final CustomerMapper customerMapper; |
| | | |
| | | private final OfficialInventoryMapper officialInventoryMapper; |
| | | |
| | | @Override |
| | | public IPage<SalesRecord> selectSalesRecordList(Page page, SalesRecordDto salesRecordDto) { |
| | | LambdaQueryWrapper<SalesRecord> queryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | // 参数校验 |
| | | 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) { |
| | |
| | | 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); |
| | | |
| | |
| | | record.setRegistrationDate(existing.getRegistrationDate()); |
| | | } |
| | | |
| | | // 煤种 |
| | | record.setCoal(coal); |
| | | |
| | | return record; |
| | | } |
| | | |