Commit 15d767f6 by zhiwj

代码结构调整

parent 3d13d105
...@@ -10,18 +10,20 @@ public enum BuyTypeEnum { ...@@ -10,18 +10,20 @@ public enum BuyTypeEnum {
/** /**
* 短信套餐包购买 * 短信套餐包购买
*/ */
BUY_SHORT_MESSAGE_PACKAGE(2, "短信套餐包购买"), BUY_SHORT_MESSAGE_PACKAGE(2, "短信套餐包购买", "BUY_SHORT_MESSAGE_PACKAGE"),
/** /**
* 商户余额充值 * 商户余额充值
*/ */
BALANCE_RECHARGE(1, "商户余额充值"); BALANCE_RECHARGE(1, "商户余额充值", "BALANCE_RECHARGE");
private int code; private int code;
private String message; private String message;
private String type;
private BuyTypeEnum(int code, String message) { private BuyTypeEnum(int code, String message, String type) {
this.code = code; this.code = code;
this.message = message; this.message = message;
this.type = type;
} }
public static String getMessageByCode(Integer code) { public static String getMessageByCode(Integer code) {
...@@ -36,19 +38,27 @@ public enum BuyTypeEnum { ...@@ -36,19 +38,27 @@ public enum BuyTypeEnum {
return "未知"; return "未知";
} }
public int getCode() { public static String getTypeByCode(Integer code) {
return code; if (code == null) {
return "未知";
}
for (BuyTypeEnum typeEnum : values()) {
if (code.intValue() == typeEnum.getCode()) {
return typeEnum.getType();
}
}
return "未知";
} }
public void setCode(int code) { public int getCode() {
this.code = code; return code;
} }
public String getMessage() { public String getMessage() {
return message; return message;
} }
public void setMessage(String message) { public String getType() {
this.message = message; return type;
} }
} }
...@@ -93,4 +93,23 @@ public interface Constants { ...@@ -93,4 +93,23 @@ public interface Constants {
String NATIONCODESIGN = "+86"; String NATIONCODESIGN = "+86";
String ERP = "erp"; String ERP = "erp";
/**
* 支付锁
*/
String PAY_LOCK = "enterprise:biilingcenterpay";
/**
* 余额支付锁
*/
String PAY_BALANCE_LOCK = "enterprise:biilingcenterbalancepay";
/**
* 退款锁
*/
String REFUND_LOCK = "enterprise:refund";
/**
* 支付回调
*/
String PAY_BACK_LOCK = "enterprise:biilingcentercallback";
} }
...@@ -31,6 +31,10 @@ public class ApprovalCallBackDTO implements Serializable { ...@@ -31,6 +31,10 @@ public class ApprovalCallBackDTO implements Serializable {
@NotNull(message = "审批时间不能为空, 格式为yyyyMMdd", groups = ApprovalValid.class) @NotNull(message = "审批时间不能为空, 格式为yyyyMMdd", groups = ApprovalValid.class)
private String timeEnd; private String timeEnd;
private String prepayId; private String prepayId;
/**
* 支付类型
*/
private Integer payType;
private String onlineSerialNumber; private String onlineSerialNumber;
...@@ -138,6 +142,14 @@ public class ApprovalCallBackDTO implements Serializable { ...@@ -138,6 +142,14 @@ public class ApprovalCallBackDTO implements Serializable {
this.totalFee = totalFee; this.totalFee = totalFee;
} }
public Integer getPayType() {
return payType;
}
public void setPayType(Integer payType) {
this.payType = payType;
}
@Override @Override
public String toString() { public String toString() {
return "ApprovalCallBackDTO{" + return "ApprovalCallBackDTO{" +
......
...@@ -329,7 +329,7 @@ public class AuditLogApiServiceImpl implements AuditLogApiService { ...@@ -329,7 +329,7 @@ public class AuditLogApiServiceImpl implements AuditLogApiService {
if (AuditTypeEnum.HAOBAN.getCode().equals(auditLogDTO.getAuditType())) { if (AuditTypeEnum.HAOBAN.getCode().equals(auditLogDTO.getAuditType())) {
position = StringUtils.isBlank(auditLogDTO.getPosition()) ? "" : auditLogDTO.getPosition(); position = StringUtils.isBlank(auditLogDTO.getPosition()) ? "" : auditLogDTO.getPosition();
} else { } else {
UserDTO userDTO = userApiService.getUserById(auditLogDTO.getApplyUserId()).getResult(); UserDTO userDTO = userApiService.getUserInfoById(auditLogDTO.getApplyUserId()).getResult();
LoginUserTypeEnum userTypeEnum = LoginUserTypeEnum.getByCode(userDTO.getLoginType()); LoginUserTypeEnum userTypeEnum = LoginUserTypeEnum.getByCode(userDTO.getLoginType());
position = userTypeEnum != null ? userTypeEnum.getMessage() : ""; position = userTypeEnum != null ? userTypeEnum.getMessage() : "";
} }
......
...@@ -238,44 +238,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService { ...@@ -238,44 +238,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
@Override @Override
public ServiceResponse<Integer> deductAccount(double totalFee, Integer enterpriseId) { public ServiceResponse<Integer> deductAccount(double totalFee, Integer enterpriseId) {
if (isNotInWhiteList(enterpriseId)) { // 在白名单中
TabBillingAccount billingAccount = billingAccountService.getByEnterpriseId(enterpriseId); if (isInWhiteList(enterpriseId)) {
Double accountBalance = billingAccount.getAccountBalance();
if (accountBalance >= 0) {
int i = billingAccountService.deductAccount(totalFee, enterpriseId);
LOGGER.info("扣费是否成功:{}", i > 0);
if (i > 0) {
TabBillingAccount account = this.billingAccountService.getByEnterpriseId(enterpriseId);
if (account.getAccountBalance() < 0) {
Object cache = RedisUtil.getCache("message:" + enterpriseId);
if (cache == null) {
String content = "您的达摩账户已欠费, 为避免您的业务受到影响,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
sendSms(enterpriseId, "GICJFZX012");
// 待办事项
sendTotoItem(enterpriseId, "您的达摩账户已欠费");
RedisUtil.setCache("message:" + enterpriseId, 1, 1L, TimeUnit.DAYS);
}
} else if (account.getAccountBalance() < ACCOUNT_NOTICE_LINE) {
Object cache = RedisUtil.getCache("insufficientAccountBalanceMessage:" + enterpriseId);
if (cache == null) {
String content = "您的达摩账户余额已不足1000元,若账户欠费将中断部分正常业务,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
sendSms(enterpriseId, "GICJFZX001");
// 待办事项
sendTotoItem(enterpriseId, "您的达摩账户余额已不足1000元");
RedisUtil.setCache("insufficientAccountBalanceMessage:" + enterpriseId, 1, 7L, TimeUnit.DAYS);
}
}
}
return ServiceResponse.success(i);
} else {
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "余额不足");
}
} else {
int i = billingAccountService.deductAccount(totalFee, enterpriseId); int i = billingAccountService.deductAccount(totalFee, enterpriseId);
return ServiceResponse.success(i); return ServiceResponse.success(i);
} }
// 不在白名单中
TabBillingAccount billingAccount = billingAccountService.getByEnterpriseId(enterpriseId);
Double accountBalance = billingAccount.getAccountBalance();
if (accountBalance < 0) {
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "余额不足");
}
int i = billingAccountService.deductAccount(totalFee, enterpriseId);
LOGGER.info("扣费是否成功:{}", i > 0);
return ServiceResponse.success(i);
} }
private void sendSms(Integer enterpriseId, String sceneId) { private void sendSms(Integer enterpriseId, String sceneId) {
...@@ -300,14 +277,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService { ...@@ -300,14 +277,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
Integer enterpriseId = enterpriseDTO.getEnterpriseId(); Integer enterpriseId = enterpriseDTO.getEnterpriseId();
if (isNotInWhiteList(enterpriseId)) { if (isNotInWhiteList(enterpriseId)) {
TabBillingAccount account = this.billingAccountService.getByEnterpriseId(enterpriseId); TabBillingAccount account = this.billingAccountService.getByEnterpriseId(enterpriseId);
if (account.getAccountBalance() < ACCOUNT_NOTICE_LINE) { if (account.getAccountBalance() < 0) {
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), String.valueOf(-account.getAccountBalance())}; String content = "您的达摩账户已欠费, 为避免您的业务受到影响,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
ServiceResponse<UserDTO> userResult = userApiService.getUserByEnterpriseId(enterpriseId); this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
UserDTO userDTO = userResult.getResult(); sendSms(enterpriseId, "GICJFZX012");
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(account.getAccountBalance() < 0 ? "GICJFZX012" :"GICJFZX001", // 待办事项
enterpriseId, userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr); sendTotoItem(enterpriseId, "您的达摩账户已欠费");
if (!smsSendResult.isSuccess()) { } else if (account.getAccountBalance() < ACCOUNT_NOTICE_LINE) {
LOGGER.warn(smsSendResult.getMessage()); Object cache = RedisUtil.getCache("insufficientAccountBalanceMessage:" + enterpriseId);
if (cache == null) {
String content = "您的达摩账户余额已不足1000元,若账户欠费将中断部分正常业务,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
sendSms(enterpriseId, "GICJFZX001");
// 待办事项
sendTotoItem(enterpriseId, "您的达摩账户余额已不足1000元");
RedisUtil.setCache("insufficientAccountBalanceMessage:" + enterpriseId, 1, 7L, TimeUnit.DAYS);
} }
} }
} }
...@@ -320,6 +304,11 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService { ...@@ -320,6 +304,11 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) == null; return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) == null;
} }
private boolean isInWhiteList(Integer enterpriseId) {
// 判断商户在不在白名单中
return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) != null;
}
private void sendTotoItem(Integer enterpriseId, String content) { private void sendTotoItem(Integer enterpriseId, String content) {
TodoItemDTO todoItemDTO = new TodoItemDTO(); TodoItemDTO todoItemDTO = new TodoItemDTO();
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult(); UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
......
package com.gic.enterprise.service.outer.impl; package com.gic.enterprise.service.outer.impl;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.constant.BillingPayResultEnum; import com.gic.enterprise.constant.BillingPayResultEnum;
import com.gic.enterprise.constant.Constants;
import com.gic.enterprise.constant.PayTypeEnum; import com.gic.enterprise.constant.PayTypeEnum;
import com.gic.enterprise.dto.*; import com.gic.enterprise.dto.*;
import com.gic.enterprise.entity.TabBillingAccount; import com.gic.enterprise.entity.TabBillingAccount;
...@@ -20,7 +12,16 @@ import com.gic.enterprise.entity.TabBillingRefund; ...@@ -20,7 +12,16 @@ import com.gic.enterprise.entity.TabBillingRefund;
import com.gic.enterprise.error.ErrorCode; import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.service.*; import com.gic.enterprise.service.*;
import com.gic.enterprise.utils.CreateRandomUtils; import com.gic.enterprise.utils.CreateRandomUtils;
import com.gic.redis.data.util.RedisUtil;
import com.gic.store.utils.valid.ValidUtil; import com.gic.store.utils.valid.ValidUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.math.BigDecimal;
import java.util.Date;
/** /**
* *
...@@ -96,27 +97,35 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ ...@@ -96,27 +97,35 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ
@Override @Override
public ServiceResponse<BalancePayReturnDTO> savePayAndConfirmPay(OutPayDTO outPayDTO) { public ServiceResponse<BalancePayReturnDTO> savePayAndConfirmPay(OutPayDTO outPayDTO) {
ServiceResponse paramResult = ValidUtil.allCheckValidate(outPayDTO, OutPayDTO.ConfirmPay.class, OutPayDTO.SavePrePay.class); try {
if (!paramResult.isSuccess()) { RedisUtil.lock(Constants.PAY_BALANCE_LOCK + outPayDTO.getEnterpriseId(), 5L);
return paramResult; ServiceResponse paramResult = ValidUtil.allCheckValidate(outPayDTO, OutPayDTO.ConfirmPay.class, OutPayDTO.SavePrePay.class);
} if (!paramResult.isSuccess()) {
outPayDTO.setPayType(PayTypeEnum.BALANCE_PAY.getCode()); return paramResult;
ServiceResponse<BillingPayInfoDTO> serviceResponse = billingPayInfoApiService.savePrePayInfo(outPayDTO); }
if (!serviceResponse.isSuccess()) { outPayDTO.setPayType(PayTypeEnum.BALANCE_PAY.getCode());
return ServiceResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage()); ServiceResponse<BillingPayInfoDTO> serviceResponse = billingPayInfoApiService.savePrePayInfo(outPayDTO);
} if (!serviceResponse.isSuccess()) {
ServiceResponse<BillingPayInfoDTO> confirmPayResponse = billingPayInfoApiService.confirmPay(outPayDTO); return ServiceResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
if (confirmPayResponse.isSuccess()) { }
BillingPayInfoDTO payInfoDTO = confirmPayResponse.getResult(); ServiceResponse<BillingPayInfoDTO> confirmPayResponse = billingPayInfoApiService.confirmPay(outPayDTO);
BalancePayReturnDTO balancePayReturnDTO = new BalancePayReturnDTO(); if (confirmPayResponse.isSuccess()) {
balancePayReturnDTO.setPayInfoSerialNumber(payInfoDTO.getSerialNumber()); BillingPayInfoDTO payInfoDTO = confirmPayResponse.getResult();
balancePayReturnDTO.setOrderSerialNumber(payInfoDTO.getOrderSerialNumber()); BalancePayReturnDTO balancePayReturnDTO = new BalancePayReturnDTO();
balancePayReturnDTO.setResultCode(payInfoDTO.getResultCode()); balancePayReturnDTO.setPayInfoSerialNumber(payInfoDTO.getSerialNumber());
balancePayReturnDTO.setTotalFeePaid(payInfoDTO.getTotalFeePaid()); balancePayReturnDTO.setOrderSerialNumber(payInfoDTO.getOrderSerialNumber());
balancePayReturnDTO.setEnterpriseId(payInfoDTO.getEnterpriseId()); balancePayReturnDTO.setResultCode(payInfoDTO.getResultCode());
return ServiceResponse.success(balancePayReturnDTO); balancePayReturnDTO.setTotalFeePaid(payInfoDTO.getTotalFeePaid());
} else { balancePayReturnDTO.setEnterpriseId(payInfoDTO.getEnterpriseId());
return ServiceResponse.failure(confirmPayResponse.getCode(), confirmPayResponse.getMessage()); return ServiceResponse.success(balancePayReturnDTO);
} else {
return ServiceResponse.failure(confirmPayResponse.getCode(), confirmPayResponse.getMessage());
}
} catch (Exception e) {
logger.info("余额支付回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BALANCE_LOCK);
} }
} }
...@@ -150,60 +159,70 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ ...@@ -150,60 +159,70 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ
@Override @Override
public ServiceResponse<RefundReturnDTO> refund(RefundDTO refundDTO) { public ServiceResponse<RefundReturnDTO> refund(RefundDTO refundDTO) {
ServiceResponse paramResult = ValidUtil.allCheckValidate(refundDTO, RefundDTO.RefundValid.class); try {
if (!paramResult.isSuccess()) { RedisUtil.lock(Constants.REFUND_LOCK + refundDTO.getEnterpriseId(), 5L);
return paramResult;
} ServiceResponse paramResult = ValidUtil.allCheckValidate(refundDTO, RefundDTO.RefundValid.class);
ServiceResponse<BillingPayInfoDTO> payService = this.billingPayInfoApiService.getPayInfo(refundDTO.getEnterpriseId(), refundDTO.getOrderSerialNumber(), refundDTO.getRequestCode()); if (!paramResult.isSuccess()) {
if (!payService.isSuccess()) { return paramResult;
return ServiceResponse.failure(payService.getCode(), payService.getMessage()); }
} ServiceResponse<BillingPayInfoDTO> payService =
BillingPayInfoDTO payInfo = payService.getResult(); this.billingPayInfoApiService.getPayInfo(refundDTO.getEnterpriseId(), refundDTO.getOrderSerialNumber(), refundDTO.getRequestCode());
if (!BillingPayResultEnum.SUCCESS.getCode().equals(payInfo.getResultCode())) { if (!payService.isSuccess()) {
return ServiceResponse.failure(ErrorCode.NOTEXISTS.getCode(), "退款失败, 订单号不存在"); return ServiceResponse.failure(payService.getCode(), payService.getMessage());
} }
// 退款单号是否重复 BillingPayInfoDTO payInfo = payService.getResult();
TabBillingRefund refund = billingRefundService.getRefund(refundDTO.getEnterpriseId(), refundDTO.getRefundSerialNumber(), refundDTO.getRequestCode()); if (!BillingPayResultEnum.SUCCESS.getCode().equals(payInfo.getResultCode())) {
if (refund != null) { return ServiceResponse.failure(ErrorCode.NOTEXISTS.getCode(), "退款失败, 订单号不存在");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "退款失败, 退款单号重复"); }
} // 退款单号是否重复
// 每笔退款金额(部分)超出订单总金额 TabBillingRefund refund = billingRefundService.getRefund(refundDTO.getEnterpriseId(), refundDTO.getRefundSerialNumber(), refundDTO.getRequestCode());
Double refundFee = refundDTO.getRefundFee(); if (refund != null) {
if (refundFee > payInfo.getTotalFeePaid()) { return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "退款失败, 退款单号重复");
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "退款失败, 退款金额超出总金额"); }
} // 每笔退款金额(部分)超出订单总金额
// 每笔退款金额累计超出订单总金额 Double refundFee = refundDTO.getRefundFee();
Double oldTotalFee = billingRefundService.getTotalRefundFee(refundDTO.getEnterpriseId(), refundDTO.getOrderSerialNumber(), refundDTO.getRequestCode()); if (refundFee > payInfo.getTotalFeePaid()) {
if (oldTotalFee == null) { return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "退款失败, 退款金额超出总金额");
oldTotalFee = 0d; }
} // 每笔退款金额累计超出订单总金额
double olderFee = new BigDecimal(Double.toString(refundFee)).add(new BigDecimal(Double.toString(oldTotalFee))).doubleValue(); Double oldTotalFee = billingRefundService.getTotalRefundFee(refundDTO.getEnterpriseId(), refundDTO.getOrderSerialNumber(), refundDTO.getRequestCode());
if (olderFee > refundFee) { if (oldTotalFee == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "退款失败, 退款金额超出总金额"); oldTotalFee = 0d;
} }
// 保存退款记录 double olderFee = new BigDecimal(Double.toString(refundFee)).add(new BigDecimal(Double.toString(oldTotalFee))).doubleValue();
Date date = new Date(); if (olderFee > refundFee) {
String serialNumber = CreateRandomUtils.createSerialNumber(); return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "退款失败, 退款金额超出总金额");
refundDTO.setRefundPayNumber(serialNumber); }
refundDTO.setTimeEnd(date); // 保存退款记录
Integer line = billingRefundService.save(refundDTO); Date date = new Date();
if (line == 0) { String serialNumber = CreateRandomUtils.createSerialNumber();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); refundDTO.setRefundPayNumber(serialNumber);
logger.info("保存退款记录失败:{}", JSON.toJSONString(refundDTO)); refundDTO.setTimeEnd(date);
return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), "保存退款记录失败"); Integer line = billingRefundService.save(refundDTO);
} if (line == 0) {
// 退款 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
int i = billingAccountService.updateAccountAfterRechargeOrRefund(olderFee, refundDTO.getEnterpriseId()); logger.info("保存退款记录失败:{}", JSON.toJSONString(refundDTO));
if (i == 0) { return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), "保存退款记录失败");
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); }
logger.info("退款失败:{}", JSON.toJSONString(refundDTO)); // 退款
return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), "退款失败"); int i = billingAccountService.updateAccountAfterRechargeOrRefund(olderFee, refundDTO.getEnterpriseId());
if (i == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
logger.info("退款失败:{}", JSON.toJSONString(refundDTO));
return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), "退款失败");
}
// 返回应用市场
RefundReturnDTO refundReturnDTO = EntityUtil.changeEntityByOrika(RefundReturnDTO.class, refundDTO);
refundReturnDTO.setRefundPaySerialNumber(serialNumber);
refundReturnDTO.setDeductionTime(date);
return ServiceResponse.success(refundReturnDTO);
} catch (Exception e) {
logger.info("银行转账回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.REFUND_LOCK);
} }
// 返回应用市场
RefundReturnDTO refundReturnDTO = EntityUtil.changeEntityByOrika(RefundReturnDTO.class, refundDTO);
refundReturnDTO.setRefundPaySerialNumber(serialNumber);
refundReturnDTO.setDeductionTime(date);
return ServiceResponse.success(refundReturnDTO);
} }
@Override @Override
......
...@@ -59,7 +59,6 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService { ...@@ -59,7 +59,6 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
@Autowired @Autowired
public BillingPayInfoApiServiceImpl(Map<String, PayStrategy> strategyMap) { public BillingPayInfoApiServiceImpl(Map<String, PayStrategy> strategyMap) {
this.strategyMap.clear();
this.strategyMap.putAll(strategyMap); this.strategyMap.putAll(strategyMap);
} }
...@@ -126,7 +125,10 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService { ...@@ -126,7 +125,10 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
approvalCallBackDTO.setPrepayId(resData.getPrepay_id()); approvalCallBackDTO.setPrepayId(resData.getPrepay_id());
approvalCallBackDTO.setResultCode(StringUtils.equalsIgnoreCase(resData.getResult_code(), "SUCCESS") ? 1 : 0); approvalCallBackDTO.setResultCode(StringUtils.equalsIgnoreCase(resData.getResult_code(), "SUCCESS") ? 1 : 0);
approvalCallBackDTO.setTotalFeePaid(new BigDecimal(resData.getTotal_fee()).divide(new BigDecimal("100"), 5, RoundingMode.HALF_UP).doubleValue()); approvalCallBackDTO.setTotalFeePaid(new BigDecimal(resData.getTotal_fee()).divide(new BigDecimal("100"), 5, RoundingMode.HALF_UP).doubleValue());
approvalCallBackDTO.setTotalFee(approvalCallBackDTO.getTotalFeePaid());
approvalCallBackDTO.setOnlineSerialNumber(resData.getTransaction_id()); approvalCallBackDTO.setOnlineSerialNumber(resData.getTransaction_id());
approvalCallBackDTO.setAuditStatus(BillingAuditStatusEnum.PASS.getCode());
approvalCallBackDTO.setPayType(PayTypeEnum.WE_CHAT_PAY.getCode());
return strategyMap.get(PayTypeEnum.WE_CHAT_PAY.getCode() + "").callBack(approvalCallBackDTO); return strategyMap.get(PayTypeEnum.WE_CHAT_PAY.getCode() + "").callBack(approvalCallBackDTO);
} }
...@@ -145,6 +147,7 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService { ...@@ -145,6 +147,7 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
// 银行回调取计划金额 // 银行回调取计划金额
approvalCallBackDTO.setTotalFee(jsonObject.getDouble("plannedAmount")); approvalCallBackDTO.setTotalFee(jsonObject.getDouble("plannedAmount"));
approvalCallBackDTO.setTotalFeePaid(jsonObject.getDouble("accountAmount")); approvalCallBackDTO.setTotalFeePaid(jsonObject.getDouble("accountAmount"));
approvalCallBackDTO.setPayType(PayTypeEnum.OFFLINE_PAY.getCode());
ServiceResponse<Void> validParam = ValidParamsUtils.allCheckValidate(approvalCallBackDTO, ApprovalCallBackDTO.ApprovalValid.class); ServiceResponse<Void> validParam = ValidParamsUtils.allCheckValidate(approvalCallBackDTO, ApprovalCallBackDTO.ApprovalValid.class);
if (!validParam.isSuccess()) { if (!validParam.isSuccess()) {
return validParam; return validParam;
......
...@@ -147,11 +147,11 @@ public class InternationalSmsRecordApiServiceImpl implements InternationalSmsRec ...@@ -147,11 +147,11 @@ public class InternationalSmsRecordApiServiceImpl implements InternationalSmsRec
*/ */
private void setUserName(InternationalSmsRecordDTO smsRecordDTO) { private void setUserName(InternationalSmsRecordDTO smsRecordDTO) {
if (smsRecordDTO.getUserId() != null) { if (smsRecordDTO.getUserId() != null) {
ServiceResponse<UserDTO> userResp = userApiService.getUserById(smsRecordDTO.getUserId()); ServiceResponse<UserDTO> userResp = userApiService.getUserInfoById(smsRecordDTO.getUserId());
if (userResp.isSuccess()) { if (userResp.isSuccess()) {
UserDTO userDTO = userResp.getResult(); UserDTO userDTO = userResp.getResult();
if (userDTO != null) { if (userDTO != null) {
smsRecordDTO.setUserName(smsRecordDTO.getUserName()); smsRecordDTO.setUserName(userDTO.getUserName());
} }
} else { } else {
logger.info("userId:{}, UserApiService.getUserById 调用失败:{}", smsRecordDTO.getUserId(), userResp.getMessage()); logger.info("userId:{}, UserApiService.getUserById 调用失败:{}", smsRecordDTO.getUserId(), userResp.getMessage());
......
...@@ -111,10 +111,28 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService { ...@@ -111,10 +111,28 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
logger.info("短信验证不通过:{}", paramResult.getMessage()); logger.info("短信验证不通过:{}", paramResult.getMessage());
return paramResult; return paramResult;
} }
// 判断是扣套餐包还是扣余额
RAtomicLong smsCount = billingEnterpriseSmsPackageService.getTotalSmsInPackageByEnterpriseId(smsRecordDTO.getEnterpriseId());
smsRecordDTO.setCacheStatus(0);
smsRecordDTO.setDatabaseStatus(0);
// 缓存扣费 0套餐包 4余额
Integer fee = accountStandardService.queryUnitFee(smsRecordDTO.getEnterpriseId(), AccountStandardEnum.SMS.getCode());
int deductType = deduct(smsCount, smsRecordDTO.getEnterpriseId(), fee);
smsRecordDTO.setPayType(deductType);
smsRecordDTO.setFee((double)fee/1000);
Long smsRecordId = billingSmsRecordService.saveSmsRecord(smsRecordDTO);
smsRecordDTO.setSmsRecordId(smsRecordId);
billingSmsRecordService.updateCacheStatus(smsRecordDTO.getSmsRecordId());
smsRecordDTO.setCacheStatus(1);
// 队列
GicMQClient client = GICMQClientUtil.getClientInstance(); GicMQClient client = GICMQClientUtil.getClientInstance();
try { try {
String json = JSON.toJSONString(smsRecordDTO); client.sendMessage("smsDbMq", JSON.toJSONString(smsRecordDTO));
client.sendMessage("smsMq", json);
} catch (Exception e) { } catch (Exception e) {
logger.warn("调用mq失败", e); logger.warn("调用mq失败", e);
} }
...@@ -126,7 +144,7 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService { ...@@ -126,7 +144,7 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
@Override @Override
public ServiceResponse<Void> run(String arg) { public ServiceResponse<Void> run(String arg) {
// 缓存中计费 /*// 缓存中计费
GicMQClient client = GICMQClientUtil.getClientInstance(); GicMQClient client = GICMQClientUtil.getClientInstance();
try { try {
logger.info("国内短信缓存扣费:{}", arg); logger.info("国内短信缓存扣费:{}", arg);
...@@ -154,17 +172,21 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService { ...@@ -154,17 +172,21 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
} catch (Exception e) { } catch (Exception e) {
logger.warn("调用mq失败", e); logger.warn("调用mq失败", e);
} }
*/
return ServiceResponse.success(); return ServiceResponse.success();
} }
private int deduct(RAtomicLong rSmsCount, Integer enterpriseId, Integer fee) { private int deduct(RAtomicLong rSmsCount, Integer enterpriseId, Integer fee) {
long smsCount = rSmsCount.get(); long smsCount = rSmsCount.get();
if (smsCount > 0) { if (smsCount > 0) {
// 套餐包计费 /*
套餐包计费
这里不能改成 decrementAndGet自减, 否则会出现减到0的情况
*/
boolean smsCountDeduct = rSmsCount.compareAndSet(smsCount, smsCount - 1); boolean smsCountDeduct = rSmsCount.compareAndSet(smsCount, smsCount - 1);
// rSmsCount.decrementAndGet();
if (!smsCountDeduct) { if (!smsCountDeduct) {
// 设置失败 重新计算 // 设置失败 重新计算
// todo 这里不知道要不要加个延时之类的
return deduct(rSmsCount, enterpriseId, fee); return deduct(rSmsCount, enterpriseId, fee);
} else { } else {
return 0; return 0;
......
...@@ -36,6 +36,7 @@ public class AliPayStrategy implements PayStrategy { ...@@ -36,6 +36,7 @@ public class AliPayStrategy implements PayStrategy {
@Override @Override
public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) { public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) {
return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getMsg()); return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getMsg());
} }
} }
...@@ -10,18 +10,17 @@ import com.gic.commons.util.GlobalInfo; ...@@ -10,18 +10,17 @@ import com.gic.commons.util.GlobalInfo;
import com.gic.enterprise.constant.*; import com.gic.enterprise.constant.*;
import com.gic.enterprise.dto.ApprovalCallBackDTO; import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.BillingPayInfoDTO; import com.gic.enterprise.dto.BillingPayInfoDTO;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.dto.OutPayDTO; import com.gic.enterprise.dto.OutPayDTO;
import com.gic.enterprise.entity.TabBillingOrder;
import com.gic.enterprise.entity.TabBillingPayInfo; import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.entity.TabBillingRechargeRecord;
import com.gic.enterprise.entity.TabEnterprise; import com.gic.enterprise.entity.TabEnterprise;
import com.gic.enterprise.error.ErrorCode; import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.service.*; import com.gic.enterprise.service.*;
import com.gic.enterprise.service.outer.impl.payComplete.PayCompleteHandler;
import com.gic.enterprise.utils.CreateRandomUtils; import com.gic.enterprise.utils.CreateRandomUtils;
import com.gic.finance.dto.TransferAccountsApprovalDTO; import com.gic.finance.dto.TransferAccountsApprovalDTO;
import com.gic.finance.service.TransferAccountsApprovalApiService; import com.gic.finance.service.TransferAccountsApprovalApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService; import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -31,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -31,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.Date; import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* *
...@@ -58,78 +59,98 @@ public class OfflineStrategy implements PayStrategy { ...@@ -58,78 +59,98 @@ public class OfflineStrategy implements PayStrategy {
@Autowired @Autowired
private EnterpriseApiService enterpriseApiService; private EnterpriseApiService enterpriseApiService;
private Map<String, PayCompleteHandler> payCompleteHandlerMap = new ConcurrentHashMap<>();
@Autowired
public OfflineStrategy(Map<String, PayCompleteHandler> payCompleteHandlerMap) {
this.payCompleteHandlerMap.putAll(payCompleteHandlerMap);
}
@Override @Override
@Transactional(rollbackFor = Exception.class)
public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) {
try {
// 判断该商户下是否有相同的订单号 RedisUtil.lock(Constants.PAY_LOCK + outPayDTO.getEnterpriseId(), 5L);
TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), PayTypeEnum.OFFLINE_PAY.getCode()); // 判断该商户下是否有相同的订单号
if (payInfo != null) { TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), PayTypeEnum.OFFLINE_PAY.getCode());
return ServiceResponse.success(EntityUtil.changeEntityByJSON(BillingPayInfoDTO.class, payInfo)); if (payInfo != null) {
} return ServiceResponse.success(EntityUtil.changeEntityByJSON(BillingPayInfoDTO.class, payInfo));
BillingPayInfoDTO payInfoDTO = new BillingPayInfoDTO(); }
payInfoDTO.setEnterpriseId(outPayDTO.getEnterpriseId()); BillingPayInfoDTO payInfoDTO = new BillingPayInfoDTO();
payInfoDTO.setSerialNumber(CreateRandomUtils.createSerialNumber()); payInfoDTO.setEnterpriseId(outPayDTO.getEnterpriseId());
payInfoDTO.setPayType(PayTypeEnum.OFFLINE_PAY.getCode()); payInfoDTO.setSerialNumber(CreateRandomUtils.createSerialNumber());
payInfoDTO.setTotalFeePaid(outPayDTO.getTotalFeePaid()); payInfoDTO.setPayType(PayTypeEnum.OFFLINE_PAY.getCode());
payInfoDTO.setTimeStart(outPayDTO.getTimeStart()); payInfoDTO.setTotalFeePaid(outPayDTO.getTotalFeePaid());
payInfoDTO.setResultCode(BillingPayResultEnum.WAIT.getCode()); payInfoDTO.setTimeStart(outPayDTO.getTimeStart());
payInfoDTO.setInvoiceStatus(GlobalInfo.DATA_STATUS_DELETE); payInfoDTO.setResultCode(BillingPayResultEnum.WAIT.getCode());
payInfoDTO.setDeleteFlag(0); payInfoDTO.setInvoiceStatus(GlobalInfo.DATA_STATUS_DELETE);
payInfoDTO.setCreateTime(new Date()); payInfoDTO.setDeleteFlag(0);
payInfoDTO.setBuyType(outPayDTO.getBuyType()); payInfoDTO.setCreateTime(new Date());
payInfoDTO.setOrderSerialNumber(outPayDTO.getOrderSerialNumber()); payInfoDTO.setBuyType(outPayDTO.getBuyType());
payInfoDTO.setRequestCode(outPayDTO.getRequestCode()); payInfoDTO.setOrderSerialNumber(outPayDTO.getOrderSerialNumber());
payInfoDTO.setProductDescription(outPayDTO.getProductDescription()); payInfoDTO.setRequestCode(outPayDTO.getRequestCode());
Integer line = billingPayInfoService.savePayInfo(payInfoDTO); payInfoDTO.setProductDescription(outPayDTO.getProductDescription());
if (line == 0) { Integer line = billingPayInfoService.savePayInfo(payInfoDTO);
logger.info("线下支付交易保存失败, {}", JSON.toJSONString(payInfoDTO)); if (line == 0) {
// 回滚 logger.info("线下支付交易保存失败, {}", JSON.toJSONString(payInfoDTO));
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 回滚
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "线下支付交易保存失败"); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "线下支付交易保存失败");
}
return ServiceResponse.success(payInfoDTO);
} catch (Exception e) {
logger.info("预支付错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_LOCK);
} }
return ServiceResponse.success(payInfoDTO);
} }
@Override @Override
public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) {
try {
TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getEnterpriseId(), outPayDTO.getRequestCode() ,outPayDTO.getOrderSerialNumber()); RedisUtil.lock(Constants.PAY_LOCK + outPayDTO.getEnterpriseId(), 5L);
BillingPayInfoDTO billingPayInfoDTO = new BillingPayInfoDTO(); TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getEnterpriseId(), outPayDTO.getRequestCode(), outPayDTO.getOrderSerialNumber());
BillingPayInfoDTO billingPayInfoDTO = new BillingPayInfoDTO();
if (payInfo == null) {
String serialNumber = CreateRandomUtils.createSerialNumber(); if (payInfo == null) {
billingPayInfoDTO.setEnterpriseId(outPayDTO.getEnterpriseId()); String serialNumber = CreateRandomUtils.createSerialNumber();
billingPayInfoDTO.setSerialNumber(serialNumber); billingPayInfoDTO.setEnterpriseId(outPayDTO.getEnterpriseId());
billingPayInfoDTO.setOrderSerialNumber(outPayDTO.getOrderSerialNumber()); billingPayInfoDTO.setSerialNumber(serialNumber);
billingPayInfoDTO.setInvoiceStatus(GlobalInfo.DATA_STATUS_DELETE); billingPayInfoDTO.setOrderSerialNumber(outPayDTO.getOrderSerialNumber());
billingPayInfoDTO.setPayType(PayTypeEnum.OFFLINE_PAY.getCode()); billingPayInfoDTO.setInvoiceStatus(GlobalInfo.DATA_STATUS_DELETE);
billingPayInfoDTO.setTimeStart(DateUtil.formatString(new Date(), DateUtil.FORMAT_DATETIME_14)); billingPayInfoDTO.setPayType(PayTypeEnum.OFFLINE_PAY.getCode());
billingPayInfoDTO.setDeleteFlag(0); billingPayInfoDTO.setTimeStart(DateUtil.formatString(new Date(), DateUtil.FORMAT_DATETIME_14));
billingPayInfoDTO.setCreateTime(new Date()); billingPayInfoDTO.setDeleteFlag(0);
billingPayInfoDTO.setBuyType(outPayDTO.getBuyType()); billingPayInfoDTO.setCreateTime(new Date());
billingPayInfoDTO.setAuthCode(outPayDTO.getAuthCode()); billingPayInfoDTO.setBuyType(outPayDTO.getBuyType());
Integer payInfoId = billingPayInfoService.savePayInfo(billingPayInfoDTO); billingPayInfoDTO.setAuthCode(outPayDTO.getAuthCode());
billingPayInfoDTO.setPayInfoId(payInfoId); Integer payInfoId = billingPayInfoService.savePayInfo(billingPayInfoDTO);
} else { billingPayInfoDTO.setPayInfoId(payInfoId);
billingPayInfoDTO = EntityUtil.changeEntityByJSON(BillingPayInfoDTO.class, payInfo); } else {
// 更新交易信息 billingPayInfoDTO = EntityUtil.changeEntityByJSON(BillingPayInfoDTO.class, payInfo);
ApprovalCallBackDTO dto = new ApprovalCallBackDTO(); // 更新交易信息
dto.setBuyType(payInfo.getBuyType()); ApprovalCallBackDTO dto = new ApprovalCallBackDTO();
dto.setEnterpriseId(payInfo.getEnterpriseId()); dto.setBuyType(payInfo.getBuyType());
dto.setPaySerialNumber(payInfo.getSerialNumber()); dto.setEnterpriseId(payInfo.getEnterpriseId());
dto.setResultCode(BillingPayResultEnum.SUCCESS.getCode()); dto.setPaySerialNumber(payInfo.getSerialNumber());
Integer line = billingPayInfoService.updatePayInfoBySerialNumber(dto); dto.setResultCode(BillingPayResultEnum.SUCCESS.getCode());
if (line == 0) { Integer line = billingPayInfoService.updatePayInfoBySerialNumber(dto);
logger.info("更新支付信息失败, {}", JSON.toJSONString(dto)); if (line == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); logger.info("更新支付信息失败, {}", JSON.toJSONString(dto));
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "更新支付信息失败"); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "更新支付信息失败");
}
} }
billingPayInfoService.delOtherPayInfoExceptId(billingPayInfoDTO.getPayInfoId(), billingPayInfoDTO.getEnterpriseId(), billingPayInfoDTO.getOrderSerialNumber());
// 发起审批
initiateApproval(outPayDTO);
return ServiceResponse.success(billingPayInfoDTO);
} catch (Exception e) {
logger.info("确认支付错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_LOCK);
} }
billingPayInfoService.delOtherPayInfoExceptId(billingPayInfoDTO.getPayInfoId(), billingPayInfoDTO.getEnterpriseId(), billingPayInfoDTO.getOrderSerialNumber());
// 发起审批
initiateApproval(outPayDTO);
return ServiceResponse.success(billingPayInfoDTO);
} }
@Override @Override
...@@ -141,76 +162,30 @@ public class OfflineStrategy implements PayStrategy { ...@@ -141,76 +162,30 @@ public class OfflineStrategy implements PayStrategy {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) { public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) {
logger.info("银行线下支付回调结果:{}", JSON.toJSONString(resData));
String orderSerialNumber = resData.getOrderSerialNumber();
TabBillingPayInfo billingPayInfo = billingPayInfoService.getByOrderSerialNumber(orderSerialNumber, PayTypeEnum.OFFLINE_PAY.getCode());
resData.setPaySerialNumber(billingPayInfo.getSerialNumber());
if (StringUtils.isBlank(billingPayInfo.getTimeEnd())) {
// 写入支付结果
Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData);
switch (resData.getBuyType()) {
case 1:
// 商户余额充值
billingRechargeRecordService.updateBySerialNumber(billingPayInfo.getEnterpriseId(), resData.getOrderSerialNumber(), resData.getTotalFee(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd(), null);
sendRechargeSuccessSms(resData, billingPayInfo.getEnterpriseId());
sendApprovalSms(resData, "GICJFZX007");
break;
case 2:
// 短信套餐包购买
this.billingOrderService.updateBySerialNumber(resData.getOrderSerialNumber(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd());
sendOrderApprovalSms(resData, "GICJFZX008");
break;
default:
break;
}
}else {
logger.info("银行转账重复回调 orderSerialNumber:{}", resData.getOrderSerialNumber());
}
return ServiceResponse.success();
}
private void sendRechargeSuccessSms(ApprovalCallBackDTO resData, Integer enterpriseId) {
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
sendSms(resData, userDTO, "GICJFZX005");
}
private void sendApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = rechargeRecord.getInitiator();
UserDTO userDTO = userApiService.getUserById(initiator).getResult();
sendSms(resData, userDTO, code);
}
private void sendOrderApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingOrder order = billingOrderService.getOrderBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = order.getInitiatorUser();
if (initiator != null) {
UserDTO userDTO = userApiService.getUserById(initiator).getResult();
sendSms(resData, userDTO, code);
}
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try { try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) { RedisUtil.lock(Constants.PAY_BACK_LOCK + resData.getEnterpriseId(), 5L);
userDTO.setPhoneAreaCode("+86"); logger.info("银行线下支付回调结果:{}", JSON.toJSONString(resData));
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult(); String orderSerialNumber = resData.getOrderSerialNumber();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"}; TabBillingPayInfo billingPayInfo = billingPayInfoService.getByOrderSerialNumber(orderSerialNumber, PayTypeEnum.OFFLINE_PAY.getCode());
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code, resData.setPaySerialNumber(billingPayInfo.getSerialNumber());
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr); // 防止重复推信息
if (!smsSendResult.isSuccess()) { if (StringUtils.isNotBlank(billingPayInfo.getTimeEnd())) {
logger.warn(smsSendResult.getMessage()); logger.info("银行转账重复回调 orderSerialNumber:{}", resData.getOrderSerialNumber());
return ServiceResponse.success();
} }
// 写入支付结果
Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData);
payCompleteHandlerMap.get(BuyTypeEnum.getTypeByCode(resData.getBuyType())).payComplete(resData, billingPayInfo);
return ServiceResponse.success();
} catch (Exception e) { } catch (Exception e) {
logger.info("发送短信失败", e); logger.info("银行转账回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BACK_LOCK);
} }
} }
private void initiateApproval(OutPayDTO outPayDTO) { private void initiateApproval(OutPayDTO outPayDTO) {
TransferAccountsApprovalDTO approvalDTO = new TransferAccountsApprovalDTO(); TransferAccountsApprovalDTO approvalDTO = new TransferAccountsApprovalDTO();
approvalDTO.setOrderNumber(outPayDTO.getOrderSerialNumber()); approvalDTO.setOrderNumber(outPayDTO.getOrderSerialNumber());
......
...@@ -3,24 +3,26 @@ package com.gic.enterprise.service.outer.impl.pay; ...@@ -3,24 +3,26 @@ package com.gic.enterprise.service.outer.impl.pay;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO; import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.commons.util.DateUtil; import com.gic.commons.util.DateUtil;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GlobalInfo; import com.gic.commons.util.GlobalInfo;
import com.gic.enterprise.constant.BillingAuditStatusEnum; import com.gic.enterprise.constant.BuyTypeEnum;
import com.gic.enterprise.constant.Constants;
import com.gic.enterprise.constant.PayTypeEnum; import com.gic.enterprise.constant.PayTypeEnum;
import com.gic.enterprise.dto.ApprovalCallBackDTO; import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.BillingPayInfoDTO; import com.gic.enterprise.dto.BillingPayInfoDTO;
import com.gic.enterprise.dto.EnterpriseDTO; import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.dto.OutPayDTO; import com.gic.enterprise.dto.OutPayDTO;
import com.gic.enterprise.entity.TabBillingPayInfo; import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.entity.TabBillingRechargeRecord;
import com.gic.enterprise.error.ErrorCode; import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.service.*; import com.gic.enterprise.service.BillingPayInfoService;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.enterprise.service.outer.impl.payComplete.PayCompleteHandler;
import com.gic.enterprise.utils.CreateRandomUtils; import com.gic.enterprise.utils.CreateRandomUtils;
import com.gic.log.api.dto.SystemSetLogDTO; import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService; import com.gic.log.api.service.LogApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService; import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import com.gic.redis.data.util.RedisUtil;
import com.gic.thirdparty.api.dto.ScanPayReqDataDTO; import com.gic.thirdparty.api.dto.ScanPayReqDataDTO;
import com.gic.thirdparty.api.service.Pay4WXService; import com.gic.thirdparty.api.service.Pay4WXService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -31,6 +33,8 @@ import org.springframework.stereotype.Component; ...@@ -31,6 +33,8 @@ import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* *
...@@ -47,44 +51,50 @@ public class WxPayStrategy implements PayStrategy { ...@@ -47,44 +51,50 @@ public class WxPayStrategy implements PayStrategy {
@Autowired @Autowired
private BillingPayInfoService billingPayInfoService; private BillingPayInfoService billingPayInfoService;
@Autowired @Autowired
private BillingRechargeRecordService billingRechargeRecordService;
@Autowired
private BillingOrderService billingOrderService;
@Autowired
private PushMessageApiService pushMessageApiService;
@Autowired
private UserApiService userApiService;
@Autowired
private EnterpriseApiService enterpriseApiService; private EnterpriseApiService enterpriseApiService;
@Autowired @Autowired
SmsSendApiService smsSendApiService; SmsSendApiService smsSendApiService;
@Autowired @Autowired
private LogApiService logApiService; private LogApiService logApiService;
private Map<String, PayCompleteHandler> payCompleteHandlerMap = new ConcurrentHashMap<>();
@Autowired
public WxPayStrategy(Map<String, PayCompleteHandler> payCompleteHandlerMap) {
this.payCompleteHandlerMap.putAll(payCompleteHandlerMap);
}
@Override @Override
public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) {
if (StringUtils.isNotBlank(outPayDTO.getOrderSerialNumber())) { try {
TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), outPayDTO.getPayType()); RedisUtil.lock(Constants.PAY_BACK_LOCK + outPayDTO.getEnterpriseId(), 5L);
if (payInfo != null) { if (StringUtils.isNotBlank(outPayDTO.getOrderSerialNumber())) {
BillingPayInfoDTO payInfoDTO = EntityUtil.changeEntityByOrika(BillingPayInfoDTO.class, payInfo); TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), outPayDTO.getPayType());
return ServiceResponse.success(payInfoDTO); if (payInfo != null) {
BillingPayInfoDTO payInfoDTO = EntityUtil.changeEntityByOrika(BillingPayInfoDTO.class, payInfo);
return ServiceResponse.success(payInfoDTO);
}
} }
}
String serialNumber = CreateRandomUtils.createSerialNumber(); String serialNumber = CreateRandomUtils.createSerialNumber();
BillingPayInfoDTO billingPayInfoDTO = saveWxPrePay(outPayDTO.getEnterpriseId(), serialNumber, outPayDTO.getTotalFee(), outPayDTO.getBuyType(), outPayDTO.getOrderSerialNumber()); BillingPayInfoDTO billingPayInfoDTO = saveWxPrePay(outPayDTO.getEnterpriseId(), serialNumber, outPayDTO.getTotalFee(), outPayDTO.getBuyType(), outPayDTO.getOrderSerialNumber());
// 微信支付 // 微信支付
if (billingPayInfoDTO != null) { if (billingPayInfoDTO != null) {
return ServiceResponse.success(billingPayInfoDTO); return ServiceResponse.success(billingPayInfoDTO);
} else { } else {
return ServiceResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), "调用微信支付失败"); return ServiceResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), "调用微信支付失败");
}
} catch (Exception e) {
logger.info("预支付错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BACK_LOCK);
} }
} }
@Override @Override
public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) {
logger.info("线下转账没有该方法 confirmPay"); logger.info("微信没有该方法 confirmPay");
return ServiceResponse.success(); return ServiceResponse.success();
} }
...@@ -115,40 +125,29 @@ public class WxPayStrategy implements PayStrategy { ...@@ -115,40 +125,29 @@ public class WxPayStrategy implements PayStrategy {
@Override @Override
public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) { public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) {
logger.info("微信支付回调结果:{}", JSON.toJSONString(resData)); try {
// 写入支付结果 RedisUtil.lock(Constants.PAY_BACK_LOCK + resData.getEnterpriseId(), 5L);
logger.info("微信支付回调结果:{}", JSON.toJSONString(resData));
TabBillingPayInfo billingPayInfo = billingPayInfoService.getBySerialNumber(resData.getPaySerialNumber()); // 写入支付结果
if (StringUtils.isBlank(billingPayInfo.getTimeEnd())) {
Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData); TabBillingPayInfo billingPayInfo = billingPayInfoService.getBySerialNumber(resData.getPaySerialNumber());
switch (billingPayInfo.getBuyType()) { // 防止微信重复推信息
case 1: if (StringUtils.isNotBlank(billingPayInfo.getTimeEnd())) {
// 商户余额充值 logger.info("微信重复回调 paySerialNumber:{}", resData.getPaySerialNumber());
billingRechargeRecordService.updateBySerialNumber(resData.getEnterpriseId(), billingPayInfo.getOrderSerialNumber(), resData.getTotalFeePaid(), resData.getTotalFeePaid(), BillingAuditStatusEnum.PASS.getCode(), resData.getTimeEnd(), resData.getOnlineSerialNumber()); return ServiceResponse.success();
this.pushMessageApiService.pushMessage(resData.getEnterpriseId(), "系统通知", "余额充值", "您的商户成功充值"+resData.getTotalFeePaid()+"元!感谢您的支持和使用!");
sendRechargeSuccessSms(resData, billingPayInfo.getEnterpriseId());
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(billingPayInfo.getOrderSerialNumber());
UserDTO userDTO = userApiService.getUserById(rechargeRecord.getInitiatorUser()).getResult();
createLog("充值", "账户余额", userDTO);
break;
case 2:
// 短信套餐包购买
this.billingOrderService.updateBySerialNumber(billingPayInfo.getOrderSerialNumber(), resData.getTotalFeePaid(), BillingAuditStatusEnum.PASS.getCode(), resData.getTimeEnd());
TabBillingRechargeRecord tabBillingRechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(billingPayInfo.getOrderSerialNumber());
UserDTO user = userApiService.getUserById(tabBillingRechargeRecord.getInitiatorUser()).getResult();
createLog("支付", "订单内容", user);
break;
default:
break;
} }
Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData);
resData.setOrderSerialNumber(billingPayInfo.getOrderSerialNumber());
payCompleteHandlerMap.get(BuyTypeEnum.getTypeByCode(resData.getBuyType())).payComplete(resData, billingPayInfo);
// 删除其他的支付方式 // 删除其他的支付方式
billingPayInfoService.delOtherPayInfoExceptId(billingPayInfo.getPayInfoId(), billingPayInfo.getEnterpriseId(), billingPayInfo.getOrderSerialNumber()); billingPayInfoService.delOtherPayInfoExceptId(billingPayInfo.getPayInfoId(), billingPayInfo.getEnterpriseId(), billingPayInfo.getOrderSerialNumber());
return ServiceResponse.success();
} else { } catch (Exception e) {
logger.info("微信重复回调 paySerialNumber:{}", resData.getPaySerialNumber()); logger.info("微信回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BACK_LOCK);
} }
return ServiceResponse.success();
} }
private BillingPayInfoDTO saveWxPrePay(Integer enterpriseId, String serialNumber, Double totalFee, Integer buyType, String orderSerialNumber) { private BillingPayInfoDTO saveWxPrePay(Integer enterpriseId, String serialNumber, Double totalFee, Integer buyType, String orderSerialNumber) {
...@@ -187,33 +186,6 @@ public class WxPayStrategy implements PayStrategy { ...@@ -187,33 +186,6 @@ public class WxPayStrategy implements PayStrategy {
} }
} }
private void sendRechargeSuccessSms(ApprovalCallBackDTO resData, Integer enterpriseId) {
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
sendSms(resData, userDTO, "GICJFZX005");
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("+86");
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code,
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
} catch (Exception e) {
logger.info("发送短信失败", e);
}
}
public void createLog(String content, String operationObject, UserDTO userDTO) {
doLog(content, operationObject, userDTO);
}
private void doLog(String content, String operationObject, UserDTO userDTO) { private void doLog(String content, String operationObject, UserDTO userDTO) {
final SystemSetLogDTO logDTO = new SystemSetLogDTO(); final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间 //操作时间
......
package com.gic.enterprise.service.outer.impl.payComplete;
import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.entity.TabBillingPayInfo;
/**
*
* @Description:
* @author zhiwj
* @date 2020-11-24 15:39
*/
public interface PayCompleteHandler {
/**
* 购买套餐包或余额充值以后的统一处理
* @Title: payComplete
* @Description:
* @author zhiwj
* @param callBackDTO
* @param billingPayInfo
* @return void
* @throws
*/
void payComplete(ApprovalCallBackDTO callBackDTO, TabBillingPayInfo billingPayInfo);
}
package com.gic.enterprise.service.outer.impl.payComplete;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.enterprise.constant.BillingAuditStatusEnum;
import com.gic.enterprise.constant.PayTypeEnum;
import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.entity.TabBillingRechargeRecord;
import com.gic.enterprise.service.BillingRechargeRecordService;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.enterprise.service.PushMessageApiService;
import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 余额充值支付完成
* @Description:
* @author zhiwj
* @date 2020-11-24 15:57
*/
@Component("BALANCE_RECHARGE")
public class RechargeHandler implements PayCompleteHandler {
private Logger logger = LogManager.getLogger(RechargeHandler.class);
@Autowired
private BillingRechargeRecordService billingRechargeRecordService;
@Autowired
private UserApiService userApiService;
@Autowired
private PushMessageApiService pushMessageApiService;
@Autowired
private EnterpriseApiService enterpriseApiService;
@Autowired
private SmsSendApiService smsSendApiService;
@Autowired
private LogApiService logApiService;
@Override
public void payComplete(ApprovalCallBackDTO resData, TabBillingPayInfo billingPayInfo) {
// 通知
pushMessageApiService.pushMessage(resData.getEnterpriseId(), "系统通知", "余额充值", "您的商户成功充值"+resData.getTotalFeePaid()+"元!感谢您的支持和使用!");
// 充值成功短信
sendRechargeSuccessSms(resData, billingPayInfo.getEnterpriseId());
// 日志
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(billingPayInfo.getOrderSerialNumber());
UserDTO userDTO = userApiService.getUserInfoById(rechargeRecord.getInitiatorUser()).getResult();
doLog("充值", "账户余额", userDTO);
// 审核成功短信
if (PayTypeEnum.OFFLINE_PAY.getCode() == resData.getPayType()) {
sendApprovalSms(resData, "GICJFZX008");
}
billingRechargeRecordService.updateBySerialNumber(resData.getEnterpriseId(), resData.getOrderSerialNumber(),
resData.getTotalFee(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd(), resData.getOnlineSerialNumber());
}
private void sendApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = rechargeRecord.getInitiator();
UserDTO userDTO = userApiService.getUserInfoById(initiator).getResult();
sendSms(resData, userDTO, code);
}
private void sendRechargeSuccessSms(ApprovalCallBackDTO resData, Integer enterpriseId) {
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
sendSms(resData, userDTO, "GICJFZX005");
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("+86");
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code,
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
} catch (Exception e) {
logger.info("发送短信失败", e);
}
}
private void doLog(String content, String operationObject, UserDTO userDTO) {
final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间
logDTO.setLogTime(new Date());
logDTO.setCreateTime(new Date());
//操作人
logDTO.setUserId(Long.valueOf(userDTO.getUserId()));
logDTO.setUserName(userDTO.getUserName());
//操作内容
logDTO.setContent(content);
//为了search查询,暂时用这个字段存
logDTO.setInterfaceName(content);
////操作对象
logDTO.setBusinessName(operationObject);
//操作模块
logDTO.setRelationId(45000L);
logDTO.setProject("企业-计费中心");
// }
//账号(手机号)
logDTO.setRemark1(userDTO.getPhoneAreaCode());
logDTO.setRemark2(userDTO.getPhoneNumber());
logDTO.setEnterpriseId(userDTO.getEnterpriseId().longValue());
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
logDTO.setEnterpriseName(enterpriseDTO.getEnterpriseName());
logApiService.saveSystemSetLog(logDTO);
}
}
package com.gic.enterprise.service.outer.impl.payComplete;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.enterprise.constant.BillingAuditStatusEnum;
import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.entity.TabBillingOrder;
import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.service.BillingOrderService;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
*
* @Description:
* @author zhiwj
* @date 2020-11-24 16:01
*/
@Component("BUY_SHORT_MESSAGE_PACKAGE")
public class SmsPackageHandler implements PayCompleteHandler {
private Logger logger = LogManager.getLogger(SmsPackageHandler.class);
@Autowired
private BillingOrderService billingOrderService;
@Autowired
private UserApiService userApiService;
@Autowired
private EnterpriseApiService enterpriseApiService;
@Autowired
private SmsSendApiService smsSendApiService;
@Autowired
private LogApiService logApiService;
@Override
public void payComplete(ApprovalCallBackDTO resData, TabBillingPayInfo billingPayInfo) {
billingOrderService.updateBySerialNumber(resData.getOrderSerialNumber(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd());
TabBillingOrder order = this.billingOrderService.getOrderBySerialNumber(resData.getOrderSerialNumber());
UserDTO user = userApiService.getUserInfoById(order.getInitiatorUser()).getResult();
doLog("支付", "订单内容", user);
sendOrderApprovalSms(resData, "GICJFZX006");
}
private void sendOrderApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingOrder order = billingOrderService.getOrderBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = order.getInitiatorUser();
if (initiator != null) {
UserDTO userDTO = userApiService.getUserInfoById(initiator).getResult();
sendSms(resData, userDTO, code);
}
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("+86");
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code,
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
} catch (Exception e) {
logger.info("发送短信失败", e);
}
}
private void doLog(String content, String operationObject, UserDTO userDTO) {
final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间
logDTO.setLogTime(new Date());
logDTO.setCreateTime(new Date());
//操作人
logDTO.setUserId(Long.valueOf(userDTO.getUserId()));
logDTO.setUserName(userDTO.getUserName());
//操作内容
logDTO.setContent(content);
//为了search查询,暂时用这个字段存
logDTO.setInterfaceName(content);
////操作对象
logDTO.setBusinessName(operationObject);
//操作模块
logDTO.setRelationId(45000L);
logDTO.setProject("企业-计费中心");
// }
//账号(手机号)
logDTO.setRemark1(userDTO.getPhoneAreaCode());
logDTO.setRemark2(userDTO.getPhoneNumber());
logDTO.setEnterpriseId(userDTO.getEnterpriseId().longValue());
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
logDTO.setEnterpriseName(enterpriseDTO.getEnterpriseName());
logApiService.saveSystemSetLog(logDTO);
}
}
...@@ -149,4 +149,5 @@ ...@@ -149,4 +149,5 @@
<dubbo:reference interface="com.gic.widget.screening.api.service.EsScreeningEnterpriseInitService" id="esScreeningEnterpriseInitService" timeout="6000" /> <dubbo:reference interface="com.gic.widget.screening.api.service.EsScreeningEnterpriseInitService" id="esScreeningEnterpriseInitService" timeout="6000" />
<dubbo:reference interface="com.gic.cloud.service.IndexDescApiService" id="indexDescApiService" timeout="6000" /> <dubbo:reference interface="com.gic.cloud.service.IndexDescApiService" id="indexDescApiService" timeout="6000" />
<dubbo:reference interface="com.gic.member.tag.api.service.SceneCrowdGroupApiService" id="sceneCrowdGroupApiService" timeout="6000" /> <dubbo:reference interface="com.gic.member.tag.api.service.SceneCrowdGroupApiService" id="sceneCrowdGroupApiService" timeout="6000" />
<dubbo:reference interface="com.gic.store.service.StoreWidgetApiService" id="storeWidgetApiService" timeout="6000" />
</beans> </beans>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment