动态管理

main
王宇航 2024-05-17 16:50:17 +08:00
parent 0d86eedd27
commit 74b195ce48
11 changed files with 154 additions and 27 deletions

View File

@ -13,8 +13,8 @@ spring:
password: 4e14b5378637d9c7 # 数据库密码
# Redis配置
redis:
host: 139.224.213.131 # Redis服务地址
port: 7001 # Redis端口
host: 101.133.172.2 # Redis服务地址
port: 2007 # Redis端口
password: 123456 # Redis密码
database: 4 # 数据库索引

View File

@ -51,4 +51,7 @@ public class AppDongtai implements Serializable {
@ApiModelProperty(value = "引用内容id")
private Integer refId;
@ApiModelProperty(value = "发布用户")
private Integer userId;
}

View File

@ -52,13 +52,13 @@ public class AppDongtaiController {
return AjaxResult.success();
}
@Log(title = "动态编辑")
@PostMapping("/edit")
@ApiOperation(value="动态编辑")
public AjaxResult<Object> edit(@Validated @RequestBody AppDongtaiUpdateValidate updateValidate) {
iAppDongtaiService.edit(updateValidate);
return AjaxResult.success();
}
// @Log(title = "动态编辑")
// @PostMapping("/edit")
// @ApiOperation(value="动态编辑")
// public AjaxResult<Object> edit(@Validated @RequestBody AppDongtaiUpdateValidate updateValidate) {
// iAppDongtaiService.edit(updateValidate);
// return AjaxResult.success();
// }
@Log(title = "动态删除")
@PostMapping("/del")

View File

