package com.qianwen.smartman.modules.notify.service.impl; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.base.BaseServiceImpl; import com.qianwen.core.notify.template.TemplateProvider; import com.qianwen.core.tool.metadata.ConfigMetadata; import com.qianwen.core.tool.metadata.ConfigPropertyMetadata; import com.qianwen.core.tool.metadata.types.StringType; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.modules.notify.entity.BusinessNotify; import com.qianwen.smartman.modules.notify.entity.NotifyTemplateEntity; import com.qianwen.smartman.modules.notify.enums.NotifyTemplateExpandEnum; import com.qianwen.smartman.modules.notify.mapper.BusinessNotifyMapper; import com.qianwen.smartman.modules.notify.mapper.NotifyTemplateMapper; import com.qianwen.smartman.modules.notify.service.INotifyTemplateService; import cn.hutool.core.convert.Convert; @Service public class NotifyTemplateServiceImpl extends BaseServiceImpl implements INotifyTemplateService { private static final Logger log = LoggerFactory.getLogger(NotifyTemplateServiceImpl.class); @Autowired private BusinessNotifyMapper businessNotifyMapper; @Override // org.springblade.modules.notify.service.INotifyTemplateService public boolean checkUsedByBusinessNotify(String id) { Long count = this.businessNotifyMapper.selectCount(Wrappers.lambdaQuery() .eq(BusinessNotify::getNotifyTemplateId, id)); /* Long count = this.businessNotifyMapper.selectCount((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getNotifyTemplateId(); }, id));*/ if (count.longValue() > 0) { throw new ServiceException("当前通知模板正在被业务使用,无法删除"); } return true; } @Override // org.springblade.modules.notify.service.INotifyTemplateService public ConfigMetadata getAllTypes(String type, String provider, List providers) { NotifyTemplateExpandEnum[] values; ConfigMetadata result = null; List providerList = 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).getTemplateConfigMetadata(); } if (result != null) { for (NotifyTemplateExpandEnum expandEnum : NotifyTemplateExpandEnum.values()) { setExpands(result, type, provider, expandEnum); } } return result; } private void setExpands(ConfigMetadata configMetadata, String type, String provider, NotifyTemplateExpandEnum expandEnum) { List properties = configMetadata.getProperties(); if (type.equals(expandEnum.getType()) && provider.equals(expandEnum.getProvider())) { Optional metadata = properties.stream().filter(prop -> { return expandEnum.getProperty().equals(prop.getProperty()); }).findFirst(); metadata.ifPresent(configPropertyMetadata -> { StringType stringType = (StringType) Convert.convert(StringType.class, configPropertyMetadata.getType()); stringType.getExpands().put(expandEnum.getKey(), expandEnum.getValue()); }); } } }