From 75b742855cba8106732b561a015a87bd711963ed Mon Sep 17 00:00:00 2001 From: “djh” <“3298565835@qq.com”> Date: 星期四, 23 一月 2025 17:02:16 +0800 Subject: [PATCH] 煤矿缴费个人缴费 --- exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java | 93 +++++++++++++++++++++++++++------------------- 1 files changed, 54 insertions(+), 39 deletions(-) diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java index 4271919..a046a22 100644 --- a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java +++ b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java @@ -214,18 +214,65 @@ if (coalPayTypeReq.getPayPersonType() != null && byId.getPayPersonType() == 2) { throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "已为团体缴费,不可更改"); } - return coalPayMapper.updateByPayId(coalPayTypeReq); + int i = coalPayMapper.updateByPayId(coalPayTypeReq); + if (i>0){ + CoalPayStudent coalPayStudent = new CoalPayStudent(); + coalPayStudent.setCoalPayId(coalPayTypeReq.getCoalPayId()); + coalPayStudent.setPayType(2); + coalPayStudentService.updateByCoalPayId(coalPayStudent); + } + return i; } @Override public String personPayMoney(Long coalPayId, Long studentId) { - CoalPayStudent coalPayStudent = coalPayStudentService.selectbyId(studentId); - CoalPay coalPay = coalPayMapper.selectById(coalPayId); - List<CoalCategory> coalCategories = coalCategoryMapper.selectByCoalPayId(coalPayId); - CoalTicket coalTicket = coalCategoryMapper.selectCoalTicket(); + CoalPayStudent payStudent = new CoalPayStudent(); + RLock lock = redissonClient.getLock("SWSPKMAS_PAY_PERSON_" + coalPayId); + try { + lock.lock(10, TimeUnit.SECONDS); + + CoalPayStudent coalPayStudent = coalPayStudentService.selectbyId(studentId); + CoalPay coalPay = coalPayMapper.selectById(coalPayId); + List<CoalCategory> coalCategories = coalCategoryMapper.selectByCoalPayId(coalPayId); + CoalTicket coalTicket = coalCategoryMapper.selectCoalTicket(); + if (coalPayStudent==null){ + throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"缴费学员不存在"); + } + if (coalPay==null){ + throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"未找到相关缴费信息"); + } + if (coalPayStudent.getPayStatus()==1){ + throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"请勿重新缴费"); + } + + PayReqData payReqData = fillData(coalPayStudent,coalPay,coalCategories,coalTicket); + + ResultVo resultVo = payUtils.sendApiPost(payReqData); + if (resultVo.getRespcode().equals("BUS0000")) { + payStudent.setId(studentId); + payStudent.setOrderId(resultVo.getRespdata().getOrderNo()); + payStudent.setGovPayStatus(1); + payStudent.setPayCode(resultVo.getRespdata().getBillNo()); + coalPayStudentService.updateByCoalPayStudent(payStudent); + return resultVo.getRespdata().getOrderId(); + } else { + throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "发起支付失败,请稍后重试"); + } + } catch (BusinessException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (lock.isLocked()) { + lock.unlock(); + } + } + } + + private PayReqData fillData(CoalPayStudent coalPayStudent, CoalPay coalPay, List<CoalCategory> coalCategories, CoalTicket coalTicket) { PayReqData payReqData = new PayReqData(); - payReqData.setOrderNo(RandomUtil.generateOrderNumber(coalPayId, "CO")); + payReqData.setOrderNo(RandomUtil.generateOrderNumber(coalPay.getId(), "CO")); payReqData.setMoney(coalPay.getAmount()); payReqData.setAmount(1); payReqData.setPayerName(coalPayStudent.getName()); @@ -246,39 +293,7 @@ feedatas.add(feedata); } payReqData.setFeeDatas(feedatas); + return payReqData; - CoalPayStudent payStudent = new CoalPayStudent(); - - RLock lock = redissonClient.getLock("SWSPKMAS_PAY_PERSON_" + coalPayId); - try { - lock.lock(10, TimeUnit.SECONDS); - if (coalPayStudent.getGovPayStatus() != 0) { - throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "请勿重复发起支付"); - } - if (StringUtils.isEmpty(coalPayStudent.getPayCode())) { - - } - - - ResultVo resultVo = payUtils.sendApiPost(payReqData); - if (resultVo.getRespcode().equals("BUS0000")) { - payStudent.setId(studentId); - payStudent.setOrderId(resultVo.getRespdata().getOrderNo()); - payStudent.setGovPayStatus(1); - payStudent.setPayCode(resultVo.getRespdata().getBillNo()); - coalPayStudentService.updateByCoalPayStudent(payStudent); - return resultVo.getRespdata().getBillNo(); - } else { - throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "发起支付失败,请稍后重试"); - } - } catch (BusinessException e) { - throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "请稍后重试"); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - if (lock.isLocked()) { - lock.unlock(); - } - } } } -- Gitblit v1.9.2