| | |
| | | package com.gkhy.exam.pay.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.institutionalaccess.enums.StudentSex; |
| | | import com.gkhy.exam.pay.dto.rep.NonCoalCateRep; |
| | | import com.gkhy.exam.pay.dto.rep.NonCoalPayOrder; |
| | | import com.gkhy.exam.pay.dto.rep.NonCoalStuRep; |
| | | import com.gkhy.exam.pay.dto.req.NonCoalPayStuImport; |
| | | import com.gkhy.exam.pay.dto.req.NonCoalPayStudentReqDto; |
| | | import com.gkhy.exam.pay.entity.NonCoalPay; |
| | | import com.gkhy.exam.pay.entity.NonCoalPayStudent; |
| | | import com.gkhy.exam.pay.entity.PayReqData; |
| | | import com.gkhy.exam.pay.mapper.NonCoalPayMapper; |
| | | import com.gkhy.exam.pay.mapper.NonCoalPayStudentMapper; |
| | | import com.gkhy.exam.pay.service.NonCoalPayStudentService; |
| | | import com.gkhy.exam.pay.utils.CaiZhengConstans; |
| | | import com.gkhy.exam.pay.utils.PayUtils; |
| | | import com.gkhy.exam.pay.utils.ResultVo; |
| | | import com.gkhy.exam.pay.utils.SexUtils; |
| | | import com.ruoyi.common.constant.ResultConstants; |
| | | import com.ruoyi.common.exception.BusinessException; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.RandomUtil; |
| | | import com.ruoyi.common.utils.RedisLock; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | |
| | | * @date 2025-01-16 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class NonCoalPayStudentServiceImpl extends ServiceImpl<NonCoalPayStudentMapper, NonCoalPayStudent> implements NonCoalPayStudentService { |
| | | @Resource |
| | | private NonCoalPayStudentMapper nonCoalPayStudentMapper; |
| | | @Resource |
| | | private NonCoalPayMapper nonCoalPayMapper; |
| | | @Resource |
| | | private PayUtils payUtils; |
| | | @Autowired |
| | | private RedisLock redisLock; |
| | | |
| | | |
| | | @Override |
| | | public String sendOrder(Long dataId, String payType) { |
| | | |
| | | String lockKey = CaiZhengConstans.NON_COAL_PAY_STUDENT_LOCK + dataId + CaiZhengConstans.UN_COAL_ORDER_KEY_1 + payType; |
| | | |
| | | |
| | | Boolean b = redisLock.tryLock(lockKey, 30, 40, TimeUnit.SECONDS); |
| | | if (b) { |
| | | String orderNo = RandomUtil.generateOrderNumber(dataId, CaiZhengConstans.UN_COAL_ORDER_PERFIX); |
| | | List<NonCoalPayOrder> nonCoalPayOrders = nonCoalPayMapper.selectNonCoalPayOrderByParam(dataId, Long.valueOf(payType), 1L); |
| | | if (StringUtils.isEmpty(nonCoalPayOrders)) { |
| | | throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到相关缴费信息"); |
| | | } |
| | | NonCoalPayOrder nonCoalPayOrder = nonCoalPayOrders.get(0); |
| | | |
| | | List<NonCoalStuRep> nonCoalStuList = nonCoalPayOrder.getNonCoalStuList(); |
| | | |
| | | if (StringUtils.isEmpty(nonCoalStuList)) { |
| | | throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到需要缴费的学员"); |
| | | } |
| | | NonCoalStuRep nonCoalStuRep = nonCoalStuList.get(0); |
| | | |
| | | if (nonCoalStuRep.getPayStatus() == 1) { |
| | | throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "已缴费请勿重复缴费"); |
| | | } |
| | | //财政缴款码已生成了 |
| | | if (nonCoalStuRep.getGovPayStatus() == 2) { |
| | | return nonCoalStuRep.getOrderId(); |
| | | } |
| | | //todo 验证缴款类型 |
| | | if (!nonCoalStuRep.getPayType().toString().equals(payType)) { |
| | | throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "缴费类型不一致,请核对类型"); |
| | | } |
| | | //财政缴款码未生成 |
| | | // if (nonCoalStuRep.getPayStatus() == 0) { |
| | | // if ("1".equals(payType)) { |
| | | // baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate() |
| | | // .set(NonCoalPayStudent::getOrderNo, orderNo) |
| | | // .set(NonCoalPayStudent::getGovPayStatus, 1) |
| | | // .eq(NonCoalPayStudent::getId, dataId).eq(NonCoalPayStudent::getDelFlag, 0) |
| | | // .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0)); |
| | | // } else { |
| | | // //团体缴费 |
| | | // baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate() |
| | | // .set(NonCoalPayStudent::getOrderNo, orderNo) |
| | | // .set(NonCoalPayStudent::getGovPayStatus, 1) |
| | | // .eq(NonCoalPayStudent::getNonCoalPayId, dataId).eq(NonCoalPayStudent::getDelFlag, 0) |
| | | // .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0)); |
| | | // } |
| | | // } else { |
| | | // orderNo = nonCoalStuRep.getOrderNo(); |
| | | // } |
| | | List<NonCoalCateRep> nonCoalPayCategoryList = nonCoalPayOrder.getNonCoalPayCategoryList(); |
| | | |
| | | if (StringUtils.isEmpty(nonCoalPayCategoryList)) { |
| | | throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "缴费信息缺失"); |
| | | } |
| | | // 业务处理 |
| | | //查询主信息 查询是否是团队 |
| | | PayReqData payReqData = dealData(nonCoalPayOrder, orderNo, payType); |
| | | |
| | | try { |
| | | ResultVo resultVo = payUtils.faqiV2(payReqData); |
| | | log.info("调用接口返回结果:" + resultVo); |
| | | if (resultVo.getRespcode().equals(CaiZhengConstans.CAI_ZHENG_SUCCESS)) { |
| | | String orderId = resultVo.getRespdata().getOrderId(); |
| | | String billNo = resultVo.getRespdata().getBillNo(); |
| | | if (StringUtils.isNotEmpty(orderId)) { |
| | | // 更新订单 |
| | | if ("1".equals(payType)) { |
| | | baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate() |
| | | .set(NonCoalPayStudent::getOrderId, orderId) |
| | | .set(NonCoalPayStudent::getOrderNo, orderNo) |
| | | .set(NonCoalPayStudent::getPayCode, billNo) |
| | | .set(NonCoalPayStudent::getGovPayStatus, 2) |
| | | .eq(NonCoalPayStudent::getId, dataId).eq(NonCoalPayStudent::getDelFlag, 0) |
| | | .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0)); |
| | | } else { |
| | | //团体缴费 |
| | | baseMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate() |
| | | .set(NonCoalPayStudent::getOrderId, orderId) |
| | | .set(NonCoalPayStudent::getOrderNo, orderNo) |
| | | .set(NonCoalPayStudent::getPayCode, billNo) |
| | | .set(NonCoalPayStudent::getGovPayStatus, 2) |
| | | .eq(NonCoalPayStudent::getNonCoalPayId, dataId).eq(NonCoalPayStudent::getDelFlag, 0) |
| | | .eq(NonCoalPayStudent::getPayType, payType).eq(NonCoalPayStudent::getPayStatus, 0)); |
| | | } |
| | | } |
| | | return orderId; |
| | | } else { |
| | | log.error("生成订单失败:" + resultVo.getRespmsg() + ",请稍后重试,错误编码:" + resultVo.getRespcode() + "参数如下:" + payReqData); |
| | | throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR, "发起支付失败,请稍后重试"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("发起支付调用接口失败:" + e); |
| | | throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR, e.getMessage()); |
| | | } finally { |
| | | redisLock.unlock(lockKey); |
| | | } |
| | | } |
| | | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public NonCoalStuRep queryOrder(Long dataId, String payType) { |
| | | List<NonCoalPayOrder> nonCoalPayOrders = nonCoalPayMapper.selectNonCoalPayOrderByParam(dataId, Long.valueOf(payType), 2L); |
| | | if (StringUtils.isEmpty(nonCoalPayOrders)) { |
| | | throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到相关缴费信息"); |
| | | } |
| | | NonCoalPayOrder nonCoalPayOrder = nonCoalPayOrders.get(0); |
| | | |
| | | List<NonCoalStuRep> nonCoalStuList = nonCoalPayOrder.getNonCoalStuList(); |
| | | |
| | | if (StringUtils.isEmpty(nonCoalStuList)) { |
| | | throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到需要缴费的学员"); |
| | | } |
| | | NonCoalStuRep nonCoalStuRep = nonCoalStuList.get(0); |
| | | |
| | | // if (nonCoalStuRep.getPayStatus() == 1) { |
| | | // throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "已缴费请勿重复缴费"); |
| | | // } |
| | | |
| | | if (nonCoalStuRep.getGovPayStatus() == 2 && nonCoalStuRep.getPayStatus() == 0) { |
| | | try { |
| | | JSONObject result = payUtils.query(nonCoalStuRep.getOrderNo()); |
| | | log.info("查询财政订单返回结果:" + result); |
| | | String respcode = result.getString("respcode"); |
| | | if (CaiZhengConstans.CAI_ZHENG_SUCCESS.equals(respcode)) { |
| | | JSONObject respdata = result.getJSONObject("respdata"); |
| | | if (respdata != null && "1".equals(respdata.getString("status"))) { |
| | | nonCoalPayStudentMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate() |
| | | .set(NonCoalPayStudent::getPayStatus, 1) |
| | | .set(NonCoalPayStudent::getPayTime, respdata.getDate("payTime")) |
| | | .eq(NonCoalPayStudent::getOrderNo, nonCoalStuRep.getOrderNo()).eq(NonCoalPayStudent::getDelFlag, 0) |
| | | .eq(NonCoalPayStudent::getPayStatus, 0)); |
| | | // 回调确认支付 |
| | | nonCoalStuRep.setPayStatus(1L); |
| | | payUtils.affirmPost(nonCoalStuRep.getOrderNo()); |
| | | } else { |
| | | log.error("查询财政订单失败:" + result.getString("respmsg") + ",错误编码:" + result.getString("respcode")); |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("查询财政订单失败:" + e.getMessage()); |
| | | |
| | | } |
| | | } |
| | | |
| | | return nonCoalStuRep; |
| | | } |
| | | |
| | | private PayReqData dealData(NonCoalPayOrder nonCoalPayOrder, String orderNo, String payType) { |
| | | List<NonCoalStuRep> nonCoalStuList = nonCoalPayOrder.getNonCoalStuList(); |
| | | List<NonCoalCateRep> nonCoalPayCategoryList = nonCoalPayOrder.getNonCoalPayCategoryList(); |
| | | PayReqData payReqData = new PayReqData(); |
| | | payReqData.setOrderNo(orderNo); |
| | | payReqData.setPayerType(Integer.valueOf(payType)); |
| | | payReqData.setMoney(nonCoalPayOrder.getAmount().multiply(BigDecimal.valueOf(nonCoalStuList.size()))); |
| | | payReqData.setAmount(nonCoalPayCategoryList.size()); |
| | | |
| | | payReqData.setDesc(nonCoalPayOrder.getBatchName()); |
| | | |
| | | NonCoalCateRep nonCoalCateRep1 = nonCoalPayCategoryList.get(0); |
| | | payReqData.setHandlingPerson(nonCoalCateRep1.getDrawer()); |
| | | payReqData.setChecker(nonCoalCateRep1.getReviewer()); |
| | | payReqData.setEnterCode(nonCoalCateRep1.getCompanyCode()); |
| | | payReqData.setInvoiceSocialCode(nonCoalCateRep1.getInvoicingCompanyCode()); |
| | | |
| | | List<PayReqData.Feedata> feedatas1 = new ArrayList<>(); |
| | | for (NonCoalCateRep nonCoalCateRep : nonCoalPayCategoryList) { |
| | | PayReqData.Feedata feedatas = new PayReqData.Feedata(); |
| | | feedatas.setAmount(nonCoalStuList.size()); |
| | | feedatas.setBusCode(nonCoalCateRep.getBusinessCode()); |
| | | feedatas.setPrice(nonCoalCateRep.getCategoryAmount().multiply(BigDecimal.valueOf(nonCoalStuList.size()))); |
| | | feedatas1.add(feedatas); |
| | | } |
| | | payReqData.setFeeDatas(feedatas1); |
| | | if ("1".equals(payType)) { |
| | | //个人缴费 |
| | | NonCoalStuRep nonCoalStuRep = nonCoalStuList.get(0); |
| | | payReqData.setPayerName(nonCoalStuRep.getStudentName()); |
| | | payReqData.setCertNo(nonCoalStuRep.getIdCard()); |
| | | } else { |
| | | //团体缴费 |
| | | payReqData.setPayerName(nonCoalPayOrder.getPayCompanyName()); |
| | | payReqData.setCertNo(nonCoalPayOrder.getPayCompanyCard()); |
| | | //todo 待确认 |
| | | // payReqData.setInvoiceSocialCode(nonCoalPayOrder.getPayCompanyCard()); |
| | | // payReqData.setEnterCode(nonCoalPayOrder.getPayCompanyCard()); |
| | | } |
| | | return payReqData; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 查询【请填写功能名称】 |
| | |
| | | checkSameData(nonCoalPayStudent); |
| | | NonCoalPay nonCoalPay = checkNonCoalPay(nonCoalPayStudent.getNonCoalPayId()); |
| | | nonCoalPayStudent.setPayType(nonCoalPay.getPayPersonType().longValue()); |
| | | nonCoalPayStudent.setOrderNo(RandomUtil.generateOrderNumber()); |
| | | nonCoalPayStudent.setGovPayStatus(0L); |
| | | // nonCoalPayStudent.setOrderNo(RandomUtil.generateOrderNumber()); |
| | | |
| | | nonCoalPayStudent.setCreateBy(SecurityUtils.getUsername()); |
| | | return nonCoalPayStudentMapper.insertNonCoalPayStudent(nonCoalPayStudent); |
| | | } |
| | |
| | | StringBuilder failureMsg = new StringBuilder(); |
| | | for (NonCoalPayStuImport stu : nonCoalPayStudents) { |
| | | try { |
| | | if (StringUtils.isEmpty(stu.getIdCard()) || StringUtils.isEmpty(stu.getName()) || StringUtils.isEmpty(stu.getPhone()) || stu.getSex() == null) { |
| | | if (StringUtils.isEmpty(stu.getIdCard()) || StringUtils.isEmpty(stu.getName()) || StringUtils.isEmpty(stu.getPhone())) { |
| | | failureMsg.append("<br/>" + failureNum + "、导入数据为空: " + stu.getIdCard() + " 数据错误"); |
| | | } else if (idCardToNameMap.get(stu.getIdCard().trim()) != null) { |
| | | failureMsg.append("<br/>" + failureNum + "、身份证号: " + stu.getIdCard() + " 数据已存在"); |
| | |
| | | stu1.setName(stu.getName()); |
| | | stu1.setIdCard(stu.getIdCard()); |
| | | stu1.setPhone(stu.getPhone()); |
| | | stu1.setGovPayStatus(0L); |
| | | stu1.setOrderNo(RandomUtil.generateOrderNumber()); |
| | | stu1.setSex(StudentSex.BOY.getStatus().equals(stu.getSex().trim()) ? 0L : 1L); |
| | | if (StringUtils.isNotEmpty(stu.getTrain())) { |
| | | stu1.setTrain(stu.getTrain()); |
| | | } |
| | | stu1.setSex(SexUtils.sexType(stu.getIdCard())); |
| | | nonCoalPayStudentMapper.insertNonCoalPayStudent(stu1); |
| | | successNum++; |
| | | successMsg.append("<br/>" + successNum + "、身份证号 " + stu.getIdCard() + " 导入成功"); |