|
|
@@ -0,0 +1,187 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
|
|
|
+ *
|
|
|
+ * https://www.gz-yami.com/
|
|
|
+ *
|
|
|
+ * 未经允许,不可做商业用途!
|
|
|
+ *
|
|
|
+ * 版权所有,侵权必究!
|
|
|
+ */
|
|
|
+
|
|
|
+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.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.
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class ProdWaterfallFlowServiceImpl extends ServiceImpl<ProdWaterfallFlowMapper, WaterfallFlow> implements ProdWaterfallFlowService {
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 7天的销量
|
|
|
+// * 统计销售量并更新销量
|
|
|
+// * @param todayStartDate
|
|
|
+// * @param first7DaysStartDate
|
|
|
+// */
|
|
|
+// public void countSales(Date todayStartDate, Date first7DaysStartDate) {
|
|
|
+// List<CountSales> countSales = baseMapper.countSales(todayStartDate, first7DaysStartDate);
|
|
|
+// List<WaterfallFlow> waterfallFlows = new ArrayList<>();
|
|
|
+// BeanUtils.copyProperties(countSales,waterfallFlows);
|
|
|
+// baseMapper.saveByConcatId(waterfallFlows);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计每天的销量
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 每天统计库存
|
|
|
+ */
|
|
|
+ public List<CountInventoryNum> countInventoryNum() {
|
|
|
+ List<CountInventoryNum> countInventoryNums =baseMapper.countInventoryNum();
|
|
|
+// List<WaterfallFlow> waterfallFlows = new ArrayList<>();
|
|
|
+// BeanUtils.copyProperties(countInventoryNums,waterfallFlows);
|
|
|
+// baseMapper.saveByConcatId(waterfallFlows);
|
|
|
+ return countInventoryNums;
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 每天转化率
|
|
|
+// * @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() {
|
|
|
+ LocalDateTime todayStart = LocalDate.now().atStartOfDay(); // 今天0点
|
|
|
+ LocalDateTime yesterdayStart = todayStart.minusDays(1); // 昨天0点
|
|
|
+ ArrayList<WaterfallFlow> waterfallFlows = new ArrayList<>();
|
|
|
+ List<CountInventoryNum> countInventoryNums = countInventoryNum();
|
|
|
+ BeanUtils.copyProperties(waterfallFlows,countInventoryNums);
|
|
|
+ List<CountSales> countSales = countSales(yesterdayStart, todayStart);
|
|
|
+ if (countSales!=null&& !countSales.isEmpty()){
|
|
|
+ Map<String, CountSales> stringCountSalesHashMap = new HashMap<>();
|
|
|
+ for (CountSales countSale : countSales) {
|
|
|
+ stringCountSalesHashMap.put(countSale.getConcatId(),countSale);
|
|
|
+ }
|
|
|
+ for (WaterfallFlow waterfallFlow : waterfallFlows) {
|
|
|
+ CountSales countSalesMap = stringCountSalesHashMap.get(waterfallFlow.getConcatId());
|
|
|
+ if (countSalesMap!=null){
|
|
|
+ waterfallFlow.setSalesNum(countSalesMap.getCountNum());
|
|
|
+ waterfallFlow.setSalesTotalMoney(countSalesMap.getSalesTotalMoney());
|
|
|
+ waterfallFlow.setCostTotalMoney(countSalesMap.getCostTotalMoney());
|
|
|
+ waterfallFlow.setEvaluateScore(countSalesMap.getEvaluateScore());
|
|
|
+ waterfallFlow.setGrossProfitMargin(countSalesMap.getGrossProfitMargin());
|
|
|
+ waterfallFlow.setOrderNumberTotal(countSalesMap.getOrderNumberTotal());
|
|
|
+ waterfallFlow.setScoreTotal(countSalesMap.getScoreTotal());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseMapper.saveByConcatId(waterfallFlows);
|
|
|
+ }
|
|
|
+}
|