package com.fdkankan.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fdkankan.ucenter.entity.ScenePlusExt;
import com.fdkankan.ucenter.mapper.IScenePlusExtMapper;
import com.fdkankan.ucenter.service.IScenePlusExtService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2022-07-04
 */
@Service
public class ScenePlusExtServiceImpl extends ServiceImpl<IScenePlusExtMapper, ScenePlusExt> implements IScenePlusExtService {

    @Override
    public ScenePlusExt getByPlusId(Long plusId) {
        LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ScenePlusExt::getPlusId,plusId);
        List<ScenePlusExt> list = this.list(wrapper);
        if(list != null && list.size() >0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public HashMap<Long, ScenePlusExt> getByPlusIds(List<Long> plusIds) {
        HashMap<Long,ScenePlusExt> map = new HashMap<>();
        if(plusIds.size() >0){
            LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
            wrapper.in(ScenePlusExt::getPlusId,plusIds);
            List<ScenePlusExt> list = this.list(wrapper);
            list.forEach(entity -> map.put(entity.getPlusId(),entity));
        }
        return map;
    }

    @Override
    public ScenePlusExt getByUnicode(String unicode) {
        LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ScenePlusExt::getDataSource,unicode);
        wrapper.orderByDesc(ScenePlusExt::getCreateTime);
        List<ScenePlusExt> list = this.list(wrapper);
        if(list != null && list.size() >0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<ScenePlusExt> getSsObj() {
        LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ScenePlusExt::getIsObj,1);
        return this.list(wrapper);
    }

    @Override
    public void removeByPlusIds(List<Long> plusIds) {
        if(CollectionUtils.isEmpty(plusIds)){
            return;
        }
        LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(ScenePlusExt::getPlusId,plusIds);
        this.remove(wrapper);
    }


}
