1、为发布的作品添加标签

2、修改标签
3、不允许用户重复参与活动
4、查询所有参与活动的作品
This commit is contained in:
2024-10-09 13:51:16 +08:00
parent f0e0987f31
commit 463ddf3cb2
16 changed files with 115 additions and 45 deletions

View File

@@ -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 RCA_WORKSHOP_TAG = "#RCAworkshop_2024";
} }

View File

@@ -118,10 +118,10 @@ public class PortfolioController {
return Response.success(portfolioService.commentDelete(commentDTO)); return Response.success(portfolioService.commentDelete(commentDTO));
} }
@ApiOperation(value = "按标签名查询作品") /* @ApiOperation(value = "按标签名查询作品")
@GetMapping("/queryPortfolioByTag") @GetMapping("/queryPortfolioByTag")
public Response<List<PortfolioVO>> queryPortfolioByTag(@RequestParam(value = "tagName", required = false) String tagName, public Response<List<PortfolioVO>> queryPortfolioByTag(@RequestParam(value = "tagName", required = false) String tagName,
@RequestParam(value = "tagId", required = false) Long tagId) { @RequestParam(value = "tagId", required = false) Long tagId) {
return Response.success(portfolioService.queryPortfolioByTag(tagName, tagId)); return Response.success(portfolioService.queryPortfolioByTag(tagName, tagId));
} }*/
} }

View File

@@ -3,6 +3,10 @@ package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper; import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.Portfolio; import com.ai.da.mapper.primary.entity.Portfolio;
import java.util.List;
public interface PortfolioMapper extends CommonMapper<Portfolio> { public interface PortfolioMapper extends CommonMapper<Portfolio> {
Portfolio getByIdAll(Long originalPortfolioId); Portfolio getByIdAll(Long originalPortfolioId);
List<Portfolio> getByTag(Long accountId, String tagName);
} }

View File

@@ -2,10 +2,14 @@ package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper; import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.PortfolioTags; 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> { public interface PortfolioTagsMapper extends CommonMapper<PortfolioTags> {
void deleteByPortfolioId(Long portfolioId);
// portfolioId与tagId建立唯一约束 如果组合 portfolio_id 和 tag_id 已经存在,插入操作会被忽略。
void insertIgnore(Long portfolioId, Long tagId, LocalDateTime time);
} }

View File

@@ -2,6 +2,7 @@ package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper; import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.Tags; import com.ai.da.mapper.primary.entity.Tags;
import com.ai.da.model.dto.TagsDTO;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -11,4 +12,6 @@ public interface TagsMapper extends CommonMapper<Tags> {
List<Map<String, String>> getMatchingTags(String userInput); List<Map<String, String>> getMatchingTags(String userInput);
List<TagsDTO> getTagByPortfolioId(Long portfolioId);
} }

View File

@@ -2,11 +2,8 @@ package com.ai.da.model.dto;
import com.ai.da.model.vo.PageQueryBaseVo; import com.ai.da.model.vo.PageQueryBaseVo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
@ApiModel("作品集分页查询") @ApiModel("作品集分页查询")
public class QueryPortfolioPageDTO extends PageQueryBaseVo { public class QueryPortfolioPageDTO extends PageQueryBaseVo {
@@ -14,4 +11,6 @@ public class QueryPortfolioPageDTO extends PageQueryBaseVo {
private Integer getMyPortfolio; private Integer getMyPortfolio;
private Integer getLikePortfolio; private Integer getLikePortfolio;
private Long tagId;
} }

View File

@@ -1,13 +1,11 @@
package com.ai.da.model.vo; 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.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@Data @Data
@ApiModel("用户choose详细-响应") @ApiModel("用户choose详细-响应")
@@ -26,5 +24,6 @@ public class UserLikeChooseVO {
private Integer beenPublished; private Integer beenPublished;
private Portfolio portfolio; // private Portfolio portfolio;
private PortfolioDTO portfolioDTO;
} }

View File

@@ -44,5 +44,5 @@ public interface PortfolioService extends IService<Portfolio> {
Portfolio getByIdAll(Long originalPortfolioId); Portfolio getByIdAll(Long originalPortfolioId);
List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId); // List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId);
} }

View File

@@ -9,4 +9,6 @@ public interface TagsService extends IService<Tags> {
List<Tags> getTags(String tagPrefix); List<Tags> getTags(String tagPrefix);
Tags addTag(String tagName);
} }

