diff --git a/src/main/java/cn/palmte/work/model/process/ProcurementDetail.java b/src/main/java/cn/palmte/work/model/process/ProcurementDetail.java index 0e1b8b0..f50ae45 100644 --- a/src/main/java/cn/palmte/work/model/process/ProcurementDetail.java +++ b/src/main/java/cn/palmte/work/model/process/ProcurementDetail.java @@ -29,6 +29,7 @@ public class ProcurementDetail { private String contractParty; private int isUnderwritten; + private String isUnderwrittenDesc; private BigDecimal underwrittenAmount; @@ -53,4 +54,8 @@ public class ProcurementDetail { private List purchaseDetails; + public void setIsUnderwritten(int isUnderwritten) { + this.isUnderwritten = isUnderwritten; + this.isUnderwrittenDesc = isUnderwritten == 1 ? "是" : "否"; + } } diff --git a/src/main/java/cn/palmte/work/service/ProjectProcessService.java b/src/main/java/cn/palmte/work/service/ProjectProcessService.java index e315244..ba007b7 100644 --- a/src/main/java/cn/palmte/work/service/ProjectProcessService.java +++ b/src/main/java/cn/palmte/work/service/ProjectProcessService.java @@ -205,32 +205,40 @@ public class ProjectProcessService { * @param processId 流程ID 一般用于获取详情 */ public List getProcurementDetails(int projectId, Integer processId) { - List ret = new ArrayList<>(); + ArrayList ret = new ArrayList<>(); + if (processId != null) { + // 根据流程获取 + List purchaseAmount = getProcessPurchaseAmount(processId); + for (BudgetPurchaseAmount amount : purchaseAmount) { + ProjectBudgetCostDetail costDetail = getCostDetailById(amount.getBudgetCostId()); + ProcurementDetail detail = new ProcurementDetail(); + BeanUtils.copyProperties(costDetail, detail); - List costDetails = getCostDetails(projectId); - for (ProjectBudgetCostDetail costDetail : costDetails) { - ProcurementDetail detail = new ProcurementDetail(); - BeanUtils.copyProperties(costDetail, detail); - // 可能为 0 - BigDecimal amountAlready = getAmountAlready(costDetail.getId()); - detail.setAmountAlready(amountAlready); - - if (processId != null) { - // 根据 processId 确定唯一的 BudgetPurchaseAmount 用作获取详情 , 可能还未创建 - BudgetPurchaseAmount purchaseAmount = getPurchaseAmount(costDetail.getId(), processId); - if (purchaseAmount != null) { - Integer amountId = purchaseAmount.getId(); - List purchaseDetails = getBudgetPurchaseDetails(amountId); - detail.setPurchaseDetails(purchaseDetails); - } + Integer amountId = amount.getId(); + // 找对应 预算采购明细的数量记录 的采购详情 + List purchaseDetails = getBudgetPurchaseDetails(amountId); + detail.setPurchaseDetails(purchaseDetails); + detail.setBudgetCostId(costDetail.getId()); + detail.setCategory(getCategory(costDetail)); + detail.setAmountAlready(amount.getAmountAlready()); } - // TODO 查询太频繁 - detail.setCategory(getCategory(costDetail)); - - detail.setBudgetCostId(costDetail.getId()); - ret.add(detail); } + else { + List costDetails = getCostDetails(projectId); + for (ProjectBudgetCostDetail costDetail : costDetails) { + ProcurementDetail detail = new ProcurementDetail(); + BeanUtils.copyProperties(costDetail, detail); + // 可能为 0 + BigDecimal amountAlready = getAmountAlready(costDetail.getId()); + detail.setAmountAlready(amountAlready); + // TODO 查询太频繁 + detail.setCategory(getCategory(costDetail)); + + detail.setBudgetCostId(costDetail.getId()); + ret.add(detail); + } + } return ret; } @@ -255,6 +263,10 @@ public class ProjectProcessService { return query.getResultList(); } + private ProjectBudgetCostDetail getCostDetailById(int budgetCostId) { + return entityManager.find(ProjectBudgetCostDetail.class, budgetCostId); + } + private List getCostDetails(int projectId) { TypedQuery query = entityManager.createQuery( "from ProjectBudgetCostDetail where projectId=:projectId", ProjectBudgetCostDetail.class); @@ -262,6 +274,24 @@ public class ProjectProcessService { return query.getResultList(); } + /** + * 获取采购合同流程所有的 预算采购明细的数量记录 + * + * @param processId 合同流程 + * @return 采购合同流程预算采购明细的数量记录 列表 + */ + public List getProcessPurchaseAmount(Integer processId) { + TypedQuery amountQuery = entityManager.createQuery( + "from BudgetPurchaseAmount where processId=:processId", BudgetPurchaseAmount.class); + amountQuery.setParameter("processId", processId); + try { + return amountQuery.getResultList(); + } + catch (NoResultException e) { + return null; + } + } + public BudgetPurchaseAmount getPurchaseAmount(int budgetCostId, Integer processId) { TypedQuery amountQuery = entityManager.createQuery( "from BudgetPurchaseAmount where budgetCostId=:budgetCostId and processId=:processId", BudgetPurchaseAmount.class); diff --git a/src/main/resources/templates/admin/business/process-edit.ftl b/src/main/resources/templates/admin/business/process-edit.ftl index c4775ce..815d9ae 100644 --- a/src/main/resources/templates/admin/business/process-edit.ftl +++ b/src/main/resources/templates/admin/business/process-edit.ftl @@ -370,7 +370,7 @@ - + @@ -468,6 +468,19 @@ const saleContractDetail = "saleContractDetail" const BUTTON = "btn" + const procurementDetailProperties = [ + "spec", + "amount", + "purchaseList", + "amountAlready", + "amountCurrent", + "supplierName", + "totalTaxInclude", + "manufacturerName", + "procurementPrice", + "procurementAmount" + ] + const isEmpty = (obj) => { return !obj || (obj.length && obj.length === 0) } @@ -618,22 +631,40 @@ let rowKey = 0 - function mapChildren(detail) { - const { purchaseDetails } = detail - return (purchaseDetails || []).map(purchase => ({ - ...purchase, ...detail, rowKey: rowKey++, feeType: computeFeeType(detail.type), + const convertCommon = detail => { + return { + rowKey: rowKey++, feeType: computeFeeType(detail.type), totalTaxInclude_: detail.totalTaxInclude, totalTaxInclude: undefined, // 存在相同字段转换一下 - isUnderwritten: detail.isUnderwritten === 1 ? "是" : "否", - })) + } } - this.procurementDetails = procurementDetails && procurementDetails.map(detail => ({ - ...detail, feeType: computeFeeType(detail.type), - totalTaxInclude_: detail.totalTaxInclude, totalTaxInclude: undefined, // 存在相同字段转换一下 - isUnderwritten: detail.isUnderwritten === 1 ? "是" : "否", - rowKey: rowKey++, children: mapChildren(detail) - })) + const computeProcurementDetails = procurementDetails => { + const ret = [] + for (let detail of procurementDetails || []) { + const newDetail = { + ...detail, ...convertCommon(detail), + } + // mapChildren + let { purchaseDetails } = newDetail + if (isNotEmpty(purchaseDetails)) { + purchaseDetails = purchaseDetails.map(purchase => ({ + ...purchase, ...detail, parent: newDetail + })) + // 合并第一行到父级 + const first = purchaseDetails.shift(); + Object.assign(newDetail, first) + delete newDetail['parent'] + delete newDetail['purchaseDetails'] + + newDetail['children'] = purchaseDetails + } + ret.push(newDetail) + } + return ret + } + + this.procurementDetails = computeProcurementDetails(procurementDetails) this.procurementDetailsRowKey = rowKey if (process.processType === 'sale_contract') {