package com.usky.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.iot.domain.VcDevice;
import com.usky.iot.domain.VcStream;
import com.usky.iot.mapper.VcStreamMapper;
import com.usky.iot.service.VcStreamService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author han
 * @since 2024-10-23
 */
@Service
public class VcStreamServiceImpl extends AbstractCrudService<VcStreamMapper, VcStream> implements VcStreamService {
    @Override
    public CommonPage<VcStream> pageList(String platformAddress, Integer platformType, Integer pageNum, Integer pageSize){
        IPage<VcStream> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<VcStream> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.like(StringUtils.isNotBlank(platformAddress),VcStream::getPlatformAddress,platformAddress)
                .eq(null != platformType,VcStream::getPlatformType,platformType)
                .eq(VcStream::getDelFlag,0)
                .orderByDesc(VcStream::getId);
        page = this.page(page,lambdaQuery);
        return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
    }

    @Override
    public boolean add(VcStream vcStream){
        vcStream.setCreateBy(SecurityUtils.getUsername());
        vcStream.setCreateTime(LocalDateTime.now());
        return this.save(vcStream);
    }

    @Override
    public void update(VcStream vcStream){
        vcStream.setUpdateBy(SecurityUtils.getUsername());
        vcStream.setUpdateTime(LocalDateTime.now());
        this.updateById(vcStream);
    }

    @Override
    public boolean remove(Integer id) {
        VcStream vcStream = this.getById(id);
        vcStream.setDelFlag(1);
        return this.updateById(vcStream);
    }
}
