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.visualdata.entity.VisualRecordEntity;
import com.yunzhupaas.visualdata.mapper.VisualRecordMapper;
import com.yunzhupaas.visualdata.model.VisualPagination;
import com.yunzhupaas.visualdata.model.visual.VisualPaginationModel;
import com.yunzhupaas.visualdata.service.VisualRecordService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 大屏数据集
 *
 * @author 云筑产品开发平台组
 * @version V3.5.0
 * @copyright 深圳市乐程软件有限公司
 * @date 2023年7月7日
 */
@Service
public class VisualRecordServiceImpl extends SuperServiceImpl<VisualRecordMapper, VisualRecordEntity> implements VisualRecordService {

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

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

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

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

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

    @Override
    public void delete(VisualRecordEntity entity) {
        if (entity != null) {
            this.removeById(entity.getId());
        }
    }


}

