liding
8 天以前 360f96ffb62a0ba418c0de0a4a5b5f537912872e
src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
@@ -5,13 +5,14 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.SupplierManageDto;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.vo.FileVo;
import com.ruoyi.sales.dto.InvoiceLedgerDto;
import com.ruoyi.sales.dto.InvoiceRegistrationProductDto;
import com.ruoyi.sales.excel.InvoiceLedgerExcelDto;
import com.ruoyi.sales.mapper.InvoiceLedgerFileMapper;
import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
import com.ruoyi.sales.pojo.InvoiceLedger;
import com.ruoyi.sales.pojo.InvoiceLedgerFile;
import com.ruoyi.sales.service.InvoiceLedgerService;
@@ -26,7 +27,11 @@
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -42,34 +47,49 @@
    @Autowired
    private InvoiceLedgerFileMapper invoiceLedgerFileMapper;
    @Autowired
    private InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
    /**
     * 开票台账新增
     * @param invoiceLedgerDto
     * @param productDto
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int invoiceLedgerSaveOrUpdate(InvoiceLedgerDto invoiceLedgerDto) {
        InvoiceLedger invoiceLedger = new InvoiceLedger();
        BeanUtils.copyProperties(invoiceLedgerDto, invoiceLedger);
    public int invoiceLedgerSaveOrUpdate(InvoiceRegistrationProductDto productDto) {
        // 判断是否已经新增开票台账
        QueryWrapper<InvoiceLedger> ledgerQueryWrapper = new QueryWrapper<>();
        ledgerQueryWrapper.eq("invoice_registration_product_id", productDto.getId());
        InvoiceLedger invoiceLedger = invoiceLedgerMapper.selectOne(ledgerQueryWrapper);
        int result;
        if(invoiceLedgerDto.getId() == null){
        if(ObjectUtils.isEmpty(invoiceLedger)){
            invoiceLedger = new InvoiceLedger();
            invoiceLedger.setInvoiceRegistrationProductId(productDto.getId());
            invoiceLedger.setInvoiceNo(productDto.getInvoiceNo());
            invoiceLedger.setInvoiceTotal(productDto.getInvoiceTotal());
            invoiceLedger.setInvoiceDate(productDto.getInvoiceDate());
            invoiceLedger.setInvoicePerson(productDto.getInvoicePerson());
            result = invoiceLedgerMapper.insert(invoiceLedger);
        }else {
            invoiceLedger.setInvoiceNo(productDto.getInvoiceNo());
            invoiceLedger.setInvoiceTotal(productDto.getInvoiceTotal());
            invoiceLedger.setInvoiceDate(productDto.getInvoiceDate());
            invoiceLedger.setInvoicePerson(productDto.getInvoicePerson());
            result = invoiceLedgerMapper.updateById(invoiceLedger);
            //删除所有附件关联
            LambdaQueryWrapper<InvoiceLedgerFile> delWrapper = new LambdaQueryWrapper<>();
            delWrapper.eq(InvoiceLedgerFile::getInvoiceLedgerId, invoiceLedgerDto.getId());
            delWrapper.eq(InvoiceLedgerFile::getInvoiceLedgerId, invoiceLedger.getId());
            invoiceLedgerFileMapper.delete(delWrapper);
        }
        List<FileVo> fileList = invoiceLedgerDto.getFileList();
        List<FileVo> fileList = productDto.getFileList();
        if(CollectionUtils.isNotEmpty(fileList)){
            fileList.forEach(fileVo -> {
            for (FileVo fileVo : fileList) {
                InvoiceLedgerFile invoiceLedgerFile = new InvoiceLedgerFile();
                BeanUtils.copyProperties(fileVo, invoiceLedgerFile);
                invoiceLedgerFile.setInvoiceLedgerId(invoiceLedger.getId());
                invoiceLedgerFileMapper.insert(invoiceLedgerFile);
            });
            }
        }
        return result;
    }
@@ -199,4 +219,82 @@
        });
    }
    /**
     * 开票台账查询
     * @param invoiceLedgerDto
     * @return
     */
    @Override
    public List<InvoiceLedgerDto> invoiceLedgerList(InvoiceLedgerDto invoiceLedgerDto) {
        return invoiceLedgerMapper.invoiceLedgerList(invoiceLedgerDto);
    }
    /**
     * 客户销售记录
     * @param page
     * @param invoiceLedgerDto
     * @return
     */
    @Override
    public IPage<InvoiceLedgerDto> invoiceLedgerSalesAccount(Page page, InvoiceLedgerDto invoiceLedgerDto) {
        IPage<InvoiceLedgerDto> invoiceLedgerDtoIPage = invoiceLedgerMapper.invoiceLedgerSalesAccount(page, invoiceLedgerDto);
        return invoiceLedgerDtoIPage;
    }
    @Override
    public BigDecimal getInvoiceAmount() {
        LocalDate now = LocalDate.now();
        YearMonth currentMonth = YearMonth.from(now);
        // 创建LambdaQueryWrapper
        LambdaQueryWrapper<InvoiceLedger> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(InvoiceLedger::getInvoiceDate, currentMonth.atDay(1).atStartOfDay())  // 大于等于本月第一天
                .lt(InvoiceLedger::getInvoiceDate, currentMonth.plusMonths(1).atDay(1).atStartOfDay()); // 小于下月第一天
        // 执行查询并计算总和
        List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(queryWrapper);
        BigDecimal totalContractAmount = invoiceLedgers.stream()
                .map(InvoiceLedger::getInvoiceTotal)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        return totalContractAmount;
    }
    /**
     * 开票登记产品分页查询
     * @param page
     * @param registrationProductDto
     * @return
     */
    @Override
    public IPage<InvoiceRegistrationProductDto> registrationProductPage(Page page, InvoiceRegistrationProductDto registrationProductDto) {
        return invoiceRegistrationProductMapper.invoiceRegistrationProductPage(page,registrationProductDto);
    }
    /**
     * 产品开票台账详情
     * @param id
     * @return
     */
    @Override
    public InvoiceRegistrationProductDto invoiceLedgerProductDetail(Integer id) {
        InvoiceRegistrationProductDto invoiceRegistrationProductDto = invoiceLedgerMapper.invoiceLedgerProductInfo(id);
        if(ObjectUtils.isEmpty(invoiceRegistrationProductDto)){
            throw new RuntimeException("产品开票台账查找失败");
        }
        // 查询附件
        QueryWrapper<InvoiceLedgerFile> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("invoice_ledger_id", invoiceRegistrationProductDto.getInvoiceLedgerId());
        List<InvoiceLedgerFile> invoiceLedgerFileList = invoiceLedgerFileMapper.selectList(queryWrapper);
        List<FileVo> fileList = invoiceLedgerFileList.stream().map(item -> {
            FileVo fileVo = new FileVo();
            BeanUtils.copyProperties(item, fileVo);
            return fileVo;
        }).collect(Collectors.toList());
        invoiceRegistrationProductDto.setFileList(fileList);
        return invoiceRegistrationProductDto;
    }
}