Преглед на файлове

商家经营数据,定时统计团购上下架数据

jyc преди 3 месеца
родител
ревизия
4beb5c32ef

+ 82 - 0
alien-job/src/main/java/shop/alien/job/store/LifeGroupBuyCountJob.java

@@ -0,0 +1,82 @@
+package shop.alien.job.store;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import shop.alien.entity.store.*;
+import shop.alien.entity.store.vo.LifeUserOrderVo;
+import shop.alien.job.feign.AlienStoreFeign;
+import shop.alien.mapper.*;
+import shop.alien.util.common.UniqueRandomNumGenerator;
+import shop.alien.util.common.constant.DiscountCouponEnum;
+import shop.alien.util.common.constant.OrderStatusEnum;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 团购上下架数据统计
+ *
+ * @author jyc
+ * @date 2023/12/20 14:20
+ * @see LifeUserOrder
+ */
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class LifeGroupBuyCountJob {
+
+    private final LifeGroupBuyCountMapper lifeGroupBuyCountMapper;
+    private final LifeGroupBuyMainMapper lifeGroupBuyMainMapper;
+
+    /**
+     * 待支付订单超时处理
+     */
+    @XxlJob("countSxjGroupBuy")
+    @Transactional(rollbackFor = Exception.class)
+    public void autoCancelUnpaidOrders() {
+        List<LifeGroupBuyCount> list = new ArrayList<>();
+        //上架数据
+        LambdaQueryWrapper<LifeGroupBuyMain> sjQuery = new LambdaQueryWrapper<>();
+        sjQuery.eq(LifeGroupBuyMain::getStatus, "5").eq(LifeGroupBuyMain::getDeleteFlag, 0).eq(LifeGroupBuyMain::getGroupType, 1);
+        Map<String, List<LifeGroupBuyMain>> sjCollect = lifeGroupBuyMainMapper.selectList(sjQuery).stream().collect(Collectors.groupingBy(LifeGroupBuyMain::getStoreId));
+        for (String s : sjCollect.keySet()) {
+            LifeGroupBuyCount sj = new LifeGroupBuyCount();
+            sj.setStoreId(Integer.valueOf(sjCollect.get(s).get(0).getStoreId()));
+            sj.setCountType("2");
+            sj.setCountNum(sjCollect.get(s).size());
+            sj.setCountDate(new Date());
+            list.add(sj);
+        }
+
+        //下架数据
+        LambdaQueryWrapper<LifeGroupBuyMain> xjQuery = new LambdaQueryWrapper<>();
+        xjQuery.in(LifeGroupBuyMain::getStatus, "7", "8").eq(LifeGroupBuyMain::getDeleteFlag, 0).eq(LifeGroupBuyMain::getGroupType, 1);
+        Map<String, List<LifeGroupBuyMain>> xjCollect = lifeGroupBuyMainMapper.selectList(xjQuery).stream().collect(Collectors.groupingBy(LifeGroupBuyMain::getStoreId));
+        for (String s : xjCollect.keySet()) {
+            LifeGroupBuyCount xj = new LifeGroupBuyCount();
+            xj.setStoreId(Integer.valueOf(xjCollect.get(s).get(0).getStoreId()));
+            xj.setCountType("3");
+            xj.setCountNum(xjCollect.get(s).size());
+            xj.setCountDate(new Date());
+            list.add(xj);
+        }
+        if (ObjectUtils.isNotEmpty(list)) {
+            lifeGroupBuyCountMapper.insertList(list);
+        }
+    }
+}
+

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

@@ -63,4 +63,11 @@ public class LifeGroupBuyCountController {
         log.info("LifeGroupBuyCountController.getDpzbpm?storeId={}", storeId);
         return R.data(lifeGroupBuyCountService.getDpzbpm(storeId));
     }
+
+    /*@ApiOperation("团购统计-测试")
+    @GetMapping("/test")
+    private R test() {
+        lifeGroupBuyCountService.test();
+        return R.success("成功");
+    }*/
 }

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

@@ -21,4 +21,6 @@ public interface LifeGroupBuyCountService extends IService<LifeGroupBuyCount> {
     List<LifeGroupBuyCountDateVo> getSphxzb(String storeId);
 
     List<LifeGroupBuyCountDateVo> getDpzbpm(String storeId);
+
+    void test();
 }

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

@@ -10,14 +10,17 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import shop.alien.entity.store.LifeGroupBuyCount;
+import shop.alien.entity.store.LifeGroupBuyMain;
 import shop.alien.entity.store.LifeUserOrder;
 import shop.alien.entity.store.vo.LifeGroupBuyCountDateVo;
 import shop.alien.entity.store.vo.LifeGroupBuyCountVo;
 import shop.alien.mapper.LifeGroupBuyCountMapper;
+import shop.alien.mapper.LifeGroupBuyMainMapper;
 import shop.alien.mapper.LifeUserOrderMapper;
 import shop.alien.store.service.LifeGroupBuyCountService;
 
 import java.math.BigDecimal;
+import java.math.MathContext;
 import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -35,6 +38,9 @@ public class LifeGroupBuyCountServiceImpl extends ServiceImpl<LifeGroupBuyCountM
     @Autowired
     private LifeUserOrderMapper lifeUserOrderMapper;
 
