HotIconServiceImpl.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.HashSet;
  18. import java.util.List;
  19. import java.util.stream.Collectors;
  20. /**
  21. * <p>
  22. * 服务实现类
  23. * </p>
  24. *
  25. * @author
  26. * @since 2022-08-02
  27. */
  28. @Service
  29. public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> implements IHotIconService {
  30. @Autowired
  31. ICaseTagService caseTagService;
  32. @Override
  33. public List<HotIcon> getListByUserName(String username) {
  34. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  35. wrapper.eq(HotIcon::getUserName,username)
  36. .or().eq(HotIcon::getIsSystem,1);
  37. wrapper.orderByDesc(HotIcon::getIsSystem) // 官方默认
  38. .orderByDesc(HotIcon::getIsNew) // 新增
  39. .orderByDesc(HotIcon::getLastUse) // 上次使用
  40. .orderByDesc(HotIcon::getUseNum) // 使用次数
  41. .orderByDesc(HotIcon::getCreateTime);
  42. return this.list(wrapper);
  43. }
  44. @Override
  45. public 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. if(list!= null && list.size() >0){
  51. return list.get(0);
  52. }
  53. return null;
  54. }
  55. @Override
  56. public void addUseNum(Integer hotIconId) {
  57. HotIcon hotIcon = this.getById(hotIconId);
  58. if(hotIcon == null){
  59. throw new BusinessException(ResultCode.HOT_ICON_NOT_EXIST);
  60. }
  61. hotIcon.setUseNum( hotIcon.getUseNum() + 1);
  62. hotIcon.setLastUse(1);
  63. LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
  64. wrapper.set(HotIcon::getLastUse,0);
  65. wrapper.eq(HotIcon::getUserName,hotIcon.getUserName());
  66. this.update(wrapper);
  67. hotIcon.setUpdateTime(null);
  68. this.updateById(hotIcon);
  69. }
  70. @Override
  71. public void cancelIsNew(String username) {
  72. LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
  73. wrapper.set(HotIcon::getIsNew,1)
  74. .eq(HotIcon::getUserName,username);
  75. this.update(wrapper);
  76. }
  77. @Override
  78. public List<HotIcon> getListByCaseId(Integer caseId) {
  79. HashSet<Integer> hotIconIds = new HashSet<>();
  80. List<CaseTag> list = caseTagService.getListByCaseId(caseId);
  81. if(list.size() >0){
  82. List<Integer> ids = list.parallelStream().map(CaseTag::getHotIconId).collect(Collectors.toList());
  83. if(!ids.isEmpty()){
  84. hotIconIds.addAll(ids);
  85. }
  86. }
  87. hotIconIds.add(getDefaultIcon().getIconId());
  88. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  89. wrapper.eq(HotIcon::getCaseId,caseId);
  90. List<HotIcon> list1 = this.list(wrapper);
  91. List<Integer> ids = list1.stream().map(HotIcon::getIconId).collect(Collectors.toList());
  92. if(!ids.isEmpty()){
  93. hotIconIds.addAll(ids);
  94. }
  95. if(hotIconIds.isEmpty()){
  96. return new ArrayList<>();
  97. }
  98. return this.getByIds(hotIconIds);
  99. }
  100. @Override
  101. public List<HotIcon> getByIds( HashSet<Integer> hotIconIds) {
  102. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  103. wrapper.in(HotIcon::getIconId,hotIconIds);
  104. wrapper.orderByDesc(HotIcon::getIsSystem) // 官方默认
  105. .orderByDesc(HotIcon::getIsNew) // 新增
  106. .orderByDesc(HotIcon::getLastUse) // 上次使用
  107. .orderByDesc(HotIcon::getUseNum) // 使用次数
  108. .orderByDesc(HotIcon::getCreateTime);
  109. return this.list(wrapper);
  110. }
  111. }