View File

@@ -1,8 +1,10 @@
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.response.ResultEnum;
import com.ai.da.common.utils.CopyUtil; import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.MinioUtil; import com.ai.da.common.utils.MinioUtil;
import com.ai.da.common.utils.RedisUtil; import com.ai.da.common.utils.RedisUtil;
@@ -133,6 +135,10 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
if (!CollectionUtils.isEmpty(portfoliosSameName)) { if (!CollectionUtils.isEmpty(portfoliosSameName)) {
throw new BusinessException("The title of the published work has been used."); 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) { if (file != null && file.getOriginalFilename() != null) {
Long portfolioId; Long portfolioId;
String upload = minioUtil.upload("aida-canvas", String.valueOf(authPrincipalVo.getId()), file); 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(); resultPortfolioId = portfolio.getId();
portfolioId = portfolio.getId(); portfolioId = portfolio.getId();
} }
// id不为空 表示更新发布;为空,表示新发布
if (!Objects.isNull(portfolioDTO.getId())){
portfolioId = portfolioDTO.getId();
// 删除作品的所有与标签的关联关系
portfolioTagsMapper.deleteByPortfolioId(portfolioId);
}
// 记录作品添加的标签 // 记录作品添加的标签
if (!portfolioDTO.getTagsDTO().isEmpty()){ if (!portfolioDTO.getTagsDTO().isEmpty()){
addTagsForPortfolio(portfolioDTO.getTagsDTO(), portfolioId); addTagsForPortfolio(portfolioDTO.getTagsDTO(), portfolioId);
@@ -456,15 +468,17 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
} }
} }
List<Portfolio> topThree = new ArrayList<>(); if (!Objects.isNull(query.getTagId()) && !query.getTagId().equals(0L)){
List<Long> excludeIds = new ArrayList<>(); // 存放需要排除的 ID 列表 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)) { if (query.getPage() == 1 && (query.getGetMyPortfolio() != 1 || query.getGetLikePortfolio() != 1)) {
// 获取前三点赞的作品集 ID // 获取前三点赞的作品集 ID
List<Long> topThreeLike = getTopThreeLikeFromRedis(RedisUtil.PORTFOLIO_LIKE_KEY); List<Long> topThreeLike = getTopThreeLikeFromRedis(RedisUtil.PORTFOLIO_LIKE_KEY);
List<Long> topThreeView = getTopThreeViewFromRedis(RedisUtil.PORTFOLIO_VIEW_KEY, topThreeLike); List<Long> topThreeView = getTopThreeViewFromRedis(RedisUtil.PORTFOLIO_VIEW_KEY, topThreeLike);
// 获取前三点赞的作品集 // 获取前三点赞的作品集
if (!CollectionUtils.isEmpty(topThreeLike)) { if (!CollectionUtils.isEmpty(topThreeLike)) {
QueryWrapper<Portfolio> queryLike = new QueryWrapper<>(); QueryWrapper<Portfolio> queryLike = new QueryWrapper<>();
@@ -473,7 +487,6 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
topThree.addAll(topThreeLikePortfolio); topThree.addAll(topThreeLikePortfolio);
excludeIds.addAll(topThreeLike); // 添加到排除 ID 列表 excludeIds.addAll(topThreeLike); // 添加到排除 ID 列表
} }
// 获取前三浏览的作品集 // 获取前三浏览的作品集
if (!CollectionUtils.isEmpty(topThreeView)) { if (!CollectionUtils.isEmpty(topThreeView)) {
QueryWrapper<Portfolio> queryView = new QueryWrapper<>(); QueryWrapper<Portfolio> queryView = new QueryWrapper<>();
@@ -483,11 +496,10 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
excludeIds.addAll(topThreeView); // 添加到排除 ID 列表 excludeIds.addAll(topThreeView); // 添加到排除 ID 列表
} }
} }
// 在正常分页查询中排除前三点赞和前三浏览的作品集 // 在正常分页查询中排除前三点赞和前三浏览的作品集
if (!CollectionUtils.isEmpty(excludeIds)) { if (!CollectionUtils.isEmpty(excludeIds)) {
qw.lambda().notIn(Portfolio::getId, excludeIds); qw.lambda().notIn(Portfolio::getId, excludeIds);
} }*/
// 按更新时间排序 // 按更新时间排序
qw.lambda().orderByDesc(Portfolio::getUpdateDate); 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); IPage<Portfolio> page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
// 如果前三点赞和浏览不为空,将它们添加到分页查询的结果最前面 /*// 如果前三点赞和浏览不为空,将它们添加到分页查询的结果最前面
if (!topThree.isEmpty()) { if (!topThree.isEmpty()) {
List<Portfolio> records = page.getRecords(); List<Portfolio> records = page.getRecords();
records.addAll(0, topThree); // 添加到查询结果的开头 records.addAll(0, topThree); // 添加到查询结果的开头
page.setRecords(records); page.setRecords(records);
} }*/
// 将 Portfolio 转换为 PortfolioVO 并进行相关处理 // 将 Portfolio 转换为 PortfolioVO 并进行相关处理
IPage<PortfolioVO> convert = page.convert((Function<Portfolio, PortfolioVO>) portfolio -> { IPage<PortfolioVO> convert = page.convert((Function<Portfolio, PortfolioVO>) portfolio -> {
@@ -523,7 +535,6 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
return PageBaseResponse.success(convert); return PageBaseResponse.success(convert);
} }
@Override @Override
public PortfolioVO detail(PortfolioDTO portfolioDTO) { public PortfolioVO detail(PortfolioDTO portfolioDTO) {
AuthPrincipalVo userHolder = UserContext.getUserHolder(); 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."); throw new BusinessException("You do not have the permission to delete portfolio.");
} }
portfolioMapper.deleteById(id); portfolioMapper.deleteById(id);
// 删除作品与标签的关联记录
portfolioTagsMapper.deleteByPortfolioId(id);
return Boolean.TRUE; return Boolean.TRUE;
} }
@@ -1063,33 +1077,32 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
return null; 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) { public void addTagsForPortfolio(List<TagsDTO> tagsDTOS, Long portfolioId) {
// 遍历数组添加到t_portfolio_tags表中没有id的tag添加到t_tags表中 // 遍历数组添加到t_portfolio_tags表中没有id的tag添加到t_tags表中
// todo 1、如何处理重复的tag
tagsDTOS.forEach(tag -> { tagsDTOS.forEach(tag -> {
PortfolioTags portfolioTags = new PortfolioTags(); Long tagId;
if (Objects.isNull(tag.getId())){ if (Objects.isNull(tag.getId())){
Tags newTag = new Tags(); Tags tags = tagsService.addTag(tag.getTagName());
String tagName = tag.getTagName(); tagId = tags.getId();
/*if (tagName.startsWith("#")){
tagName = tagName.replace("#", "");
}*/
newTag.setTagName(tagName);
newTag.setCreateTime(LocalDateTime.now());
tagsService.save(newTag);
portfolioTags.setTagId(newTag.getId());
}else { }else {
portfolioTags.setTagId(tag.getId()); tagId = tag.getId();
} }
portfolioTags.setPortfolioId(portfolioId); portfolioTagsMapper.insertIgnore(portfolioId, tagId, LocalDateTime.now());
portfolioTags.setCreateTime(LocalDateTime.now());
portfolioTagsMapper.insert(portfolioTags);
}); });
} }
public List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId){ public PageBaseResponse<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId, Integer page, Integer size) {
ArrayList<PortfolioVO> portfolioVOS = new ArrayList<>();
long bestMatchTagId; long bestMatchTagId;
if (Objects.isNull(tagId)){ if (Objects.isNull(tagId)){
@@ -1108,9 +1121,11 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
QueryWrapper<Portfolio> qw = new QueryWrapper<>(); QueryWrapper<Portfolio> qw = new QueryWrapper<>();
qw.in("id", portfolioIdList); 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) { if (portfolio != null) {
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class); PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
Canvas canvas = canvasMapper.selectById(vo.getCanvasId()); Canvas canvas = canvasMapper.selectById(vo.getCanvasId());
@@ -1122,9 +1137,10 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
if (vo.getOriginal() == 0) { if (vo.getOriginal() == 0) {
vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName()); vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName());
} }
portfolioVOS.add(vo); return vo;
} }
return null;
}); });
return portfolioVOS; return PageBaseResponse.success(convert);
} }
} }

