浏览代码

商家经营数据

jyc 3 月之前
父节点
当前提交
28c2af235e

+ 1 - 1
alien-entity/src/main/java/shop/alien/mapper/LifeGroupBuyCountMapper.java

@@ -38,7 +38,7 @@ public interface LifeGroupBuyCountMapper extends BaseMapper<LifeGroupBuyCount> {
             "(select count(DISTINCT(user_id)) from life_group_buy_count where count_type = '0' and group_id = groupId group by count_date) spfks, " +
             "(select count(0) from life_collect where coupon_id = groupId and business_type is null and delete_flag = 0) spscl, " +
             "(select count(DISTINCT(luo.user_id)) from life_user_order luo left join order_coupon_middle ocm on luo.id = ocm.order_id  where luo.coupon_type = 2 and luo.status = '7' and ocm.coupon_id = groupId) jgrs, " +
-            "(select count(0) from life_user_order luo left join order_coupon_middle ocm on luo.id = ocm.order_id  where luo.coupon_type = 2 and luo.status = '7' and ocm.coupon_id = groupId) xfrs " +
+            "(select count(0) from order_coupon_middle ocm left join life_user_order luo on luo.id = ocm.order_id  where luo.coupon_type = 2 and luo.status = '7' and ocm.coupon_id = groupId) xfrs " +
             "from life_group_buy_main where store_id = #{storeId} order by spfwl desc")
     List<LifeGroupBuyCountDateVo> selectDpzbpmListByStoreId(@Param("storeId") String storeId);
 }

+ 1 - 1
alien-store/src/main/java/shop/alien/store/controller/LifeGroupBuyCountController.java

@@ -43,7 +43,7 @@ public class LifeGroupBuyCountController {
     @ApiOperation("团购统计-经营数据")
     @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query", required = true)})
     @GetMapping("/getJysj")
-    private R<List<LifeGroupBuyCountVo>> getJysj(@RequestParam(value = "storeId") String storeId) {
+    private R getJysj(@RequestParam(value = "storeId") String storeId) {
         log.info("LifeGroupBuyCountController.getJysj?storeId={}", storeId);
         return R.data(lifeGroupBuyCountService.getJysj(storeId));
     }

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/LifeGroupBuyCountService.java

@@ -7,6 +7,7 @@ import shop.alien.entity.store.vo.LifeGroupBuyCountDateVo;
 import shop.alien.entity.store.vo.LifeGroupBuyCountVo;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 团购统计
@@ -15,7 +16,7 @@ public interface LifeGroupBuyCountService extends IService<LifeGroupBuyCount> {
 
     void insertGroupBuyCount(Integer storeId, Integer groupId, Integer userId, String countType);
 
-    List<LifeGroupBuyCountVo> getJysj(String storeId);
+    Map<String, LifeGroupBuyCountVo> getJysj(String storeId);
 
     List<LifeGroupBuyCountDateVo> getSphxzb(String storeId);
 

+ 19 - 7
alien-store/src/main/java/shop/alien/store/service/impl/LifeGroupBuyCountServiceImpl.java

@@ -19,9 +19,7 @@ import shop.alien.store.service.LifeGroupBuyCountService;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -69,7 +67,7 @@ public class LifeGroupBuyCountServiceImpl extends ServiceImpl<LifeGroupBuyCountM
     }
 
     @Override
-    public List<LifeGroupBuyCountVo> getJysj(String storeId) {
+    public Map<String, LifeGroupBuyCountVo> getJysj(String storeId) {
         String today = DateUtils.format(new Date(), "yyyy-MM-dd");
         String yesterday = DateUtils.format(shop.alien.util.common.DateUtils.calcDays(new Date(), -1), "yyyy-MM-dd");
 
@@ -114,12 +112,26 @@ public class LifeGroupBuyCountServiceImpl extends ServiceImpl<LifeGroupBuyCountM
         countVo.setYesCountNum(yesterdayOrderNum.toString());
         todayList.add(countVo);
         bfb(todayList);
-        return todayList.stream().sorted(Comparator.comparing(LifeGroupBuyCountVo::getCountType)).collect(Collectors.toList());
+
+        Map<String, LifeGroupBuyCountVo> map = new HashMap<>();
+        map.put("tcfwl", new LifeGroupBuyCountVo());
+        map.put("tcfks", new LifeGroupBuyCountVo());
+        map.put("sjtcs", new LifeGroupBuyCountVo());
+        map.put("xjtcs", new LifeGroupBuyCountVo());
+        map.put("sfrs", new LifeGroupBuyCountVo());
+        todayList.stream().filter(item -> "0".equals(item.getCountType())).findFirst().ifPresent(item -> map.put("tcfwl", item));
+        todayList.stream().filter(item -> "1".equals(item.getCountType())).findFirst().ifPresent(item -> map.put("tcfks", item));
+        todayList.stream().filter(item -> "2".equals(item.getCountType())).findFirst().ifPresent(item -> map.put("sjtcs", item));
+        todayList.stream().filter(item -> "3".equals(item.getCountType())).findFirst().ifPresent(item -> map.put("xjtcs", item));
+        todayList.stream().filter(item -> "4".equals(item.getCountType())).findFirst().ifPresent(item -> map.put("sfrs", item));
+        return map;
     }
 
     @Override
     public List<LifeGroupBuyCountDateVo> getSphxzb(String storeId) {
-        return lifeGroupBuyCountMapper.selectSphxzbListByStoreId(storeId, DateUtils.format(new Date(), "yyyy-MM-dd"), DateUtils.format(shop.alien.util.common.DateUtils.calcDays(new Date(), -7), "yyyy-MM-dd"));
+        List<LifeGroupBuyCountDateVo> lifeGroupBuyCountDateVos = lifeGroupBuyCountMapper.selectSphxzbListByStoreId(storeId, DateUtils.format(shop.alien.util.common.DateUtils.calcDays(new Date(), -6), "yyyy-MM-dd"), DateUtils.format(new Date(), "yyyy-MM-dd"));
+        lifeGroupBuyCountDateVos.forEach(i -> i.setCountDate(DateUtils.format(DateUtils.parseDate(i.getCountDate()), "MM-dd")));
+        return lifeGroupBuyCountDateVos;
     }
 
     @Override
@@ -134,7 +146,7 @@ public class LifeGroupBuyCountServiceImpl extends ServiceImpl<LifeGroupBuyCountM
 
     private void bfb(List<LifeGroupBuyCountVo> list) {
         for (LifeGroupBuyCountVo item : list) {
-                item.setJqrBfb(StringUtils.isNotEmpty(item.getYesCountNum()) && !"0".equals(item.getYesCountNum()) ? new BigDecimal(item.getYesCountNum()).subtract(new BigDecimal(item.getCountNum())).divide(new BigDecimal(item.getYesCountNum()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)) + "%" : "0.0%");
+                item.setJqrBfb(StringUtils.isNotEmpty(item.getYesCountNum()) && !"0".equals(item.getYesCountNum()) ? new BigDecimal(item.getYesCountNum()).subtract(new BigDecimal(item.getCountNum())).divide(new BigDecimal(item.getYesCountNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)) + "%" : "0.00%");
         }
     }
 }