HotIconServiceImpl.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.fdkankan.fusion.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.fdkankan.fusion.common.ResultCode;
  5. import com.fdkankan.fusion.common.ResultCode;
  6. import com.fdkankan.fusion.entity.CaseTag;
  7. import com.fdkankan.fusion.exception.BusinessException;
  8. import com.fdkankan.fusion.entity.HotIcon;
  9. import com.fdkankan.fusion.mapper.IHotIconMapper;
  10. import com.fdkankan.fusion.service.ICaseTagService;
  11. import com.fdkankan.fusion.service.IHotIconService;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.HashSet;
  19. import java.util.List;
  20. import java.util.stream.Collectors;
  21. /**
  22. * <p>
  23. * 服务实现类
  24. * </p>
  25. *
  26. * @author
  27. * @since 2022-08-02
  28. */
  29. @Service
  30. public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> implements IHotIconService {
  31. @Autowired
  32. ICaseTagService caseTagService;
  33. @Override
  34. public List<HotIcon> getListByUserName(String username) {
  35. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  36. wrapper.orderByDesc(HotIcon::getIsSystem) // 官方默认
  37. .orderByDesc(HotIcon::getIsNew) // 新增
  38. .orderByDesc(HotIcon::getLastUse) // 上次使用
  39. .orderByDesc(HotIcon::getUseNum) // 使用次数
  40. .orderByDesc(HotIcon::getSort)
  41. .orderByDesc(HotIcon::getCreateTime);
  42. return this.list(wrapper);
  43. }
  44. @Override
  45. public List<HotIcon> getDefaultIcon() {
  46. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  47. wrapper.eq(HotIcon::getIsSystem,1);
  48. wrapper.orderByDesc(HotIcon::getCreateTime);
  49. List<HotIcon> list = this.list(wrapper);
  50. return list;
  51. }
  52. @Override
  53. public void addUseNum(Integer hotIconId) {
  54. HotIcon hotIcon = this.getById(hotIconId);
  55. if(hotIcon == null){
  56. throw new BusinessException(ResultCode.HOT_ICON_NOT_EXIST);
  57. }
  58. hotIcon.setUseNum( hotIcon.getUseNum() + 1);
  59. hotIcon.setLastUse(1);
  60. LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
  61. wrapper.set(HotIcon::getLastUse,0);
  62. wrapper.eq(HotIcon::getUserName,hotIcon.getUserName());
  63. this.update(wrapper);
  64. hotIcon.setUpdateTime(null);
  65. this.updateById(hotIcon);
  66. }
  67. @Override
  68. public void cancelIsNew(String username) {
  69. LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
  70. wrapper.set(HotIcon::getIsNew,1)
  71. .eq(HotIcon::getUserName,username);
  72. this.update(wrapper);
  73. }
  74. @Override
  75. public List<HotIcon> getListByFusionId(Integer fusionId) {
  76. HashSet<Integer> hotIconIds = new HashSet<>();
  77. List<CaseTag> list = caseTagService.getListByFusionId(fusionId);
  78. if(list.size() >0){
  79. List<Integer> ids = list.parallelStream().map(CaseTag::getHotIconId).collect(Collectors.toList());
  80. if(!ids.isEmpty()){
  81. hotIconIds.addAll(ids);
  82. }
  83. }
  84. hotIconIds.addAll(getDefaultIcon().stream().map(HotIcon::getIconId).collect(Collectors.toList()));
  85. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  86. wrapper.eq(HotIcon::getFusionId,fusionId);
  87. List<HotIcon> list1 = this.list(wrapper);
  88. List<Integer> ids = list1.stream().map(HotIcon::getIconId).collect(Collectors.toList());
  89. if(!ids.isEmpty()){
  90. hotIconIds.addAll(ids);
  91. }
  92. if(hotIconIds.isEmpty()){
  93. return new ArrayList<>();
  94. }
  95. return this.getByIds(hotIconIds);
  96. }
  97. @Override
  98. public List<HotIcon> getByIds( HashSet<Integer> hotIconIds) {
  99. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  100. wrapper.in(HotIcon::getIconId,hotIconIds);
  101. wrapper.orderByDesc(HotIcon::getIsSystem) // 官方默认
  102. .orderByAsc(HotIcon::getIconTitle)
  103. .orderByAsc(HotIcon::getSort);
  104. return this.list(wrapper);
  105. }
  106. @Override
  107. public List<HotIcon> treeList(List<HotIcon> iconList) {
  108. HashMap<Integer,HotIcon> map = new HashMap<>();
  109. List<HotIcon> list = new ArrayList<>();
  110. List<HotIcon> result = new ArrayList<>();
  111. for (HotIcon hotIcon : iconList) {
  112. if(hotIcon.getParentId() == null){
  113. list.add(hotIcon);
  114. }
  115. map.put(hotIcon.getIconId(),hotIcon);
  116. }
  117. for (HotIcon hotIcon : iconList) {
  118. if(hotIcon.getParentId() == null){
  119. continue;
  120. }
  121. HotIcon parent = map.get(hotIcon.getParentId());
  122. if(parent.getChildrenList() == null){
  123. parent.setChildrenList(new ArrayList<>());
  124. }
  125. parent.getChildrenList().add(hotIcon);
  126. }
  127. for (HotIcon hotIcon : list) {
  128. result.add( map.get(hotIcon.getIconId()));
  129. }
  130. return result;
  131. }
  132. }