| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.purchase.dto.ProductRecordDto; |
| | | import com.ruoyi.purchase.dto.TicketRegistrationDto; |
| | | import com.ruoyi.purchase.mapper.ProductRecordMapper; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | | import com.ruoyi.purchase.mapper.TicketRegistrationMapper; |
| | | import com.ruoyi.purchase.pojo.ProductRecord; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import com.ruoyi.purchase.pojo.TicketRegistration; |
| | | import com.ruoyi.purchase.service.IProductRecordService; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @AllArgsConstructor |
| | | public class ProductRecordServiceImpl extends ServiceImpl<ProductRecordMapper, ProductRecord> implements IProductRecordService { |
| | | |
| | | @Autowired |
| | | private ProductRecordMapper productRecordMapper; |
| | | |
| | | @Autowired |
| | | private CommonFileMapper commonFileMapper; |
| | | @Autowired |
| | | private SalesLedgerProductMapper salesLedgerProductMapper; |
| | | @Autowired |
| | | private PurchaseLedgerMapper purchaseLedgerMapper; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | public IPage<ProductRecordDto> productRecordPage(Page page, TicketRegistrationDto ticketRegistrationDto) { |
| | | |
| | | return productRecordMapper.productRecordPage(page, ticketRegistrationDto); |
| | | IPage<ProductRecordDto> productRecordDtoIPage1 = productRecordMapper.productRecordPage(page, ticketRegistrationDto); |
| | | page.setSize(productRecordDtoIPage1.getTotal()); |
| | | IPage<ProductRecordDto> productRecordDtoIPage = productRecordMapper.productRecordPage(page, ticketRegistrationDto); |
| | | productRecordDtoIPage.getRecords().forEach(productRecordDto -> { |
| | | productRecordDto.setCommonFiles(commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, productRecordDto.getId()) |
| | | .eq(CommonFile::getType, FileNameType.PURCHASELEDGER.getValue()))); |
| | | }); |
| | | return productRecordDtoIPage; |
| | | } |
| | | |
| | | private final TicketRegistrationMapper ticketRegistrationMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult updateRecord(ProductRecordDto productRecordDto) { |
| | | ProductRecord productRecord = productRecordMapper.selectById(productRecordDto.getId()); |
| | | if (productRecord == null) return AjaxResult.error("记录不存在"); |
| | | |
| | | // 更新产品台账 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(productRecord.getSaleLedgerProjectId()); |
| | | if (salesLedgerProduct != null) { |
| | | // 未来票金额 = 原未来票金额 + 旧行金额 - 新行金额 |
| | | BigDecimal futureTicketsAmount = salesLedgerProduct.getFutureTicketsAmount() |
| | | .add(productRecord.getTicketsAmount()) |
| | | .subtract(productRecordDto.getTicketsAmount()); |
| | | salesLedgerProduct.setFutureTicketsAmount(futureTicketsAmount); |
| | | |
| | | // 未来票数 = 原未来票数 + 旧行数量 - 新行数量 |
| | | BigDecimal futureTickets = salesLedgerProduct.getFutureTickets() |
| | | .add(productRecord.getTicketsNum()) |
| | | .subtract(productRecordDto.getTicketsNum()); |
| | | salesLedgerProduct.setFutureTickets(futureTickets); |
| | | |
| | | // 更新产品表本次数值 |
| | | salesLedgerProduct.setTicketsAmount(productRecordDto.getTicketsAmount()); |
| | | salesLedgerProduct.setTicketsNum(productRecordDto.getTicketsNum()); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | |
| | | // 更新来票登记 |
| | | TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(productRecord.getTicketRegistrationId()); |
| | | if (ticketRegistration != null) { |
| | | // 金额 = 新金额 - 旧金额 |
| | | BigDecimal amountDiff = productRecordDto.getTicketsAmount().subtract(productRecord.getTicketsAmount()); |
| | | // 总金额 = 原总金额 + 差值 |
| | | ticketRegistration.setInvoiceAmount(ticketRegistration.getInvoiceAmount().add(amountDiff)); |
| | | // 更新发票号 |
| | | ticketRegistration.setInvoiceNumber(productRecordDto.getInvoiceNumber()); |
| | | |
| | | ticketRegistrationMapper.updateById(ticketRegistration); |
| | | } |
| | | |
| | | BeanUtils.copyProperties(productRecordDto, productRecord); |
| | | // 重新计算未来票金额(根据剩余票数 * 单价) |
| | | productRecord.setFutureTicketsAmount(productRecord.getFutureTickets().multiply(productRecord.getTaxInclusiveUnitPrice())); |
| | | productRecordMapper.updateById(productRecord); |
| | | |
| | | return AjaxResult.success("修改成功"); |
| | | } |
| | | |
| | | @Override |
| | | public ProductRecordDto getProductRecordById(ProductRecordDto productRecordDto) { |
| | | List<ProductRecordDto> productRecordDtoList = productRecordMapper.getProductRecordById(productRecordDto); |
| | | if (CollectionUtils.isNotEmpty(productRecordDtoList)) { |
| | | ProductRecordDto productRecordDto1 = productRecordDtoList.stream() |
| | | .filter(item -> item.getId().equals(productRecordDto.getId())) |
| | | .findFirst() |
| | | .orElse(null); |
| | | // 过滤出与传入的 productRecordDto 主键相同的记录 |
| | | BigDecimal reduce = productRecordDtoList |
| | | .stream() |
| | | .filter(item -> item.getProductModelId().equals(productRecordDto.getProductModelId())) |
| | | .map(ProductRecordDto::getTicketsNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (productRecordDto1 != null) { |
| | | productRecordDto1.setFutureTickets(productRecordDto1.getQuantity().subtract(reduce)); |
| | | productRecordDto1.setFutureTicketsAmount(productRecordDto1.getFutureTickets().multiply(productRecordDto1.getTaxInclusiveUnitPrice())); |
| | | } |
| | | return productRecordDto1; |
| | | } |
| | | return null; |
| | | } |
| | | } |