Now I want to send the message to the people which may be student,teacher or schoolmaster,and all of them have the phone,name and availdSendMsgCount.Before send the message which means insert the data to database,I have to judge whether them can be sent or not.So I write the code like this:
if(sendType=SendType.student){
List<Student> students=tStudentServiceImpl.queryByParam(conditionMap);
sendPhoneCout=students.size();
checkSendNumber(availdSendMsgCount,sendPhoneCout);
Log log=logMsgSend(content,sendPhoneCout,sendType);
for (Student vo : students)
sendMsgItem(content,vo.getPhone(),vo.getName(),vo.getId(),log.getId());
}
else if(sendType=SendType.teacher){
List<Teacher> teachers=tTeacherServiceImpl.queryByParam(conditionMap);
sendPhoneCout=teachers.size();
checkSendNumber(availdSendMsgCount,sendPhoneCout);
Log log=logMsgSend(content,sendPhoneCout,sendType);
for (Teacher vo : teachers)
sendMsgItem(content,vo.getPhone(),vo.getName(),vo.getId(),log.getId());
}
else{
List<Schoolmaster> schoolmasters=tSchoolmasterServiceImpl.queryByParam(conditionMap);
sendPhoneCout=schoolmasters.size();
checkSendNumber(availdSendMsgCount,sendPhoneCout);
Log log=logMsgSend(content,sendPhoneCout,sendType);
for (Schoolmaster vo : schoolmasters)
sendMsgItem(content,vo.getMasterPhone(),vo.getMasterName(),vo.getId(),log.getId());
}
I think this code is bad.But how to optimize?
What I have tried:
I have try to extract the common code in
checkSendNumber
and
logMsgSend
,but I think it still be bad.