package com.yunzhupaas.visualdata.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.util.RandomUtil;
import com.yunzhupaas.util.StringUtil;
import com.yunzhupaas.visualdata.entity.VisualAssetsEntity;
import com.yunzhupaas.visualdata.mapper.VisualAssetsMapper;
import com.yunzhupaas.visualdata.model.visual.VisualPaginationModel;
import com.yunzhupaas.visualdata.service.VisualAssetsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 静态资源
 *
 * @author 云筑产品开发平台组
 * @version V3.5.0
 * @copyright 深圳市乐程软件有限公司
 * @date 2023年7月7日
 */
@Service
public class VisualAssetsServiceImpl extends SuperServiceImpl<VisualAssetsMapper, VisualAssetsEntity> implements VisualAssetsService {

    @Override
    public List<VisualAssetsEntity> getList(VisualPaginationModel pagination) {
        QueryWrapper<VisualAssetsEntity> queryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNotEmpty(pagination.getAssetsName())){
            queryWrapper.lambda().like(VisualAssetsEntity::getAssetsName, pagination.getAssetsName());
        }
        Page page = new Page(pagination.getCurrent(), pagination.getSize());
        IPage<VisualAssetsEntity> iPages = this.page(page, queryWrapper);
        return pagination.setData(iPages);
    }

    @Override
    public List<VisualAssetsEntity> getList() {
        QueryWrapper<VisualAssetsEntity> queryWrapper = new QueryWrapper<>();
        return this.list(queryWrapper);
    }

    @Override
    public VisualAssetsEntity getInfo(String id) {
        QueryWrapper<VisualAssetsEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(VisualAssetsEntity::getId, id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(VisualAssetsEntity entity) {
        entity.setId(RandomUtil.uuId());
        this.save(entity);
    }

    @Override
    public boolean update(String id, VisualAssetsEntity entity) {
        entity.setId(id);
        return this.updateById(entity);
    }

    @Override
    public boolean delete(String id) {
        if (StringUtil.isNotEmpty(id)) {
            return this.removeById(id);
        }
        return false;
    }


}

