lyhzzz 2 лет назад
Родитель
Сommit
5361c52652

+ 25 - 16
src/main/java/com/cdf/controller/api/PageDataApiController.java

@@ -7,11 +7,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.cdf.common.ResultCode;
 import com.cdf.common.ResultData;
 import com.cdf.entity.PageData;
+import com.cdf.entity.ProductSource;
 import com.cdf.entity.TotalData;
 import com.cdf.exception.BusinessException;
 import com.cdf.httpClient.client.CdfClient;
+import com.cdf.httpClient.client.CdfHKClient;
 import com.cdf.httpClient.request.CdfChannelclick;
 import com.cdf.service.IPageDataService;
+import com.cdf.service.IProductSourceService;
+import com.cdf.service.ISceneSourceService;
 import com.cdf.service.ITotalDataService;
 import com.cdf.util.DateUtil;
 import org.apache.commons.lang3.StringUtils;
@@ -38,7 +42,9 @@ public class PageDataApiController {
     @Autowired
     ITotalDataService totalDataService;
     @Resource
-    CdfClient cdfClient;
+    CdfHKClient cdfHKClient;
+    @Autowired
+    ISceneSourceService sceneSourceService;
 
 
     @GetMapping("/point")
@@ -49,7 +55,7 @@ public class PageDataApiController {
                                   @RequestParam(required = false) String whereUrl,
                                   @RequestParam(required = false) Integer type,
                                   @RequestParam(required = false) String productId,
-                                  @RequestParam(required = false,defaultValue = "22") Integer deptId,
+                                  @RequestParam(required = false) String sceneNum,
                                   HttpServletRequest request) throws Exception {
 
         LambdaQueryWrapper<PageData> wrapper = new LambdaQueryWrapper<>();
@@ -60,7 +66,7 @@ public class PageDataApiController {
         PageData pageData;
         if(list.size() <=0){
             pageData = new PageData();
-            pageData.setDeptId(deptId);
+            pageData.setSceneNum(sceneNum);
             pageData.setCdfUserId(userId);
             pageData.setCdfToken(AccessToken);
             pageData.setCdfCookieId(cookieId);
@@ -71,6 +77,7 @@ public class PageDataApiController {
             pageData = list.get(0);
         }
         pageData.setUrl(whereUrl);
+        ProductSource productSource = sceneSourceService.getByNum(sceneNum);
         switch (type){
             case 0:     //用戶打开页面
                 pageData.setInPageTime(DateUtil.getDateTime(new Date()));
@@ -87,9 +94,7 @@ public class PageDataApiController {
                 pageData.setIsClickGame(1);
                 break;
             case 3:     //用戶点击商品详情
-                if(deptId == 22){
-                    sendCdf(productId,cookieId,AccessToken,userId);
-                }
+                sendCdf(productSource.getCdfHost(),productSource.getCdfMchId(),productId,cookieId,AccessToken,userId);
                 pageData.setIsClickShop(1);
                 break;
             case 4:     //用戶点击場景点位
@@ -100,9 +105,7 @@ public class PageDataApiController {
                 break;
             case 6:     //用戶点击收藏
             case 7:     //加入购物车
-                if(deptId == 22){
-                    sendCdf(productId,cookieId,AccessToken,userId);
-                }
+                sendCdf(productSource.getCdfHost(),productSource.getCdfMchId(),productId,cookieId,AccessToken,userId);
                 return ResultData.ok();
         }
         pageData.setUpdateTime(null);
@@ -110,13 +113,13 @@ public class PageDataApiController {
         return ResultData.ok();
     }
 
-    private void sendCdf(String productId,String cookieId,String accesstoken,String userId){
+    private void sendCdf(String host,String mchId,String productId,String cookieId,String accesstoken,String userId){
         if(StringUtils.isEmpty(productId)){
             return;
         }
         CdfChannelclick cdfChannelclick = new CdfChannelclick();
         cdfChannelclick.setProductId(productId);
-        cdfClient.channelclick(cookieId,accesstoken,userId,cdfChannelclick);
+        cdfHKClient.channelclick(host,mchId,cookieId,accesstoken,userId,cdfChannelclick);
     }
 
 
@@ -124,17 +127,19 @@ public class PageDataApiController {
     public ResultData getPageData(@RequestParam(required = false) String day,
                                   @RequestParam(required = false,defaultValue = "0") Integer type,
                                   @RequestParam(required = false) String startDay,
-                                  @RequestParam(required = false) String endDay) throws Exception {
-        return ResultData.ok(totalDataService.getByType(type,day,startDay,endDay));
+                                  @RequestParam(required = false) String endDay,
+                                  @RequestParam(required = false,defaultValue = "600667208") String mchId) throws Exception {
+        return ResultData.ok(totalDataService.getByType(type,day,startDay,endDay,mchId));
     }
 
     @GetMapping("/pageDataTime")
     public ResultData pageDataTime(@RequestParam(required = false) String startDay,
-                                  @RequestParam(required = false) String endDay) {
+                                  @RequestParam(required = false) String endDay,
+                                   @RequestParam(required = false,defaultValue = "600667208") String mchId) {
         if(StringUtils.isEmpty(startDay) || StringUtils.isEmpty(endDay)){
             throw new BusinessException(ResultCode.PARAM_MISS);
         }
-        return ResultData.ok(totalDataService.pageDataTime(startDay,endDay));
+        return ResultData.ok(totalDataService.pageDataTime(startDay,endDay,mchId));
     }
 
     @PostMapping("/pageDataList")
@@ -143,8 +148,12 @@ public class PageDataApiController {
         if(jsonArray == null || jsonArray.size() <=0){
             return  ResultData.ok(new ArrayList<>());
         }
+        String mchId = jsonObject.getString("mchId");
+        if(StringUtils.isBlank(mchId)){
+            mchId = "600667208";
+        }
         List<String> days = new ArrayList(jsonArray);
-        return ResultData.ok(totalDataService.getListByType(days));
+        return ResultData.ok(totalDataService.getListByType(days,mchId));
     }
 }
 

+ 2 - 2
src/main/java/com/cdf/entity/PageData.java

@@ -77,7 +77,7 @@ public class PageData implements Serializable {
     @TableField("out_page_time")
     private String outPageTime;
 
-    @TableField("dept_id")
-    private Integer deptId;
+    @TableField("scene_num")
+    private String sceneNum;
 
 }

+ 9 - 1
src/main/java/com/cdf/entity/TotalData.java

@@ -1,5 +1,6 @@
 package com.cdf.entity;
 
+import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
@@ -8,6 +9,7 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import lombok.Getter;
 import lombok.Setter;
+import org.apache.commons.lang3.StringUtils;
 
 /**
  * <p>
@@ -24,9 +26,12 @@ public class TotalData implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @TableId("id")
+    @TableId(value = "id",type = IdType.AUTO)
     private String id;
 
+    @TableField("day_time")
+    private String dayTime;
+
     /**
      * 平均停留时间 /秒
      */
@@ -61,6 +66,9 @@ public class TotalData implements Serializable {
     @TableField("video_num")
     private Long videoNum;
 
+    @TableField("product_source_id")
+    private Integer productSourceId;
+
     @TableField("create_time")
     private String createTime;
 

+ 0 - 73
src/main/java/com/cdf/entity/TotalDataHk.java

@@ -1,73 +0,0 @@
-package com.cdf.entity;
-
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * <p>
- * 
- * </p>
- *
- * @author 
- * @since 2022-11-08
- */
-@Getter
-@Setter
-@TableName("t_total_data_hk")
-public class TotalDataHk implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @TableId("id")
-    private String id;
-
-    /**
-     * 平均停留时间 /秒
-     */
-    @TableField("avg_stop_time")
-    private Long avgStopTime;
-
-    /**
-     * 跳出率
-     */
-    @TableField("avg_jump")
-    private BigDecimal avgJump;
-
-    /**
-     * 寻宝游戏点击率
-     */
-    @TableField("avg_click_game")
-    private BigDecimal avgClickGame;
-
-    /**
-     * 商品详情点击率
-     */
-    @TableField("avg_click_shop")
-    private BigDecimal avgClickShop;
-
-    /**
-     * 平均步数
-     */
-    @TableField("avg_step_num")
-    private Long avgStepNum;
-
-    /**
-     * 视频点击次数
-     */
-    @TableField("video_num")
-    private Long videoNum;
-
-    @TableField("create_time")
-    private String createTime;
-
-    @TableField("update_time")
-    private String updateTime;
-
-
-}

+ 3 - 3
src/main/java/com/cdf/httpClient/client/CdfClient.java

@@ -65,10 +65,10 @@ public interface CdfClient {
      */
     @Post(url = "/api/prodextra/channelclick",
         headers = {
-            "app-key: h5sqBuyer_600667208",
+            "app-key: h5sqBuyer_{mchId}",
             "app-version: 6.6.88",
             "cookieid: {cookieId}",
-            "ymt-pars: appid=71&accesstoken={accessToken}&userid={userId}&mchId=600667208&language=zh_CN&format=json",
+            "ymt-pars: appid=71&accesstoken={accessToken}&userid={userId}&mchId={mchid}&language=zh_CN&format=json",
         })
-    JSONObject channelclick(@Var("cookieId") String cookieId, @Var("accessToken") String accessToken, @Var("userId")String userId, @JSONBody CdfChannelclick request);
+    JSONObject channelclick(@Var("mchId")String mchId,@Var("cookieId") String cookieId, @Var("accessToken") String accessToken, @Var("userId")String userId, @JSONBody CdfChannelclick request);
 }

+ 0 - 18
src/main/java/com/cdf/mapper/ITotalDataHkMapper.java

@@ -1,18 +0,0 @@
-package com.cdf.mapper;
-
-import com.cdf.entity.TotalDataHk;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * <p>
- *  Mapper 接口
- * </p>
- *
- * @author 
- * @since 2022-11-08
- */
-@Mapper
-public interface ITotalDataHkMapper extends BaseMapper<TotalDataHk> {
-
-}

+ 2 - 2
src/main/java/com/cdf/mapper/ITotalDataMapper.java

@@ -16,7 +16,7 @@ import org.apache.ibatis.annotations.Param;
 @Mapper
 public interface ITotalDataMapper extends BaseMapper<TotalData> {
 
-    TotalData getMonth(@Param("time") String time);
+    TotalData getMonth(@Param("productSourceId") Integer productSourceId,@Param("time") String time);
 
-    TotalData getWeek(@Param("startTime") String weekStart, @Param("endTime") String weekEnd);
+    TotalData getWeek(@Param("productSourceId") Integer productSourceId,@Param("startTime") String weekStart, @Param("endTime") String weekEnd);
 }

+ 42 - 31
src/main/java/com/cdf/schedule/ScheduleTask.java

@@ -2,10 +2,10 @@ package com.cdf.schedule;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.cdf.entity.PageData;
+import com.cdf.entity.SceneSource;
 import com.cdf.entity.TotalData;
-import com.cdf.entity.TotalDataHk;
 import com.cdf.service.IPageDataService;
-import com.cdf.service.ITotalDataHkService;
+import com.cdf.service.ISceneSourceService;
 import com.cdf.service.ITotalDataService;
 import com.cdf.util.DateUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -16,7 +16,9 @@ import org.springframework.stereotype.Component;
 
 import javax.naming.ldap.PagedResultsControl;
 import java.math.BigDecimal;
+import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 @Component
@@ -28,7 +30,7 @@ public class ScheduleTask {
     @Autowired
     ITotalDataService totalDataService;
     @Autowired
-    ITotalDataHkService totalDataHkService;
+    ISceneSourceService sceneSourceService;
 
     public static String day = null;
 
@@ -39,23 +41,42 @@ public class ScheduleTask {
             day = DateUtil.getDay(new Date(), -1);
         }
         log.info("开始统计{}的数据,{}",day,DateUtil.getDateTime(new Date()));
-        TotalData totalData = new TotalData();
-        TotalDataHk totalDatahk = new TotalDataHk();
-
-        this.dataT(totalData,totalDatahk,22);
-        totalDataService.saveOrUpdate(totalData);
-        this.dataT(totalData,totalDatahk,33);
-        totalDataHkService.saveOrUpdate(totalDatahk);
+        this.dataT();
         //待添加传输
         log.info("{结束统计{}的数据,{}",day,DateUtil.getDateTime(new Date()));
         day = null;
     }
 
-    private void dataT(TotalData totalData,TotalDataHk totalDataHk,Integer deptId) throws Exception {
+    private void dataT() throws Exception {
+        List<SceneSource> sceneSources = sceneSourceService.list();
+        HashMap<Integer,List<String>> sceneMap = new HashMap<>();
+        for (SceneSource sceneSource : sceneSources) {
+            if(sceneMap.get(sceneSource.getProductSourceId()) == null){
+                sceneMap.put(sceneSource.getProductSourceId(), Arrays.asList(sceneSource.getSceneNum()));
+            }else {
+                sceneMap.get(sceneSource.getProductSourceId()).add(sceneSource.getSceneNum());
+            }
+        }
+        for (Integer productSourceId : sceneMap.keySet()) {
+            LambdaQueryWrapper<PageData> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(PageData::getDay,day);
+            if(sceneMap.get(productSourceId).size() <=0 ){
+                continue;
+            }
+            wrapper.in(PageData::getSceneNum,sceneMap.get(productSourceId));
+            List<PageData> list = pageDataService.list(wrapper);
+            this.saveData(list,productSourceId);
+        }
+
         LambdaQueryWrapper<PageData> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(PageData::getDeptId,deptId);
         wrapper.eq(PageData::getDay,day);
+        wrapper.isNull(PageData::getSceneNum);
         List<PageData> list = pageDataService.list(wrapper);
+        this.saveData(list,1);
+    }
+
+    private void saveData( List<PageData> list,Integer productSourceId) throws Exception {
+        TotalData totalData = new TotalData();
         Long stopTimeCount = 0L;
         BigDecimal jumpCount = BigDecimal.ZERO;
         BigDecimal clickGameCount = BigDecimal.ZERO;
@@ -101,25 +122,15 @@ public class ScheduleTask {
             avgClickShop = clickShopCount.divide(new BigDecimal(list.size()),4,BigDecimal.ROUND_HALF_UP);
             avgStepNum = totalStepNum / list.size();
         }
-        if(deptId == 22){
-            totalData.setId(day);
-            totalData.setAvgStopTime(avgStopTime);
-            totalData.setAvgJump(avgJump);
-            totalData.setAvgClickGame(avgClickGame);
-            totalData.setAvgClickShop(avgClickShop);
-            totalData.setVideoNum(totalVideoNum);
-            totalData.setAvgStepNum(avgStepNum);
-        }
-        if(deptId == 33){
-            totalDataHk.setId(day);
-            totalDataHk.setAvgStopTime(avgStopTime);
-            totalDataHk.setAvgJump(avgJump);
-            totalDataHk.setAvgClickGame(avgClickGame);
-            totalDataHk.setAvgClickShop(avgClickShop);
-            totalDataHk.setVideoNum(totalVideoNum);
-            totalDataHk.setAvgStepNum(avgStepNum);
-        }
-
+        totalData.setDayTime(day);
+        totalData.setAvgStopTime(avgStopTime);
+        totalData.setAvgJump(avgJump);
+        totalData.setAvgClickGame(avgClickGame);
+        totalData.setAvgClickShop(avgClickShop);
+        totalData.setVideoNum(totalVideoNum);
+        totalData.setAvgStepNum(avgStepNum);
+        totalData.setProductSourceId(productSourceId);
+        totalDataService.save(totalData);
     }
 
 }

+ 2 - 0
src/main/java/com/cdf/service/IProductSourceService.java

@@ -19,4 +19,6 @@ public interface IProductSourceService extends IService<ProductSource> {
     List<ProductSource> getProductHk(String type);
 
     Object getBySource(CdfProductListRequest param,ProductSource productSource);
+
+    ProductSource getByMchId(String mchId);
 }

+ 0 - 16
src/main/java/com/cdf/service/ITotalDataHkService.java

@@ -1,16 +0,0 @@
-package com.cdf.service;
-
-import com.cdf.entity.TotalDataHk;
-import com.baomidou.mybatisplus.extension.service.IService;
-
-/**
- * <p>
- *  服务类
- * </p>
- *
- * @author 
- * @since 2022-11-08
- */
-public interface ITotalDataHkService extends IService<TotalDataHk> {
-
-}

+ 3 - 3
src/main/java/com/cdf/service/ITotalDataService.java

@@ -15,9 +15,9 @@ import java.util.List;
  */
 public interface ITotalDataService extends IService<TotalData> {
 
-    TotalData getByType(Integer type, String day,String startDay,String endDay) throws Exception;
+    TotalData getByType(Integer type, String day,String startDay,String endDay,String mchId) throws Exception;
 
-    List<TotalData> getListByType( List<String> days) throws Exception;
+    List<TotalData> getListByType( List<String> days,String mchId) throws Exception;
 
-    List<TotalData> pageDataTime(String startDay, String endDay);
+    List<TotalData> pageDataTime(String startDay, String endDay,String mchId);
 }

+ 16 - 0
src/main/java/com/cdf/service/impl/ProductSourceServiceImpl.java

@@ -12,7 +12,9 @@ import com.cdf.httpClient.response.cdf.*;
 import com.cdf.mapper.IProductSourceMapper;
 import com.cdf.service.IProductSourceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cdf.service.ISceneSourceService;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -69,4 +71,18 @@ public class ProductSourceServiceImpl extends ServiceImpl<IProductSourceMapper,
         PageInfo pageInfo = PageInfo.PageInfo(param.getPageIndex(), 20L, productList.getCount()*20, productList.getList());
         return pageInfo;
     }
+
+    @Override
+    public ProductSource getByMchId(String mchId) {
+        if(StringUtils.isBlank(mchId)){
+            return this.getById(1);
+        }
+        LambdaQueryWrapper<ProductSource> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ProductSource::getCdfMchId,mchId);
+        List<ProductSource> list = this.list(wrapper);
+        if(list != null && list.size() >0){
+            return list.get(0);
+        }
+        return this.getById(1);
+    }
 }

+ 4 - 0
src/main/java/com/cdf/service/impl/SceneSourceServiceImpl.java

@@ -7,6 +7,7 @@ import com.cdf.mapper.ISceneSourceMapper;
 import com.cdf.service.IProductSourceService;
 import com.cdf.service.ISceneSourceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -28,6 +29,9 @@ public class SceneSourceServiceImpl extends ServiceImpl<ISceneSourceMapper, Scen
 
     @Override
     public ProductSource getByNum(String num) {
+        if(StringUtils.isBlank(num)){
+            return productSourceService.getById(1);
+        }
         LambdaQueryWrapper<SceneSource> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(SceneSource::getSceneNum,num);
         List<SceneSource> list = this.list(wrapper);

+ 0 - 20
src/main/java/com/cdf/service/impl/TotalDataHkServiceImpl.java

@@ -1,20 +0,0 @@
-package com.cdf.service.impl;
-
-import com.cdf.entity.TotalDataHk;
-import com.cdf.mapper.ITotalDataHkMapper;
-import com.cdf.service.ITotalDataHkService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- *  服务实现类
- * </p>
- *
- * @author 
- * @since 2022-11-08
- */
-@Service
-public class TotalDataHkServiceImpl extends ServiceImpl<ITotalDataHkMapper, TotalDataHk> implements ITotalDataHkService {
-
-}

+ 38 - 12
src/main/java/com/cdf/service/impl/TotalDataServiceImpl.java

@@ -1,12 +1,15 @@
 package com.cdf.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.cdf.entity.ProductSource;
 import com.cdf.entity.TotalData;
 import com.cdf.mapper.ITotalDataMapper;
+import com.cdf.service.IProductSourceService;
 import com.cdf.service.ITotalDataService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cdf.util.DateUtil;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -26,15 +29,19 @@ import java.util.List;
 @Service
 public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalData> implements ITotalDataService {
 
+    @Autowired
+    IProductSourceService productSourceService;
+
     @Override
-    public TotalData getByType(Integer type, String time,String startDay,String endDay) throws Exception {
+    public TotalData getByType(Integer type, String time,String startDay,String endDay,String mchId) throws Exception {
+        ProductSource productSource = productSourceService.getByMchId(mchId);
+
         switch (type){
             case 0:     //日
                 if(StringUtils.isEmpty(time)){
                     time = DateUtil.getDay(new Date(),-1);
                 }
-                TotalData byId = this.getById(time);
-                return  byId == null ? newTotalData(time) : byId;
+                return this.getByDay(time,productSource.getId());
             case 1:     //周
                 String weekStart =null;
                 if(StringUtils.isEmpty(time)){
@@ -44,10 +51,11 @@ public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalDat
                     weekStart = DateUtil.getWeekStart(date);
                 }
                 String weekEnd = DateUtil.getWeekEnd(weekStart);
-                TotalData week = this.getBaseMapper().getWeek(weekStart, weekEnd);
+                TotalData week = this.getBaseMapper().getWeek(productSource.getId(),weekStart, weekEnd);
                 if(week == null){
                     week = newTotalData(weekStart);
                 }
+                week.setDayTime(weekStart);
                 week.setId(weekStart);
                 return week;
             case 2:     //月
@@ -55,15 +63,16 @@ public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalDat
                     time = DateUtil.getLastMonth();
                 }
                 time = DateUtil.getMonth(time);
-                TotalData month = this.getBaseMapper().getMonth(time);
+                TotalData month = this.getBaseMapper().getMonth(productSource.getId(),time);
                 if(month == null){
                     month = newTotalData(time);
                 }
                 month.setId(time);
+                month.setDayTime(time);
                 return month;
             case 3:     //时间段
                 if(StringUtils.isNotBlank(startDay) && StringUtils.isNotBlank(endDay)){
-                    TotalData totalData = this.getBaseMapper().getWeek(startDay, endDay);
+                    TotalData totalData = this.getBaseMapper().getWeek(productSource.getId(),startDay, endDay);
                     if(totalData == null){
                         totalData = newTotalData(startDay +"-"+endDay);
                     }
@@ -73,30 +82,46 @@ public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalDat
                 if(StringUtils.isEmpty(time)){
                     time = DateUtil.getDay(new Date(),-1);
                 }
-                return  this.getById(time) == null ? newTotalData(time) : this.getById(time);
+                return  this.getByDay(time,productSource.getId());
             default:
                 throw new IllegalStateException("Unexpected value: " + type);
         }
     }
 
+    private TotalData getByDay(String time, Integer productSourceId) {
+        LambdaQueryWrapper<TotalData> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(TotalData::getId,time);
+        wrapper.eq(TotalData::getProductSourceId,productSourceId);
+        List<TotalData> list = this.list(wrapper);
+        if(list !=null && list.size() >0 ){
+            return list.get(0);
+        }
+        return newTotalData(time);
+    }
+
     @Override
-    public List<TotalData> pageDataTime(String startDay, String endDay) {
+    public List<TotalData> pageDataTime(String startDay, String endDay,String mchId) {
+        ProductSource productSource = productSourceService.getByMchId(mchId);
         LambdaQueryWrapper<TotalData> wrapper = new LambdaQueryWrapper<>();
-        wrapper.between(TotalData::getId,startDay,endDay);
+        wrapper.between(TotalData::getDayTime,startDay,endDay);
+        wrapper.eq(TotalData::getProductSourceId,productSource.getId());
         wrapper.orderByAsc(TotalData::getId);
         return this.list(wrapper);
     }
 
     @Override
-    public List<TotalData> getListByType(List<String> days) throws Exception {
+    public List<TotalData> getListByType(List<String> days,String mchId) throws Exception {
+        ProductSource productSource = productSourceService.getByMchId(mchId);
+
         LambdaQueryWrapper<TotalData> wrapper = new LambdaQueryWrapper<>();
-        wrapper.in(TotalData::getId,days);
+        wrapper.in(TotalData::getDayTime,days);
+        wrapper.eq(TotalData::getProductSourceId,productSource.getId());
         List<TotalData> list = this.list(wrapper);
 
         List<TotalData> voList = new ArrayList<>();
         HashMap<String,TotalData> map = new HashMap<>();
         for (TotalData totalData : list) {
-            map.put(totalData.getId(),totalData);
+            map.put(totalData.getDayTime(),totalData);
         }
         for (String day : days) {
             TotalData totalData = map.get(day);
@@ -111,6 +136,7 @@ public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalDat
     private TotalData newTotalData(String id ){
         TotalData totalData = new TotalData();
         totalData.setId(id);
+        totalData.setDayTime(id);
         totalData.setAvgStopTime(0L);
         totalData.setAvgStepNum(0L);
         totalData.setVideoNum(0L);

+ 0 - 5
src/main/resources/mapper/TotalDataHkMapper.xml

@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.cdf.mapper.ITotalDataHkMapper">
-
-</mapper>

+ 2 - 2
src/main/resources/mapper/TotalDataMapper.xml

@@ -15,12 +15,12 @@
     <select id="getMonth" resultType="com.cdf.entity.TotalData">
         SELECT
         <include refid="baseRow"></include>
-        FROM t_total_data WHERE id like CONCAT('%',#{time},'%')
+        FROM t_total_data WHERE product_source_id = #{productSourceId} and day_time like CONCAT('%',#{time},'%')
     </select>
 
     <select id="getWeek" resultType="com.cdf.entity.TotalData">
         SELECT
          <include refid="baseRow"></include>
-        FROM t_total_data WHERE id &gt;= #{startTime} and id &lt;=#{endTime}
+        FROM t_total_data WHERE product_source_id = #{productSourceId} and day_time &gt;= #{startTime} and day_time &lt;=#{endTime}
     </select>
 </mapper>