添加头像
This commit is contained in:
@@ -59,4 +59,6 @@ public class CommonConstant {
|
|||||||
|
|
||||||
public static final List<String> IS_SUBSCRIBE = Arrays.asList("yes", "no");
|
public static final List<String> IS_SUBSCRIBE = Arrays.asList("yes", "no");
|
||||||
|
|
||||||
|
public static final String DEFAULT_AVATAR = "aida-users/87/avatar/default.jpg";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.ai.da.controller;
|
package com.ai.da.controller;
|
||||||
|
|
||||||
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
import com.ai.da.common.response.PageBaseResponse;
|
import com.ai.da.common.response.PageBaseResponse;
|
||||||
import com.ai.da.common.response.Response;
|
import com.ai.da.common.response.Response;
|
||||||
import com.ai.da.mapper.primary.entity.Account;
|
|
||||||
import com.ai.da.mapper.primary.entity.TrialOrder;
|
import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||||
import com.ai.da.model.dto.*;
|
import com.ai.da.model.dto.*;
|
||||||
import com.ai.da.model.vo.AccountLoginVO;
|
import com.ai.da.model.vo.AccountLoginVO;
|
||||||
@@ -12,7 +12,9 @@ import io.swagger.annotations.Api;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -194,4 +196,14 @@ public class AccountController {
|
|||||||
public Response<List<Long>> setUserValidToDayEnd(){
|
public Response<List<Long>> setUserValidToDayEnd(){
|
||||||
return Response.success(accountService.setUserValidToDayEnd());
|
return Response.success(accountService.setUserValidToDayEnd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 用户上传头像
|
||||||
|
@ApiOperation(value = "上传头像")
|
||||||
|
@PostMapping(path = "/uploadAvatar"/*, consumes = MediaType.MULTIPART_FORM_DATA_VALUE*/)
|
||||||
|
public Response<String> uploadAvatar(@RequestParam("file") MultipartFile file) {
|
||||||
|
if (null == file || StringUtils.isEmpty(file.getOriginalFilename())) {
|
||||||
|
throw new BusinessException("file.cannot.be.empty");
|
||||||
|
}
|
||||||
|
return Response.success(accountService.uploadAvatar(file));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,10 @@ public class AccountLoginVO {
|
|||||||
|
|
||||||
private Integer systemUser;
|
private Integer systemUser;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
private Long followeeCount;
|
||||||
|
|
||||||
|
private Long followerCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,4 +14,6 @@ public class NotificationVO extends Notification {
|
|||||||
|
|
||||||
private String portfolioName;
|
private String portfolioName;
|
||||||
|
|
||||||
|
private String senderAvatar;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,4 +30,6 @@ public class PortfolioVO extends Portfolio {
|
|||||||
private Integer jumpable;
|
private Integer jumpable;
|
||||||
|
|
||||||
private Integer isFollow;
|
private Integer isFollow;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.ai.da.model.vo.AccountLoginVO;
|
|||||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -157,4 +158,6 @@ public interface AccountService extends IService<Account> {
|
|||||||
|
|
||||||
IPage<Account> getPageByIds(List<Long> ids, int pageNum, int size);
|
IPage<Account> getPageByIds(List<Long> ids, int pageNum, int size);
|
||||||
List<Account> getByIds(List<Long> ids);
|
List<Account> getByIds(List<Long> ids);
|
||||||
|
|
||||||
|
String uploadAvatar(MultipartFile file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,11 @@ public interface PortfolioService extends IService<Portfolio> {
|
|||||||
|
|
||||||
void cancelFollow(Long followeeId);
|
void cancelFollow(Long followeeId);
|
||||||
|
|
||||||
|
Long getFolloweeCount();
|
||||||
|
|
||||||
List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo);
|
List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo);
|
||||||
|
|
||||||
|
Long getFollowerCount();
|
||||||
|
|
||||||
List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo);
|
List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.ai.da.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.ai.da.common.config.exception.BusinessException;
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
|
import com.ai.da.common.constant.CommonConstant;
|
||||||
import com.ai.da.common.context.UserContext;
|
import com.ai.da.common.context.UserContext;
|
||||||
import com.ai.da.common.enums.AuthenticationOperationTypeEnum;
|
import com.ai.da.common.enums.AuthenticationOperationTypeEnum;
|
||||||
import com.ai.da.common.enums.CreditsEventsEnum;
|
import com.ai.da.common.enums.CreditsEventsEnum;
|
||||||
@@ -32,9 +33,11 @@ import com.zaxxer.hikari.HikariDataSource;
|
|||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -83,6 +86,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
@Resource
|
@Resource
|
||||||
private CreditsService creditsService;
|
private CreditsService creditsService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MinioUtil minioUtil;
|
||||||
|
@Value("${minio.bucketName.users}")
|
||||||
|
private String userBucket;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
||||||
@@ -137,6 +145,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
return new AccountPreLoginVO(account.getId());
|
return new AccountPreLoginVO(account.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PortfolioService portfolioService;
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request) {
|
public AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request) {
|
||||||
@@ -189,6 +200,16 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
}
|
}
|
||||||
response.setUserId(account.getId());
|
response.setUserId(account.getId());
|
||||||
response.setSystemUser(account.getSystemUser());
|
response.setSystemUser(account.getSystemUser());
|
||||||
|
// 设置头像
|
||||||
|
String avatar;
|
||||||
|
if (StringUtil.isNullOrEmpty(account.getAvatar())){
|
||||||
|
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||||
|
}else {
|
||||||
|
avatar = account.getAvatar();
|
||||||
|
}
|
||||||
|
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||||
|
response.setFolloweeCount(portfolioService.getFolloweeCount());
|
||||||
|
response.setFollowerCount(portfolioService.getFollowerCount());
|
||||||
//判断是否常用ip 不是则发邮件提示
|
//判断是否常用ip 不是则发邮件提示
|
||||||
calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
|
calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
|
||||||
return response;
|
return response;
|
||||||
@@ -1421,7 +1442,23 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
return baseMapper.selectList(queryWrapper);
|
return baseMapper.selectList(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String uploadAvatar(MultipartFile file){
|
||||||
|
Long accountId = UserContext.getUserHolder().getId();
|
||||||
|
// 1、上传图片到minio
|
||||||
|
String avatarPath = minioUtil.upload(userBucket, accountId.toString() + "/avatar", file);
|
||||||
|
// 2、查询该用户之前的头像
|
||||||
|
String avatar = baseMapper.selectById(accountId).getAvatar();
|
||||||
|
if (!StringUtil.isNullOrEmpty(avatar) && !avatar.equals(CommonConstant.DEFAULT_AVATAR)){
|
||||||
|
minioUtil.deleteObject(avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3、替换新的头像
|
||||||
|
Account account = new Account();
|
||||||
|
account.setId(accountId);
|
||||||
|
account.setAvatar(avatarPath);
|
||||||
|
baseMapper.updateById(account);
|
||||||
|
|
||||||
|
return minioUtil.getPreSignedUrl(avatarPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.mysql.cj.util.StringUtils;
|
import com.mysql.cj.util.StringUtils;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -80,9 +81,9 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
|
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
|
||||||
IPage<NotificationVO> convert = notificationPage.convert(o -> {
|
IPage<NotificationVO> convert = notificationPage.convert(o -> {
|
||||||
NotificationVO notificationVO = CopyUtil.copyObject(o, NotificationVO.class);
|
NotificationVO notificationVO = CopyUtil.copyObject(o, NotificationVO.class);
|
||||||
Account account = accountService.getById(notificationVO.getSenderId());
|
Account senderAccount = accountService.getById(notificationVO.getSenderId());
|
||||||
notificationVO.setSenderUserName(account.getUserName());
|
notificationVO.setSenderUserName(senderAccount.getUserName());
|
||||||
notificationVO.setSenderUserAvatar(StringUtils.isNullOrEmpty(account.getAvatar()) ? null : minioUtil.getPreSignedUrl(account.getAvatar(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
notificationVO.setSenderUserAvatar(StringUtils.isNullOrEmpty(senderAccount.getAvatar()) ? null : minioUtil.getPreSignedUrl(senderAccount.getAvatar(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||||
notificationVO.setPortfolioName(Objects.isNull(notificationVO.getPortfolioId()) ? null : portfolioService.getById(notificationVO.getPortfolioId()).getPortfolioName());
|
notificationVO.setPortfolioName(Objects.isNull(notificationVO.getPortfolioId()) ? null : portfolioService.getById(notificationVO.getPortfolioId()).getPortfolioName());
|
||||||
// 设置单个人 系统消息是否已读
|
// 设置单个人 系统消息是否已读
|
||||||
if (notificationVO.getType().equals("system")){
|
if (notificationVO.getType().equals("system")){
|
||||||
@@ -91,6 +92,9 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
}else {
|
}else {
|
||||||
notificationVO.setIsRead(1);
|
notificationVO.setIsRead(1);
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
|
String avatar = StringUtil.isNullOrEmpty(senderAccount.getAvatar()) ? CommonConstant.DEFAULT_AVATAR : senderAccount.getAvatar();
|
||||||
|
notificationVO.setSenderAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||||
}
|
}
|
||||||
return notificationVO;
|
return notificationVO;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ai.da.service.impl;
|
package com.ai.da.service.impl;
|
||||||
|
|
||||||
import com.ai.da.common.config.exception.BusinessException;
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
|
import com.ai.da.common.constant.CommonConstant;
|
||||||
import com.ai.da.common.context.UserContext;
|
import com.ai.da.common.context.UserContext;
|
||||||
import com.ai.da.common.response.PageBaseResponse;
|
import com.ai.da.common.response.PageBaseResponse;
|
||||||
import com.ai.da.common.utils.CopyUtil;
|
import com.ai.da.common.utils.CopyUtil;
|
||||||
@@ -20,6 +21,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@@ -481,9 +483,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
Canvas canvas = canvasMapper.selectById(vo.getCanvasId());
|
Canvas canvas = canvasMapper.selectById(vo.getCanvasId());
|
||||||
vo.setCanvasUrl(minioUtil.getPreSignedUrl(canvas.getUrl(), 24 * 60));
|
vo.setCanvasUrl(minioUtil.getPreSignedUrl(canvas.getUrl(), 24 * 60));
|
||||||
vo.setLikeNum(redisUtil.getLikeCount(vo.getId()));
|
vo.setLikeNum(redisUtil.getLikeCount(vo.getId()));
|
||||||
|
String avatar;
|
||||||
|
Account account = accountMapper.selectById(vo.getAccountId());
|
||||||
if (userHolder == null) {
|
if (userHolder == null) {
|
||||||
vo.setIsLike(0);
|
vo.setIsLike(0);
|
||||||
vo.setIsFollow(0);
|
vo.setIsFollow(0);
|
||||||
|
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||||
} else {
|
} else {
|
||||||
boolean postLikedByUser = redisUtil.isPostLikedByUser(portfolioDTO.getId(), userHolder.getId());
|
boolean postLikedByUser = redisUtil.isPostLikedByUser(portfolioDTO.getId(), userHolder.getId());
|
||||||
if (postLikedByUser) {
|
if (postLikedByUser) {
|
||||||
@@ -500,10 +505,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
}else {
|
}else {
|
||||||
vo.setIsFollow(1);
|
vo.setIsFollow(1);
|
||||||
}
|
}
|
||||||
|
avatar = StringUtil.isNullOrEmpty(account.getAvatar()) ? CommonConstant.DEFAULT_AVATAR : account.getAvatar();
|
||||||
}
|
}
|
||||||
|
vo.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||||
redisUtil.increaseViewCount(portfolioDTO.getId());
|
redisUtil.increaseViewCount(portfolioDTO.getId());
|
||||||
vo.setViewNums(redisUtil.getViewCount(portfolioDTO.getId()));
|
vo.setViewNums(redisUtil.getViewCount(portfolioDTO.getId()));
|
||||||
vo.setUserName(accountMapper.selectById(vo.getAccountId()).getUserName());
|
vo.setUserName(account.getUserName());
|
||||||
if (vo.getOriginal() == 0) {
|
if (vo.getOriginal() == 0) {
|
||||||
vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName());
|
vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName());
|
||||||
Portfolio byId = portfolioMapper.getByIdAll(vo.getOriginalPortfolioId());
|
Portfolio byId = portfolioMapper.getByIdAll(vo.getOriginalPortfolioId());
|
||||||
@@ -997,6 +1004,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getFolloweeCount(){
|
||||||
|
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("follower_id", UserContext.getUserHolder().getId()).select("followee_id");
|
||||||
|
return userFollowMapper.selectCount(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取某个用户的关注列表
|
// 获取某个用户的关注列表
|
||||||
public List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo){
|
public List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo){
|
||||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||||
@@ -1010,6 +1023,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getFollowerCount(){
|
||||||
|
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("followee_id", UserContext.getUserHolder().getId()).select("follower_id");
|
||||||
|
return userFollowMapper.selectCount(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取某个用户的粉丝列表
|
// 获取某个用户的粉丝列表
|
||||||
public List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo){
|
public List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo){
|
||||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
FROM `t_notification`
|
FROM `t_notification`
|
||||||
WHERE receiver_id = #{receiverId}
|
WHERE receiver_id = #{receiverId}
|
||||||
AND is_read = 0
|
AND is_read = 0
|
||||||
|
AND is_deleted = 0
|
||||||
GROUP BY type
|
GROUP BY type
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user