diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java index 9fd46716..ba203a6b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java @@ -171,34 +171,6 @@ public class PurchaseOrderController extends BaseController } - /** - * 新增采购订单 - */ - @GetMapping("/add") - public String add() - { - return prefix + "/add"; - } - - /** - * 新增保存采购订单 - */ - @RequiresPermissions("purchase:purchaseOrder:add") - @Log(title = "采购订单", businessType = BusinessType.INSERT) - @PostMapping("/add") - @ResponseBody - public AjaxResult addSave( @RequestBody PurchaseOrder purchaseOrder) { - purchaseOrder.setAuditStatus("0"); - purchaseOrder.setUseStatus("0"); - purchaseOrder.setDelFlag("0"); - // 数据校验,确保前端传入数据格式正确 - // 生成采购订单编号 - // 执行主表插入操作 - purchaseOrderService.insertPurchaseOrder(purchaseOrder); - //物料的供应商整合,生成该订单相关的应付账款 - return AjaxResult.success(); // 假设toAjax方法处理成功逻辑 - } - /** * 采购计划添加采购订单 @@ -215,58 +187,10 @@ public class PurchaseOrderController extends BaseController return AjaxResult.success(); } - /** - * 修改采购订单 - */ - @GetMapping("/edit/{purchaseOrderId}") - public String edit(@PathVariable("purchaseOrderId") Long purchaseOrderId, ModelMap mmap) - { - PurchaseOrder purchaseOrder = purchaseOrderService.selectPurchaseOrderById(purchaseOrderId); - //获取子表信息 - List purchaseOrderChildList = purchaseOrderChildService.selectPurchaseOrderChildByOrderCode(purchaseOrder.getPurchaseOrderCode()); - //Set子表供应商的信息 供应商编号-供应商名称 - //Set子表采购计划单信息 -// Set supplierCodes = new HashSet<>(); -// Set purchasePlanCodes = new HashSet<>(); -// for(PurchaseOrderChild purchaseOrderChild : purchaseOrderChildList){ -// supplierCodes.add(purchaseOrderChild.getSupplierCode()); -// purchasePlanCodes.add(purchaseOrderChild.getPurchasePlanCode()); -// } -// purchaseOrder.setPurchaseOrderChildList(purchaseOrderChildList); -// mmap.put("supplierCodes", supplierCodes); -// mmap.put("purchasePlanCodes", purchasePlanCodes); -// mmap.put("purchaseOrder", purchaseOrder); - return prefix + "/edit"; - } - @GetMapping("/editPurchaserOrder/{purchaseOrderId}") - @ResponseBody - public AjaxResult editPurchaser(@PathVariable("purchaseOrderId") Long purchaseOrderId, ModelMap mmap) - { - PurchaseOrder purchaseOrder = purchaseOrderService.selectPurchaseOrderById(purchaseOrderId); - //获取子表信息 - List purchaseOrderChildList = purchaseOrderChildService.selectPurchaseOrderChildByOrderCode(purchaseOrder.getPurchaseOrderCode()); - //Set子表供应商的信息 供应商编号-供应商名称 - //Set子表采购计划单信息 - Set supplierCodes = new HashSet<>(); - Set purchasePlanCodes = new HashSet<>(); -// for(PurchaseOrderChild purchaseOrderChild : purchaseOrderChildList){ -// //获取区分的供应商物料信息 -// if(!purchasePlanCodes.contains(purchaseOrderChild.getPurchasePlanCode())){ -// purchasePlanCodes.add(purchaseOrderChild.getPurchasePlanCode()); -// } -// //获取区分的采购计划单信息 -// if(!supplierCodes.contains(purchaseOrderChild.getSupplierCode())){ -// supplierCodes.add(purchaseOrderChild.getSupplierCode()); -// } -// supplierCodes.add(purchaseOrderChild.getSupplierCode()); -// } -// mmap.put("supplierCodes", supplierCodes); -// mmap.put("purchasePlanCodes", purchasePlanCodes); -// mmap.put("purchaseOrder", purchaseOrder); -// mmap.put("purchasePlanChildList",purchaseOrderChildList); - return AjaxResult.success(mmap); - } + + + @GetMapping("/detail/{purchaseOrderId}") public String detail(@PathVariable("purchaseOrderId") Long purchaseOrderChildId, ModelMap mmap) { @@ -316,17 +240,11 @@ public class PurchaseOrderController extends BaseController // .collect(Collectors.groupingBy(PurchaseOrderChild::getSupplierCode)); // return groupedDetails; // } - /** - * 修改保存采购订单 - */ - @RequiresPermissions("purchase:purchaseOrder:edit") - @Log(title = "采购订单", businessType = BusinessType.UPDATE) - @PostMapping("/edit") - @ResponseBody - public AjaxResult editSave(PurchaseOrder purchaseOrder) - { - return toAjax(purchaseOrderService.updatePurchaseOrder(purchaseOrder)); - } + + + + + /** * 加载审批弹窗 * @param taskId @@ -360,20 +278,25 @@ public class PurchaseOrderController extends BaseController String instanceType = purchaseOrderVo.getInstanceType(); boolean approvedFlag = processService.complete(taskId, instanceId, purchaseOrderVo.getApplyTitle(), purchaseOrderVo.getPurchaseOrderCode(), "purchaseOrder", new HashMap(), request); - if(!approvedFlag){ - // 审核状态-审核拒绝 - purchaseOrderVo.setAuditStatus("2"); - } + // 如果任务已结束更新业务表状态 boolean processIsFinish = processService.judgeProcessIsFinish(instanceId); if (processIsFinish) { + // 审核通过 purchaseOrderVo.setAuditStatus("1"); + + if(!approvedFlag){ + // 审核状态-审核拒绝 + purchaseOrderVo.setAuditStatus("2"); + } + + // 提交 if("submit".equals(instanceType)){ // 使用状态-是 purchaseOrderVo.setUseStatus("1"); - purchaseOrderService.addPurchaseOrderPayable(purchaseOrderVo); + //purchaseOrderService.addPurchaseOrderPayable(purchaseOrderVo); } // 作废 else if("cancel".equals(instanceType)){ @@ -407,19 +330,7 @@ public class PurchaseOrderController extends BaseController - /** - * 加载采购订单审核页面 - */ - @GetMapping("/auditPurchaseOrder/{purchaseOrderId}") - public String auditPurchaseOrder(@PathVariable("purchaseOrderId") Long purchaseOrderId,ModelMap mmap){ - //purchasePlanCodes去除重复数据,purchasePlanCodeArray作为数组类型去除 - //查询相关采购计划数据 - PurchaseOrder purchaseOrder = purchaseOrderService.selectPurchaseOrderById(purchaseOrderId); - //根据采购计划编号查询对应的采购报价数据 - //再根据采购计划编号分组查询对应的采购报价数据分组 - mmap.put("purchaseOrder", purchaseOrder); - return prefix + "/taskFzjlVerify"; - } + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseOrderMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseOrderMapper.java index 32c095ba..334f0fc9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseOrderMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseOrderMapper.java @@ -59,6 +59,15 @@ public interface PurchaseOrderMapper */ public int updatePurchaseOrder(PurchaseOrder purchaseOrder); + + + /** + * 根据采购单号修改采购订单 + * + * */ + int updatePurchaseOrderCode(PurchaseOrder purchaseOrder); + + /** * 删除采购订单 * diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanMapper.java index 243d36e5..ffbe7bee 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanMapper.java @@ -28,6 +28,12 @@ public interface PurchasePlanMapper */ public List selectPurchasePlanList(PurchasePlan purchasePlan); + + /** + * 根据计划编号查询采购计划单 + * */ + public PurchasePlan selectPurchasePlanByPlanCode(String purchasePlanCode); + /** * 新增采购计划单 * @@ -76,7 +82,6 @@ public interface PurchasePlanMapper */ public int restorePurchasePlanById(Long purchasePlanId); - public PurchasePlan selectPurchasePlanByPlanCode(String purchasePlanCode); public List selectPurchasePlanByPlanCodes(String[] planCode); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java index f3fcaee8..69273fba 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java @@ -545,9 +545,6 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService } - - - //新增采购订单子表 private void buildPurchaseChild(List purchasePlanSelectMaterialVoList, PurchaseOrder purchaseOrder) { List purchaseOrderChildren = new ArrayList<>(); @@ -572,7 +569,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService purchaseOrderChild.setSharedInventoryOccupancyNum(purchasePlanSelectMaterialVo.getSharedInventoryOccupancyNum()); purchaseOrderChild.setMaterialNormbSum(purchasePlanSelectMaterialVo.getMaterialNoRmbSum()); purchaseOrderChild.setMaterialRmbSum(purchasePlanSelectMaterialVo.getMaterialRmbSum()); - purchaseOrderChild.setPlanPurchaseNum(purchasePlanSelectMaterialVo.getThisPurchaseNum()); + purchaseOrderChild.setPlanPurchaseNum(purchasePlanSelectMaterialVo.getPurchaseNum()); purchaseOrderChild.setActualPurchaseNum(purchasePlanSelectMaterialVo.getThisPurchaseNum()); purchaseOrderChild.setCreateBy(ShiroUtils.getLoginName()); purchaseOrderChild.setCreateTime(new Date()); @@ -596,13 +593,176 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService * @param purchaseOrder 采购订单 * @return 结果 */ + @Transactional(rollbackFor = Exception.class) @Override public int updatePurchaseOrder(PurchaseOrder purchaseOrder) { purchaseOrder.setCreateTime(DateUtils.getNowDate()); purchaseOrder.setCreateBy(ShiroUtils.getLoginName()); + + //处理审核拒绝的情况 + if (purchaseOrder.getAuditStatus().equals("2")){ + purchaseOrderAuditRefuse(purchaseOrder); + } + return purchaseOrderMapper.updatePurchaseOrder(purchaseOrder); } + + + /** + * 采购订单审核拒绝,需要更新采购计划数据,采购计划子表数据 + * */ + private void purchaseOrderAuditRefuse(PurchaseOrder purchaseOrder) { + + Long purchaseOrderId = purchaseOrder.getPurchaseOrderId(); + PurchaseOrderVo purchaseOrderVo = purchaseOrderMapper.selectPurchaseOrderById(purchaseOrderId); + + String purchaseOrderCode = purchaseOrderVo.getPurchaseOrderCode(); + + + //得到采购订单子表的数据 + List purchaseOrderChildList = purchaseOrderChildMapper.selectPurchaseOrderChildByOrderCode(purchaseOrderCode); + + String purchasePlanCode = purchaseOrderVo.getPurchasePlanCode(); + + //得到采购计划单号的集合 + List purchasePlanCodeList = new ArrayList<>(); + + if (StringUtils.isNotEmpty(purchasePlanCode)){ + String[] splitSalesOrderCode = purchasePlanCode.split(","); + purchasePlanCodeList = Arrays.asList(splitSalesOrderCode); + } + + + // 得到采购计划主表数据 + List purchasePlanList = purchasePlanMapper.selectPurchaseOrderByPlanCodeList(purchasePlanCodeList); + // 得到采购计划子表数据 + List purchasePlanChildList = purchasePlanChildMapper.selectPurchasePlanChildPlanCodeList(purchasePlanCodeList); + + // 创建一个 map 用于快速查找采购计划子表数据 + Map> purchasePlanChildMap = purchasePlanChildList.stream() + .collect(Collectors.groupingBy(PurchasePlanChild::getPurchasePlanCode)); + + // 用于存储每个采购计划的总变动量 + Map planSumChanges = new HashMap<>(); + + // 将采购订单子表中的实际采购数量分配给采购计划子表 + // 将采购订单子表中的实际采购数量分配给采购计划子表 + for (PurchaseOrderChild orderChild : purchaseOrderChildList) { + String materialNo = orderChild.getMaterialNo(); + int actualPurchaseNum = orderChild.getActualPurchaseNum(); + + for (String planCode : purchasePlanCodeList) { + List planChildren = purchasePlanChildMap.get(planCode); + if (planChildren != null) { + // 按创建时间排序 + planChildren.sort(Comparator.comparing(PurchasePlanChild::getCreateTime)); + + for (PurchasePlanChild planChild : planChildren) { + if (planChild.getMaterialNo().equals(materialNo) && actualPurchaseNum > 0) { + int remainingPurchaseNum = planChild.getPlanPurchaseNum() - planChild.getActualPurchaseNum(); + if (remainingPurchaseNum > 0) { + int consumeNum = Math.min(actualPurchaseNum, remainingPurchaseNum); + planChild.setActualPurchaseNum(planChild.getActualPurchaseNum() - consumeNum); // 减少实际采购数 + planChild.setPurchaseNum(planChild.getPurchaseNum() + consumeNum); // 增加待采购数 + actualPurchaseNum -= consumeNum; + + updatePurchasePlanChildStatus(planChild); + + // 更新采购计划子表 + int updatePurchasePlanChildResult = purchasePlanChildMapper.updatePurchasePlanChild(planChild); + if (updatePurchasePlanChildResult <= 0) { + throw new BusinessException("更新采购计划子表数据失败"); + } + + // 记录采购计划主表的变动量 + planSumChanges.put(planCode, planSumChanges.getOrDefault(planCode, 0) + consumeNum); + } else if (remainingPurchaseNum == 0) { + // 如果剩余待采购数为0,直接增加实际采购数 + planChild.setActualPurchaseNum(planChild.getActualPurchaseNum() - actualPurchaseNum); // 减少实际采购数 + planChild.setPurchaseNum(planChild.getPurchaseNum() + actualPurchaseNum); // 增加待采购数 + + updatePurchasePlanChildStatus(planChild); + + // 更新采购计划子表 + int updatePurchasePlanChildResult = purchasePlanChildMapper.updatePurchasePlanChild(planChild); + if (updatePurchasePlanChildResult <= 0) { + throw new BusinessException("更新采购计划子表数据失败"); + } + + // 记录采购计划主表的变动量 + planSumChanges.put(planCode, planSumChanges.getOrDefault(planCode, 0) + actualPurchaseNum); + + // 退出循环,因为已经分配完所有实际采购数 + break; + } + } + } + } + } + } + + // 更新采购计划主表 + for (String planCode : planSumChanges.keySet()) { + int totalChange = planSumChanges.get(planCode); + refuseUpdatePurchasePlan(planCode, totalChange); + } + } + + // 更新采购计划主表的方法 + private void refuseUpdatePurchasePlan(String purchasePlanCode, int totalChange) { + PurchasePlan purchasePlan = purchasePlanMapper.selectPurchasePlanByPlanCode(purchasePlanCode); + if (purchasePlan != null) { + if (purchasePlan.getActualPurchaseSum() == null) { + purchasePlan.setActualPurchaseSum(0); + } + if (purchasePlan.getPurchaseSum() == null) { + purchasePlan.setPurchaseSum(0); + } + + // 增加实际采购数 + purchasePlan.setActualPurchaseSum(purchasePlan.getActualPurchaseSum() - totalChange); + // 减少待采购数 + purchasePlan.setPurchaseSum(purchasePlan.getPurchaseSum() + totalChange); + + // 更新采购计划主表的状态 + updatePurchasePlanStatus(purchasePlan); + + purchasePlan.setUpdateTime(new Date()); + purchasePlan.setUpdateBy(ShiroUtils.getLoginName()); + + purchasePlanMapper.updatePurchasePlan(purchasePlan); + } + } + + // 更新采购计划主表状态的方法 + private void updatePurchasePlanStatus(PurchasePlan purchasePlan) { + if (purchasePlan.getActualPurchaseSum() > 0 &&purchasePlan.getActualPurchaseSum() < purchasePlan.getPlanPurchaseSum()) { + purchasePlan.setPurchasePlanStatus("1"); // 部分申请 + } else if (purchasePlan.getActualPurchaseSum().equals(purchasePlan.getPlanPurchaseSum())) { + purchasePlan.setPurchasePlanStatus("2"); // 全部申请 + } else if (purchasePlan.getPlanPurchaseSum().equals(purchasePlan.getPurchaseSum())) { + purchasePlan.setPurchasePlanStatus("0"); // 待申请 + } + } + + + + // 更新采购计划子表状态的方法 + private void updatePurchasePlanChildStatus(PurchasePlanChild planChild) { + + if (planChild != null) { + if (planChild.getActualPurchaseNum() > 0 && planChild.getActualPurchaseNum() < planChild.getPlanPurchaseNum()) { + planChild.setPurchasePlanStatus("1");// 部分申请 + } else if (planChild.getActualPurchaseNum().equals(planChild.getPlanPurchaseNum())) { + planChild.setPurchasePlanStatus("2"); // 全部申请 + } else if (planChild.getPlanPurchaseNum().equals(planChild.getPurchaseNum())) { + planChild.setPurchasePlanStatus("0");// 待申请 + } + } + } + + /** * 修改采购订单 * @@ -612,7 +772,10 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService @Override public int updatePurchaseOrderCode(PurchaseOrder purchaseOrder) { - return 1; + purchaseOrder.setUpdateTime(DateUtils.getNowDate()); + purchaseOrder.setUpdateBy(ShiroUtils.getLoginName()); + return purchaseOrderMapper.updatePurchaseOrderCode(purchaseOrder); + } /** diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderMapper.xml index 5b3c6b1d..b1fe8d8d 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderMapper.xml @@ -204,6 +204,53 @@ where purchase_order_id = #{purchaseOrderId} + + + update purchase_order + + purchase_order_code = #{purchaseOrderCode}, + purchase_plan_code = #{purchasePlanCode}, + warehouse_storage_status = #{warehouseStorageStatus}, + payment_status = #{paymentStatus}, + supplier_code = #{supplierCode}, + supplier_name = #{supplierName}, + material_sum = #{materialSum}, + actual_purchase_sum = #{actualPurchaseSum}, + shared_inventory_occupancy_sum = #{sharedInventoryOccupancySum}, + refunds_exchanges_sum = #{refundsExchangesSum}, + storage_sum = #{storageSum}, + noRmb_sum = #{noRmbSum}, + rmb_sum = #{rmbSum}, + eceipt_type = #{eceiptType}, + arrived_time = #{arrivedTime}, + stock_no = #{stockNo}, + stock_name = #{stockName}, + receive_person = #{receivePerson}, + receive_person_phone = #{receivePersonPhone}, + receive_address = #{receiveAddress}, + purchase_buyer = #{purchaseBuyer}, + use_status = #{useStatus}, + audit_status = #{auditStatus}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + instance_id = #{instanceId}, + instance_type = #{instanceType}, + submit_instance_id = #{submitInstanceId}, + cancel_instance_id = #{cancelInstanceId}, + restore_instance_id = #{restoreInstanceId}, + apply_title = #{applyTitle}, + apply_user = #{applyUser}, + apply_time = #{applyTime}, + + where purchase_order_code = #{purchaseOrderCode} + + + + + delete from purchase_order where purchase_order_id = #{purchaseOrderId} @@ -223,4 +270,5 @@ update purchase_order set del_flag = '0' where purchase_order_id = #{purchaseOrderId} + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanMapper.xml index 8da4004f..f9cd1dc2 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanMapper.xml @@ -58,6 +58,11 @@ + + insert into purchase_plan diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html index d15c32ae..36d43346 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html @@ -263,7 +263,7 @@ } - actions.push('审核 '); + //actions.push('审核 '); var actionLinks = actions.join(''); return $.table.dropdownToggle(actionLinks); } @@ -274,14 +274,6 @@ - //打开采购订单审核页面 - function openAudit(purchaseOrderId){ - var url = prefix + "/auditPurchaseOrder/" + purchaseOrderId; - $.modal.open("采购订单审核", url); - } - - - // 导出 function exportExcel(formId) { // $.table.set(); diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/taskCgjlVerify.html b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/taskCgjlVerify.html index 7de4ba3d..4a201d4e 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/taskCgjlVerify.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/taskCgjlVerify.html @@ -1,18 +1,12 @@ - - - +
-
+ + @@ -20,135 +14,124 @@ - -