Commit 254a5363 authored by bsatyanarayana-nisum-com's avatar bsatyanarayana-nisum-com Committed by rbonthala-nisum-com

MT-167_1 :SNS :: Able_to_see_attendance_report_shift_wise (#169)

parent 121c7b94
...@@ -60,10 +60,10 @@ public class AttendanceController { ...@@ -60,10 +60,10 @@ public class AttendanceController {
method = RequestMethod.GET, method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<AttendenceData>> attendanciesReport( public ResponseEntity<List<AttendenceData>> attendanciesReport(
@PathVariable("reportDate") String reportDate) @PathVariable("reportDate") String reportDate
,@RequestParam(value= "shift", required = false, defaultValue ="All") String shift)
throws MyTimeException, SQLException { throws MyTimeException, SQLException {
List<AttendenceData> lisOfAttendenceData = attendanceService List<AttendenceData> lisOfAttendenceData = attendanceService.getAttendanciesReport(reportDate,shift);
.getAttendanciesReport(reportDate);
return new ResponseEntity<>(lisOfAttendenceData, HttpStatus.OK); return new ResponseEntity<>(lisOfAttendenceData, HttpStatus.OK);
} }
...@@ -77,14 +77,6 @@ public class AttendanceController { ...@@ -77,14 +77,6 @@ public class AttendanceController {
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
/*
* @RequestMapping(value = "copyRemoteMdbFileToLocal", method =
* RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public
* ResponseEntity<Boolean> copyRemoteMdbFileToLocal() throws MyTimeException
* { Boolean result = attendanceService.copyRemoteMdbFileToLocal(); return
* new ResponseEntity<>(result, HttpStatus.OK); }
*/
@RequestMapping(value = "resyncMonthData/{fromDate}", @RequestMapping(value = "resyncMonthData/{fromDate}",
method = RequestMethod.POST, method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
......
...@@ -22,7 +22,7 @@ public class AttendenceData implements Serializable { ...@@ -22,7 +22,7 @@ public class AttendenceData implements Serializable {
private String employeeId; private String employeeId;
private String employeeName; private String employeeName;
private String ifPresent; private String present;
private int totalPresent; private int totalPresent;
private int totalAbsent; private int totalAbsent;
......
package com.nisum.mytime.repository; package com.nisum.mytime.repository;
import java.util.List; import java.util.List;
import java.util.Optional;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
...@@ -12,27 +13,17 @@ public interface ProjectTeamMatesRepo ...@@ -12,27 +13,17 @@ public interface ProjectTeamMatesRepo
List<ProjectTeamMate> findByProjectId(String projectId); List<ProjectTeamMate> findByProjectId(String projectId);
// List<ProjectTeamMate> findByManagerId(String projectId);
// List<ProjectTeamMate> findByManagerIds(String managerId);
List<ProjectTeamMate> findByEmployeeId(String employeeId); List<ProjectTeamMate> findByEmployeeId(String employeeId);
ProjectTeamMate findById(ObjectId id); ProjectTeamMate findById(ObjectId id);
/* ProjectTeamMate findByEmployeeIdAndManagerId(String employeeId, ProjectTeamMate findByEmployeeIdAndProjectId(String employeeId,String projectId);
String managerId);*/
ProjectTeamMate findByEmployeeIdAndProjectId(String employeeId,
String projectId);
List<ProjectTeamMate> findByEmployeeIdAndActive(String employeeId, List<ProjectTeamMate> findByEmployeeIdAndActive(String employeeId,boolean status);
boolean status);
List<ProjectTeamMate> findByEmployeeIdAndProjectIdAndActive( List<ProjectTeamMate> findByEmployeeIdAndProjectIdAndActive(String employeeId, String projectId, boolean status);
String employeeId, String projectId, boolean status);
List<ProjectTeamMate> findByAccountAndActiveAndBillableStatus(
String account, boolean status, String billableStatus);
List<ProjectTeamMate> findByAccountAndActiveAndBillableStatus( String account, boolean status, String billableStatus);
Optional<List<ProjectTeamMate>> findByActiveAndShiftLikeOrderByEmployeeIdDesc( boolean active, String shift);
} }
...@@ -8,6 +8,6 @@ import com.nisum.mytime.model.AttendenceData; ...@@ -8,6 +8,6 @@ import com.nisum.mytime.model.AttendenceData;
public interface AttendanceService { public interface AttendanceService {
List<AttendenceData> getAttendanciesReport(String reportDate) throws MyTimeException, SQLException; List<AttendenceData> getAttendanciesReport(String reportDate,String shift) throws MyTimeException, SQLException;
} }
...@@ -6,15 +6,17 @@ import java.sql.SQLException; ...@@ -6,15 +6,17 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.nisum.mytime.configuration.DbConnection; import com.nisum.mytime.configuration.DbConnection;
import com.nisum.mytime.exception.handler.MyTimeException; import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.AttendenceData; import com.nisum.mytime.model.AttendenceData;
import com.nisum.mytime.model.ProjectTeamMate;
import com.nisum.mytime.repository.ProjectTeamMatesRepo;
import com.nisum.mytime.utils.MyTimeLogger; import com.nisum.mytime.utils.MyTimeLogger;
import com.nisum.mytime.utils.MyTimeUtils; import com.nisum.mytime.utils.MyTimeUtils;
...@@ -23,30 +25,96 @@ public class AttendanceServiceImpl implements AttendanceService { ...@@ -23,30 +25,96 @@ public class AttendanceServiceImpl implements AttendanceService {
@Autowired @Autowired
DbConnection dbConnection; DbConnection dbConnection;
@Autowired
ProjectTeamMatesRepo projectTeamMatesRepo;
@Override @Override
public List getAttendanciesReport(String reportDate) throws MyTimeException, SQLException { public List<AttendenceData> getAttendanciesReport(String reportDate, String shift) throws MyTimeException, SQLException {
long start_ms = System.currentTimeMillis(); long start_ms = System.currentTimeMillis();
List listOfEmployees = new ArrayList<>(); List<AttendenceData> listOfEmployees = getEmpsAttendenceByShiftWise(reportDate,shift);
String querys=MyTimeUtils.ATTENDANCE_PRESENT_REPORT_QUERY +"'"+reportDate+"'"+ MyTimeUtils.UNION +MyTimeUtils.ATTENDANCE_ABSENT_REPORT_QUERY+"'"+reportDate+"')"; MyTimeLogger.getInstance().info("Time Taken for " + (System.currentTimeMillis() - start_ms));
try(Connection connection = dbConnection.getDBConnection(); return listOfEmployees;
Statement statement = connection.createStatement(); }
ResultSet resultSet = statement.executeQuery(querys.toString()))
{ private List<AttendenceData> getEmpsAttendenceByShiftWise(String reportDate,String shift) throws MyTimeException {
while (resultSet.next()) { String query = null;
AttendenceData attendData=new AttendenceData(); List<String> presentList = null;
attendData.setEmployeeId(resultSet.getString("EmployeeCode")); List<String> empIdList = null;
attendData.setEmployeeName(resultSet.getString("FirstName")); List<AttendenceData> listOfEmployees = new ArrayList<AttendenceData>();
attendData.setIfPresent(resultSet.getString("AttStatus"));
listOfEmployees.add(attendData); Optional<List<ProjectTeamMate>> list = findEmpIdsByShiftWise(shift);
}
MyTimeLogger.getInstance().info("Time Taken for " + (System.currentTimeMillis() - start_ms)); if(list.isPresent()) {
} catch (Exception e) { empIdList = list.get().stream()
MyTimeLogger.getInstance().error("Exception occured due to : ", e); .map(ProjectTeamMate::getEmployeeId)
throw new MyTimeException(e.getMessage()); .collect(Collectors.toList());
} }
query = buildSqlQuery(reportDate,empIdList.toString().substring(1, empIdList.toString().length()-1),MyTimeUtils.PRESENT);
listOfEmployees .addAll(getAttendenceData(query));
presentList = listOfEmployees.stream().map(AttendenceData :: getEmployeeId).collect(Collectors.toList());
empIdList.removeAll(presentList);
System.out.println("Absent List :: "+empIdList);
query = buildSqlQuery(reportDate, empIdList.toString().substring(1, empIdList.toString().length()-1), MyTimeUtils.ABSENT);
listOfEmployees .addAll(getAttendenceData(query));
return listOfEmployees; return listOfEmployees;
}
private Optional<List<ProjectTeamMate>> findEmpIdsByShiftWise(String shift) {
Optional<List<ProjectTeamMate>> list = null;
if(MyTimeUtils.ALL.equalsIgnoreCase(shift)) {
list = projectTeamMatesRepo.findByActiveAndShiftLikeOrderByEmployeeIdDesc( true, MyTimeUtils.SHIFT);
}else {
list = projectTeamMatesRepo.findByActiveAndShiftLikeOrderByEmployeeIdDesc( true,shift);
}
return list;
}
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)
.replace("<EMPIDS>",empIdsStr);
}else {
query = MyTimeUtils.ABSENT_QUERY
.replace("<ABSENTLIST>", empIdsStr);
} }
return query;
}
private List<AttendenceData> getAttendenceData(String query) throws MyTimeException {
List<AttendenceData> listOfEmployees = null;
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"));
listOfEmployees.add(attendData);
attendData = null;
}
}catch (Exception e) {
MyTimeLogger.getInstance().error("Exception occured due to : ", e);
throw new MyTimeException(e.getMessage());
}
return listOfEmployees;
} }
}
...@@ -97,6 +97,16 @@ public class MyTimeUtils { ...@@ -97,6 +97,16 @@ public class MyTimeUtils {
" where tr.EmployeemasterID=emp.EmployeeMasterID and \n" + " where tr.EmployeemasterID=emp.EmployeeMasterID and \n" +
" replace(convert(varchar,tr.aDateTime, 111), '/', '-')="; " 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 = "P";
public final static String ABSENT = "A";
public final static String ALL = "All";
public final static String SHIFT = "Shift";
// Role Mapping Info // Role Mapping Info
public static final String ACCOUNT = "Delivery Manager"; public static final String ACCOUNT = "Delivery Manager";
public static final String DOMAIN = "Delivery Lead"; public static final String DOMAIN = "Delivery Lead";
......
...@@ -63,9 +63,9 @@ public class AttendanceControllerTest { ...@@ -63,9 +63,9 @@ public class AttendanceControllerTest {
@Test @Test
public void testattendanciesReport() throws Exception{ public void testattendanciesReport() throws Exception{
List<AttendenceData> lisOfAttendenceData = createAttendenceData(); List<AttendenceData> lisOfAttendenceData = createAttendenceData();
when(attendanceService.getAttendanciesReport("2017-12-29")).thenReturn(lisOfAttendenceData); when(attendanceService.getAttendanciesReport("2017-12-29","All")).thenReturn(lisOfAttendenceData);
mockMvc.perform(get("/attendance/attendanciesReport/2017-12-29")).andExpect(MockMvcResultMatchers.status().isOk()); mockMvc.perform(get("/attendance/attendanciesReport/2017-12-29").param("All")).andExpect(MockMvcResultMatchers.status().isOk());
verify(attendanceService).getAttendanciesReport("2017-12-29"); verify(attendanceService).getAttendanciesReport("2017-12-29","All");
} }
@Test @Test
...@@ -80,14 +80,14 @@ public class AttendanceControllerTest { ...@@ -80,14 +80,14 @@ public class AttendanceControllerTest {
AttendenceData record1=new AttendenceData(); AttendenceData record1=new AttendenceData();
record1.setEmployeeId("16127"); record1.setEmployeeId("16127");
record1.setEmployeeName("Monika Srivastava"); record1.setEmployeeName("Monika Srivastava");
record1.setIfPresent("Present"); record1.setPresent("Present");
record1.setTotalAbsent(0); record1.setTotalAbsent(0);
record1.setTotalPresent(31); record1.setTotalPresent(31);
AttendenceData record2=new AttendenceData(); AttendenceData record2=new AttendenceData();
record2.setEmployeeId("16157"); record2.setEmployeeId("16157");
record2.setEmployeeName("Syed Parveen"); record2.setEmployeeName("Syed Parveen");
record2.setIfPresent("Present"); record2.setPresent("Present");
record2.setTotalAbsent(0); record2.setTotalAbsent(0);
record2.setTotalPresent(30); record2.setTotalPresent(30);
......
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