通过枚举替换if-else

This commit is contained in:
kuang.yifei@iwhalecloud.com 2022-05-30 11:01:32 +08:00
parent f5202904f9
commit b074e3fbce
2 changed files with 36 additions and 11 deletions

View File

@ -0,0 +1,32 @@
package com.ghy.common.enums;
public enum PayTypeEnum {
WX_LITE(0, "微信支付"),
ALIPAY_QR(1, "支付宝支付");
private Integer code;
private String desc;
PayTypeEnum(Integer code, String desc){
this.code = code;
this.desc = desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

View File

@ -2,6 +2,7 @@ package com.ghy.payment.service.impl;
import com.ghy.common.adapay.model.PaymentDTO;
import com.ghy.common.core.text.Convert;
import com.ghy.common.enums.PayTypeEnum;
import com.ghy.payment.domain.FinancialMaster;
import com.ghy.payment.mapper.FinancialMasterMapper;
import com.ghy.payment.mapper.PaymentMapper;
@ -73,19 +74,11 @@ public class FinancialMasterServiceImpl implements FinancialMasterService {
@Override
public void paySucceeded(String orderNo, String payChannel) {
int payType;
if (StringUtils.isBlank(payChannel)) {
payType = -1;
logger.warn("OrderNo[{}] Unknown payChannel [{}]!", orderNo, payChannel);
} else if (payChannel.startsWith(WX)) {
payType = 0;
} else if (payChannel.startsWith(ALIPAY)) {
payType = 1;
} else {
payType = -1;
try {
financialMasterMapper.paySucceeded(orderNo, PayTypeEnum.valueOf(payChannel.toUpperCase()).getCode());
}catch (IllegalArgumentException e){
logger.warn("OrderNo[{}] Unknown payChannel [{}]!", orderNo, payChannel);
}
financialMasterMapper.paySucceeded(orderNo, payType);
}
@Override