Unverified Commit e70d4af7 authored by mduppanapudi-nisum-com's avatar mduppanapudi-nisum-com Committed by GitHub

Merge pull request #174 from nisum-inc/FEATURE/MT-167-PerformanceImprovement

Improve performance on click of search button
parents c22777b2 5275656e
......@@ -39,8 +39,7 @@ public class AttendanceController {
@RequestParam("toDate") String toDate) throws MyTimeException {
List<EmpLoginData> message = new ArrayList<>();
try {
message = userService.employeeLoginsBasedOnDate(id, fromDate,
toDate);
message = userService.employeeLoginsBasedOnDate(id, fromDate, toDate);
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -2,7 +2,6 @@ package com.nisum.mytime.service;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
......@@ -30,35 +29,29 @@ public class AttendanceServiceImpl implements AttendanceService {
ProjectTeamMatesRepo projectTeamMatesRepo;
@Override
public List<AttendenceData> getAttendanciesReport(String reportDate, String shift) throws MyTimeException, SQLException {
public List<AttendenceData> getAttendanciesReport(String reportDate, String shift) throws MyTimeException {
long start_ms = System.currentTimeMillis();
List<AttendenceData> listOfEmployees = getEmpsAttendenceByShiftWise(reportDate,shift);
String reportDateInReqDateFormat = reportDate.replace("-", "/");
List<AttendenceData> listOfEmployees = getEmpsAttendenceByShiftWise(reportDateInReqDateFormat, shift);
MyTimeLogger.getInstance().info("Time Taken for " + (System.currentTimeMillis() - start_ms));
return listOfEmployees;
}
private List<AttendenceData> getEmpsAttendenceByShiftWise(String reportDate,String shift) throws MyTimeException {
private List<AttendenceData> getEmpsAttendenceByShiftWise(String reportDate, String shift) throws MyTimeException {
List<AttendenceData> listOfEmployees = new ArrayList<AttendenceData>();
Optional<List<ProjectTeamMate>> list = findEmpIdsByShiftWise(shift);
if(list.isPresent()) {
List<String> empIdList = list.get().stream()
.map(ProjectTeamMate::getEmployeeId)
.collect(Collectors.toList());
if(null != empIdList && empIdList.size() == MyTimeUtils.INT_ZERO) {
return listOfEmployees;
}
String query = buildSqlQuery(reportDate,empIdList.toString().substring(1, empIdList.toString().length()-1),MyTimeUtils.PRESENT);
listOfEmployees.addAll(getAttendenceData(query));
List<String> presentList = listOfEmployees.stream().map(AttendenceData :: getEmployeeId).collect(Collectors.toList());
empIdList.removeAll(presentList);
if(empIdList.size()>0) {
query = buildSqlQuery(reportDate, empIdList.toString().substring(1, empIdList.toString().length()-1), MyTimeUtils.ABSENT);
listOfEmployees .addAll(getAttendenceData(query));
List<String> empIdList = list.get().stream().map(ProjectTeamMate::getEmployeeId).collect(Collectors.toList());
if(null != empIdList && empIdList.size() > MyTimeUtils.INT_ZERO) {
String query = buildSqlQuery(reportDate,empIdList.toString().substring(1, empIdList.toString().length()-1), MyTimeUtils.PRESENT);
listOfEmployees.addAll(getAttendenceData(query, MyTimeUtils.PRESENT));
List<String> presentList = listOfEmployees.stream().map(AttendenceData :: getEmployeeId).collect(Collectors.toList());
empIdList.removeAll(presentList);
if(empIdList.size() > MyTimeUtils.INT_ZERO) {
query = buildSqlQuery(reportDate, empIdList.toString().substring(1, empIdList.toString().length()-1), MyTimeUtils.ABSENT);
listOfEmployees .addAll(getAttendenceData(query, MyTimeUtils.ABSENT));
}
}
}
return listOfEmployees;
......@@ -66,7 +59,6 @@ public class AttendanceServiceImpl implements AttendanceService {
private Optional<List<ProjectTeamMate>> findEmpIdsByShiftWise(String shift) {
Optional<List<ProjectTeamMate>> list = null;
if(MyTimeUtils.ALL.equalsIgnoreCase(shift)) {
list = projectTeamMatesRepo.findByActiveAndShiftLikeOrderByEmployeeIdDesc( true, MyTimeUtils.SHIFT);
}else {
......@@ -75,46 +67,38 @@ public class AttendanceServiceImpl implements AttendanceService {
return list;
}
private String buildSqlQuery(String reportDate, String empIdsStr,String type) {
private String buildSqlQuery(String reportDate, String empIdsStr, String type) {
String query = null;
if(MyTimeUtils.PRESENT.equals(type)) {
query = MyTimeUtils.PRESENT_QUERY
.replace("<TYPE>", type)
.replace("<REPORTDATE>", reportDate)
query = MyTimeUtils.PRESENT_QUERY.replace("<REPORTDATE>", reportDate)
.replace("<EMPIDS>",empIdsStr);
}else {
query = MyTimeUtils.ABSENT_QUERY
.replace("<ABSENTLIST>", empIdsStr);
query = MyTimeUtils.ABSENT_QUERY.replace("<ABSENTLIST>", empIdsStr);
}
return query;
}
private List<AttendenceData> getAttendenceData(String query) throws MyTimeException {
private List<AttendenceData> getAttendenceData(String query, String type) throws MyTimeException {
List<AttendenceData> listOfEmployees = null;
try (Connection connection = dbConnection.getDBConnection();
try(Connection connection = dbConnection.getDBConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query)) {
AttendenceData attendData = null;
listOfEmployees = new ArrayList<AttendenceData>();
while (resultSet.next()) {
attendData = new AttendenceData();
attendData.setEmployeeId(resultSet.getString("EmployeeCode"));
attendData.setEmployeeName(resultSet.getString("FirstName"));
attendData.setPresent(resultSet.getString("AttStatus"));
attendData.setPresent(type);
listOfEmployees.add(attendData);
attendData = null;
}
}catch (Exception e) {
} catch (Exception e) {
MyTimeLogger.getInstance().error("Exception occured due to : ", e);
throw new MyTimeException(e.getMessage());
}
return listOfEmployees;
}
}
......@@ -26,36 +26,32 @@ public class EmployeeDataService {
@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)
querys = MyTimeUtils.ABESENT_STATUS_QUERY + "'" + fromDate + "'"
+ MyTimeUtils.ABESENT_STATUS_QUERY1 + "'" + toDate + "'"
if (employeeId == 0) {
querys = MyTimeUtils.ABESENT_STATUS_QUERY + "'" + fromDate.replace("-", "/") + "'"
+ MyTimeUtils.ABESENT_STATUS_QUERY1 + "'" + toDate.replace("-", "/") + "'"
+ MyTimeUtils.ABESENT_STATUS_QUERY3;
else
querys = MyTimeUtils.ABESENT_STATUS_QUERY + "'" + fromDate + "'"
+ MyTimeUtils.ABESENT_STATUS_QUERY1 + "'" + toDate + "'"
} 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())) {
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());
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();
......@@ -64,31 +60,21 @@ public class EmployeeDataService {
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());
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()));
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 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
......@@ -114,10 +114,8 @@ public class UserServiceImpl implements UserService {
}
@Override
public List<EmpLoginData> employeeLoginsBasedOnDate(long id,
String fromDate, String toDate) throws MyTimeException {
return employeeDataBaseService.fetchEmployeeLoginsBasedOnDates(id,
fromDate, toDate);
public List<EmpLoginData> employeeLoginsBasedOnDate(long id, String fromDate, String toDate) throws MyTimeException {
return employeeDataBaseService.fetchEmployeeLoginsBasedOnDates(id, fromDate, toDate);
}
@Override
......
......@@ -28,14 +28,14 @@ public class MyTimeUtils {
public final static String COLON = ":";
public final static String EMP_NAME_QUERY = "SELECT * FROM EMPLOYEES Where EMPLOYEECODE=?";
public final static String WORKING_EMPLOYEES = "SELECT * FROM EMPLOYEES WHERE EMPLOYEECODE NOT IN(SELECT UserId FROM DeviceLogs_12_2017 WHERE LogDate BETWEEN '2017-12-27 06:00:00' AND '2017-12-27 11:00:00') AND STATUS='Working'";
public final static String QUERY = "SELECT * FROM DeviceLogs_";
public final static String USERID_QUERY = "SELECT USERID FROM DeviceLogs_";
public final static String WHERE_COND = " WHERE LogDate between '";
//public final static String WORKING_EMPLOYEES = "SELECT * FROM EMPLOYEES WHERE EMPLOYEECODE NOT IN(SELECT UserId FROM DeviceLogs_12_2017 WHERE LogDate BETWEEN '2017-12-27 06:00:00' AND '2017-12-27 11:00:00') AND STATUS='Working'";
//public final static String QUERY = "SELECT * FROM DeviceLogs_";
//public final static String USERID_QUERY = "SELECT USERID FROM DeviceLogs_";
//public final static String WHERE_COND = " WHERE LogDate between '";
public final static String AND_COND = " AND '";
public final static String SINGLE_QUOTE = "'";
public final static String ABESENT_QUERY = "SELECT * FROM EMPLOYEES WHERE EMPLOYEECODE NOT IN(";
public final static String ABESENT_QUERY1 = ") AND STATUS='Working' AND EMPLOYEECODE NOT LIKE 'del%' ";
//public final static String ABESENT_QUERY = "SELECT * FROM EMPLOYEES WHERE EMPLOYEECODE NOT IN(";
//public final static String ABESENT_QUERY1 = ") AND STATUS='Working' AND EMPLOYEECODE NOT LIKE 'del%' ";
public final static String ABESENT = "Absent";
public final static String EMAIL_ID = "emailId";
......@@ -80,26 +80,16 @@ public class MyTimeUtils {
+ "MIN(tr.aDateTime) AS FirstLogin,MAX(tr.aDateTime) AS LastLogin\n" +
"from Transactions as tr,EmployeeMaster as emp\n" +
"where tr.EmployeemasterID=emp.EmployeeMasterID and \n" +
"replace(convert(varchar,tr.aDateTime, 111), '/', '-')>= ";
public final static String ABESENT_STATUS_QUERY1 =" and \n" +
"replace(convert(varchar,tr.aDateTime, 111), '/', '-')<= ";
public final static String ABESENT_STATUS_QUERY2 =" and emp.EmployeeCode=";
public final static String ABESENT_STATUS_QUERY3 =" group by convert(varchar,tr.aDateTime, 111),emp.EmployeeCode,emp.FirstName";
"convert(varchar,tr.aDateTime, 111) >= ";
public final static String ATTENDANCE_PRESENT_REPORT_QUERY ="select distinct emp.EmployeeCode,emp.FirstName,'P' as AttStatus\n" +
" FROM Transactions as tr,EmployeeMaster as emp where tr.EmployeemasterID=emp.EmployeeMasterID and \n" +
" replace(convert(varchar,tr.aDateTime, 111), '/', '-')= ";
public final static String ABESENT_STATUS_QUERY1 =" and convert(varchar,tr.aDateTime, 111) <= ";
public final static String ABESENT_STATUS_QUERY2 =" and emp.EmployeeCode = ";
public final static String ABESENT_STATUS_QUERY3 =" group by convert(varchar,tr.aDateTime, 111), emp.EmployeeCode, emp.FirstName";
public final static String UNION=" Union ";
public final static String ATTENDANCE_ABSENT_REPORT_QUERY= "select distinct M.EmployeeCode,M.FirstName,'A' as AttStatus from [smartiSCC].[dbo].[EmployeeMaster] M \n" +
"where M.EmployeeCode not in \n" +
" (select distinct emp.EmployeeCode \n" +
" FROM Transactions as tr,EmployeeMaster as emp \n" +
" where tr.EmployeemasterID=emp.EmployeeMasterID and \n" +
" replace(convert(varchar,tr.aDateTime, 111), '/', '-')=";
public final static String PRESENT_QUERY = "SELECT DISTINCT Emp.EmployeeCode,Emp.FirstName,'<TYPE>' AS AttStatus FROM Transactions AS Tr,EmployeeMaster AS Emp WHERE Tr.EmployeemasterID = Emp.EmployeeMasterID AND REPLACE(CONVERT(VARCHAR,Tr.aDateTime, 111), '/', '-')= '<REPORTDATE>' AND Emp.EmployeeCode IN (<EMPIDS>)";
public final static String ABSENT_QUERY = "SELECT [EmployeeCode], [FirstName],'A' AS AttStatus FROM [smartiSCC].[dbo].[EmployeeMaster] WHERE [EmployeeCode] IN(<ABSENTLIST>)";
public final static String PRESENT_QUERY = "SELECT DISTINCT Emp.EmployeeCode, Emp.FirstName FROM Transactions AS Tr, EmployeeMaster AS Emp WHERE Tr.EmployeemasterID = Emp.EmployeeMasterID AND CONVERT(VARCHAR,Tr.aDateTime, 111) = '<REPORTDATE>' AND Emp.EmployeeCode IN (<EMPIDS>)";
public final static String ABSENT_QUERY = "SELECT [EmployeeCode], [FirstName] FROM [EmployeeMaster] WHERE [EmployeeCode] IN(<ABSENTLIST>)";
public final static String PRESENT = "P";
public final static String ABSENT = "A";
......
......@@ -39,6 +39,8 @@ spring.mvc.favicon.enabled = false
#MS SQL configuration
myTime.data.mssqldb.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
myTime.data.mssqldb.url=jdbc:sqlserver://10.3.45.105:1433;databaseName=smartiSCC
#myTime.data.mssqldb.url=jdbc:sqlserver://10.3.45.105:1433;databaseName=smartiSCC
myTime.data.mssqldb.url=jdbc:sqlserver://10.3.45.218:1433;databaseName=smartiSCC
myTime.data.mssqldb.username=sa
myTime.data.mssqldb.password=nisum@123
\ No newline at end of file
#myTime.data.mssqldb.password=nisum@123
myTime.data.mssqldb.password=admin@123
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment