Просмотр исходного кода

招行支付2.0—全面接入支付逻辑+定时轮询

ZhangWenQiang 4 лет назад
Родитель
Сommit
f672f43948

+ 22 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/common/zhutils/PayConst.java

@@ -18,6 +18,28 @@ public class PayConst {
     public static String SUCCESS = "SUC0000";
 
     /**
+     * 请求状态-银行处理中
+     */
+    public static String NTE = "NTE";
+
+
+    /**
+     * 请求状态-完成
+     */
+    public static String FIN = "FIN";
+
+    /**
+     * 结果状态-成功
+     */
+    public static String RES_SUCCESS = "S";
+
+    /**
+     * 结果状态-失败
+     */
+    public static String RES_FAIL = "F";
+
+
+    /**
      * 系统内标志(Y:开户行是招商银行;N:开户行是他行)
      */
     public static String bnkflg_Y = "Y";

+ 2 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayaccount/mapper/HlwPayRecordMapper.java

@@ -15,4 +15,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 public interface HlwPayRecordMapper extends BaseMapper<HlwPayRecord> {
 
     List<HlwPayRecord> findNoPayList();
+
+    List<HlwPayRecord> findNoPayRsaList();
 }

+ 8 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayaccount/mapper/xml/HlwPayRecordMapper.xml

@@ -11,4 +11,12 @@
         </where>
     </select>
 
+    <select id="findNoPayRsaList" resultType="org.jeecg.modules.hlwpayaccount.entity.HlwPayRecord">
+        select * from hlw_pay_record
+        <where>
+            del_flag = '0'
+            and (recsts is null OR recsts != 'FIN')
+        </where>
+    </select>
+
 </mapper>

+ 2 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayaccount/service/IHlwPayRecordService.java

@@ -14,4 +14,6 @@ import java.util.List;
 public interface IHlwPayRecordService extends IService<HlwPayRecord> {
 
     List<HlwPayRecord> findNoPayList();
+
+    List<HlwPayRecord> findNoPayRsaList();
 }

+ 5 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayaccount/service/impl/HlwPayRecordServiceImpl.java

@@ -22,4 +22,9 @@ public class HlwPayRecordServiceImpl extends ServiceImpl<HlwPayRecordMapper, Hlw
     public List<HlwPayRecord> findNoPayList() {
         return baseMapper.findNoPayList();
     }
+
+    @Override
+    public List<HlwPayRecord> findNoPayRsaList() {
+        return baseMapper.findNoPayRsaList();
+    }
 }

+ 34 - 19
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayment/service/impl/HlwPaymentServiceImpl.java

@@ -12,12 +12,12 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.businessAccountUtils;
+import org.jeecg.common.zhutils.PayConst;
 import org.jeecg.modules.api.SysBaseRemoteApi;
 import org.jeecg.modules.api.entity.HlwContractApi;
 import org.jeecg.modules.hlwaccount.entity.HlwCompany;
 import org.jeecg.modules.hlwaccount.entity.HlwCompanyAccount;
 import org.jeecg.modules.hlwaccount.entity.HlwCompanyAccountDetail;
-import org.jeecg.modules.hlwaccount.entity.HlwCompanySubcontractor;
 import org.jeecg.modules.hlwaccount.service.IHlwCompanyAccountDetailService;
 import org.jeecg.modules.hlwaccount.service.IHlwCompanyAccountService;
 import org.jeecg.modules.hlwaccount.service.IHlwCompanyService;
@@ -47,7 +47,7 @@ import org.jeecg.modules.hlwtax.service.IHlwTaxService;
 import org.jeecg.modules.hlwuser.entity.HlwUser;
 import org.jeecg.modules.hlwuser.service.IHlwUserService;
 import org.jeecg.modules.utils.HlwConstant;
