|
|
@@ -1,13 +1,23 @@
|
|
|
package com.tzld.piaoquan.api.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.piaoquan.api.component.AigcApiService;
|
|
|
+import com.tzld.piaoquan.api.component.TouLiuHttpClient;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.GhDetailExtMapper;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.GhDetailMapperExt;
|
|
|
+import com.tzld.piaoquan.api.model.po.GhDetailExt;
|
|
|
+import com.tzld.piaoquan.api.model.po.GhDetailExtExample;
|
|
|
import com.tzld.piaoquan.api.model.vo.GhDetailVo;
|
|
|
import com.tzld.piaoquan.api.service.GhDetailService;
|
|
|
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
|
|
|
import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
|
|
|
import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
|
|
|
+import com.tzld.piaoquan.growth.common.dao.mapper.CgiReplyBucketDataMapper;
|
|
|
import com.tzld.piaoquan.growth.common.dao.mapper.GhDetailMapper;
|
|
|
+import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
|
|
|
+import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketDataExample;
|
|
|
import com.tzld.piaoquan.growth.common.model.po.GhDetail;
|
|
|
import com.tzld.piaoquan.growth.common.model.po.GhDetailExample;
|
|
|
import com.tzld.piaoquan.growth.common.utils.DateUtil;
|
|
|
@@ -16,13 +26,12 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@@ -30,11 +39,23 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
|
|
|
@Autowired
|
|
|
private GhDetailMapper ghDetailMapper;
|
|
|
+ @Autowired
|
|
|
+ private GhDetailExtMapper ghDetailExtMapper;
|
|
|
+ @Autowired
|
|
|
+ private GhDetailMapperExt ghDetailMapperExt;
|
|
|
+ @Autowired
|
|
|
+ private AigcApiService aigcApiService;
|
|
|
+ @Autowired
|
|
|
+ private TouLiuHttpClient touLiuHttpClient;
|
|
|
+ @Autowired
|
|
|
+ private CgiReplyBucketDataMapper cgiReplyBucketDataMapper;
|
|
|
|
|
|
+ @Value("${small_page_url}")
|
|
|
+ private String GET_SMALL_PAGE_URL;
|
|
|
|
|
|
@Override
|
|
|
public CommonResponse<Page<GhDetailVo>> getGhDetailList(Integer pageNum, Integer pageSize,
|
|
|
- String accountId, String accountName) {
|
|
|
+ String accountId, String accountName, Long videoId) {
|
|
|
if (pageNum == null) {
|
|
|
pageNum = 1;
|
|
|
}
|
|
|
@@ -56,12 +77,20 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
if (StringUtils.isNotEmpty(accountName)) {
|
|
|
criteria.andGhNameLike("%" + accountName + "%");
|
|
|
}
|
|
|
+ if (Objects.nonNull(videoId)) {
|
|
|
+ criteria.andVideoIdsLike("%" + videoId + "%");
|
|
|
+ }
|
|
|
example.setPage(page);
|
|
|
long total = ghDetailMapper.countByExample(example);
|
|
|
page.setTotalSize((int) total);
|
|
|
List<GhDetail> ghDetails = ghDetailMapper.selectByExample(example);
|
|
|
List<GhDetailVo> ghDetailVos = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(ghDetails)) {
|
|
|
+ List<Long> ghDetailIds = ghDetails.stream().map(GhDetail::getId).collect(Collectors.toList());
|
|
|
+ GhDetailExtExample exampleExt = new GhDetailExtExample();
|
|
|
+ exampleExt.createCriteria().andGhDetailIdIn(ghDetailIds).andIsDeleteEqualTo(0);
|
|
|
+ List<GhDetailExt> ghDetailExts = ghDetailExtMapper.selectByExample(exampleExt);
|
|
|
+ Map<Long, List<GhDetailExt>> ghDetailExtMap = ghDetailExts.stream().collect(Collectors.groupingBy(GhDetailExt::getGhDetailId));
|
|
|
for (GhDetail ghDetail : ghDetails) {
|
|
|
GhDetailVo ghDetailVo = new GhDetailVo();
|
|
|
BeanUtils.copyProperties(ghDetail, ghDetailVo);
|
|
|
@@ -74,6 +103,20 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
if (StringUtils.isNotEmpty(ghDetail.getVideoIds())) {
|
|
|
List<Long> videoIds = JSONObject.parseArray(ghDetail.getVideoIds(), Long.class);
|
|
|
ghDetailVo.setVideoIds(videoIds);
|
|
|
+ List<GhDetailExt> videoExts = ghDetailExtMap.get(ghDetail.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(videoExts)) {
|
|
|
+ videoExts.sort(Comparator.comparing(GhDetailExt::getSort));
|
|
|
+ List<GhDetailVo.VideoDetail> videoList = new ArrayList<>();
|
|
|
+ for (GhDetailExt videoExt : videoExts) {
|
|
|
+ GhDetailVo.VideoDetail videoDetail = new GhDetailVo.VideoDetail();
|
|
|
+ videoDetail.setVideoId(videoExt.getVideoId());
|
|
|
+ videoDetail.setSort(videoExt.getSort());
|
|
|
+ videoDetail.setTitle(videoExt.getTitle());
|
|
|
+ videoDetail.setCover(videoExt.getCover());
|
|
|
+ videoList.add(videoDetail);
|
|
|
+ }
|
|
|
+ ghDetailVo.setVideoList(videoList);
|
|
|
+ }
|
|
|
}
|
|
|
ghDetailVo.setStrategyStatusName(StrategyStatusEnum.getStrategyStatusName(ghDetail.getStrategyStatus()));
|
|
|
ghDetailVos.add(ghDetailVo);
|
|
|
@@ -117,6 +160,9 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
ghDetail.setContentDetail(null);
|
|
|
}
|
|
|
ghDetailMapper.insertSelective(ghDetail);
|
|
|
+ ghDetailMapperExt.deleteOldGhDetailExt(ghDetailVo.getAccountId(), ghDetailVo.getType());
|
|
|
+ batchSaveGhDetailExt(ghDetailVo);
|
|
|
+ aigcApiService.refreshGzhAutoReplyMsgData(ghDetailVo.getAccountId());
|
|
|
return CommonResponse.success();
|
|
|
} catch (Exception e) {
|
|
|
log.error("addGhDetail error", e);
|
|
|
@@ -124,6 +170,48 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
return CommonResponse.create(500, "插入失败");
|
|
|
}
|
|
|
|
|
|
+ private void batchSaveGhDetailExt(GhDetailVo ghDetailVo) {
|
|
|
+ if (CollectionUtils.isEmpty(ghDetailVo.getVideoIds())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GhDetail ghDetail = getGhDetailByGhIdType(ghDetailVo.getAccountId(), ghDetailVo.getType());
|
|
|
+ if (ghDetail == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<GhDetailExt> ghDetailExts = new ArrayList<>();
|
|
|
+ for (GhDetailVo.VideoDetail videoDetail : ghDetailVo.getVideoList()) {
|
|
|
+ GhDetailExt ghDetailExt = new GhDetailExt();
|
|
|
+ ghDetailExt.setGhDetailId(ghDetail.getId());
|
|
|
+ ghDetailExt.setVideoId(videoDetail.getVideoId());
|
|
|
+ ghDetailExt.setPage(getVideoPageUrl(videoDetail.getVideoId(), ghDetailVo.getChannel(), ghDetailVo.getAccountId(), videoDetail.getSort()));
|
|
|
+ ghDetailExt.setTitle(videoDetail.getTitle());
|
|
|
+ ghDetailExt.setCover(videoDetail.getCover());
|
|
|
+ ghDetailExt.setSort(videoDetail.getSort());
|
|
|
+ ghDetailExt.setIsDelete(0);
|
|
|
+ ghDetailExts.add(ghDetailExt);
|
|
|
+ }
|
|
|
+ ghDetailMapperExt.batchInsertGhDetailExt(ghDetailExts);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getVideoPageUrl(Long videoId, String channel, String ghId, Integer sort) {
|
|
|
+ // 查询库里是否存在,如果存在即复用
|
|
|
+ CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
|
|
|
+ cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andMiniVideoIdEqualTo(videoId).andGhIdEqualTo(ghId);
|
|
|
+ List<CgiReplyBucketData> cgiReplyBucketData = cgiReplyBucketDataMapper.selectByExample(cgiReplyBucketDataExample);
|
|
|
+ if (!CollectionUtils.isEmpty(cgiReplyBucketData)) {
|
|
|
+ return cgiReplyBucketData.get(0).getPagePathUrlId().toString();
|
|
|
+ }
|
|
|
+ String response = touLiuHttpClient.sendAdFlowAddRequest(GET_SMALL_PAGE_URL, String.valueOf(videoId), "dyyjs", channel, "自动", "公众号", "自动回复小程序", "位置" + sort, ghId);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(response);
|
|
|
+ if (jsonObject != null && jsonObject.containsKey("data")) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (data != null && data.containsKey("url")) {
|
|
|
+ return data.getString("url");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public CommonResponse<Void> updateDetail(GhDetailVo ghDetailVo) {
|
|
|
if (ghDetailVo == null || ghDetailVo.getId() == null) {
|
|
|
@@ -149,6 +237,8 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
ghDetail.setGhName(ghDetailVo.getAccountName());
|
|
|
ghDetail.setVideoIds(JSONObject.toJSONString(ghDetailVo.getVideoIds()));
|
|
|
ghDetailMapper.updateByPrimaryKeySelective(ghDetail);
|
|
|
+ ghDetailMapperExt.deleteOldGhDetailExt(ghDetailVo.getAccountId(), ghDetailVo.getType());
|
|
|
+ batchSaveGhDetailExt(ghDetailVo);
|
|
|
|
|
|
if (StringUtils.isEmpty(ghDetail.getContentDetail()) || StringUtils.isEmpty(ghDetail.getRate())) {
|
|
|
GhDetail updateGhDetail = ghDetailMapper.selectByPrimaryKey(ghDetail.getId());
|
|
|
@@ -161,7 +251,7 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
updateGhDetail.setUpdateTime(new Date());
|
|
|
ghDetailMapper.updateByPrimaryKey(updateGhDetail);
|
|
|
}
|
|
|
-
|
|
|
+ aigcApiService.refreshGzhAutoReplyMsgData(ghDetailVo.getAccountId());
|
|
|
|
|
|
return CommonResponse.success();
|
|
|
} catch (Exception e) {
|