加入推荐算法 优化朋友圈 service 初级算法

service 加入推荐算法 优化朋友圈 初级算法

import com.alibaba.dubbo.config.annotation.Reference;

import com.tanhua.common.pojo.User;

import com.tanhua.common.utils.UserThreadLocal;

import com.tanhua.dubbo.server.api.QuanZiApi;

import com.tanhua.dubbo.server.pojo.Publish;

import lombok.extern.slf4j.Slf4j;

import org.apache.rocketmq.spring.core.RocketMQTemplate;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.HashMap;

import java.util.Map;

@Service

@Slf4j

public class QuanziMQService {

@Autowired

private RocketMQTemplate rocketMQTemplate;

@Reference(version = “1.0.0”)

private QuanZiApi quanZiApi;

/**

* 发布动态消息

*

* @param publishId

* @return

*/

public Boolean publishMsg(String publishId) {

return this.sendMsg(publishId, 1);

}

/**

* 浏览动态消息

*

* @param publishId

* @return

*/

public Boolean queryPublishMsg(String publishId) {

return this.sendMsg(publishId, 2);

}

/**

* 点赞动态消息

*

* @param publishId

* @return

*/

public Boolean likePublishMsg(String publishId) {

return this.sendMsg(publishId, 3);

}

/**

* 取消点赞动态消息

*

* @param publishId

* @return

*/

public Boolean disLikePublishMsg(String publishId) {

return this.sendMsg(publishId, 6);

}

/**

* 喜欢动态消息

*

* @param publishId

* @return

*/

public Boolean lovePublishMsg(String publishId) {

return this.sendMsg(publishId, 4);

}

/**

* 取消喜欢动态消息

*

* @param publishId

* @return

*/

public Boolean disLovePublishMsg(String publishId) {

return this.sendMsg(publishId, 7);

}

/**

* 评论动态消息

*

* @param publishId

* @return

*/

public Boolean commentPublishMsg(String publishId) {

return this.sendMsg(publishId, 5);

}

/**

* 发送圈子操作相关的消息

*

* @param publishId

* @param type 1-发动态,2-浏览动态, 3-点赞, 4-喜欢, 5-评论,6-取消点赞,7-取消喜欢

* @return

*/

private Boolean sendMsg(String publishId, Integer type) {

try {

User user = UserThreadLocal.get();

Publish publish = this.quanZiApi.queryPublishById(publishId);

//构建消息

Map msg = new HashMap();

msg.put(“userId”, user.getId());

msg.put(“date”, System.currentTimeMillis());

msg.put(“publishId”, publishId);

msg.put(“pid”, publish.getPid());

msg.put(“type”, type);

this.rocketMQTemplate.convertAndSend(“tanhua-quanzi”, msg);

} catch (Exception e) {

log.error(“发送消息失败! publishId = ” + publishId + “, type = ” + type, e);

return false;

}

return true;

}

}

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
(0)
用户投稿
上一篇 2022年6月28日
下一篇 2022年6月28日

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息