catmonthmodel
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package de.htwsaar.webshop.controller;
|
package de.htwsaar.webshop.controller;
|
||||||
|
|
||||||
import de.htwsaar.webshop.model.CatMonthModel;
|
import de.htwsaar.webshop.model.CategoryMonthModel;
|
||||||
import de.htwsaar.webshop.model.OrderStatus;
|
import de.htwsaar.webshop.model.OrderStatus;
|
||||||
import de.htwsaar.webshop.service.SessionService;
|
import de.htwsaar.webshop.service.SessionService;
|
||||||
import de.htwsaar.webshop.service.StatisticsService;
|
import de.htwsaar.webshop.service.StatisticsService;
|
||||||
@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ public class StatisticsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = STATISTICS_VOLUME, method = RequestMethod.GET, produces = "application/json")
|
@RequestMapping(value = STATISTICS_VOLUME, method = RequestMethod.GET, produces = "application/json")
|
||||||
public ResponseEntity<CatMonthModel<Integer>> getMonthlySalesVolume(HttpServletRequest request,
|
public ResponseEntity<CategoryMonthModel<Integer>> getMonthlySalesVolume(HttpServletRequest request,
|
||||||
@RequestParam(value = PARAM_SESSION) UUID session,
|
@RequestParam(value = PARAM_SESSION) UUID session,
|
||||||
@RequestParam(value = PARAM_EMAIL) String email) {
|
@RequestParam(value = PARAM_EMAIL) String email) {
|
||||||
logRequest(request);
|
logRequest(request);
|
||||||
@@ -46,7 +45,7 @@ public class StatisticsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = STATISTICS_REVENUE, method = RequestMethod.GET, produces = "application/json")
|
@RequestMapping(value = STATISTICS_REVENUE, method = RequestMethod.GET, produces = "application/json")
|
||||||
public ResponseEntity<CatMonthModel<Integer>> getMonthlyRevenue(HttpServletRequest request,
|
public ResponseEntity<CategoryMonthModel<Integer>> getMonthlyRevenue(HttpServletRequest request,
|
||||||
@RequestParam(value = PARAM_SESSION) UUID token,
|
@RequestParam(value = PARAM_SESSION) UUID token,
|
||||||
@RequestParam(value = PARAM_EMAIL) String email) {
|
@RequestParam(value = PARAM_EMAIL) String email) {
|
||||||
logRequest(request);
|
logRequest(request);
|
||||||
|
|||||||
@@ -16,17 +16,10 @@ public class ExpiredSessionDeleteJob {
|
|||||||
|
|
||||||
private final SessionService sessionService;
|
private final SessionService sessionService;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor of the class
|
|
||||||
* @param sessionService used in the class
|
|
||||||
*/
|
|
||||||
public ExpiredSessionDeleteJob(SessionService sessionService) {
|
public ExpiredSessionDeleteJob(SessionService sessionService) {
|
||||||
this.sessionService = sessionService;
|
this.sessionService = sessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method running the job calling the referring service method
|
|
||||||
*/
|
|
||||||
@Scheduled(fixedRate = MILLIS_TO_WEEK)
|
@Scheduled(fixedRate = MILLIS_TO_WEEK)
|
||||||
public void runFixedRateTask() {
|
public void runFixedRateTask() {
|
||||||
log.info("Deleting expired sessions...");
|
log.info("Deleting expired sessions...");
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ import java.util.Map;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CatMonthModel<T extends Number> {
|
public class CategoryMonthModel<T extends Number> {
|
||||||
Map<String, Map<Long, T>> catMonthMap;
|
Map<String, Map<Long, T>> catMonthMap;
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
package de.htwsaar.webshop.service;
|
package de.htwsaar.webshop.service;
|
||||||
|
|
||||||
import de.htwsaar.webshop.model.CatMonthModel;
|
import de.htwsaar.webshop.model.CategoryMonthModel;
|
||||||
import de.htwsaar.webshop.model.OrderStatus;
|
import de.htwsaar.webshop.model.OrderStatus;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface StatisticsService {
|
public interface StatisticsService {
|
||||||
CatMonthModel<Integer> getSalesVolume();
|
CategoryMonthModel<Integer> getSalesVolume();
|
||||||
|
|
||||||
CatMonthModel<Integer> getSalesRevenue();
|
CategoryMonthModel<Integer> getSalesRevenue();
|
||||||
|
|
||||||
Map<OrderStatus, Integer> getOrderStatus();
|
Map<OrderStatus, Integer> getOrderStatus();
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package de.htwsaar.webshop.service.impl;
|
package de.htwsaar.webshop.service.impl;
|
||||||
|
|
||||||
import de.htwsaar.webshop.model.ArticleCategory;
|
import de.htwsaar.webshop.model.ArticleCategory;
|
||||||
import de.htwsaar.webshop.model.CatMonthModel;
|
import de.htwsaar.webshop.model.CategoryMonthModel;
|
||||||
import de.htwsaar.webshop.model.OrderStatus;
|
import de.htwsaar.webshop.model.OrderStatus;
|
||||||
import de.htwsaar.webshop.repository.entities.OrderItem;
|
import de.htwsaar.webshop.repository.entities.OrderItem;
|
||||||
import de.htwsaar.webshop.service.ArticleService;
|
import de.htwsaar.webshop.service.ArticleService;
|
||||||
@@ -30,7 +30,7 @@ public class StatisticsServiceImpl implements StatisticsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//returns Map<unix milli timestamp, Map<Category, T>>
|
//returns Map<unix milli timestamp, Map<Category, T>>
|
||||||
private <T extends Number> CatMonthModel<T> getMonthCategoryMap(Function<OrderItem, T> mappingFunction,
|
private <T extends Number> CategoryMonthModel<T> getMonthCategoryMap(Function<OrderItem, T> mappingFunction,
|
||||||
BinaryOperator<T> reduceFunction,
|
BinaryOperator<T> reduceFunction,
|
||||||
T defaultValue) {
|
T defaultValue) {
|
||||||
Map<String, Map<Long, T>> map = new TreeMap<>();
|
Map<String, Map<Long, T>> map = new TreeMap<>();
|
||||||
@@ -49,16 +49,16 @@ public class StatisticsServiceImpl implements StatisticsService {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return new CatMonthModel<>(map);
|
return new CategoryMonthModel<>(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CatMonthModel<Integer> getSalesVolume() {
|
public CategoryMonthModel<Integer> getSalesVolume() {
|
||||||
return getMonthCategoryMap(OrderItem::getAmount, Integer::sum, 0);
|
return getMonthCategoryMap(OrderItem::getAmount, Integer::sum, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CatMonthModel<Integer> getSalesRevenue() {
|
public CategoryMonthModel<Integer> getSalesRevenue() {
|
||||||
return getMonthCategoryMap(item -> item.getArticle().getPrice100(), Integer::sum, 0);
|
return getMonthCategoryMap(item -> item.getArticle().getPrice100(), Integer::sum, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user