Commit a7e97f5b authored by Md Suleman's avatar Md Suleman

Sub status sevice changes

parent 1d6f10ce
......@@ -9,8 +9,10 @@ import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import com.nisum.myteam.model.dao.EmployeeSubStatus;
import com.nisum.myteam.model.dao.EmployeeVisa;
import com.nisum.myteam.repository.EmployeeVisaRepo;
import com.nisum.myteam.service.ISubStatusService;
import com.nisum.myteam.service.impl.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
......@@ -45,6 +47,9 @@ public class EmployeeController {
@Autowired
private EmployeeVisaRepo employeeVisaRepo;
@Autowired
private ISubStatusService subStatusService;
@RequestMapping(value = "/employees/{empId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createEmployee( @RequestBody Employee employeeReq,
......@@ -72,7 +77,7 @@ public class EmployeeController {
if (empService.isEmployeeExistsById(loginEmpId)) {
Employee employeeUpdated = empService.updateEmployee(employeeReq, loginEmpId);
ResponseDetails updateRespDetails = new ResponseDetails(new Date(), 906, empService.messege ,
ResponseDetails updateRespDetails = new ResponseDetails(new Date(), 906, empService.response.get("messege").toString() ,
"Employee Updation", null, request.getRequestURI(), "Updation Employee details",
employeeUpdated);
return new ResponseEntity<ResponseDetails>(updateRespDetails, HttpStatus.OK);
......@@ -267,6 +272,15 @@ public class EmployeeController {
}
@RequestMapping(value = "/subStatus", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> endSubStatus(@RequestBody EmployeeSubStatus employeeSubStatus, @RequestParam("loginEmpId") String loginEmpId ,HttpServletRequest request){
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Sub status end updated successfully",
"Emoployee sub status updated successfully", subStatusService.endSubStatus(employeeSubStatus) , request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
}
\ No newline at end of file
......@@ -4,7 +4,12 @@ import com.nisum.myteam.model.dao.EmployeeSubStatus;
public interface ISubStatusService {
public EmployeeSubStatus getLatestEmployeeSubStatus(String empId);
public EmployeeSubStatus updateExistingEmplyeeSubStatus(EmployeeSubStatus employeeSubStatusReq);
public EmployeeSubStatus addEmployeeSubStatus(EmployeeSubStatus employeeSubStatus);
public EmployeeSubStatus getCurrentSubStatus(String employeeId);
public EmployeeSubStatus endSubStatus(EmployeeSubStatus subStatus);
}
......@@ -59,7 +59,7 @@ public class EmployeeService implements IEmployeeService {
@Autowired
private ISubStatusService subStatusService;
public String message = "";
public Map<String , String> response = new HashMap<>();
@Override
public Employee createEmployee(Employee employee, String loginEmpId) throws MyTeamException {
......@@ -78,7 +78,7 @@ public class EmployeeService implements IEmployeeService {
@Override
public Employee updateEmployee(Employee employeeReq, String loginEmpId) throws ParseException {
message = "Employee has been updated";
response.put("messege" , "Employee has been updated");
// update all emp details to inactive if employee is inactive
Query query = new Query(Criteria.where("employeeId").is(employeeReq.getEmployeeId()));
Update update = new Update();
......@@ -118,21 +118,22 @@ public class EmployeeService implements IEmployeeService {
//update substatus
if(employeeReq.getEmpSubStatus()!=null) {
HashMap<String,Object> substatus = (LinkedHashMap)employeeReq.getEmpSubStatus();
EmployeeSubStatus latestSubStatus = new EmployeeSubStatus();
latestSubStatus.setEmployeeID(substatus.get("employeeID").toString());
latestSubStatus.setSubStatus(substatus.get("subStatus").toString());
latestSubStatus.setFromDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(substatus.get("fromDate").toString()));
latestSubStatus.setToDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(substatus.get("toDate").toString()));
EmployeeSubStatus currentSubStatus = subStatusService.getCurrentSubStatus(employeeReq.getEmployeeId());
if (currentSubStatus != null ){
if(currentSubStatus.getSubStatus().equals(latestSubStatus.getSubStatus())) {
latestSubStatus.setId(currentSubStatus.getId());
subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus);
}else{
message = "Employee is already "+currentSubStatus.getSubStatus()+" from "+currentSubStatus.getFromDate()+" to "+currentSubStatus.getToDate();
}
}else{
HashMap<String, Object> substatus = (LinkedHashMap) employeeReq.getEmpSubStatus();
if (substatus.keySet().contains("subStatus")) {
EmployeeSubStatus latestSubStatus = new EmployeeSubStatus();
latestSubStatus.setEmployeeID(substatus.get("employeeID").toString());
latestSubStatus.setSubStatus(substatus.get("subStatus").toString());
latestSubStatus.setFromDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(substatus.get("fromDate").toString()));
latestSubStatus.setToDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(substatus.get("toDate").toString()));
EmployeeSubStatus currentSubStatus = subStatusService.getCurrentSubStatus(employeeReq.getEmployeeId());
if (currentSubStatus != null) {
if (currentSubStatus.getSubStatus().equals(latestSubStatus.getSubStatus())) {
latestSubStatus.setId(currentSubStatus.getId());
subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus);
} else {
response.put("messege", "Employee is already " + currentSubStatus.getSubStatus() + " from " + currentSubStatus.getFromDate() + " to " + currentSubStatus.getToDate());
}
} else {
// currentSubStatus = subStatusService.getLatestEmployeeSubStatus(employeeReq.getEmployeeId());
// if(currentSubStatus == null)
subStatusService.addEmployeeSubStatus(latestSubStatus);
......@@ -140,6 +141,7 @@ public class EmployeeService implements IEmployeeService {
// latestSubStatus.setId(currentSubStatus.getId());
// subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus);
// }
}
}
}
......
......@@ -3,6 +3,8 @@ package com.nisum.myteam.service.impl;
import com.nisum.myteam.model.dao.EmployeeSubStatus;
import com.nisum.myteam.repository.EmployeeSubStatusRepo;
import com.nisum.myteam.service.ISubStatusService;
import com.nisum.myteam.utils.MyTeamDateUtils;
import com.nisum.myteam.utils.MyTeamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -52,4 +54,15 @@ public class SubStatusService implements ISubStatusService {
}else
return null;
}
@Override
public EmployeeSubStatus endSubStatus(EmployeeSubStatus subStatus){
EmployeeSubStatus currentSubStatus = getCurrentSubStatus(subStatus.getEmployeeID());
if(currentSubStatus.getId().equals(subStatus.getId())){
subStatus.setToDate(MyTeamDateUtils.getDayLessThanDate(new Date()));
updateExistingEmplyeeSubStatus(subStatus);
}
return null;
}
}
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