+    @Autowired
+    private LifeGroupBuyMainMapper lifeGroupBuyMainMapper;
+
     @Override
     public void insertGroupBuyCount(Integer storeId, Integer groupId, Integer userId, String countType) {
         LambdaQueryWrapper<LifeGroupBuyCount> queryWrapper = new LambdaQueryWrapper<>();
@@ -114,11 +120,21 @@ public class LifeGroupBuyCountServiceImpl extends ServiceImpl<LifeGroupBuyCountM
         bfb(todayList);
 
         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());
+        LifeGroupBuyCountVo tcfwl = new LifeGroupBuyCountVo();
+        tcfwl.setCountType("0");
+        LifeGroupBuyCountVo tcfks = new LifeGroupBuyCountVo();
+        tcfks.setCountType("1");
+        LifeGroupBuyCountVo sjtcs = new LifeGroupBuyCountVo();
+        sjtcs.setCountType("2");
+        LifeGroupBuyCountVo xjtcs = new LifeGroupBuyCountVo();
+        xjtcs.setCountType("3");
+        LifeGroupBuyCountVo sfrs = new LifeGroupBuyCountVo();
+        sfrs.setCountType("4");
+        map.put("tcfwl", tcfwl);
+        map.put("tcfks", tcfks);
+        map.put("sjtcs", sjtcs);
+        map.put("xjtcs", xjtcs);
+        map.put("sfrs", sfrs);
         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));
@@ -138,15 +154,46 @@ public class LifeGroupBuyCountServiceImpl extends ServiceImpl<LifeGroupBuyCountM
     public List<LifeGroupBuyCountDateVo> getDpzbpm(String storeId) {
         List<LifeGroupBuyCountDateVo> lifeGroupBuyCountDateVos = lifeGroupBuyCountMapper.selectDpzbpmListByStoreId(storeId);
         for (LifeGroupBuyCountDateVo lifeGroupBuyCountDateVo : lifeGroupBuyCountDateVos) {
-            lifeGroupBuyCountDateVo.setRjfws(StringUtils.isNotEmpty(lifeGroupBuyCountDateVo.getSpfks()) ? new BigDecimal(lifeGroupBuyCountDateVo.getSpfwl()).divide(new BigDecimal(lifeGroupBuyCountDateVo.getSpfks()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)) + "%" : "0.0%");
+            lifeGroupBuyCountDateVo.setRjfws(StringUtils.isNotEmpty(lifeGroupBuyCountDateVo.getSpfks()) ? (new BigDecimal(lifeGroupBuyCountDateVo.getSpfwl()).divide(new BigDecimal(lifeGroupBuyCountDateVo.getSpfks()), 0, RoundingMode.HALF_UP)).toString() : "0");
             lifeGroupBuyCountDateVo.setScl(StringUtils.isNotEmpty(lifeGroupBuyCountDateVo.getSpfks()) ? new BigDecimal(lifeGroupBuyCountDateVo.getSpscl()).divide(new BigDecimal(lifeGroupBuyCountDateVo.getSpfks()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)) + "%" : "0.0%");
         }
         return lifeGroupBuyCountDateVos;
     }
 
+    @Override
+    public void test() {
+        List<LifeGroupBuyCount> list = new ArrayList<>();
+        LambdaQueryWrapper<LifeGroupBuyMain> sjQuery = new LambdaQueryWrapper<>();
+        sjQuery.eq(LifeGroupBuyMain::getStatus, "5").eq(LifeGroupBuyMain::getDeleteFlag, 0).eq(LifeGroupBuyMain::getGroupType, 1);
+        Map<String, List<LifeGroupBuyMain>> sjCollect = lifeGroupBuyMainMapper.selectList(sjQuery).stream().collect(Collectors.groupingBy(LifeGroupBuyMain::getStoreId));
+        for (String s : sjCollect.keySet()) {
+            LifeGroupBuyCount sj = new LifeGroupBuyCount();
+            sj.setStoreId(Integer.valueOf(sjCollect.get(s).get(0).getStoreId()));
+            sj.setCountType("2");
+            sj.setCountNum(sjCollect.get(s).size());
+            sj.setCountDate(new Date());
+            list.add(sj);
+        }
+
+        LambdaQueryWrapper<LifeGroupBuyMain> xjQuery = new LambdaQueryWrapper<>();
+        xjQuery.in(LifeGroupBuyMain::getStatus, "7", "8").eq(LifeGroupBuyMain::getDeleteFlag, 0).eq(LifeGroupBuyMain::getGroupType, 1);
+        Map<String, List<LifeGroupBuyMain>> xjCollect = lifeGroupBuyMainMapper.selectList(xjQuery).stream().collect(Collectors.groupingBy(LifeGroupBuyMain::getStoreId));
+        for (String s : xjCollect.keySet()) {
+            LifeGroupBuyCount xj = new LifeGroupBuyCount();
+            xj.setStoreId(Integer.valueOf(xjCollect.get(s).get(0).getStoreId()));
+            xj.setCountType("3");
+            xj.setCountNum(xjCollect.get(s).size());
+            xj.setCountDate(new Date());
+            list.add(xj);
+        }
+        if (ObjectUtils.isNotEmpty(list)) {
+            lifeGroupBuyCountMapper.insertList(list);
+        }
+    }
+
     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()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)) + "%" : "0.00%");
+            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)).setScale(2, RoundingMode.HALF_UP) + "%" : "0.00%");
         }
     }
 }