Authored by Lixiaodi

增加订单alarm信息

package com.yohoufo.common.alarm;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class CommonAlarmEventPublisher implements ApplicationContextAware {
private static final Logger logger = LoggerFactory.getLogger(CommonAlarmEventPublisher.class);
private static ApplicationContext applicationContext;
private static ExecutorService exe;
public CommonAlarmEventPublisher() {
exe = Executors.newFixedThreadPool(1);
}
public static void publish(String name, String type, String content) {
logger.info("publish an event name={}, type={}, content={}", name, type, content);
exe.execute(() -> {
applicationContext.publishEvent(new SmsAlarmEvent(name, type, content));
});
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
CommonAlarmEventPublisher.applicationContext = applicationContext;
}
}
\ No newline at end of file
... ...
package com.yohoufo.common.alarm;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@ToString
@EqualsAndHashCode(callSuper=false)
public class SmsAlarmEvent extends Event {
private String name;
private String type;
... ...
... ... @@ -17,6 +17,7 @@ import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
... ... @@ -527,7 +528,7 @@ public class PaymentServiceImpl implements IPaymentService {
logger.info("transferMon计算费用结果为 {}", transferAmount);
if (transferAmount == null) {
logger.warn("transferMonErr transferMon计算费用结果为 null, 不合法的金额");
// TODO alarm
alarm("转账金额不合法", "ufo.order.transferMon", "订单号:" + buyerOrderCode + "操作类型(" + transferType + ")计算金额结果为null");
record.setTradeStatus(202);
addTradeBills(record);
throw new ServiceException(400, "计算金额错误!:");
... ... @@ -538,7 +539,7 @@ public class PaymentServiceImpl implements IPaymentService {
record.setSystemAmount(transferAmount.multiply(new BigDecimal("-1")));
if (transferAmount.compareTo(new BigDecimal("0.1")) < 0) {
logger.warn("transferMonErr transferMon计算费用结果为 {}, 小于0.1", transferAmount);
// TODO alarm
alarm("转账金额小于0.1", "ufo.order.transferMon", "订单号:" + buyerOrderCode + "操作类型(" + transferType + ")计算金额结果为" + transferAmount);
record.setTradeStatus(202);
addTradeBills(record);
throw new ServiceException(400, "不合法的金额:" + transferAmount);
... ... @@ -570,7 +571,7 @@ public class PaymentServiceImpl implements IPaymentService {
}
} catch (Exception e) {
logger.warn("transferMonErr 转账失败 , orderCode is {}, msg is {}", buyerOrderCode, e.getMessage());
// TODO alarm
alarm("转账失败", "ufo.order.transferMon", "订单号:" + buyerOrderCode + "操作类型(" + transferType + ")转账失败,msg=" + e.getMessage());
transfer.setStatus(3);
if(e instanceof ServiceException) {
throw new ServiceException(((ServiceException) e).getCode(), e.getMessage());
... ... @@ -672,7 +673,8 @@ public class PaymentServiceImpl implements IPaymentService {
}
} catch (Exception e) {
logger.warn("manualDealErr 退款失败 , tradeBillsId is {}, msg is {}", tradeBillsId, e.getMessage());
// TODO alarm
alarm("人工处理退款失败", "ufo.order.manualDeal",
"订单号:" + orderCode + "操作类型(退款)转账失败,流水id=" + tradeBillsId + ",msg=" + e.getMessage());
preSuccess.setDealStatus(0);
tradeBillsMapper.updateToFailByPrimaryKey(preSuccess);
if (e instanceof ServiceException) {
... ... @@ -717,7 +719,8 @@ public class PaymentServiceImpl implements IPaymentService {
}
} catch (Exception e) {
logger.warn("manualDealErr 转账失败 , orderCode is {}, msg is {}", orderCode, e.getMessage());
// alarm
alarm("人工处理转账失败", "ufo.order.manualDeal",
"订单号:" + orderCode + "操作类型(退款)转账失败,流水id=" + tradeBillsId + ",msg=" + e.getMessage());
preSuccess.setDealStatus(0);
tradeBillsMapper.updateToFailByPrimaryKey(preSuccess);
if (e instanceof ServiceException) {
... ... @@ -780,7 +783,9 @@ public class PaymentServiceImpl implements IPaymentService {
tradeBillsMapper.insert(record);
} catch (Exception e) {
logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
// TODO alarm
alarm("记录流水到数据库出错", "ufo.order.addTradeBills",
"流水信息:" + record.toString() + ",msg=" + e.getMessage());
}
}
... ... @@ -964,7 +969,9 @@ public class PaymentServiceImpl implements IPaymentService {
}
private void alarm(String name, String type, String content) {
CommonAlarmEventPublisher.publish(name, type, content);
}
... ...