-import org.jeecg.modules.utils.PayCommon;
+import org.jeecg.modules.utils.PayRsaCommon;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -423,12 +423,16 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
         //服务商信息
         HlwSubcontractor hlwSubcontractor = hlwSubcontractorService.getById(hlwPayment.getSubcontractorId());
         //银行业务接口(代发工资)
-        JSONObject jsonObjectBody = PayCommon.DCAGPOPR(hlwPaymentDetailList, totalPaymenStr, hlwSubcontractor);
+        JSONObject jsonObjectBody = PayRsaCommon.NTAGCAPY(hlwPaymentDetailList, totalPaymenStr, hlwSubcontractor);
         if (jsonObjectBody != null) {
+            //请求状态(对应payRecord表批次状态)(NTE: 银行处理中)
             String reqsta = jsonObjectBody.getString("reqsta");
-            String agpseq = jsonObjectBody.getString("agpseq");
+            //流程实例号(对应payRecord表批次号)
+            String reqnbr = jsonObjectBody.getString("reqnbr");
+            //业务参考号
+            String yurref = jsonObjectBody.getString("yurref");
             //银行处理返回成功
-            if ("SUC".equals(reqsta)) {
+            if (PayConst.NTE.equals(reqsta)) {
                 //获取当前登录用户
                 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
                 for (int i = 0; i < hlwPaymentDetailList.size(); i++) {
@@ -457,7 +461,8 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
                 //保存付款记录
                 HlwPayRecord hlwPayRecord = new HlwPayRecord();
                 hlwPayRecord.setPaymentId(hlwPaymentDetailList.get(0).getPaymentId());
-                hlwPayRecord.setAgpseq(agpseq);
+                hlwPayRecord.setAgpseq(reqnbr);
+                hlwPayRecord.setYurref(yurref);
                 hlwPayRecord.setDetail(JSON.toJSONString(hlwPaymentDetailList));
                 hlwPayRecord.setDelFlag("0");
                 hlwPayRecordService.save(hlwPayRecord);
@@ -688,12 +693,16 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
         //服务商信息
         HlwSubcontractor hlwSubcontractor = hlwSubcontractorService.getById(hlwPayment.getSubcontractorId());
         //银行业务接口(代发工资)
-        JSONObject jsonObjectBody = PayCommon.DCAGPOPR(hlwPaymentDetailList, totalPaymenStr, hlwSubcontractor);
+        JSONObject jsonObjectBody = PayRsaCommon.NTAGCAPY(hlwPaymentDetailList, totalPaymenStr, hlwSubcontractor);
         if (jsonObjectBody != null) {
+            //请求状态(对应payRecord表批次状态)(NTE: 银行处理中)
             String reqsta = jsonObjectBody.getString("reqsta");
-            String agpseq = jsonObjectBody.getString("agpseq");
+            //流程实例号(对应payRecord表批次号)
+            String reqnbr = jsonObjectBody.getString("reqnbr");
+            //业务参考号
+            String yurref = jsonObjectBody.getString("yurref");
             //银行处理返回成功
-            if ("SUC".equals(reqsta)) {
+            if (PayConst.NTE.equals(reqsta)) {
                 //获取当前登录用户
                 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
                 for (int i = 0; i < hlwPaymentDetailList.size(); i++) {
@@ -722,7 +731,8 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
                 //保存付款记录
                 HlwPayRecord hlwPayRecord = new HlwPayRecord();
                 hlwPayRecord.setPaymentId(hlwPaymentDetailList.get(0).getPaymentId());
-                hlwPayRecord.setAgpseq(agpseq);
+                hlwPayRecord.setAgpseq(reqnbr);
+                hlwPayRecord.setYurref(yurref);
                 hlwPayRecord.setDetail(JSON.toJSONString(hlwPaymentDetailList));
                 hlwPayRecord.setDelFlag("0");
                 hlwPayRecordService.save(hlwPayRecord);
@@ -1048,12 +1058,16 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
         //服务商信息
         HlwSubcontractor hlwSubcontractor = hlwSubcontractorService.getById(hlwPayment.getSubcontractorId());
         //银行业务接口(代发工资)
-        JSONObject jsonObjectBody = PayCommon.DCAGPOPR(hlwPaymentDetailList, totalPaymenStr, hlwSubcontractor);
+        JSONObject jsonObjectBody = PayRsaCommon.NTAGCAPY(hlwPaymentDetailList, totalPaymenStr, hlwSubcontractor);
         if (jsonObjectBody != null) {
+            //请求状态(对应payRecord表批次状态)(NTE: 银行处理中)
             String reqsta = jsonObjectBody.getString("reqsta");
-            String agpseq = jsonObjectBody.getString("agpseq");
+            //流程实例号(对应payRecord表批次号)
+            String reqnbr = jsonObjectBody.getString("reqnbr");
+            //业务参考号
+            String yurref = jsonObjectBody.getString("yurref");
             //银行处理返回成功
-            if ("SUC".equals(reqsta)) {
+            if (PayConst.NTE.equals(reqsta)) {
                 //获取当前登录用户
                 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
                 for (int i = 0; i < hlwPaymentDetailList.size(); i++) {
@@ -1069,7 +1083,8 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
                 //保存付款记录
                 HlwPayRecord hlwPayRecord = new HlwPayRecord();
                 hlwPayRecord.setPaymentId(hlwPaymentDetailList.get(0).getPaymentId());
-                hlwPayRecord.setAgpseq(agpseq);
+                hlwPayRecord.setAgpseq(reqnbr);
+                hlwPayRecord.setYurref(yurref);
                 hlwPayRecord.setDetail(JSON.toJSONString(hlwPaymentDetailList));
                 hlwPayRecord.setDelFlag("0");
                 hlwPayRecordService.save(hlwPayRecord);
@@ -1283,28 +1298,28 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
 
     @Override
     public int getCountPayment(int companyId, int subcontractorId) {
-        return baseMapper.getCountPayment(companyId,subcontractorId);
+        return baseMapper.getCountPayment(companyId, subcontractorId);
     }
 
     @Override
     public HlwContractApi getHlwContractApi(int companyId, int subcontractorId) {
-        return baseMapper.getHlwContractApi(companyId,subcontractorId);
+        return baseMapper.getHlwContractApi(companyId, subcontractorId);
     }
 
     @Override
     public int getCountPaymentCp(int companyId, int cpId) {
-        return baseMapper.getCountPaymentCp(companyId,cpId);
+        return baseMapper.getCountPaymentCp(companyId, cpId);
     }
 
 
     @Override
     public HlwContractApi getHlwContractApiCp(int companyId, int cpId) {
-        return baseMapper.getHlwContractApiCp(companyId,cpId);
+        return baseMapper.getHlwContractApiCp(companyId, cpId);
     }
 
 
     @Override
     public HlwPayment getPaymentTimeRange(Integer companyId, Integer subcontractorId) {
-        return baseMapper.getPaymentTimeRange(companyId,subcontractorId);
+        return baseMapper.getPaymentTimeRange(companyId, subcontractorId);
     }
 }

+ 207 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayment/task/PaymentRsaJob.java

@@ -0,0 +1,207 @@
+package org.jeecg.modules.hlwpayment.task;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xxl.job.core.log.XxlJobLogger;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.businessAccountUtils;
+import org.jeecg.common.zhutils.PayConst;
+import org.jeecg.modules.hlwinvoice.entity.HlwDutyApply;
+import org.jeecg.modules.hlwinvoice.service.IHlwDutyApplyService;
+import org.jeecg.modules.hlwpayaccount.entity.HlwPayRecord;
+import org.jeecg.modules.hlwpayaccount.service.IHlwPayRecordService;
+import org.jeecg.modules.hlwpayment.entity.HlwPayment;
+import org.jeecg.modules.hlwpayment.entity.HlwPaymentDetail;
+import org.jeecg.modules.hlwpayment.service.IHlwPaymentDetailService;
+import org.jeecg.modules.hlwpayment.service.IHlwPaymentService;
+import org.jeecg.modules.hlwsubcontractor.entity.HlwSubcontractor;
+import org.jeecg.modules.hlwsubcontractor.service.IHlwSubcontractorService;
+import org.jeecg.modules.utils.HlwConstant;
+import org.jeecg.modules.utils.PayRsaCommon;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Author: zwq
+ * @Description:支付查询定时器
+ * @Date: Create in 17:19 2021/06/07
+ */
+@Slf4j
+@Component
+@Service
+public class PaymentRsaJob {
+    @Autowired
+    private IHlwPayRecordService hlwPayRecordService;
+    @Autowired
+    private IHlwPaymentDetailService hlwPaymentDetailService;
+    @Autowired
+    private IHlwPaymentService hlwPaymentService;
+    @Autowired
+    private IHlwSubcontractorService hlwSubcontractorService;
+    @Autowired
+    private IHlwDutyApplyService hlwDutyApplyService;
+
+
+    @XxlJob("paymentRsaJobHandler")
+    @Transactional(rollbackFor = Exception.class)
+    public ReturnT<String> paymentRsaJobHandler(String param) throws Exception {
+        log.info(String.format(" 支付查询定时器!  时间:" + DateUtils.getTimestamp()));
+        XxlJobLogger.log(String.format(" 支付查询定时器!  时间:" + DateUtils.getTimestamp()));
+
+        //查询所有交易状态为在途(不为FIN))的批次
+        List<HlwPayRecord> hlwPayRecordList = hlwPayRecordService.findNoPayRsaList();
+        log.info("未有付款结果======={}", hlwPayRecordList.size());
+        for (HlwPayRecord hlwPayRecord : hlwPayRecordList) {
+            //完税金额
+            Double amount = 0.00;
+            //完税人员
+            List<String> applyList = new ArrayList<>();
+            //获取当前支付单
+            HlwPayment hlwPaymentDto = hlwPaymentService.getById(hlwPayRecord.getPaymentId());
+            //服务商信息
+            HlwSubcontractor hlwSubcontractor = hlwSubcontractorService.getById(hlwPaymentDto.getSubcontractorId());
+            //请求银行接口查询结果
+            JSONObject jsonObjectBody = PayRsaCommon.NTAGCINY(hlwPayRecord, hlwSubcontractor);
+            //流程实例号
+            String reqnbr = jsonObjectBody.getString("reqnbr");
+            //业务请求状态
+            String reqsta = jsonObjectBody.getString("reqsta");
+            //业务请求结果
+            String rtnflg = jsonObjectBody.getString("rtnflg");
+
+            //代发明细信息
+            JSONArray jsonArray = new JSONArray();
+            //获取record表支付记录detail
+            String payDetail = hlwPayRecord.getDetail();
+            JSONArray jsonArray1 = JSONArray.parseArray(payDetail);
+            //reqsta=FIN && rtnflg=S时,调明细接口
+            if (PayConst.FIN.equals(reqsta) && PayConst.RES_SUCCESS.equals(rtnflg)) {
+                //请求银行接口查询交易明细
+                JSONObject jsonDetailBody = PayRsaCommon.NTAGDINF(hlwPayRecord, hlwSubcontractor);
+                //代发明细信息
+                jsonArray = jsonDetailBody.getJSONArray("ntagcdtly1");
+                //遍历查询付款状态并更新到hlw_payment_detail表
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    JSONObject jsonObject = jsonArray.getJSONObject(i);
+                    //获取当笔支付的交易状态(A:待处理 S: 成功 E:失败)
+                    String stscod = jsonObject.getString("stscod");
+                    //卡号
+                    String accnbr = jsonObject.getString("accnbr");
+                    for (int k = 0; k < jsonArray1.size(); k++) {
+                        //比较卡号,确定是否是同一个人
+                        if (accnbr.equals(jsonArray1.getJSONObject(k).getString("cardNumber"))) {
+                            //获取详情表主键id
+                            String hlwPaymentDetailId = jsonArray1.getJSONObject(k).getString("id");
+                            HlwPaymentDetail hlwPaymentDetail = hlwPaymentDetailService.getById(hlwPaymentDetailId);
+                            switch (stscod) {
+                                case "A":
+
+                                    break;
+                                case "S":
+                                    hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_SUCCESS);
+                                    //累加完税金额
+                                    amount = businessAccountUtils.add(amount, hlwPaymentDetail.getNetPayment());
+                                    //完税人员
+                                    applyList.add(hlwPaymentDetailId);
+                                    break;
+                                case "E":
+                                    hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_FAIL);
+                                    //代发失败的错误描述
+                                    String errmsg = jsonObject.getString("errdsp");
+                                    hlwPaymentDetail.setFailureReason(errmsg);
+                                    break;
+                                default:
+
+                                    break;
+                            }
+                            /**
+                             * 更新付款详情
+                             */
+                            //状态为非待交易状态,则更新付款单明细
+                            if (StringUtils.isNotBlank(stscod) && !"A".equals(stscod)) {
+                                hlwPaymentDetail.setPaymentResultTime(new Date());
+                                hlwPaymentDetailService.updateById(hlwPaymentDetail);
+                            }
+                            break;
+                        }
+                    }
+                }
+            } else if (PayConst.FIN.equals(reqsta) && PayConst.RES_FAIL.equals(rtnflg)) {
+                //rtnflg为F表示整批业务都已经失败
+                for (int k = 0; k < jsonArray1.size(); k++) {
+                    //获取详情表主键id
+                    String hlwPaymentDetailId = jsonArray1.getJSONObject(k).getString("id");
+                    HlwPaymentDetail hlwPaymentDetail = hlwPaymentDetailService.getById(hlwPaymentDetailId);
+                    hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_FAIL);
+                    //代发失败的错误描述
+                    String errmsg = "银行支付失败";
+                    hlwPaymentDetail.setFailureReason(errmsg);
+                    hlwPaymentDetail.setPaymentResultTime(new Date());
+                    hlwPaymentDetailService.updateById(hlwPaymentDetail);
+                }
+            }
+            //更新hlwPayRecord
+            hlwPayRecord.setRecsts(reqsta);
+            hlwPayRecord.setTrade(jsonArray.toJSONString());
+            hlwPayRecord.setUpdateTime(new Date());
+            hlwPayRecordService.updateById(hlwPayRecord);
+
+            //付款单状态是终态,才更新
+            if (PayConst.FIN.equals(reqsta)) {
+                /**
+                 * 更新付款信息表
+                 */
+                //获取付款表主键id
+                String paymentId = jsonArray1.getJSONObject(0).getString("paymentId");
+                HlwPayment hlwPayment = hlwPaymentService.getById(paymentId);
+                //状态修改为已付款
+                hlwPayment.setStatus(HlwConstant.PAYMENT_STATUS_PAY_OK);
+                hlwPaymentService.updateById(hlwPayment);
+                try {
+                    //返回结果,插入完税申请表
+                    insertDutyApply(amount, applyList);
+                } catch (Exception e) {
+                    log.info("插入完税申请失败");
+                    e.printStackTrace();
+                }
+            }
+        }
+        return ReturnT.SUCCESS;
+    }
+
+    /**
+     * 插入完税申请表
+     * PROPAGATION_REQUIRES_NEW:创建一个新的事务,如果当前存在事务,则把当前事务挂起。
+     *
+     * @param amount
+     */
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
+    public void insertDutyApply(Double amount, List<String> applyList) {
+        if (applyList != null && applyList.size() > 0) {
+            HlwDutyApply hlwDutyApply = new HlwDutyApply();
+            hlwDutyApply.setAmount(amount);
+            hlwDutyApply.setApplyTime(new Date());
+            //定时任务无法获取用户信息
+            hlwDutyApply.setApplyBy("admin");
+            hlwDutyApplyService.save(hlwDutyApply);
+            //遍历完税人员,更新信息
+            for (String paymentDetailId : applyList) {
+                HlwPaymentDetail hlwPaymentDetail = hlwPaymentDetailService.getById(paymentDetailId);
+                hlwPaymentDetail.setDutyApplyId(hlwDutyApply.getId());
+                hlwPaymentDetailService.updateById(hlwPaymentDetail);
+            }
+        }
+    }
+
+}

+ 18 - 18
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/utils/PayRsaCommon.java

@@ -8,7 +8,6 @@ import org.jeecg.common.zhutils.PayConst;
 import org.jeecg.common.zhutils.PayRequest;
 import org.jeecg.common.zhutils.RandomRequest;
 import org.jeecg.common.zhutils.RsaKeyProperties;
-import org.jeecg.modules.hlwpayaccount.entity.HlwPayAccount;
 import org.jeecg.modules.hlwpayaccount.entity.HlwPayAccountCmb;
 import org.jeecg.modules.hlwpayaccount.entity.HlwPayRecord;
 import org.jeecg.modules.hlwpayaccount.service.IHlwPayAccountCmbService;
@@ -23,7 +22,6 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Random;
 import java.util.stream.Stream;
 
 /**
@@ -158,7 +156,7 @@ public class PayRsaCommon {
      * @param totalPayment
      * @return
      */
-    public static JSONObject NTAGCAPY(List<HlwPaymentDetail> hlgPaymentDetailList, String totalPayment, HlwSubcontractor hlgSubcontractor) {
+    public static JSONObject NTAGCAPY(List<HlwPaymentDetail> hlgPaymentDetailList, String totalPayment, HlwSubcontractor hlwSubcontractor) {
         JSONObject jsonObjectBody = null;
         try {
             // body
@@ -168,13 +166,13 @@ public class PayRsaCommon {
             //funCode接口名称
             String funCode = PayConst.NTAGCAPY;
             //账户
-            HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlgSubcontractor);
+            HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlwSubcontractor);
             /**
              * 模式信息
              */
             JSONArray jsonArrayRequest1 = new JSONArray();
             JSONObject jsonObjectRequest1 = new JSONObject();
-            jsonObjectRequest1.put("busmod", hlgSubcontractor.getBusmod());
+            jsonObjectRequest1.put("busmod", hlwSubcontractor.getBusmod());
             jsonArrayRequest1.add(jsonObjectRequest1);
             /**
              * 汇总信息
@@ -204,7 +202,7 @@ public class PayRsaCommon {
             //货币市场
             jsonObjectRequest2.put("ccymkt", "0");
             //交易代码(代发类型),默认代发其他
-            jsonObjectRequest2.put("trstyp", hlgSubcontractor.getTrsTyp());
+            jsonObjectRequest2.put("trstyp", hlwSubcontractor.getTrsTyp());
             //用途
             jsonObjectRequest2.put("nusage", PayConst.NUSAGE);
             //业务参考号采用时间戳+8位随机数
@@ -260,7 +258,7 @@ public class PayRsaCommon {
             obj_body.put("ntbusmody", jsonArrayRequest1);
             obj_body.put("ntagcagcx1", jsonArrayRequest2);
             obj_body.put("ntagcdtly1", jsonArrayRequest3);
-            String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
+            String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
                     iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
@@ -274,9 +272,9 @@ public class PayRsaCommon {
                     //单记录
                     if (jsonArrayBody != null && jsonArrayBody.size() > 0) {
                         jsonObjectBody = jsonArrayBody.getJSONObject(0);
-                        //请求状态(NTE: 银行处理中)
+                        //请求状态(对应payRecord表批次状态)(NTE: 银行处理中)
                         String reqsta = jsonObjectBody.getString("reqsta");
-                        //流程实例号
+                        //流程实例号(对应payRecord表批次号)
                         String reqnbr = jsonObjectBody.getString("reqnbr");
                         //传回业务参考号
                         jsonObjectBody.put("yurref", yurref);
@@ -296,9 +294,9 @@ public class PayRsaCommon {
     /**
      * 代发结果查询-按业务参考号
      *
-     * @param hlgSubcontractor
+     * @param hlwSubcontractor
      */
-    public static JSONObject NTAGCINY(HlwPayRecord hlwPayRecord, HlwSubcontractor hlgSubcontractor) {
+    public static JSONObject NTAGCINY(HlwPayRecord hlwPayRecord, HlwSubcontractor hlwSubcontractor) {
         JSONObject jsonResponseBody = new JSONObject();
         try {
             // body
@@ -311,7 +309,7 @@ public class PayRsaCommon {
             JSONArray jsonArrayRequest = new JSONArray();
             JSONObject jsonObjectRequest = new JSONObject();
             //业务类型
-            jsonObjectRequest.put("buscod", hlgSubcontractor.getBuscod());
+            jsonObjectRequest.put("buscod", hlwSubcontractor.getBuscod());
             //业务参考号
             jsonObjectRequest.put("yurref", hlwPayRecord.getYurref());
             //起始日期
@@ -321,7 +319,7 @@ public class PayRsaCommon {
             jsonArrayRequest.add(jsonObjectRequest);
             //查询条件
             obj_body.put("ntagcinyx1", jsonArrayRequest);
-            String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
+            String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
                     iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
@@ -333,13 +331,15 @@ public class PayRsaCommon {
                     JSONObject jsonObjectBody = jsonObject1.getJSONObject("body");
                     JSONArray jsonArray = jsonObjectBody.getJSONArray("ntagcinqz");
                     //单记录
-                    for (int i = 0; i < jsonArray.size(); i++) {
-                        jsonResponseBody = jsonArray.getJSONObject(i);
+                    if (jsonArray != null && jsonArray.size() > 0) {
+                        jsonResponseBody = jsonArray.getJSONObject(0);
                         System.out.println("流程实例号========" + jsonResponseBody.get("reqnbr"));
                         System.out.println("业务类型========" + jsonResponseBody.get("buscod"));
                         //reqsta=FIN && rtnflg=S时,调明细接口
                         System.out.println("业务请求状态========" + jsonResponseBody.get("reqsta"));
                         System.out.println("业务请求结果========" + jsonResponseBody.get("rtnflg"));
+                        //业务参考号
+                        System.out.println("业务参考号========" + jsonResponseBody.get("yurref"));
                     }
                     System.out.println("head========" + jsonObjectHead.getString("resultcode"));
                     System.out.println("body========" + jsonArray);
@@ -358,9 +358,9 @@ public class PayRsaCommon {
     /**
      * 交易明细信息查询
      *
-     * @param hlgSubcontractor
+     * @param hlwSubcontractor
      */
-    public static JSONObject NTAGDINF(HlwPayRecord hlwPayRecord, HlwSubcontractor hlgSubcontractor) {
+    public static JSONObject NTAGDINF(HlwPayRecord hlwPayRecord, HlwSubcontractor hlwSubcontractor) {
         JSONObject jsonObjectBody = new JSONObject();
         try {
             // body
@@ -377,7 +377,7 @@ public class PayRsaCommon {
             jsonArrayRequest.add(jsonObjectRequest);
             //查询条件
             obj_body.put("ntagdinfy1", jsonArrayRequest);
-            String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
+            String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
                     iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);