按标签查询作品
This commit is contained in:
@@ -6,7 +6,6 @@ import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.CommentVO;
|
||||
import com.ai.da.model.vo.PortfolioVO;
|
||||
import com.ai.da.model.vo.UserLikeChooseVO;
|
||||
import com.ai.da.model.vo.UserLikeGroupVO;
|
||||
import com.ai.da.service.PortfolioService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -29,8 +28,8 @@ public class PortfolioController {
|
||||
|
||||
@ApiOperation(value = "发布作品集")
|
||||
@PostMapping("/publish")
|
||||
public Response<Boolean> preLogin(@RequestParam("file") MultipartFile canvas, @RequestParam("data") String data, @RequestParam("tags") List<TagsDTO> tagsDTOS) {
|
||||
return Response.success(portfolioService.publish(canvas, data, tagsDTOS));
|
||||
public Response<Boolean> preLogin(@RequestParam("file") MultipartFile canvas, @RequestParam("data") String data) {
|
||||
return Response.success(portfolioService.publish(canvas, data));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除作品集")
|
||||
@@ -120,8 +119,9 @@ public class PortfolioController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "按标签名查询作品")
|
||||
@PostMapping("/queryPortfolioByTag")
|
||||
public Response<List<PortfolioVO>> queryPortfolioByTag(@RequestParam("tagName") String tagName) {
|
||||
return Response.success(portfolioService.queryPortfolioByTag(tagName));
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.ai.da.model.dto;
|
||||
|
||||
import com.ai.da.mapper.primary.entity.Portfolio;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PortfolioDTO extends Portfolio {
|
||||
private Long userLikeGroupId;
|
||||
|
||||
private List<TagsDTO> tagsDTO;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.List;
|
||||
|
||||
public interface PortfolioService extends IService<Portfolio> {
|
||||
Boolean publish(MultipartFile canvas, String data, List<TagsDTO> tagsDTOS);
|
||||
Boolean publish(MultipartFile canvas, String data);
|
||||
|
||||
PortfolioVO update(PortfolioDTO portfolioDTO);
|
||||
|
||||
@@ -44,5 +44,5 @@ public interface PortfolioService extends IService<Portfolio> {
|
||||
|
||||
Portfolio getByIdAll(Long originalPortfolioId);
|
||||
|
||||
List<PortfolioVO> queryPortfolioByTag(String tagName);
|
||||
List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.ai.da.service;
|
||||
import com.ai.da.mapper.primary.entity.Tags;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TagsService extends IService<Tags> {
|
||||
|
||||
List<Tags> getTags(String tagPrefix);
|
||||
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean publish(MultipartFile file, String data, List<TagsDTO> tagsDTOS) {
|
||||
public Boolean publish(MultipartFile file, String data) {
|
||||
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
||||
PortfolioDTO portfolioDTO = JSONObject.parseObject(data, PortfolioDTO.class);
|
||||
QueryWrapper<Portfolio> existSameNameQw = new QueryWrapper<>();
|
||||
@@ -296,7 +296,9 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
portfolioId = portfolio.getId();
|
||||
}
|
||||
// 记录作品添加的标签
|
||||
addTagsForPortfolio(tagsDTOS, portfolioId);
|
||||
if (!portfolioDTO.getTagsDTO().isEmpty()){
|
||||
addTagsForPortfolio(portfolioDTO.getTagsDTO(), portfolioId);
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
@@ -1059,11 +1061,17 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
|
||||
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();
|
||||
if (Objects.isNull(tag.getId())){
|
||||
Tags newTag = new Tags();
|
||||
newTag.setTagName(tag.getTagName());
|
||||
String tagName = tag.getTagName();
|
||||
/*if (tagName.startsWith("#")){
|
||||
tagName = tagName.replace("#", "");
|
||||
}*/
|
||||
newTag.setTagName(tagName);
|
||||
newTag.setCreateTime(LocalDateTime.now());
|
||||
tagsService.save(newTag);
|
||||
portfolioTags.setTagId(newTag.getId());
|
||||
@@ -1076,11 +1084,17 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
});
|
||||
}
|
||||
|
||||
public List<PortfolioVO> queryPortfolioByTag(String tagName){
|
||||
public List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId){
|
||||
ArrayList<PortfolioVO> portfolioVOS = new ArrayList<>();
|
||||
List<Map<String, String>> matchingTags = tagsMapper.getMatchingTags(tagName);
|
||||
Map<String, String> tagMap = matchingTags.get(0);
|
||||
long bestMatchTagId = Long.parseLong(tagMap.get("id"));
|
||||
long bestMatchTagId;
|
||||
if (Objects.isNull(tagId)){
|
||||
|
||||
List<Map<String, String>> matchingTags = tagsMapper.getMatchingTags(tagName);
|
||||
Map<String, String> tagMap = matchingTags.get(0);
|
||||
bestMatchTagId = Long.parseLong(tagMap.get("id"));
|
||||
}else {
|
||||
bestMatchTagId = tagId;
|
||||
}
|
||||
|
||||
QueryWrapper<PortfolioTags> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("tag_id", bestMatchTagId).select("portfolio_id");
|
||||
|
||||
@@ -19,7 +19,7 @@ public class TagsServiceImpl extends ServiceImpl<TagsMapper, Tags> implements Ta
|
||||
public List<Tags> getTags(String tagPrefix){
|
||||
// 1、根据tag前缀,查询
|
||||
QueryWrapper<Tags> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.likeLeft("tag_name", tagPrefix);
|
||||
queryWrapper.likeRight("tag_name", tagPrefix);
|
||||
|
||||
// 需返回标签内容和id
|
||||
return baseMapper.selectList(queryWrapper);
|
||||
|
||||
Reference in New Issue
Block a user