Commit aa7f2c24 authored by Ramakanth Dhane's avatar Ramakanth Dhane

Removed test data from dashboard

parent 96c532dd
package com.nisum.omd; package com.nisum.omd;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
......
package com.nisum.omd.config; package com.nisum.omd.config;
import com.github.javafaker.Faker;
import com.nisum.omd.domain.Order; import com.nisum.omd.domain.Order;
import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer; import org.apache.kafka.common.serialization.StringSerializer;
...@@ -36,4 +37,8 @@ public class OmdProducerConfig { ...@@ -36,4 +37,8 @@ public class OmdProducerConfig {
public KafkaTemplate<String, Order> kafkaTemplate(){ public KafkaTemplate<String, Order> kafkaTemplate(){
return new KafkaTemplate<>(producerFactory()); return new KafkaTemplate<>(producerFactory());
} }
@Bean
public Faker getFaker() {
return new Faker();
}
} }
...@@ -19,7 +19,8 @@ public class RandomDataGeneratorImpl implements RandomDataGenerator { ...@@ -19,7 +19,8 @@ public class RandomDataGeneratorImpl implements RandomDataGenerator {
@Autowired @Autowired
private Order order; private Order order;
private Faker faker = new Faker(); @Autowired
private Faker faker;
public String generateOrderNumber() { public String generateOrderNumber() {
return String.valueOf(faker.number().numberBetween(1000000, 9999999)); return String.valueOf(faker.number().numberBetween(1000000, 9999999));
......
package com.nisum.omd.controllers; package com.nisum.omd.controllers;
import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; 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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -13,7 +12,7 @@ import com.nisum.omd.dto.WeeklyOrders; ...@@ -13,7 +12,7 @@ import com.nisum.omd.dto.WeeklyOrders;
import com.nisum.omd.pojo.OrdersSummary; import com.nisum.omd.pojo.OrdersSummary;
import com.nisum.omd.service.OrdersSummaryService; import com.nisum.omd.service.OrdersSummaryService;
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController @RestController
@RequestMapping("orders") @RequestMapping("orders")
public class OrdersSummaryController { public class OrdersSummaryController {
...@@ -26,14 +25,6 @@ public class OrdersSummaryController { ...@@ -26,14 +25,6 @@ public class OrdersSummaryController {
OrdersSummary ordersSummary=ordersSummaryService.getOrderSummaryCount(); OrdersSummary ordersSummary=ordersSummaryService.getOrderSummaryCount();
return ordersSummary; return ordersSummary;
} }
/*
@GetMapping("/weeklyCount")
public Map<LocalDate, Long> getWeeklyOrderSummary(){
Map<LocalDate, Long> ordersSummary=ordersSummaryService.getOrderSummaryInWeek();
return ordersSummary;
} */
@GetMapping("/weeklyCount") @GetMapping("/weeklyCount")
public List<WeeklyOrders> getWeeklyOrderSummary(){ public List<WeeklyOrders> getWeeklyOrderSummary(){
List<WeeklyOrders> ordersSummary=ordersSummaryService.getOrderSummaryInWeek(); List<WeeklyOrders> ordersSummary=ordersSummaryService.getOrderSummaryInWeek();
......
package com.nisum.omd.service; package com.nisum.omd.service;
import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Map;
import com.nisum.omd.dto.WeeklyOrders; import com.nisum.omd.dto.WeeklyOrders;
import com.nisum.omd.pojo.OrdersSummary; import com.nisum.omd.pojo.OrdersSummary;
...@@ -10,7 +8,6 @@ import com.nisum.omd.pojo.OrdersSummary; ...@@ -10,7 +8,6 @@ import com.nisum.omd.pojo.OrdersSummary;
public interface OrdersSummaryService { public interface OrdersSummaryService {
OrdersSummary getOrderSummaryCount(); OrdersSummary getOrderSummaryCount();
// Map<LocalDate,Long> getOrderSummaryInWeek();
List<WeeklyOrders> getOrderSummaryInWeek(); List<WeeklyOrders> getOrderSummaryInWeek();
} }
......
...@@ -125,60 +125,36 @@ public class OrdersSummaryServiceImpl implements OrdersSummaryService { ...@@ -125,60 +125,36 @@ public class OrdersSummaryServiceImpl implements OrdersSummaryService {
} }
/* private Map<LocalDate, Long> orderCountInCustomDate(){
Integer weekCount = 6;
TreeMap<LocalDate, Long> hm = new TreeMap<>();
for(int i=weekCount; i >=0; i--) {
LocalTime fromdt = LocalTime.of(00, 00,00);
LocalTime todt = LocalTime.of(23, 59,59);
Instant instant = fromdt.atDate(LocalDate.now().minusDays(i)).
atZone(ZoneId.systemDefault()).toInstant();
Date time1 = Date.from(instant);
Long fromDate=time1.getTime();
Instant instant2 = todt.atDate(LocalDate.now().minusDays(i)).
atZone(ZoneId.systemDefault()).toInstant();
Date time2 = Date.from(instant2);
Long toDate=time2.getTime();
DynamicQuery dynamicQuery = new DynamicQuery();
dynamicQuery.setOrderDateFrom(fromDate);
dynamicQuery.setOrderDateTo(toDate);
Long orderCount = ordersSummaryRepository.query(dynamicQuery);
LocalDate formattedFromDate =
Instant.ofEpochMilli(fromDate).atZone(ZoneId.systemDefault()).toLocalDate();
hm.put(formattedFromDate, orderCount);
}
return hm;
}
*/
private List<WeeklyOrders> orderCountInCustomDate() { private List<WeeklyOrders> orderCountInCustomDate() {
List<WeeklyOrders> orders = new ArrayList<>(); List<WeeklyOrders> orders = new ArrayList<>();
WeeklyOrders order1 = new WeeklyOrders(LocalDate.now() + "", 900L); Integer weekCount = 6;
WeeklyOrders order2 = new WeeklyOrders(LocalDate.now().minusDays(1) + "", 100L); for (int i = weekCount; i >= 0; i--) {
WeeklyOrders order3 = new WeeklyOrders(LocalDate.now().minusDays(2) + "", 200L);
WeeklyOrders order4 = new WeeklyOrders(LocalDate.now().minusDays(3) + "", 300L); LocalTime fromdt = LocalTime.of(00, 00, 00);
WeeklyOrders order5 = new WeeklyOrders(LocalDate.now().minusDays(4) + "", 400L); LocalTime todt = LocalTime.of(23, 59, 59);
WeeklyOrders order6 = new WeeklyOrders(LocalDate.now().minusDays(5) + "", 500L);
WeeklyOrders order7 = new WeeklyOrders(LocalDate.now().minusDays(6) + "", 600L); Instant instant = fromdt.atDate(LocalDate.now().minusDays(i)).atZone(ZoneId.systemDefault()).toInstant();
orders.add(order1); Date time1 = Date.from(instant);
orders.add(order2); Long fromDate = time1.getTime();
orders.add(order3);
orders.add(order4); Instant instant2 = todt.atDate(LocalDate.now().minusDays(i)).atZone(ZoneId.systemDefault()).toInstant();
orders.add(order5); Date time2 = Date.from(instant2);
orders.add(order6); Long toDate = time2.getTime();
orders.add(order7);
DynamicQuery dynamicQuery = new DynamicQuery();
dynamicQuery.setOrderDateFrom(fromDate);
dynamicQuery.setOrderDateTo(toDate);
Long orderCount = ordersSummaryRepository.query(dynamicQuery);
LocalDate formattedFromDate = Instant.ofEpochMilli(fromDate).atZone(ZoneId.systemDefault()).toLocalDate();
WeeklyOrders order = new WeeklyOrders(formattedFromDate + "", orderCount);
orders.add(order);
}
return orders; return orders;
} }
/* public OrdersSummary getOrderSummaryCount(){ public OrdersSummary getOrderSummaryCount(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-YYYY"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-YYYY");
LocalDateTime localTime = LocalDateTime.now(); LocalDateTime localTime = LocalDateTime.now();
OrdersSummary ordersSummary=new OrdersSummary(); OrdersSummary ordersSummary=new OrdersSummary();
...@@ -191,37 +167,12 @@ public class OrdersSummaryServiceImpl implements OrdersSummaryService { ...@@ -191,37 +167,12 @@ public class OrdersSummaryServiceImpl implements OrdersSummaryService {
ordersSummary.setCurrentDate(simpleDateFormat.format(new Date())); ordersSummary.setCurrentDate(simpleDateFormat.format(new Date()));
return ordersSummary; return ordersSummary;
} }
*/
public OrdersSummary getOrderSummaryCount(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-YYYY");
LocalDateTime localTime = LocalDateTime.now();
OrdersSummary ordersSummary=new OrdersSummary();
ordersSummary.setOrderCountInMinute(++minuteCount);
ordersSummary.setOrderCountInHour(++HrCount);
ordersSummary.setOrderCountInDay(++dayCount);
ordersSummary.setTotalCustomers(++cutomers);
ordersSummary.setCurrentMinute(LocalTime.of(localTime.getHour(), localTime.getMinute(),00).toString());
ordersSummary.setCurrentHour(LocalTime.of(localTime.getHour(), 00,00).toString());
ordersSummary.setCurrentDate(simpleDateFormat.format(new Date()));
return ordersSummary;
}
/* @Override
public Map<LocalDate, Long> getOrderSummaryInWeek() {
return orderCountInCustomDate();
}
*/
@Override @Override
public List<WeeklyOrders> getOrderSummaryInWeek() { public List<WeeklyOrders> getOrderSummaryInWeek() {
return orderCountInCustomDate(); 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