| | |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.framework.web.page.TableDataInfo; |
| | | import com.ruoyi.sales.dto.SalesLedgerDto; |
| | | import com.ruoyi.sales.dto.SalesLedgerEditFlagDto; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.service.ICommonFileService; |
| | | import com.ruoyi.sales.service.ISalesLedgerService; |
| | |
| | | // 获取当前页所有台账记录的 ID 集合 |
| | | List<Long> salesLedgerIds = iPage.getRecords().stream().map(SalesLedger::getId).collect(Collectors.toList()); |
| | | |
| | | |
| | | |
| | | |
| | | // 转换回款数据, key 为台账ID, value 为该台账的总回款金额 |
| | | Map<Long, BigDecimal> receiptTotals = new HashMap<>(); |
| | | |
| | | // 批量查询每个台账的编辑限制标记:是否含需要生产的产品、生产计划是否已下发、是否已发货 |
| | | Map<Long, SalesLedgerEditFlagDto> editFlags = salesLedgerService.getEditFlags(salesLedgerIds); |
| | | |
| | | for (SalesLedgerVo salesLedgerVo : iPage.getRecords()) { |
| | | Long ledgerId = salesLedgerVo.getId(); |
| | | // 合同总金额 |
| | | BigDecimal contractAmount = salesLedgerVo.getContractAmount() == null ? BigDecimal.ZERO : salesLedgerVo.getContractAmount(); |
| | | // 开票总额和回款总额 |
| | | BigDecimal receiptPaymentAmountTotal = receiptTotals.getOrDefault(ledgerId, BigDecimal.ZERO); |
| | | SalesLedgerEditFlagDto editFlag = editFlags.get(ledgerId); |
| | | boolean needsProduction = isFlagTrue(editFlag == null ? null : editFlag.getNeedsProduction()); |
| | | boolean planIssued = isFlagTrue(editFlag == null ? null : editFlag.getPlanIssued()); |
| | | boolean shipped = isFlagTrue(editFlag == null ? null : editFlag.getShipped()); |
| | | |
| | | // 如果已经有过开票或回款操作,则不允许编辑 |
| | | boolean hasReceiptOperation = receiptPaymentAmountTotal.compareTo(BigDecimal.ZERO) > 0; |
| | | salesLedgerVo.setIsEdit(hasReceiptOperation); |
| | | // 需要生产的订单:生产计划已下发(含部分下发)则不允许编辑 |
| | | // 走库存的订单:已发货则不允许编辑,否则可以编辑 |
| | | salesLedgerVo.setIsEdit(needsProduction ? !planIssued : !shipped); |
| | | salesLedgerVo.setHasProductionRecord(planIssued); |
| | | |
| | | salesLedgerVo.setStorageBlobVOs(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.FILE, RecordTypeEnum.SALES_LEDGER, ledgerId)); |
| | | } |
| | |
| | | } |
| | | return AjaxResult.success(data); |
| | | } |
| | | |
| | | private boolean isFlagTrue(Integer flag) { |
| | | return flag != null && flag == 1; |
| | | } |
| | | } |