Sm_emp_disorder_OEI.java 3.36 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
package com.csc.library.process;

import java.util.HashMap;
import java.util.Iterator;

import com.csc.library.database.DataSet;
import com.csc.library.mail.SendMail;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.InitialEnvironment;
import com.csc.library.session.InitialInquiry;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.MyLog;

public class Sm_emp_disorder_OEI extends MyProcess{

	public void process(){
		CscCalendar cc = new CscCalendar();
		cc.decDate(1);
		HashMap<String,String> hm_name = new HashMap<String,String>();
		HashMap<String,String> hm_mail = new HashMap<String,String>();
		HashMap<String,String> hm_data = new HashMap<String,String>();
		MyLog.debug(this,this.getUProfile(),"================== Before Query By BlizZoniC ==================");
		try{
		//	String sql = "select * from SENDMAILTOEMP where dateid='"+cc.getYYYYMMDD()+"' order by empid ";
			String sql = "select * from SENDMAILTOEMP where dateid='2015-02-02' order by empid ";
			DataSet ds = new DataSet(sql,this.getUProfile().get("dbname"),"SENDMAILTOEMP"); 
			ds.initConnection(this.getUProfile());
			while(ds.next()){
				MyLog.debug(this,this.getUProfile(),"================== Query By BlizZoniC ==================");
				String val = 	"<tr>"+
										"<td>"+ds.getString("empid")+"</td>"+
										"<td>&nbsp;&nbsp;&nbsp;&nbsp;"+ds.getString("data")+"</td>"+
									"</tr>\n";
				hm_name.put(ds.getString("empid"), ds.getString("fullname"));
				hm_mail.put(ds.getString("empid"), ds.getString("email"));
	            if(hm_data.containsKey(ds.getString("empid"))){
	            	hm_data.put(ds.getString("empid"), hm_data.get(ds.getString("empid"))+val);
	            }else{
	            	hm_data.put(ds.getString("empid"),val);
	            }
				
			}

		}catch(Exception e){
			e.printStackTrace();
		}
		
		try{
			Iterator<String> it = hm_mail.keySet().iterator();
			while(it.hasNext()){
				String key = it.next();
				String email = hm_mail.get(key);
	            String content = hm_data.get(key);
	            String name = hm_name.get(key);
	            
	            sendMail(email,content,name);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}


	private void sendMail(String email,String content,String name){
		MyLog.debug(this,this.getUProfile(),"================== Before Sendmail By Nut Freedom ==================");
		if(email!=null){
			CscCalendar cc2 = new CscCalendar();
			cc2.decDate(2);
				
			InitialEnvironment ine = new InitialEnvironment("GLOBAL");
			String 	from = ine.getValue("mailauth-username");
			String 	head = "<b>¹س "+cc2.getDDMMYYYY()+"</b><br>";
						head += "&nbsp;&nbsp;&nbsp;&nbsp;ҡõǨͺҡ÷ӧҹͧҹ к myHR ҷӧҹ 繡͢ͼԴҴѧ<br>";
			String footer = "&nbsp;&nbsp;&nbsp;&nbsp;ѧ鹾ѡҹ ¡سһѺاŢͧҹк myHR ˹ҷ˹§ҹ÷Ѿҡ ͻªͧǷҹͧ<br><br>˹§ҹ÷þҡ";
			//SendMail sm = new SendMail(hostname, from, to, cc, subject, content);
			SendMail sm = new SendMail("", from,(String) email, (String) this.data.get("cc"), "Time attendance notification", head+"<table><tr><td>ѹ</td><td>&nbsp;&nbsp;&nbsp;&nbsp;´</td></tr>\n"+content+"</table><br>"+footer);
			sm.send();
		}
	}

}