package com.stylefeng.guns.modular.api;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.stylefeng.guns.modular.system.dto.AddFindDTO;
|
import com.stylefeng.guns.modular.system.dto.CommentQuery;
|
import com.stylefeng.guns.modular.system.dto.FindQuery;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.*;
|
import com.stylefeng.guns.modular.system.util.Page;
|
import com.stylefeng.guns.modular.system.vo.*;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author 无关风月
|
* @Date 2024/2/6 18:25
|
*/
|
@RestController
|
@RequestMapping("")
|
public class FindController {
|
@Autowired
|
private IAppUserService appUserService;
|
@Autowired
|
private IFindService findService;
|
@Autowired
|
private IFindCommentService findCommentService;
|
@Autowired
|
private IFindReportService reportService;
|
@Autowired
|
private IMessageService messageService;
|
|
@ResponseBody
|
@PostMapping("/base/find/testAudit")
|
@ApiOperation(value = "测试接口", tags = {"测试"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "text", value = "如果是评论的动态 pid传0 否则传一级评论的id", required = true),
|
})
|
public ResultUtil<AuditVO> messageList(String text) {
|
AuditVO content = auditUtil.content(text);
|
return ResultUtil.success(content);
|
}
|
|
@ResponseBody
|
@PostMapping("/base/find/messageList")
|
@ApiOperation(value = "消息中心", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
|
})
|
public ResultUtil<List<MessagesVO>> messageList(MessageQuery req) {
|
req.setPageNum((req.getPageNum() - 1) * req.getPageSize());
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUser.getId();
|
List<MessagesVO> res = messageService.selectMessages(id,req);
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
|
for (MessagesVO re : res) {
|
String format1 = format.format(re.getTime());
|
re.setInsertTime(format1);
|
if (re.getFindId()!=null){
|
Find find = findService.selectById(re.getFindId());
|
if (find.getState()==2 || find.getIsDelete() == 1){
|
re.setIsTurn(0);
|
}else{
|
re.setIsTurn(1);
|
}
|
}else{
|
re.setIsTurn(0);
|
}
|
}
|
// 将这十条消息设置为已读
|
List<Integer> collect = res.stream().map(MessagesVO::getId).collect(Collectors.toList());
|
// 消息ids
|
if (collect.size()>0){
|
List<Message> messages = messageService.selectBatchIds(collect);
|
for (Message message : messages) {
|
message.setIsRead(1);
|
messageService.updateById(message);
|
}
|
}
|
return ResultUtil.success(res);
|
}
|
|
@ResponseBody
|
@PostMapping("/base/find/messageCount")
|
@ApiOperation(value = "消息中心-未读消息数量", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil<Integer> messageCount() {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
int size = messageService.selectList(new EntityWrapper<Message>()
|
.eq("userId", appUser.getId())
|
.eq("isRead", 0)).size();
|
return ResultUtil.success(size);
|
}
|
@Autowired
|
private AuditUtil auditUtil;
|
@ResponseBody
|
@PostMapping("/base/find/addComment")
|
@ApiOperation(value = "发布评论", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "pid", value = "如果是评论的动态 pid传0 否则传一级评论的id", required = true),
|
@ApiImplicitParam(name = "findId", value = "动态id", required = true),
|
@ApiImplicitParam(name = "replyUserId", value = "回复的那条评论的用户id,不是回复就不传"),
|
@ApiImplicitParam(name = "replyCommentId", value = "回复的那条评论的评论id,不是回复评论就不传"),
|
@ApiImplicitParam(name = "content", value = "回复内容", required = true),
|
})
|
public ResultUtil addComment(Integer findId,Integer pid,Integer replyUserId,String content,Integer replyCommentId) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
AuditVO content1 = auditUtil.content(content);
|
switch (content1.getType()){
|
case "terrorism":
|
return ResultUtil.error("评论内容涉及暴恐");
|
case "porn":
|
return ResultUtil.error("评论内容涉及色情");
|
case "ban":
|
return ResultUtil.error("评论内容违禁");
|
case "abuse":
|
return ResultUtil.error("评论内容涉及辱骂");
|
case "ad":
|
return ResultUtil.error("评论内容涉及广告");
|
case "politics":
|
return ResultUtil.error("评论内容涉及政治");
|
}
|
FindComment findComment = new FindComment();
|
findComment.setFindId(findId);
|
findComment.setContent(content);
|
findComment.setPid(pid);
|
findComment.setUserId(appUserService.getAppUser().getId());
|
findComment.setReplyUserId(replyUserId);
|
findComment.setInsertTime(new Date());
|
// 添加消息
|
Message message = new Message();
|
message.setType(3);
|
if (replyCommentId == null){
|
// 评论的动态
|
message.setTitle("评论了你");
|
}else{
|
// 评论的评论
|
message.setTitle("回复了你");
|
// 评论的是某个评论
|
FindComment findComment1 = findComment.selectById(replyCommentId);
|
message.setUserId(findComment1.getUserId());
|
}
|
message.setContent(content);
|
message.setInsertTime(new Date());
|
message.setFindId(findId);
|
message.setFindCommentId(replyCommentId);
|
message.setReplayUserId(appUserService.getAppUser().getId());
|
if (pid == 0){
|
// 评论的动态 需要给发布动态的人发送一条消息
|
Find find = findService.selectById(findId);
|
message.setUserId(find.getUserId());
|
}
|
messageService.insert(message);
|
findCommentService.insert(findComment);
|
return ResultUtil.success("发布成功");
|
}
|
@ResponseBody
|
@PostMapping("/base/find/addFind")
|
@ApiOperation(value = "发布动态", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil collectCourse(AddFindDTO dto) throws InterruptedException {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
if (StringUtils.hasLength(dto.getVideo())){
|
// 根据id回查
|
String id = auditUtil.video(dto.getVideo());
|
String audit = auditUtil.audit(id);
|
while(audit.equals("running")){
|
Thread.sleep(500);
|
audit = auditUtil.audit(id);
|
System.err.println("未审核完");
|
}
|
if (!audit.equals("succeeded")){
|
// 再重新调用
|
return ResultUtil.error("上传的视频涉及违规内容,请修改后发布");
|
}
|
}
|
AuditVO content1 = auditUtil.content(dto.getContent());
|
AuditVO content2 = auditUtil.content(dto.getTitle());
|
if (StringUtils.hasLength(dto.getImg())){
|
String[] split = dto.getImg().split(",");
|
for (String s : split) {
|
AuditVO content3 = auditUtil.image(s);
|
if (content3.getType()!=null){
|
switch (content3.getType()){
|
case "terrorism":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请修改后上传");
|
case "porn":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请修改后上传");
|
case "ban":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请修改后上传");
|
case "abuse":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请修改后上传");
|
case "ad":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请修改后上传");
|
case "politics":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请修改后上传");
|
}
|
}
|
}
|
}
|
if (content1.getType()!=null){
|
switch (content1.getType()){
|
case "terrorism":
|
return ResultUtil.error("动态内容涉及暴恐,请修改后发布");
|
case "porn":
|
return ResultUtil.error("动态内容涉及色情,请修改后发布");
|
case "ban":
|
return ResultUtil.error("动态内容违禁,请修改后发布");
|
case "abuse":
|
return ResultUtil.error("动态内容涉及辱骂,请修改后发布");
|
case "ad":
|
return ResultUtil.error("动态内容涉及广告,请修改后发布");
|
case "politics":
|
return ResultUtil.error("动态内容涉及政治,请修改后发布");
|
}
|
}
|
if (content2.getType()!=null){
|
switch (content2.getType()){
|
case "terrorism":
|
return ResultUtil.error("标题内容涉及暴恐,请修改后发布");
|
case "porn":
|
return ResultUtil.error("标题内容涉及色情,请修改后发布");
|
case "ban":
|
return ResultUtil.error("标题内容违禁,请修改后发布");
|
case "abuse":
|
return ResultUtil.error("标题内容涉及辱骂,请修改后发布");
|
case "ad":
|
return ResultUtil.error("标题内容涉及广告,请修改后发布");
|
case "politics":
|
return ResultUtil.error("标题内容涉及政治,请修改后发布");
|
}
|
}
|
|
Find find = new Find();
|
BeanUtils.copyProperties(dto,find);
|
find.setInsertTime(new Date());
|
find.setUserId(appUserService.getAppUser().getId());
|
findService.insert(find);
|
return ResultUtil.success("发布成功");
|
}
|
|
@ResponseBody
|
@PostMapping("/base/find/findDetail")
|
@ApiOperation(value = "动态详情", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "id", value = "动态id", required = true)
|
})
|
public ResultUtil<FindVO> findDetail(Integer id) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Find find1 = findService.selectById(id);
|
FindVO findVO = new FindVO();
|
findVO.setId(find1.getId());
|
findVO.setUserId(find1.getUserId());
|
findVO.setInsertTime1(find1.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String parse = format.format(find1.getInsertTime());
|
findVO.setInsertTime(parse);
|
findVO.setLikeCount(find1.getLikeCount());
|
findVO.setTitle(find1.getTitle());
|
findVO.setContent(find1.getContent());
|
findVO.setImg(find1.getImg());
|
findVO.setVideo(find1.getVideo());
|
findVO.setIsTop(find1.getIsTop());
|
findVO.setIsDelete(find1.getIsDelete());
|
findVO.setCoverImage(find1.getCoverImage());
|
// 计算每个动态的评论数量
|
int size = findCommentService.selectList(new EntityWrapper<FindComment>()
|
.eq("findId", find1.getId())
|
.eq("isShow", 1)).size();
|
findVO.setComment(size);
|
|
findVO.setHeadImg(appUser.getHeadImg());
|
findVO.setUserName(appUser.getName());
|
findVO.setClockIn(appUser.getClockIn());
|
// 查询用户点赞记录
|
int size1 = likeService.selectList(new EntityWrapper<Like>()
|
.eq("userId", appUserService.getAppUser().getId())
|
.eq("type", 1)
|
.eq("findId", id)).size();
|
// 点赞过该动态
|
if (size1>0){
|
findVO.setIsLike(1);
|
}else{
|
findVO.setIsLike(0);
|
}
|
return ResultUtil.success(findVO);
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/find/findCommentList")
|
@ApiOperation(value = "动态详情-评论列表", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil<List<CommentVO>> findDetail(CommentQuery query) throws ParseException {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
query.setPageNum((query.getPageNum() - 1) * query.getPageSize());
|
// 查询一级评论
|
List<CommentVO> one = findCommentService.getCommentOne(query);
|
for (CommentVO comment : one) {
|
Integer id = comment.getId();
|
Like like = likeService.selectOne(new EntityWrapper<Like>()
|
.eq("userId", appUserService.getAppUser().getId())
|
.eq("type", 2)
|
.eq("findId", id));
|
if (like == null){
|
// 没有点赞
|
comment.setIsLike(0);
|
}else{
|
comment.setIsLike(1);
|
}
|
// 假设这是您要判断的日期
|
Date targetDate = comment.getInsertTime1();
|
// 获取今天的日期
|
Date today = new Date();
|
// 获取昨天的日期
|
Calendar yesterdayCal = Calendar.getInstance();
|
yesterdayCal.add(Calendar.DAY_OF_MONTH, -1);
|
Date yesterday = yesterdayCal.getTime();
|
// 将目标日期、今天和昨天的日期格式化为 yyyy-MM-dd 格式的字符串
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
|
String targetDateStr = sdf.format(targetDate);
|
String todayStr = sdf.format(today);
|
String yesterdayStr = sdf.format(yesterday);
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
SimpleDateFormat format1 = new SimpleDateFormat("HH:mm");
|
// 判断目标日期是否是今天、昨天还是更早以前
|
if (targetDateStr.equals(todayStr)) {
|
String format2 = format1.format(comment.getInsertTime1());
|
comment.setInsertTime(format2);
|
System.out.println("目标日期是今天");
|
} else if (targetDateStr.equals(yesterdayStr)) {
|
String format2 = format1.format(comment.getInsertTime1());
|
comment.setInsertTime("昨天 "+format2);
|
System.out.println("目标日期是昨天");
|
} else {
|
String format2 = format.format(comment.getInsertTime1());
|
comment.setInsertTime(format2);
|
System.out.println("目标日期更早以前");
|
}
|
|
|
// 查询这条评论下面的子评论
|
List<CommentVO> two = findCommentService.getCommentTwo(comment.getId());
|
for (CommentVO commentVO : two) {
|
Integer id1 = commentVO.getId();
|
Like like1 = likeService.selectOne(new EntityWrapper<Like>()
|
.eq("userId", appUserService.getAppUser().getId())
|
.eq("type", 2)
|
.eq("findId", id1));
|
if (like1 == null){
|
// 没有点赞
|
commentVO.setIsLike(0);
|
}else{
|
commentVO.setIsLike(1);
|
}
|
// 假设这是您要判断的日期
|
Date targetDate1 = commentVO.getInsertTime1();
|
// 获取今天的日期
|
// 获取昨天的日期
|
// 将目标日期、今天和昨天的日期格式化为 yyyy-MM-dd 格式的字符串
|
String targetDateStr1 = sdf.format(targetDate1);
|
// 判断目标日期是否是今天、昨天还是更早以前
|
if (targetDateStr1.equals(todayStr)) {
|
String format2 = format1.format(commentVO.getInsertTime1());
|
commentVO.setInsertTime(format2);
|
System.out.println("目标日期是今天");
|
} else if (targetDateStr1.equals(yesterdayStr)) {
|
String format2 = format1.format(commentVO.getInsertTime1());
|
commentVO.setInsertTime("昨天 "+format2);
|
System.out.println("目标日期是昨天");
|
} else {
|
String format2 = format.format(commentVO.getInsertTime1());
|
commentVO.setInsertTime(format2);
|
System.out.println("目标日期更早以前");
|
}
|
}
|
comment.setCommentList(two);
|
}
|
return ResultUtil.success(one);
|
}
|
public static void main(String[] args) {
|
|
String request = HttpRequestUtil.getRequest("https://restapi.amap.com/v3/distance?key=" + "4bdddca5a75e9fcf95fc8404082d3330" + "&origins=" + "105.907813,29.342846" + "&destination=" + "105.906929,29.341645" +
|
"&type=" + "1");
|
System.err.println(request);
|
}
|
public static int daysBetween(Calendar startDate, Calendar endDate) {
|
// 将时间转换为毫秒
|
long startTimeInMillis = startDate.getTimeInMillis();
|
long endTimeInMillis = endDate.getTimeInMillis();
|
// 计算日期差异并返回
|
return (int) ((endTimeInMillis - startTimeInMillis) / (1000 * 60 * 60 * 24));
|
}
|
@ResponseBody
|
@PostMapping("/base/find/findCommentListOne")
|
@ApiOperation(value = "动态详情-查看一级评论下的评论", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil<List<CommentVO>> findCommentListOne(CommentQuery query) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
// 查询一级评论
|
List<CommentVO> one = findCommentService.getCommentThree(query);
|
for (CommentVO commentVO : one) {
|
Integer id1 = commentVO.getId();
|
Like like1 = likeService.selectOne(new EntityWrapper<Like>()
|
.eq("userId", appUserService.getAppUser().getId())
|
.eq("type", 2)
|
.eq("findId", id1));
|
if (like1 == null){
|
// 没有点赞
|
commentVO.setIsLike(0);
|
}else{
|
commentVO.setIsLike(1);
|
}
|
// 假设这是您要判断的日期
|
Date targetDate = commentVO.getInsertTime1();
|
// 获取今天的日期
|
Date today = new Date();
|
// 获取昨天的日期
|
Calendar yesterdayCal = Calendar.getInstance();
|
yesterdayCal.add(Calendar.DAY_OF_MONTH, -1);
|
Date yesterday = yesterdayCal.getTime();
|
// 将目标日期、今天和昨天的日期格式化为 yyyy-MM-dd 格式的字符串
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
|
String targetDateStr = sdf.format(targetDate);
|
String todayStr = sdf.format(today);
|
String yesterdayStr = sdf.format(yesterday);
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
SimpleDateFormat format1 = new SimpleDateFormat("HH:mm");
|
// 假设这是您要判断的日期
|
Date targetDate1 = commentVO.getInsertTime1();
|
// 获取今天的日期
|
// 获取昨天的日期
|
// 将目标日期、今天和昨天的日期格式化为 yyyy-MM-dd 格式的字符串
|
String targetDateStr1 = sdf.format(targetDate1);
|
// 判断目标日期是否是今天、昨天还是更早以前
|
if (targetDateStr1.equals(todayStr)) {
|
String format2 = format1.format(commentVO.getInsertTime1());
|
commentVO.setInsertTime(format2);
|
System.out.println("目标日期是今天");
|
} else if (targetDateStr1.equals(yesterdayStr)) {
|
String format2 = format1.format(commentVO.getInsertTime1());
|
commentVO.setInsertTime("昨天 "+format2);
|
System.out.println("目标日期是昨天");
|
} else {
|
String format2 = format.format(commentVO.getInsertTime1());
|
commentVO.setInsertTime(format2);
|
System.out.println("目标日期更早以前");
|
}
|
}
|
List<CommentVO> commentVOS = testing1(one.size(), query.getPageNum(), query.getPageSize(), one);
|
return ResultUtil.success(commentVOS);
|
}
|
|
public static List<CommentVO> testing1(long total, long current, long size, List<CommentVO> str){
|
List<CommentVO> result = new ArrayList<>();
|
//获取初始化分页结构
|
com.stylefeng.guns.modular.system.util.Page<CommentVO> page = new Page().getPage(total, size, current - 1);
|
//获取集合下标初始值
|
long startIndex = page.getStartIndex();
|
//获取集合下标结束值
|
long endInddex = 0;
|
if(startIndex + page.getCurrent() >= total || size > total){
|
endInddex = total;
|
}else {
|
endInddex = Math.min(startIndex + page.getSize(), total);
|
}
|
//如果输入的开始查询下标大于集合大小,则查询为空值
|
if(startIndex > total){
|
result = Collections.emptyList();
|
}else{
|
result = str.subList((int)startIndex,(int)endInddex);
|
}
|
return result;
|
}
|
@Autowired
|
private ILikeService likeService;
|
@ResponseBody
|
@PostMapping("/base/find/cancelLike")
|
@ApiOperation(value = "动态/评论取消点赞", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "id", value = "动态/评论id", required = true),
|
@ApiImplicitParam(name = "type", value = "类型 1 = 点赞动态 2 = 点赞评论", required = true)
|
})
|
public ResultUtil cancelLike(Integer id,Integer type) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Like like = likeService.selectOne(new EntityWrapper<Like>()
|
.eq("userId", appUserService.getAppUser().getId())
|
.eq("type", type)
|
.eq("findId", id));
|
if (like!=null){
|
likeService.deleteById(like.getId());
|
}
|
return ResultUtil.success();
|
}
|
@ResponseBody
|
@PostMapping("/base/find/Like")
|
@ApiOperation(value = "动态/评论点赞", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "id", value = "动态id", required = true),
|
@ApiImplicitParam(name = "findCommentId", value = "评论id(如果点赞的是评论才传)"),
|
@ApiImplicitParam(name = "type", value = "类型 1 = 点赞动态 2 = 点赞评论", required = true)
|
})
|
public ResultUtil Like(Integer id,Integer type,Integer findCommentId) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
// 点赞之后要加入一条消息
|
Message message = new Message();
|
message.setType(2);
|
message.setFindId(id);
|
message.setFindCommentId(findCommentId);
|
message.setReplayUserId(appUser.getId());
|
message.setInsertTime(new Date());
|
switch (type){
|
case 1:
|
// 点赞动态
|
Find find = findService.selectById(id);
|
int i = find.getLikeCount() + 1;
|
find.setLikeCount(i);
|
findService.updateById(find);
|
// 判断用户有没有点赞这条记录
|
Like like = likeService.selectOne(new EntityWrapper<Like>()
|
.eq("type", type)
|
.eq("findId", findCommentId));
|
if (like!=null){
|
// 说明点过赞了 取消掉 同时减少这个的
|
likeService.deleteById(like.getId());
|
Integer likeCount = find.getLikeCount();
|
find.setLikeCount(likeCount-1);
|
break;
|
}
|
message.setUserId(find.getUserId());
|
message.setTitle("赞了你的动态");
|
message.setContent(find.getTitle());
|
// 判断有没有重复消息 如果有就不发了
|
Message message1 = messageService.selectOne(new EntityWrapper<Message>()
|
.eq("userId", appUser.getId())
|
.eq("findId", find.getId())
|
.isNull("findCommentId"));
|
if (message1 == null){
|
messageService.insert(message);
|
}
|
// 新增用户点赞记录
|
Like like1 = new Like();
|
like1.setUserId(appUser.getId());
|
like1.setType(type);
|
like1.setFindId(find.getId());
|
likeService.insert(like1);
|
break;
|
case 2:
|
message.setTitle("赞了你的评论");
|
FindComment findComment = findCommentService.selectById(findCommentId);
|
message.setContent(findComment.getContent());
|
message.setUserId(findComment.getUserId());
|
int i1 = findComment.getLikeCount() + 1;
|
findComment.setLikeCount(i1);
|
message.setContent(findComment.getContent());
|
findCommentService.updateById(findComment);
|
// 判断有没有重复消息 如果有就不发了
|
Message message2 = messageService.selectOne(new EntityWrapper<Message>()
|
.eq("userId", appUser.getId())
|
.eq("type",3)
|
.eq("findCommentId", findComment.getId())
|
);
|
if (message2 == null){
|
messageService.insert(message);
|
}
|
Like like2 = new Like();
|
like2.setUserId(appUser.getId());
|
like2.setType(type);
|
like2.setFindId(findComment.getId());
|
likeService.insert(like2);
|
break;
|
}
|
return ResultUtil.success("点赞成功");
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/find/report")
|
@ApiOperation(value = "动态/评论举报", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "id", value = "动态id/评论id", required = true),
|
@ApiImplicitParam(name = "content", value = "举报内容"),
|
@ApiImplicitParam(name = "type", value = "类型 1 = 举报动态 2 = 举报评论", required = true)
|
})
|
public ResultUtil report(Integer id,String content,Integer type) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
AuditVO content1 = auditUtil.content(content);
|
switch (content1.getType()){
|
case "terrorism":
|
return ResultUtil.error("举报内容涉及暴恐");
|
case "porn":
|
return ResultUtil.error("举报内容涉及色情");
|
case "ban":
|
return ResultUtil.error("举报内容违禁");
|
case "abuse":
|
return ResultUtil.error("举报内容涉及辱骂");
|
case "ad":
|
return ResultUtil.error("举报内容涉及广告");
|
case "politics":
|
return ResultUtil.error("举报内容涉及政治");
|
}
|
FindReport findReport = new FindReport();
|
|
switch (type){
|
case 1:
|
findReport.setReported(findService.selectById(id).getUserId());
|
findReport.setUserId(appUserService.getAppUser().getId());
|
findReport.setFindId(id);
|
break;
|
case 2:
|
FindComment findComment = findCommentService.selectById(id);
|
findReport.setReported(findCommentService.selectById(id).getUserId());
|
findReport.setUserId(appUserService.getAppUser().getId());
|
findReport.setCommentId(id);
|
findReport.setFindId(findComment.getFindId());
|
|
break;
|
}
|
findReport.setInsertTime(new Date());
|
findReport.setContent(content);
|
reportService.insert(findReport);
|
return ResultUtil.success("举报成功");
|
}
|
|
@Autowired
|
private IUserBlackService userBlackService;
|
@ResponseBody
|
@PostMapping("/base/find/findList")
|
@ApiOperation(value = "主页", tags = {"发现"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
|
})
|
public ResultUtil<List<FindVO>> findList(FindQuery query) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
EntityWrapper<Find> wrapper = new EntityWrapper<>();
|
if (StringUtils.hasLength(query.getUserNameOrTitle())){
|
wrapper.like("title",query.getUserNameOrTitle());
|
}
|
List<FindVO> result = findService.findList(query.getUserNameOrTitle());
|
List<FindVO> res = new ArrayList<>();
|
|
// 被拉黑用户ids
|
List<Integer> collect = userBlackService.selectList(new EntityWrapper<UserBlack>()
|
.eq("userId", appUser.getId())).stream().map(UserBlack::getBlackUserId).collect(Collectors.toList());
|
// todo 2.0新增 被拉黑不查看双方动态
|
for (FindVO find : result) {
|
// 如果用户拉黑了 那么不展示该条动态
|
if (collect.size()>0){
|
if (collect.contains(find.getUserId())){
|
// 如果当前动态的发布用户id 是登录用户的黑名单 那过滤掉该条动态
|
continue;
|
}
|
}
|
FindVO temp = new FindVO();
|
BeanUtils.copyProperties(find,temp);
|
Like like = likeService.selectOne(new EntityWrapper<Like>()
|
.eq("userId", appUserService.getAppUser().getId())
|
.eq("type", 1)
|
.eq("findId", find.getId()));
|
if (like == null){
|
// 没有点赞
|
find.setIsLike(0);
|
}else{
|
find.setIsLike(1);
|
}
|
// 计算每个动态的评论数量
|
int size = findCommentService.selectList(new EntityWrapper<FindComment>()
|
.eq("findId", find.getId())
|
.eq("isShow", 1)).size();
|
find.setComment(size);
|
res.add(find);
|
}
|
List<FindVO> testing = testing(res.size(), query.getPageNum(), query.getPageSize(), res);
|
return ResultUtil.success(testing);
|
}
|
public static List<FindVO> testing(long total, long current, long size, List<FindVO> str){
|
List<FindVO> result = new ArrayList<>();
|
//获取初始化分页结构
|
com.stylefeng.guns.modular.system.util.Page<FindVO> page = new Page().getPage(total, size, current - 1);
|
//获取集合下标初始值
|
long startIndex = page.getStartIndex();
|
//获取集合下标结束值
|
long endInddex = 0;
|
if(startIndex + page.getCurrent() >= total || size > total){
|
endInddex = total;
|
}else {
|
endInddex = Math.min(startIndex + page.getSize(), total);
|
}
|
//如果输入的开始查询下标大于集合大小,则查询为空值
|
if(startIndex > total){
|
result = Collections.emptyList();
|
}else{
|
result = str.subList((int)startIndex,(int)endInddex);
|
}
|
return result;
|
}
|
|
}
|