|
|
@@ -10,93 +10,21 @@
|
|
|
|
|
|
package com.yami.shop.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.io.IORuntimeException;
|
|
|
-import cn.hutool.core.lang.Snowflake;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.RandomUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.poi.excel.ExcelUtil;
|
|
|
-import cn.hutool.poi.excel.ExcelWriter;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import com.google.common.collect.Maps;
|
|
|
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
-import com.google.gson.internal.LinkedTreeMap;
|
|
|
-import com.yami.shop.bean.app.dto.OrderCountData;
|
|
|
-import com.yami.shop.bean.app.dto.ShopCartOrderMergerDto;
|
|
|
-import com.yami.shop.bean.dto.hb.HBBaseReq;
|
|
|
-import com.yami.shop.bean.enums.*;
|
|
|
-import com.yami.shop.bean.event.CancelOrderEvent;
|
|
|
-import com.yami.shop.bean.event.ReceiptOrderEvent;
|
|
|
-import com.yami.shop.bean.event.SubmitOrderEvent;
|
|
|
-import com.yami.shop.bean.event.SubmitScoreOrderEvent;
|
|
|
import com.yami.shop.bean.model.*;
|
|
|
-import com.yami.shop.bean.param.*;
|
|
|
-import com.yami.shop.bean.prodWatefallFlow.CountInventoryNum;
|
|
|
-import com.yami.shop.bean.prodWatefallFlow.CountSales;
|
|
|
-import com.yami.shop.bean.vo.ExportContext;
|
|
|
-import com.yami.shop.bean.vo.OrderCountVo;
|
|
|
-import com.yami.shop.common.config.Constant;
|
|
|
-import com.yami.shop.common.exception.GlobalException;
|
|
|
-import com.yami.shop.common.util.Arith;
|
|
|
-import com.yami.shop.common.util.PageAdapter;
|
|
|
-import com.yami.shop.common.util.PageParam;
|
|
|
-import com.yami.shop.common.util.R;
|
|
|
+import com.yami.shop.bean.prodWaterfallFlow.CountInventoryNum;
|
|
|
+import com.yami.shop.bean.prodWaterfallFlow.CountSales;
|
|
|
import com.yami.shop.dao.*;
|
|
|
import com.yami.shop.service.*;
|
|
|
-import com.yami.shop.utils.CullenUtils;
|
|
|
-import com.yami.shop.utils.ExportUtils;
|
|
|
-import com.yami.shop.utils.HBSignUtil;
|
|
|
-import com.yami.shop.wx.po.RefundInfoPo;
|
|
|
-import com.yami.shop.wx.service.WxProviderService;
|
|
|
import io.swagger.annotations.ApiModelProperty;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-import org.apache.poi.xssf.streaming.SXSSFSheet;
|
|
|
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.cache.annotation.CacheEvict;
|
|
|
-import org.springframework.cache.annotation.CachePut;
|
|
|
-import org.springframework.cache.annotation.Cacheable;
|
|
|
-import org.springframework.context.ApplicationEventPublisher;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import javax.servlet.ServletOutputStream;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.BufferedOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.rmi.server.ExportException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import static com.yami.shop.common.util.HttpUtil.post;
|
|
|
|
|
|
/**
|
|
|
* @author lgh on 2018/09/15.
|
|
|
@@ -107,6 +35,8 @@ import static com.yami.shop.common.util.HttpUtil.post;
|
|
|
public class ProdWaterfallFlowServiceImpl extends ServiceImpl<ProdWaterfallFlowMapper, WaterfallFlow> implements ProdWaterfallFlowService {
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProdWaterfallFlowNormalizationMapper prodWaterfallFlowNormalizationMapper;
|
|
|
// /**
|
|
|
// * 7天的销量
|
|
|
// * 统计销售量并更新销量
|
|
|
@@ -124,40 +54,21 @@ public class ProdWaterfallFlowServiceImpl extends ServiceImpl<ProdWaterfallFlowM
|
|
|
* 统计每天的销量
|
|
|
*/
|
|
|
public List<CountSales> countSales(LocalDateTime yesterdayStart, LocalDateTime todayStart) {
|
|
|
-// LocalDateTime todayStart = LocalDate.now().atStartOfDay(); // 今天0点
|
|
|
-// LocalDateTime yesterdayStart = todayStart.minusDays(1); // 昨天0点
|
|
|
- List<CountSales> countSales = baseMapper.countSales(yesterdayStart,todayStart);
|
|
|
-// List<WaterfallFlow> waterfallFlows = new ArrayList<>();
|
|
|
-// BeanUtils.copyProperties(countSales,waterfallFlows);
|
|
|
-// baseMapper.saveByConcatId(waterfallFlows);
|
|
|
- return countSales;
|
|
|
+ return baseMapper.countSales(yesterdayStart,todayStart);
|
|
|
}
|
|
|
/**
|
|
|
* 每天统计库存
|
|
|
*/
|
|
|
public List<CountInventoryNum> countInventoryNum() {
|
|
|
- List<CountInventoryNum> countInventoryNums =baseMapper.countInventoryNum();
|
|
|
-// List<WaterfallFlow> waterfallFlows = new ArrayList<>();
|
|
|
-// BeanUtils.copyProperties(countInventoryNums,waterfallFlows);
|
|
|
-// baseMapper.saveByConcatId(waterfallFlows);
|
|
|
- return countInventoryNums;
|
|
|
+ return baseMapper.countInventoryNum();
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 每天转化率
|
|
|
-// * @param yesterday
|
|
|
-// */
|
|
|
-// public void countConversionRate(LocalDateTime yesterdayStart, LocalDateTime todayStart) {
|
|
|
-// List<CountInventoryNum> countInventoryNums =baseMapper.countConversionRate(yesterday);
|
|
|
-// List<WaterfallFlow> waterfallFlows = new ArrayList<>();
|
|
|
-// BeanUtils.copyProperties(countInventoryNums,waterfallFlows);
|
|
|
-// baseMapper.saveByConcatId(waterfallFlows);
|
|
|
-// }
|
|
|
/**
|
|
|
* 每天更新瀑布流相关数据
|
|
|
*/
|
|
|
@Override
|
|
|
public void waterfallFlow() {
|
|
|
+ log.info("瀑布流相关数据处理开始");
|
|
|
LocalDateTime todayStart = LocalDate.now().atStartOfDay(); // 今天0点
|
|
|
LocalDateTime yesterdayStart = todayStart.minusDays(1); // 昨天0点
|
|
|
ArrayList<WaterfallFlow> waterfallFlows = new ArrayList<>();
|
|
|
@@ -179,9 +90,52 @@ public class ProdWaterfallFlowServiceImpl extends ServiceImpl<ProdWaterfallFlowM
|
|
|
waterfallFlow.setGrossProfitMargin(countSalesMap.getGrossProfitMargin());
|
|
|
waterfallFlow.setOrderNumberTotal(countSalesMap.getOrderNumberTotal());
|
|
|
waterfallFlow.setScoreTotal(countSalesMap.getScoreTotal());
|
|
|
+ waterfallFlow.setExposureOrderNum(countSalesMap.getExposureOrderNum());
|
|
|
+ waterfallFlow.setExposureProdNum(countSalesMap.getExposureProdNum());
|
|
|
+ waterfallFlow.setConversionRate(countSalesMap.getConversionRate());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- baseMapper.saveByConcatId(waterfallFlows);
|
|
|
+ if (!waterfallFlows.isEmpty()){
|
|
|
+ try {
|
|
|
+ baseMapper.saveByConcatId(waterfallFlows);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ waterfallFlowNormalization();
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("瀑布流相关数据处理完成");
|
|
|
}
|
|
|
-}
|
|
|
+ /**
|
|
|
+ * 每日需要更新的数据
|
|
|
+ * 处理瀑布流归一化数据
|
|
|
+ */
|
|
|
+ public void waterfallFlowNormalization() {
|
|
|
+ LocalDate todayStart = LocalDate.now();//获取今天年月日
|
|
|
+ LocalDate yesterdayStart = todayStart.minusDays(1);//获取昨天年月日
|
|
|
+ LocalDate sevenDayStart = todayStart.minusDays(7);//获取七天前年月日
|
|
|
+ List<WaterfallFlowNormalization> waterfallFlowNormalizations = baseMapper.findWaterfallFlowNormalization(yesterdayStart,sevenDayStart);
|
|
|
+ if (waterfallFlowNormalizations!=null&&!waterfallFlowNormalizations.isEmpty()){
|
|
|
+ prodWaterfallFlowNormalizationMapper.saveList(waterfallFlowNormalizations);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每月一号需要更新的数据
|
|
|
+ * 处理瀑布流归一化数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void inventoryTurnoverRate() {
|
|
|
+ log.info("瀑布流每月库存周转率数据处理开始");
|
|
|
+ LocalDate todayStart = LocalDate.now();//获取今天年月日
|
|
|
+ LocalDate firstDayOfLastMonth = todayStart.minusMonths(1).withDayOfMonth(1);//获取上月第一天年月日
|
|
|
+ LocalDate lastDayOfLastMonth = todayStart.withDayOfMonth(1).minusDays(1);//获取上月最后一天年月日
|
|
|
+ List<WaterfallFlowNormalization> waterfallFlowNormalizations = baseMapper.inventoryTurnoverRate(firstDayOfLastMonth,lastDayOfLastMonth);
|
|
|
+ if (waterfallFlowNormalizations!=null&&!waterfallFlowNormalizations.isEmpty()){
|
|
|
+ prodWaterfallFlowNormalizationMapper.updateList(waterfallFlowNormalizations);
|
|
|
+ }
|
|
|
+ log.info("瀑布流每月库存周转率数据处理完成");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|