Commit 382539ab authored by Ramakanth Dhane's avatar Ramakanth Dhane

omd-dashboard added logic to display static weekly orders

parent d643ba93
package com.nisum.omd.controllers;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nisum.omd.models.OrdersSummary;
import com.nisum.omd.models.WeeklyOrders;
import com.nisum.omd.security.services.OrderService;
import com.nisum.omd.security.services.UserDetailsImpl;
import com.nisum.omd.service.OrdersSummaryService;
import com.nisum.omd.pojo.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/test")
public class OrdersController {
static Long dailyOrders=new Long(0);
static Long hoursOrders=new Long(0);
static Long minutesOrders=new Long(0);
static Long customers=new Long(100);
@Autowired
OrderService service;
@Autowired
OrdersSummaryService ordersSummaryService;
@GetMapping(value= "/getOrdersSummary", produces= "application/vnd.jcg.api.v1+json")
public OrdersSummary getOrdersCount()
{
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println("getOrdersCount:::called at:::"+dtf.format(now));
OrdersSummary ordersSummary= new OrdersSummary();
ordersSummary.setToday_orders(++dailyOrders);
ordersSummary.setToday_date("04/28/2020");
ordersSummary.setCurrent_hour_orders(++hoursOrders);
ordersSummary.setCurrent_hour("12");
ordersSummary.setCurrent_minute_orders(++minutesOrders);
ordersSummary.setCurrent_minute("36");
ordersSummary.setCustomers_count(++customers);
return ordersSummary;
}
@GetMapping(value= "/getTopOrders", produces= "application/json")
public List<OrdersSummary> getTopOrders() {
System.out.println("getTopOrders Called.");
return service.getTopOrders();
}
@GetMapping(value= "/getWeekOrders", produces= "application/json")
public List<WeeklyOrders> getWeekOrders() {
System.out.println("getWeekOrders Called.");
List<WeeklyOrders> list = new ArrayList<WeeklyOrders>();
WeeklyOrders weeklyOrders1= new WeeklyOrders(new Date(), new Long(12548));
WeeklyOrders weeklyOrders2= new WeeklyOrders(new Date(), new Long(25415));
list.add(weeklyOrders1);
list.add(weeklyOrders2);
return list;
}
@GetMapping("/orderCount")
public com.nisum.omd.pojo.OrdersSummary getOrderSummary(){
com.nisum.omd.pojo.OrdersSummary ordersSummary=ordersSummaryService.getOrderSummaryCount();
return ordersSummary;
}
@GetMapping("/weeklyCount")
public Map<LocalDate, Long> getWeeklyOrderSummary(){
Map<LocalDate, Long> ordersSummary=ordersSummaryService.getOrderSummaryInWeek();
return ordersSummary;
}
}
package com.nisum.omd.controllers;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nisum.omd.dto.WeeklyOrders;
import com.nisum.omd.pojo.OrdersSummary;
import com.nisum.omd.service.OrdersSummaryService;
......@@ -24,13 +26,21 @@ public class OrdersSummaryController {
OrdersSummary ordersSummary=ordersSummaryService.getOrderSummaryCount();
return ordersSummary;
}
/*
@GetMapping("/weeklyCount")
public Map<LocalDate, Long> getWeeklyOrderSummary(){
Map<LocalDate, Long> ordersSummary=ordersSummaryService.getOrderSummaryInWeek();
return ordersSummary;
} */
@GetMapping("/weeklyCount")
public List<WeeklyOrders> getWeeklyOrderSummary(){
List<WeeklyOrders> ordersSummary=ordersSummaryService.getOrderSummaryInWeek();
return ordersSummary;
}
}
package com.nisum.omd.models;
import java.util.Date;
public class WeeklyOrders {
private Date oderDate;
private Long orderCount;
public WeeklyOrders(Date oderDate, Long orderCount) {
super();
this.oderDate = oderDate;
this.orderCount = orderCount;
}
@Override
public String toString() {
return "WeeklyOrders [oderDate=" + oderDate + ", orderCount=" + orderCount + "]";
}
public Date getOderDate() {
return oderDate;
}
public void setOderDate(Date oderDate) {
this.oderDate = oderDate;
}
public Long getOrderCount() {
return orderCount;
}
public void setOrderCount(Long orderCount) {
this.orderCount = orderCount;
}
}
package com.nisum.omd.service;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import com.nisum.omd.dto.WeeklyOrders;
import com.nisum.omd.pojo.OrdersSummary;
public interface OrdersSummaryService {
OrdersSummary getOrderSummaryCount();
Map<LocalDate,Long> getOrderSummaryInWeek();
// Map<LocalDate,Long> getOrderSummaryInWeek();
List<WeeklyOrders> getOrderSummaryInWeek();
}
......
......@@ -6,7 +6,9 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
......@@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import com.nisum.omd.dto.WeeklyOrders;
import com.nisum.omd.pojo.OrdersSummary;
import com.nisum.omd.repository.DynamicQuery;
import com.nisum.omd.repository.OrdersSummaryRepository;
......@@ -119,7 +122,7 @@ public class OrdersSummaryServiceImpl implements OrdersSummaryService {
}
private Map<LocalDate, Long> orderCountInCustomDate(){
/* private Map<LocalDate, Long> orderCountInCustomDate(){
Integer weekCount = 6;
TreeMap<LocalDate, Long> hm = new TreeMap<>();
......@@ -151,6 +154,27 @@ public class OrdersSummaryServiceImpl implements OrdersSummaryService {
return hm;
}
*/
private List<WeeklyOrders> orderCountInCustomDate() {
List<WeeklyOrders> orders = new ArrayList<>();
WeeklyOrders order1 = new WeeklyOrders(LocalDate.now() + "", 900L);
WeeklyOrders order2 = new WeeklyOrders(LocalDate.now().minusDays(1) + "", 100L);
WeeklyOrders order3 = new WeeklyOrders(LocalDate.now().minusDays(2) + "", 200L);
WeeklyOrders order4 = new WeeklyOrders(LocalDate.now().minusDays(3) + "", 300L);
WeeklyOrders order5 = new WeeklyOrders(LocalDate.now().minusDays(4) + "", 400L);
WeeklyOrders order6 = new WeeklyOrders(LocalDate.now().minusDays(5) + "", 500L);
WeeklyOrders order7 = new WeeklyOrders(LocalDate.now().minusDays(6) + "", 600L);
orders.add(order1);
orders.add(order2);
orders.add(order3);
orders.add(order4);
orders.add(order5);
orders.add(order6);
orders.add(order7);
return orders;
}
public OrdersSummary getOrderSummaryCount(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-YYYY");
LocalDateTime localTime = LocalDateTime.now();
......@@ -170,9 +194,16 @@ public class OrdersSummaryServiceImpl implements OrdersSummaryService {
@Override
/* @Override
public Map<LocalDate, Long> getOrderSummaryInWeek() {
return orderCountInCustomDate();
}
*/
@Override
public List<WeeklyOrders> getOrderSummaryInWeek() {
return orderCountInCustomDate();
}
}
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