|
|
@@ -0,0 +1,180 @@
|
|
|
+package org.jeecg.modules.hlwpayment.task;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.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.PayCommon;
|
|
|
+import org.quartz.Job;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.quartz.JobExecutionException;
|
|
|
+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.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: zwq
|
|
|
+ * @Description:支付查询定时器
|
|
|
+ * @Date: Create in 17:19 2020/07/27
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+@Service
|
|
|
+public class PaymentJob implements Job {
|
|
|
+ @Autowired
|
|
|
+ private IHlwPayRecordService hlwPayRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwPaymentDetailService hlwPaymentDetailService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwPaymentService hlwPaymentService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwSubcontractorService hlwSubcontractorService;
|
|
|
+ @Autowired
|
|
|
+ private IHlwDutyApplyService hlwDutyApplyService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
+ log.info(String.format(" 支付查询定时器! 时间:" + DateUtils.getTimestamp()));
|
|
|
+ //查询所有没结果的付款批次(终态包括:VD,CL,WF,UF,OF,SY)
|
|
|
+ List<HlwPayRecord> hlwPayRecordList = hlwPayRecordService.findNoPayList();
|
|
|
+ //完税金额
|
|
|
+ Double amount = 0.00;
|
|
|
+ for (HlwPayRecord hlwPayRecord : hlwPayRecordList) {
|
|
|
+ //获取当前支付单
|
|
|
+ HlwPayment hlwPaymentDto = hlwPaymentService.getById(hlwPayRecord.getPaymentId());
|
|
|
+ //服务商信息
|
|
|
+ HlwSubcontractor hlwSubcontractor = hlwSubcontractorService.getById(hlwPaymentDto.getSubcontractorId());
|
|
|
+ //请求银行接口查询结果
|
|
|
+ JSONObject jsonObjectBody = PayCommon.DCAGPDTL(hlwPayRecord, hlwSubcontractor);
|
|
|
+ //续传键值
|
|
|
+ String ctnkey = jsonObjectBody.getString("ctnkey");
|
|
|
+ //代发明细汇总信息
|
|
|
+ JSONObject jsonObjectDetail = jsonObjectBody.getJSONObject("detail");
|
|
|
+ //代发明细信息
|
|
|
+ JSONArray jsonArray = jsonObjectBody.getJSONArray("tradeList");
|
|
|
+ //更新hlwPayRecord
|
|
|
+ hlwPayRecord.setCtnkey(ctnkey);
|
|
|
+ String recsts = jsonObjectDetail.getString("recsts");
|
|
|
+ hlwPayRecord.setRecsts(recsts);
|
|
|
+ hlwPayRecord.setTrade(jsonArray.toJSONString());
|
|
|
+ hlwPayRecord.setUpdateTime(new Date());
|
|
|
+ hlwPayRecordService.updateById(hlwPayRecord);
|
|
|
+ //获取record表支付记录detail
|
|
|
+ String payDetail = hlwPayRecord.getDetail();
|
|
|
+ JSONArray jsonArray1 = JSONArray.parseArray(payDetail);
|
|
|
+ //遍历查询付款状态并更新到hlw_payment_detail表
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
+ //获取当笔支付的交易状态(W:待交易S:成功E:失败)
|
|
|
+ String stscod = jsonObject.getString("stscod");
|
|
|
+ //卡号
|
|
|
+ String eacnbr = jsonObject.getString("eacnbr");
|
|
|
+ for (int k = 0; k < jsonArray1.size(); k++) {
|
|
|
+ //比较卡号,确定是否是同一个人
|
|
|
+ if (eacnbr.equals(jsonArray1.getJSONObject(k).getString("cardNumber"))) {
|
|
|
+ //获取详情表主键id
|
|
|
+ String hlwPaymentDetailId = jsonArray1.getJSONObject(k).getString("id");
|
|
|
+ HlwPaymentDetail hlwPaymentDetail = hlwPaymentDetailService.getById(hlwPaymentDetailId);
|
|
|
+ switch (stscod) {
|
|
|
+ case "W":
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "S":
|
|
|
+ hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_SUCCESS);
|
|
|
+ //累加完税金额
|
|
|
+ amount = businessAccountUtils.add(amount, hlwPaymentDetail.getNetPayment());
|
|
|
+ break;
|
|
|
+ case "E":
|
|
|
+ hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_FAIL);
|
|
|
+ //代发失败的错误描述
|
|
|
+ String errmsg = jsonObject.getString("errmsg");
|
|
|
+ hlwPaymentDetail.setFailureReason(errmsg);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新付款详情
|
|
|
+ */
|
|
|
+ //状态为非待交易状态,则更新付款单明细
|
|
|
+ if (StringUtils.isNotBlank(stscod) && !"W".equals(stscod)) {
|
|
|
+ hlwPaymentDetail.setPaymentResultTime(new Date());
|
|
|
+ hlwPaymentDetailService.updateById(hlwPaymentDetail);
|
|
|
+ }
|
|
|
+ //不产生流水的支付失败,明细状态全部变更为支付失败
|
|
|
+ if ("VD".equals(recsts) || "CL".equals(recsts)
|
|
|
+ || "WF".equals(recsts) || "UF".equals(recsts)
|
|
|
+ || "OF".equals(recsts)) {
|
|
|
+ hlwPaymentDetail.setStatus(HlwConstant.PAYMENT_RESULT_PAY_FAIL);
|
|
|
+ //代发失败的错误描述
|
|
|
+ String errnar = jsonObjectDetail.getString("errnar");
|
|
|
+ hlwPaymentDetail.setFailureReason(errnar);
|
|
|
+ hlwPaymentDetail.setPaymentResultTime(new Date());
|
|
|
+ hlwPaymentDetailService.updateById(hlwPaymentDetail);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //付款单状态是终态,才更新
|
|
|
+ if ("VD".equals(recsts) || "CL".equals(recsts)
|
|
|
+ || "WF".equals(recsts) || "UF".equals(recsts)
|
|
|
+ || "OF".equals(recsts) || "SY".equals(recsts)) {
|
|
|
+ /**
|
|
|
+ * 更新付款信息表
|
|
|
+ */
|
|
|
+ //获取付款表主键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);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("插入完税申请失败");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入完税申请表
|
|
|
+ * PROPAGATION_REQUIRES_NEW:创建一个新的事务,如果当前存在事务,则把当前事务挂起。
|
|
|
+ *
|
|
|
+ * @param amount
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
|
|
+ public void insertDutyApply(Double amount) {
|
|
|
+ HlwDutyApply hlwDutyApply = new HlwDutyApply();
|
|
|
+ hlwDutyApply.setAmount(amount);
|
|
|
+ hlwDutyApply.setApplyTime(new Date());
|
|
|
+ //定时任务无法获取用户信息
|
|
|
+ hlwDutyApply.setApplyBy("admin");
|
|
|
+ hlwDutyApplyService.save(hlwDutyApply);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|