猿问

在java中检查多个布尔条件

我有一个场景,我必须检查模板是否已经存在于数据库中。如果存在,我必须根据现有模板返回一条消息。


我有几个模板:电子邮件、信件、短信。如果它们都存在,我必须返回“所有模板都已经存在”。


如果只有电子邮件模板存在,我必须返回只有电子邮件模板存在,信函和短信模板也是如此。


代码:


for (EventVO eventVO: eventModuleList) {

    List <EmailTemplateMaster> emailTemplateList = communicationDAO

        .checkEmailTemplateExist(eventVO.getEventCode());

    if (CollectionUtils.isNotEmpty(emailTemplateList)) {

        emailTemplateExist = true;

    }

    List <LetterTemplateMaster> letterTemplateList = communicationDAO

        .checkLetterTemplateExist(eventVO.getEventCode());

    if (CollectionUtils.isNotEmpty(letterTemplateList)) {

        letterTemplateExist = true;

    }

    List <SmsTemplateMaster> smsTemplateList = communicationDAO

        .checkSmsTemplateExist(eventVO.getEventCode());

    if (CollectionUtils.isNotEmpty(smsTemplateList)) {

        smsTemplateExist = true;

    }

    if (emailTemplateExist && letterTemplateExist && smsTemplateExist) {

        templateExist = CommunicationConstants.ALL_TEMPLATE_EXIST;

    }

    if (emailTemplateExist || !letterTemplateExist && !smsTemplateExist) {

        templateExist = CommunicationConstants.EMAIL_TEMPLATE_EXIST;

    }

    if (!emailTemplateExist && letterTemplateExist && !smsTemplateExist) {

        templateExist = CommunicationConstants.LETTER_TEMPLATE_EXIST;

    }

    if (!emailTemplateExist && !letterTemplateExist && smsTemplateExist) {

        templateExist = CommunicationConstants.SMS_TEMPLATE_EXIST;

    }

}

我可以知道检查退出模板布尔值的最简单方法是否存在。


基于退出,我必须发送相应的消息。


public static final String ALL_TEMPLATE_EXIST = "Email, Letter and Sms Template already exist for the selected event."; 

public static final String EMAIL_TEMPLATE_EXIST = "Email Template already exist for the selected event.";

public static final String SMS_TEMPLATE_EXIST = "Sms Template already exist for the selected event.";

public static final String LETTER_TEMPLATE_EXIST = "Email Letter Template already exist for the selected event.";


温温酱
浏览 296回答 3
3回答
随时随地看视频慕课网APP

相关分类

Java
我要回答