|
|
@@ -0,0 +1,427 @@
|
|
|
+package org.jeecg.modules.utils;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jeecg.common.nbcbutils.PayNbcbConst;
|
|
|
+import org.jeecg.common.nbcbutils.PayNbcbRequest;
|
|
|
+import org.jeecg.common.zhutils.PayConst;
|
|
|
+import org.jeecg.common.zhutils.PayRequest;
|
|
|
+import org.jeecg.common.zhutils.RandomRequest;
|
|
|
+import org.jeecg.common.zhutils.RsaUtils;
|
|
|
+import org.jeecg.modules.hlwpayaccount.entity.HlwPayAccountCmb;
|
|
|
+import org.jeecg.modules.hlwpayaccount.entity.HlwPayRecord;
|
|
|
+import org.jeecg.modules.hlwpayaccount.service.IHlwPayAccountCmbService;
|
|
|
+import org.jeecg.modules.hlwpayment.entity.HlwPaymentDetail;
|
|
|
+import org.jeecg.modules.hlwsubcontractor.entity.HlwSubcontractor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: zwq
|
|
|
+ * @Description:
|
|
|
+ * @Date: Create in 12:58 2021/05/31
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class PayNbcbCommon {
|
|
|
+ @Autowired
|
|
|
+ private IHlwPayAccountCmbService hlwPayAccountCmbService;
|
|
|
+
|
|
|
+ public static PayNbcbCommon payCommon;
|
|
|
+
|
|
|
+ public static IHlwPayAccountCmbService iHlwPayAccountCmbService;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ payCommon = this;
|
|
|
+ iHlwPayAccountCmbService = hlwPayAccountCmbService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户信息查询
|
|
|
+ *
|
|
|
+ * @param hlwSubcontractor
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<HlwPayAccountCmb> DCLISACC(HlwSubcontractor hlwSubcontractor) {
|
|
|
+ List<HlwPayAccountCmb> hlwPayAccountCmbList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ // body
|
|
|
+ JSONObject obj_body = new JSONObject();
|
|
|
+ //产品号
|
|
|
+ String productID = PayNbcbConst.ACCINFO;
|
|
|
+ //服务号
|
|
|
+ String serviceID = PayNbcbConst.QUERYACCOUNT;
|
|
|
+ //客户号
|
|
|
+ obj_body.put("custId", hlwSubcontractor.getUserId());
|
|
|
+ //每页条数
|
|
|
+ obj_body.put("pageSize", "10");
|
|
|
+ //当前页数
|
|
|
+ obj_body.put("currentPage", "1");
|
|
|
+ String result = PayNbcbRequest.doRequest(obj_body, productID, serviceID, hlwSubcontractor.getPaymentUrl());
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ JSONObject jsonObjectData = jsonObject.getJSONObject("Data");
|
|
|
+ if (jsonObjectData != null) {
|
|
|
+ String retCode = jsonObjectData.getString("retCode");
|
|
|
+ //正常响应为SUC0000
|
|
|
+ if (PayNbcbConst.SUCCESS.equals(retCode)) {
|
|
|
+ JSONArray jsonArray = jsonObjectData.getJSONArray("list");
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
|
+ log.info("账号========{}", jsonObject1.get("bankAcc"));
|
|
|
+ log.info("户名========{}", jsonObject1.get("accName"));
|
|
|
+ //新建json对象,转存账户信息
|
|
|
+ JSONObject jsonObject2 = new JSONObject();
|
|
|
+ jsonObject2.put("ccynbr", jsonObject1.get("curCode"));
|
|
|
+ jsonObject2.put("bbknbr", jsonObject1.get("bankName"));
|
|
|
+ jsonObject2.put("accnbr", jsonObject1.get("bankAcc"));
|
|
|
+ jsonObject2.put("accnam", jsonObject1.get("accName"));
|
|
|
+ jsonObject2.put("corpCode", jsonObject1.get("corpCode"));
|
|
|
+ HlwPayAccountCmb hlwPayAccountCmb = iHlwPayAccountCmbService.saveAccout(jsonObject2, hlwSubcontractor);
|
|
|
+ if (hlwPayAccountCmb != null) {
|
|
|
+ hlwPayAccountCmbList.add(hlwPayAccountCmb);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("head========{}", jsonObjectData.getString("retCode"));
|
|
|
+ log.info("body========{}", jsonObjectData);
|
|
|
+ } else {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ log.info("resultmsg========{}", jsonObjectData.getString("retMsg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("请求报错{}", e.getMessage());
|
|
|
+ }
|
|
|
+ return hlwPayAccountCmbList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量转账
|
|
|
+ *
|
|
|
+ * @param hlgPaymentDetailList
|
|
|
+ * @param totalPayment
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static JSONObject NTAGCAPY(List<HlwPaymentDetail> hlgPaymentDetailList, String totalPayment, HlwSubcontractor hlwSubcontractor) {
|
|
|
+ JSONObject jsonObjectData = null;
|
|
|
+ try {
|
|
|
+ // body
|
|
|
+ JSONObject obj_body = new JSONObject();
|
|
|
+ //支付总量
|
|
|
+ int payLength = hlgPaymentDetailList.size();
|
|
|
+ //产品号
|
|
|
+ String productID = PayNbcbConst.BATCHTRANSFER;
|
|
|
+ //服务号
|
|
|
+ String serviceID = PayNbcbConst.BATCHTRANSFER;
|
|
|
+ //账户
|
|
|
+ HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlwSubcontractor);
|
|
|
+ /**
|
|
|
+ * 请求报文
|
|
|
+ */
|
|
|
+ //客户号
|
|
|
+ obj_body.put("custId", hlwSubcontractor.getUserId());
|
|
|
+ //批次流水号,8位日期+8位数字
|
|
|
+ //获取当天时间,格式:yyyymmdd
|
|
|
+ String localDate = LocalDate.now().toString().replaceAll("[[\\s-:punct:]]", "");
|
|
|
+ //8位纯数字随机数
|
|
|
+ int numLength = 8;
|
|
|
+ //获取随机数字
|
|
|
+ String code = RandomRequest.getRandomNumber(numLength);
|
|
|
+ String batchSerialNo = localDate + code;
|
|
|
+ obj_body.put("batchSerialNo", batchSerialNo);
|
|
|
+ //业务类型
|
|
|
+ obj_body.put("businessCode", PayNbcbConst.NIS_SMART_EXPENSE);
|
|
|
+ //总金额
|
|
|
+ obj_body.put("totalAmt", totalPayment);
|
|
|
+ //总笔数
|
|
|
+ obj_body.put("totalNumber", payLength);
|
|
|
+ /**
|
|
|
+ * 明细信息
|
|
|
+ */
|
|
|
+ JSONArray jsonArrayRequest3 = new JSONArray();
|
|
|
+ for (int i = 0; i < payLength; i++) {
|
|
|
+ JSONObject trs = new JSONObject();
|
|
|
+ HlwPaymentDetail hlgPaymentDetail = hlgPaymentDetailList.get(i);
|
|
|
+ //明细流水号=8位日期+8位数字
|
|
|
+ //为8位纯数字,格式为:00000001、00000002...
|
|
|
+ String trxseq = Stream.iterate(i + 1, item -> item + 1).limit(1)
|
|
|
+ .map(item -> String.valueOf(item))
|
|
|
+ .map(item -> {
|
|
|
+ while (item.length() < numLength) {
|
|
|
+ item = "0" + item;
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ }).iterator().next();
|
|
|
+ trs.put("dtlSerialNo", localDate + trxseq);
|
|
|
+ //付款账户
|
|
|
+ trs.put("payAcc", hlwPayAccountCmb.getAccnbr());
|
|
|
+ //收款账号
|
|
|
+ trs.put("rcvAcc", hlgPaymentDetail.getCardNumber());
|
|
|
+ //单位code
|
|
|
+ trs.put("corpCode", hlwPayAccountCmb.getCorpCode());
|
|
|
+ //收款方户名
|
|
|
+ trs.put("rcvName", hlgPaymentDetail.getUserName());
|
|
|
+ //四舍五入,保留俩位小数
|
|
|
+ BigDecimal bg = BigDecimal.valueOf(hlgPaymentDetail.getNetPayment()).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ //金额
|
|
|
+ trs.put("amt", bg);
|
|
|
+ //备注
|
|
|
+ trs.put("remark", "");
|
|
|
+ jsonArrayRequest3.add(trs);
|
|
|
+ }
|
|
|
+ //明细列表
|
|
|
+ obj_body.put("transferDtls", jsonArrayRequest3);
|
|
|
+ String result = PayNbcbRequest.doRequest(obj_body, productID, serviceID, hlwSubcontractor.getPaymentUrl());
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ jsonObjectData = jsonObject.getJSONObject("Data");
|
|
|
+ if (jsonObjectData != null) {
|
|
|
+ String retCode = jsonObjectData.getString("retCode");
|
|
|
+ //正常响应为SUC0000
|
|
|
+ if (PayNbcbConst.SUCCESS.equals(retCode)) {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ //失败集合
|
|
|
+ JSONArray jsonArrayBody = jsonObjectData.getJSONArray("failures");
|
|
|
+ //多记录
|
|
|
+ if (jsonArrayBody != null && jsonArrayBody.size() > 0) {
|
|
|
+ for (int i = 0; i < jsonArrayBody.size(); i++) {
|
|
|
+ JSONObject jsonObjectFail = jsonArrayBody.getJSONObject(i);
|
|
|
+ //流水号
|
|
|
+ String serialNo = jsonObjectFail.getString("serialNo");
|
|
|
+ //错误码
|
|
|
+ String errorCode = jsonObjectFail.getString("errorCode");
|
|
|
+ //错误描述
|
|
|
+ String errorMsg = jsonObjectFail.getString("errorMsg");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //传回批次流水号
|
|
|
+ jsonObjectData.put("yurref", batchSerialNo);
|
|
|
+ } else {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ log.info("resultmsg========{}", jsonObjectData.getString("retMsg"));
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量查证-按批次流水号
|
|
|
+ *
|
|
|
+ * @param hlwSubcontractor
|
|
|
+ */
|
|
|
+ public static JSONObject NTAGCINY(HlwPayRecord hlwPayRecord, HlwSubcontractor hlwSubcontractor) {
|
|
|
+ JSONObject jsonObjectData = null;
|
|
|
+ try {
|
|
|
+ // body
|
|
|
+ JSONObject obj_body = new JSONObject();
|
|
|
+ //产品号
|
|
|
+ String productID = PayNbcbConst.BATCHTRANSFER;
|
|
|
+ //服务号
|
|
|
+ String serviceID = PayNbcbConst.QUERYBATCHTRANSFERRESULT;
|
|
|
+ /**
|
|
|
+ * 请求报文
|
|
|
+ */
|
|
|
+ //客户号
|
|
|
+ obj_body.put("custId", hlwSubcontractor.getUserId());
|
|
|
+ //批次流水号
|
|
|
+ obj_body.put("batchSerialNo", hlwPayRecord.getYurref());
|
|
|
+ String result = PayNbcbRequest.doRequest(obj_body, productID, serviceID, hlwSubcontractor.getPaymentUrl());
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ jsonObjectData = jsonObject.getJSONObject("Data");
|
|
|
+ if (jsonObjectData != null) {
|
|
|
+ String retCode = jsonObjectData.getString("retCode");
|
|
|
+ //正常响应为SUC0000
|
|
|
+ if (PayNbcbConst.SUCCESS.equals(retCode)) {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ //成功笔数
|
|
|
+ int successNum = jsonObjectData.getInteger("successNum");
|
|
|
+ log.info("successNum========{}", successNum);
|
|
|
+ //失败笔数
|
|
|
+ int failNum = jsonObjectData.getInteger("failNum");
|
|
|
+ //进行中的笔数
|
|
|
+ int processNum = jsonObjectData.getInteger("processNum");
|
|
|
+ //交易明细列表
|
|
|
+ JSONArray jsonArrayBody = jsonObjectData.getJSONArray("transferDtls");
|
|
|
+ //多记录
|
|
|
+ if (jsonArrayBody != null && jsonArrayBody.size() > 0) {
|
|
|
+ for (int i = 0; i < jsonArrayBody.size(); i++) {
|
|
|
+ JSONObject jsonObjectDetail = jsonArrayBody.getJSONObject(i);
|
|
|
+ log.info("状态========{}", jsonObjectDetail.getString("status"));
|
|
|
+ //明细流水号
|
|
|
+ String serialNo = jsonObjectDetail.getString("serialNo");
|
|
|
+ //交易状态(0:交易成功)
|
|
|
+ String status = jsonObjectDetail.getString("status");
|
|
|
+ //错误描述
|
|
|
+ String errDesc = jsonObjectDetail.getString("errDesc");
|
|
|
+ /**当是经办 + 复核时,明细信息添加以下字段*/
|
|
|
+ //收款账号
|
|
|
+ String rcvAcc = jsonObjectDetail.getString("rcvAcc");
|
|
|
+ //收款户名
|
|
|
+ String rcvName = jsonObjectDetail.getString("rcvName");
|
|
|
+ log.info("收款账户====={}", jsonObjectDetail.getString("rcvAcc"));
|
|
|
+ log.info("收款户名========{}", jsonObjectDetail.get("rcvName"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ log.info("resultmsg========{}", jsonObjectData.getString("retMsg"));
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("请求报错{}", e.getMessage());
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代发明细回单查询
|
|
|
+ *
|
|
|
+ * @param hlwSubcontractor
|
|
|
+ */
|
|
|
+ public static JSONObject DCAGPPDF(HlwPayRecord hlwPayRecord, HlwSubcontractor hlwSubcontractor, String prtmod) {
|
|
|
+ JSONObject jsonObjectData = null;
|
|
|
+ try {
|
|
|
+ // body
|
|
|
+ JSONObject obj_body = new JSONObject();
|
|
|
+ //产品号
|
|
|
+ String productID = PayNbcbConst.ACCINFO;
|
|
|
+ //服务号
|
|
|
+ String serviceID = PayNbcbConst.QUERYRECEIPT;
|
|
|
+ /**
|
|
|
+ * 请求报文
|
|
|
+ */
|
|
|
+ //客户号
|
|
|
+ obj_body.put("custId", hlwSubcontractor.getUserId());
|
|
|
+ //查询标识 0:erp批次编号查询 1::单账户查询 2:多账户查询 3: erp单笔付款编号查询或批次明细编号查询
|
|
|
+ obj_body.put("queryFlag", "0");
|
|
|
+ //交易流水号 queryFlag为0或3时必输
|
|
|
+ obj_body.put("serialNo", hlwPayRecord.getYurref());
|
|
|
+ String result = PayNbcbRequest.doRequest(obj_body, productID, serviceID, hlwSubcontractor.getPaymentUrl());
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ jsonObjectData = jsonObject.getJSONObject("Data");
|
|
|
+ if (jsonObjectData != null) {
|
|
|
+ String retCode = jsonObjectData.getString("retCode");
|
|
|
+ //正常响应为SUC0000
|
|
|
+ if (PayNbcbConst.SUCCESS.equals(retCode)) {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ //下载编号
|
|
|
+ String downloadNo = jsonObjectData.getString("downloadNo");
|
|
|
+ log.info("downloadNo========{}", downloadNo);
|
|
|
+ } else {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ log.info("resultmsg========{}", jsonObjectData.getString("retMsg"));
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("请求报错{}", e.getMessage());
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取下载地址通用接口
|
|
|
+ *
|
|
|
+ * @param hlwSubcontractor
|
|
|
+ */
|
|
|
+ public static JSONObject DCTASKID(String downloadNo, HlwSubcontractor hlwSubcontractor) {
|
|
|
+ JSONObject jsonObjectData = null;
|
|
|
+ try {
|
|
|
+ // body
|
|
|
+ JSONObject obj_body = new JSONObject();
|
|
|
+ //产品号
|
|
|
+ String productID = PayNbcbConst.DOWNLOAD;
|
|
|
+ //服务号
|
|
|
+ String serviceID = PayNbcbConst.GETGENERALDOWNLOADURL;
|
|
|
+ /**
|
|
|
+ * 查询条件
|
|
|
+ */
|
|
|
+ //客户号
|
|
|
+ obj_body.put("custId", hlwSubcontractor.getUserId());
|
|
|
+ //下载编号
|
|
|
+ obj_body.put("downloadNo", downloadNo);
|
|
|
+ //交易类型
|
|
|
+ obj_body.put("tradeType", PayNbcbConst.RECEIPT);
|
|
|
+ String result = PayNbcbRequest.doRequest(obj_body, productID, serviceID, hlwSubcontractor.getPaymentUrl());
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ jsonObjectData = jsonObject.getJSONObject("Data");
|
|
|
+ if (jsonObjectData != null) {
|
|
|
+ String retCode = jsonObjectData.getString("retCode");
|
|
|
+ //正常响应为SUC0000
|
|
|
+ if (PayNbcbConst.SUCCESS.equals(retCode)) {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ //下载地址
|
|
|
+ String downloadUrl = jsonObjectData.getString("downloadUrl");
|
|
|
+ log.info("downloadUrl========{}", downloadUrl);
|
|
|
+ //交易状态
|
|
|
+ //0:交易成功
|
|
|
+ //1:交易失败
|
|
|
+ //2:待查询
|
|
|
+ log.info("transState========{}", jsonObjectData.getString("transState"));
|
|
|
+ } else {
|
|
|
+ log.info("resultcode========{}", jsonObjectData.getString("retCode"));
|
|
|
+ log.info("resultmsg========{}", jsonObjectData.getString("retMsg"));
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("请求报错{}", e.getMessage());
|
|
|
+ }
|
|
|
+ return jsonObjectData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取支付账户信息
|
|
|
+ *
|
|
|
+ * @param hlwSubcontractor
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static HlwPayAccountCmb getAccnbr(HlwSubcontractor hlwSubcontractor) {
|
|
|
+ HlwPayAccountCmb hlwPayAccountCmb = new HlwPayAccountCmb();
|
|
|
+ //获取支付账户信息
|
|
|
+ QueryWrapper<HlwPayAccountCmb> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("subcontractor_id", hlwSubcontractor.getId());
|
|
|
+ List<HlwPayAccountCmb> hlwPayAccountCmbList = iHlwPayAccountCmbService.list(queryWrapper);
|
|
|
+ if (hlwPayAccountCmbList != null && hlwPayAccountCmbList.size() > 0) {
|
|
|
+ hlwPayAccountCmb = hlwPayAccountCmbList.get(0);
|
|
|
+ } else {
|
|
|
+ //没有支付账户信息,则调用获取账户信息接口
|
|
|
+ List<HlwPayAccountCmb> hlwPayAccountCmbList1 = DCLISACC(hlwSubcontractor);
|
|
|
+ if (hlwPayAccountCmbList1 != null && hlwPayAccountCmbList1.size() > 0) {
|
|
|
+ hlwPayAccountCmb = hlwPayAccountCmbList1.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return hlwPayAccountCmb;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|