|
@@ -0,0 +1,162 @@
|
|
|
+package com.tzld.piaoquan.api.service.contentplatform.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
|
|
|
+import com.tzld.piaoquan.api.common.enums.contentplatform.AccountStatusEnum;
|
|
|
+import com.tzld.piaoquan.api.common.enums.contentplatform.QwPlanTypeEnum;
|
|
|
+import com.tzld.piaoquan.api.common.exception.CommonException;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt;
|
|
|
+import com.tzld.piaoquan.api.model.param.contentplatform.QwPlanSaveVideoParam;
|
|
|
+import com.tzld.piaoquan.api.model.param.contentplatform.VideoContentListParam;
|
|
|
+import com.tzld.piaoquan.api.model.param.contentplatform.api.GetContentPageParam;
|
|
|
+import com.tzld.piaoquan.api.model.param.contentplatform.api.GetTokenParam;
|
|
|
+import com.tzld.piaoquan.api.model.param.contentplatform.api.GetVideoPageUrlParam;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformAccount;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwPlan;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo;
|
|
|
+import com.tzld.piaoquan.api.model.vo.contentplatform.api.VideoIdTitleVO;
|
|
|
+import com.tzld.piaoquan.api.model.vo.contentplatform.api.VideoPageUrlVO;
|
|
|
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformAccountService;
|
|
|
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformApiService;
|
|
|
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
|
|
|
+import com.tzld.piaoquan.growth.common.service.MessageAttachmentService;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.MessageUtil;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.RedisUtils;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.page.Page;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ContentPlatformApiServiceImpl implements ContentPlatformApiService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformAccountService accountService;
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformPlanService planService;
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformPlanMapperExt planMapperExt;
|
|
|
+ @Autowired
|
|
|
+ private MessageAttachmentService messageAttachmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+
|
|
|
+ @Value("${video.min.score:0.6}")
|
|
|
+ private Double videoMinScore;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getToken(GetTokenParam param) {
|
|
|
+ ContentPlatformAccount account = accountService.getAccountByTelNum(param.getTelNum());
|
|
|
+ if (Objects.isNull(account)) {
|
|
|
+ throw new CommonException(ExceptionEnum.ACCOUNT_NOT_EXISTS_WRONG);
|
|
|
+ }
|
|
|
+ if (account.getStatus() == AccountStatusEnum.FORBIDDEN.getVal()) {
|
|
|
+ throw new CommonException(ExceptionEnum.ACCOUNT_BANNED);
|
|
|
+ }
|
|
|
+ if (!account.getPassword().equals(param.getPassword())) {
|
|
|
+ throw new CommonException(ExceptionEnum.LOGIN_PASSWORD_WRONG);
|
|
|
+ }
|
|
|
+ String token = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ saveTokenToRedis(account, token, 4 * 60 * 60L);
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveTokenToRedis(ContentPlatformAccount account, String token, Long expireTime) {
|
|
|
+ String tokenPrefix = "api.{token}";
|
|
|
+ String redisKey = tokenPrefix.replace("{token}", token);
|
|
|
+ redisUtils.setValueWithExpire(redisKey, JSON.toJSONString(account), expireTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<VideoIdTitleVO> getContent(String token, GetContentPageParam param) {
|
|
|
+ checkToken(token);
|
|
|
+ if (Objects.isNull(param.getPageNum()) || Objects.isNull(param.getPageSize())
|
|
|
+ || param.getPageNum() <= 0 || param.getPageSize() <= 0) {
|
|
|
+ throw new CommonException(ExceptionEnum.API_PAGE_PARAM_ERROR);
|
|
|
+ }
|
|
|
+ if (param.getPageSize() > 500) {
|
|
|
+ throw new CommonException(ExceptionEnum.API_PAGE_SIZE_TOO_LARGE);
|
|
|
+ }
|
|
|
+ Page<VideoIdTitleVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
+ String dt = planMapperExt.getVideoMaxDt();
|
|
|
+ VideoContentListParam listParam = new VideoContentListParam();
|
|
|
+ int count = planMapperExt.getVideoCount(listParam, dt, videoMinScore);
|
|
|
+ result.setTotalSize(count);
|
|
|
+ if (count == 0) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<ContentPlatformVideo> videoList = planMapperExt.getVideoList(listParam, dt, videoMinScore, offset, param.getPageSize());
|
|
|
+ List<VideoIdTitleVO> list = videoList.stream().map(video -> {
|
|
|
+ VideoIdTitleVO vo = new VideoIdTitleVO();
|
|
|
+ vo.setVideoId(video.getVideoId());
|
|
|
+ vo.setTitle(video.getTitle());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ result.setObjs(list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ContentPlatformAccount checkToken(String token) {
|
|
|
+ String tokenPrefix = "api.{token}";
|
|
|
+ String redisKey = tokenPrefix.replace("{token}", token);
|
|
|
+ String value = redisUtils.getString(redisKey);
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
|
+ throw new CommonException(ExceptionEnum.API_TOKEN_ERROR);
|
|
|
+ }
|
|
|
+ return JSON.parseObject(value, ContentPlatformAccount.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<VideoPageUrlVO> getVideoPageUrl(String token, GetVideoPageUrlParam param) {
|
|
|
+ ContentPlatformAccount account = checkToken(token);
|
|
|
+ if (CollectionUtils.isEmpty(param.getVideoList()) || param.getVideoList().size() > 20) {
|
|
|
+ throw new CommonException(ExceptionEnum.API_PAGE_URL_SIZE_TOO_LARGE);
|
|
|
+ }
|
|
|
+ List<Long> videoIds = param.getVideoList().stream().map(GetVideoPageUrlParam.VideoItem::getVideoId).collect(Collectors.toList());
|
|
|
+ List<ContentPlatformVideo> videoList = planMapperExt.getVideoListByIds(videoIds);
|
|
|
+ Map<Long, ContentPlatformVideo> videoMap = videoList.stream().collect(Collectors.toMap(ContentPlatformVideo::getVideoId, video -> video));
|
|
|
+ List<VideoPageUrlVO> result = new ArrayList<>();
|
|
|
+ if (param.getType() == 1) {
|
|
|
+ for (GetVideoPageUrlParam.VideoItem item : param.getVideoList()) {
|
|
|
+ ContentPlatformQwPlan qwPlan = new ContentPlatformQwPlan();
|
|
|
+ qwPlan.setType(param.getType());
|
|
|
+ qwPlan.setScene(0);
|
|
|
+ String pageUrl = messageAttachmentService.getPage(account.getChannel(), "wxbdd2a2e93d9a6e25",
|
|
|
+ "dyyqw", "企微", QwPlanTypeEnum.from(param.getType()).getDescription(),
|
|
|
+ "位置1", item.getVideoId());
|
|
|
+ String rootSourceId = MessageUtil.getRootSourceId(pageUrl);
|
|
|
+ qwPlan.setPageUrl(pageUrl);
|
|
|
+ qwPlan.setRootSourceId(rootSourceId);
|
|
|
+ qwPlan.setCreateAccountId(account.getId());
|
|
|
+ qwPlan.setCreateTimestamp(System.currentTimeMillis());
|
|
|
+ planMapperExt.insertQwPlanReturnId(qwPlan);
|
|
|
+ // 保存视频内容
|
|
|
+ ContentPlatformVideo video = videoMap.get(item.getVideoId());
|
|
|
+ QwPlanSaveVideoParam videoParam = new QwPlanSaveVideoParam();
|
|
|
+ videoParam.setVideoId(video.getVideoId());
|
|
|
+ videoParam.setTitle(video.getTitle());
|
|
|
+ videoParam.setCover(video.getCover());
|
|
|
+ videoParam.setVideo(video.getVideo());
|
|
|
+ planService.saveQwPlanVideo(videoParam, qwPlan.getId(), account.getId());
|
|
|
+ VideoPageUrlVO vo = new VideoPageUrlVO();
|
|
|
+ vo.setVideoId(item.getVideoId());
|
|
|
+ vo.setTitle(video.getTitle());
|
|
|
+ vo.setCover(video.getCover());
|
|
|
+ vo.setPageUrl(pageUrl);
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (GetVideoPageUrlParam.VideoItem item : param.getVideoList()) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|