|
|
@@ -0,0 +1,137 @@
|
|
|
+package org.dromara.system.controller;
|
|
|
+
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.core.utils.DateUtils;
|
|
|
+import org.dromara.common.web.core.BaseController;
|
|
|
+import org.dromara.fulfiller.api.RemoteAuditService;
|
|
|
+import org.dromara.fulfiller.api.RemoteFulfillerService;
|
|
|
+import org.dromara.fulfiller.api.domain.vo.RemoteFulfillerVo;
|
|
|
+import org.dromara.order.api.RemoteSubOrderLogService;
|
|
|
+import org.dromara.order.api.RemoteSubOrderService;
|
|
|
+import org.dromara.order.api.domain.vo.RemoteSubOrderLogListVo;
|
|
|
+import org.dromara.order.api.domain.vo.RemoteSubOrderVo;
|
|
|
+import org.dromara.system.domain.SysStore;
|
|
|
+import org.dromara.system.domain.vo.AdminIndexCountVo;
|
|
|
+import org.dromara.system.domain.vo.AdminIndexFulfillerRankVo;
|
|
|
+import org.dromara.system.domain.vo.AdminIndexStoreRankVo;
|
|
|
+import org.dromara.system.domain.vo.AdminIndexSubOrderVo;
|
|
|
+import org.dromara.system.mapper.SysStoreMapper;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Validated
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin/index")
|
|
|
+public class AdminIndexController extends BaseController {
|
|
|
+
|
|
|
+ private final SysStoreMapper sysStoreMapper;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteAuditService remoteAuditService;
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteSubOrderService remoteSubOrderService;
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteSubOrderLogService remoteSubOrderLogService;
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteFulfillerService remoteFulfillerService;
|
|
|
+
|
|
|
+ @GetMapping("/count")
|
|
|
+ public R<AdminIndexCountVo> count() {
|
|
|
+ AdminIndexCountVo vo = new AdminIndexCountVo();
|
|
|
+ vo.setUnderReviewFulfillerCount(remoteAuditService.countUnderReview());
|
|
|
+ List<RemoteSubOrderVo> orders = remoteSubOrderService.listAfterDate(DateUtils.getDateDaysAgo(1L));
|
|
|
+ long priceToday = 0L, priceLastday = 0L;
|
|
|
+ int countToday = 0, countLastday = 0;
|
|
|
+ for (RemoteSubOrderVo order : orders) {
|
|
|
+ if (order.getCreateTime().before(DateUtils.getDateDaysAgo(0L))) {
|
|
|
+ countLastday++;
|
|
|
+ priceLastday += order.getPrice();
|
|
|
+ } else {
|
|
|
+ countToday++;
|
|
|
+ priceToday += order.getPrice();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setPriceToday(priceToday);
|
|
|
+ vo.setPriceLastday(priceLastday);
|
|
|
+ vo.setOrderCountToday(countToday);
|
|
|
+ vo.setOrderCountLastday(countLastday);
|
|
|
+ vo.setFulfillerCount(remoteFulfillerService.count());
|
|
|
+ List<SysStore> stores = sysStoreMapper.selectList();
|
|
|
+ int newStoreCountThisMonth = 0;
|
|
|
+ for (SysStore store : stores) {
|
|
|
+ if (store.getCreateTime().after(DateUtils.getFirstDayOfMonth())) {
|
|
|
+ newStoreCountThisMonth++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setStoreCount(stores.size());
|
|
|
+ vo.setNewStoreCountThisMonth(newStoreCountThisMonth);
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/listOrder")
|
|
|
+ public R<List<AdminIndexSubOrderVo>> listOrder(@RequestParam Integer type) {
|
|
|
+ Date time = type == 0 ? DateUtils.getDateDaysAgo(7L) : DateUtils.getFirstDayOfMonth();
|
|
|
+ return R.ok(remoteSubOrderService.listAfterDate(time).stream()
|
|
|
+ .map(e -> {
|
|
|
+ AdminIndexSubOrderVo vo = new AdminIndexSubOrderVo();
|
|
|
+ vo.setId(e.getId());
|
|
|
+ vo.setService(e.getService());
|
|
|
+ vo.setPrice(e.getPrice());
|
|
|
+ vo.setCreateTime(e.getCreateTime());
|
|
|
+ return vo;
|
|
|
+ }).toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/fulfillerRank")
|
|
|
+ public R<List<AdminIndexFulfillerRankVo>> fulfillerRank() {
|
|
|
+ Map<Long, List<RemoteSubOrderLogListVo>> map = new HashMap<>();
|
|
|
+ List<RemoteSubOrderLogListVo> list = remoteSubOrderLogService.listAllRecieved();
|
|
|
+ list.forEach(e -> map.computeIfAbsent(e.getFulfiller(), k -> new ArrayList<>()).add(e));
|
|
|
+ return R.ok(map.entrySet().stream()
|
|
|
+ .sorted(Map.Entry.<Long, List<RemoteSubOrderLogListVo>>comparingByValue(
|
|
|
+ Comparator.comparingInt(List::size)
|
|
|
+ ).reversed())
|
|
|
+ .limit(5)
|
|
|
+ .map(entry -> {
|
|
|
+ AdminIndexFulfillerRankVo vo = new AdminIndexFulfillerRankVo();
|
|
|
+ vo.setId(entry.getKey());
|
|
|
+ vo.setCount(entry.getValue().size());
|
|
|
+ RemoteFulfillerVo fulfiller = remoteFulfillerService.getById(entry.getKey());
|
|
|
+ vo.setName(fulfiller.getName());
|
|
|
+ vo.setSite(fulfiller.getSite());
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/storeRank")
|
|
|
+ public R<List<AdminIndexStoreRankVo>> storeRank() {
|
|
|
+ List<RemoteSubOrderVo> list = remoteSubOrderService.listAll();
|
|
|
+ Map<Long, List<RemoteSubOrderVo>> map = new HashMap<>();
|
|
|
+ list.forEach(e -> map.computeIfAbsent(e.getStore(), k -> new ArrayList<>()).add(e));
|
|
|
+ return R.ok(map.entrySet().stream()
|
|
|
+ .sorted(Map.Entry.<Long, List<RemoteSubOrderVo>>comparingByValue(
|
|
|
+ Comparator.comparingInt(List::size)
|
|
|
+ ).reversed()).limit(5)
|
|
|
+ .map(entry -> {
|
|
|
+ AdminIndexStoreRankVo vo = new AdminIndexStoreRankVo();
|
|
|
+ vo.setId(entry.getKey());
|
|
|
+ vo.setCount(entry.getValue().size());
|
|
|
+ SysStore store = sysStoreMapper.selectById(entry.getKey());
|
|
|
+ vo.setName(store.getName());
|
|
|
+ vo.setLogo(store.getLogo());
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|