package com.template.services.impl;

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.template.mapper.SmartScreenshotRecordMapper;
import com.template.model.pojo.SmartScreenshotRecord;
import com.template.model.pojo.SmartScreenshotRecord;
import com.template.mapper.SmartScreenshotRecordMapper;
import com.template.model.result.PageUtils;
import com.template.model.vo.ScreenshotRecordPageVo;
import com.template.services.SmartScreenshotRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-12-04
 */
@Service
public class SmartScreenshotRecordServiceImpl extends ServiceImpl<SmartScreenshotRecordMapper, SmartScreenshotRecord> implements SmartScreenshotRecordService {
    @Autowired
    private SmartScreenshotRecordMapper smartScreenshotRecordMapper;

    @Override
    public int insertSmartScreenshotRecord(SmartScreenshotRecord sa) {
        int result = smartScreenshotRecordMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartScreenshotRecord(SmartScreenshotRecord sa) {
        int result = smartScreenshotRecordMapper.updateById(sa);
        return result;
    }

    @Override
    public PageUtils<SmartScreenshotRecord> queryPageSmartScreenshotRecords(int currentPage, int pageCount, String name) {
        Page<SmartScreenshotRecord> page = new Page<>(currentPage, pageCount);
        QueryWrapper<SmartScreenshotRecord> queryWrapper = new QueryWrapper<>();
        //queryWrapper.like(StringUtils.hasText(name), "name", name);
        IPage<SmartScreenshotRecord> result = smartScreenshotRecordMapper.selectPage(page,queryWrapper);
        return new PageUtils<>(result);
    }

    @Override
    public int deleteSmartScreenshotRecordById(int id) {
        int result = smartScreenshotRecordMapper.deleteById(id);
        return result;
    }

    @Override
    public SmartScreenshotRecord getSmartById(int id) {
        SmartScreenshotRecord result = smartScreenshotRecordMapper.selectById(id);
        return result;
    }

    @Override
    public PageUtils<ScreenshotRecordPageVo> queryScreenshotRecordPageList(int currentPage, int pageCount) {
        Page<ScreenshotRecordPageVo> page = new Page<>(currentPage, pageCount);
        IPage<ScreenshotRecordPageVo> result = smartScreenshotRecordMapper.queryScreenshotRecordPageList(page);
        return new PageUtils<>(result);
    }

    @Override
    public int querySmartScreenshotRecords(int userId) {
        QueryWrapper<SmartScreenshotRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(userId > 0, "user_id", userId);
        queryWrapper.eq("is_freeze", 0);
        Integer count = smartScreenshotRecordMapper.selectCount(queryWrapper);
        return count;
    }
}
