feat(content): Implement content module foundation
This commit is contained in:
@@ -29,6 +29,7 @@ public class SecurityConfig {
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers(
|
||||
"/user/profile/public/**",
|
||||
"/user/profile/count/**",
|
||||
"/user/profile/init",
|
||||
"/actuator/**",
|
||||
"/error"
|
||||
|
||||
@@ -122,6 +122,59 @@ public class UserProfileController {
|
||||
return userInfoService.searchUsers(pageParam, keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户视频数量
|
||||
*/
|
||||
@PostMapping("/count/video/{userId}/{count}")
|
||||
public Result<Void> increaseVideoCount(
|
||||
@PathVariable Long userId,
|
||||
@PathVariable Integer count,
|
||||
HttpServletRequest request) {
|
||||
// 验证权限(实际可以通过更复杂的权限验证)
|
||||
Long currentUserId = getUserIdFromRequest(request);
|
||||
if (currentUserId == null) {
|
||||
return Result.error("未登录");
|
||||
}
|
||||
|
||||
// 调用service增加用户视频数量
|
||||
return userInfoService.increaseVideoCount(userId, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户获赞数量
|
||||
*/
|
||||
@PostMapping("/count/like/{userId}/{count}")
|
||||
public Result<Void> increaseLikeCount(
|
||||
@PathVariable Long userId,
|
||||
@PathVariable Integer count,
|
||||
HttpServletRequest request) {
|
||||
// 验证权限
|
||||
Long currentUserId = getUserIdFromRequest(request);
|
||||
if (currentUserId == null) {
|
||||
return Result.error("未登录");
|
||||
}
|
||||
|
||||
// 调用service增加用户获赞数量
|
||||
return userInfoService.increaseLikeCount(userId, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户收藏数量
|
||||
*/
|
||||
@PostMapping("/count/favorite/{userId}/{count}")
|
||||
public Result<Void> increaseFavoriteCount(
|
||||
@PathVariable Long userId,
|
||||
@PathVariable Integer count,
|
||||
HttpServletRequest request) {
|
||||
// 验证权限
|
||||
Long currentUserId = getUserIdFromRequest(request);
|
||||
if (currentUserId == null) {
|
||||
return Result.error("未登录");
|
||||
}
|
||||
|
||||
// 调用service增加用户收藏数量
|
||||
return userInfoService.increaseFavoriteCount(userId, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从请求中获取用户名
|
||||
|
||||
@@ -65,4 +65,31 @@ public interface UserInfoService extends IService<UserInfo> {
|
||||
* @return 用户列表
|
||||
*/
|
||||
Result<Page<UserInfo>> searchUsers(Page<UserInfo> page, String keyword);
|
||||
|
||||
/**
|
||||
* 增加用户视频数量
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param count 增加数量
|
||||
* @return 结果
|
||||
*/
|
||||
Result<Void> increaseVideoCount(Long userId, Integer count);
|
||||
|
||||
/**
|
||||
* 增加用户获赞数量
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param count 增加数量
|
||||
* @return 结果
|
||||
*/
|
||||
Result<Void> increaseLikeCount(Long userId, Integer count);
|
||||
|
||||
/**
|
||||
* 增加用户收藏数量
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param count 增加数量
|
||||
* @return 结果
|
||||
*/
|
||||
Result<Void> increaseFavoriteCount(Long userId, Integer count);
|
||||
}
|
||||
@@ -8,8 +8,10 @@ import com.nuaa.video.common.model.vo.Result;
|
||||
import com.nuaa.video.common.utils.MinioUtils;
|
||||
import com.nuaa.video.user.dto.UserProfileDTO;
|
||||
import com.nuaa.video.user.entity.UserInfo;
|
||||
import com.nuaa.video.user.entity.UserStatDaily;
|
||||
import com.nuaa.video.user.mapper.UserFollowMapper;
|
||||
import com.nuaa.video.user.mapper.UserInfoMapper;
|
||||
import com.nuaa.video.user.mapper.UserStatDailyMapper;
|
||||
import com.nuaa.video.user.service.UserInfoService;
|
||||
import com.nuaa.video.user.service.UserSettingService;
|
||||
import com.nuaa.video.user.vo.UserProfileVO;
|
||||
@@ -20,6 +22,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -34,6 +37,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
|
||||
private final UserFollowMapper userFollowMapper;
|
||||
private final UserSettingService userSettingService;
|
||||
private final MinioUtils minioUtils;
|
||||
private final UserStatDailyMapper userStatDailyMapper;
|
||||
|
||||
@Override
|
||||
public Result<UserProfileVO> getUserProfile(Long userId, Long currentUserId) {
|
||||
@@ -186,4 +190,119 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
|
||||
|
||||
return Result.success(resultPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<Void> increaseVideoCount(Long userId, Integer count) {
|
||||
// 验证用户是否存在
|
||||
UserInfo userInfo = getById(userId);
|
||||
if (userInfo == null) {
|
||||
return Result.error(ResultCode.USER_NOT_FOUND.getCode(),ResultCode.USER_NOT_FOUND.getMessage());
|
||||
}
|
||||
|
||||
// 更新视频数量
|
||||
userInfo.setVideoCount(userInfo.getVideoCount() + count);
|
||||
userInfo.setUpdateTime(LocalDateTime.now());
|
||||
updateById(userInfo);
|
||||
|
||||
// 更新每日统计
|
||||
updateUserStatDaily(userId, "video", count);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<Void> increaseLikeCount(Long userId, Integer count) {
|
||||
// 验证用户是否存在
|
||||
UserInfo userInfo = getById(userId);
|
||||
if (userInfo == null) {
|
||||
return Result.error(ResultCode.USER_NOT_FOUND.getCode(),ResultCode.USER_NOT_FOUND.getMessage());
|
||||
}
|
||||
|
||||
// 更新获赞数量
|
||||
userInfo.setLikeCount(userInfo.getLikeCount() + count);
|
||||
userInfo.setUpdateTime(LocalDateTime.now());
|
||||
updateById(userInfo);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<Void> increaseFavoriteCount(Long userId, Integer count) {
|
||||
// 验证用户是否存在
|
||||
UserInfo userInfo = getById(userId);
|
||||
if (userInfo == null) {
|
||||
return Result.error(ResultCode.USER_NOT_FOUND.getCode(),ResultCode.USER_NOT_FOUND.getMessage());
|
||||
}
|
||||
|
||||
// 更新收藏数量
|
||||
userInfo.setFavoriteCount(userInfo.getFavoriteCount() + count);
|
||||
userInfo.setUpdateTime(LocalDateTime.now());
|
||||
updateById(userInfo);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户每日统计数据
|
||||
*/
|
||||
private void updateUserStatDaily(Long userId, String statType, int count) {
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
// 查询今日统计记录
|
||||
UserStatDaily statDaily = userStatDailyMapper.selectOne(
|
||||
new LambdaQueryWrapper<UserStatDaily>()
|
||||
.eq(UserStatDaily::getUserId, userId)
|
||||
.eq(UserStatDaily::getStatDate, today)
|
||||
);
|
||||
|
||||
// 如果不存在,创建新记录
|
||||
if (statDaily == null) {
|
||||
statDaily = new UserStatDaily();
|
||||
statDaily.setUserId(userId);
|
||||
statDaily.setStatDate(today);
|
||||
statDaily.setFollowerIncrement(0);
|
||||
statDaily.setFollowingIncrement(0);
|
||||
statDaily.setVideoIncrement(0);
|
||||
statDaily.setLikeIncrement(0);
|
||||
statDaily.setCoinIncrement(0);
|
||||
statDaily.setFavoriteIncrement(0);
|
||||
statDaily.setViewIncrement(0L);
|
||||
statDaily.setCreateTime(LocalDateTime.now());
|
||||
}
|
||||
|
||||
// 根据统计类型更新数据
|
||||
switch (statType) {
|
||||
case "video":
|
||||
statDaily.setVideoIncrement(statDaily.getVideoIncrement() + count);
|
||||
break;
|
||||
case "like":
|
||||
statDaily.setLikeIncrement(statDaily.getLikeIncrement() + count);
|
||||
break;
|
||||
case "follower":
|
||||
statDaily.setFollowerIncrement(statDaily.getFollowerIncrement() + count);
|
||||
break;
|
||||
case "following":
|
||||
statDaily.setFollowingIncrement(statDaily.getFollowingIncrement() + count);
|
||||
break;
|
||||
case "favorite":
|
||||
statDaily.setFavoriteIncrement(statDaily.getFavoriteIncrement() + count);
|
||||
break;
|
||||
case "coin":
|
||||
statDaily.setCoinIncrement(statDaily.getCoinIncrement() + count);
|
||||
break;
|
||||
case "view":
|
||||
statDaily.setViewIncrement(statDaily.getViewIncrement() + count);
|
||||
break;
|
||||
}
|
||||
|
||||
// 保存更新
|
||||
if (statDaily.getId() == null) {
|
||||
userStatDailyMapper.insert(statDaily);
|
||||
} else {
|
||||
userStatDailyMapper.updateById(statDaily);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user