|
|
|
@ -15,6 +15,7 @@ import cc.hiver.mall.ie.service.IeContentAuditLogService; |
|
|
|
import cc.hiver.mall.ie.service.IeSecurityAuditService; |
|
|
|
import cc.hiver.mall.ie.vo.IeAliyunModerationResult; |
|
|
|
import cc.hiver.mall.ie.vo.IeAuditResult; |
|
|
|
import cc.hiver.mall.utils.WechatSendMessageUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
@ -22,6 +23,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -31,8 +33,11 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
|
import org.springframework.transaction.TransactionDefinition; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.support.TransactionSynchronization; |
|
|
|
import org.springframework.transaction.support.TransactionSynchronizationManager; |
|
|
|
import org.springframework.transaction.support.TransactionTemplate; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.function.Function; |
|
|
|
@ -45,6 +50,7 @@ public class CampusServiceImpl implements CampusService { |
|
|
|
private static final String IMAGE_AUDIT_REJECT_MESSAGE = "图片审核未通过,请更换后重试"; |
|
|
|
private static final String CHAT_UNREAD_KEY_PREFIX = "campus:unread:chat:"; |
|
|
|
private static final String COMMENT_UNREAD_KEY_PREFIX = "campus:unread:comment:"; |
|
|
|
private static final String CAMPUS_COMMENT_WECHAT_TEMPLATE_ID = "X-lezVQyqm9EUsHCi6ja2cAnjdif5uyA21nhmg0RsuU"; |
|
|
|
private static final int STATUS_NORMAL = 1; |
|
|
|
private static final int STATUS_OFF_SHELF = 2; |
|
|
|
private static final int STATUS_DELETED = 3; |
|
|
|
@ -84,6 +90,8 @@ public class CampusServiceImpl implements CampusService { |
|
|
|
private SimpMessagingTemplate messagingTemplate; |
|
|
|
@Autowired |
|
|
|
private PlatformTransactionManager transactionManager; |
|
|
|
@Autowired |
|
|
|
private WechatSendMessageUtil wechatSendMessageUtil; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<CampusCategory> listCategories(String regionId, String parentCode, String categoryType) { |
|
|
|
@ -378,6 +386,11 @@ public class CampusServiceImpl implements CampusService { |
|
|
|
if (!user.getId().equals(post.getUserId())) { |
|
|
|
incrementUnread(commentUnreadKey(post.getUserId()), commentUnreadField(post.getId(), comment.getId())); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(comment.getParentId()) |
|
|
|
&& Integer.valueOf(AUDIT_PASS).equals(comment.getAuditStatus()) |
|
|
|
&& !user.getId().equals(post.getUserId())) { |
|
|
|
sendCampusCommentNotifyAfterCommit(comment, post); |
|
|
|
} |
|
|
|
return comment; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1253,6 +1266,44 @@ public class CampusServiceImpl implements CampusService { |
|
|
|
messagingTemplate.convertAndSend("/topic/campus/session/" + message.getSessionId(), message); |
|
|
|
} |
|
|
|
|
|
|
|
private void sendCampusCommentNotifyAfterCommit(CampusComment comment, CampusPost post) { |
|
|
|
if (comment == null || post == null || StringUtils.isBlank(post.getUserId())) return; |
|
|
|
if (TransactionSynchronizationManager.isSynchronizationActive()) { |
|
|
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { |
|
|
|
@Override |
|
|
|
public void afterCommit() { |
|
|
|
sendCampusCommentNotify(comment, post); |
|
|
|
} |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
sendCampusCommentNotify(comment, post); |
|
|
|
} |
|
|
|
|
|
|
|
private void sendCampusCommentNotify(CampusComment comment, CampusPost post) { |
|
|
|
try { |
|
|
|
User receiver = userService.findById(post.getUserId()); |
|
|
|
if (receiver == null || StringUtils.isBlank(receiver.getOfficialAccountOpenid())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
List<WxMpTemplateData> data = new ArrayList<>(); |
|
|
|
Date createTime = comment.getCreateTime() == null ? new Date() : comment.getCreateTime(); |
|
|
|
data.add(new WxMpTemplateData("time5", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(createTime))); |
|
|
|
data.add(new WxMpTemplateData("thing10", "校园圈有新的评论啦")); |
|
|
|
data.add(new WxMpTemplateData("character_string6", limitCharacterStringValue(defaultString(comment.getId(), post.getId())))); |
|
|
|
wechatSendMessageUtil.sendWechatTempMessage( |
|
|
|
Collections.singletonList(receiver.getOfficialAccountOpenid()), |
|
|
|
CAMPUS_COMMENT_WECHAT_TEMPLATE_ID, |
|
|
|
data, |
|
|
|
"pages/index/index" |
|
|
|
); |
|
|
|
log.info("校园圈评论公众号通知已发送,commentId={}, receiverId={}", comment.getId(), post.getUserId()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("校园圈评论公众号通知发送失败,commentId={}, receiverId={}, reason={}", |
|
|
|
comment == null ? null : comment.getId(), post == null ? null : post.getUserId(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void incrementUnread(String key, String field) { |
|
|
|
if (stringRedisTemplate == null || StringUtils.isAnyBlank(key, field)) return; |
|
|
|
stringRedisTemplate.opsForHash().increment(key, field, 1L); |
|
|
|
@ -1324,6 +1375,14 @@ public class CampusServiceImpl implements CampusService { |
|
|
|
return postId + ":" + commentId; |
|
|
|
} |
|
|
|
|
|
|
|
private String limitCharacterStringValue(String value) { |
|
|
|
String text = StringUtils.defaultString(value).replaceAll("[^A-Za-z0-9_-]", ""); |
|
|
|
if (StringUtils.isBlank(text)) { |
|
|
|
return "campus"; |
|
|
|
} |
|
|
|
return text.length() > 32 ? text.substring(0, 32) : text; |
|
|
|
} |
|
|
|
|
|
|
|
private CampusPageQuery normalizeQuery(CampusPageQuery query) { |
|
|
|
CampusPageQuery q = query == null ? new CampusPageQuery() : query; |
|
|
|
q.setPageNum(q.getPageNum() == null || q.getPageNum() < 1 ? 1 : q.getPageNum()); |
|
|
|
|