Subversion Repository Public Repository

FP_REPORT_SEND_MAIL

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package com.nru.test;

import java.sql.Connection;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.Vector;

import com.mysql.jdbc.log.Log;

public class MainClass {
	Connection con;
	Utilities utilities = new Utilities();
	
	public MainClass() {
		Connection con = utilities.getConnection();
		this.con = con;
	}
	
	public Vector getids(){
		String query="select distinct visitor_id from t_visitor_master";
		Vector values=utilities.selectQuery(query, 1, con);
		return values;
	}
	
	public Vector getData(){
		Vector data = new Vector();
		Vector maindata = new Vector();
		try {
			String query = "  ";
			query = " SELECT ADDTIME(NOW(), '0:0:0.000000')";
			String server_datetime = utilities.getField(query, con);
			
			// get all users
			
			
			// get only date not time
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		    Date date = formatter.parse(server_datetime);
		    String year = ""+(1900+date.getYear());
	    //  String month = (date.getMonth() < 10)?"0"+(1+date.getMonth()):""+(1+date.getMonth());
		    String month = (date.getMonth() < 10)?""+(1+date.getMonth()):""+(1+date.getMonth());
		    String day  = (date.getDate() < 10)?"0"+date.getDate():""+date.getDate();
		    String date_full = "";
		    
		    date_full = year+"-"+month+"-"+day;
		    String date_from = date_full+" 00:00:000";
		    String date_to   = date_full+" 23:59:999";
		    System.out.println("demoooooooooooo"+date_full+"  >>  "+date_from+"  >>  "+date_to);
		    
		    Vector values=getids();
		    //System.out.println("vector values"+values);
		    if(values.size()>0){
		    	for (int i = 0; i < values.size(); i++) {
					Vector temp=(Vector)values.elementAt(i);
					String visitor_id=temp.elementAt(0).toString();
					query = " SELECT m.visitor_fname, c.checkin_time, c.checkout_time "
							+ " FROM t_visitor_master m, t_visitor_check_in_out c "
							+ " where m.visitor_id = c.visitor_id "
							+ " and m.visitor_id="+visitor_id
							+ " and c.checkin_time >= '"+date_from+"'"
							+ " and c.checkin_time <= '"+date_to+"'"
							+ " ";
					data = utilities.selectQuery(query, 3, con);
					System.out.println("3 >> "+query);
					System.out.println("3 >> "+data);  
					if(data.size() > 0){
						Vector t = new Vector();
						String fname    = (((Vector)data.elementAt(0)).elementAt(0) == null)?"":((Vector)data.elementAt(0)).elementAt(0).toString();
						String checkin  = (((Vector)data.elementAt(0)).elementAt(1) == null)?"":((Vector)data.elementAt(0)).elementAt(1).toString();
						String checkout = (((Vector)data.elementAt(data.size()-1)).elementAt(2) == null)?"":((Vector)data.elementAt(data.size()-1)).elementAt(2).toString();
						
						
						DateFormat date_format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
						String checkin_time  = "";
						String checkout_time = "";
						String duration_time="";
						Date date1 = null;
					    String checkin_time_output = "";
					    String checkout_time_output = "";
					 
						
						
						System.out.println("@@@checkin: "+checkin+"    checkout: "+checkout);
						if(checkin != null && checkin.length() > 0){
							Date checkinT  = (Date)formatter.parse(checkin);
							checkin_time  = formattedTime(checkinT);
							
							 DateFormat df = new SimpleDateFormat("hh:mm");
							 DateFormat outputformat = new SimpleDateFormat("hh:mmaa");
						       try{
						          //Conversion of input String to date
						    	  date1= df.parse(checkin_time);
						          //old date format to new date format
						    	  checkin_time_output = outputformat.format(date1);
						    	  System.out.println("checkin_time_output "+checkin_time_output);
						    	}catch(ParseException pe){
						    	    pe.printStackTrace();
						    	 }
							
							
							
						}else{
							checkin_time_output = "-";
						}
						
						if(checkout != null && checkout.length() > 0){
							Date checkoutT = (Date)formatter.parse(checkout);
				            checkout_time = formattedTime(checkoutT);
				            
				            DateFormat df = new SimpleDateFormat("hh:mm");
							 DateFormat outputformat = new SimpleDateFormat("hh:mmaa");
						       try{
						          //Conversion of input String to date
						    	  date1= df.parse(checkout_time);
						          //old date format to new date format
						    	  checkout_time_output = outputformat.format(date1);
						    	  System.out.println("checkout_time_output "+checkout_time_output);
						    	}catch(ParseException pe){
						    	    pe.printStackTrace();
						    	 }
						}else{
							checkout_time_output = "-";
						}
						System.out.println("@@@checkin_time: "+checkin_time+"    checkout_time: "+checkout_time);
						
						if(checkin!=null && checkin.length() > 0 && checkout!=null && checkout.length() > 0){
							Date d1 = null;
							Date d2 = null;
							SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
							 try{ 
							d1 = format.parse(checkin_time);
							d2 = format.parse(checkout_time);
							//in milliseconds
							long diff = d2.getTime() - d1.getTime();

							long diffSeconds = diff / 1000 % 60;
							long diffMinutes = diff / (60 * 1000) % 60;
							long diffHours = diff / (60 * 60 * 1000) % 24;
							long diffDays = diff / (24 * 60 * 60 * 1000);
							//duration_time+= diffDays+"days:"+diffHours+"hr:"+diffMinutes+"min:"+diffSeconds+"sec";
							//duration_time+= diffHours+"hr:"+diffMinutes+"min:"+diffSeconds+"sec";
							duration_time+= diffHours+"hr:"+diffMinutes+"min";
							
							System.out.println("results_duration"+duration_time);
							

						} catch (Exception e) {
							e.printStackTrace();
						}
							
					
						
						} 
            
						t.add(fname);
						t.add(checkin_time_output);
						t.add(checkout_time_output);
						t.add(duration_time);
						maindata.add(t);
					}
				}
		    }
			System.out.println("1 >> "+maindata);
		} catch (Exception e) {e.printStackTrace();}
		return maindata;
	}
	
	public String formattedTime(Date date){
		if(date != null){
			String hr = ""+date.getHours();
			String mn = ""+date.getMinutes();
			String sc = ""+date.getSeconds();
			return hr+":"+mn+":"+sc;
		}else{
			return "-";
		}
	}
	
	public static void main(String[] args){
		MainClass mainClass =  new MainClass();
		Vector data = mainClass.getData();
		System.out.println("2 >> "+data);
		new mailer(data);
	}

}

Commits for FP_REPORT_SEND_MAIL/src/com/nru/test/MainClass.java

Diff revisions: vs.
Revision Author Commited Message
1 lingaraj picture lingaraj Sat 24 Nov, 2018 10:13:09 +0000