package com.repair.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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.repair.mapper.RepairConsumeMapper;
import com.repair.model.pojo.RepairConsume;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.ConsumeVo;
import com.repair.model.vo.RepairArticleConsumeVo;
import com.repair.model.vo.RepairConsumeVo;
import com.repair.services.RepairConsumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-07-18
 */
@Service
public class RepairConsumeServiceImpl extends ServiceImpl<RepairConsumeMapper, RepairConsume> implements RepairConsumeService {

    @Autowired
    private RepairConsumeMapper repairConsumeMapper;

    @Override
    public int insertRepairConsume(RepairConsume rc) {
        int result = repairConsumeMapper.insert(rc);
        return result;
    }

    @Override
    public int updateRepairConsume(RepairConsume rc) {
        int result = repairConsumeMapper.updateById(rc);
        return result;
    }

    @Override
    public PageUtils<RepairConsumeVo> queryPageRepairConsumes(int currentPage, int pageCount, String name, String startTime, String endTime) {
        Page<RepairConsumeVo> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(pageCount);
        IPage<RepairConsumeVo> datas = repairConsumeMapper.queryConsumePageList(page, name, startTime, endTime);
        return new PageUtils(datas);
    }

    @Override
    public int deleteRepairConsumeById(int id) {
        int result = repairConsumeMapper.deleteById(id);
        return result;
    }

    @Override
    public RepairConsume getRepairById(int id) {
        RepairConsume result = repairConsumeMapper.selectById(id);
        return result;
    }

    @Override
    public List<ConsumeVo> queryConsumeList(String name, String startTime, String endTime) {
        List<ConsumeVo> result = repairConsumeMapper.queryConsumeList(name, startTime, endTime);
        return result;
    }

    @Override
    public RepairConsume queryConsumeByName(String name, Integer schoolId) {
        QueryWrapper<RepairConsume> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        queryWrapper.eq("school_id", schoolId);
        RepairConsume result = repairConsumeMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public List<RepairArticleConsumeVo> queryArticleConsumes(Integer schoolId, String keyWork, String findInSet) {
        List<RepairArticleConsumeVo> result = repairConsumeMapper.queryArticleConsumes(schoolId, keyWork, findInSet);
        return result;
    }

    @Override
    public List<RepairArticleConsumeVo> queryArticleConsumesName(String findInSet,int schoolId) {
        List<RepairArticleConsumeVo> result= repairConsumeMapper.queryArticleConsumesName(findInSet,schoolId);
        return result;
    }

    @Override
    public List<RepairConsume> getConsumes() {
        List<RepairConsume> consumes = repairConsumeMapper.selectList(null);
        return consumes;
    }

    @Override
    public List<RepairConsume> getConsumesByKeyword(Integer schoolId, String keyWord) {
        QueryWrapper<RepairConsume> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("school_id", schoolId);
        queryWrapper.like(keyWord != null ,"name", keyWord);
        List<RepairConsume> consumes = repairConsumeMapper.selectList(queryWrapper);
        return consumes;
    }
}
