Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
Java
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900