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 {
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
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 {
List<AttendenceData> lisOfAttendenceData = attendanceService
.getAttendanciesReport(reportDate);
List<AttendenceData> lisOfAttendenceData = attendanceService.getAttendanciesReport(reportDate,shift);
return new ResponseEntity<>(lisOfAttendenceData, HttpStatus.OK);
}
......@@ -77,14 +77,6 @@ public class AttendanceController {
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}",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
......
......@@ -22,7 +22,7 @@ public class AttendenceData implements Serializable {
private String employeeId;
private String employeeName;
private String ifPresent;
private String present;
private int totalPresent;
private int totalAbsent;
......
package com.nisum.mytime.repository;
import java.util.List;
import java.util.Optional;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
......@@ -12,27 +13,17 @@ public interface ProjectTeamMatesRepo
List<ProjectTeamMate> findByProjectId(String projectId);
// List<ProjectTeamMate> findByManagerId(String projectId);
// List<ProjectTeamMate> findByManagerIds(String managerId);
List<ProjectTeamMate> findByEmployeeId(String employeeId);
ProjectTeamMate findById(ObjectId id);
/* ProjectTeamMate findByEmployeeIdAndManagerId(String employeeId,
String managerId);*/
ProjectTeamMate findByEmployeeIdAndProjectId(String employeeId,
String projectId);
ProjectTeamMate findByEmployeeIdAndProjectId(String employeeId,String projectId);
List<ProjectTeamMate> findByEmployeeIdAndActive(String employeeId,
boolean status);
List<ProjectTeamMate> findByEmployeeIdAndActive(String employeeId,boolean status);
List<ProjectTeamMate> findByEmployeeIdAndProjectIdAndActive(
String employeeId, String projectId, boolean status);
List<ProjectTeamMate> findByAccountAndActiveAndBillableStatus(
String account, boolean status, String billableStatus);
List<ProjectTeamMate> findByEmployeeIdAndProjectIdAndActive(String employeeId, String projectId, boolean status);
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;
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;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nisum.mytime.configuration.DbConnection;
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.MyTimeUtils;
......@@ -23,30 +25,96 @@ public class AttendanceServiceImpl implements AttendanceService {
@Autowired
DbConnection dbConnection;
@Autowired
ProjectTeamMatesRepo projectTeamMatesRepo;
@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();
List listOfEmployees = new ArrayList<>();
String querys=MyTimeUtils.ATTENDANCE_PRESENT_REPORT_QUERY +"'"+reportDate+"'"+ MyTimeUtils.UNION +MyTimeUtils.ATTENDANCE_ABSENT_REPORT_QUERY+"'"+reportDate+"')";
try(Connection connection = dbConnection.getDBConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(querys.toString()))
{
while (resultSet.next()) {
AttendenceData attendData=new AttendenceData();
attendData.setEmployeeId(resultSet.getString("EmployeeCode"));
attendData.setEmployeeName(resultSet.getString("FirstName"));
attendData.setIfPresent(resultSet.getString("AttStatus"));
listOfEmployees.add(attendData);
}
MyTimeLogger.getInstance().info("Time Taken for " + (System.currentTimeMillis() - start_ms));
} catch (Exception e) {
MyTimeLogger.getInstance().error("Exception occured due to : ", e);
throw new MyTimeException(e.getMessage());
}
List<AttendenceData> listOfEmployees = getEmpsAttendenceByShiftWise(reportDate,shift);
MyTimeLogger.getInstance().info("Time Taken for " + (System.currentTimeMillis() - start_ms));
return listOfEmployees;
}
private List<AttendenceData> getEmpsAttendenceByShiftWise(String reportDate,String shift) throws MyTimeException {
String query = null;
List<String> presentList = null;
List<String> empIdList = null;
List<AttendenceData> listOfEmployees = new ArrayList<AttendenceData>();
Optional<List<ProjectTeamMate>> list = findEmpIdsByShiftWise(shift);
if(list.isPresent()) {
empIdList = list.get().stream()
.map(ProjectTeamMate::getEmployeeId)
.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;
}
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 {
" 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 = "P";
public final static String ABSENT = "A";
public final static String ALL = "All";
public final static String SHIFT = "Shift";
// Role Mapping Info
public static final String ACCOUNT = "Delivery Manager";
public static final String DOMAIN = "Delivery Lead";
......
......@@ -63,9 +63,9 @@ public class AttendanceControllerTest {
@Test
public void testattendanciesReport() throws Exception{
List<AttendenceData> lisOfAttendenceData = createAttendenceData();
when(attendanceService.getAttendanciesReport("2017-12-29")).thenReturn(lisOfAttendenceData);
mockMvc.perform(get("/attendance/attendanciesReport/2017-12-29")).andExpect(MockMvcResultMatchers.status().isOk());
verify(attendanceService).getAttendanciesReport("2017-12-29");
when(attendanceService.getAttendanciesReport("2017-12-29","All")).thenReturn(lisOfAttendenceData);
mockMvc.perform(get("/attendance/attendanciesReport/2017-12-29").param("All")).andExpect(MockMvcResultMatchers.status().isOk());
verify(attendanceService).getAttendanciesReport("2017-12-29","All");
}
@Test
......@@ -80,14 +80,14 @@ public class AttendanceControllerTest {
AttendenceData record1=new AttendenceData();
record1.setEmployeeId("16127");
record1.setEmployeeName("Monika Srivastava");
record1.setIfPresent("Present");
record1.setPresent("Present");
record1.setTotalAbsent(0);
record1.setTotalPresent(31);
AttendenceData record2=new AttendenceData();
record2.setEmployeeId("16157");
record2.setEmployeeName("Syed Parveen");
record2.setIfPresent("Present");
record2.setPresent("Present");
record2.setTotalAbsent(0);
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