HotIconServiceImpl.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.exception.BusinessException;
  7. import com.fdkankan.fusion.entity.HotIcon;
  8. import com.fdkankan.fusion.mapper.IHotIconMapper;
  9. import com.fdkankan.fusion.service.IHotIconService;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.stereotype.Service;
  13. import java.util.List;
  14. /**
  15. * <p>
  16. * 服务实现类
  17. * </p>
  18. *
  19. * @author
  20. * @since 2022-08-02
  21. */
  22. @Service
  23. public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> implements IHotIconService {
  24. @Override
  25. public List<HotIcon> getListByUserName(String username) {
  26. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  27. wrapper.eq(HotIcon::getUserName,username)
  28. .or().eq(HotIcon::getIsSystem,1);
  29. wrapper.orderByDesc(HotIcon::getIsSystem) // 官方默认
  30. .orderByDesc(HotIcon::getIsNew) // 新增
  31. .orderByDesc(HotIcon::getLastUse) // 上次使用
  32. .orderByDesc(HotIcon::getUseNum) // 使用次数
  33. .orderByDesc(HotIcon::getCreateTime);
  34. return this.list(wrapper);
  35. }
  36. @Override
  37. public HotIcon getDefaultIcon() {
  38. LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
  39. wrapper.eq(HotIcon::getIsSystem,1);
  40. wrapper.orderByDesc(HotIcon::getCreateTime);
  41. List<HotIcon> list = this.list(wrapper);
  42. if(list!= null && list.size() >0){
  43. return list.get(0);
  44. }
  45. return null;
  46. }
  47. @Override
  48. public void addUseNum(Integer hotIconId) {
  49. HotIcon hotIcon = this.getById(hotIconId);
  50. if(hotIcon == null){
  51. throw new BusinessException(ResultCode.HOT_ICON_NOT_EXIST);
  52. }
  53. hotIcon.setUseNum( hotIcon.getUseNum() + 1);
  54. hotIcon.setLastUse(1);
  55. LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
  56. wrapper.set(HotIcon::getLastUse,0);
  57. wrapper.eq(HotIcon::getUserName,hotIcon.getUserName());
  58. this.update(wrapper);
  59. hotIcon.setUpdateTime(null);
  60. this.updateById(hotIcon);
  61. }
  62. @Override
  63. public void cancelIsNew(String username) {
  64. LambdaUpdateWrapper<HotIcon> wrapper = new LambdaUpdateWrapper<>();
  65. wrapper.set(HotIcon::getIsNew,1)
  66. .eq(HotIcon::getUserName,username);
  67. this.update(wrapper);
  68. }
  69. }