Commit 69fca593 authored by 刘基明's avatar 刘基明

Merge branch 'v2.3.1' of 47.100.44.39:tp-backend/tanpu-community into v2.3.1

parents 84a1ea38 d29ce8f9
package com.tanpu.community.feign.wxcp;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboDetailVO;
import com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboListResp;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
@FeignClient(value = "service-wxcp", url = "${tanpu.wxcp.svc:}", contextId = "wxcp", fallbackFactory = FeignbackForWxcp.class, path = "/wxcp")
//@FeignClient(value = "service-product", contextId = "product", fallbackFactory = FeignBackClientForProducts.class, url = "http://127.0.0.1:8194/product")
public interface FeignClientForWxcp {
@PostMapping("/wx/kf/sendMessage/{agentId}/{corpId}")
@ApiOperation("发送微信客服消息")
CommonResp sendMessage(@PathVariable("agentId") Long agentId,
@PathVariable("corpId") String corpId,
@RequestBody String requestBody);
}
package com.tanpu.community.feign.wxcp;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboDetailVO;
import com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboListResp;
import com.tanpu.community.feign.zhibo.FeignClientForZhibo;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
@Slf4j
@Component
public class FeignbackForWxcp implements FallbackFactory<FeignClientForWxcp> {
@Override
public FeignClientForWxcp create(Throwable throwable) {
return new FeignClientForWxcp() {
@Override
public CommonResp sendMessage(Long agentId, String corpId, String requestBody) {
log.error("请求信息", throwable);
log.error("FeignClientForWxcp.sendMessage-agentId:{}, corpId:{}, request:{}", agentId, corpId, requestBody);
return CommonResp.error();
}
};
}
}
...@@ -21,11 +21,7 @@ import org.springframework.stereotype.Service; ...@@ -21,11 +21,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tanpu.community.api.constants.RedisKeyConstant.*; import static com.tanpu.community.api.constants.RedisKeyConstant.*;
...@@ -72,10 +68,21 @@ public class CommentService { ...@@ -72,10 +68,21 @@ public class CommentService {
//统计主题集合的评论量 //统计主题集合的评论量
public Integer getCommentCountByThemeId(String themeId) { public Integer getCommentCountByThemeId(String themeId) {
return commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>() return commentMapper.selectCount((new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getThemeId, themeId)) .eq(CommentEntity::getThemeId, themeId))
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)) .eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
.size(); }
public Integer getCommentCountByThemeIds(List<String> themeIds) {
return commentMapper.selectCount((new LambdaQueryWrapper<CommentEntity>()
.in(CommentEntity::getThemeId, themeIds))
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
}
public Integer getCommentCountByThemeIds(List<String> themeIds, Date startDate, Date endDate) {
return commentMapper.selectCount((new LambdaQueryWrapper<CommentEntity>()
.in(CommentEntity::getThemeId, themeIds))
.gt(CommentEntity::getCreateTime, startDate)
.lt(CommentEntity::getCreateTime, endDate)
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
} }
......
...@@ -28,13 +28,7 @@ import org.springframework.stereotype.Service; ...@@ -28,13 +28,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -203,6 +197,16 @@ public class ThemeService { ...@@ -203,6 +197,16 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper).stream().map(ThemeEntity::getThemeId).collect(Collectors.toList()); return themeMapper.selectList(queryWrapper).stream().map(ThemeEntity::getThemeId).collect(Collectors.toList());
} }
public List<String> queryThemeIdsByTopic(String topidId, Date startDate, Date endDate) {
if (StringUtils.isEmpty(topidId)) {
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getTopicId, topidId).gt(ThemeEntity::getCreateTime, startDate).lt(ThemeEntity::getCreateTime, endDate);
queryWrapper.select(ThemeEntity::getThemeId);
return themeMapper.selectList(queryWrapper).stream().map(ThemeEntity::getThemeId).collect(Collectors.toList());
}
/** /**
* 根据作者查询主题分页列表 * 根据作者查询主题分页列表
* *
......
...@@ -34,12 +34,7 @@ import org.springframework.stereotype.Service; ...@@ -34,12 +34,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -48,10 +43,10 @@ import java.util.stream.Collectors; ...@@ -48,10 +43,10 @@ import java.util.stream.Collectors;
public class TopicService { public class TopicService {
@Resource @Resource
TopicFollowRelMapper topicFollowRelMapper; private TopicFollowRelMapper topicFollowRelMapper;
@Resource @Resource
TopicMapper topicMapper; private TopicMapper topicMapper;
@Resource @Resource
private TopicManagerMapper topicManagerMapper; private TopicManagerMapper topicManagerMapper;
...@@ -76,6 +71,13 @@ public class TopicService { ...@@ -76,6 +71,13 @@ public class TopicService {
return retList; return retList;
} }
public List<TopicEntity> queryTopicNeedReport() {
// 是否同步动态至管理员企业微信 0:否 1:是
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getSyncCorpWechat, 1)
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
public TopicEntity queryOnlineTopicById(String topicId) { public TopicEntity queryOnlineTopicById(String topicId) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>() return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
...@@ -98,6 +100,10 @@ public class TopicService { ...@@ -98,6 +100,10 @@ public class TopicService {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId, topicIds)); return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId, topicIds));
} }
/**
* CRUD Topic_Follow
*/
public List<TopicFollowQo> queryFollowTopic(String keyword, String userId) { public List<TopicFollowQo> queryFollowTopic(String keyword, String userId) {
// 用户的关注列表(包括专属) // 用户的关注列表(包括专属)
List<String> followTopicIds = topicFollowRelMapper.selectTopicIdByUserId(userId); List<String> followTopicIds = topicFollowRelMapper.selectTopicIdByUserId(userId);
...@@ -108,7 +114,21 @@ public class TopicService { ...@@ -108,7 +114,21 @@ public class TopicService {
List<TopicEntity> topicEntities = topicMapper.selectAllByTopicIdIn(followTopicIds); List<TopicEntity> topicEntities = topicMapper.selectAllByTopicIdIn(followTopicIds);
List<TopicFollowQo> topicFollowQos = ConvertUtil.topicEntityToFollowQos(topicEntities); List<TopicFollowQo> topicFollowQos = ConvertUtil.topicEntityToFollowQos(topicEntities);
return topicFollowQos; return topicFollowQos;
}
// 根据关注事件 count
public Integer countTotalFollow(String topicId) {
return topicFollowRelMapper.selectCount(new LambdaQueryWrapper<TopicFollowRelEntity>()
.eq(TopicFollowRelEntity::getTopicId, topicId)
.eq(TopicFollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
public Integer countFollowByIdAndTime(String topicId, Date startDate, Date endDate) {
return topicFollowRelMapper.selectCount(new LambdaQueryWrapper<TopicFollowRelEntity>()
.eq(TopicFollowRelEntity::getTopicId, topicId)
.gt(TopicFollowRelEntity::getFollowTime, startDate)
.lt(TopicFollowRelEntity::getFollowTime, endDate)
.eq(TopicFollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
} }
...@@ -267,6 +287,10 @@ public class TopicService { ...@@ -267,6 +287,10 @@ public class TopicService {
} }
} }
public List<TopicManagerEntity> getManagersByTopic(String topicId) {
return topicManagerMapper.selectList(new LambdaQueryWrapper<TopicManagerEntity>().eq(TopicManagerEntity::getTopicId, topicId));
}
public Set<String> getManagerId(String topicId) { public Set<String> getManagerId(String topicId) {
if (StringUtils.isBlank(topicId)) { if (StringUtils.isBlank(topicId)) {
return new HashSet<>(); return new HashSet<>();
......
package com.tanpu.community.service.quartz;
import com.alibaba.fastjson.JSON;
import com.tanpu.common.util.DateUtils;
import com.tanpu.community.api.beans.vo.feign.user.UserInfoVo;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.entity.community.TopicManagerEntity;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.feign.wxcp.FeignClientForWxcp;
import com.tanpu.community.manager.TopicManager;
import com.tanpu.community.service.CommentService;
import com.tanpu.community.service.ThemeService;
import com.tanpu.community.service.TopicService;
import com.tanpu.community.service.VisitLogService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class TopicReportService {
@Value("${wxcp.topicreport.agentId}")
private Long agentId;
@Value("${wxcp.topicreport.corpId}")
private String corpId;
@Autowired
private TopicService topicService;
@Autowired
private ThemeService themeService;
@Autowired
private CommentService commentService;
@Autowired
private VisitLogService visitLogService;
@Autowired
private FeignClientForWxcp feignClientForWxcp;
@Autowired
private FeignClientForFatools feignClientForFatools;
// 每个工作日早上09:30汇报
public static String content_report_topic_weekday = "话题(%s) 当前总成员: %s, 当前总阅读: %s, 当前总讨论: %s, 昨日新增成员: %s, 昨日新增讨论";
public void reportTopicWeekday() {
List<TopicEntity> topics = topicService.queryTopicNeedReport();
for (TopicEntity topic : topics) {
// 当前总成员
Integer totalFollowNum = topicService.countTotalFollow(topic.getTopicId());
// 阅读量
Integer totalVisitNum = visitLogService.queryTopicDetailVisit(topic.getTopicId());
// 讨论量 包括主题数量和评论数量 不算长文
List<String> totalThemeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
Integer totalCommentNum = commentService.getCommentCountByThemeIds(totalThemeIds);
Integer totalDiscussNum = totalCommentNum + totalThemeIds.size();
Date endDate = DateUtils.getDayStartTime(new Date());
Date startDate = DateUtils.getAfterDay(endDate, -1);
// 昨日新增成员
Integer newFollowNum = topicService.countFollowByIdAndTime(topic.getTopicId(), startDate, endDate);
// 昨日新增讨论
List<String> newThemeIds = themeService.queryThemeIdsByTopic(topic.getTopicId(), startDate, endDate);
Integer newCommentNum = commentService.getCommentCountByThemeIds(totalThemeIds, startDate, endDate);
Integer newDiscussNum = newThemeIds.size() + newCommentNum;
String content = String.format(content_report_topic_weekday, topic.getTopicTitle(), totalFollowNum, totalVisitNum, totalDiscussNum, newFollowNum, newDiscussNum);
List<String> wxcpIds = getTopicManagerWxcpIds(topic.getTopicId());
sendReportMessage(content, wxcpIds);
}
}
// 每周六早上09:00汇报
public static String content_report_topic_saturday = "话题(%s) 当前总成员: %s, 当前总阅读: %s, 当前总讨论: %s, 截至本周五新增成员: %s, 昨日新增讨论";
public void reportTopicSaturday() {
List<TopicEntity> topics = topicService.queryTopicNeedReport();
for (TopicEntity topic : topics) {
// 当前总成员
Integer totalFollowNum = topicService.countTotalFollow(topic.getTopicId());
// 阅读量
Integer totalVisitNum = visitLogService.queryTopicDetailVisit(topic.getTopicId());
// 讨论量 包括主题数量和评论数量 不算长文
List<String> totalThemeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
Integer totalCommentNum = commentService.getCommentCountByThemeIds(totalThemeIds);
Integer totalDiscussNum = totalCommentNum + totalThemeIds.size();
Date today = DateUtils.getDayStartTime(new Date());
Date endDate = DateUtils.getAfterDay(today, -1);
Date startDate = DateUtils.getAfterDay(endDate, -5);
// 昨日新增成员
Integer newFollowNum = topicService.countFollowByIdAndTime(topic.getTopicId(), startDate, endDate);
// 昨日新增讨论
List<String> newThemeIds = themeService.queryThemeIdsByTopic(topic.getTopicId(), startDate, endDate);
Integer newCommentNum = commentService.getCommentCountByThemeIds(totalThemeIds, startDate, endDate);
Integer newDiscussNum = newThemeIds.size() + newCommentNum;
String content = String.format(content_report_topic_saturday, topic.getTopicTitle(), totalFollowNum, totalVisitNum, totalDiscussNum, newFollowNum, newDiscussNum);
List<String> wxcpIds = getTopicManagerWxcpIds(topic.getTopicId());
sendReportMessage(content, wxcpIds);
}
}
public void sendReportMessage(String content, List<String> wxcpIds) {
Map<String, Object> parmMap = new HashMap<>();
parmMap.put("type", "text");
parmMap.put("content", content);
parmMap.put("list", wxcpIds);
feignClientForWxcp.sendMessage(agentId, corpId, JSON.toJSONString(parmMap));
}
public List<String> getTopicManagerWxcpIds(String topicId) {
List<String> retList = new ArrayList<>();
List<TopicManagerEntity> managers = topicService.getManagersByTopic(topicId);
for (TopicManagerEntity mgr : managers) {
UserInfoVo user = feignClientForFatools.getUserInfoById(mgr.getUserId());
if (user != null && user.getUiTelphone() != null) {
// todo 应该用企业微信 这里暂时用手机号代替
retList.add(user.getUiTelphone());
}
}
return retList;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment