📄 tsmissingutil.java.svn-base
字号:
package com.nsi.components.util;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.mail.MessagingException;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.nsi.components.tsmissing.TsMissingDetails;
import com.nsi.components.tsmissing.TsMissingInfo;
import com.nsi.constants.AppConstants;
import com.nsi.control.exceptions.NsiEventException;
import com.nsi.persistence.DataSrcUtil;
import com.nsi.persistence.IsqlDataSource;
import com.nsi.util.ValHelper;
/**
* @author Chris Ye, created on Oct 9, 2008
*
* TsMissingUtil
*/
public final class TsMissingUtil
{
private static Log log = LogFactory.getLog(ActInfoUtil.class);
/**
* private constructor of TsMissingUtil, prevent instantiation
*/
private TsMissingUtil()
{
}
private static class TsMissingUtilHolder
{
static final TsMissingUtil tsMissingUtil = new TsMissingUtil();
}
/**
* @return an instance of TsMissingUtil
*/
public static TsMissingUtil getInstance()
{
return TsMissingUtilHolder.tsMissingUtil;
}
public void prepareTsMissInfo( TsMissingInfo tsmissinfo, String searchtype, int weeks, String deptid) throws NsiEventException
{
List<Map<String,String>> result = new ArrayList<Map<String,String>>();
int j = (weeks + 1) * 7;
String activeCondition = AppConstants.EMPTY_STRING;
String deptCondition = AppConstants.EMPTY_STRING;
if("A".equalsIgnoreCase(searchtype))
{
activeCondition = "and b.bactive='T'";
}
else if("I".equalsIgnoreCase(searchtype))
{
activeCondition = " and b.bactive='F'";
}
String sSql = "select distinct a.resourceid, a.weekbegining, to_char( a.weekbegining, 'MON-DD-YYYY' ) as missedweek, " +
"b.firstname, b.middlename, b.lastname, b.officephone, b.email, c.empltype, b.bactive " +
"from t_timesheet a, t_resource b, ct_empl_type c, t_res_position p " +
"where a.resourceid = b.resourceid " +
"and b.empltypeid = c.empltypeid " +
"and p.resourceid = b.resourceid " +
"and a.weekbegining >= to_date(to_char(b.startdate - to_number(to_char(b.startdate, 'd'),'9') * interval '1 day', 'dd/mm/yyyy'), 'dd/mm/yyyy') " +
"and a.bactive = 'T' " +
"and a.bfinalized <> 'T' " +
"and a.weekbegining between ( current_date - " + j + " ) and ( current_date - 7 ) " +
" " + activeCondition + " " +
"order by a.resourceid, missedweek, b.firstname, b.lastname, a.weekbegining";
IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
Connection conn = null;
try
{
conn = src.getConnection();
result = src.executeRetrieve(conn, sSql);
}
catch(SQLException se)
{
log.error("setUserprofile() caught SQLException: " + se);
}
catch(Exception ex)
{
log.error("setUserprofile() caught Exception: " + ex);
}
finally
{
src.closeConn(conn);
}
if( !result.isEmpty())
{
Map<String,TsMissingDetails> tsmissdtlmap = tsmissinfo.getTsmissdtlmap();
int size = result.size();
String tmp_resourceid = AppConstants.EMPTY_STRING;
for (int i = 0; i < size; i++)
{
Map<String,String> resultmap = result.get(i);
String resourceid = ValHelper.getInstance().getValue(resultmap, "resourceid");
if(!tmp_resourceid.trim().equalsIgnoreCase(resourceid.trim()))
{
TsMissingDetails tsmissingdetails = new TsMissingDetails();
String resourcename = AppConstants.EMPTY_STRING;
String firstname = ValHelper.getInstance().getValue(resultmap, "firstname");
String lastname = ValHelper.getInstance().getValue(resultmap, "lastname");
String middlename = ValHelper.getInstance().getValue(resultmap, "middlename");
if(ValHelper.getInstance().isNotNullAndEmpty(middlename))
{
resourcename = firstname + " " + middlename + " " + lastname;
}
else
{
resourcename = firstname + " " + lastname;
}
String workphone = ValHelper.getInstance().getValue(resultmap, "officephone");
String email = ValHelper.getInstance().getValue(resultmap, "email");
tsmissingdetails.setResactive(ValHelper.getInstance().getValue(resultmap, "bactive"));
tsmissingdetails.setResourceid(resourceid);
tsmissingdetails.setResourcename(resourcename);
tsmissingdetails.setWorkphone(workphone);
tsmissingdetails.setEmail(email);
tsmissingdetails.setEmpltype(ValHelper.getInstance().getValue(resultmap, "empltype"));
tsmissingdetails.getMissedweeks().add(ValHelper.getInstance().getValue(resultmap, "missedweek"));
tsmissdtlmap.put( resourceid, tsmissingdetails );
tmp_resourceid = resourceid;
}
else
{
TsMissingDetails tsmissingdetails = tsmissdtlmap.get(resourceid);
tsmissingdetails.getMissedweeks().add(ValHelper.getInstance().getValue(resultmap, "missedweek"));
}
}
}
}
public void mailling(Map<String,TsMissingDetails> tsmissdtlmap, String name, String email, String deptid) throws NsiEventException, SendFailedException
{
try
{
String subject = "Timesheet Missing Report For Professional Service - Internal";
if(!"2".equals(deptid)) subject = "Timesheet Missing Report For Professional Service - External";
Properties properties = System.getProperties();
properties.put(AppConstants.MAILPROVIDER, AppConstants.SMTPHOST);
Session session = Session.getInstance(properties, null);
MimeMessage mimemessage = new MimeMessage(session);
InternetAddress internetaddress = new InternetAddress(AppConstants.FROM_ADMIN);
mimemessage.setFrom(internetaddress);
mimemessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email));
//mimemessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(AppConstants.FROM_ADMIN));
mimemessage.setSubject(subject);
mimemessage.setSentDate(new Date());
String msgbody = "Dear " + name + ": \n\n";
msgbody = msgbody + "Following Staff did not finalize their timesheets for the following week(s): \n\n";
Set<String> keyset = tsmissdtlmap.keySet();
Iterator<String> iter = keyset.iterator();
while( iter.hasNext())
{
String resourceid = iter.next();
TsMissingDetails tsmissingdetails = tsmissdtlmap.get(resourceid);
String resourcename = tsmissingdetails.getResourcename();
if("T".equals(tsmissingdetails.getResactive()))
{
msgbody = msgbody + resourcename + ": \n\n";
List<String> missedweeks = tsmissingdetails.getMissedweeks();
int size = missedweeks.size();
for (int i = 0; i < size; i++)
{
msgbody = msgbody + "\t\t " + missedweeks.get(i) + "\n";
}
}
}
msgbody = msgbody + "\n\nYours sincerely,\n\n";
msgbody = msgbody + "RMS Admin\n\n";
mimemessage.setText(msgbody);
Transport.send(mimemessage);
}
catch(AddressException addressexception)
{
log.error("mailling() to [" + email +"] -- caught addressexception : ", addressexception );
throw new NsiEventException( "mailling() to [" + email +"] -- caught addressexception : ", addressexception);
}
catch(MessagingException messagingexception)
{
log.error("mailling() to [" + email +"] -- caught messagingexception : ", messagingexception );
throw new NsiEventException("mailling() to [" + email +"] -- caught messagingexception : ", messagingexception);
}
}
public void mailling(TsMissingDetails tsmissingdetails, String resourcename, String email) throws NsiEventException, SendFailedException
{
try
{
Properties properties = System.getProperties();
properties.put(AppConstants.MAILPROVIDER, AppConstants.SMTPHOST);
Session session = Session.getInstance(properties, null);
MimeMessage mimemessage = new MimeMessage(session);
InternetAddress internetaddress = new InternetAddress(AppConstants.FROM_ADMIN);
mimemessage.setFrom(internetaddress);
mimemessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email));
mimemessage.setSubject("Timesheet Missing Reminder");
mimemessage.setSentDate(new Date());
String text2 = resourcename + ": \n\n";
text2 = text2 + "Please kindly finalize your timesheet for the following week(s): \n\n";
List<String> missedweeks = tsmissingdetails.getMissedweeks();
int size = missedweeks.size();
for (int i = 0; i < size; i++)
{
text2 = text2 + "\t\t " + missedweeks.get(i) + "\n";
}
text2 = text2 + "\n\n";
text2 = text2 + "Yours sincerely,\n\n";
text2 = text2 + "RMS Admin\n\n";
mimemessage.setText(text2);
Transport.send(mimemessage);
}
catch(AddressException addressexception)
{
log.error("mailling() to [" + email +"] -- caught addressexception : ", addressexception );
throw new NsiEventException( "mailling() to [" + email +"] -- caught addressexception : ", addressexception);
}
catch(MessagingException messagingexception)
{
log.error("mailling() -- to [" + email +"] caught messagingexception : ", messagingexception );
throw new NsiEventException("mailling() to [" + email +"] -- caught messagingexception : ", messagingexception);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -