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
6e6f159f
Commit
6e6f159f
authored
Sep 06, 2018
by
Mahesh Mudrakola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MT-175:Code Refactor for Login Report based on Date Time
parent
fd6b1cf9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
155 additions
and
145 deletions
+155
-145
AttendanceServiceImpl.java
.../java/com/nisum/mytime/service/AttendanceServiceImpl.java
+6
-27
EmployeeDataService.java
...in/java/com/nisum/mytime/service/EmployeeDataService.java
+104
-118
IEmployeeDataService.java
...n/java/com/nisum/mytime/service/IEmployeeDataService.java
+11
-0
CommomUtil.java
src/main/java/com/nisum/mytime/utils/CommomUtil.java
+34
-0
No files found.
src/main/java/com/nisum/mytime/service/AttendanceServiceImpl.java
View file @
6e6f159f
...
...
@@ -23,6 +23,7 @@ import com.nisum.mytime.model.AttendenceData;
import
com.nisum.mytime.model.EmpLoginData
;
import
com.nisum.mytime.model.ProjectTeamMate
;
import
com.nisum.mytime.repository.ProjectTeamMatesRepo
;
import
com.nisum.mytime.utils.CommomUtil
;
import
com.nisum.mytime.utils.MyTimeLogger
;
import
com.nisum.mytime.utils.MyTimeUtils
;
import
com.nisum.mytime.utils.PdfReportGenerator
;
...
...
@@ -53,34 +54,12 @@ public class AttendanceServiceImpl implements AttendanceService {
@Override
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
);
//Required Format
String
timeFrom
=
displayFormat
.
format
(
from
);
String
timeTo
=
displayFormat
.
format
(
to
);
//Getting Hours from Time
String
nextDate
=
fromDate
;
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
();
}
return
employeeDataBaseService
.
fetchEmployeeLoginsBasedOnDatesTime
(
id
,
fromDate
,
nextDate
,
toDate
,
timeFrom
,
timeTo
);
String
timeFrom
=
CommomUtil
.
convertTimeFormat
(
fromTime
);
String
timeTo
=
CommomUtil
.
convertTimeFormat
(
toTime
);
String
nextDayDate
=
CommomUtil
.
getNextDay
(
fromDate
,
fromTime
,
toTime
);
return
employeeDataBaseService
.
fetchEmployeeLoginsBasedOnDatesTime
(
id
,
fromDate
,
nextDayDate
,
toDate
,
timeFrom
,
timeTo
);
}
@Override
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
...
...
src/main/java/com/nisum/mytime/service/EmployeeDataService.java
View file @
6e6f159f
...
...
@@ -4,10 +4,6 @@ import java.sql.Connection;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
java.sql.Time
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.Duration
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.Period
;
...
...
@@ -24,17 +20,19 @@ import org.springframework.stereotype.Component;
import
com.nisum.mytime.configuration.DbConnection
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.model.EmpLoginData
;
import
com.nisum.mytime.utils.CommomUtil
;
import
com.nisum.mytime.utils.MyTimeLogger
;
import
com.nisum.mytime.utils.MyTimeUtils
;
@Component
@Transactional
public
class
EmployeeDataService
{
public
class
EmployeeDataService
implements
IEmployeeDataService
{
@Autowired
DbConnection
dbConnection
;
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDates
(
long
employeeId
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
{
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDates
(
long
employeeId
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
{
long
start_ms
=
System
.
currentTimeMillis
();
String
querys
=
null
;
if
(
employeeId
==
0
)
{
...
...
@@ -44,75 +42,57 @@ public class EmployeeDataService {
}
else
{
querys
=
MyTimeUtils
.
ABESENT_STATUS_QUERY
+
"'"
+
fromDate
.
replace
(
"-"
,
"/"
)
+
"'"
+
MyTimeUtils
.
ABESENT_STATUS_QUERY1
+
"'"
+
toDate
.
replace
(
"-"
,
"/"
)
+
"'"
+
MyTimeUtils
.
ABESENT_STATUS_QUERY2
+
employeeId
+
MyTimeUtils
.
ABESENT_STATUS_QUERY3
;
}
int
countHours
=
0
;
List
<
EmpLoginData
>
listOfEmpLoginData
=
new
ArrayList
<>();
try
(
Connection
connection
=
dbConnection
.
getDBConnection
();
Statement
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
querys
.
toString
()))
{
while
(
resultSet
.
next
())
{
EmpLoginData
empLoginData
=
new
EmpLoginData
();
empLoginData
.
setEmployeeId
(
resultSet
.
getString
(
"EmployeeCode"
));
empLoginData
.
setEmployeeName
(
resultSet
.
getString
(
"FirstName"
));
empLoginData
.
setDateOfLogin
(
resultSet
.
getDate
(
"FirstLogin"
).
toString
());
empLoginData
.
setFirstLogin
(
resultSet
.
getTime
(
"FirstLogin"
).
toString
());
empLoginData
.
setLastLogout
(
resultSet
.
getTime
(
"LastLogin"
).
toString
());
Time
from
=
resultSet
.
getTime
(
"FirstLogin"
);
Time
to
=
resultSet
.
getTime
(
"LastLogin"
);
long
milliseconds
=
to
.
getTime
()
-
from
.
getTime
();
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
();
listOfEmpLoginData
.
add
(
empLoginData
);
}
if
(!
listOfEmpLoginData
.
isEmpty
())
{
listOfEmpLoginData
.
get
(
0
).
setTotalAvgTime
(
MyTimeUtils
.
tdf
.
format
(
countHours
/
listOfEmpLoginData
.
size
()));
}
MyTimeLogger
.
getInstance
().
info
(
" Time Taken fecth Employee data based on Dates ::: "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
MyTimeLogger
.
getInstance
().
error
(
e
.
getMessage
());
throw
new
MyTimeException
(
e
.
getMessage
());
+
MyTimeUtils
.
ABESENT_STATUS_QUERY2
+
employeeId
+
MyTimeUtils
.
ABESENT_STATUS_QUERY3
;
}
List
<
EmpLoginData
>
listOfEmpLoginData
=
executeQuery
(
querys
,
1
);
MyTimeLogger
.
getInstance
()
.
info
(
" Time Taken fecth Employee data based on Dates ::: "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
return
listOfEmpLoginData
;
}
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDatesTime
(
long
employeeId
,
String
fromDate
,
String
nextDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
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
();
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
=
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
;
String
query
=
null
;
List
<
EmpLoginData
>
resultSetData
=
new
ArrayList
<>();
List
<
EmpLoginData
>
listOfEmpLoginDetails
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
differentBetweenDays
;
i
++)
{
String
fromDateTime
=
fromDate
+
" "
+
fromTime
;
String
toDateTime
=
nextDate
+
" "
+
toTime
;
if
(
i
>
0
)
{
fromDate
=
formatedFromDate
.
plusDays
(
1
).
toString
();
formatedFromDate
=
LocalDate
.
parse
(
fromDate
);
nextDate
=
formatedNextDate
.
plusDays
(
1
).
toString
();
formatedNextDate
=
LocalDate
.
parse
(
nextDate
);
fromDateTime
=
fromDate
+
" "
+
fromTime
;
toDateTime
=
nextDate
+
" "
+
toTime
;
}
if
(
i
==
differentBetweenDays
&&
formatedNextDate
==
LocalDate
.
now
())
{
toDateTime
=
nextDate
+
" "
+
"23:59"
;
}
query
=
MyTimeUtils
.
LOGIN_REPORT_BY_TIME
+
"'"
+
fromDateTime
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME2
+
"'"
+
toDateTime
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME3
+
employeeId
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME4
;
resultSetData
=
executeQuery
(
query
,
2
);
listOfEmpLoginDetails
.
add
(
resultSetData
.
get
(
0
));
MyTimeLogger
.
getInstance
().
info
(
" Time Taken fecth Employee data based on Dates ::: "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
}
return
listOfEmpLoginDetails
;
}
querys
=
MyTimeUtils
.
LOGIN_REPORT_BY_TIME
+
"'"
+
date1
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME2
+
"'"
+
date2
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME3
+
employeeId
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME4
;
private
List
<
EmpLoginData
>
executeQuery
(
String
query
,
int
flag
)
throws
MyTimeException
{
long
start_ms
=
System
.
currentTimeMillis
();
long
totalseconds
=
0
;
int
countHours
=
0
;
List
<
EmpLoginData
>
listOfEmpLoginData
=
new
ArrayList
<>();
try
(
Connection
connection
=
dbConnection
.
getDBConnection
();
Statement
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
querys
.
toString
()))
{
ResultSet
resultSet
=
statement
.
executeQuery
(
query
.
toString
()))
{
while
(
resultSet
.
next
())
{
EmpLoginData
empLoginData
=
new
EmpLoginData
();
empLoginData
.
setEmployeeId
(
resultSet
.
getString
(
"EmployeeCode"
));
...
...
@@ -120,32 +100,38 @@ public class EmployeeDataService {
empLoginData
.
setDateOfLogin
(
resultSet
.
getDate
(
"FirstLogin"
).
toString
());
empLoginData
.
setFirstLogin
(
resultSet
.
getTime
(
"FirstLogin"
).
toString
());
empLoginData
.
setLastLogout
(
resultSet
.
getTime
(
"LastLogin"
).
toString
());
LocalDateTime
loginTime
=
resultSet
.
getTimestamp
(
"FirstLogin"
).
toLocalDateTime
();
LocalDateTime
logoutTime
=
resultSet
.
getTimestamp
(
"LastLogin"
).
toLocalDateTime
();
long
totalseconds
=
java
.
time
.
Duration
.
between
(
loginTime
,
logoutTime
).
getSeconds
();
if
(
flag
==
1
)
{
Time
from
=
resultSet
.
getTime
(
"FirstLogin"
);
Time
to
=
resultSet
.
getTime
(
"LastLogin"
);
long
milliseconds
=
to
.
getTime
()
-
from
.
getTime
();
totalseconds
=
milliseconds
/
1000
;
}
if
(
flag
==
2
)
{
LocalDateTime
loginTime
=
resultSet
.
getTimestamp
(
"FirstLogin"
).
toLocalDateTime
();
LocalDateTime
logoutTime
=
resultSet
.
getTimestamp
(
"LastLogin"
).
toLocalDateTime
();
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
);
empLoginData
.
setTotalLoginTime
(
hours
+
":"
+
minutes
+
":"
+
seconds
);
Date
d
=
MyTimeUtils
.
tdf
.
parse
(
empLoginData
.
getTotalLoginTime
());
countHours
+=
d
.
getTime
();
empLoginData
.
setTotalLoginTime
(
CommomUtil
.
appendZero
(
hours
)
+
":"
+
CommomUtil
.
appendZero
(
minutes
)
+
":"
+
CommomUtil
.
appendZero
(
seconds
));
listOfEmpLoginData
.
add
(
empLoginData
);
}
if
(!
listOfEmpLoginData
.
isEmpty
())
{
if
(
flag
==
1
&&
!
listOfEmpLoginData
.
isEmpty
())
{
Date
loginTime
=
MyTimeUtils
.
tdf
.
parse
(
empLoginData
.
getTotalLoginTime
());
countHours
+=
loginTime
.
getTime
();
listOfEmpLoginData
.
get
(
0
).
setTotalAvgTime
(
MyTimeUtils
.
tdf
.
format
(
countHours
/
listOfEmpLoginData
.
size
()));
}
MyTimeLogger
.
getInstance
().
info
(
" Time Taken fecth Employee data based on Dates ::: "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
MyTimeLogger
.
getInstance
()
.
info
(
" Time Taken to execute the query to fecth Employee data based on Dates ::: "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
MyTimeLogger
.
getInstance
().
error
(
e
.
getMessage
());
throw
new
MyTimeException
(
e
.
getMessage
());
}
}
return
listOfEmpLoginData
;
}
}
\ No newline at end of file
src/main/java/com/nisum/mytime/service/IEmployeeDataService.java
0 → 100644
View file @
6e6f159f
package
com
.
nisum
.
mytime
.
service
;
import
java.util.List
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.model.EmpLoginData
;
public
interface
IEmployeeDataService
{
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDates
(
long
employeeId
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
;
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDatesTime
(
long
employeeId
,
String
fromDate
,
String
nextDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
;
}
src/main/java/com/nisum/mytime/utils/CommomUtil.java
View file @
6e6f159f
package
com
.
nisum
.
mytime
.
utils
;
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
;
public
class
CommomUtil
{
...
...
@@ -24,4 +29,33 @@ public class CommomUtil {
return
deletedManager
;
}
public
static
String
appendZero
(
int
val
)
{
return
val
<
10
?(
"0"
+
val
):(
val
+
""
);
}
public
static
String
convertTimeFormat
(
String
time
)
throws
ParseException
{
SimpleDateFormat
displayFormat
=
new
SimpleDateFormat
(
"HH:mm"
);
SimpleDateFormat
parseFormat
=
new
SimpleDateFormat
(
"hh:mm a"
);
Date
from
=
parseFormat
.
parse
(
time
);
return
displayFormat
.
format
(
from
);
}
public
static
String
getNextDay
(
String
fromDate
,
String
fromTime
,
String
toTime
)
throws
ParseException
{
String
timeSignFrom
=
fromTime
.
substring
(
6
,
8
);
String
timeSignTo
=
toTime
.
substring
(
6
,
8
);
String
timeFrom
=
convertTimeFormat
(
fromTime
);
String
timeTo
=
convertTimeFormat
(
toTime
);
//Getting Hours from Time
String
nextDate
=
fromDate
;
int
hoursFrom
=
Integer
.
parseInt
(
timeFrom
.
substring
(
0
,
2
));
int
hoursTo
=
Integer
.
parseInt
(
timeTo
.
substring
(
0
,
2
));
if
(
hoursTo
<=
hoursFrom
&&
timeSignFrom
.
equals
(
timeSignTo
)
||
hoursTo
<=
hoursFrom
/*this condition is applicable if fromTime is PM & toTime is AM*/
)
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-d"
);
LocalDate
nextDay
=
(
LocalDate
.
parse
(
fromDate
,
formatter
)).
plusDays
(
1
);
nextDate
=
nextDay
.
toString
();
}
return
nextDate
;
}
}
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