View File

@@ -8,6 +8,7 @@ import com.ai.da.common.enums.CreditsEventsEnum;
import com.ai.da.common.utils.*; import com.ai.da.common.utils.*;
import com.ai.da.mapper.primary.*; import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.*; 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.ProductImageLikeDTO;
import com.ai.da.model.dto.ToProductImageDTO; import com.ai.da.model.dto.ToProductImageDTO;
import com.ai.da.model.vo.*; import com.ai.da.model.vo.*;
@@ -69,6 +70,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private LibraryMapper libraryMapper; private LibraryMapper libraryMapper;
@Resource @Resource
private PortfolioMapper portfolioMapper; private PortfolioMapper portfolioMapper;
@Resource
private TagsMapper tagsMapper;
@Override @Override
public void deleteUserGroup(Long userGroupId) { public void deleteUserGroup(Long userGroupId) {
@@ -155,12 +158,15 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
QueryWrapper<Portfolio> qw = new QueryWrapper<>(); QueryWrapper<Portfolio> qw = new QueryWrapper<>();
qw.lambda().eq(Portfolio::getUserLikeGroupSourceId, userGroupId); qw.lambda().eq(Portfolio::getUserLikeGroupSourceId, userGroupId);
List<Portfolio> portfolios = portfolioMapper.selectList(qw); List<Portfolio> portfolios = portfolioMapper.selectList(qw);
Portfolio portfolio = new Portfolio(); // Portfolio portfolio = new Portfolio();
PortfolioDTO portfolioDTO = new PortfolioDTO();
if (CollectionUtil.isNotEmpty(portfolios)) { if (CollectionUtil.isNotEmpty(portfolios)) {
portfolio = portfolios.get(0); // portfolio = portfolios.get(0);
portfolioDTO = CopyUtil.copyObject(portfolios.get(0), PortfolioDTO.class);
beenPublished = 1; 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 @Override

View File

@@ -9,4 +9,14 @@
from portfolio from portfolio
where id = #{originalPortfolioId} where id = #{originalPortfolioId}
</select> </select>
<select id="getByTag" resultType="com.ai.da.mapper.primary.entity.Portfolio">
SELECT p.*
FROM portfolio p
JOIN t_portfolio_tags pt ON p.id = pt.portfolio_id
JOIN t_tags t ON pt.tag_id = t.id
WHERE p.account_id = #{accountId}
AND t.tag_name = #{tagName};
</select>
</mapper> </mapper>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ai.da.mapper.primary.PortfolioTagsMapper">
<delete id="deleteByPortfolioId">
DELETE
FROM t_portfolio_tags
WHERE portfolio_id = #{portfolioId};
</delete>
<insert id="insertIgnore">
INSERT
IGNORE INTO t_portfolio_tags (portfolio_id, tag_id, create_time)
VALUES (#{portfolioId}, #{tagId}, #{time});
</insert>
</mapper>

View File

@@ -9,5 +9,12 @@
ORDER BY relevance DESC; ORDER BY relevance DESC;
</select> </select>
<select id="getTagByPortfolioId" resultType="com.ai.da.mapper.primary.entity.Tags">
SELECT t.*
FROM t_tags t
JOIN t_portfolio_tags pt ON t.id = pt.tag_id
WHERE pt.portfolio_id = #{portfolioId};
</select>
</mapper> </mapper>

View File

@@ -139,6 +139,7 @@ slogan.style.cannot.be.empty=Slogan style text cannot be empty.
slogan.image.cannot.be.empty=Slogan image cannot be empty. slogan.image.cannot.be.empty=Slogan image cannot be empty.
questionnaire.filled.out=You have filled out the current questionnaire. questionnaire.filled.out=You have filled out the current questionnaire.
user.has.no.account=The current user has no account user.has.no.account=The current user has no account
you.have.participated.in.the.event=You have participated in the event.
# 可能会报异常 # 可能会报异常
# Informative: # Informative:

View File

@@ -134,6 +134,7 @@ slogan.style.cannot.be.empty=标语风格文本不能为空。
slogan.image.cannot.be.empty=标语图片不能为空。 slogan.image.cannot.be.empty=标语图片不能为空。
questionnaire.filled.out=您已填写过当前问卷。 questionnaire.filled.out=您已填写过当前问卷。
user.has.no.account=当前用户没有账号。 user.has.no.account=当前用户没有账号。
you.have.participated.in.the.event=您已经参与活动
# 可能会报异常 # 可能会报异常
# Informative: # Informative: