package com.repair.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.repair.mapper.RepairArticleBuildMapper;
import com.repair.model.pojo.*;
import com.repair.services.RepairArticleBuildService;
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-11-02
 */
@Service
public class RepairArticleBuildServiceImpl extends ServiceImpl<RepairArticleBuildMapper, RepairArticleBuild> implements RepairArticleBuildService {
    @Autowired
    private RepairArticleBuildMapper repairArticleBuildMapper;

    @Override
    public boolean saveArticleBuildBatch(List<RepairArticleBuild> rab) {
        boolean result = this.saveBatch(rab);
        return result;
    }

    @Override
    public int insertRepairArticleBuild(RepairArticleBuild rab) {
        int result = repairArticleBuildMapper.insert(rab);
        return result;
    }

    @Override
    public int updateRepairArticleBuild(RepairArticleBuild ra) {
        int result = repairArticleBuildMapper.updateById(ra);
        return result;
    }

    @Override
    public int updateArticleBuildByUserId(int userId, RepairArticleBuild data) {
        QueryWrapper<RepairArticleBuild> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        int result = repairArticleBuildMapper.update(data, queryWrapper);
        return result;
    }

    @Override
    public int deleteRepairArticleBuildById(int id) {
        int result = repairArticleBuildMapper.deleteById(id);
        return result;
    }

    @Override
    public int deleteRepairArticleBuildByWrapper(int userId) {
        QueryWrapper<RepairArticleBuild> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        int result = repairArticleBuildMapper.delete(queryWrapper);
        return result;
    }

    @Override
    public List<RepairArticleBuild> queryRepairArticleBuilds() {
        List<RepairArticleBuild> result = repairArticleBuildMapper.selectList(null);
        return result;
    }

    @Override
    public List<RepairArticleBuild> getRepairArticleBuilds(int userId) {
        QueryWrapper<RepairArticleBuild> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<RepairArticleBuild> datas = repairArticleBuildMapper.selectList(queryWrapper);
        return datas;
    }

    @Override
    public int deletedArticleBuildByIds(List<Integer> ids) {
        QueryWrapper<RepairArticleBuild> queryWrapper = new QueryWrapper();
        queryWrapper.in("id", ids);
        int result = repairArticleBuildMapper.delete(queryWrapper);
        return result;
    }

    @Override
    public boolean saveorUpdateArticleBuildBatch(List<RepairArticleBuild> rab) {
        boolean result = this.saveOrUpdateBatch(rab);
        return result;
    }
}
