refactor(core):优化字符串比较逻辑以提高代码健壮性

- 将多个equals方法调用改为常量在前的写法,避免空指针异常
- 统一了所有字符串比较的格式,增强代码可读性和一致性- 修复潜在的NPE风险,提升系统稳定性
This commit is contained in:
pikachu1995@126.com
2025-10-11 18:19:52 +08:00
parent 85c8c5d021
commit 33fcce1cc9
4 changed files with 15 additions and 15 deletions

View File

@@ -205,7 +205,7 @@ public class GoodsImportServiceImpl implements GoodsImportService {
goodsImportDTO.setCategory(category);
goodsImportDTO.setTemplate(templateId);
goodsImportDTO.setGoodsUnit(objects.get(4).toString().substring(objects.get(4).toString().indexOf("-") + 1));
goodsImportDTO.setRelease(objects.get(5).toString().equals("上架"));
goodsImportDTO.setRelease("上架".equals(objects.get(5).toString()));
List<String> goodsGalleryList = new ArrayList<>();
goodsGalleryList.add(objects.get(6).toString());

View File

@@ -158,7 +158,7 @@ public class WechatPlugin implements Payment {
}
Config config =null;
if(setting.getPublicType().equals("CERT")){
if("CERT".equals(setting.getPublicType())){
config=this.getCertificateConfig(setting);
}else {
config=this.getPublicKeyConfig(setting);
@@ -221,7 +221,7 @@ public class WechatPlugin implements Payment {
}
Config config =null;
if(setting.getPublicType().equals("CERT")){
if("CERT".equals(setting.getPublicType())){
config=this.getCertificateConfig(setting);
}else {
config=this.getPublicKeyConfig(setting);
@@ -280,7 +280,7 @@ public class WechatPlugin implements Payment {
}
Config config =null;
if(setting.getPublicType().equals("CERT")){
if("CERT".equals(setting.getPublicType())){
config=this.getCertificateConfig(setting);
}else {
config=this.getPublicKeyConfig(setting);
@@ -341,7 +341,7 @@ public class WechatPlugin implements Payment {
}
Config config =null;
if(setting.getPublicType().equals("CERT")){
if("CERT".equals(setting.getPublicType())){
config=this.getCertificateConfig(setting);
}else {
config=this.getPublicKeyConfig(setting);
@@ -410,7 +410,7 @@ public class WechatPlugin implements Payment {
WechatPaymentSetting setting = wechatPaymentSetting();
Config config =null;
if(setting.getPublicType().equals("CERT")){
if("CERT".equals(setting.getPublicType())){
config=this.getCertificateConfig(setting);
}else {
config=this.getPublicKeyConfig(setting);
@@ -511,7 +511,7 @@ public class WechatPlugin implements Payment {
WechatPaymentSetting setting = wechatPaymentSetting();
Config config =null;
if(setting.getPublicType().equals("CERT")){
if("CERT".equals(setting.getPublicType())){
config=this.getCertificateConfig(setting);
}else {
config=this.getPublicKeyConfig(setting);
@@ -572,7 +572,7 @@ public class WechatPlugin implements Payment {
WechatPaymentSetting setting = wechatPaymentSetting();
NotificationConfig config=null;
if(setting.getPublicType().equals("CERT")) {
if("CERT".equals(setting.getPublicType())){
config = new RSAAutoCertificateConfig.Builder()
.merchantId(setting.getMchId())
.privateKey(setting.getApiclientKey())
@@ -631,7 +631,7 @@ public class WechatPlugin implements Payment {
WechatPaymentSetting setting = wechatPaymentSetting();
Config config =null;
if(setting.getPublicType().equals("CERT")){
if("CERT".equals(setting.getPublicType())){
config=this.getCertificateConfig(setting);
}else {
config=this.getPublicKeyConfig(setting);
@@ -669,7 +669,7 @@ public class WechatPlugin implements Payment {
WechatPaymentSetting setting = wechatPaymentSetting();
NotificationConfig config=null;
if(setting.getPublicType().equals("CERT")) {
if("CERT".equals(setting.getPublicType())){
config = new RSAAutoCertificateConfig.Builder()
.merchantId(setting.getMchId())
.privateKey(setting.getApiclientKey())
@@ -756,11 +756,11 @@ public class WechatPlugin implements Payment {
* @param outOrderNo 订单号
*/
private void updateOrderPayNo(PayParam payParam,String outOrderNo ){
if(payParam.getOrderType().equals("ORDER")){
if("ORDER".equals(payParam.getOrderType())){
orderService.update(new LambdaUpdateWrapper<Order>()
.eq(Order::getSn,payParam.getSn())
.set(Order::getPayOrderNo,outOrderNo));
}else if(payParam.getOrderType().equals("TRADE")){
}else if("TRADE".equals(payParam.getOrderType())){
orderService.update(new LambdaUpdateWrapper<Order>()
.eq(Order::getTradeSn,payParam.getSn())
.set(Order::getPayOrderNo,outOrderNo));

View File

@@ -248,9 +248,9 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
List<PromotionGoods> promotionGoods = skuValidPromotions.stream()
.filter(j ->
(CharSequenceUtil.isNotEmpty(j.getSkuId()) && j.getSkuId().equals(goodsSku.getId())) ||
(j.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name()) && j.getStoreId().equals("0")) ||
(j.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name()) && "0".equals(j.getStoreId())) ||
(j.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name()) && j.getStoreId().equals(esGoodsIndex.getStoreId())) ||
(j.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && j.getStoreId().equals("0") && j.getScopeId().contains(goodsSku.getCategoryPath()))||
(j.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && "0".equals(j.getStoreId()) && j.getScopeId().contains(goodsSku.getCategoryPath()))||
(j.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && j.getStoreId().equals(goodsSku.getStoreId()) && j.getScopeId().contains(goodsSku.getCategoryPath()))
)
.collect(Collectors.toList());

View File

@@ -123,7 +123,7 @@ public class SmsUtilAliImplService implements SmsUtil {
@Override
public boolean verifyCode(String mobile, VerificationEnums verificationEnums, String uuid, String code) {
Object result = cache.get(cacheKey(verificationEnums, mobile, uuid));
if (code.equals(result) || code.equals("0")) {
if (code.equals(result) || "0".equals( code)) {
//校验之后,删除
cache.remove(cacheKey(verificationEnums, mobile, uuid));
return true;