Click here to Skip to main content
14,037,223 members
Rate this:
 
Please Sign up or sign in to vote.
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:
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190424.1 | Last Updated 23 Jun 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100