12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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.exception.BusinessException;
- import com.fdkankan.fusion.entity.HotIcon;
- import com.fdkankan.fusion.mapper.IHotIconMapper;
- import com.fdkankan.fusion.service.IHotIconService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.stereotype.Service;
- import java.util.List;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-08-02
- */
- @Service
- public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> implements IHotIconService {
- @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);
- }
- }
|