package com.payday.quartz;
import com.payday.dto.paycenter.PaycenterResponse;
import com.payday.model.MsgNotify;
import com.payday.model.OrderPaymentInfo;
import com.payday.model.Orders;
import com.payday.service.OrderPaymentInfoService;
import com.payday.service.impl.MsgNotifyServiceImpl;
import com.payday.util.DateUtil;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
/**
* 打款结果查询【每三分钟执行任务查询没有支付结果的打款记录】
* @author Chengfei.Sun on 2015/10/8.
*/
public class PaymentQueryQuartz {
private static final Logger logger = LoggerFactory.getLogger(PaymentQueryQuartz.class);
@Autowired
private OrderPaymentInfoService orderPaymentInfoServiceImpl;
@Autowired
private MsgNotifyServiceImpl msgNotifyServiceImpl;
public void paymentQueryWork() {
try {
logger.info("paymentQueryWork--------------打款结果查询定时任务调度执行开始 " + DateUtil.GetStringDate(new Date()));
//查询状态为打款处理中的的打款订单
List<OrderPaymentInfo> paymentInfoList = orderPaymentInfoServiceImpl.getPendingPaymentInfoList();
if (paymentInfoList != null && !paymentInfoList.isEmpty()) {
logger.info("打款结果处理需要查询的数量是:" + paymentInfoList.size());
}
for (OrderPaymentInfo orderPaymentInfo : paymentInfoList) {
//发送第三方请求
PaycenterResponse response = orderPaymentInfoServiceImpl.queryPaymentInfo(orderPaymentInfo.getPaySource(),
orderPaymentInfo.getOrderNo(), orderPaymentInfo.getBatchNo());
if(response!=null){
//如果是处理中状态直接返回
if (("00A4").equals(response.getPayState()) || ("00A4").equals(response.getResultCode())) {//00A4处理中
logger.info("批次号:" + response.getBatchNo() + "支付请求正在处理中,返回码payState:" + response.getPayState());
continue;
}
if(response.isSuccess()){//打款成功
logger.info("支付请求发送成功" + response.getPayState());
String orderNo=orderPaymentInfo.getOrderNo();
Orders orders=new Orders();
orders.setOrderStatus(20);
orders.setOrderNo(orderNo);
//根据BatchNo修改order订单状态
orderPaymentInfoServiceImpl.updateOrder(orders);
OrderPaymentInfo orderPayment=new OrderPaymentInfo();
orderPayment.setStatus(20);
//修改支付记录状态
orderPaymentInfoServiceImpl.updateOrderPaymentInfoByBatchNo(orderPayment);
//插入MsgNotify
MsgNotify msg=new MsgNotify();
msg.setOrderStatus(8);//8成功 10失败
msg.setMessageStatus(20);
msg.setEditor("1002");
msg.setCreater("1002");
msg.setEditTime(new Date());
msg.setCreateTime(new Date());
msg.setMessageDataType("json");
msg.setMessageSendTimes(0);
msg.setAreadlyDead("y");
msg.setMessageStatus(20);
msg.setRemark("1002");
msg.setDealTime(new Date());
msgNotifyServiceImpl.insertMessage(msg);
}else{//打款失败
logger.error("支付请求失败" + response.getPayState());
String orderNo=orderPaymentInfo.getOrderNo();
Orders orders=new Orders();
orders.setOrderStatus(30);
orders.setOrderNo(orderNo);
//根据BatchNo修改order订单状态
orderPaymentInfoServiceImpl.updateOrder(orders);
OrderPaymentInfo orderPayment=new OrderPaymentInfo();
orderPayment.setStatus(30);
orderPayment.setOrderNo(orderNo);
//修改支付记录状态
orderPaymentInfoServiceImpl.updateOrderPaymentInfoByBatchNo(orderPayment);
//插入MsgNotify
MsgNotify msg=new MsgNotify();
msg.setOrderStatus(10);//8成功 10失败
msg.setMessageStatus(30);
msg.setEditor("1002");
msg.setCreater("1002");
msg.setEditTime(new Date());
msg.setCreateTime(new Date());
msg.setMessageDataType("json");
msg.setMessageSendTimes(0);
msg.setAreadlyDead("y");
msg.setMessageStatus(20);
msg.setRemark("1002");
msg.setDealTime(new Date());
msgNotifyServiceImpl.insertMessage(msg);
}
}
}
} catch (Exception e) {
logger.error("打款结果查询定时器异常:{}", ExceptionUtils.getStackTrace(e));
}
}
}
import com.payday.dto.paycenter.PaycenterResponse;
import com.payday.model.MsgNotify;
import com.payday.model.OrderPaymentInfo;
import com.payday.model.Orders;
import com.payday.service.OrderPaymentInfoService;
import com.payday.service.impl.MsgNotifyServiceImpl;
import com.payday.util.DateUtil;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
/**
* 打款结果查询【每三分钟执行任务查询没有支付结果的打款记录】
* @author Chengfei.Sun on 2015/10/8.
*/
public class PaymentQueryQuartz {
private static final Logger logger = LoggerFactory.getLogger(PaymentQueryQuartz.class);
@Autowired
private OrderPaymentInfoService orderPaymentInfoServiceImpl;
@Autowired
private MsgNotifyServiceImpl msgNotifyServiceImpl;
public void paymentQueryWork() {
try {
logger.info("paymentQueryWork--------------打款结果查询定时任务调度执行开始 " + DateUtil.GetStringDate(new Date()));
//查询状态为打款处理中的的打款订单
List<OrderPaymentInfo> paymentInfoList = orderPaymentInfoServiceImpl.getPendingPaymentInfoList();
if (paymentInfoList != null && !paymentInfoList.isEmpty()) {
logger.info("打款结果处理需要查询的数量是:" + paymentInfoList.size());
}
for (OrderPaymentInfo orderPaymentInfo : paymentInfoList) {
//发送第三方请求
PaycenterResponse response = orderPaymentInfoServiceImpl.queryPaymentInfo(orderPaymentInfo.getPaySource(),
orderPaymentInfo.getOrderNo(), orderPaymentInfo.getBatchNo());
if(response!=null){
//如果是处理中状态直接返回
if (("00A4").equals(response.getPayState()) || ("00A4").equals(response.getResultCode())) {//00A4处理中
logger.info("批次号:" + response.getBatchNo() + "支付请求正在处理中,返回码payState:" + response.getPayState());
continue;
}
if(response.isSuccess()){//打款成功
logger.info("支付请求发送成功" + response.getPayState());
String orderNo=orderPaymentInfo.getOrderNo();
Orders orders=new Orders();
orders.setOrderStatus(20);
orders.setOrderNo(orderNo);
//根据BatchNo修改order订单状态
orderPaymentInfoServiceImpl.updateOrder(orders);
OrderPaymentInfo orderPayment=new OrderPaymentInfo();
orderPayment.setStatus(20);
//修改支付记录状态
orderPaymentInfoServiceImpl.updateOrderPaymentInfoByBatchNo(orderPayment);
//插入MsgNotify
MsgNotify msg=new MsgNotify();
msg.setOrderStatus(8);//8成功 10失败
msg.setMessageStatus(20);
msg.setEditor("1002");
msg.setCreater("1002");
msg.setEditTime(new Date());
msg.setCreateTime(new Date());
msg.setMessageDataType("json");
msg.setMessageSendTimes(0);
msg.setAreadlyDead("y");
msg.setMessageStatus(20);
msg.setRemark("1002");
msg.setDealTime(new Date());
msgNotifyServiceImpl.insertMessage(msg);
}else{//打款失败
logger.error("支付请求失败" + response.getPayState());
String orderNo=orderPaymentInfo.getOrderNo();
Orders orders=new Orders();
orders.setOrderStatus(30);
orders.setOrderNo(orderNo);
//根据BatchNo修改order订单状态
orderPaymentInfoServiceImpl.updateOrder(orders);
OrderPaymentInfo orderPayment=new OrderPaymentInfo();
orderPayment.setStatus(30);
orderPayment.setOrderNo(orderNo);
//修改支付记录状态
orderPaymentInfoServiceImpl.updateOrderPaymentInfoByBatchNo(orderPayment);
//插入MsgNotify
MsgNotify msg=new MsgNotify();
msg.setOrderStatus(10);//8成功 10失败
msg.setMessageStatus(30);
msg.setEditor("1002");
msg.setCreater("1002");
msg.setEditTime(new Date());
msg.setCreateTime(new Date());
msg.setMessageDataType("json");
msg.setMessageSendTimes(0);
msg.setAreadlyDead("y");
msg.setMessageStatus(20);
msg.setRemark("1002");
msg.setDealTime(new Date());
msgNotifyServiceImpl.insertMessage(msg);
}
}
}
} catch (Exception e) {
logger.error("打款结果查询定时器异常:{}", ExceptionUtils.getStackTrace(e));
}
}
}