@ -5,11 +5,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.query.MPJQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mdd.common.entity.AppFriend;
import com.mdd.common.entity.AppUser;
import com.mdd.common.entity.dttag.AppTag;
import com.mdd.common.mapper.AppFriendMapper;
import com.mdd.common.mapper.AppUserMapper;
import com.mdd.common.mapper.dttag.AppTagMapper;
import com.mdd.common.util.StringUtils;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.validate.common.PageValidate;
import com.mdd.front.service.IAppDongtaiService;
import com.mdd.front.validate.AppDongtaiCreateValidate;
@ -24,12 +27,16 @@ import com.mdd.common.mapper.AppDongtaiMapper;
import com.mdd.common.util.ListUtils;
import com.mdd.common.util.TimeUtils;
import com.mdd.common.util.UrlUtils;
import com.mdd.front.vo.AppTagVo;
import com.mdd.front.vo.AppUserListedVo;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
*
@ -49,6 +56,9 @@ public class AppDongtaiServiceImpl implements IAppDongtaiService {
@Resource
AppUserMapper appUserMapper;
@Resource
AppFriendMapper appFriendMapper;
/**
*
*
@ -65,6 +75,20 @@ public class AppDongtaiServiceImpl implements IAppDongtaiService {
QueryWrapper<AppDongtai> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByDesc("id");
//查所有的好友
List<AppFriend> friends = new ArrayList<>();
QueryWrapper<AppFriend> friendWrapper = new QueryWrapper<>();
if (searchValidate.getUserId() != null) {
friendWrapper.eq("user_id", searchValidate.getUserId());
friends = appFriendMapper.selectList(friendWrapper);
}
List<Integer> collect = friends.stream().map(item -> item.getFriendId()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)){
return PageResult.pageHelper(new ArrayList<>());
}
else {
queryWrapper.in("user_id", collect);
}
appDongtaiMapper.setSearch(queryWrapper, searchValidate, new String[]{
"=:content:str",
"=:img:str",
@ -77,11 +101,66 @@ public class AppDongtaiServiceImpl implements IAppDongtaiService {
});
IPage<AppDongtai> iPage = appDongtaiMapper.selectPage(new Page<>(page, limit), queryWrapper);
List<AppUserListedVo> userList = new LinkedList<>();
List<AppTagVo> tagList = new LinkedList<>();
List<AppDongtaiListedVo> list = new LinkedList<>();
for (AppDongtai item : iPage.getRecords()) {
AppDongtaiListedVo vo = new AppDongtaiListedVo();
BeanUtils.copyProperties(item, vo);
// 处理提及用户,多个和单个
if (StringUtils.isNoneBlank(item.getRefUser())) {
if (item.getRefUser().contains(",")) {
List<Integer> userIds = ListUtils.stringToListAsInt(item.getTagId(), ",");
userIds.forEach(id -> {
List<AppUser> appUsers = appUserMapper.selectList(new LambdaQueryWrapper<AppUser>().eq(AppUser::getId, id));
Assert.notEmpty(appUsers, "用户不存在");
boolean b = userList.addAll(appUsers.stream().map(user -> {
AppUserListedVo appUserListedVo = new AppUserListedVo();
BeanUtils.copyProperties(user, appUserListedVo);
appUserListedVo.setCreateTime(TimeUtils.timestampToDate(user.getCreateTime()));
appUserListedVo.setUpdateTime(TimeUtils.timestampToDate(user.getUpdateTime()));
return appUserListedVo;
}).collect(Collectors.toList()));
Assert.isTrue(b, "用户不存在");
});
} else {
AppUser appUsers = appUserMapper.selectById(Integer.parseInt(item.getRefUser()));
Assert.notNull(appUsers, "用户不存在");
AppUserListedVo appUserListedVo = new AppUserListedVo();
BeanUtils.copyProperties(appUsers, appUserListedVo);
appUserListedVo.setCreateTime(TimeUtils.timestampToDate(appUsers.getCreateTime()));
appUserListedVo.setUpdateTime(TimeUtils.timestampToDate(appUsers.getUpdateTime()));
userList.add(appUserListedVo);
}
vo.setUserInfos(userList);
}
if (StringUtils.isNoneBlank(item.getTagId())) {
if (item.getTagId().contains(",")) {
List<Integer> tagIds = ListUtils.stringToListAsInt(item.getTagId(), ",");
tagIds.forEach(id -> {
List<AppTag> tags = appTagMapper.selectList(new LambdaQueryWrapper<AppTag>().eq(AppTag::getId, id));
Assert.notEmpty(tags, "用户不存在");
boolean b = tagList.addAll(tags.stream().map(tag -> {
AppTagVo appTagVo = new AppTagVo();
BeanUtils.copyProperties(tag, appTagVo);
appTagVo.setCreateTime(TimeUtils.timestampToDate(tag.getCreateTime()));
appTagVo.setUpdateTime(TimeUtils.timestampToDate(tag.getUpdateTime()));
return appTagVo;
}).collect(Collectors.toList()));
Assert.isTrue(b, "标签不存在");
});
} else {
AppTag appTags = appTagMapper.selectById(Integer.parseInt(item.getTagId()));
Assert.notNull(appTags, "标签不存在");
AppTagVo appTagVo = new AppTagVo();
BeanUtils.copyProperties(appTags, appTagVo);
appTagVo.setCreateTime(TimeUtils.timestampToDate(appTags.getCreateTime()));
appTagVo.setUpdateTime(TimeUtils.timestampToDate(appTags.getUpdateTime()));
tagList.add(appTagVo);
}
vo.setAppTags(tagList);
}
vo.setImg(UrlUtils.toAbsoluteUrl(item.getImg()));
vo.setCreateTime(TimeUtils.timestampToDate(item.getCreateTime()));
vo.setUpdateTime(TimeUtils.timestampToDate(item.getUpdateTime()));
@ -125,7 +204,7 @@ public class AppDongtaiServiceImpl implements IAppDongtaiService {
Assert.isNull(null, "引用id不能为空");
}
if (StringUtils.isNotEmpty(createValidate.getTagId()) && createValidate.getTagId().contains(",")) {
if (StringUtils.isNoneBlank(createValidate.getTagId()) && createValidate.getTagId().contains(",")) {
List<Integer> tags = ListUtils.stringToListAsInt(createValidate.getTagId(), ",");
tags.forEach(id -> {
AppTag tag = appTagMapper.selectById(id);
@ -138,18 +217,20 @@ public class AppDongtaiServiceImpl implements IAppDongtaiService {
.last("limit 1"));
Assert.notNull(tag, "标签不存在");
}
if (StringUtils.isNotEmpty(createValidate.getRefUser()) && createValidate.getRefUser().contains(",")) {
List<Integer> users = ListUtils.stringToListAsInt(createValidate.getTagId(), ",");
users.forEach(id -> {
AppUser appUser = appUserMapper.selectById(id);
if (StringUtils.isNoneBlank(createValidate.getRefUser())) {
if (createValidate.getRefUser().contains(",")) {
List<Integer> users = ListUtils.stringToListAsInt(createValidate.getTagId(), ",");
users.forEach(id -> {
AppUser appUser = appUserMapper.selectById(id);
Assert.notNull(appUser, "用户不存在");
});
} else {
AppUser appUser = appUserMapper.selectOne(
new QueryWrapper<AppUser>()
.eq("id", createValidate.getRefUser())
.last("limit 1"));
Assert.notNull(appUser, "用户不存在");
});
} else {
AppUser appUser = appUserMapper.selectOne(
new QueryWrapper<AppUser>()
.eq("id", createValidate.getRefUser())
.last("limit 1"));
Assert.notNull(appUser, "用户不存在");
}
}
AppDongtai model = new AppDongtai();
model.setCreateTime(System.currentTimeMillis() / 1000);

View File

@ -37,4 +37,7 @@ public class AppDongtaiCreateValidate implements Serializable {
@ApiModelProperty(value = "引用内容id")
private Integer refId;
@ApiModelProperty(value = "发布用户")
private Integer userId;
}

View File

@ -35,4 +35,7 @@ public class AppDongtaiSearchValidate implements Serializable {
@ApiModelProperty(value = "引用内容id")
private Integer refId;
@ApiModelProperty(value = "发布用户")
private Integer userId;
}

View File

@ -53,4 +53,7 @@ public class AppDongtaiUpdateValidate implements Serializable {
@ApiModelProperty(value = "引用内容id")
private Integer refId;
@ApiModelProperty(value = "发布用户")
private Integer userId;
}

View File

@ -20,19 +20,15 @@ public class RegisterValidate implements Serializable {
@NotBlank(message = "用户名不能为空")
@ApiModelProperty(value = "用户名", required = true)
private String username;
@NotBlank(message = "头像不能为空")
@ApiModelProperty(value = "头像", required = true)
private String avatar;
@NotBlank(message = "手机号不能为空")
@ApiModelProperty(value = "手机号", required = true)
private String mobile;
@NotNull(message = "性别不能为空")
@ApiModelProperty(value = "性别1男2女", required = true)
private Integer sex;
@ApiModelProperty(value = "地址")
private String address;

View File

@ -39,5 +39,8 @@ public class AppDongtaiDetailVo implements Serializable {
@ApiModelProperty(value = "引用内容id")
private Integer refId;
@ApiModelProperty(value = "发布用户")
private Integer userId;
}

View File

@ -44,9 +44,12 @@ public class AppDongtaiListedVo implements Serializable {
@ApiModelProperty(value = "引用内容id")
private Integer refId;
@ApiModelProperty(value = "发布用户")
private Integer userId;
private List<AppUserListedVo> userInfos;
private List<AppTag> appTags;
private List<AppTagVo> appTags;
}

View File

@ -0,0 +1,32 @@
package com.mdd.front.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.mdd.common.entity.dttag.AppTag;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class AppTagVo {
private static final long serialVersionUID = 1L;
@TableId(value="id", type= IdType.AUTO)
@ApiModelProperty(value = "主键")
private Integer id;
@ApiModelProperty(value = "创建时间")
private String createTime;
@ApiModelProperty(value = "更新时间")
private String updateTime;
@ApiModelProperty(value = "标签名称")
private String name;
@ApiModelProperty(value = "父级id顶级为0")
private Integer parentId;
@ApiModelProperty(value = "标签类型1分类2标签")
private Integer type;
}