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