package com.bankaudit.rest.process.controller;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bankaudit.dto.DataTableResponse;
import com.bankaudit.dto.process.BranchPerformanceBUResponse;
import com.bankaudit.dto.process.BranchPerformanceResponseDto;
import com.bankaudit.dto.process.DashboardSummaryDto;
import com.bankaudit.dto.process.PlanCalendarResponseDto;
import com.bankaudit.dto.process.RatingVarianceGraphResponseDto;
import com.bankaudit.dto.process.RealTimeRectificationResponseDto;
import com.bankaudit.dto.process.ScheduleVarianceGraphResponseDto;
import com.bankaudit.dto.process.UnitBreakUpResponseDto;
import com.bankaudit.model.MaintAuditTypeDesc;
import com.bankaudit.model.MaintUsergroupRoles;
import com.bankaudit.process.model.AuditSchedule;
import com.bankaudit.rest.process.service.DashboardService;
import com.bankaudit.util.BankAuditUtil;
import com.bankaudit.util.ServiceStatus;



@RestController

@RequestMapping("/api/dashboard")
public class DashboardController {

	@Autowired
	DashboardService dashboardService;
	
	static final Logger logger = Logger.getLogger(DashboardController.class);
		
		
@RequestMapping(value="/getAuditStatus",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getAuditStatus(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					Map<String, HashMap<String, Long>> result =	dashboardService.getAuditStatus(Integer.parseInt(legalEntityCode),
							auditType,
							unitType,
							criticality, 
							period,
							fromDate,
							toDate, 
							userId,
							role);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value = "/getAudits", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		DataTableResponse getAuditSchedules(
				@RequestParam("draw") String drawStr,
				@RequestParam("length") String length,
				@RequestParam("start") String start,
				@RequestParam("search[value]") String search,
				@RequestParam("order[0][column]") String orderColumnStr,
				@RequestParam("order[0][dir]") String orderDirection,
				@RequestParam("legalEntityCode")String legalEntityCodeStr,
				@RequestParam("userId")String userId,
				@RequestParam(required=true,value="role")String role){

			DataTableResponse dataTableResponse = null;

			if (!BankAuditUtil.isEmptyString(drawStr) && !BankAuditUtil.isEmptyString(length)
					&& !BankAuditUtil.isEmptyString(start)) {
				try {
					Integer draw = Integer.parseInt(drawStr);
					Integer size = Integer.parseInt(length);
					Integer page = Integer.parseInt(start) / size;
					Integer orderColumn = null;
					if (!BankAuditUtil.isEmptyString(orderColumnStr)) {
						orderColumn = Integer.parseInt(orderColumnStr);
					}
					logger.info("legalEntityCode:: "+legalEntityCodeStr +" userId:: "+ userId);
					dataTableResponse = dashboardService.getAuditSchedules(Integer.parseInt(legalEntityCodeStr),userId,search, orderColumn, orderDirection, page, size,role);
					logger.info("Inside controller dataTableResponse .... "+dataTableResponse);
					dataTableResponse.setDraw(draw);

				} catch (Exception e) {
					dataTableResponse = new DataTableResponse();
					dataTableResponse.setError(e.getMessage());
					e.printStackTrace();
				}

			} else {
				dataTableResponse = new DataTableResponse();
				dataTableResponse.setError("invalid data");
			}

			return dataTableResponse;
		}		
	
		
@RequestMapping(value = "/getScheduleVariance", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getScheduleVariance(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					Map<String,List<ScheduleVarianceGraphResponseDto>> result =	dashboardService.getScheduleVariance(Integer.parseInt(legalEntityCode),
							auditType,
							period,
							fromDate,
							toDate, 
							userId,
							role,
							unitType,
							criticality);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}		
	

		
@RequestMapping(value = "/getRealTimeRectification", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getRealTimeRectification(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List<RealTimeRectificationResponseDto> result =	dashboardService.getRealTimeRectification(Integer.parseInt(legalEntityCode),
							auditType,
							
							period,
							fromDate,
							toDate, 
							userId,
							role,
							unitType,
							criticality );
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value = "/getRatingVariance", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getRatingStatus(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List<RatingVarianceGraphResponseDto> result =	dashboardService.getRatingStatus(Integer.parseInt(legalEntityCode),
							auditType,
							period,
							fromDate,
							toDate, 
							userId,role,
							unitType,
							criticality);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}				
		
		
@RequestMapping(value = "/getRatingVarianceActl", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getRatingVariance(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List<Map<String, HashMap<String,Long>>> result  =	dashboardService.getRatingVariance(Integer.parseInt(legalEntityCode),
							auditType,
							period,
							fromDate,
							toDate, 
							userId,role,
							unitType,
							criticality);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}	
		
		
@RequestMapping(value = "/getRatingTrend", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getRatingTrend(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode) && !BankAuditUtil.isEmptyString(auditType) 
					&& !BankAuditUtil.isEmptyString(userId) && !BankAuditUtil.isEmptyString(role) 
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List<Map<String, List<Map<String,Long>>>> result  =	dashboardService.getRatingTrend(Integer.parseInt(legalEntityCode),
							auditType,
							period,
							fromDate,
							toDate, 
							userId,role,
							unitType,
							criticality);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}	
		
		
@RequestMapping(value="/getMyAuditStatistics",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getMyAuditStatistics(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					Map<String, HashMap<String, Long>> result =	dashboardService.getMyAuditStatistics(Integer.parseInt(legalEntityCode),
							auditType,
							unitType,
							criticality, 
							period,
							fromDate,
							toDate, 
							userId,
							role);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value = "/getBranchPerformance", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getBranchPerformance(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					Map<String,BranchPerformanceResponseDto> result =	dashboardService.getBranchPerformance(Integer.parseInt(legalEntityCode),
							auditType,
							period,
							fromDate,
							toDate, 
							userId,
							role,
							unitType,
							criticality);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value = "/getBranchPerformanceRectification", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getBranchPerformanceRectification(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List<BranchPerformanceBUResponse> result =	dashboardService.getBranchPerformanceRectification(Integer.parseInt(legalEntityCode),
							auditType,	period, fromDate, toDate, userId, role,	criticality );
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value = "/getBranchPerformanceForBU", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getBranchPerformanceForBU(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(userId)
					&&!BankAuditUtil.isEmptyString(role)
					){
				try {
					
					 Map<String, List>  result =	dashboardService.getBranchPerformanceForBU(Integer.parseInt(legalEntityCode),
							auditType,
							userId,
							role
							);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		

		
		
@RequestMapping(value = "/getUnitBreakUp", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getUnitBreakUp(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=true,value="criteria") String criteria
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					){
				if(!BankAuditUtil.isEmptyString(period)&&period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List<UnitBreakUpResponseDto> result =	dashboardService.getUnitBreakUp(Integer.parseInt(legalEntityCode),
							auditType,
							unitType,
							period,
							fromDate,
							toDate, 
							role,
							userId,
							criteria
							);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		

		
@RequestMapping(value = "/getPlanCalendar", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getPlanCalendar(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode)){
				try {
					List<PlanCalendarResponseDto> result =	dashboardService.getPlanCalendar(Integer.parseInt(legalEntityCode));
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode required ");
			}
	
			return serviceStatus;
			
		}
		
		
@RequestMapping(value = "/getResourcePlanningAuditorEffort", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getResourcePlanningAuditorEffort(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="unitType")String unitType,
				@RequestParam(required=false,value="criticality")String criticality
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(userId)
					&&!BankAuditUtil.isEmptyString(role)
					){
				try {
					
					 Map<String, String>  result =	dashboardService.getResourcePlanningAuditorEffort(Integer.parseInt(legalEntityCode),auditType,userId,role,unitType,criticality);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value = "/getAuditSummary", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getAuditSummary(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=false,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)){
				if(!BankAuditUtil.isEmptyString(period) && period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List<AuditSchedule> result =	dashboardService.getAuditSummary(Integer.parseInt(legalEntityCode),auditType,
							period, fromDate, toDate, userId,role, unitType, criticality );
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode is required");
			}
			
			return serviceStatus;
			
		}	
		
		
@RequestMapping(value="/getUserDtlsforAdminDB",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getUserDtlsforAdminDB(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(userId)) 
			{
				try {
					
					Map<String, Integer> result =dashboardService.getUserDtlsforAdminDB(Integer.parseInt(legalEntityCode),userId,role);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("LegalEntityCode, Role & UserId is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value="/getRolewiseUsersCount",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getRolewiseUsersCount(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=false,value="role")String role
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(userId)) 
			{
				try {
					
					List<MaintUsergroupRoles> listUserRoles =dashboardService.getRolewiseUsersCount(Integer.parseInt(legalEntityCode),userId,role);
					
				    serviceStatus.setResult(listUserRoles);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("LegalEntityCode, Role & UserId is required");
			}
			
			return serviceStatus;
			
		}
		
		
		
		
@RequestMapping(value = "/getAuditSummaryTgtWtchlstTotal", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	  	ServiceStatus getAuditSummaryTrgtWtchlstTotal(@RequestParam("legalEntityCode") int legalEntityCode,
	  							      @RequestParam(value="userOrUnitCode") String userOrUnitCode,
	  							      @RequestParam(value="type") String type,
	  							      @RequestParam(value="auditType",required=false) String auditTypeCode
	  	){ 
			ServiceStatus serviceStatus =new ServiceStatus();
			if(/*!BankAuditUtil.isEmptyString(legalEntityCode)*/ legalEntityCode > -1 && !BankAuditUtil.isEmptyString(userOrUnitCode) 
					&& !BankAuditUtil.isEmptyString(type)) 
			{
				try {
					Map<String, String> auditSummaryTgtWtchTtlMap =dashboardService.getAuditSummaryTrgtWtchlstTotal(legalEntityCode,userOrUnitCode,type,auditTypeCode);
				    serviceStatus.setResult(auditSummaryTgtWtchTtlMap);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("LegalEntityCode, UserOrUnitCode & Type is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value="/getAuditClosureStatusTmp",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getAuditClosureStatusTmp(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role, 
				String toDeleteMthd
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					List< List> result =	dashboardService.getAuditClosureStatusTmp(Integer.parseInt(legalEntityCode),
							auditType,
							unitType,
							criticality, 
							period,
							fromDate,
							toDate, 
							userId,
							role);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		
@RequestMapping(value="/getAuditClosureStatus",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getAuditClosureStatus(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unitType") String unitType,
				@RequestParam(required=false,value="criticality") String criticality,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role
				){
			
			
			ServiceStatus serviceStatus =new ServiceStatus();
			
			if(!BankAuditUtil.isEmptyString(legalEntityCode)
					&&!BankAuditUtil.isEmptyString(period) 
					){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					
					Map<String, HashMap<String, Long>> result =	dashboardService.getAuditClosureStatus(Integer.parseInt(legalEntityCode),
							auditType,
							unitType,
							criticality, 
							period,
							fromDate,
							toDate, 
							userId,
							role);
					
				    serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					
					} catch (Exception e) {

						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
				
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			
			return serviceStatus;
			
		}
		
		/****************************************************************************************************************************
		 **************************************         DASHBOARDS FOR RCSA NABARD           ****************************************
		 ****************************************************************************************************************************/
		
		
@RequestMapping(value = "/getAssessmentSummaryDtls", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	  	ServiceStatus getAssessmentSummaryDtls(@RequestParam("legalEntityCode") int legalEntityCode,
	  							      @RequestParam(value="user",required=true) String userId,
	  							      @RequestParam(value="role",required=true) String role,
	  							      @RequestParam(value="auditType",required=false) String auditTypeCode,
	  							      @RequestParam(value="unit",required=false)String unitId
	  	){ 
			ServiceStatus serviceStatus =new ServiceStatus();
			if(/*!BankAuditUtil.isEmptyString(legalEntityCode)*/ legalEntityCode > -1 && !BankAuditUtil.isEmptyString(userId) 
					&& !BankAuditUtil.isEmptyString(role)) 
			{
				try {
					Map<String, String> assessmentSummary =dashboardService.getAssessmentSummaryDtls(legalEntityCode,userId,unitId,role,auditTypeCode);
				    serviceStatus.setResult(assessmentSummary);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
					} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
					}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("LegalEntityCode, UserOrUnitCode & Type is required");
			}
			return serviceStatus;
		}
		
		
@RequestMapping(value = "/getRiskProfileDeptwise", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getRiskProfileDeptwise(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(period)){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					List<HashMap<String,String>> result  =	dashboardService.getRiskProfileDeptwise(Integer.parseInt(legalEntityCode),
							auditType, period, fromDate, toDate, userId, role, unitId);
					serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}	
		
		
@RequestMapping(value = "/getRiskProfileProductwise", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getRiskProfileProductwise(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(period)){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					List<HashMap<String,String>> result  =	dashboardService.getRiskProfileProductwise(Integer.parseInt(legalEntityCode),
							auditType, period, fromDate, toDate, userId, role, unitId);
					serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}	
		
		
@RequestMapping(value = "/getControlProfileDeptwise", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getControlProfileDeptwise(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(period)){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					List<HashMap<String,String>> result  =	dashboardService.getControlProfileDeptwise(Integer.parseInt(legalEntityCode),
							auditType, period, fromDate, toDate, userId, role, unitId);
					serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}
		
		
@RequestMapping(value = "/getControlProfileProductwise", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getControlProfileProductwise(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=true,value="period") String period,
				@RequestParam(required=false,value="fromDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate fromDate,
				@RequestParam(required=false,value="toDate")
				@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate toDate,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(period)){
				if(period.equalsIgnoreCase("range")){
					if(fromDate==null || toDate==null){
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("if period is range then fromdate and toDate both are required ");
					    return serviceStatus;
					}
				}
				try {
					List<HashMap<String,String>> result  =	dashboardService.getControlProfileProductwise(Integer.parseInt(legalEntityCode),
							auditType, period, fromDate, toDate, userId, role, unitId);
					serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}
		
		
@RequestMapping(value = "/getTaskStatistics", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getTaskStatistics(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(userId) &&!BankAuditUtil.isEmptyString(role)){
				try {
					Map<String, Integer> result  =	dashboardService.getTaskStatistics(Integer.parseInt(legalEntityCode),
							userId, role, auditType, unitId );
					serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}
		
		
@RequestMapping(value = "/getOverDueTaskStatistics", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getOverDueTaskStatistics(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(userId) &&!BankAuditUtil.isEmptyString(role)){
				try {
					Map<String, Integer> result  =	dashboardService.getOverDueTaskStatistics(Integer.parseInt(legalEntityCode),
							userId, role, auditType, unitId );
					serviceStatus.setResult(result);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}
		
		
@RequestMapping(value = "/getHealthControlRiskSummaryDetails", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getHealthControlRiskSummaryDetails(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=true,value="userId")String userId,
				@RequestParam(required=true,value="role")String role,
				@RequestParam(required=false,value="auditType") String auditType,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) &&!BankAuditUtil.isEmptyString(userId) &&!BankAuditUtil.isEmptyString(role)){
				try {
					logger.info("Inside getHealthControlRiskSummaryDetails .."+legalEntityCode +" userId .."+userId+" role .."+role+" auditType .."+auditType +" unit.."+ unitId);
					Map<String, String> healthControlRiskSummaryDetails  =dashboardService.getHealthControlRiskSummaryDetails(Integer.parseInt(legalEntityCode),
							userId, role, auditType, unitId );
					serviceStatus.setResult(healthControlRiskSummaryDetails);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				} catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}
		
		/******************** New Dashboard implementation start ********************/	
		
		
@RequestMapping(value = "/getAuditSummaryTrgtWtchlstTotalTopBand", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getAuditSummaryTrgtWtchlstTotalTopBand(
				 @RequestParam("legalEntityCode") Integer legalEntityCode,
			     @RequestParam(value="userOrUnitCode") String userOrUnitCode,
			     @RequestParam(value="type") String type,
			     @RequestParam(value="auditType",required=false) String auditTypeCode,
				 @RequestParam(value="financialYear") @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate financialYear
			    ){
			ServiceStatus serviceStatus =new ServiceStatus(); 
			try{ 
				logger.info("Inside getAllInspectorWidget .."+legalEntityCode + "financialYear .."+financialYear 
						+" auditTypeCode .."+auditTypeCode + " userOrUnitCode .."+userOrUnitCode+" financialYear.."+financialYear  );				    
			    serviceStatus.setResult(dashboardService.getAuditSummaryTrgtWtchlstTotalTopBand(legalEntityCode, userOrUnitCode, type, auditTypeCode, financialYear));
			    serviceStatus.setStatus("success");
			    serviceStatus.setMessage("sucessfully retrieved"); 
			     
			}catch (Exception e) {
					serviceStatus.setStatus("failure");
					serviceStatus.setMessage("failure");
					e.printStackTrace();
			}
			      
			return serviceStatus;
		}
		
		
@RequestMapping(value = "/getAllManagementWidget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getAllManagementWidget(
				@RequestParam(required=true,value="legalEntityCode") Integer legalEntityCode,
				@RequestParam(required=false,value="userId")String userId,
				@RequestParam(required=false,value="role")String role,
				@RequestParam(required=true,value="financialYear") @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate financialYear,
				@RequestParam(required=false,value="auditTypeCode") String auditTypeCode,
				@RequestParam(required=false,value="zone")String zone,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus(); 
			try{ 
				logger.info("Inside getAllManagementWidget .."+legalEntityCode +" userId .."+userId+" role .."+role+"financialYear .."+financialYear 
						+" auditTypeCode .."+auditTypeCode + "zone .."+zone +" unit.."+ unitId);				    
			    serviceStatus.setResult(dashboardService.getAllManagementWidget(legalEntityCode, userId, role, financialYear,
						auditTypeCode, zone, unitId));
			    serviceStatus.setStatus("success");
			    serviceStatus.setMessage("sucessfully retrieved"); 
			}catch (Exception e) {
					serviceStatus.setStatus("failure");
					serviceStatus.setMessage("failure");
					e.printStackTrace();
			} 
			return serviceStatus;
		}
		
		
@RequestMapping(value = "/getAllOperationalWidget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getAllOperationalWidget(
				@RequestParam(required=true,value="legalEntityCode") Integer legalEntityCode,
				@RequestParam(required=false,value="userId")String userId,
				@RequestParam(required=false,value="role")String role,
				@RequestParam(required=true,value="financialYear") @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate financialYear,
				@RequestParam(required=false,value="auditTypeCode") String auditTypeCode,
				@RequestParam(required=false,value="zone")String zone,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus(); 
			try{ 
				logger.info("Inside getAllOperationalWidget .."+legalEntityCode +" userId .."+userId+" role .."+role+"financialYear .."+financialYear 
						+" auditTypeCode .."+auditTypeCode + "zone .."+zone +" unit.."+ unitId);				    
			    serviceStatus.setResult(dashboardService.getAllOperationalWidget(legalEntityCode, userId, role, financialYear, auditTypeCode, zone, unitId));
			    serviceStatus.setStatus("success");
			    serviceStatus.setMessage("sucessfully retrieved"); 
			}catch (Exception e) {
					serviceStatus.setStatus("failure");
					serviceStatus.setMessage("failure");
					e.printStackTrace();
			}
			 
			return serviceStatus;
		}
		
	
@RequestMapping(value = "/getAllInspectorWidget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getAllInspectorWidget(
			@RequestParam(required=true,value="legalEntityCode") Integer legalEntityCode,
			@RequestParam(required=false,value="userId")String userId,
			@RequestParam(required=false,value="role")String role,
			@RequestParam(required=true,value="financialYear") @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate financialYear,
			@RequestParam(required=false,value="auditTypeCode") String auditTypeCode,
			@RequestParam(required=false,value="zone")String zone,
			@RequestParam(required=false,value="unit")String unitId
			){
		ServiceStatus serviceStatus =new ServiceStatus(); 
		try{ 
			logger.info("Inside getAllInspectorWidget .."+legalEntityCode +" userId .."+userId+" role .."+role+"financialYear .."+financialYear 
					+" auditTypeCode .."+auditTypeCode + "zone .."+zone +" unit.."+ unitId);				    
		    serviceStatus.setResult(dashboardService.getAllInspectorWidget(legalEntityCode, userId, role, financialYear,
					auditTypeCode, zone, unitId));
		    serviceStatus.setStatus("success");
		    serviceStatus.setMessage("sucessfully retrieved"); 
		     
		}catch (Exception e) {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("failure");
				e.printStackTrace();
		}
		 
		return serviceStatus;
	}
	
	
@RequestMapping(value = "/getAllBankUserWidget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getAllBankUserWidget(
			@RequestParam(required=true,value="legalEntityCode") Integer legalEntityCode,
			@RequestParam(required=false,value="userId")String userId,
			@RequestParam(required=false,value="role")String role,
			@RequestParam(required=true,value="financialYear") @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate financialYear,
			@RequestParam(required=false,value="auditTypeCode") String auditTypeCode,
			@RequestParam(required=false,value="zone")String zone,
			@RequestParam(required=false,value="unit")String unitId
			){
		ServiceStatus serviceStatus =new ServiceStatus();
		 
		try{ 
			logger.info("Inside getAllBankUserWidget .."+legalEntityCode +" userId .."+userId+" role .."+role+"financialYear .."+financialYear 
					+" auditTypeCode .."+auditTypeCode + "zone .."+zone +" unit.."+ unitId);				    
		    serviceStatus.setResult(dashboardService.getAllBankUserWidget(legalEntityCode, userId, role, financialYear, auditTypeCode, zone, unitId));
		    serviceStatus.setStatus("success");
		    serviceStatus.setMessage("sucessfully retrieved"); 
		     
		}catch (Exception e) {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("failure");
				e.printStackTrace();
		}
		 
		return serviceStatus;
	}
	
	
@RequestMapping(value = "/getAllScrutinyWidget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getAllScrutinyWidget(
			@RequestParam(required=true,value="legalEntityCode") Integer legalEntityCode,
			@RequestParam(required=false,value="userId")String userId,
			@RequestParam(required=false,value="role")String role,
			@RequestParam(required=true,value="financialYear") @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate financialYear,
			@RequestParam(required=false,value="auditTypeCode") String auditTypeCode,
			@RequestParam(required=false,value="zone")String zone,
			@RequestParam(required=false,value="unit")String unitId
			){
		ServiceStatus serviceStatus =new ServiceStatus(); 
		try{ 
			logger.info("Inside getAllScrutinyWidget .."+legalEntityCode +" userId .."+userId+" role .."+role+"financialYear .."+financialYear 
					+" auditTypeCode .."+auditTypeCode + "zone .."+zone +" unit.."+ unitId);				    
		    serviceStatus.setResult(dashboardService.getScrutinyWidget(legalEntityCode, userId, role, financialYear, auditTypeCode, zone, unitId));
		    serviceStatus.setStatus("success");
		    serviceStatus.setMessage("sucessfully retrieved"); 
		     
		}catch (Exception e) {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("failure");
				e.printStackTrace();
		} 
		return serviceStatus;
	}
		
	
@RequestMapping(value = "/getMyAuditSchedules", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	DataTableResponse getMyAuditSchedules(
			@RequestParam("draw") String drawStr,
			@RequestParam("length") String length,
			@RequestParam("start") String start,
			@RequestParam("search[value]") String search,
			@RequestParam("order[0][column]") String orderColumnStr,
			@RequestParam("order[0][dir]") String orderDirection,
			@RequestParam("legalEntityCode")Integer legalEntityCodeStr,
			@RequestParam("userId")String userId,
			@RequestParam(required=true,value="role")String role){

		DataTableResponse dataTableResponse = null;
		if (!BankAuditUtil.isEmptyString(drawStr) && !BankAuditUtil.isEmptyString(length)
				&& !BankAuditUtil.isEmptyString(start)) {
			try {
				Integer draw = Integer.parseInt(drawStr);
				Integer size = Integer.parseInt(length);
				Integer page = Integer.parseInt(start) / size;
				Integer orderColumn = null;
				if (!BankAuditUtil.isEmptyString(orderColumnStr)) {
					orderColumn = Integer.parseInt(orderColumnStr);
				} 
				dataTableResponse = dashboardService.getMyAuditSchedules(legalEntityCodeStr,userId,search, orderColumn, orderDirection,
						page, size, role);
				dataTableResponse.setDraw(draw);

			} catch (Exception e) {
				dataTableResponse = new DataTableResponse();
				dataTableResponse.setError(e.getMessage());
				e.printStackTrace();
			}

		} else {
			dataTableResponse = new DataTableResponse();
			dataTableResponse.setError("invalid data");
		}

		return dataTableResponse;
	}			
		/*
		
@RequestMapping(value = "/getDashboardWidget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
		ServiceStatus getDashboardWidget(
				@RequestParam(required=true,value="legalEntityCode") String legalEntityCode,
				@RequestParam(required=false,value="userId")String userId,
				@RequestParam(required=false,value="role")String role,
				@RequestParam(required=true,value="financialYear") @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate financialYear,
				@RequestParam(required=false,value="auditTypeCode") String auditTypeCode,
				@RequestParam(required=false,value="zone")String zone,
				@RequestParam(required=false,value="unit")String unitId
				){
			ServiceStatus serviceStatus =new ServiceStatus();
			if(!BankAuditUtil.isEmptyString(legalEntityCode) ){
				try{ 
					logger.info("Inside getDeskComplianceRatingWidget .."+legalEntityCode +" userId .."+userId+" role .."+role+"financialYear .."+financialYear 
							+" auditTypeCode .."+auditTypeCode + "zone .."+zone +" unit.."+ unitId);				    
				    serviceStatus.setResult(dashboardService.getAllManagementWidget(legalEntityCode, userId, role, financialYear,
							auditTypeCode, zone, unitId));
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");
				    
				    /*Map<String, Map<String, String>>  deskComplianceRatingWidget = dashboardService.getSupervisoryRatingMigrationWidget(legalEntityCode, userId, role, financialYear, auditTypeCode, zone, unitId);
					serviceStatus.setResult(deskComplianceRatingWidget);
				    serviceStatus.setStatus("success");
				    serviceStatus.setMessage("sucessfully retrieved");* /
				     
				}catch (Exception e) {
						serviceStatus.setStatus("failure");
						serviceStatus.setMessage("failure");
						e.printStackTrace();
				}
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("legalEntityCode and period is required");
			}
			return serviceStatus;
		}
		
		*/	
}
