| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.pojo.AccountExpense; |
| | | import com.ruoyi.account.pojo.AccountIncome; |
| | | import com.ruoyi.account.service.AccountIncomeService; |
| | | import com.ruoyi.basic.mapper.CustomerMapper; |
| | | import com.ruoyi.basic.pojo.Customer; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | |
| | | @RequiredArgsConstructor |
| | | @Slf4j |
| | | public class SalesLedgerServiceImpl extends ServiceImpl<SalesLedgerMapper, SalesLedger> implements ISalesLedgerService { |
| | | private final AccountIncomeService accountIncomeService; |
| | | |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | |
| | |
| | | private final InvoiceLedgerMapper invoiceLedgerMapper; |
| | | |
| | | private final SalesLedgerSchedulingMapper salesLedgerSchedulingMapper; |
| | | private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper; |
| | | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | |
| | | LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>() |
| | | .in(SalesLedgerScheduling::getSalesLedgerId, idList); |
| | | salesLedgerSchedulingMapper.delete(in); |
| | | LambdaQueryWrapper<InvoiceRegistrationProduct> InvoiceRegistrationProductWrapper = new LambdaQueryWrapper<>(); |
| | | InvoiceRegistrationProductWrapper.in(InvoiceRegistrationProduct::getSalesLedgerId, idList); |
| | | List<InvoiceRegistrationProduct> invoiceRegistrationProducts = invoiceRegistrationProductMapper.selectList(InvoiceRegistrationProductWrapper); |
| | | if (!CollectionUtils.isEmpty(invoiceRegistrationProducts)) { |
| | | List<Integer> InvoiceRegistrationProductIds = invoiceRegistrationProducts.stream().map(InvoiceRegistrationProduct::getId).collect(Collectors.toList()); |
| | | LambdaQueryWrapper<InvoiceLedger> invoiceLedgerQuery = new LambdaQueryWrapper<>(); |
| | | invoiceLedgerQuery.in(InvoiceLedger::getInvoiceRegistrationProductId, InvoiceRegistrationProductIds); |
| | | invoiceLedgerMapper.delete(invoiceLedgerQuery); |
| | | } |
| | | // 2. 再删除主表数据 |
| | | return salesLedgerMapper.deleteBatchIds(idList); |
| | | } |
| | |
| | | salesLedger.setCustomerName(customer.getCustomerName()); |
| | | salesLedger.setTenantId(customer.getTenantId()); |
| | | |
| | | AccountIncome accountIncome = new AccountIncome(); |
| | | accountIncome.setIncomeDate(salesLedger.getEntryDate()); |
| | | accountIncome.setIncomeType("0"); |
| | | accountIncome.setCustomerName(customer.getCustomerName()); |
| | | accountIncome.setIncomeMoney(salesLedger.getContractAmount()); |
| | | accountIncome.setIncomeMethod("0"); |
| | | accountIncome.setInputTime(new Date()); |
| | | accountIncome.setInputUser(salesLedger.getEntryPerson()); |
| | | // 3. 新增或更新主表 |
| | | if (salesLedger.getId() == null) { |
| | | String contractNo = generateSalesContractNo(); |
| | | salesLedger.setSalesContractNo(contractNo); |
| | | salesLedgerMapper.insert(salesLedger); |
| | | accountIncome.setIncomeDescribed("销售合同:" + salesLedger.getSalesContractNo()); |
| | | accountIncome.setInvoiceNumber(salesLedger.getSalesContractNo()); |
| | | accountIncomeService.save(accountIncome); |
| | | } else { |
| | | salesLedgerMapper.updateById(salesLedger); |
| | | SalesLedger salesLedgerDB = salesLedgerMapper.selectById(salesLedger.getId()); |
| | | List<AccountIncome> accountIncomeDBs = accountIncomeService.getByInvoiceNumberList(salesLedger.getSalesContractNo()); |
| | | if (!CollectionUtils.isEmpty(accountIncomeDBs)) { |
| | | accountIncomeDBs.forEach(accountIncomeDB ->{ |
| | | accountIncomeDB.setCustomerName(salesLedgerDB.getCustomerName()); |
| | | accountIncomeDB.setIncomeMoney(salesLedgerDB.getContractAmount()); |
| | | accountIncomeDB.setIncomeDescribed("销售合同:" + salesLedgerDB.getSalesContractNo()); |
| | | accountIncomeDB.setInvoiceNumber(salesLedgerDB.getSalesContractNo()); |
| | | accountIncomeDB.setInputTime(new Date()); |
| | | accountIncomeDB.setInputUser(salesLedgerDB.getEntryPerson()); |
| | | accountIncomeService.updateById(accountIncomeDB); |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 4. 处理子表数据 |