添加头像
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 String DEFAULT_AVATAR = "aida-users/87/avatar/default.jpg";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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.Response;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
@@ -12,7 +12,9 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -194,4 +196,14 @@ public class AccountController {
|
||||
public Response<List<Long>> 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 String avatar;
|
||||
|
||||
private Long followeeCount;
|
||||
|
||||
private Long followerCount;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ public class NotificationVO extends Notification {
|
||||
|
||||
private String portfolioName;
|
||||
|
||||
private String senderAvatar;
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,6 @@ public class PortfolioVO extends Portfolio {
|
||||
private Integer jumpable;
|
||||
|
||||
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.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
@@ -157,4 +158,6 @@ public interface AccountService extends IService<Account> {
|
||||
|
||||
IPage<Account> getPageByIds(List<Long> ids, int pageNum, int size);
|
||||
List<Account> getByIds(List<Long> ids);
|
||||
|
||||
String uploadAvatar(MultipartFile file);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,11 @@ public interface PortfolioService extends IService<Portfolio> {
|
||||
|
||||
void cancelFollow(Long followeeId);
|
||||
|
||||
Long getFolloweeCount();
|
||||
|
||||
List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo);
|
||||
|
||||
Long getFollowerCount();
|
||||
|
||||
List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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.enums.AuthenticationOperationTypeEnum;
|
||||
import com.ai.da.common.enums.CreditsEventsEnum;
|
||||
@@ -32,9 +33,11 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -83,6 +86,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
@Resource
|
||||
private CreditsService creditsService;
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
@Value("${minio.bucketName.users}")
|
||||
private String userBucket;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
||||
@@ -137,6 +145,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
return new AccountPreLoginVO(account.getId());
|
||||
}
|
||||
|
||||
@Resource
|
||||
private PortfolioService portfolioService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request) {
|
||||
@@ -189,6 +200,16 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
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 不是则发邮件提示
|
||||
calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
|
||||
return response;
|
||||
@@ -1421,7 +1442,23 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
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.google.gson.Gson;
|
||||
import com.mysql.cj.util.StringUtils;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -80,9 +81,9 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
|
||||
IPage<NotificationVO> convert = notificationPage.convert(o -> {
|
||||
NotificationVO notificationVO = CopyUtil.copyObject(o, NotificationVO.class);
|
||||
Account account = accountService.getById(notificationVO.getSenderId());
|
||||
notificationVO.setSenderUserName(account.getUserName());
|
||||
notificationVO.setSenderUserAvatar(StringUtils.isNullOrEmpty(account.getAvatar()) ? null : minioUtil.getPreSignedUrl(account.getAvatar(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
Account senderAccount = accountService.getById(notificationVO.getSenderId());
|
||||
notificationVO.setSenderUserName(senderAccount.getUserName());
|
||||
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());
|
||||
// 设置单个人 系统消息是否已读
|
||||
if (notificationVO.getType().equals("system")){
|
||||
@@ -91,6 +92,9 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
}else {
|
||||
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;
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
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.response.PageBaseResponse;
|
||||
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.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Function;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -481,9 +483,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
Canvas canvas = canvasMapper.selectById(vo.getCanvasId());
|
||||
vo.setCanvasUrl(minioUtil.getPreSignedUrl(canvas.getUrl(), 24 * 60));
|
||||
vo.setLikeNum(redisUtil.getLikeCount(vo.getId()));
|
||||
String avatar;
|
||||
Account account = accountMapper.selectById(vo.getAccountId());
|
||||
if (userHolder == null) {
|
||||
vo.setIsLike(0);
|
||||
vo.setIsFollow(0);
|
||||
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||
} else {
|
||||
boolean postLikedByUser = redisUtil.isPostLikedByUser(portfolioDTO.getId(), userHolder.getId());
|
||||
if (postLikedByUser) {
|
||||
@@ -500,10 +505,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
}else {
|
||||
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());
|
||||
vo.setViewNums(redisUtil.getViewCount(portfolioDTO.getId()));
|
||||
vo.setUserName(accountMapper.selectById(vo.getAccountId()).getUserName());
|
||||
vo.setUserName(account.getUserName());
|
||||
if (vo.getOriginal() == 0) {
|
||||
vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName());
|
||||
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){
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
@@ -1010,6 +1023,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
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){
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
Reference in New Issue
Block a user