package com.qianwen.smartman.modules.notify.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import com.qianwen.smartman.common.constant.CommonConstant;
|
import com.qianwen.smartman.common.constant.NotifyConstant;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.core.cache.utils.CacheUtil;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.base.BaseServiceImpl;
|
import com.qianwen.core.notify.DefaultNotifyType;
|
import com.qianwen.core.notify.NotifyType;
|
import com.qianwen.core.notify.notifier.NotifierProvider;
|
import com.qianwen.core.tool.metadata.ConfigMetadata;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.notify.api.DingTalkApi;
|
import com.qianwen.smartman.modules.notify.dto.NotifyTypeInfo;
|
import com.qianwen.smartman.modules.notify.dto.ProviderInfo;
|
import com.qianwen.smartman.modules.notify.entity.BusinessNotify;
|
import com.qianwen.smartman.modules.notify.entity.NotifyConfigEntity;
|
import com.qianwen.smartman.modules.notify.mapper.BusinessNotifyMapper;
|
import com.qianwen.smartman.modules.notify.mapper.NotifyConfigMapper;
|
import com.qianwen.smartman.modules.notify.service.INotifyConfigService;
|
import com.qianwen.smartman.modules.sync.constant.OuterAppConfigConstant;
|
import com.qianwen.smartman.modules.sync.entity.OuterAppConfig;
|
import com.qianwen.smartman.modules.sync.service.IOuterAppConfigService;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/service/impl/NotifyConfigServiceImpl.class */
|
public class NotifyConfigServiceImpl extends BaseServiceImpl<NotifyConfigMapper, NotifyConfigEntity> implements INotifyConfigService {
|
private static final Logger log = LoggerFactory.getLogger(NotifyConfigServiceImpl.class);
|
private final BusinessNotifyMapper notifyBusinessMapper;
|
private final List<NotifierProvider> providers;
|
private final DingTalkApi dingTalkApi;
|
private final IOuterAppConfigService outerAppConfigService;
|
|
private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
|
String implMethodName = lambda.getImplMethodName();
|
boolean z = true;
|
switch (implMethodName.hashCode()) {
|
case -1462663655:
|
if (implMethodName.equals("getNotifyType")) {
|
z = true;
|
break;
|
}
|
break;
|
case -631689286:
|
if (implMethodName.equals("getNotifyId")) {
|
z = false;
|
break;
|
}
|
break;
|
case -75106384:
|
if (implMethodName.equals("getType")) {
|
z = true;
|
break;
|
}
|
break;
|
case 98245393:
|
if (implMethodName.equals("getId")) {
|
z = true;
|
break;
|
}
|
break;
|
case 803533544:
|
if (implMethodName.equals("getStatus")) {
|
z = true;
|
break;
|
}
|
break;
|
}
|
switch (z) {
|
case false:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/BusinessNotify") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getNotifyId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/BusinessNotify") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getNotifyId();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/NotifyConfigEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getType();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/NotifyConfigEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getType();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/NotifyConfigEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getType();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/NotifyConfigEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getType();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/NotifyConfigEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getType();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/BusinessNotify") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getNotifyType();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
break;
|
}
|
throw new IllegalArgumentException("Invalid lambda deserialization");
|
}
|
|
public NotifyConfigServiceImpl(BusinessNotifyMapper notifyBusinessMapper, List<NotifierProvider> providers, @Lazy DingTalkApi dingTalkApi, @Lazy IOuterAppConfigService outerAppConfigService) {
|
this.notifyBusinessMapper = notifyBusinessMapper;
|
this.providers = providers;
|
this.dingTalkApi = dingTalkApi;
|
this.outerAppConfigService = outerAppConfigService;
|
}
|
|
@Override // org.springblade.modules.notify.service.INotifyConfigService
|
public void updateServerConfig(OuterAppConfig outerAppConfig) {
|
Integer appType = outerAppConfig.getAppType();
|
if (appType.intValue() == 1) {
|
Object agentid = outerAppConfig.getWxAgentId();
|
Object corpid = outerAppConfig.getWxCorpId();
|
Object corpsecret = outerAppConfig.getWxAppSecret();
|
Map<String, Object> data = new HashMap<>();
|
data.put("agentid", agentid);
|
data.put("corpid", corpid);
|
data.put("corpsecret", corpsecret);
|
NotifyConfigEntity config = (NotifyConfigEntity) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getStatus();
|
}, 1)).eq((v0) -> {
|
return v0.getType();
|
}, DefaultNotifyType.weiXinQY.name()));
|
if (config == null) {
|
config = new NotifyConfigEntity();
|
config.setName(DefaultNotifyType.weiXinQY.getName());
|
config.setType(DefaultNotifyType.weiXinQY.name());
|
config.setProvider("qyTextMessage");
|
config.setStatus(1);
|
config.setConfiguration(data);
|
} else {
|
config.setConfiguration(data);
|
}
|
saveOrUpdateConfig(config);
|
} else if (appType.intValue() == 2) {
|
Object appKey = outerAppConfig.getDingAppKey();
|
Object appSecret = outerAppConfig.getDingAppSecret();
|
Map<String, Object> data2 = new HashMap<>();
|
data2.put("appKey", appKey);
|
data2.put("appSecret", appSecret);
|
NotifyConfigEntity config2 = (NotifyConfigEntity) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getStatus();
|
}, 1)).eq((v0) -> {
|
return v0.getType();
|
}, DefaultNotifyType.dingTalk.name()));
|
if (config2 == null) {
|
config2 = new NotifyConfigEntity();
|
config2.setName(DefaultNotifyType.dingTalk.getName());
|
config2.setType(DefaultNotifyType.dingTalk.name());
|
config2.setProvider("dingTalkMessage");
|
config2.setStatus(1);
|
config2.setConfiguration(data2);
|
} else {
|
config2.setConfiguration(data2);
|
}
|
saveOrUpdateConfig(config2);
|
}
|
}
|
|
public boolean checkMatchingByOuterAppConfig(String notifyType) {
|
if (Func.equals(notifyType, DefaultNotifyType.dingTalk.name())) {
|
OuterAppConfig outerAppConfigDing = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.DING);
|
if (Func.isNotEmpty(outerAppConfigDing) && outerAppConfigDing.getStatus().equals(CommonConstant.ENABLE)) {
|
NotifyConfigEntity config = (NotifyConfigEntity) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getType();
|
}, DefaultNotifyType.dingTalk.name())).eq((v0) -> {
|
return v0.getStatus();
|
}, 1));
|
Map<String, Object> configuration = config.getConfiguration();
|
if (!configuration.containsKey("appKey") || !configuration.containsKey("appSecret")) {
|
updateServerConfig(outerAppConfigDing);
|
return true;
|
}
|
Object appKey = configuration.get("appKey");
|
Object appSecret = configuration.get("appSecret");
|
String dingAppKey = outerAppConfigDing.getDingAppKey();
|
String dingAppSecret = outerAppConfigDing.getDingAppSecret();
|
if (!Func.equals(appKey, dingAppKey) || !Func.equals(appSecret, dingAppSecret)) {
|
updateServerConfig(outerAppConfigDing);
|
return true;
|
}
|
return true;
|
}
|
return false;
|
}
|
return false;
|
}
|
|
@Override // org.springblade.modules.notify.service.INotifyConfigService
|
public NotifyConfigEntity saveOrUpdateConfig(NotifyConfigEntity notificationConfig) {
|
if (Func.isNotEmpty(notificationConfig.getId())) {
|
CacheUtil.evict("blade:notify", "notifier:id:", notificationConfig.getId(), false);
|
}
|
long count = count((Wrapper) Wrappers.lambdaQuery().ne(Func.isNotEmpty(notificationConfig.getId()), (v0) -> {
|
return v0.getId();
|
}, notificationConfig.getId()).eq((v0) -> {
|
return v0.getType();
|
}, notificationConfig.getType()));
|
if (count > 0) {
|
throw new ServiceException(MessageUtils.message("notify.service.config.not.be.repeated", new Object[0]));
|
}
|
checkProvider(notificationConfig);
|
saveOrUpdate(notificationConfig);
|
return notificationConfig;
|
}
|
|
@Override // org.springblade.modules.notify.service.INotifyConfigService
|
public boolean checkUsedByBusinessNotify(String id) {
|
Long count = this.notifyBusinessMapper.selectCount((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getNotifyId();
|
}, id));
|
if (count.longValue() > 0) {
|
throw new ServiceException(MessageUtils.message("notify.service.config.not.delete", new Object[0]));
|
}
|
return true;
|
}
|
|
public Map<String, NotifyTypeInfo> getNotifyInfo() {
|
return (Map) getAllNotifyType().stream().filter(n -> {
|
return ("weiXinMini".equals(n.getId()) || "weiXinMp".equals(n.getId())) ? false : true;
|
}).collect(Collectors.toMap((v0) -> {
|
return v0.getId();
|
}, notifyTypeInfo -> {
|
return notifyTypeInfo;
|
}));
|
}
|
|
@Override // org.springblade.modules.notify.service.INotifyConfigService
|
public List<NotifyTypeInfo> getServiceList() {
|
Map<String, NotifyTypeInfo> typeInfoMap = getNotifyInfo();
|
List<String> typeList = CollectionUtil.list(Boolean.FALSE.booleanValue(), typeInfoMap.keySet());
|
Map<String, NotifyConfigEntity> configMap = getConfigs(typeList);
|
List<BusinessNotify> businessNotifies = this.notifyBusinessMapper.selectList((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getNotifyType();
|
}, typeList));
|
Map<String, List<BusinessNotify>> notifyMap = (Map) businessNotifies.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getNotifyType();
|
}));
|
typeInfoMap.forEach(typeId, typeInfo -> {
|
if (configMap.containsKey(typeId)) {
|
NotifyConfigEntity config = (NotifyConfigEntity) configMap.get(typeId);
|
typeInfo.setConfigEntity(config);
|
if (Func.equals(config.getType(), DefaultNotifyType.dingTalk.name()) && checkMatchingByOuterAppConfig(DefaultNotifyType.dingTalk.name())) {
|
String companyName = this.dingTalkApi.getCompanyName();
|
typeInfo.setCompanyName(companyName);
|
}
|
}
|
typeInfo.setIsBindBusiness(Boolean.valueOf(notifyMap.containsKey(typeId)));
|
});
|
return new ArrayList(typeInfoMap.values());
|
}
|
|
@Override // org.springblade.modules.notify.service.INotifyConfigService
|
public ConfigMetadata getMetadataByTypeAndProvider(String type, String provider) {
|
ConfigMetadata result = null;
|
List<NotifierProvider> providerList = (List) this.providers.stream().filter(prov -> {
|
return prov.getType().getId().equalsIgnoreCase(type) && prov.getProvider().getId().equalsIgnoreCase(provider);
|
}).collect(Collectors.toList());
|
if (Func.isNotEmpty(providerList)) {
|
result = providerList.get(0).getNotifierConfigMetadata();
|
}
|
return result;
|
}
|
|
public void checkProvider(NotifyConfigEntity notificationConfig) {
|
if (Func.isEmpty(notificationConfig.getId())) {
|
return;
|
}
|
String type = notificationConfig.getType();
|
if (!type.equals(NotifyConstant.SMS_TYPE_VALUE)) {
|
return;
|
}
|
NotifyConfigEntity configEntity = (NotifyConfigEntity) getOne((Wrapper) Wrappers.lambdaQuery(NotifyConfigEntity.class).eq((v0) -> {
|
return v0.getId();
|
}, notificationConfig.getId()));
|
if (ObjectUtil.isNull(configEntity)) {
|
throw new ServiceException(MessageUtils.message("notify.service.config.is.null", new Object[0]));
|
}
|
if (notificationConfig.getProvider().equals(configEntity.getProvider())) {
|
return;
|
}
|
Optional<ProviderInfo> first = getNotifyInfo().get(type).getProviderInfos().stream().filter(p -> {
|
return p.getId().equals(configEntity.getProvider());
|
}).findFirst();
|
if (!first.isPresent()) {
|
throw new ServiceException(MessageUtils.message("notify.service.config.is.null", new Object[0]));
|
}
|
if (this.notifyBusinessMapper.exists((Wrapper) Wrappers.lambdaQuery(BusinessNotify.class).eq((v0) -> {
|
return v0.getNotifyId();
|
}, configEntity.getId()))) {
|
throw new ServiceException(first.get().getName() + MessageUtils.message("notify.config.not.be.edit", new Object[0]));
|
}
|
}
|
|
public Map<String, NotifyConfigEntity> getConfigs(List<String> types) {
|
List<NotifyConfigEntity> configList = list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getType();
|
}, types));
|
return (Map) configList.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getType();
|
}, notifyConfigEntity -> {
|
return notifyConfigEntity;
|
}, a, b -> {
|
return a;
|
}));
|
}
|
|
@Override // org.springblade.modules.notify.service.INotifyConfigService
|
public List<NotifyTypeInfo> getAllNotifyType() {
|
List<NotifyTypeInfo> result = new ArrayList<>();
|
Map<NotifyType, List<NotifierProvider>> groups = (Map) this.providers.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getType();
|
}));
|
groups.forEach(type, providerList -> {
|
NotifyTypeInfo typeInfo = new NotifyTypeInfo();
|
typeInfo.setId(type.getId());
|
typeInfo.setName(type.getName());
|
typeInfo.setProviderInfos((List) providerList.stream().map(ProviderInfo::of).collect(Collectors.toList()));
|
result.add(typeInfo);
|
});
|
return result;
|
}
|
}
|