|
@@ -0,0 +1,134 @@
|
|
|
|
|
+package shop.alien.store.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson2.util.DateUtils;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+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.LifeUserOrder;
|
|
|
|
|
+import shop.alien.entity.store.vo.LifeGroupBuyCountDateVo;
|
|
|
|
|
+import shop.alien.entity.store.vo.LifeGroupBuyCountVo;
|
|
|
|
|
+import shop.alien.mapper.LifeGroupBuyCountMapper;
|
|
|
|
|
+import shop.alien.mapper.LifeUserOrderMapper;
|
|
|
|
|
+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.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 团购统计
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class LifeGroupBuyCountServiceImpl extends ServiceImpl<LifeGroupBuyCountMapper, LifeGroupBuyCount> implements LifeGroupBuyCountService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private LifeGroupBuyCountMapper lifeGroupBuyCountMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private LifeUserOrderMapper lifeUserOrderMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void insertGroupBuyCount(LifeGroupBuyCount lifeGroupBuyCount) {
|
|
|
|
|
+ LambdaQueryWrapper<LifeGroupBuyCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(LifeGroupBuyCount::getCountType, lifeGroupBuyCount.getCountType())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getStoreId, lifeGroupBuyCount.getStoreId())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getGroupId, lifeGroupBuyCount.getGroupId())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getUserId, lifeGroupBuyCount.getUserId())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getCountDate, DateUtils.format(new Date(), "yyyy-MM-dd"));
|
|
|
|
|
+ Integer count = lifeGroupBuyCountMapper.selectCount(queryWrapper);
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ List<LifeGroupBuyCount> lifeGroupBuyCounts = lifeGroupBuyCountMapper.selectList(queryWrapper);
|
|
|
|
|
+ LambdaUpdateWrapper<LifeGroupBuyCount> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.eq(LifeGroupBuyCount::getCountType, lifeGroupBuyCount.getCountType())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getStoreId, lifeGroupBuyCount.getStoreId())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getGroupId, lifeGroupBuyCount.getGroupId())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getUserId, lifeGroupBuyCount.getUserId())
|
|
|
|
|
+ .eq(LifeGroupBuyCount::getCountDate, DateUtils.format(new Date(), "yyyy-MM-dd"))
|
|
|
|
|
+ .set(LifeGroupBuyCount::getCountNum, lifeGroupBuyCounts.get(0).getCountNum() + 1);
|
|
|
|
|
+ lifeGroupBuyCountMapper.update(null, queryWrapper);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lifeGroupBuyCount.setCountNum(1);
|
|
|
|
|
+ lifeGroupBuyCountMapper.insert(lifeGroupBuyCount);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<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");
|
|
|
|
|
+
|
|
|
|
|
+ List<LifeGroupBuyCountVo> todayList = lifeGroupBuyCountMapper.selectJysjListByStoreId(storeId, today);
|
|
|
|
|
+ List<LifeGroupBuyCountVo> yesterdayList = lifeGroupBuyCountMapper.selectJysjListByStoreId(storeId, yesterday);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(todayList)) {
|
|
|
|
|
+ for (LifeGroupBuyCountVo lifeGroupBuyCountVo : todayList) {
|
|
|
|
|
+ //昨天数据
|
|
|
|
|
+ if (yesterdayList.stream().map(LifeGroupBuyCount::getCountType).collect(Collectors.toList()).contains(lifeGroupBuyCountVo.getCountType())) {
|
|
|
|
|
+ yesterdayList.stream().filter(item -> item.getCountType().equals(lifeGroupBuyCountVo.getCountType())).findFirst().ifPresent(item -> lifeGroupBuyCountVo.setYesCountNum(item.getCountNum().toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<LifeGroupBuyCountVo> collect = todayList.stream().filter(item -> "0".equals(item.getCountType())).collect(Collectors.toList());
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(collect)) {
|
|
|
|
|
+ LifeGroupBuyCountVo lifeGroupBuyCountVo = collect.get(0);
|
|
|
|
|
+
|
|
|
|
|
+ LifeGroupBuyCountVo countVo = new LifeGroupBuyCountVo();
|
|
|
|
|
+ //访客
|
|
|
|
|
+ countVo.setCountType("1");
|
|
|
|
|
+ countVo.setCountNum(Integer.valueOf(lifeGroupBuyCountVo.getPersonNum()));
|
|
|
|
|
+ //昨天的访客人数
|
|
|
|
|
+ yesterdayList.stream().filter(item -> "0".equals(item.getCountType())).findFirst().ifPresent(item -> countVo.setYesCountNum(item.getPersonNum()));
|
|
|
|
|
+ todayList.add(countVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<LifeUserOrder> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ orderLambdaQueryWrapper.eq(LifeUserOrder::getStoreId, storeId)
|
|
|
|
|
+ .eq(LifeUserOrder::getStatus, "7")
|
|
|
|
|
+ .like(LifeUserOrder::getFinishTime, today);
|
|
|
|
|
+ Integer todayOrderNum = lifeUserOrderMapper.selectCount(orderLambdaQueryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<LifeUserOrder> orderLambdaQueryWrapper1 = new LambdaQueryWrapper<>();
|
|
|
|
|
+ orderLambdaQueryWrapper1.eq(LifeUserOrder::getStoreId, storeId)
|
|
|
|
|
+ .eq(LifeUserOrder::getStatus, "7")
|
|
|
|
|
+ .like(LifeUserOrder::getFinishTime, yesterday);
|
|
|
|
|
+ Integer yesterdayOrderNum = lifeUserOrderMapper.selectCount(orderLambdaQueryWrapper1);
|
|
|
|
|
+ LifeGroupBuyCountVo countVo = new LifeGroupBuyCountVo();
|
|
|
|
|
+ countVo.setCountType("4");
|
|
|
|
|
+ countVo.setCountNum(todayOrderNum);
|
|
|
|
|
+ countVo.setYesCountNum(yesterdayOrderNum.toString());
|
|
|
|
|
+ todayList.add(countVo);
|
|
|
|
|
+ bfb(todayList);
|
|
|
|
|
+ return todayList.stream().sorted(Comparator.comparing(LifeGroupBuyCountVo::getCountType)).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @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"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ 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.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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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%");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|