Commit 5a042734 authored by manishatyagi's avatar manishatyagi
Browse files

Api code to generate category wise Assessment infographic report

parent 51baf0f9
......@@ -100,10 +100,10 @@
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependency> -->
</dependencies>
<build>
......
......@@ -186,6 +186,17 @@ public class ReportController {
return reportService.getGenderAssessInfographicReport(startDate, endDate, assessmentId,subLobId);
}
@RequestMapping(method=RequestMethod.GET,value="/api/admin/getCategoryAssessmentInfographicReport")
public ResponseEntity<List<DBObject>> getCategoryAssessmentInfographicReport(
@RequestParam(value = "startDate", required = true) String startDate,
@RequestParam(value = "endDate", required = true) String endDate,
@RequestParam(value = "assessmentId", required = true) long assessmentId,
@RequestParam(value = "subLobId") long subLobId) throws Exception {
log.debug("Inside ReportController called method getCategoryAssessmentInfographicReport with parameter,"
+ "startDate={},endDate={},assessmentId={},subLobId={}",startDate,endDate,assessmentId,subLobId);
return reportService.getCategoryAssessmentInfographicReport(startDate, endDate, assessmentId,subLobId);
}
@RequestMapping(method=RequestMethod.GET,value="/api/user/getUserAssessmentReport")
public ResponseEntity<List<DBObject>> getUserAssessmentReport (
@RequestParam(value="userId", required = true) String userId,
......
......@@ -70,7 +70,9 @@ public interface QuizResultRepositoryCustom {
List<DBObject> getUserScoreCard(String userId) throws Exception;
public List<DBObject> getCriteriaWiseAssessInfographicReport(Date startDate, Date endDate, long assessmentId, long subLobId, String criteria) throws Exception;
List<DBObject> getCriteriaWiseAssessInfographicReport(Date startDate, Date endDate, long assessmentId, long subLobId, String criteria) throws Exception;
List<DBObject> getCategoryAssessmentInfographicReport(Date startDate, Date endDate, long assessmentId, long subLobId) throws Exception;
List<DBObject> getUserAssessmentReport(Date stDate, Date enDate, String userId)throws Exception;
......
......@@ -13,12 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationExpression;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators;
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
import org.springframework.data.mongodb.core.aggregation.GroupOperation.GroupOperationBuilder;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
......@@ -783,6 +781,31 @@ AggregationOperation match = Aggregation.match(new Criteria().andOperator(Crite
log.debug("Response returned from QuizResultRepositoryImpl--getCriteriaWiseAssessInfographicReport method,result={}",result.getMappedResults().size());
return result.getMappedResults();
}
@Override
public List<DBObject> getCategoryAssessmentInfographicReport(Date startDate, Date endDate, long assessmentId,
long subLobId) throws Exception {
// TODO Auto-generated method stub
log.debug("Inside QuizResultRepositoryImpl called getCategoryAssessmentInfographicReport method, with parameter"
+ " startDate={},endDate={},assessmentId={},subLobId={}",startDate,endDate,assessmentId,subLobId);
AggregationOperation match = Aggregation.match(new Criteria().andOperator(Criteria.where("quizDate")
.gte(startDate).lte(endDate),Criteria.where("questionSet.subLob._id").is(subLobId)
, Criteria.where("questionSet.assessmentId").is(assessmentId)));
AggregationOperation project = Aggregation.project("_id").and("questionSet.userId").as("userId")
.and("questionSet.questionList").as("questionList");
AggregationOperation sort= Aggregation.sort(Sort.Direction.ASC,"_id");
AggregationOperation group=Aggregation.group("userId").last("questionList").as("questionList");
AggregationOperation unwind=Aggregation.unwind("questionList");
Cond correctQuestionOperation =ConditionalOperators.when(Criteria.where("questionList.questionResult").is(CommonUtils.Question_Result_Status.Correct.name())).then(1).otherwise(0);
Cond incorrectQuestionOperation =ConditionalOperators.when(Criteria.where("questionList.questionResult").is(CommonUtils.Question_Result_Status.Incorrect.name())).then(1).otherwise(0);
AggregationOperation project1 = Aggregation.project("userId").and("questionList.category").as("category")
.and(correctQuestionOperation).as("correctQues").and(incorrectQuestionOperation).as("inCorrectQues");
AggregationOperation group1=Aggregation.group("category").sum("correctQues").as("correctQues").sum("inCorrectQues").as("inCorrectQues");
Aggregation agg = Aggregation.newAggregation(match,project,sort,group,unwind,project1,group1);
AggregationResults<DBObject> result = template.aggregate(agg,COLLECTION,DBObject.class);
log.debug("Response returned from QuizResultRepositoryImpl--getCategoryAssessmentInfographicReport method,result={}",result.getMappedResults().size());
return result.getMappedResults();
}
@Override
public List<DBObject> getUserAssessmentReport(Date stDate, Date enDate, String userId) throws Exception {
......@@ -860,9 +883,5 @@ AggregationOperation match = Aggregation.match(new Criteria().andOperator(Crite
return result.getMappedResults();
}
////
}
......@@ -59,6 +59,9 @@ public interface ReportService {
public ResponseEntity<List<UserAssessmentInfographicReport>> getGenderAssessInfographicReport (String startDate,
String endDate,long assessmentId, long subLobId) throws Exception;
public ResponseEntity<List<DBObject>> getCategoryAssessmentInfographicReport (String startDate,
String endDate,long assessmentId, long subLobId) throws Exception;
public ResponseEntity<List<DBObject>> getUserAssessmentReport(String userId,String startDate,String endDate)throws Exception;
public ResponseEntity<Map<String, Integer>> getPercentageWiseInfographicReport(String startDate, String endDate,
......
......@@ -3,10 +3,8 @@
*/
package com.statestreet.service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
......@@ -525,11 +523,13 @@ public class ReportServiceImpl implements ReportService{
{
List<Designation> desgList=desgRepo.findAll();
Map<Long, String> desgMap = desgList.stream().collect(Collectors.toMap(Designation :: getDesignationId,Designation :: getDesignationName));
report.forEach(obj -> obj.setCriteria(desgMap.get(Long.parseLong(report.get(0).getCriteria()))));
report.forEach(obj -> obj.setCriteria(desgMap.get(Long.parseLong(obj.getCriteria()))));
log.debug("Response returned from ReportServiceImpl --getDesignationAssessInfographicReport method, No of record={}",report.size());
return new ResponseEntity<List<UserAssessmentInfographicReport>> (report,HttpStatus.OK);
}
else
{
log.debug("Response returned from ReportServiceImpl --getDesignationAssessInfographicReport method -- No record found");
return new ResponseEntity<List<UserAssessmentInfographicReport>> (HttpStatus.NO_CONTENT);
}
}
......@@ -590,13 +590,41 @@ public class ReportServiceImpl implements ReportService{
}
if(report.size()>0)
{
log.debug("Response returned from ReportServiceImpl --getGenderAssessInfographicReport method, No of record={}",report.size());
return new ResponseEntity<List<UserAssessmentInfographicReport>> (report,HttpStatus.OK);
}
else
{
log.debug("Response returned from ReportServiceImpl --getGenderAssessInfographicReport method -- No record found");
return new ResponseEntity<List<UserAssessmentInfographicReport>> (HttpStatus.NO_CONTENT);
}
}
@Override
public ResponseEntity<List<DBObject>> getCategoryAssessmentInfographicReport(
String startDate, String endDate, long assessmentId, long subLobId) throws Exception {
// TODO Auto-generated method stub
log.debug("Inside ReportServiceImpl called method getCategoryAssessmentInfographicReport with parameter,"
+ "startDate={},endDate={},assessmentId={},subLobId={}",startDate,endDate,assessmentId,subLobId);
DATE_FORMAT.setTimeZone(CommonUtils.TIME_ZONE);
Date stDate=DATE_FORMAT.parse(startDate);
Date enDate=DATE_FORMAT.parse(endDate);
Calendar cal = Calendar.getInstance();
cal.setTime(enDate);
cal.add(Calendar.DATE,1);
enDate=DATE_FORMAT.parse(DATE_FORMAT.format(cal.getTime()));
List<DBObject> result = quizResultRepo.getCategoryAssessmentInfographicReport(stDate, enDate,assessmentId,subLobId);
if(result.size()>0)
{
log.debug("Response returned from ReportServiceImpl --getCategoryAssessmentInfographicReport method, No of record={}",result.size());
return new ResponseEntity<List<DBObject>> (result,HttpStatus.OK);
}
else
{
log.debug("Response returned from ReportServiceImpl --getCategoryAssessmentInfographicReport method -- No record found");
return new ResponseEntity<List<DBObject>> (HttpStatus.NO_CONTENT);
}
}
@Override
public ResponseEntity<List<DBObject>> getUserAssessmentReport(String userId,String startDate, String endDate) throws Exception {
......
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