This commit is contained in:
张良(004796)
2024-02-21 14:11:43 +08:00
parent 61d00af5c6
commit c6efe0eb0b
6 changed files with 42 additions and 5 deletions

View File

@@ -16,6 +16,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
@RestController
@@ -32,9 +34,33 @@ public class UserDynamicAppController {
public R<List<DynamicListVo>> page(PageQuery pageQuery, DynamicQuery query){
query.setCurrentUserId(LoginHelper.getUserId());
Page<DynamicListVo> resp = dynamicService.pageApp(pageQuery,query);
resp.getRecords().forEach(i -> {
i.setTimeDiffText(diffTime(i.getCreateTime()));
});
return R.ok(resp.getRecords());
}
private String diffTime(LocalDateTime time){
Duration duration = Duration.between(time, LocalDateTime.now());
long seconds = duration.getSeconds();
long absSeconds = Math.abs(seconds);
long days = absSeconds / (60 * 60 * 24);
long hours = (absSeconds % (60 * 60 * 24)) / (60 * 60);
long minutes = (absSeconds % (60 * 60)) / 60;
long secs = absSeconds % 60;
if(days > 0){
return "1天前";
}
if(hours > 0){
return hours+"小时前";
}
if(minutes > 0){
return minutes+"分钟前";
}
return (secs == 0 ? 1 : secs) + "秒前";
}
@PostMapping("/push")
@Operation(summary = "发布动态")
@Log(title = "发布动态", businessType = BusinessType.OTHER, isSaveDb = true)

View File

@@ -21,6 +21,8 @@ public class DynamicListVo extends DynamicVo{
private String avatar;
@Schema(description = "昵称")
private String nickname;
@Schema(description = "时间差值文字显示")
private String timeDiffText;
@Schema(description = "是否关注用户")
private boolean star;
}

View File

@@ -14,6 +14,9 @@ public class UserMinInfoVo {
private Integer isAnchor;
@Schema(description = "蜜瓜号")
private String usercode;
@Schema(description = "性别")
private Integer gender;
@Schema(description = "昵称")
private String nickname;
@Schema(description = "头像")

View File

@@ -33,10 +33,15 @@ public class UserBlacklistServiceImpl extends ServiceImpl<UserBlacklistMapper, U
throw new ServiceException("不能对自己操作哦");
}
if(actionType == 1){ // 拉黑
UserBlacklist userBlacklist = new UserBlacklist();
userBlacklist.setUserId(userId);
userBlacklist.setBlackUid(blackUserId);
this.save(userBlacklist);
UserBlacklist one = this.getOne(Wrappers.lambdaQuery(UserBlacklist.class)
.eq(UserBlacklist::getUserId, userId)
.eq(UserBlacklist::getBlackUid, blackUserId));
if(one == null){
UserBlacklist userBlacklist = new UserBlacklist();
userBlacklist.setUserId(userId);
userBlacklist.setBlackUid(blackUserId);
this.save(userBlacklist);
}
}else { // 取消拉黑
this.remove(Wrappers.lambdaQuery(UserBlacklist.class)
.eq(UserBlacklist::getUserId,userId)

View File

@@ -393,6 +393,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
vo.setIsAnchor(user.getIsAnchor());
vo.setUsercode(user.getUsercode());
vo.setNickname(user.getNickname());
vo.setGender(user.getGender());
vo.setAvatar(user.getAvatar());
vo.setAge(user.getAge());
vo.setCity(user.getCity());

View File

@@ -13,7 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.user.UserListVo">
select t2.id as user_id,t2.avatar,t2.gender,t2.city_id,t2.city,t2.nickname,t2.usercode,t2.age
from cai_user_blacklist t1
join cai_user t2 on t1.user_id = t2.id
join cai_user t2 on t1.black_uid = t2.id
where t1.user_id = #{userId}
</select>