Commit fa1f9fbe by zhiwj

Merge branch '1202' into 'developer'

1202

See merge request !55
parents ffb1a08d 16990677
......@@ -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 String message;
private String type;
private BuyTypeEnum(int code, String message) {
private BuyTypeEnum(int code, String message, String type) {
this.code = code;
this.message = message;
this.type = type;
}
public static String getMessageByCode(Integer code) {
......@@ -36,19 +38,27 @@ public enum BuyTypeEnum {
return "未知";
}
public int getCode() {
return code;
public static String getTypeByCode(Integer code) {
if (code == null) {
return "未知";
}
for (BuyTypeEnum typeEnum : values()) {
if (code.intValue() == typeEnum.getCode()) {
return typeEnum.getType();
}
}
return "未知";
}
public void setCode(int code) {
this.code = code;
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
public String getType() {
return type;
}
}
......@@ -93,4 +93,23 @@ public interface Constants {
String NATIONCODESIGN = "+86";
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 {
@NotNull(message = "审批时间不能为空, 格式为yyyyMMdd", groups = ApprovalValid.class)
private String timeEnd;
private String prepayId;
/**
* 支付类型
*/
private Integer payType;
private String onlineSerialNumber;
......@@ -138,6 +142,14 @@ public class ApprovalCallBackDTO implements Serializable {
this.totalFee = totalFee;
}
public Integer getPayType() {
return payType;
}
public void setPayType(Integer payType) {
this.payType = payType;
}
@Override
public String toString() {
return "ApprovalCallBackDTO{" +
......
......@@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
......@@ -51,6 +50,7 @@ public class BillingAccountServiceImpl implements BillingAccountService{
}
@Override
@Transactional(rollbackFor = Exception.class)
public int updateAccountAfterRechargeOrRefund(double totalFee, Integer enterpriseId) {
RedissonClient redisClient = RedisUtil.getRedisClient();
......@@ -58,7 +58,8 @@ public class BillingAccountServiceImpl implements BillingAccountService{
account.addAndGet(totalFee);
TabBillingAccount tabBillingAccount = tabBillingAccountMapper.selectByEnterpriseId(enterpriseId);
double newTotal = new BigDecimal(tabBillingAccount.getAccountBalance().toString()).add(new BigDecimal(totalFee + "")).doubleValue();
// double newTotal = new BigDecimal(tabBillingAccount.getAccountBalance().toString()).add(new BigDecimal(totalFee + "")).doubleValue();
double newTotal = tabBillingAccount.getAccountBalance() + totalFee;
logger.info("商户:{}, 充值/退款前余额:{}, 充值/退款金额:{}, 充值/退款后余额:{}", enterpriseId, tabBillingAccount.getAccountBalance(), totalFee, newTotal);
UserDTO user = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
todoItemService.finishTodoItem(enterpriseId, user.getUserId(), Constants.PRODUCT, config.getHost() + Constants.TODO_ITEM_ACCOUNT_BALANCE_URL);
......
......@@ -329,7 +329,7 @@ public class AuditLogApiServiceImpl implements AuditLogApiService {
if (AuditTypeEnum.HAOBAN.getCode().equals(auditLogDTO.getAuditType())) {
position = StringUtils.isBlank(auditLogDTO.getPosition()) ? "" : auditLogDTO.getPosition();
} else {
UserDTO userDTO = userApiService.getUserById(auditLogDTO.getApplyUserId()).getResult();
UserDTO userDTO = userApiService.getUserInfoById(auditLogDTO.getApplyUserId()).getResult();
LoginUserTypeEnum userTypeEnum = LoginUserTypeEnum.getByCode(userDTO.getLoginType());
position = userTypeEnum != null ? userTypeEnum.getMessage() : "";
}
......
......@@ -238,44 +238,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
@Override
public ServiceResponse<Integer> deductAccount(double totalFee, Integer enterpriseId) {
if (isNotInWhiteList(enterpriseId)) {
TabBillingAccount billingAccount = billingAccountService.getByEnterpriseId(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 {
// 在白名单中
if (isInWhiteList(enterpriseId)) {
int i = billingAccountService.deductAccount(totalFee, enterpriseId);
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) {
......@@ -300,14 +277,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
Integer enterpriseId = enterpriseDTO.getEnterpriseId();
if (isNotInWhiteList(enterpriseId)) {
TabBillingAccount account = this.billingAccountService.getByEnterpriseId(enterpriseId);
if (account.getAccountBalance() < ACCOUNT_NOTICE_LINE) {
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), String.valueOf(-account.getAccountBalance())};
ServiceResponse<UserDTO> userResult = userApiService.getUserByEnterpriseId(enterpriseId);
UserDTO userDTO = userResult.getResult();
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(account.getAccountBalance() < 0 ? "GICJFZX012" :"GICJFZX001",
enterpriseId, userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
LOGGER.warn(smsSendResult.getMessage());
if (account.getAccountBalance() < 0) {
String content = "您的达摩账户已欠费, 为避免您的业务受到影响,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
sendSms(enterpriseId, "GICJFZX012");
// 待办事项
sendTotoItem(enterpriseId, "您的达摩账户已欠费");
} 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);
}
}
}
......@@ -320,6 +304,11 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) == null;
}
private boolean isInWhiteList(Integer enterpriseId) {
// 判断商户在不在白名单中
return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) != null;
}
private void sendTotoItem(Integer enterpriseId, String content) {
TodoItemDTO todoItemDTO = new TodoItemDTO();
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
......
......@@ -59,7 +59,6 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
@Autowired
public BillingPayInfoApiServiceImpl(Map<String, PayStrategy> strategyMap) {
this.strategyMap.clear();
this.strategyMap.putAll(strategyMap);
}
......@@ -126,7 +125,10 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
approvalCallBackDTO.setPrepayId(resData.getPrepay_id());
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.setTotalFee(approvalCallBackDTO.getTotalFeePaid());
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);
}
......@@ -145,6 +147,7 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
// 银行回调取计划金额
approvalCallBackDTO.setTotalFee(jsonObject.getDouble("plannedAmount"));
approvalCallBackDTO.setTotalFeePaid(jsonObject.getDouble("accountAmount"));
approvalCallBackDTO.setPayType(PayTypeEnum.OFFLINE_PAY.getCode());
ServiceResponse<Void> validParam = ValidParamsUtils.allCheckValidate(approvalCallBackDTO, ApprovalCallBackDTO.ApprovalValid.class);
if (!validParam.isSuccess()) {
return validParam;
......
......@@ -147,11 +147,11 @@ public class InternationalSmsRecordApiServiceImpl implements InternationalSmsRec
*/
private void setUserName(InternationalSmsRecordDTO smsRecordDTO) {
if (smsRecordDTO.getUserId() != null) {
ServiceResponse<UserDTO> userResp = userApiService.getUserById(smsRecordDTO.getUserId());
ServiceResponse<UserDTO> userResp = userApiService.getUserInfoById(smsRecordDTO.getUserId());
if (userResp.isSuccess()) {
UserDTO userDTO = userResp.getResult();
if (userDTO != null) {
smsRecordDTO.setUserName(smsRecordDTO.getUserName());
smsRecordDTO.setUserName(userDTO.getUserName());
}
} else {
logger.info("userId:{}, UserApiService.getUserById 调用失败:{}", smsRecordDTO.getUserId(), userResp.getMessage());
......
......@@ -111,10 +111,28 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
logger.info("短信验证不通过:{}", paramResult.getMessage());
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();
try {
String json = JSON.toJSONString(smsRecordDTO);
client.sendMessage("smsMq", json);
client.sendMessage("smsDbMq", JSON.toJSONString(smsRecordDTO));
} catch (Exception e) {
logger.warn("调用mq失败", e);
}
......@@ -126,7 +144,7 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
@Override
public ServiceResponse<Void> run(String arg) {
// 缓存中计费
/*// 缓存中计费
GicMQClient client = GICMQClientUtil.getClientInstance();
try {
logger.info("国内短信缓存扣费:{}", arg);
......@@ -154,17 +172,21 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
} catch (Exception e) {
logger.warn("调用mq失败", e);
}
*/
return ServiceResponse.success();
}
private int deduct(RAtomicLong rSmsCount, Integer enterpriseId, Integer fee) {
long smsCount = rSmsCount.get();
if (smsCount > 0) {
// 套餐包计费
/*
套餐包计费
这里不能改成 decrementAndGet自减, 否则会出现减到0的情况
*/
boolean smsCountDeduct = rSmsCount.compareAndSet(smsCount, smsCount - 1);
// rSmsCount.decrementAndGet();
if (!smsCountDeduct) {
// 设置失败 重新计算
// todo 这里不知道要不要加个延时之类的
return deduct(rSmsCount, enterpriseId, fee);
} else {
return 0;
......
......@@ -36,6 +36,7 @@ public class AliPayStrategy implements PayStrategy {
@Override
public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) {
return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getMsg());
}
}
......@@ -51,7 +51,7 @@ public interface PayStrategy {
* @Title: callBack
* @Description:
* @author taogs
* @param resData
* @param resData
* @return com.gic.api.base.commons.ServiceResponse<java.lang.Void>
* @throws
*/
......
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 @@
<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.member.tag.api.service.SceneCrowdGroupApiService" id="sceneCrowdGroupApiService" timeout="6000" />
<dubbo:reference interface="com.gic.store.service.StoreWidgetApiService" id="storeWidgetApiService" timeout="6000" />
</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