|
@@ -1,26 +1,214 @@
|
|
package com.tzld.piaoquan.api.service.contentplatform.impl;
|
|
package com.tzld.piaoquan.api.service.contentplatform.impl;
|
|
|
|
|
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformDataStatMapperExt;
|
|
|
|
+import com.tzld.piaoquan.api.model.config.LoginUserContext;
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.GzhDatastatListParam;
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.GzhDatastatListParam;
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.QwDatastatListParam;
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.QwDatastatListParam;
|
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.*;
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.GzhDatastatItemVO;
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.GzhDatastatItemVO;
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.QwDatastatItemVO;
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.QwDatastatItemVO;
|
|
|
|
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformCooperateAccountService;
|
|
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformDatastatService;
|
|
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformDatastatService;
|
|
|
|
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
|
|
import com.tzld.piaoquan.growth.common.utils.page.Page;
|
|
import com.tzld.piaoquan.growth.common.utils.page.Page;
|
|
-import lombok.Data;
|
|
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class ContentPlatformDatastatServiceImpl implements ContentPlatformDatastatService {
|
|
public class ContentPlatformDatastatServiceImpl implements ContentPlatformDatastatService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ContentPlatformDataStatMapperExt dataStatMapperExt;
|
|
|
|
+ @Autowired
|
|
|
|
+ ContentPlatformCooperateAccountService cooperateAccountService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ContentPlatformPlanService planService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Page<GzhDatastatItemVO> gzhDatastatList(GzhDatastatListParam param) {
|
|
public Page<GzhDatastatItemVO> gzhDatastatList(GzhDatastatListParam param) {
|
|
- return null;
|
|
|
|
|
|
+ switch (param.getType()) {
|
|
|
|
+ case 0:
|
|
|
|
+ return gzhTotalDatastatList(param);
|
|
|
|
+ case 1:
|
|
|
|
+ return gzhAccountDatastatList(param);
|
|
|
|
+ default:
|
|
|
|
+ return gzhAccountDatastatList(param);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Page<GzhDatastatItemVO> gzhTotalDatastatList(GzhDatastatListParam param) {
|
|
|
|
+ ContentPlatformAccount user = LoginUserContext.getUser();
|
|
|
|
+ Page<GzhDatastatItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
|
+ int count = dataStatMapperExt.getGzhTotalDatastatCount(param, user.getId());
|
|
|
|
+ result.setTotalSize(count);
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ List<ContentPlatformGzhDataStat> datastatList = dataStatMapperExt.getGzhTotalDatastatList(param,
|
|
|
|
+ user.getId(), offset, param.getPageSize());
|
|
|
|
+ List<GzhDatastatItemVO> list = buildGzhDatastatItemVOList(param.getType(), datastatList);
|
|
|
|
+ result.setObjs(list);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Page<GzhDatastatItemVO> gzhAccountDatastatList(GzhDatastatListParam param) {
|
|
|
|
+ ContentPlatformAccount user = LoginUserContext.getUser();
|
|
|
|
+ Page<GzhDatastatItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
|
+ int count = dataStatMapperExt.getGzhAccountDatastatCount(param, user.getId());
|
|
|
|
+ result.setTotalSize(count);
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ List<ContentPlatformGzhDataStat> datastatList = dataStatMapperExt.getGzhAccountDatastatList(param,
|
|
|
|
+ user.getId(), offset, param.getPageSize());
|
|
|
|
+ List<GzhDatastatItemVO> list = buildGzhDatastatItemVOList(param.getType(), datastatList);
|
|
|
|
+ result.setObjs(list);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<GzhDatastatItemVO> buildGzhDatastatItemVOList(Integer type, List<ContentPlatformGzhDataStat> datastatList) {
|
|
|
|
+ if (CollectionUtils.isEmpty(datastatList)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ Map<Long, ContentPlatformGzhAccount> accountMap = new HashMap<>();
|
|
|
|
+ if (type != 0) {
|
|
|
|
+ List<Long> accountIds = datastatList.stream().map(ContentPlatformGzhDataStat::getAccountId).distinct().collect(Collectors.toList());
|
|
|
|
+ List<ContentPlatformGzhAccount> accountList = cooperateAccountService.getAccountListByIds(accountIds);
|
|
|
|
+ accountMap = accountList.stream().collect(Collectors.toMap(ContentPlatformGzhAccount::getId, a -> a));
|
|
|
|
+ }
|
|
|
|
+ List<GzhDatastatItemVO> result = new ArrayList<>();
|
|
|
|
+ for (ContentPlatformGzhDataStat datastat : datastatList) {
|
|
|
|
+ GzhDatastatItemVO vo = new GzhDatastatItemVO();
|
|
|
|
+ vo.setDateStr(datastat.getDateStr());
|
|
|
|
+ ContentPlatformGzhAccount account = accountMap.get(datastat.getAccountId());
|
|
|
|
+ if (Objects.nonNull(account)) {
|
|
|
|
+ vo.setName(account.getName());
|
|
|
|
+ }
|
|
|
|
+ vo.setFansIncreaseCount(datastat.getFansIncreaseCount());
|
|
|
|
+ vo.setFirstLevel(datastat.getFirstLevelCount());
|
|
|
|
+ vo.setScore(datastat.getScore());
|
|
|
|
+ if (Objects.nonNull(vo.getFansIncreaseCount()) && vo.getFansIncreaseCount() > 0) {
|
|
|
|
+ vo.setOpenRate(vo.getFirstLevel() / (double) vo.getFansIncreaseCount());
|
|
|
|
+ }
|
|
|
|
+ result.add(vo);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Page<QwDatastatItemVO> qwDatastatList(QwDatastatListParam param) {
|
|
public Page<QwDatastatItemVO> qwDatastatList(QwDatastatListParam param) {
|
|
- return null;
|
|
|
|
|
|
+ switch (param.getType()) {
|
|
|
|
+ case 0:
|
|
|
|
+ return qwTotalDatastatList(param);
|
|
|
|
+ case 1:
|
|
|
|
+ return qwSceneDatastatList(param, 0);
|
|
|
|
+ case 2:
|
|
|
|
+ return qwSceneDatastatList(param, 1);
|
|
|
|
+ case 3:
|
|
|
|
+ return qwReplyDatastatList(param);
|
|
|
|
+ case 4:
|
|
|
|
+ return qwRootSourceIdDatastatList(param);
|
|
|
|
+ default:
|
|
|
|
+ return qwRootSourceIdDatastatList(param);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Page<QwDatastatItemVO> qwTotalDatastatList(QwDatastatListParam param) {
|
|
|
|
+ ContentPlatformAccount user = LoginUserContext.getUser();
|
|
|
|
+ Page<QwDatastatItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
|
+ int count = dataStatMapperExt.getQwTotalDatastatCount(param, user.getId());
|
|
|
|
+ result.setTotalSize(count);
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ List<ContentPlatformQwDataStat> datastatList = dataStatMapperExt.getQwTotalDatastatList(param,
|
|
|
|
+ user.getId(), offset, param.getPageSize());
|
|
|
|
+ List<QwDatastatItemVO> list = buildQwRootSourceIdDatastatItemVOList(datastatList);
|
|
|
|
+ result.setObjs(list);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Page<QwDatastatItemVO> qwSceneDatastatList(QwDatastatListParam param, Integer scene) {
|
|
|
|
+ ContentPlatformAccount user = LoginUserContext.getUser();
|
|
|
|
+ Page<QwDatastatItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
|
+ int count = dataStatMapperExt.getQwSceneDatastatCount(param, scene, user.getId());
|
|
|
|
+ result.setTotalSize(count);
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ List<ContentPlatformQwDataStat> datastatList = dataStatMapperExt.getQwSceneDatastatList(param, scene,
|
|
|
|
+ user.getId(), offset, param.getPageSize());
|
|
|
|
+ List<QwDatastatItemVO> list = buildQwRootSourceIdDatastatItemVOList(datastatList);
|
|
|
|
+ result.setObjs(list);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Page<QwDatastatItemVO> qwReplyDatastatList(QwDatastatListParam param) {
|
|
|
|
+ ContentPlatformAccount user = LoginUserContext.getUser();
|
|
|
|
+ Page<QwDatastatItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
|
+ int count = dataStatMapperExt.getQwReplyDatastatCount(param, user.getId());
|
|
|
|
+ result.setTotalSize(count);
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ List<ContentPlatformQwDataStat> datastatList = dataStatMapperExt.getReplyDatastatList(param,
|
|
|
|
+ user.getId(), offset, param.getPageSize());
|
|
|
|
+ List<QwDatastatItemVO> list = buildQwRootSourceIdDatastatItemVOList(datastatList);
|
|
|
|
+ result.setObjs(list);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Page<QwDatastatItemVO> qwRootSourceIdDatastatList(QwDatastatListParam param) {
|
|
|
|
+ ContentPlatformAccount user = LoginUserContext.getUser();
|
|
|
|
+ Page<QwDatastatItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
|
+ int count = dataStatMapperExt.getQwRootSourceIdDatastatCount(param, user.getId());
|
|
|
|
+ result.setTotalSize(count);
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ List<ContentPlatformQwDataStat> datastatList = dataStatMapperExt.getQwRootSourceIdDatastatList(param,
|
|
|
|
+ user.getId(), offset, param.getPageSize());
|
|
|
|
+ List<QwDatastatItemVO> list = buildQwRootSourceIdDatastatItemVOList(datastatList);
|
|
|
|
+ result.setObjs(list);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<QwDatastatItemVO> buildQwRootSourceIdDatastatItemVOList(List<ContentPlatformQwDataStat> datastatList) {
|
|
|
|
+ if (CollectionUtils.isEmpty(datastatList)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ List<String> rootSourceIds = datastatList.stream().map(ContentPlatformQwDataStat::getRootSourceId).distinct().collect(Collectors.toList());
|
|
|
|
+ List<ContentPlatformQwPlan> qwPlanList = planService.getQwPlanListByRootSourceIds(rootSourceIds);
|
|
|
|
+ Map<String, Long> qwPlanMap = qwPlanList.stream().collect(Collectors.toMap(ContentPlatformQwPlan::getRootSourceId, ContentPlatformQwPlan::getId));
|
|
|
|
+ List<Long> planIds = qwPlanList.stream().map(ContentPlatformQwPlan::getId).distinct().collect(Collectors.toList());
|
|
|
|
+ List<ContentPlatformQwPlanVideo> qwPlanVideoList = planService.getQwPlanVideoListByPlanIds(planIds);
|
|
|
|
+ Map<Long, List<ContentPlatformQwPlanVideo>> qwPlanVideoMap = qwPlanVideoList.stream().collect(Collectors.groupingBy(ContentPlatformQwPlanVideo::getPlanId));
|
|
|
|
+ List<QwDatastatItemVO> result = new ArrayList<>();
|
|
|
|
+ for (ContentPlatformQwDataStat datastat : datastatList) {
|
|
|
|
+ QwDatastatItemVO vo = new QwDatastatItemVO();
|
|
|
|
+ vo.setDateStr(datastat.getDateStr());
|
|
|
|
+ vo.setScore(datastat.getScore());
|
|
|
|
+ Long planId = qwPlanMap.get(datastat.getRootSourceId());
|
|
|
|
+ if (Objects.nonNull(planId)) {
|
|
|
|
+ List<ContentPlatformQwPlanVideo> planVideoList = qwPlanVideoMap.get(planId);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(planVideoList)) {
|
|
|
|
+ vo.setVideoId(planVideoList.get(0).getVideoId());
|
|
|
|
+ vo.setTitle(planVideoList.get(0).getTitle());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result.add(vo);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|