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.model.pojo.SmartApply;
import com.template.mapper.SmartApplyMapper;
import com.template.model.pojo.SmartIdentity;
import com.template.model.result.PageUtils;
import com.template.model.vo.ApplyVo;
import com.template.services.SmartApplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-12-04
 */
@Service
public class SmartApplyServiceImpl extends ServiceImpl<SmartApplyMapper, SmartApply> implements SmartApplyService {
    @Autowired
    private SmartApplyMapper smartApplyMapper;

    @Override
    public List<ApplyVo> queryApplys() {
        List<ApplyVo> result = smartApplyMapper.queryApplys();
        return result;
    }

    @Override
    public int insertSmartApply(SmartApply sa) {
        int result = smartApplyMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartApply(SmartApply sa) {
        int result = smartApplyMapper.updateById(sa);
        return result;
    }

    @Override
    public SmartApply queryApplyByName(String name){
        QueryWrapper<SmartApply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        SmartApply result = smartApplyMapper.selectOne(queryWrapper);
        return result;
    }

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

    @Override
    public int deleteSmartApplyById(int id) {
        int result = smartApplyMapper.deleteById(id);
        return result;
    }

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

    @Override
    public List<SmartApply> queryAppletApplys() {
        QueryWrapper<SmartApply> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("category", "管理后台");
        List<SmartApply> result = smartApplyMapper.selectList(queryWrapper);
        return result;
    }
}
