feat: columnTag -> JournalTag

main
itao 12 months ago
parent 823f626227
commit fec88aaa9c

@ -1,6 +1,6 @@
package com.luoo.tag.dao;
import com.luoo.tag.pojo.ColumnTag;
import com.luoo.tag.pojo.JournalTag;
import com.luoo.tag.pojo.TagCountDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
@ -10,8 +10,8 @@ import java.util.List;
/**
* DAO
*/
public interface ColumnTagDao extends JpaRepository<ColumnTag, String>{
public interface JournalTagDao extends JpaRepository<JournalTag, String>{
@Query(value = "select new com.luoo.tag.pojo.TagCountDTO(tagId, count(*)) from SongTag where tagId in :tagIds group by tagId")
@Query(value = "select new com.luoo.tag.pojo.TagCountDTO(tagId, count(*)) from JournalTag where tagId in :tagIds group by tagId")
List<TagCountDTO> countByTagIds(List<String> tagIds);
}

@ -15,8 +15,8 @@ import java.io.Serializable;
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "tb_column_tag")
public class ColumnTag implements Serializable {
@Table(name = "tb_journal_tag")
public class JournalTag implements Serializable {
private static final long serialVersionUID = -6632726210980182896L;
@Id
private String id;
@ -24,7 +24,7 @@ public class ColumnTag implements Serializable {
/**
* ID
*/
private String columnId;
private String journalId;
/**
* ID

@ -35,7 +35,7 @@ public class TagDTO implements Serializable {
private Long childTagCount = 0L;
@ApiModelProperty(value = "关联期刊数量")
private Long columnRefCount = 0L;
private Long journalRefCount = 0L;
@ApiModelProperty(value = "关联歌曲数量")
private Long songRefCount = 0L;

@ -32,7 +32,7 @@ public class TagStatistic implements Serializable {
*
*/
@Builder.Default
private Long columnRefCount = 0L;
private Long journalRefCount = 0L;
/**
*
@ -44,14 +44,14 @@ public class TagStatistic implements Serializable {
public TagStatistic(String tagId){
this.tagId = tagId;
this.childTagCount = 0L;
this.columnRefCount = 0L;
this.journalRefCount = 0L;
this.songRefCount = 0L;
}
public TagStatistic(String tagId, Long childTagCount){
this.tagId = tagId;
this.childTagCount = childTagCount;
this.columnRefCount = 0L;
this.journalRefCount = 0L;
this.songRefCount = 0L;
}
}

@ -4,7 +4,7 @@ import api.PageResult;
import com.google.common.collect.Lists;
import com.luoo.tag.client.UserClient;
import com.luoo.tag.config.RequestContext;
import com.luoo.tag.dao.ColumnTagDao;
import com.luoo.tag.dao.JournalTagDao;
import com.luoo.tag.dao.SongTagDao;
import com.luoo.tag.dao.TagDao;
import com.luoo.tag.enums.TagLevelEnum;
@ -38,7 +38,7 @@ public class TagService {
private final TagDao tagDao;
private final IdWorker idWorker;
private final UserClient userClient;
private final ColumnTagDao columnTagDao;
private final JournalTagDao journalTagDao;
private final SongTagDao songTagDao;
@ -65,7 +65,7 @@ public class TagService {
BeanUtils.copyProperties(tag, tagDTO);
TagStatistic tagStatistic = tagStatisticMap.get(tag.getId());
tagDTO.setChildTagCount(tagStatistic.getChildTagCount());
tagDTO.setColumnRefCount(tagStatistic.getColumnRefCount());
tagDTO.setJournalRefCount(tagStatistic.getJournalRefCount());
tagDTO.setSongRefCount(tagStatistic.getSongRefCount());
Tag parentTag = parentTagMap.get(tagDTO.getParentId());
if (Objects.nonNull(parentTag)) {
@ -151,7 +151,7 @@ public class TagService {
TagStatistic tagStatistic = queryTagStatistic(tag.getId());
tagDTO.setChildTagCount(tagStatistic.getChildTagCount());
tagDTO.setColumnRefCount(tagStatistic.getColumnRefCount());
tagDTO.setJournalRefCount(tagStatistic.getJournalRefCount());
tagDTO.setSongRefCount(tagStatistic.getSongRefCount());
return tagDTO;
}
@ -184,7 +184,7 @@ public class TagService {
}
TagStatistic referenceStatistic = queryTagStatistic(tagOptional.get().getId());
AssertUtil.mustEq(referenceStatistic.getColumnRefCount(), 0L,"无法执行删除, 该标签还存在关联的期刊");
AssertUtil.mustEq(referenceStatistic.getJournalRefCount(), 0L,"无法执行删除, 该标签还存在关联的期刊");
AssertUtil.mustEq(referenceStatistic.getSongRefCount(), 0L,"无法执行删除, 该标签还存在关联的音乐");
AssertUtil.mustEq(referenceStatistic.getChildTagCount(), 0L,"无法执行删除, 该标签还存在关联的子标签");
tagDao.deleteById(id);
@ -255,19 +255,19 @@ public class TagService {
List<TagCountDTO> songTagCountList = songTagDao.countByTagIds(tagIdList);
Map<String, Long> songTagCountMap = songTagCountList.stream()
.collect(toMap(TagCountDTO::getTagId, TagCountDTO::getCount));
List<TagCountDTO> columnTagCountList = columnTagDao.countByTagIds(tagIdList);
Map<String, Long> columnTagCountMap = columnTagCountList.stream()
List<TagCountDTO> journalTagCountList = journalTagDao.countByTagIds(tagIdList);
Map<String, Long> journalTagCountMap = journalTagCountList.stream()
.collect(toMap(TagCountDTO::getTagId, TagCountDTO::getCount));
List<TagStatistic> tagStatisticList = tagIdList.stream().map(tagId -> {
Long childTagCount = childTagCountMap.getOrDefault(tagId, 0L);
Long songTagCount = songTagCountMap.getOrDefault(tagId, 0L);
Long columnTagCount = columnTagCountMap.getOrDefault(tagId, 0L);
Long journalTagCount = journalTagCountMap.getOrDefault(tagId, 0L);
return TagStatistic.builder()
.tagId(tagId)
.childTagCount(childTagCount)
.songRefCount(songTagCount)
.columnRefCount(columnTagCount)
.journalRefCount(journalTagCount)
.build();
}).collect(toList());

Loading…
Cancel
Save