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;
/**
*
* 服务实现类
*
*
* @author
* @since 2022-08-02
*/
@Service
public class HotIconServiceImpl extends ServiceImpl implements IHotIconService {
@Override
public List getListByUserName(String username) {
LambdaQueryWrapper 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 wrapper = new LambdaQueryWrapper<>();
wrapper.eq(HotIcon::getIsSystem,1);
wrapper.orderByDesc(HotIcon::getCreateTime);
List 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 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 wrapper = new LambdaUpdateWrapper<>();
wrapper.set(HotIcon::getIsNew,1)
.eq(HotIcon::getUserName,username);
this.update(wrapper);
}
}