package com.codvision.base.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codvision.base.entity.LocalIconLibrary;
import com.codvision.base.entity.vo.LocalIconLibraryVO;
import com.codvision.base.mapper.LocalIconLibraryMapper;
import com.codvision.base.service.ILocalIconLibraryService;
import com.codvision.webcore.service.impl.BaseServiceImpl;
import com.codvision.webcore.bean.QueryPage;
import com.codvision.webcore.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 本地图标 服务实现类
 * </p>
 *
 * @author lingee
 * @since 2023-11-20
 */
@Service
public class LocalIconLibraryServiceImpl extends BaseServiceImpl<LocalIconLibraryMapper, LocalIconLibrary, LocalIconLibraryVO> implements ILocalIconLibraryService {

    @Override
    public LocalIconLibraryVO getDetail(Long id) {
        LocalIconLibraryVO vo = new LocalIconLibraryVO();
        LocalIconLibrary po = this.getById(id);
        if (null != po) {
            BeanUtil.copyProperties(po, vo);
        }
        return vo;
    }

    @Override
    public IPage<LocalIconLibraryVO> getPageResult(QueryPage<LocalIconLibrary> queryPage) {
        QueryWrapper<LocalIconLibrary> queryWrapper = queryPage.getWrapper();
        IPage<LocalIconLibraryVO> pageResult = this.getBasePage(queryPage.getPage(), queryWrapper);
        return pageResult;
    }

    @Override
    public List<LocalIconLibraryVO> listAll(LocalIconLibrary queryBean) {
        QueryWrapper<LocalIconLibrary> wrapper = PageUtil.initWrapper(queryBean);
        List<LocalIconLibrary> list = this.list(wrapper);
        return BeanUtil.copyToList(list, LocalIconLibraryVO.class);
    }

    @Override
    public boolean save(LocalIconLibrary localIconLibrary) {
        Assert.notNull(localIconLibrary, "本地图标不能为空");
        getBaseMapper().insert(localIconLibrary);
        return true;
    }

    @Override
    public boolean updateById(LocalIconLibrary localIconLibrary) {
        Assert.notNull(localIconLibrary, "本地图标不能为空");
        Assert.notNull(localIconLibrary.getId(), "本地图标id不能为空");
        getBaseMapper().updateById(localIconLibrary);
        return true;
    }

    @Override
    public boolean removeById(Serializable id) {
        LocalIconLibrary localIconLibrary = getById(id);
        Assert.notNull(localIconLibrary, "本地图标不存在");
        getBaseMapper().deleteById(id);
        return true;
    }
}
