Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mytime
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narendar Vakiti
mytime
Commits
47402225
Unverified
Commit
47402225
authored
Sep 04, 2018
by
mshaik-nisum-com
Committed by
GitHub
Sep 04, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #180 from nisum-inc/FEATURE/Login_Report_Based_On_Date_Time
MT-175:Login Report Based on Date and Time
parents
915e62a3
2ec35378
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
142 deletions
+128
-142
AttendanceService.java
...main/java/com/nisum/mytime/service/AttendanceService.java
+2
-1
AttendanceServiceImpl.java
.../java/com/nisum/mytime/service/AttendanceServiceImpl.java
+34
-11
EmployeeDataService.java
...in/java/com/nisum/mytime/service/EmployeeDataService.java
+84
-130
MyTimeUtils.java
src/main/java/com/nisum/mytime/utils/MyTimeUtils.java
+8
-0
No files found.
src/main/java/com/nisum/mytime/service/AttendanceService.java
View file @
47402225
package
com
.
nisum
.
mytime
.
service
;
import
java.sql.SQLException
;
import
java.text.ParseException
;
import
java.util.List
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
...
...
@@ -14,5 +15,5 @@ public interface AttendanceService {
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
;
List
<
EmpLoginData
>
employeeLoginReportBasedOnDateTime
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
;
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
;
}
src/main/java/com/nisum/mytime/service/AttendanceServiceImpl.java
View file @
47402225
...
...
@@ -3,8 +3,13 @@ package com.nisum.mytime.service;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
...
...
@@ -45,20 +50,38 @@ public class AttendanceServiceImpl implements AttendanceService {
MyTimeLogger
.
getInstance
().
info
(
"Time Taken for "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
return
listOfEmployees
;
}
@Override
public
List
<
EmpLoginData
>
employeeLoginReportBasedOnDateTime
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
public
List
<
EmpLoginData
>
employeeLoginReportBasedOnDateTime
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
{
//Getting Sign AM/PM of Time
String
timeSignFrom
=
fromTime
.
substring
(
6
,
8
);
String
timeSignTo
=
toTime
.
substring
(
6
,
8
);
// Converting the Time from 12 Hours to 24 Hours Format
SimpleDateFormat
displayFormat
=
new
SimpleDateFormat
(
"HH:mm"
);
SimpleDateFormat
parseFormat
=
new
SimpleDateFormat
(
"hh:mm a"
);
// Given Format
Date
from
=
parseFormat
.
parse
(
fromTime
);
Date
to
=
parseFormat
.
parse
(
toTime
);
String
timeSignFrom
=
fromTime
.
substring
(
7
,
9
);
String
timeSignTo
=
toTime
.
substring
(
7
,
9
);
//Required Format
String
timeFrom
=
displayFormat
.
format
(
from
);
String
timeTo
=
displayFormat
.
format
(
to
);
int
from
=
Integer
.
parseInt
(
fromTime
.
substring
(
0
,
2
));
int
to
=
Integer
.
parseInt
(
toTime
.
substring
(
0
,
2
));
//Getting Hours from Time
String
nextDate
=
fromDate
;
if
(
to
<
from
)
{
LocalDate
newtoDate
=
LocalDate
.
parse
(
toDate
).
plusDays
(
1
);
int
hoursFrom
=
Integer
.
parseInt
(
timeFrom
.
substring
(
0
,
2
));
int
hoursTo
=
Integer
.
parseInt
(
timeTo
.
substring
(
0
,
2
));
if
(
hoursTo
<=
hoursFrom
&&
timeSignFrom
.
equals
(
timeSignTo
)
||
hoursTo
<=
hoursFrom
)
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/d"
);
LocalDate
newtoDate
=
(
LocalDate
.
parse
(
fromDate
,
formatter
)).
plusDays
(
1
);
nextDate
=
newtoDate
.
toString
();
nextDate
=
nextDate
.
replace
(
"-"
,
"/"
);
}
return
employeeDataBaseService
.
fetchEmployeeLoginsBasedOnDates
1
(
id
,
fromDate
,
nextDate
,
toDate
);
return
employeeDataBaseService
.
fetchEmployeeLoginsBasedOnDates
Time
(
id
,
fromDate
,
nextDate
,
toDate
,
timeFrom
,
timeTo
);
}
@Override
...
...
src/main/java/com/nisum/mytime/service/EmployeeDataService.java
View file @
47402225
...
...
@@ -11,6 +11,7 @@ import java.time.Duration;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.Period
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -34,36 +35,6 @@ public class EmployeeDataService {
DbConnection
dbConnection
;
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDates
(
long
employeeId
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
{
System
.
out
.
println
(
"---------------Generate Report------------"
);
//Checking Condition whether fromDate and Todate are having the Time
if
(
fromDate
.
length
()>
10
)
{
// Converting the Time from AM/PM to 24 Hours Format
DateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm aa"
);
DateFormat
outputformat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
String
fromDateIn24Hours
=
null
;
String
toDateIn24Hours
=
null
;
try
{
fromDateIn24Hours
=
outputformat
.
format
(
df
.
parse
(
fromDate
));
toDateIn24Hours
=
outputformat
.
format
(
df
.
parse
(
toDate
));
}
catch
(
ParseException
e
)
{
System
.
out
.
println
(
"Exception While Converting String to Date"
);
}
// Getting only hours from Date and Time
int
from
=
Integer
.
parseInt
(
fromDateIn24Hours
.
substring
(
11
,
13
));
int
to
=
Integer
.
parseInt
(
toDateIn24Hours
.
substring
(
11
,
13
));
//if from is greater than the to time
if
(
to
<
from
)
{
// Get the Date from Date and Time
fromDate
=
fromDate
.
substring
(
0
,
11
);
toDate
=
fromDate
.
substring
(
0
,
11
);
// Increasing the to Date to next time because of from time is greater than the to time
LocalDate
newtoDate
=
LocalDate
.
parse
(
toDate
).
plusDays
(
1
);
toDate
=
newtoDate
.
toString
();
}
}
long
start_ms
=
System
.
currentTimeMillis
();
String
querys
=
null
;
if
(
employeeId
==
0
)
{
...
...
@@ -75,11 +46,10 @@ public class EmployeeDataService {
+
MyTimeUtils
.
ABESENT_STATUS_QUERY1
+
"'"
+
toDate
.
replace
(
"-"
,
"/"
)
+
"'"
+
MyTimeUtils
.
ABESENT_STATUS_QUERY2
+
employeeId
+
MyTimeUtils
.
ABESENT_STATUS_QUERY3
;
System
.
out
.
println
(
"Query from fetchEmployeeLoginsBasedOnDates "
+
querys
);
}
int
countHours
=
0
;
List
<
EmpLoginData
>
listOfEmpLoginData
=
new
ArrayList
<>();
long
totalseconds
=
0
;
try
(
Connection
connection
=
dbConnection
.
getDBConnection
();
Statement
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
querys
.
toString
()))
{
...
...
@@ -90,26 +60,15 @@ public class EmployeeDataService {
empLoginData
.
setDateOfLogin
(
resultSet
.
getDate
(
"FirstLogin"
).
toString
());
empLoginData
.
setFirstLogin
(
resultSet
.
getTime
(
"FirstLogin"
).
toString
());
empLoginData
.
setLastLogout
(
resultSet
.
getTime
(
"LastLogin"
).
toString
());
int
start
=
resultSet
.
getTime
(
"FirstLogin"
).
getHours
();
int
end
=
resultSet
.
getTime
(
"LastLogin"
).
getHours
();
if
(
end
<
start
){
LocalDateTime
loginTime
=
resultSet
.
getTimestamp
(
"FirstLogin"
).
toLocalDateTime
();
LocalDateTime
logoutTime
=
resultSet
.
getTimestamp
(
"LastLogin"
).
toLocalDateTime
();
totalseconds
=
java
.
time
.
Duration
.
between
(
loginTime
,
logoutTime
).
getSeconds
();
}
else
{
Time
from
=
resultSet
.
getTime
(
"FirstLogin"
);
Time
to
=
resultSet
.
getTime
(
"LastLogin"
);
long
milliseconds
=
to
.
getTime
()
-
from
.
getTime
();
totalseconds
=
(
int
)
milliseconds
/
1000
;
}
int
hours
=
(
int
)
(
totalseconds
/
3600
);
int
minutes
=
(
int
)
((
totalseconds
%
3600
)
/
60
);
int
seconds
=
(
int
)
((
totalseconds
%
3600
)
%
60
);
int
seconds
=
(
int
)
milliseconds
/
1000
;
int
hours
=
seconds
/
3600
;
int
minutes
=
(
seconds
%
3600
)
/
60
;
seconds
=
(
seconds
%
3600
)
%
60
;
empLoginData
.
setTotalLoginTime
(
hours
+
":"
+
minutes
+
":"
+
seconds
);
empLoginData
.
setTotalLoginTime
(
hours
+
":"
+
minutes
+
":"
+
seconds
);
Date
d
=
MyTimeUtils
.
tdf
.
parse
(
empLoginData
.
getTotalLoginTime
());
countHours
+=
d
.
getTime
();
...
...
@@ -127,22 +86,30 @@ public class EmployeeDataService {
return
listOfEmpLoginData
;
}
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDates1
(
long
employeeId
,
String
fromDate
,
String
nextDate
,
String
toDate
)
throws
MyTimeException
{
int
differentBetweenDays
=
Period
.
between
(
LocalDate
.
parse
(
fromDate
),
LocalDate
(
toDate
)).
getDays
();
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDatesTime
(
long
employeeId
,
String
fromDate
,
String
nextDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/dd"
);
LocalDate
formatedFromDate
=
LocalDate
.
parse
(
fromDate
,
formatter
);
LocalDate
formatedNextDate
=
LocalDate
.
parse
(
nextDate
,
formatter
);
LocalDate
formatedToDate
=
LocalDate
.
parse
(
toDate
,
formatter
);
int
differentBetweenDays
=
Period
.
between
(
formatedFromDate
,
formatedToDate
).
getDays
();
long
start_ms
=
System
.
currentTimeMillis
();
String
querys
=
null
;
List
<
EmpLoginData
>
listOfEmpLoginData
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<=
differentBetweenDays
;
i
++)
{
querys
=
"select emp.EmployeeCode,emp.FirstName,MIN(tr.aDateTime) AS FirstLogin,MAX(tr.aDateTime) AS LastLogin\r\n"
+
"from [smartiSCC].[dbo].[Transactions] as tr,[smartiSCC].[dbo].[EmployeeMaster] as emp\r\n"
+
"where tr.EmployeemasterID=emp.EmployeeMasterID and \r\n"
+
"tr.aDateTime >= '2018/08/11 22:00' and tr.aDateTime<= '2018/08/12 10:00' \r\n"
+
"and emp.EmployeeCode = 16107 group by emp.EmployeeCode,\r\n"
+
" emp.FirstName"
;
System
.
out
.
println
(
"Query from fetchEmployeeLoginsBasedOnDates "
+
querys
);
for
(
int
i
=
0
;
i
<=
differentBetweenDays
;
i
++)
{
String
date1
=
fromDate
+
" "
+
fromTime
;
String
date2
=
nextDate
+
" "
+
toTime
;
if
(
i
>
0
)
{
fromDate
=
formatedFromDate
.
plusDays
(
1
).
toString
();
formatedFromDate
=
LocalDate
.
parse
(
fromDate
);
nextDate
=
formatedNextDate
.
plusDays
(
1
).
toString
();
formatedNextDate
=
LocalDate
.
parse
(
nextDate
);
date1
=
fromDate
+
" "
+
fromTime
;
date2
=
nextDate
+
" "
+
toTime
;
}
querys
=
MyTimeUtils
.
LOGIN_REPORT_BY_TIME
+
"'"
+
date1
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME2
+
"'"
+
date2
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME3
+
employeeId
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME4
;
int
countHours
=
0
;
long
totalseconds
=
0
;
try
(
Connection
connection
=
dbConnection
.
getDBConnection
();
Statement
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
querys
.
toString
()))
{
...
...
@@ -154,20 +121,10 @@ public class EmployeeDataService {
empLoginData
.
setFirstLogin
(
resultSet
.
getTime
(
"FirstLogin"
).
toString
());
empLoginData
.
setLastLogout
(
resultSet
.
getTime
(
"LastLogin"
).
toString
());
int
start
=
resultSet
.
getTime
(
"FirstLogin"
).
getHours
();
int
end
=
resultSet
.
getTime
(
"LastLogin"
).
getHours
();
if
(
end
<
start
){
LocalDateTime
loginTime
=
resultSet
.
getTimestamp
(
"FirstLogin"
).
toLocalDateTime
();
LocalDateTime
logoutTime
=
resultSet
.
getTimestamp
(
"LastLogin"
).
toLocalDateTime
();
totalseconds
=
java
.
time
.
Duration
.
between
(
loginTime
,
logoutTime
).
getSeconds
();
}
else
{
Time
from
=
resultSet
.
getTime
(
"FirstLogin"
);
Time
to
=
resultSet
.
getTime
(
"LastLogin"
);
long
milliseconds
=
to
.
getTime
()
-
from
.
getTime
();
totalseconds
=
(
int
)
milliseconds
/
1000
;
}
long
totalseconds
=
java
.
time
.
Duration
.
between
(
loginTime
,
logoutTime
).
getSeconds
();
int
hours
=
(
int
)
(
totalseconds
/
3600
);
int
minutes
=
(
int
)
((
totalseconds
%
3600
)
/
60
);
int
seconds
=
(
int
)
((
totalseconds
%
3600
)
%
60
);
...
...
@@ -175,7 +132,9 @@ public class EmployeeDataService {
empLoginData
.
setTotalLoginTime
(
hours
+
":"
+
minutes
+
":"
+
seconds
);
Date
d
=
MyTimeUtils
.
tdf
.
parse
(
empLoginData
.
getTotalLoginTime
());
countHours
+=
d
.
getTime
();
listOfEmpLoginData
.
add
(
empLoginData
);
}
if
(!
listOfEmpLoginData
.
isEmpty
())
{
listOfEmpLoginData
.
get
(
0
).
setTotalAvgTime
(
MyTimeUtils
.
tdf
.
format
(
countHours
/
listOfEmpLoginData
.
size
()));
...
...
@@ -190,9 +149,4 @@ public class EmployeeDataService {
return
listOfEmpLoginData
;
}
private
LocalDate
LocalDate
(
String
toDate
)
{
// TODO Auto-generated method stub
return
null
;
}
}
\ No newline at end of file
src/main/java/com/nisum/mytime/utils/MyTimeUtils.java
View file @
47402225
...
...
@@ -100,6 +100,14 @@ public class MyTimeUtils {
public
final
static
String
ALL
=
"All"
;
public
final
static
String
SHIFT
=
"Shift"
;
public
final
static
String
LOGIN_REPORT_BY_TIME
=
"select emp.EmployeeCode,emp.FirstName,MIN(tr.aDateTime) AS FirstLogin,MAX(tr.aDateTime) AS LastLogin \n"
+
" from [smartiSCC].[dbo].[Transactions] as tr,[smartiSCC].[dbo].[EmployeeMaster] as emp \n"
+
" where tr.EmployeemasterID=emp.EmployeeMasterID and \n"
+
" tr.aDateTime >= "
;
public
final
static
String
LOGIN_REPORT_BY_TIME2
=
" and tr.aDateTime<= "
;
public
final
static
String
LOGIN_REPORT_BY_TIME3
=
" and emp.EmployeeCode = "
;
public
final
static
String
LOGIN_REPORT_BY_TIME4
=
" group by emp.EmployeeCode, emp.FirstName "
;
// Role Mapping Info
public
static
final
String
ACCOUNT
=
"Delivery Manager"
;
public
static
final
String
DOMAIN
=
"Delivery Lead"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment