|
|
@@ -0,0 +1,203 @@
|
|
|
+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 org.apache.commons.lang.StringUtils;
|
|
|
+import org.jeecg.common.nbcbutils.PayNbcbConst;
|
|
|
+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.PayNbcbCommon;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+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.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: zwq
|
|
|
+ * @Description: 宁波银行支付查询定时器
|
|
|
+ * @Date: Create in 09:19 2021/09/25
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Service
|
|
|
+public class PaymentNbcbJob {
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(PaymentNbcbJob.class);
|
|
|
+ @Autowired
|
|
|
+ private IHlwPayRecordService hlwPayRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwPaymentDetailService hlwPaymentDetailService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwPaymentService hlwPaymentService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwSubcontractorService hlwSubcontractorService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwDutyApplyService hlwDutyApplyService;
|
|
|
+
|
|
|
+
|
|
|
+ @XxlJob("paymentNbcbJobHandler")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public ReturnT<String> paymentNbcbJobHandler(String param) throws Exception {
|
|
|
+ logger.info(String.format(" 支付查询定时器! 时间:" + DateUtils.getTimestamp()));
|
|
|
+ XxlJobLogger.log(String.format(" 支付查询定时器! 时间:" + DateUtils.getTimestamp()));
|
|
|
+
|
|
|
+ //查询所有交易状态为在途(不为FIN))的批次
|
|
|
+ List<HlwPayRecord> hlwPayRecordList = hlwPayRecordService.findNoPayRsaList();
|
|
|
+ logger.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 = PayNbcbCommon.NTAGCINY(hlwPayRecord, hlwSubcontractor);
|
|
|
+ if (jsonObjectBody != null) {
|
|
|
+ String retCode = jsonObjectBody.getString("retCode");
|
|
|
+ //正常响应为SUC0000
|
|
|
+ if (PayNbcbConst.SUCCESS.equals(retCode)) {
|
|
|
+ //成功笔数
|
|
|
+ int successNum = jsonObjectBody.getInteger("successNum");
|
|
|
+ logger.info("successNum========{}", successNum);
|
|
|
+ //失败笔数
|
|
|
+ int failNum = jsonObjectBody.getInteger("failNum");
|
|
|
+ logger.info("failNum========{}", failNum);
|
|
|
+ //进行中的笔数
|
|
|
+ int processNum = jsonObjectBody.getInteger("processNum");
|
|
|
+ logger.info("processNum========{}", processNum);
|
|
|
+ //业务请求状态
|
|
|
+ String reqsta = null;
|
|
|
+ //代发明细信息
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ //获取record表支付记录detail
|
|
|
+ String payDetail = hlwPayRecord.getDetail();
|
|
|
+ JSONArray jsonArray1 = JSONArray.parseArray(payDetail);
|
|
|
+ //processNum=0时,说明批次已完成,调明细接口
|
|
|
+ if (processNum == 0) {
|
|
|
+ reqsta = PayConst.FIN;
|
|
|
+ //代发明细信息
|
|
|
+ jsonArray = jsonObjectBody.getJSONArray("transferDtls");
|
|
|
+ //遍历查询付款状态并更新到hlw_payment_detail表
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
+ //明细流水号
|
|
|
+ String serialNo = jsonObject.getString("serialNo");
|
|
|
+ //交易状态(0:交易成功)
|
|
|
+ String status = jsonObject.getString("status");
|
|
|
+ for (int k = 0; k < jsonArray1.size(); k++) {
|
|
|
+ //比较明细流水号,确定是否是同一个人
|
|
|
+ if (serialNo.equals(jsonArray1.getJSONObject(k).getString("dtlSerialNo"))) {
|
|
|
+ //获取详情表主键id
|
|
|
+ String hlwPaymentDetailId = jsonArray1.getJSONObject(k).getString("id");
|
|
|
+ HlwPaymentDetail hlwPaymentDetail = hlwPaymentDetailService.getById(hlwPaymentDetailId);
|
|
|
+ List<String> failStatus = Arrays.asList(PayNbcbConst.PAY_STATUS_FAIL.split(","));
|
|
|
+ if (status.equals(PayNbcbConst.PAY_STATUS_SUCCESS)) {
|
|
|
+ //成功
|
|
|
+ hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_SUCCESS);
|
|
|
+ //累加完税金额
|
|
|
+ amount = businessAccountUtils.add(amount, hlwPaymentDetail.getNetPayment());
|
|
|
+ //完税人员
|
|
|
+ applyList.add(hlwPaymentDetailId);
|
|
|
+ } else if (failStatus.contains(status)) {
|
|
|
+ //失败
|
|
|
+ hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_FAIL);
|
|
|
+ //代发失败的错误描述
|
|
|
+ String errmsg = jsonObject.getString("errDesc");
|
|
|
+ hlwPaymentDetail.setFailureReason(errmsg);
|
|
|
+ } else {
|
|
|
+ //进行中
|
|
|
+ status = "A";
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新付款详情
|
|
|
+ */
|
|
|
+ //状态为非待交易状态,则更新付款单明细
|
|
|
+ if (StringUtils.isNotBlank(status) && !"A".equals(status)) {
|
|
|
+ hlwPaymentDetail.setPaymentResultTime(new Date());
|
|
|
+ hlwPaymentDetailService.updateById(hlwPaymentDetail);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //更新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) {
|
|
|
+ logger.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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|