123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package com.fdkankan.fusion.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.entity.CaseTag;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.entity.HotIcon;
- import com.fdkankan.fusion.mapper.IHotIconMapper;
- import com.fdkankan.fusion.service.ICaseTagService;
- import com.fdkankan.fusion.service.IHotIconService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-08-02
- */
- @Service
- public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> implements IHotIconService {
- @Autowired
- ICaseTagService caseTagService;
- @Override
- public List<HotIcon> getListByUserName(String username) {
- LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(HotIcon::getUserName,username)
- .or().eq(HotIcon::getIsSystem,1);
- wrapper.orderByDesc(HotIcon::getIsSystem) // 官方默认
- .orderByDesc(HotIcon::getIsNew) // 新增
- .orderByDesc(HotIcon::getLastUse) // 上次使用
- .orderByDesc(HotIcon::getUseNum) // 使用次数
- .orderByDesc(HotIcon::getCreateTime);
- return this.list(wrapper);
- }
- @Override
- public HotIcon getDefaultIcon() {
- LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(HotIcon::getIsSystem,1);
- wrapper.orderByDesc(HotIcon::getCreateTime);
- List<HotIcon> list = this.list(wrapper);
- if(list!= null && list.size() >0){
- return list.get(0);
- }
- return null;
- }
- @Override
- public void addUseNum(Integer hotIconId) {
- HotIcon hotIcon = this.getById(hotIconId);
- if(hotIcon == null){
- throw new BusinessException(ResultCode.HOT_ICON_NOT_EXIST);
- }
- hotIcon.setUseNum( hotIcon.getUseNum() + 1);
- hotIcon.setLastUse(1);
- LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
- wrapper.set(HotIcon::getLastUse,0);
- wrapper.eq(HotIcon::getUserName,hotIcon.getUserName());
- this.update(wrapper);
- hotIcon.setUpdateTime(null);
- this.updateById(hotIcon);
- }
- @Override
- public void cancelIsNew(String username) {
- LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
- wrapper.set(HotIcon::getIsNew,1)
- .eq(HotIcon::getUserName,username);
- this.update(wrapper);
- }
- @Override
- public List<HotIcon> getListByCaseId(Integer caseId) {
- HashSet<Integer> hotIconIds = new HashSet<>();
- List<CaseTag> list = caseTagService.getListByCaseId(caseId);
- if(list.size() >0){
- List<Integer> ids = list.parallelStream().map(CaseTag::getHotIconId).collect(Collectors.toList());
- if(!ids.isEmpty()){
- hotIconIds.addAll(ids);
- }
- }
- hotIconIds.add(getDefaultIcon().getIconId());
- LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(HotIcon::getCaseId,caseId);
- List<HotIcon> list1 = this.list(wrapper);
- List<Integer> ids = list1.stream().map(HotIcon::getIconId).collect(Collectors.toList());
- if(!ids.isEmpty()){
- hotIconIds.addAll(ids);
- }
- if(hotIconIds.isEmpty()){
- return new ArrayList<>();
- }
- return this.getByIds(hotIconIds);
- }
- @Override
- public List<HotIcon> getByIds( HashSet<Integer> hotIconIds) {
- LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(HotIcon::getIconId,hotIconIds);
- wrapper.orderByDesc(HotIcon::getIsSystem) // 官方默认
- .orderByDesc(HotIcon::getIsNew) // 新增
- .orderByDesc(HotIcon::getLastUse) // 上次使用
- .orderByDesc(HotIcon::getUseNum) // 使用次数
- .orderByDesc(HotIcon::getCreateTime);
- return this.list(wrapper);
- }
- }
|