1、为发布的作品添加标签
2、修改标签 3、不允许用户重复参与活动 4、查询所有参与活动的作品
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 RCA_WORKSHOP_TAG = "#RCAworkshop_2024";
|
||||
|
||||
}
|
||||
|
||||
@@ -118,10 +118,10 @@ public class PortfolioController {
|
||||
return Response.success(portfolioService.commentDelete(commentDTO));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "按标签名查询作品")
|
||||
/* @ApiOperation(value = "按标签名查询作品")
|
||||
@GetMapping("/queryPortfolioByTag")
|
||||
public Response<List<PortfolioVO>> queryPortfolioByTag(@RequestParam(value = "tagName", required = false) String tagName,
|
||||
@RequestParam(value = "tagId", required = false) Long tagId) {
|
||||
return Response.success(portfolioService.queryPortfolioByTag(tagName, tagId));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.ai.da.mapper.primary;
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.primary.entity.Portfolio;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PortfolioMapper extends CommonMapper<Portfolio> {
|
||||
Portfolio getByIdAll(Long originalPortfolioId);
|
||||
|
||||
List<Portfolio> getByTag(Long accountId, String tagName);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@ package com.ai.da.mapper.primary;
|
||||
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.primary.entity.PortfolioTags;
|
||||
import com.ai.da.mapper.primary.entity.Tags;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public interface PortfolioTagsMapper extends CommonMapper<PortfolioTags> {
|
||||
|
||||
void deleteByPortfolioId(Long portfolioId);
|
||||
|
||||
// portfolioId与tagId建立唯一约束, 如果组合 portfolio_id 和 tag_id 已经存在,插入操作会被忽略。
|
||||
void insertIgnore(Long portfolioId, Long tagId, LocalDateTime time);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ai.da.mapper.primary;
|
||||
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.primary.entity.Tags;
|
||||
import com.ai.da.model.dto.TagsDTO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -11,4 +12,6 @@ public interface TagsMapper extends CommonMapper<Tags> {
|
||||
|
||||
List<Map<String, String>> getMatchingTags(String userInput);
|
||||
|
||||
List<TagsDTO> getTagByPortfolioId(Long portfolioId);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@ package com.ai.da.model.dto;
|
||||
|
||||
import com.ai.da.model.vo.PageQueryBaseVo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("作品集分页查询")
|
||||
public class QueryPortfolioPageDTO extends PageQueryBaseVo {
|
||||
@@ -14,4 +11,6 @@ public class QueryPortfolioPageDTO extends PageQueryBaseVo {
|
||||
private Integer getMyPortfolio;
|
||||
|
||||
private Integer getLikePortfolio;
|
||||
|
||||
private Long tagId;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import com.ai.da.mapper.primary.entity.Portfolio;
|
||||
import com.ai.da.model.dto.PortfolioDTO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@ApiModel("用户choose详细-响应")
|
||||
@@ -26,5 +24,6 @@ public class UserLikeChooseVO {
|
||||
|
||||
private Integer beenPublished;
|
||||
|
||||
private Portfolio portfolio;
|
||||
// private Portfolio portfolio;
|
||||
private PortfolioDTO portfolioDTO;
|
||||
}
|
||||
|
||||
@@ -44,5 +44,5 @@ public interface PortfolioService extends IService<Portfolio> {
|
||||
|
||||
Portfolio getByIdAll(Long originalPortfolioId);
|
||||
|
||||
List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId);
|
||||
// List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId);
|
||||
}
|
||||
|
||||
@@ -9,4 +9,6 @@ public interface TagsService extends IService<Tags> {
|
||||
|
||||
List<Tags> getTags(String tagPrefix);
|
||||
|
||||
Tags addTag(String tagName);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
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.response.ResultEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.common.utils.RedisUtil;
|
||||
@@ -133,6 +135,10 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
if (!CollectionUtils.isEmpty(portfoliosSameName)) {
|
||||
throw new BusinessException("The title of the published work has been used.");
|
||||
}
|
||||
// 判断用户是否参与#RCAworkshop_2024的活动
|
||||
if (Objects.isNull(portfolioDTO.getId()) && hasParticipatedRCAWorkshop(authPrincipalVo.getId(), portfolioDTO.getTagsDTO())){
|
||||
throw new BusinessException("you.have.participated.in.the.event", ResultEnum.PROMPT.getCode());
|
||||
}
|
||||
if (file != null && file.getOriginalFilename() != null) {
|
||||
Long portfolioId;
|
||||
String upload = minioUtil.upload("aida-canvas", String.valueOf(authPrincipalVo.getId()), file);
|
||||
@@ -299,6 +305,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
resultPortfolioId = portfolio.getId();
|
||||
portfolioId = portfolio.getId();
|
||||
}
|
||||
// id不为空 表示更新发布;为空,表示新发布
|
||||
if (!Objects.isNull(portfolioDTO.getId())){
|
||||
portfolioId = portfolioDTO.getId();
|
||||
// 删除作品的所有与标签的关联关系
|
||||
portfolioTagsMapper.deleteByPortfolioId(portfolioId);
|
||||
}
|
||||
// 记录作品添加的标签
|
||||
if (!portfolioDTO.getTagsDTO().isEmpty()){
|
||||
addTagsForPortfolio(portfolioDTO.getTagsDTO(), portfolioId);
|
||||
@@ -456,15 +468,17 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
}
|
||||
}
|
||||
|
||||
List<Portfolio> topThree = new ArrayList<>();
|
||||
List<Long> excludeIds = new ArrayList<>(); // 存放需要排除的 ID 列表
|
||||
if (!Objects.isNull(query.getTagId()) && !query.getTagId().equals(0L)){
|
||||
return queryPortfolioByTag(null, query.getTagId(), query.getPage(), query.getSize());
|
||||
}
|
||||
|
||||
/*List<Portfolio> topThree = new ArrayList<>();
|
||||
List<Long> excludeIds = new ArrayList<>(); // 存放需要排除的 ID 列表
|
||||
// 获取前三点赞和前三浏览的作品集,并将其排除在分页查询之外
|
||||
if (query.getPage() == 1 && (query.getGetMyPortfolio() != 1 || query.getGetLikePortfolio() != 1)) {
|
||||
// 获取前三点赞的作品集 ID
|
||||
List<Long> topThreeLike = getTopThreeLikeFromRedis(RedisUtil.PORTFOLIO_LIKE_KEY);
|
||||
List<Long> topThreeView = getTopThreeViewFromRedis(RedisUtil.PORTFOLIO_VIEW_KEY, topThreeLike);
|
||||
|
||||
// 获取前三点赞的作品集
|
||||
if (!CollectionUtils.isEmpty(topThreeLike)) {
|
||||
QueryWrapper<Portfolio> queryLike = new QueryWrapper<>();
|
||||
@@ -473,7 +487,6 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
topThree.addAll(topThreeLikePortfolio);
|
||||
excludeIds.addAll(topThreeLike); // 添加到排除 ID 列表
|
||||
}
|
||||
|
||||
// 获取前三浏览的作品集
|
||||
if (!CollectionUtils.isEmpty(topThreeView)) {
|
||||
QueryWrapper<Portfolio> queryView = new QueryWrapper<>();
|
||||
@@ -483,11 +496,10 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
excludeIds.addAll(topThreeView); // 添加到排除 ID 列表
|
||||
}
|
||||
}
|
||||
|
||||
// 在正常分页查询中排除前三点赞和前三浏览的作品集
|
||||
if (!CollectionUtils.isEmpty(excludeIds)) {
|
||||
qw.lambda().notIn(Portfolio::getId, excludeIds);
|
||||
}
|
||||
}*/
|
||||
|
||||
// 按更新时间排序
|
||||
qw.lambda().orderByDesc(Portfolio::getUpdateDate);
|
||||
@@ -495,12 +507,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
// 执行分页查询
|
||||
IPage<Portfolio> page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
|
||||
|
||||
// 如果前三点赞和浏览不为空,将它们添加到分页查询的结果最前面
|
||||
/*// 如果前三点赞和浏览不为空,将它们添加到分页查询的结果最前面
|
||||
if (!topThree.isEmpty()) {
|
||||
List<Portfolio> records = page.getRecords();
|
||||
records.addAll(0, topThree); // 添加到查询结果的开头
|
||||
page.setRecords(records);
|
||||
}
|
||||
}*/
|
||||
|
||||
// 将 Portfolio 转换为 PortfolioVO 并进行相关处理
|
||||
IPage<PortfolioVO> convert = page.convert((Function<Portfolio, PortfolioVO>) portfolio -> {
|
||||
@@ -523,7 +535,6 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
return PageBaseResponse.success(convert);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PortfolioVO detail(PortfolioDTO portfolioDTO) {
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
@@ -963,6 +974,9 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
throw new BusinessException("You do not have the permission to delete portfolio.");
|
||||
}
|
||||
portfolioMapper.deleteById(id);
|
||||
|
||||
// 删除作品与标签的关联记录
|
||||
portfolioTagsMapper.deleteByPortfolioId(id);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@@ -1063,33 +1077,32 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证该用户是否已参加活动
|
||||
public Boolean hasParticipatedRCAWorkshop(Long accountId, List<TagsDTO> tags) {
|
||||
List<String> collect = tags.stream().map(Tags::getTagName).collect(Collectors.toList());
|
||||
if (!collect.contains(CommonConstant.RCA_WORKSHOP_TAG)){
|
||||
return false;
|
||||
}else {
|
||||
List<Portfolio> byTag = baseMapper.getByTag(accountId, CommonConstant.RCA_WORKSHOP_TAG);
|
||||
return !byTag.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public void addTagsForPortfolio(List<TagsDTO> tagsDTOS, Long portfolioId) {
|
||||
// 遍历数组,添加到t_portfolio_tags表中,没有id的tag,添加到t_tags表中
|
||||
|
||||
// todo 1、如何处理重复的tag
|
||||
tagsDTOS.forEach(tag -> {
|
||||
PortfolioTags portfolioTags = new PortfolioTags();
|
||||
Long tagId;
|
||||
if (Objects.isNull(tag.getId())){
|
||||
Tags newTag = new Tags();
|
||||
String tagName = tag.getTagName();
|
||||
/*if (tagName.startsWith("#")){
|
||||
tagName = tagName.replace("#", "");
|
||||
}*/
|
||||
newTag.setTagName(tagName);
|
||||
newTag.setCreateTime(LocalDateTime.now());
|
||||
tagsService.save(newTag);
|
||||
portfolioTags.setTagId(newTag.getId());
|
||||
Tags tags = tagsService.addTag(tag.getTagName());
|
||||
tagId = tags.getId();
|
||||
}else {
|
||||
portfolioTags.setTagId(tag.getId());
|
||||
tagId = tag.getId();
|
||||
}
|
||||
portfolioTags.setPortfolioId(portfolioId);
|
||||
portfolioTags.setCreateTime(LocalDateTime.now());
|
||||
portfolioTagsMapper.insert(portfolioTags);
|
||||
portfolioTagsMapper.insertIgnore(portfolioId, tagId, LocalDateTime.now());
|
||||
});
|
||||
}
|
||||
|
||||
public List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId){
|
||||
ArrayList<PortfolioVO> portfolioVOS = new ArrayList<>();
|
||||
public PageBaseResponse<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId, Integer page, Integer size) {
|
||||
long bestMatchTagId;
|
||||
if (Objects.isNull(tagId)){
|
||||
|
||||
@@ -1108,9 +1121,11 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
|
||||
QueryWrapper<Portfolio> qw = new QueryWrapper<>();
|
||||
qw.in("id", portfolioIdList);
|
||||
List<Portfolio> portfolios = baseMapper.selectList(qw);
|
||||
Page<Portfolio> portfolioPage = baseMapper.selectPage(new Page<>(page, size), qw);
|
||||
// List<Portfolio> portfolios = baseMapper.selectList(qw);
|
||||
|
||||
portfolios.forEach(portfolio -> {
|
||||
// 将 Portfolio 转换为 PortfolioVO 并进行相关处理
|
||||
IPage<PortfolioVO> convert = portfolioPage.convert((Function<Portfolio, PortfolioVO>) portfolio -> {
|
||||
if (portfolio != null) {
|
||||
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
|
||||
Canvas canvas = canvasMapper.selectById(vo.getCanvasId());
|
||||
@@ -1122,9 +1137,10 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
if (vo.getOriginal() == 0) {
|
||||
vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName());
|
||||
}
|
||||
portfolioVOS.add(vo);
|
||||
return vo;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return portfolioVOS;
|
||||
return PageBaseResponse.success(convert);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.ai.da.common.enums.CreditsEventsEnum;
|
||||
import com.ai.da.common.utils.*;
|
||||
import com.ai.da.mapper.primary.*;
|
||||
import com.ai.da.mapper.primary.entity.*;
|
||||
import com.ai.da.model.dto.PortfolioDTO;
|
||||
import com.ai.da.model.dto.ProductImageLikeDTO;
|
||||
import com.ai.da.model.dto.ToProductImageDTO;
|
||||
import com.ai.da.model.vo.*;
|
||||
@@ -69,6 +70,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
private LibraryMapper libraryMapper;
|
||||
@Resource
|
||||
private PortfolioMapper portfolioMapper;
|
||||
@Resource
|
||||
private TagsMapper tagsMapper;
|
||||
|
||||
@Override
|
||||
public void deleteUserGroup(Long userGroupId) {
|
||||
@@ -155,12 +158,15 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
QueryWrapper<Portfolio> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Portfolio::getUserLikeGroupSourceId, userGroupId);
|
||||
List<Portfolio> portfolios = portfolioMapper.selectList(qw);
|
||||
Portfolio portfolio = new Portfolio();
|
||||
// Portfolio portfolio = new Portfolio();
|
||||
PortfolioDTO portfolioDTO = new PortfolioDTO();
|
||||
if (CollectionUtil.isNotEmpty(portfolios)) {
|
||||
portfolio = portfolios.get(0);
|
||||
// portfolio = portfolios.get(0);
|
||||
portfolioDTO = CopyUtil.copyObject(portfolios.get(0), PortfolioDTO.class);
|
||||
beenPublished = 1;
|
||||
portfolioDTO.setTagsDTO(tagsMapper.getTagByPortfolioId(portfolioDTO.getId()));
|
||||
}
|
||||
return new UserLikeChooseVO(userGroupId, userLikeVOS, userLikeCollection, sex, beenPublished, portfolio);
|
||||
return new UserLikeChooseVO(userGroupId, userLikeVOS, userLikeCollection, sex, beenPublished, portfolioDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user